算力挖矿系统的开发源码和demo
rewardTokens public rewardUNITokens;
LPToken public stakingLPTokens;
uint public stakingFinishTime = block.timestamp + stakingTime;
uint public stakingTime;
uint public rewardRate = 100;
uint private _totalSupply;
uint public rewardPerTokenStored;
uint public lastUpdateTime;
constructor(address _rewardUNITokens,address _stakingLPTokens,uint _stakingTime){
rewardUNITokens = rewardTokens(_rewardUNITokens);
stakingLPTokens = LPToken(_stakingLPTokens);
stakingTime = _stakingTime;
}
modifier update(address owner) {
lastUpdateTime = getLastTime();
rewardPerTokenStored = rewardUNIPerToken();
if(owner != address(0)){
userRewardsPerToken[owner] = rewardPerTokenStored;
rewards[owner] = allRewardsOfUser(owner);
}
_;
}
function rewardUNIPerToken() public view returns(uint rewardUNI){
if(_totalSupply == 0){
rewardUNI = rewardPerTokenStored;
}
rewardUNI = rewardPerTokenStored.add(getLastTime().sub(lastUpdateTime).mul(rewardRate).mul(1e18).div(_totalSupply));
}