Skip to content

Commit

Permalink
feat(StakeManager): optimizations on processAccount
Browse files Browse the repository at this point in the history
  • Loading branch information
3esmit authored and 0x-r4bbit committed Sep 5, 2024
1 parent 530bec0 commit 9f3d8ff
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
30 changes: 15 additions & 15 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
CreateVaultTest:testDeployment() (gas: 9774)
CreateVaultTest:test_createVault() (gas: 692936)
ExecuteAccountTest:testDeployment() (gas: 28720)
ExecuteAccountTest:test_ExecuteAccountMintMP() (gas: 3856635)
ExecuteAccountTest:test_ExecuteAccountMintMP() (gas: 3860579)
ExecuteAccountTest:test_RevertWhen_InvalidLimitEpoch() (gas: 1154886)
ExecuteAccountTest:test_ShouldNotMintMoreThanCap() (gas: 110522900)
ExecuteAccountTest:test_ShouldNotMintMoreThanCap() (gas: 110612896)
ExecuteEpochTest:testDeployment() (gas: 28720)
ExecuteEpochTest:testNewDeployment() (gas: 30815)
ExecuteEpochTest:test_ExecuteEpochShouldIncreaseEpoch() (gas: 94810)
Expand All @@ -14,17 +14,17 @@ LeaveTest:testDeployment() (gas: 28720)
LeaveTest:test_RevertWhen_NoPendingMigration() (gas: 1154760)
LeaveTest:test_RevertWhen_SenderIsNotVault() (gas: 10750)
LockTest:testDeployment() (gas: 28720)
LockTest:test_NewLockupPeriod() (gas: 1143587)
LockTest:test_RevertWhen_InvalidNewLockupPeriod() (gas: 1135204)
LockTest:test_RevertWhen_InvalidUpdateLockupPeriod() (gas: 1231813)
LockTest:test_NewLockupPeriod() (gas: 1143392)
LockTest:test_RevertWhen_InvalidNewLockupPeriod() (gas: 1135009)
LockTest:test_RevertWhen_InvalidUpdateLockupPeriod() (gas: 1230470)
LockTest:test_RevertWhen_SenderIsNotVault() (gas: 10630)
LockTest:test_ShouldIncreaseBonusMP() (gas: 1123687)
LockTest:test_UpdateLockupPeriod() (gas: 1281200)
LockTest:test_ShouldIncreaseBonusMP() (gas: 1123492)
LockTest:test_UpdateLockupPeriod() (gas: 1260809)
MigrateTest:testDeployment() (gas: 28720)
MigrateTest:test_RevertWhen_NoPendingMigration() (gas: 1152399)
MigrateTest:test_RevertWhen_SenderIsNotVault() (gas: 10750)
MigrationInitializeTest:testDeployment() (gas: 28720)
MigrationInitializeTest:test_RevertWhen_MigrationPending() (gas: 5716968)
MigrationInitializeTest:test_RevertWhen_MigrationPending() (gas: 5745821)
MigrationStakeManagerTest:testDeployment() (gas: 28720)
MigrationStakeManagerTest:testNewDeployment() (gas: 30859)
MigrationStakeManagerTest:test_ExecuteEpochShouldNotIncreaseEpochInMigration() (gas: 105686)
Expand All @@ -39,17 +39,17 @@ StakeTest:test_RevertWhen_RestakeWithLock() (gas: 1160132)
StakeTest:test_RevertWhen_SenderIsNotVault() (gas: 10651)
StakeTest:test_RevertWhen_StakeIsTooLow() (gas: 745253)
StakeTest:test_RevertWhen_StakeTokenTransferFails() (gas: 175040)
StakeTest:test_StakeWithoutLockUpTimeMintsMultiplierPoints() (gas: 1029215)
StakeTest:test_StakeWithoutLockUpTimeMintsMultiplierPoints() (gas: 1029020)
StakedTokenTest:testStakeToken() (gas: 7616)
UnstakeTest:testDeployment() (gas: 28742)
UnstakeTest:test_RevertWhen_AmountMoreThanBalance() (gas: 1133014)
UnstakeTest:test_RevertWhen_FundsLocked() (gas: 1158758)
UnstakeTest:test_RevertWhen_SenderIsNotVault() (gas: 10653)
UnstakeTest:test_UnstakeShouldBurnMultiplierPoints() (gas: 5497531)
UnstakeTest:test_UnstakeShouldReturnFund_NoLockUp() (gas: 1026695)
UnstakeTest:test_UnstakeShouldReturnFund_WithLockUp() (gas: 1115820)
UnstakeTest:test_UnstakeShouldBurnMultiplierPoints() (gas: 5535740)
UnstakeTest:test_UnstakeShouldReturnFund_NoLockUp() (gas: 1026500)
UnstakeTest:test_UnstakeShouldReturnFund_WithLockUp() (gas: 1114672)
UserFlowsTest:testDeployment() (gas: 28720)
UserFlowsTest:test_PendingMPToBeMintedCannotBeGreaterThanTotalSupplyMP(uint8) (runs: 1001, μ: 69673434, ~: 32945058)
UserFlowsTest:test_StakeWithLockUpTimeLocksStake() (gas: 1116708)
UserFlowsTest:test_StakedSupplyShouldIncreaseAndDecreaseAgain() (gas: 1951147)
UserFlowsTest:test_PendingMPToBeMintedCannotBeGreaterThanTotalSupplyMP(uint8) (runs: 1001, μ: 68072901, ~: 30146840)
UserFlowsTest:test_StakeWithLockUpTimeLocksStake() (gas: 1115560)
UserFlowsTest:test_StakedSupplyShouldIncreaseAndDecreaseAgain() (gas: 1950757)
VaultFactoryTest:testDeployment() (gas: 9774)
7 changes: 5 additions & 2 deletions contracts/StakeManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -449,15 +449,18 @@ contract StakeManager is Ownable {
userReward += userEpochReward;
iEpoch.epochReward -= userEpochReward;
iEpoch.totalSupply -= userSupply;
//TODO: remove epoch when iEpoch.totalSupply reaches zero
if (iEpoch.totalSupply == 0) {
pendingReward -= iEpoch.epochReward;
delete epochs[userEpoch];
}
}
account.epoch = userEpoch;
if (userReward > 0) {
pendingReward -= userReward;
stakedToken.transfer(account.rewardAddress, userReward);
}
mpDifference = account.totalMP - mpDifference; //TODO: optimize, this only needed for migration
if (address(migration) != address(0)) {
mpDifference = account.totalMP - mpDifference;
migration.increaseTotalMP(mpDifference);
}
}
Expand Down

0 comments on commit 9f3d8ff

Please sign in to comment.