function LastimeRewardApplicable () public view returns (uint){ return _min(block.timestamp, FinishTime); // return the timestamp of the last time the reward is still applicable } function _min (uint x , uint y ) private pure returns (uint) { return x <= y ? x:y; } function RewardPerCoin () public view returns (uint){ if (totalSupply == 0 ) { return RewardPerCoinInvested; } return RewardPerCoinInvested + (RewardRate + (LastimeRewardApplicable() - UpdatedTime) * 1e18)/ totalSupply; } function ClaimReward () external { uint reward = RewardInvestorsEarn[msg.sender]; if (reward >0 ) { RewardInvestorsEarn [msg.sender] = 0; Reward_Coin.transfer(msg.sender, reward); } } function Earned (address _account ) public view returns (uint) { return (balanceOf[_account] * (RewardPerToken() - RewardInvestorsEarn[_account]))/1e18 + RewardInvestorsEarn[_account]; }