Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save percybolmer/be1ed75fbdc09fbe7404d8cf9c71e953 to your computer and use it in GitHub Desktop.
Save percybolmer/be1ed75fbdc09fbe7404d8cf9c71e953 to your computer and use it in GitHub Desktop.
/**
* @notice
* calculateTotalAvailableRewards will iterate all stakes made by a account
* and summerize the total unclaimed rewards
*
*/
function calculateTotalAvailableRewards(address _staker) public view returns(uint256){
uint256 total_reward;
// Itterate all stakes from the address and calculate their reward for each stake
Stake[] memory user_stakes = stakes[stakeHolders[_staker]];
for(uint256 i = 0; i<user_stakes.length; i++) {
// Skip any stake that is actually stopped or empty
if(user_stakes[i].amount == 0 || user_stakes[i].until != 0){
continue;
}
total_reward = total_reward + calculateStakeReward(user_stakes[i]);
}
return total_reward;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment