Skip to content

Commit

Permalink
cleanup(RewardsStreamerMP): remove unnecessary writes to `account.las…
Browse files Browse the repository at this point in the history
…tMPupdateTime`

Whenever `account.lastMPupdateTime` is set, we also call
`_updateAccountMP()` before that, which never reverts, so the value set
there will never differ from the ones we set later explicitly.

Closes #80
  • Loading branch information
0x-r4bbit committed Dec 4, 2024
1 parent 9374025 commit cafffa5
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 57 deletions.
10 changes: 5 additions & 5 deletions .gas-report
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
| src/RewardsStreamerMP.sol:RewardsStreamerMP contract | | | | | |
|------------------------------------------------------|-----------------|--------|--------|--------|---------|
| Deployment Cost | Deployment Size | | | | |
| 2491772 | 11482 | | | | |
| 2494954 | 11497 | | | | |
| Function Name | min | avg | median | max | # calls |
| MAX_LOCKUP_PERIOD | 294 | 294 | 294 | 294 | 23 |
| MAX_MULTIPLIER | 251 | 251 | 251 | 251 | 30 |
Expand All @@ -35,15 +35,15 @@
| isTrustedCodehash | 519 | 519 | 519 | 519 | 231 |
| lastRewardTime | 373 | 1373 | 1373 | 2373 | 2 |
| leave | 56613 | 56613 | 56613 | 56613 | 1 |
| lock | 12041 | 34212 | 16370 | 74225 | 3 |
| lock | 12041 | 34170 | 16370 | 74099 | 3 |
| proxiableUUID | 331 | 331 | 331 | 331 | 3 |
| registerVault | 55866 | 72745 | 72966 | 72966 | 233 |
| rewardEndTime | 373 | 1373 | 1373 | 2373 | 2 |
| rewardStartTime | 352 | 1352 | 1352 | 2352 | 2 |
| rewardsBalanceOf | 1294 | 1294 | 1294 | 1294 | 4 |
| setReward | 2561 | 50875 | 60256 | 102573 | 7 |
| setTrustedCodehash | 26243 | 26243 | 26243 | 26243 | 59 |
| stake | 131211 | 170364 | 178028 | 198507 | 66 |
| stake | 131082 | 170235 | 177899 | 198378 | 66 |
| totalMP | 373 | 373 | 373 | 373 | 81 |
| totalMaxMP | 350 | 350 | 350 | 350 | 81 |
| totalRewardsAccrued | 351 | 351 | 351 | 351 | 3 |
Expand Down Expand Up @@ -100,10 +100,10 @@
| STAKING_TOKEN | 216 | 216 | 216 | 216 | 1 |
| emergencyExit | 36353 | 48857 | 48091 | 65191 | 7 |
| leave | 33507 | 131513 | 60783 | 370978 | 4 |
| lock | 33245 | 60706 | 50779 | 108022 | 4 |
| lock | 33245 | 60675 | 50779 | 107896 | 4 |
| owner | 2339 | 2339 | 2339 | 2339 | 233 |
| register | 87015 | 103894 | 104115 | 104115 | 233 |
| stake | 33411 | 241651 | 252532 | 273059 | 67 |
| stake | 33411 | 241524 | 252403 | 272930 | 67 |
| stakeManager | 368 | 368 | 368 | 368 | 233 |
| trustStakeManager | 28953 | 28953 | 28953 | 28953 | 1 |
| unstake | 33282 | 96931 | 102420 | 110233 | 14 |
Expand Down
100 changes: 50 additions & 50 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,69 +1,69 @@
EmergencyExitTest:test_CannotEnableEmergencyModeTwice() (gas: 92646)
EmergencyExitTest:test_CannotLeaveBeforeEmergencyMode() (gas: 297824)
EmergencyExitTest:test_EmergencyExitBasic() (gas: 384518)
EmergencyExitTest:test_EmergencyExitMultipleUsers() (gas: 659358)
EmergencyExitTest:test_EmergencyExitToAlternateAddress() (gas: 392437)
EmergencyExitTest:test_EmergencyExitWithLock() (gas: 392015)
EmergencyExitTest:test_EmergencyExitWithRewards() (gas: 377401)
EmergencyExitTest:test_CannotLeaveBeforeEmergencyMode() (gas: 297695)
EmergencyExitTest:test_EmergencyExitBasic() (gas: 384389)
EmergencyExitTest:test_EmergencyExitMultipleUsers() (gas: 659100)
EmergencyExitTest:test_EmergencyExitToAlternateAddress() (gas: 392308)
EmergencyExitTest:test_EmergencyExitWithLock() (gas: 391886)
EmergencyExitTest:test_EmergencyExitWithRewards() (gas: 377272)
EmergencyExitTest:test_OnlyOwnerCanEnableEmergencyMode() (gas: 39408)
IntegrationTest:testStakeFoo() (gas: 1179318)
LeaveTest:test_LeaveShouldProperlyUpdateAccounting() (gas: 2927052)
LeaveTest:test_RevertWhenStakeManagerIsTrusted() (gas: 294955)
LeaveTest:test_TrustNewStakeManager() (gas: 3004493)
LockTest:test_LockFailsWithInvalidPeriod() (gas: 310018)
IntegrationTest:testStakeFoo() (gas: 1178931)
LeaveTest:test_LeaveShouldProperlyUpdateAccounting() (gas: 2930114)
LeaveTest:test_RevertWhenStakeManagerIsTrusted() (gas: 294826)
LeaveTest:test_TrustNewStakeManager() (gas: 3007555)
LockTest:test_LockFailsWithInvalidPeriod() (gas: 309889)
LockTest:test_LockFailsWithNoStake() (gas: 63598)
LockTest:test_LockWithoutPriorLock() (gas: 391137)
MaliciousUpgradeTest:test_UpgradeStackOverflowStakeManager() (gas: 1745462)
MultipleVaultsStakeTest:test_StakeMultipleVaults() (gas: 717207)
LockTest:test_LockWithoutPriorLock() (gas: 390882)
MaliciousUpgradeTest:test_UpgradeStackOverflowStakeManager() (gas: 1745333)
MultipleVaultsStakeTest:test_StakeMultipleVaults() (gas: 716820)
NFTMetadataGeneratorSVGTest:testGenerateMetadata() (gas: 85934)
NFTMetadataGeneratorSVGTest:testSetImageStrings() (gas: 58332)
NFTMetadataGeneratorSVGTest:testSetImageStringsRevert() (gas: 35804)
NFTMetadataGeneratorURLTest:testGenerateMetadata() (gas: 102512)
NFTMetadataGeneratorURLTest:testSetBaseURL() (gas: 49555)
NFTMetadataGeneratorURLTest:testSetBaseURLRevert() (gas: 35979)
RewardsStreamerMP_RewardsTest:testRewardsBalanceOf() (gas: 670984)
RewardsStreamerMP_RewardsTest:testRewardsBalanceOf() (gas: 670855)
RewardsStreamerMP_RewardsTest:testSetRewards() (gas: 160214)
RewardsStreamerMP_RewardsTest:testSetRewards_RevertsBadAmount() (gas: 39323)
RewardsStreamerMP_RewardsTest:testSetRewards_RevertsBadDuration() (gas: 39346)
RewardsStreamerMP_RewardsTest:testSetRewards_RevertsNotAuthorized() (gas: 39359)
RewardsStreamerMP_RewardsTest:testTotalRewardsSupply() (gas: 611915)
RewardsStreamerMP_RewardsTest:testTotalRewardsSupply() (gas: 611786)
RewardsStreamerTest:testStake() (gas: 869181)
StakeTest:test_StakeMultipleAccounts() (gas: 494656)
StakeTest:test_StakeMultipleAccountsAndRewards() (gas: 500594)
StakeTest:test_StakeMultipleAccountsMPIncreasesMaxMPDoesNotChange() (gas: 831165)
StakeTest:test_StakeMultipleAccountsWithMinLockUp() (gas: 517651)
StakeTest:test_StakeMultipleAccountsWithRandomLockUp() (gas: 539579)
StakeTest:test_StakeOneAccount() (gas: 277040)
StakeTest:test_StakeOneAccountAndRewards() (gas: 283009)
StakeTest:test_StakeOneAccountMPIncreasesMaxMPDoesNotChange() (gas: 499939)
StakeTest:test_StakeOneAccountReachingMPLimit() (gas: 496276)
StakeTest:test_StakeOneAccountWithMaxLockUp() (gas: 301895)
StakeTest:test_StakeOneAccountWithMinLockUp() (gas: 301884)
StakeTest:test_StakeOneAccountWithRandomLockUp() (gas: 301951)
StakeTest:test_StakeMultipleAccounts() (gas: 494398)
StakeTest:test_StakeMultipleAccountsAndRewards() (gas: 500336)
StakeTest:test_StakeMultipleAccountsMPIncreasesMaxMPDoesNotChange() (gas: 830907)
StakeTest:test_StakeMultipleAccountsWithMinLockUp() (gas: 517393)
StakeTest:test_StakeMultipleAccountsWithRandomLockUp() (gas: 539321)
StakeTest:test_StakeOneAccount() (gas: 276911)
StakeTest:test_StakeOneAccountAndRewards() (gas: 282880)
StakeTest:test_StakeOneAccountMPIncreasesMaxMPDoesNotChange() (gas: 499810)
StakeTest:test_StakeOneAccountReachingMPLimit() (gas: 496147)
StakeTest:test_StakeOneAccountWithMaxLockUp() (gas: 301766)
StakeTest:test_StakeOneAccountWithMinLockUp() (gas: 301755)
StakeTest:test_StakeOneAccountWithRandomLockUp() (gas: 301822)
StakingTokenTest:testStakeToken() (gas: 10422)
UnstakeTest:test_StakeMultipleAccounts() (gas: 494678)
UnstakeTest:test_StakeMultipleAccountsAndRewards() (gas: 500594)
UnstakeTest:test_StakeMultipleAccountsMPIncreasesMaxMPDoesNotChange() (gas: 831142)
UnstakeTest:test_StakeMultipleAccountsWithMinLockUp() (gas: 517673)
UnstakeTest:test_StakeMultipleAccountsWithRandomLockUp() (gas: 539601)
UnstakeTest:test_StakeOneAccount() (gas: 277063)
UnstakeTest:test_StakeOneAccountAndRewards() (gas: 283031)
UnstakeTest:test_StakeOneAccountMPIncreasesMaxMPDoesNotChange() (gas: 499961)
UnstakeTest:test_StakeOneAccountReachingMPLimit() (gas: 496256)
UnstakeTest:test_StakeOneAccountWithMaxLockUp() (gas: 301895)
UnstakeTest:test_StakeOneAccountWithMinLockUp() (gas: 301884)
UnstakeTest:test_StakeOneAccountWithRandomLockUp() (gas: 301995)
UnstakeTest:test_UnstakeBonusMPAndAccuredMP() (gas: 542969)
UnstakeTest:test_UnstakeMultipleAccounts() (gas: 693417)
UnstakeTest:test_UnstakeMultipleAccountsAndRewards() (gas: 787224)
UnstakeTest:test_UnstakeOneAccount() (gas: 473460)
UnstakeTest:test_UnstakeOneAccountAndAccruedMP() (gas: 495130)
UnstakeTest:test_UnstakeOneAccountAndRewards() (gas: 404531)
UnstakeTest:test_UnstakeOneAccountWithLockUpAndAccruedMP() (gas: 531635)
UpgradeTest:test_RevertWhenNotOwner() (gas: 2568028)
UpgradeTest:test_UpgradeStakeManager() (gas: 2841596)
UnstakeTest:test_StakeMultipleAccounts() (gas: 494420)
UnstakeTest:test_StakeMultipleAccountsAndRewards() (gas: 500336)
UnstakeTest:test_StakeMultipleAccountsMPIncreasesMaxMPDoesNotChange() (gas: 830884)
UnstakeTest:test_StakeMultipleAccountsWithMinLockUp() (gas: 517415)
UnstakeTest:test_StakeMultipleAccountsWithRandomLockUp() (gas: 539343)
UnstakeTest:test_StakeOneAccount() (gas: 276934)
UnstakeTest:test_StakeOneAccountAndRewards() (gas: 282902)
UnstakeTest:test_StakeOneAccountMPIncreasesMaxMPDoesNotChange() (gas: 499832)
UnstakeTest:test_StakeOneAccountReachingMPLimit() (gas: 496127)
UnstakeTest:test_StakeOneAccountWithMaxLockUp() (gas: 301766)
UnstakeTest:test_StakeOneAccountWithMinLockUp() (gas: 301755)
UnstakeTest:test_StakeOneAccountWithRandomLockUp() (gas: 301866)
UnstakeTest:test_UnstakeBonusMPAndAccuredMP() (gas: 542840)
UnstakeTest:test_UnstakeMultipleAccounts() (gas: 693159)
UnstakeTest:test_UnstakeMultipleAccountsAndRewards() (gas: 786966)
UnstakeTest:test_UnstakeOneAccount() (gas: 473331)
UnstakeTest:test_UnstakeOneAccountAndAccruedMP() (gas: 495001)
UnstakeTest:test_UnstakeOneAccountAndRewards() (gas: 404402)
UnstakeTest:test_UnstakeOneAccountWithLockUpAndAccruedMP() (gas: 531506)
UpgradeTest:test_RevertWhenNotOwner() (gas: 2571219)
UpgradeTest:test_UpgradeStakeManager() (gas: 2844658)
VaultRegistrationTest:test_VaultRegistration() (gas: 62211)
WithdrawTest:test_CannotWithdrawStakedFunds() (gas: 310679)
WithdrawTest:test_CannotWithdrawStakedFunds() (gas: 310550)
XPNFTTokenTest:testApproveNotAllowed() (gas: 10500)
XPNFTTokenTest:testGetApproved() (gas: 10523)
XPNFTTokenTest:testIsApprovedForAll() (gas: 10698)
Expand Down
2 changes: 0 additions & 2 deletions src/RewardsStreamerMP.sol
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ contract RewardsStreamerMP is
totalMaxMP += accountMaxMP;

account.accountRewardIndex = rewardIndex;
account.lastMPUpdateTime = block.timestamp;
}

function lock(uint256 lockPeriod)
Expand Down Expand Up @@ -264,7 +263,6 @@ contract RewardsStreamerMP is
totalMaxMP += additionalBonusMP;

account.accountRewardIndex = rewardIndex;
account.lastMPUpdateTime = block.timestamp;
}

function unstake(uint256 amount)
Expand Down

0 comments on commit cafffa5

Please sign in to comment.