Skip to content

Commit

Permalink
fix: prevent underflow
Browse files Browse the repository at this point in the history
  • Loading branch information
alpanaca committed Aug 22, 2024
1 parent e68fa02 commit c8dea5f
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions contracts/8.19/xALPACAv2RevenueDistributor/xALPACAv2Rewarder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ contract xALPACAv2Rewarder is IxALPACAv2Rewarder, OwnableUpgradeable, Reentrancy
// Meaning user eligible for 25,000 rewards in this harvest
int256 _accumulatedRewards = ((_userAmount * pool.accRewardPerShare) / ACC_REWARD_PRECISION).toInt256();

uint256 _pendingRewards = (_accumulatedRewards - user.rewardDebt).toUint256();
uint256 _pendingRewards = _accumulatedRewards > user.rewardDebt
? (_accumulatedRewards - user.rewardDebt).toUint256()
: 0;

user.rewardDebt = _accumulatedRewards;
if (user.amount != _userAmount) {
Expand Down Expand Up @@ -236,8 +238,12 @@ contract xALPACAv2Rewarder is IxALPACAv2Rewarder, OwnableUpgradeable, Reentrancy
}

uint256 _totalUserAmount = IxALPACAv2RevenueDistributor(xALPACAv2RevenueDistributor).getUserTotalAmountOf(_user);
return
(((_totalUserAmount * _accRewardPerShare) / ACC_REWARD_PRECISION).toInt256() - _userInfo.rewardDebt).toUint256();
int256 _userAccumReward = ((_totalUserAmount * _accRewardPerShare) / ACC_REWARD_PRECISION).toInt256();

if (_userAccumReward < _userInfo.rewardDebt) {
return 0;
}
return (_userAccumReward - _userInfo.rewardDebt).toUint256();
}

/// @dev Perform the actual updatePool
Expand Down

0 comments on commit c8dea5f

Please sign in to comment.