diff --git a/.gas-report b/.gas-report index af54826..3c8d934 100644 --- a/.gas-report +++ b/.gas-report @@ -1,21 +1,21 @@ | contracts/StakeManager.sol:StakeManager contract | | | | | | |--------------------------------------------------|-----------------|--------|--------|--------|---------| | Deployment Cost | Deployment Size | | | | | -| 2489660 | 13152 | | | | | +| 2483377 | 13123 | | | | | | Function Name | min | avg | median | max | # calls | | EPOCH_SIZE | 263 | 263 | 263 | 263 | 1498 | | MAX_BOOST | 264 | 264 | 264 | 264 | 637 | | MAX_LOCKUP_PERIOD | 383 | 383 | 383 | 383 | 4 | | MIN_LOCKUP_PERIOD | 264 | 264 | 264 | 264 | 12 | | YEAR | 263 | 263 | 263 | 263 | 637 | -| accounts | 1616 | 1616 | 1616 | 1616 | 144249 | +| accounts | 1616 | 1616 | 1616 | 1616 | 144345 | | calculateMPToMint | 740 | 740 | 740 | 740 | 1276 | | currentEpoch | 384 | 1050 | 384 | 2384 | 54 | -| epochEnd | 649 | 649 | 649 | 2649 | 23671 | +| epochEnd | 649 | 649 | 649 | 2649 | 23687 | | epochReward | 1381 | 2881 | 1381 | 5881 | 3 | -| executeAccount(address) | 151167 | 151167 | 151167 | 151167 | 2 | -| executeAccount(address,uint256) | 26562 | 72617 | 74122 | 217855 | 141836 | -| executeEpoch() | 23480 | 120821 | 121978 | 939007 | 23560 | +| executeAccount(address) | 149300 | 149300 | 149300 | 149300 | 2 | +| executeAccount(address,uint256) | 26562 | 72242 | 74122 | 200087 | 141932 | +| executeEpoch() | 23480 | 120709 | 121865 | 900380 | 23576 | | executeEpoch(uint256) | 23861 | 24497 | 23861 | 26090 | 7 | | expiredStakeStorage | 437 | 2346 | 2437 | 2437 | 22 | | isTrustedCodehash | 541 | 949 | 541 | 2541 | 680 | @@ -25,7 +25,7 @@ | migrationInitialize | 24624 | 24624 | 24624 | 24624 | 1 | | newEpoch | 441 | 441 | 441 | 441 | 5 | | owner | 2432 | 2432 | 2432 | 2432 | 13 | -| pendingMPToBeMinted | 363 | 363 | 363 | 363 | 46424 | +| pendingMPToBeMinted | 363 | 363 | 363 | 363 | 46456 | | pendingReward | 408 | 1442 | 2408 | 2408 | 29 | | previousManager | 275 | 275 | 275 | 275 | 13 | | setTrustedCodehash | 47960 | 47960 | 47960 | 47960 | 139 | @@ -35,7 +35,7 @@ | startTime | 306 | 306 | 306 | 306 | 21 | | totalSupply | 784 | 1965 | 2784 | 2784 | 22 | | totalSupplyBalance | 407 | 1807 | 2407 | 2407 | 20 | -| totalSupplyMP | 384 | 384 | 384 | 2384 | 46445 | +| totalSupplyMP | 384 | 384 | 384 | 2384 | 46477 | | unstake | 23841 | 23841 | 23841 | 23841 | 1 | @@ -46,11 +46,11 @@ | Function Name | min | avg | median | max | # calls | | acceptMigration | 35311 | 35311 | 35311 | 35311 | 2 | | leave | 35297 | 35297 | 35297 | 35297 | 1 | -| lock | 43285 | 96103 | 64379 | 204703 | 7 | +| lock | 43285 | 95698 | 64379 | 204197 | 7 | | owner | 362 | 362 | 362 | 362 | 679 | -| stake | 27265 | 282007 | 265700 | 351859 | 684 | +| stake | 27265 | 282180 | 265700 | 351859 | 684 | | stakedToken | 212 | 212 | 212 | 212 | 2 | -| unstake | 40180 | 97074 | 78700 | 233556 | 11 | +| unstake | 40180 | 96354 | 78700 | 229598 | 11 | | contracts/VaultFactory.sol:VaultFactory contract | | | | | | @@ -68,7 +68,7 @@ | Deployment Cost | Deployment Size | | | | | | 0 | 0 | | | | | | Function Name | min | avg | median | max | # calls | -| getExpiredMP | 2427 | 2427 | 2427 | 2427 | 23721 | +| getExpiredMP | 2427 | 2427 | 2427 | 2427 | 23737 | | transferOwnership | 28533 | 28533 | 28533 | 28533 | 1 | @@ -77,24 +77,24 @@ | Deployment Cost | Deployment Size | | | | | | 0 | 0 | | | | | | Function Name | min | avg | median | max | # calls | -| approve | 46175 | 46238 | 46199 | 46367 | 679 | -| balanceOf | 561 | 2107 | 2561 | 2561 | 30740 | +| approve | 46175 | 46236 | 46199 | 46367 | 679 | +| balanceOf | 561 | 2107 | 2561 | 2561 | 30756 | | script/Deploy.s.sol:Deploy contract | | | | | | |-------------------------------------|-----------------|---------|---------|---------|---------| | Deployment Cost | Deployment Size | | | | | -| 6142896 | 29649 | | | | | +| 6136611 | 29620 | | | | | | Function Name | min | avg | median | max | # calls | -| run | 5338557 | 5338557 | 5338557 | 5338557 | 66 | +| run | 5332750 | 5332750 | 5332750 | 5332750 | 66 | | script/DeployMigrationStakeManager.s.sol:DeployMigrationStakeManager contract | | | | | | |-------------------------------------------------------------------------------|-----------------|---------|---------|---------|---------| | Deployment Cost | Deployment Size | | | | | -| 3306430 | 16417 | | | | | +| 3300146 | 16388 | | | | | | Function Name | min | avg | median | max | # calls | -| run | 2324886 | 2324886 | 2324886 | 2324886 | 19 | +| run | 2319079 | 2319079 | 2319079 | 2319079 | 19 | | script/DeploymentConfig.s.sol:DeploymentConfig contract | | | | | | @@ -117,9 +117,9 @@ | test/script/DeployBroken.s.sol:DeployBroken contract | | | | | | |------------------------------------------------------|-----------------|---------|---------|---------|---------| | Deployment Cost | Deployment Size | | | | | -| 4827656 | 23447 | | | | | +| 4821371 | 23418 | | | | | | Function Name | min | avg | median | max | # calls | -| run | 4178379 | 4178379 | 4178379 | 4178379 | 1 | +| run | 4172572 | 4172572 | 4172572 | 4172572 | 1 | diff --git a/.gas-snapshot b/.gas-snapshot index ff826a0..dad3de3 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -1,24 +1,24 @@ CreateVaultTest:testDeployment() (gas: 9774) CreateVaultTest:test_createVault() (gas: 713999) ExecuteAccountTest:testDeployment() (gas: 28828) -ExecuteAccountTest:test_ExecuteAccountLimit() (gas: 1582018) -ExecuteAccountTest:test_ExecuteAccountMintMP() (gas: 5299985) -ExecuteAccountTest:test_RevertWhen_InvalidLimitEpoch() (gas: 1790139) -ExecuteAccountTest:test_ShouldNotMintMoreThanCap() (gas: 321470949) +ExecuteAccountTest:test_ExecuteAccountLimit() (gas: 1579172) +ExecuteAccountTest:test_ExecuteAccountMintMP() (gas: 5295647) +ExecuteAccountTest:test_RevertWhen_InvalidLimitEpoch() (gas: 1787335) +ExecuteAccountTest:test_ShouldNotMintMoreThanCap() (gas: 321024135) ExecuteEpochTest:testDeployment() (gas: 28829) ExecuteEpochTest:testNewDeployment() (gas: 30901) ExecuteEpochTest:test_ExecuteEpochExecuteAccountAfterEpochEnd() (gas: 1367896) -ExecuteEpochTest:test_ExecuteEpochExecuteAccountAfterManyEpochsJumoMany() (gas: 1386983) +ExecuteEpochTest:test_ExecuteEpochExecuteAccountAfterManyEpochsJumoMany() (gas: 1385583) ExecuteEpochTest:test_ExecuteEpochExecuteAccountAfterManyEpochsWithBrokenTime() (gas: 1630994) -ExecuteEpochTest:test_ExecuteEpochExecuteAccountAfterManyEpochsWithBrokenTimeJumpMany() (gas: 1396698) -ExecuteEpochTest:test_ExecuteEpochExecuteEpochAfterEnd() (gas: 1937948) -ExecuteEpochTest:test_ExecuteEpochExecuteEpochExecuteAccountAfterManyEpochs() (gas: 2525682) -ExecuteEpochTest:test_ExecuteEpochExecuteEpochExecuteAccountAfterManyEpochsJumoMany() (gas: 1481437) -ExecuteEpochTest:test_ExecuteEpochExecuteEpochExecuteAccountAfterManyEpochsWithBrokenTime() (gas: 2535418) -ExecuteEpochTest:test_ExecuteEpochExecuteEpochExecuteAccountAfterManyEpochsWithBrokenTimeJumpMany() (gas: 1491129) -ExecuteEpochTest:test_ExecuteEpochNewEpoch() (gas: 1122427) -ExecuteEpochTest:test_ExecuteEpochShouldIncreaseEpoch() (gas: 92457) -ExecuteEpochTest:test_ExecuteEpochShouldIncreasePendingReward() (gas: 256428) +ExecuteEpochTest:test_ExecuteEpochExecuteAccountAfterManyEpochsWithBrokenTimeJumpMany() (gas: 1395298) +ExecuteEpochTest:test_ExecuteEpochExecuteEpochAfterEnd() (gas: 1928384) +ExecuteEpochTest:test_ExecuteEpochExecuteEpochExecuteAccountAfterManyEpochs() (gas: 2511226) +ExecuteEpochTest:test_ExecuteEpochExecuteEpochExecuteAccountAfterManyEpochsJumoMany() (gas: 1479103) +ExecuteEpochTest:test_ExecuteEpochExecuteEpochExecuteAccountAfterManyEpochsWithBrokenTime() (gas: 2520962) +ExecuteEpochTest:test_ExecuteEpochExecuteEpochExecuteAccountAfterManyEpochsWithBrokenTimeJumpMany() (gas: 1488795) +ExecuteEpochTest:test_ExecuteEpochNewEpoch() (gas: 1083687) +ExecuteEpochTest:test_ExecuteEpochShouldIncreaseEpoch() (gas: 92344) +ExecuteEpochTest:test_ExecuteEpochShouldIncreasePendingReward() (gas: 256338) ExecuteEpochTest:test_ExecuteEpochShouldNotIncreaseEpochBeforeEnd() (gas: 39028) ExecuteEpochTest:test_ExecuteEpochShouldNotIncreaseEpochInMigration() (gas: 149748) LeaveTest:testDeployment() (gas: 28806) @@ -27,15 +27,15 @@ LeaveTest:test_RevertWhen_SenderIsNotVault() (gas: 31995) LockTest:testDeployment() (gas: 28806) LockTest:test_NewLockupPeriod() (gas: 1330751) LockTest:test_RevertWhen_InvalidNewLockupPeriod() (gas: 1303059) -LockTest:test_RevertWhen_InvalidUpdateLockupPeriod() (gas: 1547562) +LockTest:test_RevertWhen_InvalidUpdateLockupPeriod() (gas: 1543826) LockTest:test_RevertWhen_SenderIsNotVault() (gas: 31812) LockTest:test_ShouldIncreaseBonusMP() (gas: 1313344) -LockTest:test_UpdateLockupPeriod() (gas: 1636200) +LockTest:test_UpdateLockupPeriod() (gas: 1634292) MigrateTest:testDeployment() (gas: 28806) MigrateTest:test_RevertWhen_NoPendingMigration() (gas: 1293784) MigrateTest:test_RevertWhen_SenderIsNotVault() (gas: 32007) MigrationInitializeTest:testDeployment() (gas: 28806) -MigrationInitializeTest:test_RevertWhen_MigrationPending() (gas: 5229403) +MigrationInitializeTest:test_RevertWhen_MigrationPending() (gas: 5216837) MigrationStakeManagerTest:testDeployment() (gas: 28806) MigrationStakeManagerTest:testNewDeployment() (gas: 30945) MigrationStakeManagerTest:test_ExecuteEpochShouldNotIncreaseEpochInMigration() (gas: 149713) @@ -57,11 +57,11 @@ UnstakeTest:testDeployment() (gas: 28828) UnstakeTest:test_RevertWhen_AmountMoreThanBalance() (gas: 1299127) UnstakeTest:test_RevertWhen_FundsLocked() (gas: 1343877) UnstakeTest:test_RevertWhen_SenderIsNotVault() (gas: 31879) -UnstakeTest:test_UnstakeShouldBurnMultiplierPoints() (gas: 6529254) +UnstakeTest:test_UnstakeShouldBurnMultiplierPoints() (gas: 6450051) UnstakeTest:test_UnstakeShouldReturnFund_NoLockUp() (gas: 1321289) -UnstakeTest:test_UnstakeShouldReturnFund_WithLockUp() (gas: 1441917) +UnstakeTest:test_UnstakeShouldReturnFund_WithLockUp() (gas: 1438949) UserFlowsTest:testDeployment() (gas: 28806) -UserFlowsTest:test_PendingMPToBeMintedCannotBeGreaterThanTotalSupplyMP(uint8,uint128) (runs: 106, μ: 131427031, ~: 130900495) -UserFlowsTest:test_StakeWithLockUpTimeLocksStake() (gas: 1483026) +UserFlowsTest:test_PendingMPToBeMintedCannotBeGreaterThanTotalSupplyMP(uint8,uint128) (runs: 106, μ: 130995099, ~: 130391755) +UserFlowsTest:test_StakeWithLockUpTimeLocksStake() (gas: 1480058) UserFlowsTest:test_StakedSupplyShouldIncreaseAndDecreaseAgain() (gas: 2496473) VaultFactoryTest:testDeployment() (gas: 9774) \ No newline at end of file diff --git a/contracts/StakeManager.sol b/contracts/StakeManager.sol index 34b33ed..5cce273 100644 --- a/contracts/StakeManager.sol +++ b/contracts/StakeManager.sol @@ -35,7 +35,6 @@ contract StakeManager is TrustedCodehashAccess { } struct Epoch { - uint256 startTime; uint256 epochReward; uint256 totalSupply; uint256 estimatedMP; @@ -118,18 +117,17 @@ contract StakeManager is TrustedCodehashAccess { totalMPPerEpoch -= expiredMP; expiredStakeStorage.deleteExpiredMP(tempCurrentEpoch); } - thisEpoch.estimatedMP = totalMPPerEpoch - currentEpochTotalExpiredMP; - delete currentEpochTotalExpiredMP; - pendingMPToBeMinted += thisEpoch.estimatedMP; - - //finalize current epoch + uint256 epochEstimatedMP = totalMPPerEpoch; if (tempCurrentEpoch == currentEpoch) { + epochEstimatedMP -= currentEpochTotalExpiredMP; + currentEpochTotalExpiredMP = 0; thisEpoch.epochReward = epochReward(); pendingReward += thisEpoch.epochReward; } - thisEpoch.totalSupply = totalSupply(); - //create new epoch + pendingMPToBeMinted += epochEstimatedMP; + thisEpoch.estimatedMP = epochEstimatedMP; + thisEpoch.totalSupply = totalSupply(); tempCurrentEpoch++; } currentEpoch = tempCurrentEpoch;