Skip to content

Commit

Permalink
Merge pull request #401 from Phoenix-Protocol-Group/jakub/staking-und…
Browse files Browse the repository at this point in the history
…erflow

Stake: Use saturating sub for the stake age days
  • Loading branch information
ueco-jb authored Dec 16, 2024
2 parents ddf8a1e + 89b4a91 commit 7c6c2d7
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions contracts/stake/src/distribution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,12 @@ pub fn calculate_pending_rewards(
for stake in user_info.stakes.iter() {
// Calculate the user's share of the total staked amount at the time
let user_share = stake.stake as u128 * daily_reward / total_staked;
let stake_age_days =
(staking_reward_day - stake.stake_timestamp) / SECONDS_PER_DAY;
let stake_age_days = (staking_reward_day
.saturating_sub(stake.stake_timestamp))
/ SECONDS_PER_DAY;
if stake_age_days == 0u64 {
continue;
}
let multiplier = if stake_age_days >= 60 {
Decimal::one()
} else {
Expand Down

0 comments on commit 7c6c2d7

Please sign in to comment.