Skip to content

Commit

Permalink
fix(RewardsStreamerMP): rename _calculateAccruedRewards to _calculate…
Browse files Browse the repository at this point in the history
…PendingRewards and fix specs
  • Loading branch information
gravityblast authored and 0x-r4bbit committed Dec 3, 2024
1 parent 7211b49 commit b1a4e5a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
10 changes: 8 additions & 2 deletions certora/specs/EmergencyMode.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down
6 changes: 3 additions & 3 deletions src/RewardsStreamerMP.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -300,7 +300,7 @@ contract RewardsStreamerMP is UUPSUpgradeable, IStakeManager, TrustedCodehashAcc
return;
}

uint256 newRewards = _calculateAccruedRewards();
uint256 newRewards = _calculatePendingRewards();
if (newRewards == 0) {
return;
}
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions test/RewardsStreamerMP.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ contract IntegrationTest is RewardsStreamerMPTest {

// T3
vm.prank(admin);
// rewardToken.transfer(address(streamer), 1000e18);
streamer.updateGlobalState();

checkStreamer(
Expand Down Expand Up @@ -370,7 +369,6 @@ contract IntegrationTest is RewardsStreamerMPTest {

// T6
vm.prank(admin);
// rewardToken.transfer(address(streamer), 1000e18);
streamer.updateGlobalState();

checkStreamer(
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit b1a4e5a

Please sign in to comment.