From a26f6f75594422a4981d1f5f3862c56a20297918 Mon Sep 17 00:00:00 2001 From: Ben DiFrancesco Date: Wed, 7 Feb 2024 16:03:59 -0500 Subject: [PATCH] Update variable and method names to consistently use singular reward --- script/Deploy.s.sol | 4 +- src/UniStaker.sol | 102 +++---- src/V3FactoryOwner.sol | 4 +- src/interfaces/INotifiableRewardReceiver.sol | 2 +- test/UniStaker.integration.t.sol | 4 +- test/UniStaker.t.sol | 269 +++++++++---------- test/V3FactoryOwner.t.sol | 2 +- test/mocks/MockRewardReceiver.sol | 6 +- 8 files changed, 191 insertions(+), 202 deletions(-) diff --git a/script/Deploy.s.sol b/script/Deploy.s.sol index aeca68c..9a48376 100644 --- a/script/Deploy.s.sol +++ b/script/Deploy.s.sol @@ -41,8 +41,8 @@ contract Deploy is Script, DeployInput { INotifiableRewardReceiver(uniStaker) ); - // Enable the v3FactoryOwner as a UniStaker rewards notifier - uniStaker.setRewardsNotifier(address(v3FactoryOwner), true); + // Enable the v3FactoryOwner as a UniStaker reward notifier + uniStaker.setRewardNotifier(address(v3FactoryOwner), true); // Change UniStaker admin from `msg.sender` to the Governor timelock uniStaker.setAdmin(UNISWAP_GOVERNOR_TIMELOCK); diff --git a/src/UniStaker.sol b/src/UniStaker.sol index b410e1d..f192187 100644 --- a/src/UniStaker.sol +++ b/src/UniStaker.sol @@ -59,8 +59,8 @@ contract UniStaker is INotifiableRewardReceiver, ReentrancyGuard, Multicall { /// @notice Emitted when the admin address is set. event AdminSet(address indexed oldAdmin, address indexed newAdmin); - /// @notice Emitted when a rewards notifier address is enabled or disabled. - event RewardsNotifierSet(address indexed account, bool isEnabled); + /// @notice Emitted when a reward notifier address is enabled or disabled. + event RewardNotifierSet(address indexed account, bool isEnabled); /// @notice Emitted when a surrogate contract is deployed. event SurrogateDeployed(address indexed delegatee, address indexed surrogate); @@ -94,7 +94,7 @@ contract UniStaker is INotifiableRewardReceiver, ReentrancyGuard, Multicall { } /// @notice ERC20 token in which rewards are denominated and distributed. - IERC20 public immutable REWARDS_TOKEN; + IERC20 public immutable REWARD_TOKEN; /// @notice Delegable governance token which users stake to earn rewards. IERC20Delegates public immutable STAKE_TOKEN; @@ -109,7 +109,7 @@ contract UniStaker is INotifiableRewardReceiver, ReentrancyGuard, Multicall { /// @dev Unique identifier that will be used for the next deposit. DepositIdentifier private nextDepositId; - /// @notice Permissioned actor that can enable/disable `rewardsNotifier` addresses. + /// @notice Permissioned actor that can enable/disable `rewardNotifier` addresses. address public admin; /// @notice Global amount currently staked across all deposits. @@ -129,7 +129,7 @@ contract UniStaker is INotifiableRewardReceiver, ReentrancyGuard, Multicall { mapping(address delegatee => DelegationSurrogate surrogate) public surrogates; /// @notice Time at which rewards distribution will complete if there are no new rewards. - uint256 public rewardsEndTime; + uint256 public rewardEndTime; /// @notice Last time at which the global rewards accumulator was updated. uint256 public lastCheckpointTime; @@ -138,7 +138,7 @@ contract UniStaker is INotifiableRewardReceiver, ReentrancyGuard, Multicall { /// denominated in scaled reward tokens per second, using the SCALE_FACTOR. uint256 public scaledRewardRate; - /// @notice Checkpoint value of the global rewards per token accumulator. + /// @notice Checkpoint value of the global reward per token accumulator. uint256 public rewardPerTokenAccumulatedCheckpoint; /// @notice Checkpoint of the reward per token accumulator on a per account basis. It represents @@ -152,16 +152,16 @@ contract UniStaker is INotifiableRewardReceiver, ReentrancyGuard, Multicall { /// beneficiary account. Total unclaimed rewards for an account are thus this value plus all /// rewards earned after this checkpoint was taken. This value is reset to zero when a beneficiary /// account claims their earned rewards. - mapping(address account => uint256 amount) public unclaimedRewardsCheckpoint; + mapping(address account => uint256 amount) public unclaimedRewardCheckpoint; - /// @notice Maps addresses to whether they are authorized to call `notifyRewardsAmount`. - mapping(address rewardsNotifier => bool) public isRewardsNotifier; + /// @notice Maps addresses to whether they are authorized to call `notifyRewardAmount`. + mapping(address rewardNotifier => bool) public isRewardNotifier; - /// @param _rewardsToken ERC20 token in which rewards will be denominated. + /// @param _rewardToken ERC20 token in which rewards will be denominated. /// @param _stakeToken Delegable governance token which users will stake to earn rewards. - /// @param _admin Address which will have permission to manage rewardsNotifiers. - constructor(IERC20 _rewardsToken, IERC20Delegates _stakeToken, address _admin) { - REWARDS_TOKEN = _rewardsToken; + /// @param _admin Address which will have permission to manage rewardNotifiers. + constructor(IERC20 _rewardToken, IERC20Delegates _stakeToken, address _admin) { + REWARD_TOKEN = _rewardToken; STAKE_TOKEN = _stakeToken; _setAdmin(_admin); } @@ -174,21 +174,21 @@ contract UniStaker is INotifiableRewardReceiver, ReentrancyGuard, Multicall { _setAdmin(_newAdmin); } - /// @notice Enables or disables a rewards notifier address. - /// @param _rewardsNotifier Address of the rewards notifier. - /// @param _isEnabled `true` to enable the `_rewardsNotifier`, or `false` to disable. + /// @notice Enables or disables a reward notifier address. + /// @param _rewardNotifier Address of the reward notifier. + /// @param _isEnabled `true` to enable the `_rewardNotifier`, or `false` to disable. /// @dev Caller must be the current admin. - function setRewardsNotifier(address _rewardsNotifier, bool _isEnabled) external { + function setRewardNotifier(address _rewardNotifier, bool _isEnabled) external { _revertIfNotAdmin(); - isRewardsNotifier[_rewardsNotifier] = _isEnabled; - emit RewardsNotifierSet(_rewardsNotifier, _isEnabled); + isRewardNotifier[_rewardNotifier] = _isEnabled; + emit RewardNotifierSet(_rewardNotifier, _isEnabled); } /// @notice Timestamp representing the last time at which rewards have been distributed, which is /// either the current timestamp (because rewards are still actively being streamed) or the time /// at which the reward duration ended (because all rewards to date have already been streamed). - function lastTimeRewardsDistributed() public view returns (uint256) { - if (rewardsEndTime <= block.timestamp) return rewardsEndTime; + function lastTimeRewardDistributed() public view returns (uint256) { + if (rewardEndTime <= block.timestamp) return rewardEndTime; else return block.timestamp; } @@ -199,15 +199,15 @@ contract UniStaker is INotifiableRewardReceiver, ReentrancyGuard, Multicall { if (totalStaked == 0) return rewardPerTokenAccumulatedCheckpoint; return rewardPerTokenAccumulatedCheckpoint - + (scaledRewardRate * (lastTimeRewardsDistributed() - lastCheckpointTime)) / totalStaked; + + (scaledRewardRate * (lastTimeRewardDistributed() - lastCheckpointTime)) / totalStaked; } /// @notice Live value of the unclaimed rewards earned by a given beneficiary account. It is the /// sum of the last checkpoint value of their unclaimed rewards with the live calculation of the /// rewards that have accumulated for this account in the interim. This value can only increase, /// until it is reset to zero once the beneficiary account claims their unearned rewards. - function unclaimedRewards(address _beneficiary) public view returns (uint256) { - return unclaimedRewardsCheckpoint[_beneficiary] + function unclaimedReward(address _beneficiary) public view returns (uint256) { + return unclaimedRewardCheckpoint[_beneficiary] + ( earningPower[_beneficiary] * (rewardPerTokenAccumulated() - beneficiaryRewardPerTokenCheckpoint[_beneficiary]) @@ -255,8 +255,8 @@ contract UniStaker is INotifiableRewardReceiver, ReentrancyGuard, Multicall { Deposit storage deposit = deposits[_depositId]; _revertIfNotDepositOwner(deposit); - _checkpointGlobalRewards(); - _checkpointRewards(deposit.beneficiary); + _checkpointGlobalReward(); + _checkpointReward(deposit.beneficiary); DelegationSurrogate _surrogate = surrogates[deposit.delegatee]; _stakeTokenSafeTransferFrom(msg.sender, address(_surrogate), _amount); @@ -303,12 +303,12 @@ contract UniStaker is INotifiableRewardReceiver, ReentrancyGuard, Multicall { Deposit storage deposit = deposits[_depositId]; _revertIfNotDepositOwner(deposit); - _checkpointGlobalRewards(); + _checkpointGlobalReward(); - _checkpointRewards(deposit.beneficiary); + _checkpointReward(deposit.beneficiary); earningPower[deposit.beneficiary] -= deposit.balance; - _checkpointRewards(_newBeneficiary); + _checkpointReward(_newBeneficiary); emit BeneficiaryAltered(_depositId, deposit.beneficiary, _newBeneficiary); deposit.beneficiary = _newBeneficiary; earningPower[_newBeneficiary] += deposit.balance; @@ -323,8 +323,8 @@ contract UniStaker is INotifiableRewardReceiver, ReentrancyGuard, Multicall { Deposit storage deposit = deposits[_depositId]; _revertIfNotDepositOwner(deposit); - _checkpointGlobalRewards(); - _checkpointRewards(deposit.beneficiary); + _checkpointGlobalReward(); + _checkpointReward(deposit.beneficiary); deposit.balance -= _amount; // overflow prevents withdrawing more than balance totalStaked -= _amount; @@ -337,41 +337,41 @@ contract UniStaker is INotifiableRewardReceiver, ReentrancyGuard, Multicall { /// @notice Claim reward tokens the message sender has earned as a stake beneficiary. Tokens are /// sent to the message sender. function claimReward() external nonReentrant { - _checkpointGlobalRewards(); - _checkpointRewards(msg.sender); + _checkpointGlobalReward(); + _checkpointReward(msg.sender); - uint256 _rewards = unclaimedRewardsCheckpoint[msg.sender]; - if (_rewards == 0) return; - unclaimedRewardsCheckpoint[msg.sender] = 0; - emit RewardClaimed(msg.sender, _rewards); + uint256 _reward = unclaimedRewardCheckpoint[msg.sender]; + if (_reward == 0) return; + unclaimedRewardCheckpoint[msg.sender] = 0; + emit RewardClaimed(msg.sender, _reward); - SafeERC20.safeTransfer(REWARDS_TOKEN, msg.sender, _rewards); + SafeERC20.safeTransfer(REWARD_TOKEN, msg.sender, _reward); } /// @notice Called by an authorized rewards notifier to alert the staking contract that a new /// reward has been transferred to it. Note the reward must already have been transferred to this /// staking contract before the rewards notifier calls this method. /// @param _amount Quantity of reward tokens the staking contract is being notified of. - function notifyRewardsAmount(uint256 _amount) external { - if (!isRewardsNotifier[msg.sender]) revert UniStaker__Unauthorized("not notifier", msg.sender); + function notifyRewardAmount(uint256 _amount) external { + if (!isRewardNotifier[msg.sender]) revert UniStaker__Unauthorized("not notifier", msg.sender); // We checkpoint the accumulator without updating the timestamp at which it was updated, because // that second operation will be done at the end of the method. rewardPerTokenAccumulatedCheckpoint = rewardPerTokenAccumulated(); - if (block.timestamp >= rewardsEndTime) { + if (block.timestamp >= rewardEndTime) { scaledRewardRate = (_amount * SCALE_FACTOR) / REWARD_DURATION; } else { - uint256 remainingRewards = scaledRewardRate * (rewardsEndTime - block.timestamp); - scaledRewardRate = (remainingRewards + _amount * SCALE_FACTOR) / REWARD_DURATION; + uint256 _remainingReward = scaledRewardRate * (rewardEndTime - block.timestamp); + scaledRewardRate = (_remainingReward + _amount * SCALE_FACTOR) / REWARD_DURATION; } if ((scaledRewardRate / SCALE_FACTOR) == 0) revert UniStaker__InvalidRewardRate(); if ( - (scaledRewardRate * REWARD_DURATION) > (REWARDS_TOKEN.balanceOf(address(this)) * SCALE_FACTOR) + (scaledRewardRate * REWARD_DURATION) > (REWARD_TOKEN.balanceOf(address(this)) * SCALE_FACTOR) ) revert UniStaker__InsufficientRewardBalance(); - rewardsEndTime = block.timestamp + REWARD_DURATION; + rewardEndTime = block.timestamp + REWARD_DURATION; lastCheckpointTime = block.timestamp; emit RewardNotified(_amount, msg.sender); } @@ -419,8 +419,8 @@ contract UniStaker is INotifiableRewardReceiver, ReentrancyGuard, Multicall { _revertIfAddressZero(_delegatee); _revertIfAddressZero(_beneficiary); - _checkpointGlobalRewards(); - _checkpointRewards(_beneficiary); + _checkpointGlobalReward(); + _checkpointReward(_beneficiary); DelegationSurrogate _surrogate = _fetchOrDeploySurrogate(_delegatee); _stakeTokenSafeTransferFrom(msg.sender, address(_surrogate), _amount); @@ -441,9 +441,9 @@ contract UniStaker is INotifiableRewardReceiver, ReentrancyGuard, Multicall { } /// @notice Checkpoints the global reward per token accumulator. - function _checkpointGlobalRewards() internal { + function _checkpointGlobalReward() internal { rewardPerTokenAccumulatedCheckpoint = rewardPerTokenAccumulated(); - lastCheckpointTime = lastTimeRewardsDistributed(); + lastCheckpointTime = lastTimeRewardDistributed(); } /// @notice Checkpoints the unclaimed rewards and reward per token accumulator of a given @@ -452,8 +452,8 @@ contract UniStaker is INotifiableRewardReceiver, ReentrancyGuard, Multicall { /// @dev This is a sensitive internal helper method that must only be called after global rewards /// accumulator has been checkpointed. It assumes the global `rewardPerTokenCheckpoint` is up to /// date. - function _checkpointRewards(address _beneficiary) internal { - unclaimedRewardsCheckpoint[_beneficiary] = unclaimedRewards(_beneficiary); + function _checkpointReward(address _beneficiary) internal { + unclaimedRewardCheckpoint[_beneficiary] = unclaimedReward(_beneficiary); beneficiaryRewardPerTokenCheckpoint[_beneficiary] = rewardPerTokenAccumulatedCheckpoint; } diff --git a/src/V3FactoryOwner.sol b/src/V3FactoryOwner.sol index 0d5f397..84e0554 100644 --- a/src/V3FactoryOwner.sol +++ b/src/V3FactoryOwner.sol @@ -19,7 +19,7 @@ import {SafeERC20} from "openzeppelin/token/ERC20/utils/SafeERC20.sol"; /// collect protocol fees from a pool. This method is instead exposed publicly by this contract's /// `claimFees` method. That method collects fees from the protocol as long as the caller pays for /// them with a transfer of a designated amount of a designated token. That payout is forwarded -/// to a rewards receiver. +/// to a reward receiver. /// /// In the context of the broader system, it is expected that this contract's REWARD_RECEIVER is /// a deployment of the `UniStaker` contract. It is expected the admin of this contract will be the @@ -164,7 +164,7 @@ contract V3FactoryOwner { uint128 _amount1Requested ) external returns (uint128, uint128) { PAYOUT_TOKEN.safeTransferFrom(msg.sender, address(REWARD_RECEIVER), PAYOUT_AMOUNT); - REWARD_RECEIVER.notifyRewardsAmount(PAYOUT_AMOUNT); + REWARD_RECEIVER.notifyRewardAmount(PAYOUT_AMOUNT); (uint128 _amount0, uint128 _amount1) = _pool.collectProtocol(_recipient, _amount0Requested, _amount1Requested); diff --git a/src/interfaces/INotifiableRewardReceiver.sol b/src/interfaces/INotifiableRewardReceiver.sol index 8b6fcfe..b132311 100644 --- a/src/interfaces/INotifiableRewardReceiver.sol +++ b/src/interfaces/INotifiableRewardReceiver.sol @@ -10,5 +10,5 @@ pragma solidity ^0.8.23; interface INotifiableRewardReceiver { /// @notice Method called to notify a reward receiver it has received a reward. /// @param _amount The amount of reward. - function notifyRewardsAmount(uint256 _amount) external; + function notifyRewardAmount(uint256 _amount) external; } diff --git a/test/UniStaker.integration.t.sol b/test/UniStaker.integration.t.sol index 2063120..83d9121 100644 --- a/test/UniStaker.integration.t.sol +++ b/test/UniStaker.integration.t.sol @@ -24,9 +24,9 @@ contract DeployScriptTest is Test, DeployInput { assertEq(v3FactoryOwner.PAYOUT_AMOUNT(), PAYOUT_AMOUNT); assertEq(address(v3FactoryOwner.REWARD_RECEIVER()), address(uniStaker)); - assertEq(address(uniStaker.REWARDS_TOKEN()), PAYOUT_TOKEN_ADDRESS); + assertEq(address(uniStaker.REWARD_TOKEN()), PAYOUT_TOKEN_ADDRESS); assertEq(address(uniStaker.STAKE_TOKEN()), STAKE_TOKEN_ADDRESS); assertEq(uniStaker.admin(), UNISWAP_GOVERNOR_TIMELOCK); - assertTrue(uniStaker.isRewardsNotifier(address(v3FactoryOwner))); + assertTrue(uniStaker.isRewardNotifier(address(v3FactoryOwner))); } } diff --git a/test/UniStaker.t.sol b/test/UniStaker.t.sol index b0e32b6..1220b1b 100644 --- a/test/UniStaker.t.sol +++ b/test/UniStaker.t.sol @@ -11,11 +11,11 @@ contract UniStakerTest is Test { ERC20Fake rewardToken; ERC20VotesMock govToken; address admin; - address rewardsNotifier; + address rewardNotifier; UniStakerHarness uniStaker; uint256 SCALE_FACTOR; - event RewardsNotifierSet(address indexed account, bool isEnabled); + event RewardNotifierSet(address indexed account, bool isEnabled); event AdminSet(address indexed oldAdmin, address indexed newAdmin); function setUp() public { @@ -24,13 +24,13 @@ contract UniStakerTest is Test { _jumpAhead(1234); rewardToken = new ERC20Fake(); - vm.label(address(rewardToken), "Rewards Token"); + vm.label(address(rewardToken), "Reward Token"); govToken = new ERC20VotesMock(); vm.label(address(govToken), "Governance Token"); - rewardsNotifier = address(0xaffab1ebeef); - vm.label(rewardsNotifier, "Rewards Notifier"); + rewardNotifier = address(0xaffab1ebeef); + vm.label(rewardNotifier, "Reward Notifier"); admin = makeAddr("admin"); @@ -38,7 +38,7 @@ contract UniStakerTest is Test { vm.label(address(uniStaker), "UniStaker"); vm.prank(admin); - uniStaker.setRewardsNotifier(rewardsNotifier, true); + uniStaker.setRewardNotifier(rewardNotifier, true); // Convenience for use in tests SCALE_FACTOR = uniStaker.SCALE_FACTOR(); @@ -131,21 +131,20 @@ contract UniStakerTest is Test { } contract Constructor is UniStakerTest { - function test_SetsTheRewardTokenStakeTokenAndRewardsNotifier() public { - assertEq(address(uniStaker.REWARDS_TOKEN()), address(rewardToken)); + function test_SetsTheRewardTokenStakeTokenAndRewardNotifier() public { + assertEq(address(uniStaker.REWARD_TOKEN()), address(rewardToken)); assertEq(address(uniStaker.STAKE_TOKEN()), address(govToken)); assertEq(uniStaker.admin(), admin); } - function testFuzz_SetsTheRewardsTokenStakeTokenAndOwnerToArbitraryAddresses( - address _rewardsToken, + function testFuzz_SetsTheRewardTokenStakeTokenAndOwnerToArbitraryAddresses( + address _rewardToken, address _stakeToken, address _admin ) public { vm.assume(_admin != address(0)); - UniStaker _uniStaker = - new UniStaker(IERC20(_rewardsToken), IERC20Delegates(_stakeToken), _admin); - assertEq(address(_uniStaker.REWARDS_TOKEN()), address(_rewardsToken)); + UniStaker _uniStaker = new UniStaker(IERC20(_rewardToken), IERC20Delegates(_stakeToken), _admin); + assertEq(address(_uniStaker.REWARD_TOKEN()), address(_rewardToken)); assertEq(address(_uniStaker.STAKE_TOKEN()), address(_stakeToken)); assertEq(_uniStaker.admin(), _admin); } @@ -1413,35 +1412,33 @@ contract Withdraw is UniStakerTest { } } -contract SetRewardsNotifier is UniStakerTest { - function testFuzz_AllowsAdminToSetRewardsNotifier(address _rewardsNotifier, bool _isEnabled) - public - { +contract SetRewardNotifier is UniStakerTest { + function testFuzz_AllowsAdminToSetRewardNotifier(address _rewardNotifier, bool _isEnabled) public { vm.prank(admin); - uniStaker.setRewardsNotifier(_rewardsNotifier, _isEnabled); + uniStaker.setRewardNotifier(_rewardNotifier, _isEnabled); - assertEq(uniStaker.isRewardsNotifier(_rewardsNotifier), _isEnabled); + assertEq(uniStaker.isRewardNotifier(_rewardNotifier), _isEnabled); } - function test_AllowsTheAdminToDisableAnActiveRewardsNotifier() public { + function test_AllowsTheAdminToDisableAnActiveRewardNotifier() public { vm.prank(admin); - uniStaker.setRewardsNotifier(rewardsNotifier, false); + uniStaker.setRewardNotifier(rewardNotifier, false); - assertFalse(uniStaker.isRewardsNotifier(rewardsNotifier)); + assertFalse(uniStaker.isRewardNotifier(rewardNotifier)); } - function testFuzz_EmitsEventWhenRewardsNotifierIsSet(address _rewardsNotifier, bool _isEnabled) + function testFuzz_EmitsEventWhenRewardNotifierIsSet(address _rewardNotifier, bool _isEnabled) public { vm.expectEmit(); - emit RewardsNotifierSet(_rewardsNotifier, _isEnabled); + emit RewardNotifierSet(_rewardNotifier, _isEnabled); vm.prank(admin); - uniStaker.setRewardsNotifier(_rewardsNotifier, _isEnabled); + uniStaker.setRewardNotifier(_rewardNotifier, _isEnabled); } function testFuzz_RevertIf_TheCallerIsNotTheAdmin( address _notAdmin, - address _newRewardsNotifier, + address _newRewardNotifier, bool _isEnabled ) public { vm.assume(_notAdmin != uniStaker.admin()); @@ -1452,7 +1449,7 @@ contract SetRewardsNotifier is UniStakerTest { UniStaker.UniStaker__Unauthorized.selector, bytes32("not admin"), _notAdmin ) ); - uniStaker.setRewardsNotifier(_newRewardsNotifier, _isEnabled); + uniStaker.setRewardNotifier(_newRewardNotifier, _isEnabled); } } @@ -1555,8 +1552,8 @@ contract UniStakerRewardsTest is UniStakerTest { console2.log(rewardToken.balanceOf(address(uniStaker))); console2.log("rewardDuration"); console2.log(uniStaker.REWARD_DURATION()); - console2.log("rewardsEndTime"); - console2.log(uniStaker.rewardsEndTime()); + console2.log("rewardEndTime"); + console2.log(uniStaker.rewardEndTime()); console2.log("lastCheckpointTime"); console2.log(uniStaker.lastCheckpointTime()); console2.log("totalStake"); @@ -1567,8 +1564,8 @@ contract UniStakerRewardsTest is UniStakerTest { console2.log(block.timestamp); console2.log("rewardPerTokenAccumulatedCheckpoint"); console2.log(uniStaker.rewardPerTokenAccumulatedCheckpoint()); - console2.log("lastTimeRewardsDistributed()"); - console2.log(uniStaker.lastTimeRewardsDistributed()); + console2.log("lastTimeRewardDistributed()"); + console2.log(uniStaker.lastTimeRewardDistributed()); console2.log("rewardPerTokenAccumulated()"); console2.log(uniStaker.rewardPerTokenAccumulated()); console2.log("-----------------------------------------------"); @@ -1579,10 +1576,10 @@ contract UniStakerRewardsTest is UniStakerTest { console2.log(uniStaker.earningPower(_depositor)); console2.log("beneficiaryRewardPerTokenCheckpoint[_depositor]"); console2.log(uniStaker.beneficiaryRewardPerTokenCheckpoint(_depositor)); - console2.log("unclaimedRewardsCheckpoint[_depositor]"); - console2.log(uniStaker.unclaimedRewardsCheckpoint(_depositor)); - console2.log("unclaimedRewards(_depositor)"); - console2.log(uniStaker.unclaimedRewards(_depositor)); + console2.log("unclaimedRewardCheckpoint[_depositor]"); + console2.log(uniStaker.unclaimedRewardCheckpoint(_depositor)); + console2.log("unclaimedReward(_depositor)"); + console2.log(uniStaker.unclaimedReward(_depositor)); console2.log("-----------------------------------------------"); } @@ -1609,26 +1606,26 @@ contract UniStakerRewardsTest is UniStakerTest { } function _mintTransferAndNotifyReward(uint256 _amount) public { - rewardToken.mint(rewardsNotifier, _amount); + rewardToken.mint(rewardNotifier, _amount); - vm.startPrank(rewardsNotifier); + vm.startPrank(rewardNotifier); rewardToken.transfer(address(uniStaker), _amount); - uniStaker.notifyRewardsAmount(_amount); + uniStaker.notifyRewardAmount(_amount); vm.stopPrank(); } - function _mintTransferAndNotifyReward(address _rewardsNotifier, uint256 _amount) public { - vm.assume(_rewardsNotifier != address(0)); - rewardToken.mint(_rewardsNotifier, _amount); + function _mintTransferAndNotifyReward(address _rewardNotifier, uint256 _amount) public { + vm.assume(_rewardNotifier != address(0)); + rewardToken.mint(_rewardNotifier, _amount); - vm.startPrank(_rewardsNotifier); + vm.startPrank(_rewardNotifier); rewardToken.transfer(address(uniStaker), _amount); - uniStaker.notifyRewardsAmount(_amount); + uniStaker.notifyRewardAmount(_amount); vm.stopPrank(); } } -contract NotifyRewardsAmount is UniStakerRewardsTest { +contract NotifyRewardAmount is UniStakerRewardsTest { function testFuzz_UpdatesTheRewardRate(uint256 _amount) public { _amount = _boundToRealisticReward(_amount); _mintTransferAndNotifyReward(_amount); @@ -1660,7 +1657,7 @@ contract NotifyRewardsAmount is UniStakerRewardsTest { uint256 _expectedFinishTimestamp = _futureTimestamp + uniStaker.REWARD_DURATION(); assertEq(uniStaker.lastCheckpointTime(), _futureTimestamp); - assertEq(uniStaker.rewardsEndTime(), _expectedFinishTimestamp); + assertEq(uniStaker.rewardEndTime(), _expectedFinishTimestamp); } function testFuzz_UpdatesTheCheckpointedRewardPerTokenAccumulator( @@ -1694,32 +1691,32 @@ contract NotifyRewardsAmount is UniStakerRewardsTest { assertEq(uniStaker.rewardPerTokenAccumulatedCheckpoint(), uniStaker.rewardPerTokenAccumulated()); } - function testFuzz_AllowsMultipleApprovedRewardsNotifiersToNotifyOfRewards( + function testFuzz_AllowsMultipleApprovedRewardNotifiersToNotifyOfRewards( uint256 _amount1, uint256 _amount2, uint256 _amount3, - address _rewardsNotifier1, - address _rewardsNotifier2, - address _rewardsNotifier3 + address _rewardNotifier1, + address _rewardNotifier2, + address _rewardNotifier3 ) public { _amount1 = _boundToRealisticReward(_amount1); _amount2 = _boundToRealisticReward(_amount2); _amount3 = _boundToRealisticReward(_amount3); vm.startPrank(admin); - uniStaker.setRewardsNotifier(_rewardsNotifier1, true); - uniStaker.setRewardsNotifier(_rewardsNotifier2, true); - uniStaker.setRewardsNotifier(_rewardsNotifier3, true); + uniStaker.setRewardNotifier(_rewardNotifier1, true); + uniStaker.setRewardNotifier(_rewardNotifier2, true); + uniStaker.setRewardNotifier(_rewardNotifier3, true); vm.stopPrank(); // The first notifier notifies - _mintTransferAndNotifyReward(_rewardsNotifier1, _amount1); + _mintTransferAndNotifyReward(_rewardNotifier1, _amount1); // The second notifier notifies - _mintTransferAndNotifyReward(_rewardsNotifier2, _amount2); + _mintTransferAndNotifyReward(_rewardNotifier2, _amount2); // The third notifier notifies - _mintTransferAndNotifyReward(_rewardsNotifier3, _amount3); + _mintTransferAndNotifyReward(_rewardNotifier3, _amount3); uint256 _expectedRewardRate = (SCALE_FACTOR * (_amount1 + _amount2 + _amount3)) / uniStaker.REWARD_DURATION(); // because we summed 3 amounts, the rounding error can be as much as 2 units @@ -1729,22 +1726,22 @@ contract NotifyRewardsAmount is UniStakerRewardsTest { function testFuzz_EmitsAnEventWhenRewardsAreNotified(uint256 _amount) public { _amount = _boundToRealisticReward(_amount); - rewardToken.mint(rewardsNotifier, _amount); + rewardToken.mint(rewardNotifier, _amount); - vm.startPrank(rewardsNotifier); + vm.startPrank(rewardNotifier); rewardToken.transfer(address(uniStaker), _amount); vm.expectEmit(); - emit UniStaker.RewardNotified(_amount, rewardsNotifier); + emit UniStaker.RewardNotified(_amount, rewardNotifier); - uniStaker.notifyRewardsAmount(_amount); + uniStaker.notifyRewardAmount(_amount); vm.stopPrank(); } - function testFuzz_RevertIf_CallerIsNotTheRewardsNotifier(uint256 _amount, address _notNotifier) + function testFuzz_RevertIf_CallerIsNotTheRewardNotifier(uint256 _amount, address _notNotifier) public { - vm.assume(!uniStaker.isRewardsNotifier(_notNotifier) && _notNotifier != address(0)); + vm.assume(!uniStaker.isRewardNotifier(_notNotifier) && _notNotifier != address(0)); _amount = _boundToRealisticReward(_amount); rewardToken.mint(_notNotifier, _amount); @@ -1756,19 +1753,19 @@ contract NotifyRewardsAmount is UniStakerRewardsTest { UniStaker.UniStaker__Unauthorized.selector, bytes32("not notifier"), _notNotifier ) ); - uniStaker.notifyRewardsAmount(_amount); + uniStaker.notifyRewardAmount(_amount); vm.stopPrank(); } function testFuzz_RevertIf_RewardAmountIsTooSmall(uint256 _amount) public { // If the amount is less than the rewards duration the reward rate will be truncated to 0 _amount = bound(_amount, 0, uniStaker.REWARD_DURATION() - 1); - rewardToken.mint(rewardsNotifier, _amount); + rewardToken.mint(rewardNotifier, _amount); - vm.startPrank(rewardsNotifier); + vm.startPrank(rewardNotifier); rewardToken.transfer(address(uniStaker), _amount); vm.expectRevert(UniStaker.UniStaker__InvalidRewardRate.selector); - uniStaker.notifyRewardsAmount(_amount); + uniStaker.notifyRewardAmount(_amount); vm.stopPrank(); } @@ -1783,21 +1780,21 @@ contract NotifyRewardsAmount is UniStakerRewardsTest { _transferPercent = _bound(_transferPercent, 1, 99); uint256 _transferAmount = _percentOf(_amount, _transferPercent); - rewardToken.mint(rewardsNotifier, _amount); + rewardToken.mint(rewardNotifier, _amount); - vm.startPrank(rewardsNotifier); + vm.startPrank(rewardNotifier); // Something less than the supposed reward is sent rewardToken.transfer(address(uniStaker), _transferAmount); // The reward notification should revert because the contract doesn't have enough tokens vm.expectRevert(UniStaker.UniStaker__InsufficientRewardBalance.selector); - uniStaker.notifyRewardsAmount(_amount); + uniStaker.notifyRewardAmount(_amount); vm.stopPrank(); } } -contract LastTimeRewardsDistributed is UniStakerRewardsTest { +contract LastTimeRewardDistributed is UniStakerRewardsTest { function test_ReturnsZeroBeforeARewardNotificationHasOccurred() public { - assertEq(uniStaker.lastTimeRewardsDistributed(), 0); + assertEq(uniStaker.lastTimeRewardDistributed(), 0); } function testFuzz_ReturnsTheBlockTimestampAfterARewardNotificationButBeforeTheRewardDurationElapses( @@ -1810,7 +1807,7 @@ contract LastTimeRewardsDistributed is UniStakerRewardsTest { _durationPercent = bound(_durationPercent, 0, 100); _jumpAheadByPercentOfRewardDuration(_durationPercent); - assertEq(uniStaker.lastTimeRewardsDistributed(), block.timestamp); + assertEq(uniStaker.lastTimeRewardDistributed(), block.timestamp); } function testFuzz_ReturnsTheEndOfTheRewardDurationIfItHasFullyElapsed( @@ -1825,7 +1822,7 @@ contract LastTimeRewardsDistributed is UniStakerRewardsTest { _durationPercent = bound(_durationPercent, 101, 1000); _jumpAheadByPercentOfRewardDuration(_durationPercent); - assertEq(uniStaker.lastTimeRewardsDistributed(), _durationEnd); + assertEq(uniStaker.lastTimeRewardDistributed(), _durationEnd); } function testFuzz_ReturnsTheBlockTimestampWhileWithinTheDurationOfASecondReward( @@ -1848,7 +1845,7 @@ contract LastTimeRewardsDistributed is UniStakerRewardsTest { _durationPercent2 = bound(_durationPercent2, 0, 100); _jumpAheadByPercentOfRewardDuration(_durationPercent2); - assertEq(uniStaker.lastTimeRewardsDistributed(), block.timestamp); + assertEq(uniStaker.lastTimeRewardDistributed(), block.timestamp); } function testFuzz_ReturnsTheEndOfTheSecondRewardDurationAfterTwoRewards( @@ -1872,7 +1869,7 @@ contract LastTimeRewardsDistributed is UniStakerRewardsTest { _durationPercent2 = bound(_durationPercent2, 101, 1000); _jumpAheadByPercentOfRewardDuration(_durationPercent2); - assertEq(uniStaker.lastTimeRewardsDistributed(), _durationEnd); + assertEq(uniStaker.lastTimeRewardDistributed(), _durationEnd); } } @@ -2283,7 +2280,7 @@ contract RewardPerTokenAccumulated is UniStakerRewardsTest { } } -contract UnclaimedRewards is UniStakerRewardsTest { +contract UnclaimedReward is UniStakerRewardsTest { function testFuzz_CalculatesCorrectEarningsForASingleDepositorThatStakesForFullDuration( address _depositor, address _delegatee, @@ -2300,7 +2297,7 @@ contract UnclaimedRewards is UniStakerRewardsTest { _jumpAheadByPercentOfRewardDuration(101); // The user should have earned all the rewards - assertLteWithinOnePercent(uniStaker.unclaimedRewards(_depositor), _rewardAmount); + assertLteWithinOnePercent(uniStaker.unclaimedReward(_depositor), _rewardAmount); } function testFuzz_CalculatesCorrectEarningsWhenASingleDepositorAssignsABeneficiaryAndStakesForFullDuration( @@ -2320,7 +2317,7 @@ contract UnclaimedRewards is UniStakerRewardsTest { _jumpAheadByPercentOfRewardDuration(101); // The beneficiary should have earned all the rewards - assertLteWithinOnePercent(uniStaker.unclaimedRewards(_beneficiary), _rewardAmount); + assertLteWithinOnePercent(uniStaker.unclaimedReward(_beneficiary), _rewardAmount); } function testFuzz_CalculatesCorrectEarningsWhenASingleDepositorUpdatesTheirBeneficiary( @@ -2354,10 +2351,10 @@ contract UnclaimedRewards is UniStakerRewardsTest { // The beneficiary should have earned all the rewards assertLteWithinOnePercent( - uniStaker.unclaimedRewards(_beneficiary1), _percentOf(_rewardAmount, _percentDuration) + uniStaker.unclaimedReward(_beneficiary1), _percentOf(_rewardAmount, _percentDuration) ); assertLteWithinOnePercent( - uniStaker.unclaimedRewards(_beneficiary2), _percentOf(_rewardAmount, 100 - _percentDuration) + uniStaker.unclaimedReward(_beneficiary2), _percentOf(_rewardAmount, 100 - _percentDuration) ); } @@ -2380,7 +2377,7 @@ contract UnclaimedRewards is UniStakerRewardsTest { // The user should have earned one third of the rewards assertLteWithinOnePercent( - uniStaker.unclaimedRewards(_depositor), _percentOf(_rewardAmount, _durationPercent) + uniStaker.unclaimedReward(_depositor), _percentOf(_rewardAmount, _durationPercent) ); } @@ -2402,7 +2399,7 @@ contract UnclaimedRewards is UniStakerRewardsTest { _jumpAheadByPercentOfRewardDuration(34); // The user should have earned 1/3rd of the rewards - assertLteWithinOnePercent(uniStaker.unclaimedRewards(_depositor), _percentOf(_rewardAmount, 34)); + assertLteWithinOnePercent(uniStaker.unclaimedReward(_depositor), _percentOf(_rewardAmount, 34)); } function testFuzz_CalculatesCorrectEarningsForASingleUserStakeForPartialDurationWithABeneficiary( @@ -2428,7 +2425,7 @@ contract UnclaimedRewards is UniStakerRewardsTest { // The beneficiary should have earned a portion of the rewards equal to the amount of the // duration that has passed assertLteWithinOnePercent( - uniStaker.unclaimedRewards(_beneficiary), _percentOf(_rewardAmount, _durationPercent) + uniStaker.unclaimedReward(_beneficiary), _percentOf(_rewardAmount, _durationPercent) ); } @@ -2453,7 +2450,7 @@ contract UnclaimedRewards is UniStakerRewardsTest { // The beneficiary should have earned 1/3rd of the reward assertLteWithinOnePercent( - uniStaker.unclaimedRewards(_beneficiary), _percentOf(_rewardAmount, 34) + uniStaker.unclaimedReward(_beneficiary), _percentOf(_rewardAmount, 34) ); } @@ -2480,7 +2477,7 @@ contract UnclaimedRewards is UniStakerRewardsTest { _mintTransferAndNotifyReward(_rewardAmount); // The user should have earned all the rewards - assertLteWithinOnePercent(uniStaker.unclaimedRewards(_depositor), _rewardAmount); + assertLteWithinOnePercent(uniStaker.unclaimedReward(_depositor), _rewardAmount); } function testFuzz_CalculatesCorrectEarningsForASingleUserThatDepositsStakeForTheFullDurationWithDelayedReward( @@ -2508,7 +2505,7 @@ contract UnclaimedRewards is UniStakerRewardsTest { _jumpAheadByPercentOfRewardDuration(100); // The user should have earned all the rewards - assertLteWithinOnePercent(uniStaker.unclaimedRewards(_depositor), _rewardAmount * 2); + assertLteWithinOnePercent(uniStaker.unclaimedReward(_depositor), _rewardAmount * 2); } function testFuzz_CalculatesCorrectEarningsWhenASingleDepositorUpdatesTheirBeneficiaryWithNoNewRewards( @@ -2551,10 +2548,10 @@ contract UnclaimedRewards is UniStakerRewardsTest { // The beneficiaries should have earned all the rewards for the first duration assertLteWithinOnePercent( - uniStaker.unclaimedRewards(_beneficiary1), _percentOf(_rewardAmount, _percentDuration) + uniStaker.unclaimedReward(_beneficiary1), _percentOf(_rewardAmount, _percentDuration) ); assertLteWithinOnePercent( - uniStaker.unclaimedRewards(_beneficiary2), _percentOf(_rewardAmount, 100 - _percentDuration) + uniStaker.unclaimedReward(_beneficiary2), _percentOf(_rewardAmount, 100 - _percentDuration) ); } @@ -2585,14 +2582,14 @@ contract UnclaimedRewards is UniStakerRewardsTest { _mintTransferAndNotifyReward(_rewardAmount); _jumpAheadByPercentOfRewardDuration(_durationPercent); - uint256 balance = uniStaker.REWARDS_TOKEN().balanceOf(address(_depositor)); + uint256 balance = uniStaker.REWARD_TOKEN().balanceOf(address(_depositor)); // The depositors balance should reflect the first full duration assertLteWithinOnePercent(balance, _rewardAmount); // The depositor should have earned a portion of the rewards equal to the amount of the next // duration that has passed. assertLteWithinOnePercent( - uniStaker.unclaimedRewards(_depositor), _percentOf(_rewardAmount, _durationPercent) + uniStaker.unclaimedReward(_depositor), _percentOf(_rewardAmount, _durationPercent) ); } @@ -2622,14 +2619,14 @@ contract UnclaimedRewards is UniStakerRewardsTest { // We skip ahead to the end of the duration _jumpAheadByPercentOfRewardDuration(100 - _durationPercent); - uint256 balance = uniStaker.REWARDS_TOKEN().balanceOf(address(_depositor)); + uint256 balance = uniStaker.REWARD_TOKEN().balanceOf(address(_depositor)); // The depositors balance should match the portion of the duration that passed before the // rewards were claimed assertLteWithinOnePercent(balance, _percentOf(_rewardAmount, _durationPercent)); // The depositor earned the portion of the reward after the rewards were claimed assertLteWithinOnePercent( - uniStaker.unclaimedRewards(_depositor), _percentOf(_rewardAmount, 100 - _durationPercent) + uniStaker.unclaimedReward(_depositor), _percentOf(_rewardAmount, 100 - _durationPercent) ); } @@ -2655,12 +2652,8 @@ contract UnclaimedRewards is UniStakerRewardsTest { _jumpAheadByPercentOfRewardDuration(101); // Each user should have earned half of the rewards - assertLteWithinOnePercent( - uniStaker.unclaimedRewards(_depositor1), _percentOf(_rewardAmount, 50) - ); - assertLteWithinOnePercent( - uniStaker.unclaimedRewards(_depositor2), _percentOf(_rewardAmount, 50) - ); + assertLteWithinOnePercent(uniStaker.unclaimedReward(_depositor1), _percentOf(_rewardAmount, 50)); + assertLteWithinOnePercent(uniStaker.unclaimedReward(_depositor2), _percentOf(_rewardAmount, 50)); } function testFuzz_CalculatesCorrectEarningsForTwoUsersWhenOneStakesMorePartiallyThroughTheDuration( @@ -2703,8 +2696,8 @@ contract UnclaimedRewards is UniStakerRewardsTest { _percentOf(_percentOf(_rewardAmount, 50), 34) + _percentOf(_percentOf(_rewardAmount, 25), 66); // Each user should have earned half of the rewards - assertLteWithinOnePercent(uniStaker.unclaimedRewards(_depositor1), _depositor1ExpectedEarnings); - assertLteWithinOnePercent(uniStaker.unclaimedRewards(_depositor2), _depositor2ExpectedEarnings); + assertLteWithinOnePercent(uniStaker.unclaimedReward(_depositor1), _depositor1ExpectedEarnings); + assertLteWithinOnePercent(uniStaker.unclaimedReward(_depositor2), _depositor2ExpectedEarnings); } function testFuzz_CalculatesCorrectEarningsForTwoUsersThatDepositEqualStakeForFullDurationAndBothClaim( @@ -2737,16 +2730,16 @@ contract UnclaimedRewards is UniStakerRewardsTest { vm.prank(_depositor2); uniStaker.claimReward(); - uint256 depositor1Balance = uniStaker.REWARDS_TOKEN().balanceOf(address(_depositor1)); - uint256 depositor2Balance = uniStaker.REWARDS_TOKEN().balanceOf(address(_depositor2)); + uint256 depositor1Balance = uniStaker.REWARD_TOKEN().balanceOf(address(_depositor1)); + uint256 depositor2Balance = uniStaker.REWARD_TOKEN().balanceOf(address(_depositor2)); // Each depositors balance should be half of the reward assertLteWithinOnePercent(depositor1Balance, _percentOf(_rewardAmount, 50)); assertLteWithinOnePercent(depositor2Balance, _percentOf(_rewardAmount, 50)); // Each user should have earned nothing since they both claimed their rewards - assertLteWithinOnePercent(uniStaker.unclaimedRewards(_depositor1), 0); - assertLteWithinOnePercent(uniStaker.unclaimedRewards(_depositor2), 0); + assertLteWithinOnePercent(uniStaker.unclaimedReward(_depositor1), 0); + assertLteWithinOnePercent(uniStaker.unclaimedReward(_depositor2), 0); } function testFuzz_CalculatesCorrectEarningsForTwoUsersWhenOneStakesMorePartiallyThroughTheDurationAndOneClaims( @@ -2790,11 +2783,11 @@ contract UnclaimedRewards is UniStakerRewardsTest { uint256 _depositor2ExpectedEarnings = _percentOf(_percentOf(_rewardAmount, 50), 34) + _percentOf(_percentOf(_rewardAmount, 25), 66); - uint256 depositor1Balance = uniStaker.REWARDS_TOKEN().balanceOf(address(_depositor1)); - uint256 depositor2Balance = uniStaker.REWARDS_TOKEN().balanceOf(address(_depositor2)); + uint256 depositor1Balance = uniStaker.REWARD_TOKEN().balanceOf(address(_depositor1)); + uint256 depositor2Balance = uniStaker.REWARD_TOKEN().balanceOf(address(_depositor2)); - assertLteWithinOnePercent(uniStaker.unclaimedRewards(_depositor1), _depositor1ExpectedEarnings); - assertLteWithinOnePercent(uniStaker.unclaimedRewards(_depositor2), _depositor2ExpectedEarnings); + assertLteWithinOnePercent(uniStaker.unclaimedReward(_depositor1), _depositor1ExpectedEarnings); + assertLteWithinOnePercent(uniStaker.unclaimedReward(_depositor2), _depositor2ExpectedEarnings); // Depositor 1 should have received the reward they earned from before they claimed assertLteWithinOnePercent(depositor1Balance, _percentOf(_percentOf(_rewardAmount, 50), 34)); @@ -2838,14 +2831,10 @@ contract UnclaimedRewards is UniStakerRewardsTest { _jumpAheadByPercentOfRewardDuration(101); // The first depositor has earn 3/4 of the and depositor 2 should earn a quarter of the reward - assertLteWithinOnePercent( - uniStaker.unclaimedRewards(_depositor1), _percentOf(_rewardAmount, 75) - ); - assertLteWithinOnePercent( - uniStaker.unclaimedRewards(_depositor2), _percentOf(_rewardAmount, 25) - ); - assertLteWithinOnePercent(uniStaker.unclaimedRewards(_depositor3), 0); - assertLteWithinOnePercent(uniStaker.unclaimedRewards(_depositor4), 0); + assertLteWithinOnePercent(uniStaker.unclaimedReward(_depositor1), _percentOf(_rewardAmount, 75)); + assertLteWithinOnePercent(uniStaker.unclaimedReward(_depositor2), _percentOf(_rewardAmount, 25)); + assertLteWithinOnePercent(uniStaker.unclaimedReward(_depositor3), 0); + assertLteWithinOnePercent(uniStaker.unclaimedReward(_depositor4), 0); } function testFuzz_CalculatesCorrectEarningsForFourUsersWhenOneStakesMorePartiallyThroughTheDurationAndTwoBeneficiaries( @@ -2906,10 +2895,10 @@ contract UnclaimedRewards is UniStakerRewardsTest { // The third and fourth depositor earn nothing because they are sending their rewards to a // beneficiary - assertLteWithinOnePercent(uniStaker.unclaimedRewards(_depositor1), _depositor1ExpectedEarnings); - assertLteWithinOnePercent(uniStaker.unclaimedRewards(_depositor2), _depositor2ExpectedEarnings); - assertLteWithinOnePercent(uniStaker.unclaimedRewards(_depositor3), 0); - assertLteWithinOnePercent(uniStaker.unclaimedRewards(_depositor4), 0); + assertLteWithinOnePercent(uniStaker.unclaimedReward(_depositor1), _depositor1ExpectedEarnings); + assertLteWithinOnePercent(uniStaker.unclaimedReward(_depositor2), _depositor2ExpectedEarnings); + assertLteWithinOnePercent(uniStaker.unclaimedReward(_depositor3), 0); + assertLteWithinOnePercent(uniStaker.unclaimedReward(_depositor4), 0); } function testFuzz_CalculatesCorrectEarningsForFourUsersWhenTwoStakeMorePartiallyThroughTheDurationAndOneBeneficiary( @@ -2983,25 +2972,25 @@ contract UnclaimedRewards is UniStakerRewardsTest { // quarter of the time uint256 _depositor1ExpectedEarnings = _percentOf(_percentOf(_rewardAmount, 25), 25) + _percentOf(_percentOf(_rewardAmount, 40), 75); - assertLteWithinOnePercent(uniStaker.unclaimedRewards(_depositor1), _depositor1ExpectedEarnings); + assertLteWithinOnePercent(uniStaker.unclaimedReward(_depositor1), _depositor1ExpectedEarnings); // Depositor 2 earns a quarter of the reward for one quarter of the time, a fifth of the // reward one quarter of the time, and 40 percent of the reward half the time uint256 _depositor2ExpectedEarnings = _percentOf(_percentOf(_rewardAmount, 25), 25) + _percentOf(_percentOf(_rewardAmount, 20), 25) + _percentOf(_percentOf(_rewardAmount, 40), 50); - assertLteWithinOnePercent(uniStaker.unclaimedRewards(_depositor2), _depositor2ExpectedEarnings); + assertLteWithinOnePercent(uniStaker.unclaimedReward(_depositor2), _depositor2ExpectedEarnings); // Depositor 3 earns 25% of the reward for a quarter of the time, 20% of the reward a quarter of // the time and no reward half the time. uint256 _depositor3ExpectedEarnings = _percentOf(_percentOf(_rewardAmount, 25), 25) + _percentOf(_percentOf(_rewardAmount, 20), 25); - assertLteWithinOnePercent(uniStaker.unclaimedRewards(_depositor3), _depositor3ExpectedEarnings); + assertLteWithinOnePercent(uniStaker.unclaimedReward(_depositor3), _depositor3ExpectedEarnings); // Depositor 4 earns 25% of the reward for a quarter of the time, 20% of the reward 3 quarters // of the time. uint256 _depositor4ExpectedEarnings = _percentOf(_percentOf(_rewardAmount, 25), 25) + _percentOf(_percentOf(_rewardAmount, 20), 75); - assertLteWithinOnePercent(uniStaker.unclaimedRewards(_depositor4), _depositor4ExpectedEarnings); + assertLteWithinOnePercent(uniStaker.unclaimedReward(_depositor4), _depositor4ExpectedEarnings); } function testFuzz_CalculatesCorrectEarningsWhenAUserStakesThroughTheDurationAndAnotherStakesPartially( @@ -3034,8 +3023,8 @@ contract UnclaimedRewards is UniStakerRewardsTest { // Depositor 2 earns 1/2 the rewards for 1/3rd of the duration time uint256 _depositor2ExpectedEarnings = _percentOf(_percentOf(_rewardAmount, 50), 34); - assertLteWithinOnePercent(uniStaker.unclaimedRewards(_depositor1), _depositor1ExpectedEarnings); - assertLteWithinOnePercent(uniStaker.unclaimedRewards(_depositor2), _depositor2ExpectedEarnings); + assertLteWithinOnePercent(uniStaker.unclaimedReward(_depositor1), _depositor1ExpectedEarnings); + assertLteWithinOnePercent(uniStaker.unclaimedReward(_depositor2), _depositor2ExpectedEarnings); } function testFuzz_CalculatesCorrectEarningsWhenAUserDepositsAndThereAreTwoRewards( @@ -3066,7 +3055,7 @@ contract UnclaimedRewards is UniStakerRewardsTest { // reward plus the second reward. uint256 _depositorExpectedEarnings = _percentOf(_rewardAmount1, 66) + _percentOf(_percentOf(_rewardAmount1, 34) + _rewardAmount2, 34); - assertLteWithinOnePercent(uniStaker.unclaimedRewards(_depositor), _depositorExpectedEarnings); + assertLteWithinOnePercent(uniStaker.unclaimedReward(_depositor), _depositorExpectedEarnings); } function testFuzz_CalculatesCorrectEarningsWhenTwoUsersDepositForPartialDurationsAndThereAreTwoRewards( @@ -3114,8 +3103,8 @@ contract UnclaimedRewards is UniStakerRewardsTest { uint256 _depositor1ExpectedEarnings = _percentOf(_rewardAmount1, 40) + _depositor2ExpectedEarnings; - assertLteWithinOnePercent(uniStaker.unclaimedRewards(_depositor1), _depositor1ExpectedEarnings); - assertLteWithinOnePercent(uniStaker.unclaimedRewards(_depositor2), _depositor2ExpectedEarnings); + assertLteWithinOnePercent(uniStaker.unclaimedReward(_depositor1), _depositor1ExpectedEarnings); + assertLteWithinOnePercent(uniStaker.unclaimedReward(_depositor2), _depositor2ExpectedEarnings); } function testFuzz_CalculatesCorrectEarningsWhenTwoUsersDepositDifferentAmountsForPartialDurationsAndThereAreTwoRewards( @@ -3167,8 +3156,8 @@ contract UnclaimedRewards is UniStakerRewardsTest { uint256 _depositor1ExpectedEarnings = _percentOf(_rewardAmount1, 40) + (_stakeAmount1 * _combinedPhaseExpectedTotalRewards) / _combinedStake; - assertLteWithinOnePercent(uniStaker.unclaimedRewards(_depositor1), _depositor1ExpectedEarnings); - assertLteWithinOnePercent(uniStaker.unclaimedRewards(_depositor2), _depositor2ExpectedEarnings); + assertLteWithinOnePercent(uniStaker.unclaimedReward(_depositor1), _depositor1ExpectedEarnings); + assertLteWithinOnePercent(uniStaker.unclaimedReward(_depositor2), _depositor2ExpectedEarnings); } // Could potentially add duration @@ -3210,7 +3199,7 @@ contract UnclaimedRewards is UniStakerRewardsTest { + _percentOf( _percentOf(_percentOf(_rewardAmount1, 60) + _rewardAmount2, 70) + _rewardAmount3, 30 ); - assertLteWithinOnePercent(uniStaker.unclaimedRewards(_depositor), _depositorExpectedEarnings); + assertLteWithinOnePercent(uniStaker.unclaimedReward(_depositor), _depositorExpectedEarnings); } function testFuzz_CalculatesCorrectEarningsWhenTwoUsersDepositForPartialDurationsAndThereAreThreeRewards( @@ -3273,8 +3262,8 @@ contract UnclaimedRewards is UniStakerRewardsTest { uint256 _depositor1ExpectedEarnings = _percentOf(_rewardAmount1, 20) + _depositor2ExpectedEarnings; - assertLteWithinOnePercent(uniStaker.unclaimedRewards(_depositor1), _depositor1ExpectedEarnings); - assertLteWithinOnePercent(uniStaker.unclaimedRewards(_depositor2), _depositor2ExpectedEarnings); + assertLteWithinOnePercent(uniStaker.unclaimedReward(_depositor1), _depositor1ExpectedEarnings); + assertLteWithinOnePercent(uniStaker.unclaimedReward(_depositor2), _depositor2ExpectedEarnings); } function testFuzz_CalculatesCorrectEarningsWhenTwoUsersDepositDifferentAmountsForPartialDurationsAndThereAreThreeRewards( @@ -3336,8 +3325,8 @@ contract UnclaimedRewards is UniStakerRewardsTest { uint256 _depositor1ExpectedEarnings = _percentOf(_rewardAmount1, 20) + (_stakeAmount1 * _combinedPhaseExpectedTotalRewards) / _combinedStake; - assertLteWithinOnePercent(uniStaker.unclaimedRewards(_depositor1), _depositor1ExpectedEarnings); - assertLteWithinOnePercent(uniStaker.unclaimedRewards(_depositor2), _depositor2ExpectedEarnings); + assertLteWithinOnePercent(uniStaker.unclaimedReward(_depositor1), _depositor1ExpectedEarnings); + assertLteWithinOnePercent(uniStaker.unclaimedReward(_depositor2), _depositor2ExpectedEarnings); } function testFuzz_CalculatesEarningsThatAreLessThanOrEqualToRewardsReceived( @@ -3366,8 +3355,8 @@ contract UnclaimedRewards is UniStakerRewardsTest { // The rest of the duration elapses _jumpAheadByPercentOfRewardDuration(100 - _durationPercent); - uint256 _earned1 = uniStaker.unclaimedRewards(_depositor1); - uint256 _earned2 = uniStaker.unclaimedRewards(_depositor2); + uint256 _earned1 = uniStaker.unclaimedReward(_depositor1); + uint256 _earned2 = uniStaker.unclaimedReward(_depositor2); // Rewards earned by depositors should always at most equal to the actual reward amount assertLteWithinOnePercent(_earned1 + _earned2, _rewardAmount); @@ -3394,7 +3383,7 @@ contract ClaimReward is UniStakerRewardsTest { // A portion of the duration passes _jumpAheadByPercentOfRewardDuration(_durationPercent); - uint256 _earned = uniStaker.unclaimedRewards(_depositor); + uint256 _earned = uniStaker.unclaimedReward(_depositor); vm.prank(_depositor); uniStaker.claimReward(); @@ -3422,7 +3411,7 @@ contract ClaimReward is UniStakerRewardsTest { vm.prank(_depositor); uniStaker.claimReward(); - assertEq(uniStaker.unclaimedRewards(_depositor), 0); + assertEq(uniStaker.unclaimedReward(_depositor), 0); } function testFuzz_EmitsAnEventWhenRewardsAreClaimed( @@ -3442,7 +3431,7 @@ contract ClaimReward is UniStakerRewardsTest { // A portion of the duration passes _jumpAheadByPercentOfRewardDuration(_durationPercent); - uint256 _earned = uniStaker.unclaimedRewards(_depositor); + uint256 _earned = uniStaker.unclaimedReward(_depositor); vm.expectEmit(); emit UniStaker.RewardClaimed(_depositor, _earned); diff --git a/test/V3FactoryOwner.t.sol b/test/V3FactoryOwner.t.sol index a0c4e48..8747f23 100644 --- a/test/V3FactoryOwner.t.sol +++ b/test/V3FactoryOwner.t.sol @@ -240,7 +240,7 @@ contract ClaimFees is V3FactoryOwnerTest { factoryOwner.claimFees(pool, _recipient, _amount0, _amount1); vm.stopPrank(); - assertEq(rewardReceiver.lastParam__notifyRewardsAmount_amount(), _payoutAmount); + assertEq(rewardReceiver.lastParam__notifyRewardAmount_amount(), _payoutAmount); } function testFuzz_CallsPoolCollectProtocolMethodWithRecipientAndAmountsRequestedAndReturnsForwardedFeeAmountsFromPool( diff --git a/test/mocks/MockRewardReceiver.sol b/test/mocks/MockRewardReceiver.sol index fb2fdb7..6926524 100644 --- a/test/mocks/MockRewardReceiver.sol +++ b/test/mocks/MockRewardReceiver.sol @@ -4,9 +4,9 @@ pragma solidity 0.8.23; import {INotifiableRewardReceiver} from "src/interfaces/INotifiableRewardReceiver.sol"; contract MockRewardReceiver is INotifiableRewardReceiver { - uint256 public lastParam__notifyRewardsAmount_amount; + uint256 public lastParam__notifyRewardAmount_amount; - function notifyRewardsAmount(uint256 _amount) external { - lastParam__notifyRewardsAmount_amount = _amount; + function notifyRewardAmount(uint256 _amount) external { + lastParam__notifyRewardAmount_amount = _amount; } }