diff --git a/src/UniStaker.sol b/src/UniStaker.sol index e9e76ee..6630d3c 100644 --- a/src/UniStaker.sol +++ b/src/UniStaker.sol @@ -25,6 +25,7 @@ contract UniStaker is ReentrancyGuard { IERC20 public immutable REWARDS_TOKEN; IERC20Delegates public immutable STAKE_TOKEN; address public immutable REWARDS_NOTIFIER; + uint256 public constant REWARD_DURATION = 7 days; uint256 private constant SCALE_FACTOR = 1e24; DepositIdentifier private nextDepositId; @@ -39,7 +40,6 @@ contract UniStaker is ReentrancyGuard { mapping(address delegatee => DelegationSurrogate surrogate) public surrogates; - uint256 public rewardDuration = 7 days; uint256 public finishAt; uint256 public updatedAt; uint256 public rewardRate; @@ -151,18 +151,18 @@ contract UniStaker is ReentrancyGuard { if (block.timestamp >= finishAt) { // TODO: Can we move the scale factor into the rewardRate? This should reduce rounding errors // introduced here when truncating on this division. - rewardRate = _amount / rewardDuration; + rewardRate = _amount / REWARD_DURATION; } else { uint256 remainingRewards = rewardRate * (finishAt - block.timestamp); - rewardRate = (remainingRewards + _amount) / rewardDuration; + rewardRate = (remainingRewards + _amount) / REWARD_DURATION; } if (rewardRate == 0) revert UniStaker__InvalidRewardRate(); - if ((rewardRate * rewardDuration) > REWARDS_TOKEN.balanceOf(address(this))) { + if ((rewardRate * REWARD_DURATION) > REWARDS_TOKEN.balanceOf(address(this))) { revert UniStaker__InsufficientRewardBalance(); } - finishAt = block.timestamp + rewardDuration; + finishAt = block.timestamp + REWARD_DURATION; updatedAt = block.timestamp; } diff --git a/test/UniStaker.t.sol b/test/UniStaker.t.sol index 3f8fc03..f1bf899 100644 --- a/test/UniStaker.t.sol +++ b/test/UniStaker.t.sol @@ -1208,7 +1208,7 @@ contract UniStakerRewardsTest is UniStakerTest { console2.log("reward balance"); console2.log(rewardToken.balanceOf(address(uniStaker))); console2.log("rewardDuration"); - console2.log(uniStaker.rewardDuration()); + console2.log(uniStaker.REWARD_DURATION()); console2.log("finishAt"); console2.log(uniStaker.finishAt()); console2.log("updatedAt"); @@ -1241,7 +1241,7 @@ contract UniStakerRewardsTest is UniStakerTest { } function _jumpAheadByPercentOfRewardDuration(uint256 _percent) public { - uint256 _seconds = (_percent * uniStaker.rewardDuration()) / 100; + uint256 _seconds = (_percent * uniStaker.REWARD_DURATION()) / 100; _jumpAhead(_seconds); } @@ -1277,7 +1277,7 @@ contract NotifyRewardsAmount is UniStakerRewardsTest { _amount = _boundToRealisticReward(_amount); _mintTransferAndNotifyReward(_amount); - uint256 _expectedRewardRate = _amount / uniStaker.rewardDuration(); + uint256 _expectedRewardRate = _amount / uniStaker.REWARD_DURATION(); assertEq(uniStaker.rewardRate(), _expectedRewardRate); } @@ -1286,11 +1286,11 @@ contract NotifyRewardsAmount is UniStakerRewardsTest { _amount2 = _boundToRealisticReward(_amount2); _mintTransferAndNotifyReward(_amount1); - uint256 _expectedRewardRate = _amount1 / uniStaker.rewardDuration(); + uint256 _expectedRewardRate = _amount1 / uniStaker.REWARD_DURATION(); assertEq(uniStaker.rewardRate(), _expectedRewardRate); _mintTransferAndNotifyReward(_amount2); - _expectedRewardRate = (_amount1 + _amount2) / uniStaker.rewardDuration(); + _expectedRewardRate = (_amount1 + _amount2) / uniStaker.REWARD_DURATION(); assertLteWithinOneUnit(uniStaker.rewardRate(), _expectedRewardRate); } @@ -1301,7 +1301,7 @@ contract NotifyRewardsAmount is UniStakerRewardsTest { _jumpAhead(_jumpTime); _mintTransferAndNotifyReward(_amount); - uint256 _expectedFinishTimestamp = _futureTimestamp + uniStaker.rewardDuration(); + uint256 _expectedFinishTimestamp = _futureTimestamp + uniStaker.REWARD_DURATION(); assertEq(uniStaker.updatedAt(), _futureTimestamp); assertEq(uniStaker.finishAt(), _expectedFinishTimestamp); @@ -1359,7 +1359,7 @@ contract NotifyRewardsAmount is UniStakerRewardsTest { 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.rewardDuration() - 1); + _amount = bound(_amount, 0, uniStaker.REWARD_DURATION() - 1); rewardToken.mint(rewardsNotifier, _amount); vm.startPrank(rewardsNotifier);