Skip to content

Commit

Permalink
WIP: earning power event
Browse files Browse the repository at this point in the history
  • Loading branch information
apbendi committed Feb 5, 2025
1 parent 6978a97 commit b97ec73
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Staker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ abstract contract Staker is INotifiableRewardReceiver, Multicall {
/// @notice Emitted when a reward notifier address is enabled or disabled.
event RewardNotifierSet(address indexed account, bool isEnabled);

event EarningPowerBumped(DepositIdentifier indexed depositId, uint256 oldEarningPower, uint256 newEarningPower, address tipReceiver, uint256 tipAmount);

/// @notice Thrown when an account attempts a call for which it lacks appropriate permission.
/// @param reason Human readable code explaining why the call is unauthorized.
/// @param caller The address that attempted the unauthorized call.
Expand Down Expand Up @@ -497,6 +499,8 @@ abstract contract Staker is INotifiableRewardReceiver, Multicall {
revert Staker__InsufficientUnclaimedRewards();
}

emit EarningPowerBumped(_depositId, deposit.earningPower, _newEarningPower, _tipReceiver, _requestedTip);

// Update global earning power & deposit earning power based on this bump
totalEarningPower =
_calculateTotalEarningPower(deposit.earningPower, _newEarningPower, totalEarningPower);
Expand Down
40 changes: 40 additions & 0 deletions test/Staker.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3055,6 +3055,46 @@ contract BumpEarningPower is StakerRewardsTest {
assertEq(govStaker.unclaimedReward(_depositId), _unclaimedReward - _requestedTip);
}

function testFuzz_EmitsAnEarningPowerBumpedEvent(
address _depositor,
address _delegatee,
uint256 _stakeAmount,
uint256 _rewardAmount,
address _bumpCaller,
address _tipReceiver,
uint256 _requestedTip,
uint256 _earningPowerDecrease
) public {
vm.assume(_tipReceiver != address(0) && _tipReceiver != address(govStaker));
_stakeAmount = _boundToRealisticStake(_stakeAmount);
_rewardAmount = bound(_rewardAmount, maxBumpTip + 1, 10_000_000e18);
_earningPowerDecrease = bound(_earningPowerDecrease, 1, _stakeAmount);

// A user deposits staking tokens
(, Staker.DepositIdentifier _depositId) =
_boundMintAndStake(_depositor, _stakeAmount, _delegatee);
// The contract is notified of a reward
_mintTransferAndNotifyReward(_rewardAmount);
// The full duration passes
_jumpAheadByPercentOfRewardDuration(101);
uint256 _unclaimedReward = 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, _unclaimedReward - maxBumpTip));

// The staker's earning power decreases
earningPowerCalculator.__setEarningPowerForDelegatee(
_delegatee, _stakeAmount - _earningPowerDecrease
);
uint256 _oldEarningPower = _stakeAmount;
uint256 _newEarningPower = _stakeAmount - _earningPowerDecrease;

// Bump earning power is called
vm.prank(_bumpCaller);
vm.expectEmit();
emit Staker.EarningPowerBumped(_depositId, _oldEarningPower, _newEarningPower, _tipReceiver, _requestedTip);
govStaker.bumpEarningPower(_depositId, _tipReceiver, _requestedTip);
}

function testFuzz_RevertIf_RequestedTipIsGreaterThanTheMaxTip(
address _depositor,
address _delegatee,
Expand Down

0 comments on commit b97ec73

Please sign in to comment.