Skip to content

Commit

Permalink
Subtract unclaimed rewards
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkeating committed Dec 12, 2024
1 parent a1d4835 commit 4a62ddc
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/GovernanceStaker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,8 @@ abstract contract GovernanceStaker is INotifiableRewardReceiver, Multicall {

// Send tip to the receiver
SafeERC20.safeTransfer(REWARD_TOKEN, _tipReceiver, _requestedTip);
deposit.scaledUnclaimedRewardCheckpoint =
deposit.scaledUnclaimedRewardCheckpoint - (_requestedTip * SCALE_FACTOR);
}

/// @notice Live value of the unclaimed rewards earned by a given deposit with the
Expand Down
41 changes: 41 additions & 0 deletions test/GovernanceStaker.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2983,6 +2983,47 @@ contract BumpEarningPower is GovernanceStakerRewardsTest {
assertEq(_tipReceiverBalanceIncrease, _requestedTip);
}

function testFuzz_TipRemovedFromUnclaimedWhenEarningPowerIsBumpedUp(
address _depositor,
address _delegatee,
uint256 _stakeAmount,
uint256 _rewardAmount,
address _bumpCaller,
address _tipReceiver,
uint256 _requestedTip,
uint96 _earningPowerIncrease
) public {
vm.assume(_tipReceiver != address(0) && _tipReceiver != address(govStaker));
_stakeAmount = _boundToRealisticStake(_stakeAmount);
_rewardAmount = _boundToRealisticReward(_rewardAmount);
uint256 _initialTipReceiverBalance = rewardToken.balanceOf(_tipReceiver);
_earningPowerIncrease = uint96(bound(_earningPowerIncrease, 1, type(uint48).max));

// A user deposits staking tokens
(, GovernanceStaker.DepositIdentifier _depositId) =
_boundMintAndStake(_depositor, _stakeAmount, _delegatee);
// The contract is notified of a reward
_mintTransferAndNotifyReward(_rewardAmount);
// The full duration passes
_jumpAheadByPercentOfRewardDuration(101);

uint256 _unclaimedRewards = govStaker.unclaimedReward(_depositId);
// Tip must be less than the max bump, but also less than rewards for the sake of this test
_requestedTip = bound(_requestedTip, 0, _min(maxBumpTip, _unclaimedRewards));

// The staker's earning power increases
earningPowerCalculator.__setEarningPowerForDelegatee(
_delegatee, _stakeAmount + _earningPowerIncrease
);
// Bump earning power is called
vm.prank(_bumpCaller);
govStaker.bumpEarningPower(_depositId, _tipReceiver, _requestedTip);

uint256 _tipReceiverBalanceIncrease =
rewardToken.balanceOf(_tipReceiver) - _initialTipReceiverBalance;
assertEq(govStaker.unclaimedReward(_depositId), _unclaimedRewards - _requestedTip);
}

function testFuzz_BumpsTheDepositsEarningPowerDown(
address _depositor,
address _delegatee,
Expand Down

0 comments on commit 4a62ddc

Please sign in to comment.