Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save percybolmer/42f7a1390e8c6c7945b0e41cbb965555 to your computer and use it in GitHub Desktop.
Save percybolmer/42f7a1390e8c6c7945b0e41cbb965555 to your computer and use it in GitHub Desktop.
/**
* @notice
* calculateStakeReward is used to calculate how much a user should be rewarded for their stakes
* and the duration the stake has been active
*/
function calculateStakeReward(Stake memory _current_stake) internal view returns(uint256){
// First calculate how long the stake has been active
// Use current seconds since epoch - the seconds since epoch the stake was made
// The output will be duration in SECONDS ,
// We will reward the user 0.1% per Hour So thats 0.1% per 3600 seconds
// the alghoritm is seconds = block.timestamp - stake seconds (block.timestap - _stake.since)
// hours = Seconds / 3600 (seconds /3600) 3600 is an variable in Solidity names hours
// we then multiply each token by the hours staked , then divide by the rewardPerHour rate
return (((block.timestamp - _current_stake.since) / 1 hours) * _current_stake.amount) / rewardPerHour;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment