// SPDX-License-Identifier: MIT
pragma experimental ABIEncoderV2;
pragma solidity ^0.6.0;
library SafeMath {
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a, "SafeMath: subtraction overflow");
uint256 c = a - b;
return c;
}
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0, "SafeMath: division by zero");
uint256 c = a / b;
return c;
}
}
contract ETH_3Day {
using SafeMath for uint256;
uint256 constant public CONTRACT_BALANCE_STEP = 3;
address public manager;
uint256 public day = 3 days;
uint256 public rechargeTime;
uint256 public minAmount = 1 ether;
uint256 public percentage = 900;
uint256 public totalUsers;
bool public ISEND;
struct RechargeInfo{
address rec_addr;
uint256 rec_value;
uint256 rec_time;
}
RechargeInfo[] public rechargeAddress;
struct UserInfo {
address referrer;
address[] directPush;
uint256 amountWithdrawn;
uint256 distributionIncome72;
}
mapping(address => UserInfo) public user;
mapping(address => uint256) public balance;
mapping(address => mapping(address => bool)) public userDireMap;
constructor()public{
manager = msg.sender;
}
// 充值
function deposit(address referrer) payable public {
require(msg.value > 0 && ISEND == false);
// require(msg.value >= minAmount,"Top up cannot be less than 1 eth");
UserInfo storage u = user[msg.sender];
// 当前用户没有上 && 推荐人 不能是 自己
if (u.referrer == address(0) && referrer != msg.sender) {
// 添加上级
u.referrer = referrer;
if (userDireMap[referrer][msg.sender] == false){
// 给上级添加当前下级
user[referrer].directPush.push(msg.sender);
userDireMap[referrer][msg.sender] = true;
}
}
if (balance[msg.sender] == 0){
totalUsers = totalUsers.add(1);
}
// 充值
balance[msg.sender] = balance[msg.sender].add(msg.value);
rechargeAddress.push(RechargeInfo({rec_addr:msg.sender,rec_value:msg.value,rec_time:block.timestamp}));
rechargeTime = block.timestamp;
}
// 提币
function withdraw(uint256 value) public {
require(value > 0);
// 验证是否有足够提取额度
uint256 count = getIncome(msg.sender);
require(count >= value,"Not enough quota");
// 提币
msg.sender.transfer(value);
user[msg.sender].amountWithdrawn = user[msg.sender].amountWithdrawn.add(value);
}
// pool 总量
function getPoolETH() view public returns(uint256){
return address(this).balance;
}
// 充值总笔数
function getRecTotal() view public returns(uint256){
return rechargeAddress.length;
}
// 最后10笔交易
function getRec10() view public returns(RechargeInfo[] memory){
uint256 l = rechargeAddress.length;
uint256 a = 0;
uint256 i = 0;
if (rechargeAddress.length>10){
l = 10;
a = rechargeAddress.length.sub(10);
}
RechargeInfo[] memory data = new RechargeInfo[](l);
for (;a < rechargeAddress.length; a++){
data[i] = rechargeAddress[a];
i = i+1;
}
return data;
}
// 超过72小时分币
function distribution72() public {
if (isTime() == false){return;}
uint256 a = 0;
if (rechargeAddress.length>50){
a = rechargeAddress.length.sub(50);
}
uint256 total = (address(this).balance.mul(percentage)).div(uint256(1000));
for (;a < rechargeAddress.length; a++){
user[rechargeAddress[a].rec_addr].distributionIncome72 = user[rechargeAddress[a].rec_addr].distributionIncome72.add(total.div(100));
}
ISEND = true;
return;
}
// 当前时间是否大于 72 小时
function isTime()view public returns(bool) {
if ((block.timestamp.sub(rechargeTime)) >= day && rechargeTime != 0){
return true;
}
return false;
}
// 直推倍数 公式:直推总量 / 本金
function directPushMultiple(address addr) view public isAddress(addr) returns(uint256) {
if(balance[addr] == 0){
return 0;
}
return getDirectTotal(addr).div(balance[addr]);
}
// 最大收益 公式:直推总量 - 提出总量
function getMaxIncome(address addr) view public isAddress(addr) returns(uint256){
return getDirectTotal(addr).sub(user[addr].amountWithdrawn);
}
// 当前收益 公式:本金 * 3 - 提出总量
function getIncome(address addr) view public isAddress(addr) returns(uint256){
uint256 multiple = directPushMultiple(addr);
if (multiple < 3){
return 0;
}
return (balance[addr].mul(3).sub(user[addr].amountWithdrawn));
}
// 当前已提取数量
function numberWithdrawn(address addr) view public isAddress(addr) returns(uint256) {
return user[addr].amountWithdrawn;
}
// 追投计算 公式:(直推总量 - 已提取数量 - 当前可提取数量) / 3
function additionalThrow(address addr) view public isAddress(addr) returns(uint256){
return (getDirectTotal(addr).sub(user[addr].amountWithdrawn).sub(getIncome(addr))).div(3);
}
// 获取下级充值总额
function getDirectTotal(address addr) view public isAddress(addr) returns(uint256) {
UserInfo memory u = user[addr];
if (u.directPush.length == 0){return (0);}
uint256 total;
for (uint256 i= 0; i<u.directPush.length;i++){
total += balance[u.directPush[i]];
}
return (total);
}
// 72收益领取
function distributionIncome72()public{
require(user[msg.sender].distributionIncome72 > 0);
msg.sender.transfer(user[msg.sender].distributionIncome72);
}
// 获取用户下级
function getDirectLength(address addr) view public isAddress(addr) returns(uint256){
return user[addr].directPush.length;
}
// Owner 提币
function ownerWitETH(uint256 value) public onlyOwner{
require(getPoolETH() >= value);
msg.sender.transfer(value);
}
// 权限转移
function ownerTransfer(address newOwner) public onlyOwner isAddress(newOwner) {
manager = newOwner;
}
modifier isAddress(address addr) {
require(addr != address(0));
_;
}
modifier onlyOwner {
require(manager == msg.sender);
_;
}
}
{
"compilationTarget": {
"browser/eth_game_3day_2.sol": "ETH_3Day"
},
"evmVersion": "istanbul",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"CONTRACT_BALANCE_STEP","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ISEND","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"additionalThrow","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"balance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"day","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"referrer","type":"address"}],"name":"deposit","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"directPushMultiple","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"distribution72","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"distributionIncome72","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"getDirectLength","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"getDirectTotal","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"getIncome","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"getMaxIncome","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getPoolETH","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getRec10","outputs":[{"components":[{"internalType":"address","name":"rec_addr","type":"address"},{"internalType":"uint256","name":"rec_value","type":"uint256"},{"internalType":"uint256","name":"rec_time","type":"uint256"}],"internalType":"struct ETH_3Day.RechargeInfo[]","name":"","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getRecTotal","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isTime","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"manager","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"minAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"numberWithdrawn","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"ownerTransfer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"value","type":"uint256"}],"name":"ownerWitETH","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"percentage","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"rechargeAddress","outputs":[{"internalType":"address","name":"rec_addr","type":"address"},{"internalType":"uint256","name":"rec_value","type":"uint256"},{"internalType":"uint256","name":"rec_time","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rechargeTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalUsers","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"user","outputs":[{"internalType":"address","name":"referrer","type":"address"},{"internalType":"uint256","name":"amountWithdrawn","type":"uint256"},{"internalType":"uint256","name":"distributionIncome72","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"userDireMap","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"value","type":"uint256"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"}]