Advertisement
Guest User

Untitled

a guest
Jul 6th, 2019
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.12 KB | None | 0 0
  1. pragma solidity ^0.5.1;
  2.  
  3. contract FairPonziReloaded {
  4.     struct Investment {
  5.         uint initamount;
  6.         uint inittime;
  7.        
  8.         uint refbonus;
  9.         address refaddress;
  10.         uint refcount;
  11.     }
  12.     struct Payment {
  13.         address receiver;
  14.         uint inamount;
  15.         uint outamount;
  16.     }
  17.     mapping(uint => mapping(address => Investment)) public investmentTable;
  18.     mapping(uint => Payment) public payoutList;
  19.    
  20.     uint public payoutcount = 0;
  21.     uint public payincount = 0;
  22.     uint roundcount = 0;
  23.    
  24.     uint public nextRoundStart = 1562472334; // this disables our preinvest advantage
  25.    
  26.     uint public constant delayBetweenRounds = 3600 * 24 * 7; // 1 week
  27.     uint public constant minbid = 1000000000000; // 1uETH
  28.     uint public constant rewardinterval = 3600 * 24; // 1day
  29.     uint constant gassaver_days = 391; // every 391 reward x7 -> saves gas costs, 1.05^391=6,994619351
  30.     uint constant gassaver_factor = 7; // every 391 days user will receive bonus reward of ~0.08%
  31.    
  32.     address constant nulladdress = 0x0000000000000000000000000000000000000000;
  33.    
  34.     constructor() public {
  35.     }
  36.    
  37.     function () external payable {
  38.         buyin(nulladdress); // if normal transaction, nobody get referral
  39.     }
  40.     function buyin(address refaddr)public payable{
  41.         if(msg.value < minbid) { // wants a payout
  42.             redeemPayout();
  43.             return;
  44.         }
  45.         Investment storage acc = investmentTable[roundcount][msg.sender];
  46.         uint addreward = getAccountBalance(msg.sender);
  47.         uint win = addreward - acc.initamount;
  48.         if(win > 0){
  49.             investmentTable[roundcount][acc.refaddress].refbonus += win / 10; // Referral get 10%
  50.         }
  51.        
  52.         acc.initamount = msg.value + addreward;
  53.         acc.inittime = block.timestamp;
  54.         if(refaddr != msg.sender && acc.refaddress == nulladdress){
  55.             acc.refaddress = refaddr;
  56.             investmentTable[roundcount][refaddr].refcount++;
  57.         }
  58.        
  59.         payincount++;
  60.     }
  61.     function redeemPayout() public {
  62.         Investment storage acc = investmentTable[roundcount][msg.sender];
  63.         uint addreward = getAccountBalance(msg.sender);
  64.         uint win = addreward - acc.initamount;
  65.         uint payamount = addreward + acc.refbonus;
  66.         if(payamount <= 0) return;
  67.         if(address(this).balance < payamount){
  68.             reset();
  69.         }else{
  70.             payoutList[payoutcount++] = Payment(msg.sender, acc.initamount, payamount);
  71.             acc.initamount = 0;
  72.             acc.refbonus = 0;
  73.             msg.sender.transfer(payamount);
  74.             investmentTable[roundcount][acc.refaddress].refbonus += win / 10; // Referral get 10%
  75.         }
  76.     }
  77.     function reset() private {
  78.         nextRoundStart = block.timestamp + delayBetweenRounds;
  79.         roundcount++;
  80.         payincount = 0;
  81.     }
  82.     function getAccountBalance(address addr)public view returns (uint amount){
  83.         Investment storage acc = investmentTable[roundcount][addr];
  84.         uint ret = acc.initamount;
  85.         uint usertimestamp = acc.inittime;
  86.         if(acc.initamount > 0 && block.timestamp > nextRoundStart){
  87.             if(nextRoundStart > usertimestamp) usertimestamp = nextRoundStart;
  88.             uint rewardcount = (block.timestamp - usertimestamp) / rewardinterval;
  89.             while(rewardcount >= gassaver_days){
  90.                 ret = ret * gassaver_factor;
  91.                 rewardcount = rewardcount - gassaver_days;
  92.             }
  93.             while(rewardcount > 0){
  94.                 ret += ret / 200; // 0.5%
  95.                 rewardcount--;
  96.             }
  97.             ret += (ret * ((block.timestamp - usertimestamp) % rewardinterval)) / rewardinterval; // for getting every second reward
  98.         }
  99.         return ret;
  100.     }
  101.     function getPayout(uint idrel) public view returns (address bidder, uint inamount, uint outamount) {
  102.         Payment storage cur =  payoutList[idrel];
  103.         return (cur.receiver, cur.inamount, cur.outamount);
  104.     }
  105.     function getTimeUntilStart() public view returns (uint count){
  106.         if(nextRoundStart <= block.timestamp) return 0;
  107.         else return nextRoundStart - block.timestamp;
  108.     }
  109.     function getAccountInfo(address addr) public view returns (address retaddr, uint initamount, uint investmenttime, uint currentbalance, uint _timeuntilnextreward, uint _refbonus, address _refaddress, uint _refcount) {
  110.         Investment storage acc = investmentTable[roundcount][addr];
  111.         uint nextreward = rewardinterval - ((block.timestamp - acc.inittime) % rewardinterval);
  112.         if(acc.initamount <= 0) nextreward = 0;
  113.         return (addr, acc.initamount, block.timestamp - acc.inittime, getAccountBalance(addr), nextreward, acc.refbonus, acc.refaddress, acc.refcount);
  114.     }
  115.     function getAccountInfo() public view returns (address retaddr, uint initamount, uint investmenttime, uint currentbalance, uint _timeuntilnextreward, uint _refbonus, address _refaddress, uint _refcount) {
  116.         return getAccountInfo(msg.sender);
  117.     }
  118.     function getStatus() public view returns (uint _payoutcount, uint _blocksUntilStart, uint _payincount){
  119.         return (payoutcount, getTimeUntilStart(), payincount);
  120.     }
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement