From b1a4e5ad37b537e315415387a6cde1b017385cbf Mon Sep 17 00:00:00 2001 From: Andrea Franz Date: Tue, 3 Dec 2024 13:42:03 +0100 Subject: [PATCH] fix(RewardsStreamerMP): rename _calculateAccruedRewards to _calculatePendingRewards and fix specs --- certora/specs/EmergencyMode.spec | 10 ++++++++-- src/RewardsStreamerMP.sol | 6 +++--- test/RewardsStreamerMP.t.sol | 3 +-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/certora/specs/EmergencyMode.spec b/certora/specs/EmergencyMode.spec index b32513a..4c399d0 100644 --- a/certora/specs/EmergencyMode.spec +++ b/certora/specs/EmergencyMode.spec @@ -24,12 +24,18 @@ definition isViewFunction(method f) returns bool = ( f.selector == sig:streamer.getAccount(address).selector || f.selector == sig:streamer.rewardsBalanceOf(address).selector || f.selector == sig:streamer.totalRewardsSupply().selector || - f.selector == sig:streamer.calculateAccountRewards(address).selector + f.selector == sig:streamer.calculateAccountRewards(address).selector || + f.selector == sig:streamer.lastRewardTime().selector || + f.selector == sig:streamer.rewardAmount().selector || + f.selector == sig:streamer.totalRewardsAccrued().selector || + f.selector == sig:streamer.rewardStartTime().selector || + f.selector == sig:streamer.rewardEndTime().selector ); definition isOwnableFunction(method f) returns bool = ( f.selector == sig:streamer.renounceOwnership().selector || - f.selector == sig:streamer.transferOwnership(address).selector + f.selector == sig:streamer.transferOwnership(address).selector || + f.selector == sig:streamer.setReward(uint256, uint256).selector ); definition isTrustedCodehashAccessFunction(method f) returns bool = ( diff --git a/src/RewardsStreamerMP.sol b/src/RewardsStreamerMP.sol index 8062fd4..08a4e00 100644 --- a/src/RewardsStreamerMP.sol +++ b/src/RewardsStreamerMP.sol @@ -261,7 +261,7 @@ contract RewardsStreamerMP is UUPSUpgradeable, IStakeManager, TrustedCodehashAcc rewardEndTime = block.timestamp + duration; } - function _calculateAccruedRewards() internal view returns (uint256) { + function _calculatePendingRewards() internal view returns (uint256) { if (rewardEndTime <= rewardStartTime) { // No active reward period return 0; @@ -300,7 +300,7 @@ contract RewardsStreamerMP is UUPSUpgradeable, IStakeManager, TrustedCodehashAcc return; } - uint256 newRewards = _calculateAccruedRewards(); + uint256 newRewards = _calculatePendingRewards(); if (newRewards == 0) { return; } @@ -367,7 +367,7 @@ contract RewardsStreamerMP is UUPSUpgradeable, IStakeManager, TrustedCodehashAcc } function totalRewardsSupply() public view returns (uint256) { - return totalRewardsAccrued + _calculateAccruedRewards(); + return totalRewardsAccrued + _calculatePendingRewards(); } function rewardsBalanceOf(address accountAddress) external view returns (uint256) { diff --git a/test/RewardsStreamerMP.t.sol b/test/RewardsStreamerMP.t.sol index 17a3e60..c4297a1 100644 --- a/test/RewardsStreamerMP.t.sol +++ b/test/RewardsStreamerMP.t.sol @@ -224,7 +224,6 @@ contract IntegrationTest is RewardsStreamerMPTest { // T3 vm.prank(admin); - // rewardToken.transfer(address(streamer), 1000e18); streamer.updateGlobalState(); checkStreamer( @@ -370,7 +369,6 @@ contract IntegrationTest is RewardsStreamerMPTest { // T6 vm.prank(admin); - // rewardToken.transfer(address(streamer), 1000e18); streamer.updateGlobalState(); checkStreamer( @@ -1996,6 +1994,7 @@ contract RewardsStreamerMP_RewardsTest is RewardsStreamerMPTest { // set other 2000 rewards for other 10 days vm.prank(admin); streamer.setReward(2000e18, 10 days); + // accrued is 1000 from the previous reward and still 0 for the new one assertEq(streamer.totalRewardsSupply(), 1000e18, "totalRewardsSupply should be 1000"); assertEq(streamer.totalRewardsAccrued(), 1000e18);