Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pragma solidity ^0.5.1;
- contract FairPonziReloaded {
- struct Investment {
- uint initamount;
- uint inittime;
- uint refbonus;
- address refaddress;
- uint refcount;
- }
- struct Payment {
- address receiver;
- uint inamount;
- uint outamount;
- }
- mapping(uint => mapping(address => Investment)) public investmentTable;
- mapping(uint => Payment) public payoutList;
- uint public payoutcount = 0;
- uint public payincount = 0;
- uint roundcount = 0;
- uint public nextRoundStart = 1562472334; // this disables our preinvest advantage
- uint public constant delayBetweenRounds = 3600 * 24 * 7; // 1 week
- uint public constant minbid = 1000000000000; // 1uETH
- uint public constant rewardinterval = 3600 * 24; // 1day
- uint constant gassaver_days = 391; // every 391 reward x7 -> saves gas costs, 1.05^391=6,994619351
- uint constant gassaver_factor = 7; // every 391 days user will receive bonus reward of ~0.08%
- address constant nulladdress = 0x0000000000000000000000000000000000000000;
- constructor() public {
- }
- function () external payable {
- buyin(nulladdress); // if normal transaction, nobody get referral
- }
- function buyin(address refaddr)public payable{
- if(msg.value < minbid) { // wants a payout
- redeemPayout();
- return;
- }
- Investment storage acc = investmentTable[roundcount][msg.sender];
- uint addreward = getAccountBalance(msg.sender);
- uint win = addreward - acc.initamount;
- if(win > 0){
- investmentTable[roundcount][acc.refaddress].refbonus += win / 10; // Referral get 10%
- }
- acc.initamount = msg.value + addreward;
- acc.inittime = block.timestamp;
- if(refaddr != msg.sender && acc.refaddress == nulladdress){
- acc.refaddress = refaddr;
- investmentTable[roundcount][refaddr].refcount++;
- }
- payincount++;
- }
- function redeemPayout() public {
- Investment storage acc = investmentTable[roundcount][msg.sender];
- uint addreward = getAccountBalance(msg.sender);
- uint win = addreward - acc.initamount;
- uint payamount = addreward + acc.refbonus;
- if(payamount <= 0) return;
- if(address(this).balance < payamount){
- reset();
- }else{
- payoutList[payoutcount++] = Payment(msg.sender, acc.initamount, payamount);
- acc.initamount = 0;
- acc.refbonus = 0;
- msg.sender.transfer(payamount);
- investmentTable[roundcount][acc.refaddress].refbonus += win / 10; // Referral get 10%
- }
- }
- function reset() private {
- nextRoundStart = block.timestamp + delayBetweenRounds;
- roundcount++;
- payincount = 0;
- }
- function getAccountBalance(address addr)public view returns (uint amount){
- Investment storage acc = investmentTable[roundcount][addr];
- uint ret = acc.initamount;
- uint usertimestamp = acc.inittime;
- if(acc.initamount > 0 && block.timestamp > nextRoundStart){
- if(nextRoundStart > usertimestamp) usertimestamp = nextRoundStart;
- uint rewardcount = (block.timestamp - usertimestamp) / rewardinterval;
- while(rewardcount >= gassaver_days){
- ret = ret * gassaver_factor;
- rewardcount = rewardcount - gassaver_days;
- }
- while(rewardcount > 0){
- ret += ret / 200; // 0.5%
- rewardcount--;
- }
- ret += (ret * ((block.timestamp - usertimestamp) % rewardinterval)) / rewardinterval; // for getting every second reward
- }
- return ret;
- }
- function getPayout(uint idrel) public view returns (address bidder, uint inamount, uint outamount) {
- Payment storage cur = payoutList[idrel];
- return (cur.receiver, cur.inamount, cur.outamount);
- }
- function getTimeUntilStart() public view returns (uint count){
- if(nextRoundStart <= block.timestamp) return 0;
- else return nextRoundStart - block.timestamp;
- }
- function getAccountInfo(address addr) public view returns (address retaddr, uint initamount, uint investmenttime, uint currentbalance, uint _timeuntilnextreward, uint _refbonus, address _refaddress, uint _refcount) {
- Investment storage acc = investmentTable[roundcount][addr];
- uint nextreward = rewardinterval - ((block.timestamp - acc.inittime) % rewardinterval);
- if(acc.initamount <= 0) nextreward = 0;
- return (addr, acc.initamount, block.timestamp - acc.inittime, getAccountBalance(addr), nextreward, acc.refbonus, acc.refaddress, acc.refcount);
- }
- function getAccountInfo() public view returns (address retaddr, uint initamount, uint investmenttime, uint currentbalance, uint _timeuntilnextreward, uint _refbonus, address _refaddress, uint _refcount) {
- return getAccountInfo(msg.sender);
- }
- function getStatus() public view returns (uint _payoutcount, uint _blocksUntilStart, uint _payincount){
- return (payoutcount, getTimeUntilStart(), payincount);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement