mirror of https://github.com/logos-co/staking.git
chore: update interface and update Solidity version to 0.8.27 across all files
This commit is contained in:
parent
2289457daf
commit
3f4f6a7aaf
127
.gas-report
127
.gas-report
|
@ -0,0 +1,127 @@
|
|||
| contracts/StakeManager.sol:StakeManager contract | | | | | |
|
||||
|--------------------------------------------------|-----------------|--------|--------|--------|---------|
|
||||
| Deployment Cost | Deployment Size | | | | |
|
||||
| 2600451 | 13644 | | | | |
|
||||
| Function Name | min | avg | median | max | # calls |
|
||||
| ACCURE_RATE | 328 | 328 | 328 | 328 | 1546 |
|
||||
| MAX_LOCKUP_PERIOD | 405 | 405 | 405 | 405 | 4 |
|
||||
| MAX_MULTIPLIER | 307 | 307 | 307 | 307 | 685 |
|
||||
| MIN_LOCKUP_PERIOD | 264 | 264 | 264 | 264 | 12 |
|
||||
| REWARD_TOKEN | 317 | 317 | 317 | 317 | 744 |
|
||||
| YEAR | 308 | 308 | 308 | 308 | 685 |
|
||||
| acceptUpdate | 23633 | 23633 | 23633 | 23633 | 1 |
|
||||
| accounts | 1572 | 1572 | 1572 | 1572 | 154869 |
|
||||
| calculateMP | 798 | 798 | 798 | 798 | 1372 |
|
||||
| currentEpoch | 384 | 1050 | 384 | 2384 | 54 |
|
||||
| epochEnd | 627 | 627 | 627 | 2627 | 25441 |
|
||||
| epochReward | 1381 | 2881 | 1381 | 5881 | 3 |
|
||||
| executeAccount(address) | 33469 | 110665 | 149264 | 149264 | 3 |
|
||||
| executeAccount(address,uint256) | 26562 | 72195 | 74101 | 199919 | 152455 |
|
||||
| executeEpoch() | 23435 | 120639 | 121820 | 900335 | 25330 |
|
||||
| executeEpoch(uint256) | 23861 | 24497 | 23861 | 26090 | 7 |
|
||||
| expiredStakeStorage | 416 | 2325 | 2416 | 2416 | 22 |
|
||||
| isTrustedCodehash | 541 | 944 | 541 | 2541 | 728 |
|
||||
| leave | 23675 | 23675 | 23675 | 23675 | 1 |
|
||||
| lock | 23840 | 23840 | 23840 | 23840 | 1 |
|
||||
| migration | 417 | 1417 | 1417 | 2417 | 4 |
|
||||
| migrationInitialize | 24646 | 24646 | 24646 | 24646 | 1 |
|
||||
| newEpoch | 463 | 463 | 463 | 463 | 5 |
|
||||
| owner | 2432 | 2432 | 2432 | 2432 | 13 |
|
||||
| pendingReward | 408 | 1442 | 2408 | 2408 | 29 |
|
||||
| potentialMP | 408 | 408 | 408 | 408 | 49964 |
|
||||
| previousManager | 297 | 297 | 297 | 297 | 13 |
|
||||
| setTrustedCodehash | 47982 | 47982 | 47982 | 47982 | 147 |
|
||||
| stake | 24047 | 24047 | 24047 | 24047 | 1 |
|
||||
| startMigration | 103624 | 103632 | 103636 | 103636 | 3 |
|
||||
| startTime | 306 | 306 | 306 | 306 | 21 |
|
||||
| totalMP | 385 | 385 | 385 | 2385 | 49985 |
|
||||
| totalStaked | 386 | 1786 | 2386 | 2386 | 20 |
|
||||
| totalSupply | 784 | 1965 | 2784 | 2784 | 22 |
|
||||
| unstake | 23841 | 23841 | 23841 | 23841 | 1 |
|
||||
|
||||
|
||||
| contracts/StakeVault.sol:StakeVault contract | | | | | |
|
||||
|----------------------------------------------|-----------------|--------|--------|--------|---------|
|
||||
| Deployment Cost | Deployment Size | | | | |
|
||||
| 0 | 0 | | | | |
|
||||
| Function Name | min | avg | median | max | # calls |
|
||||
| STAKING_TOKEN | 193 | 193 | 193 | 193 | 2 |
|
||||
| acceptMigration | 35141 | 35141 | 35141 | 35141 | 2 |
|
||||
| leave | 35196 | 35196 | 35196 | 35196 | 1 |
|
||||
| lock | 43196 | 71076 | 62042 | 162843 | 7 |
|
||||
| owner | 318 | 318 | 318 | 318 | 727 |
|
||||
| stake | 27291 | 282802 | 266296 | 351880 | 732 |
|
||||
| unstake | 40179 | 88236 | 78765 | 184769 | 11 |
|
||||
|
||||
|
||||
| contracts/VaultFactory.sol:VaultFactory contract | | | | | |
|
||||
|--------------------------------------------------|-----------------|--------|--------|--------|---------|
|
||||
| Deployment Cost | Deployment Size | | | | |
|
||||
| 0 | 0 | | | | |
|
||||
| Function Name | min | avg | median | max | # calls |
|
||||
| createVault | 682927 | 682927 | 682927 | 682927 | 731 |
|
||||
| setStakeManager | 23710 | 26669 | 26076 | 30222 | 3 |
|
||||
| stakeManager | 368 | 1868 | 2368 | 2368 | 4 |
|
||||
|
||||
|
||||
| contracts/storage/ExpiredStakeStorage.sol:ExpiredStakeStorage contract | | | | | |
|
||||
|------------------------------------------------------------------------|-----------------|-------|--------|-------|---------|
|
||||
| Deployment Cost | Deployment Size | | | | |
|
||||
| 0 | 0 | | | | |
|
||||
| Function Name | min | avg | median | max | # calls |
|
||||
| getExpiredMP | 2427 | 2427 | 2427 | 2427 | 25486 |
|
||||
| transferOwnership | 28533 | 28533 | 28533 | 28533 | 1 |
|
||||
|
||||
|
||||
| script/Deploy.s.sol:Deploy contract | | | | | |
|
||||
|-------------------------------------|-----------------|---------|---------|---------|---------|
|
||||
| Deployment Cost | Deployment Size | | | | |
|
||||
| 6220738 | 29931 | | | | |
|
||||
| Function Name | min | avg | median | max | # calls |
|
||||
| run | 5420174 | 5420174 | 5420174 | 5420174 | 66 |
|
||||
|
||||
|
||||
| script/DeployMigrationStakeManager.s.sol:DeployMigrationStakeManager contract | | | | | |
|
||||
|-------------------------------------------------------------------------------|-----------------|---------|---------|---------|---------|
|
||||
| Deployment Cost | Deployment Size | | | | |
|
||||
| 3412741 | 16827 | | | | |
|
||||
| Function Name | min | avg | median | max | # calls |
|
||||
| run | 2427736 | 2427736 | 2427736 | 2427736 | 19 |
|
||||
|
||||
|
||||
| script/DeploymentConfig.s.sol:DeploymentConfig contract | | | | | |
|
||||
|---------------------------------------------------------|-----------------|-----|--------|-----|---------|
|
||||
| Deployment Cost | Deployment Size | | | | |
|
||||
| 0 | 0 | | | | |
|
||||
| Function Name | min | avg | median | max | # calls |
|
||||
| activeNetworkConfig | 455 | 455 | 455 | 455 | 132 |
|
||||
|
||||
|
||||
| test/mocks/BrokenERC20.s.sol:BrokenERC20 contract | | | | | |
|
||||
|---------------------------------------------------|-----------------|-------|--------|-------|---------|
|
||||
| Deployment Cost | Deployment Size | | | | |
|
||||
| 0 | 0 | | | | |
|
||||
| Function Name | min | avg | median | max | # calls |
|
||||
| approve | 46175 | 46175 | 46175 | 46175 | 1 |
|
||||
| balanceOf | 561 | 1227 | 561 | 2561 | 3 |
|
||||
|
||||
|
||||
| test/mocks/MockERC20.sol:MockERC20 contract | | | | | |
|
||||
|---------------------------------------------|-----------------|-------|--------|-------|---------|
|
||||
| Deployment Cost | Deployment Size | | | | |
|
||||
| 0 | 0 | | | | |
|
||||
| Function Name | min | avg | median | max | # calls |
|
||||
| approve | 46175 | 46235 | 46199 | 46367 | 727 |
|
||||
| balanceOf | 561 | 2127 | 2561 | 2561 | 32612 |
|
||||
|
||||
|
||||
| test/script/DeployBroken.s.sol:DeployBroken contract | | | | | |
|
||||
|------------------------------------------------------|-----------------|---------|---------|---------|---------|
|
||||
| Deployment Cost | Deployment Size | | | | |
|
||||
| 4918894 | 23867 | | | | |
|
||||
| Function Name | min | avg | median | max | # calls |
|
||||
| run | 4266410 | 4266410 | 4266410 | 4266410 | 1 |
|
||||
|
||||
|
||||
|
||||
|
122
.gas-snapshot
122
.gas-snapshot
|
@ -1,67 +1,67 @@
|
|||
CreateVaultTest:testDeployment() (gas: 9774)
|
||||
CreateVaultTest:test_createVault() (gas: 699564)
|
||||
ExecuteAccountTest:testDeployment() (gas: 28828)
|
||||
ExecuteAccountTest:test_ExecuteAccountLimit() (gas: 1564735)
|
||||
ExecuteAccountTest:test_ExecuteAccountMintMP() (gas: 5252076)
|
||||
ExecuteAccountTest:test_RevertWhen_InvalidLimitEpoch() (gas: 1772992)
|
||||
ExecuteAccountTest:test_ShouldNotMintMoreThanCap() (gas: 320738328)
|
||||
ExecuteEpochTest:testDeployment() (gas: 28829)
|
||||
ExecuteEpochTest:testNewDeployment() (gas: 30901)
|
||||
ExecuteEpochTest:test_ExecuteEpochExecuteAccountAfterEpochEnd() (gas: 1353515)
|
||||
ExecuteEpochTest:test_ExecuteEpochExecuteAccountAfterManyEpochsJumoMany() (gas: 1371040)
|
||||
ExecuteEpochTest:test_ExecuteEpochExecuteAccountAfterManyEpochsWithBrokenTime() (gas: 1616635)
|
||||
ExecuteEpochTest:test_ExecuteEpochExecuteAccountAfterManyEpochsWithBrokenTimeJumpMany() (gas: 1380975)
|
||||
ExecuteEpochTest:test_ExecuteEpochExecuteEpochAfterEnd() (gas: 1914097)
|
||||
ExecuteEpochTest:test_ExecuteEpochExecuteEpochExecuteAccountAfterManyEpochs() (gas: 2496675)
|
||||
ExecuteEpochTest:test_ExecuteEpochExecuteEpochExecuteAccountAfterManyEpochsJumoMany() (gas: 1464542)
|
||||
ExecuteEpochTest:test_ExecuteEpochExecuteEpochExecuteAccountAfterManyEpochsWithBrokenTime() (gas: 2506631)
|
||||
ExecuteEpochTest:test_ExecuteEpochExecuteEpochExecuteAccountAfterManyEpochsWithBrokenTimeJumpMany() (gas: 1474454)
|
||||
ExecuteEpochTest:test_ExecuteEpochNewEpoch() (gas: 1083709)
|
||||
ExecuteEpochTest:test_ExecuteEpochShouldIncreaseEpoch() (gas: 92344)
|
||||
ExecuteEpochTest:test_ExecuteEpochShouldIncreasePendingReward() (gas: 256303)
|
||||
ExecuteEpochTest:test_ExecuteEpochShouldNotIncreaseEpochBeforeEnd() (gas: 39028)
|
||||
ExecuteEpochTest:test_ExecuteEpochShouldNotIncreaseEpochInMigration() (gas: 149770)
|
||||
LeaveTest:testDeployment() (gas: 28806)
|
||||
LeaveTest:test_RevertWhen_NoPendingMigration() (gas: 1315087)
|
||||
LeaveTest:test_RevertWhen_SenderIsNotVault() (gas: 31696)
|
||||
LockTest:testDeployment() (gas: 28806)
|
||||
LockTest:test_NewLockupPeriod() (gas: 1313929)
|
||||
LockTest:test_RevertWhen_InvalidNewLockupPeriod() (gas: 1288722)
|
||||
LockTest:test_RevertWhen_InvalidUpdateLockupPeriod() (gas: 1529335)
|
||||
LockTest:test_RevertWhen_SenderIsNotVault() (gas: 31856)
|
||||
LockTest:test_ShouldIncreaseBonusMP() (gas: 1296480)
|
||||
LockTest:test_UpdateLockupPeriod() (gas: 1565467)
|
||||
MigrateTest:testDeployment() (gas: 28806)
|
||||
MigrateTest:test_RevertWhen_NoPendingMigration() (gas: 1279254)
|
||||
MigrateTest:test_RevertWhen_SenderIsNotVault() (gas: 31738)
|
||||
MigrationInitializeTest:testDeployment() (gas: 28806)
|
||||
MigrationInitializeTest:test_RevertWhen_MigrationPending() (gas: 5275163)
|
||||
MigrationStakeManagerTest:testDeployment() (gas: 28806)
|
||||
MigrationStakeManagerTest:testNewDeployment() (gas: 30945)
|
||||
MigrationStakeManagerTest:test_ExecuteEpochShouldNotIncreaseEpochInMigration() (gas: 149735)
|
||||
CreateVaultTest:test_createVault() (gas: 700333)
|
||||
ExecuteAccountTest:testDeployment() (gas: 28875)
|
||||
ExecuteAccountTest:test_ExecuteAccountLimit() (gas: 1559514)
|
||||
ExecuteAccountTest:test_ExecuteAccountMintMP() (gas: 5232040)
|
||||
ExecuteAccountTest:test_RevertWhen_InvalidLimitEpoch() (gas: 1769214)
|
||||
ExecuteAccountTest:test_ShouldNotMintMoreThanCap() (gas: 320225995)
|
||||
ExecuteEpochTest:testDeployment() (gas: 28876)
|
||||
ExecuteEpochTest:testNewDeployment() (gas: 30948)
|
||||
ExecuteEpochTest:test_ExecuteEpochExecuteAccountAfterEpochEnd() (gas: 1350443)
|
||||
ExecuteEpochTest:test_ExecuteEpochExecuteAccountAfterManyEpochsJumoMany() (gas: 1367228)
|
||||
ExecuteEpochTest:test_ExecuteEpochExecuteAccountAfterManyEpochsWithBrokenTime() (gas: 1613317)
|
||||
ExecuteEpochTest:test_ExecuteEpochExecuteAccountAfterManyEpochsWithBrokenTimeJumpMany() (gas: 1377593)
|
||||
ExecuteEpochTest:test_ExecuteEpochExecuteEpochAfterEnd() (gas: 1910717)
|
||||
ExecuteEpochTest:test_ExecuteEpochExecuteEpochExecuteAccountAfterManyEpochs() (gas: 2492323)
|
||||
ExecuteEpochTest:test_ExecuteEpochExecuteEpochExecuteAccountAfterManyEpochsJumoMany() (gas: 1460710)
|
||||
ExecuteEpochTest:test_ExecuteEpochExecuteEpochExecuteAccountAfterManyEpochsWithBrokenTime() (gas: 2502709)
|
||||
ExecuteEpochTest:test_ExecuteEpochExecuteEpochExecuteAccountAfterManyEpochsWithBrokenTimeJumpMany() (gas: 1471052)
|
||||
ExecuteEpochTest:test_ExecuteEpochNewEpoch() (gas: 1083615)
|
||||
ExecuteEpochTest:test_ExecuteEpochShouldIncreaseEpoch() (gas: 92277)
|
||||
ExecuteEpochTest:test_ExecuteEpochShouldIncreasePendingReward() (gas: 252659)
|
||||
ExecuteEpochTest:test_ExecuteEpochShouldNotIncreaseEpochBeforeEnd() (gas: 38961)
|
||||
ExecuteEpochTest:test_ExecuteEpochShouldNotIncreaseEpochInMigration() (gas: 149703)
|
||||
LeaveTest:testDeployment() (gas: 28853)
|
||||
LeaveTest:test_RevertWhen_NoPendingMigration() (gas: 1311974)
|
||||
LeaveTest:test_RevertWhen_SenderIsNotVault() (gas: 31740)
|
||||
LockTest:testDeployment() (gas: 28853)
|
||||
LockTest:test_NewLockupPeriod() (gas: 1310978)
|
||||
LockTest:test_RevertWhen_InvalidNewLockupPeriod() (gas: 1285586)
|
||||
LockTest:test_RevertWhen_InvalidUpdateLockupPeriod() (gas: 1406860)
|
||||
LockTest:test_RevertWhen_SenderIsNotVault() (gas: 31834)
|
||||
LockTest:test_ShouldIncreaseBonusMP() (gas: 1293620)
|
||||
LockTest:test_UpdateLockupPeriod() (gas: 1470415)
|
||||
MigrateTest:testDeployment() (gas: 28853)
|
||||
MigrateTest:test_RevertWhen_NoPendingMigration() (gas: 1276097)
|
||||
MigrateTest:test_RevertWhen_SenderIsNotVault() (gas: 31739)
|
||||
MigrationInitializeTest:testDeployment() (gas: 28853)
|
||||
MigrationInitializeTest:test_RevertWhen_MigrationPending() (gas: 5451158)
|
||||
MigrationStakeManagerTest:testDeployment() (gas: 28853)
|
||||
MigrationStakeManagerTest:testNewDeployment() (gas: 30992)
|
||||
MigrationStakeManagerTest:test_ExecuteEpochShouldNotIncreaseEpochInMigration() (gas: 149668)
|
||||
SetStakeManagerTest:testDeployment() (gas: 9774)
|
||||
SetStakeManagerTest:test_RevertWhen_InvalidStakeManagerAddress() (gas: 63105)
|
||||
SetStakeManagerTest:test_SetStakeManager() (gas: 41301)
|
||||
StakeManagerTest:testDeployment() (gas: 28578)
|
||||
StakeTest:testDeployment() (gas: 28784)
|
||||
StakeTest:test_RevertWhen_InvalidLockupPeriod() (gas: 1061162)
|
||||
StakeTest:test_RevertWhen_Restake() (gas: 1304182)
|
||||
StakeTest:test_RevertWhen_RestakeWithLock() (gas: 1308012)
|
||||
StakeTest:test_RevertWhen_SenderIsNotVault() (gas: 32040)
|
||||
StakeTest:test_RevertWhen_StakeIsTooLow() (gas: 802919)
|
||||
StakeTest:test_RevertWhen_StakeTokenTransferFails() (gas: 211363)
|
||||
StakeTest:test_StakeWithLockBonusMP() (gas: 2327824)
|
||||
StakeTest:test_StakeWithoutLockUpTimeMintsMultiplierPoints() (gas: 1300293)
|
||||
StakedTokenTest:testStakeToken() (gas: 7619)
|
||||
UnstakeTest:testDeployment() (gas: 28828)
|
||||
UnstakeTest:test_RevertWhen_AmountMoreThanBalance() (gas: 1284745)
|
||||
UnstakeTest:test_RevertWhen_FundsLocked() (gas: 1329288)
|
||||
StakeManagerTest:testDeployment() (gas: 28625)
|
||||
StakeTest:testDeployment() (gas: 28831)
|
||||
StakeTest:test_RevertWhen_InvalidLockupPeriod() (gas: 1057656)
|
||||
StakeTest:test_RevertWhen_Restake() (gas: 1301092)
|
||||
StakeTest:test_RevertWhen_RestakeWithLock() (gas: 1304525)
|
||||
StakeTest:test_RevertWhen_SenderIsNotVault() (gas: 32082)
|
||||
StakeTest:test_RevertWhen_StakeIsTooLow() (gas: 803915)
|
||||
StakeTest:test_RevertWhen_StakeTokenTransferFails() (gas: 207758)
|
||||
StakeTest:test_StakeWithLockBonusMP() (gas: 2323783)
|
||||
StakeTest:test_StakeWithoutLockUpTimeMintsMultiplierPoints() (gas: 1297379)
|
||||
StakedTokenTest:testStakeToken() (gas: 7597)
|
||||
UnstakeTest:testDeployment() (gas: 28875)
|
||||
UnstakeTest:test_RevertWhen_AmountMoreThanBalance() (gas: 1281609)
|
||||
UnstakeTest:test_RevertWhen_FundsLocked() (gas: 1325777)
|
||||
UnstakeTest:test_RevertWhen_SenderIsNotVault() (gas: 31879)
|
||||
UnstakeTest:test_UnstakeShouldBurnMultiplierPoints() (gas: 6438180)
|
||||
UnstakeTest:test_UnstakeShouldReturnFund_NoLockUp() (gas: 1306895)
|
||||
UnstakeTest:test_UnstakeShouldReturnFund_WithLockUp() (gas: 1424419)
|
||||
UserFlowsTest:testDeployment() (gas: 28806)
|
||||
UserFlowsTest:test_PendingMPToBeMintedCannotBeGreaterThanTotalSupplyMP(uint8,uint128) (runs: 106, μ: 130825949, ~: 130282915)
|
||||
UserFlowsTest:test_StakeWithLockUpTimeLocksStake() (gas: 1463005)
|
||||
UserFlowsTest:test_StakedSupplyShouldIncreaseAndDecreaseAgain() (gas: 2467653)
|
||||
UnstakeTest:test_UnstakeShouldBurnMultiplierPoints() (gas: 6432067)
|
||||
UnstakeTest:test_UnstakeShouldReturnFund_NoLockUp() (gas: 1303800)
|
||||
UnstakeTest:test_UnstakeShouldReturnFund_WithLockUp() (gas: 1387208)
|
||||
UserFlowsTest:testDeployment() (gas: 28853)
|
||||
UserFlowsTest:test_PendingMPToBeMintedCannotBeGreaterThanTotalSupplyMP(uint8,uint128) (runs: 114, μ: 130857603, ~: 130246926)
|
||||
UserFlowsTest:test_StakeWithLockUpTimeLocksStake() (gas: 1425816)
|
||||
UserFlowsTest:test_StakedSupplyShouldIncreaseAndDecreaseAgain() (gas: 2461484)
|
||||
VaultFactoryTest:testDeployment() (gas: 9774)
|
|
@ -140,7 +140,7 @@ jobs:
|
|||
|
||||
- name: Install Solidity
|
||||
run: |
|
||||
wget https://github.com/ethereum/solidity/releases/download/v0.8.26/solc-static-linux
|
||||
wget https://github.com/ethereum/solidity/releases/download/v0.8.27/solc-static-linux
|
||||
chmod +x solc-static-linux
|
||||
sudo mv solc-static-linux /usr/local/bin/solc
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.8.26;
|
||||
pragma solidity ^0.8.27;
|
||||
|
||||
import { StakeManager } from "../../contracts/StakeManager.sol";
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.8.26;
|
||||
pragma solidity ^0.8.27;
|
||||
|
||||
import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.8.26;
|
||||
pragma solidity ^0.8.27;
|
||||
|
||||
import { ExpiredStakeStorage } from "./../../contracts/storage/ExpiredStakeStorage.sol";
|
||||
|
||||
|
|
|
@ -1,23 +1,24 @@
|
|||
// SPDX-License-Identifier: MIT-1.0
|
||||
pragma solidity ^0.8.26;
|
||||
pragma solidity ^0.8.27;
|
||||
|
||||
import { Math } from "@openzeppelin/contracts/utils/math/Math.sol";
|
||||
import { IStakeConstants } from "./interfaces/IStakeConstants.sol";
|
||||
|
||||
abstract contract MultiplierPointMath {
|
||||
abstract contract MultiplierPointMath is IStakeConstants {
|
||||
/// @notice One (mean) tropical year, in seconds.
|
||||
uint256 public constant YEAR = 365 days + 5 hours + 48 minutes + 45 seconds;
|
||||
/// @notice Multiplier points annual percentage yield.
|
||||
uint256 public constant MP_APY = 100;
|
||||
/// @notice Accrued multiplier points maximum multiplier.
|
||||
uint256 public constant MAX_MULTIPLIER = 4;
|
||||
/// @notice Multiplier points annual percentage yield.
|
||||
uint256 public constant MP_APY = 100;
|
||||
/// @notice Multiplier points accrued maximum percentage yield.
|
||||
uint256 public constant MP_MPY = MAX_MULTIPLIER * MP_APY;
|
||||
/// @notice Multiplier points absolute maximum percentage yield.
|
||||
uint256 public constant MP_MPY_ABSOLUTE = 100 + (2 * (MAX_MULTIPLIER * MP_APY));
|
||||
/// @notice The accrue rate period of time over which multiplier points are calculated.
|
||||
uint256 public constant ACCURE_RATE = 1 weeks;
|
||||
/// @notice Minimal value to generate 1 multiplier point in the accrue rate period (rounded up).
|
||||
uint256 public constant MIN_BALANCE = (((YEAR * 100) - 1) / (MP_APY * ACCURE_RATE)) + 1;
|
||||
/// @notice Multiplier points absolute maximum multiplier
|
||||
uint256 public constant MAX_MULTIPLIER_ABSOLUTE = 1 + (2 * (MAX_MULTIPLIER * MP_APY) / 100);
|
||||
/// @notice Maximum lockup period
|
||||
uint256 public constant MAX_LOCKUP_PERIOD = MAX_MULTIPLIER * YEAR;
|
||||
|
||||
/**
|
||||
* @notice Calculates the accrued multiplier points (MPs) over a time period Δt, based on the account balance
|
||||
|
@ -25,10 +26,8 @@ abstract contract MultiplierPointMath {
|
|||
* @param _deltaTime The time difference or the duration over which the multiplier points are accrued, expressed in
|
||||
* seconds
|
||||
* @return _accuredMP points accured for given `_amount` and `_seconds`
|
||||
* 51584438
|
||||
* 10000000
|
||||
*/
|
||||
function _calculateAccuredMP(uint256 _balance, uint256 _deltaTime) public pure returns (uint256 _accuredMP) {
|
||||
function _calculateAccuredMP(uint256 _balance, uint256 _deltaTime) internal pure returns (uint256 _accuredMP) {
|
||||
return Math.mulDiv(_balance, _deltaTime * MP_APY, YEAR * 100);
|
||||
}
|
||||
|
||||
|
@ -41,7 +40,7 @@ abstract contract MultiplierPointMath {
|
|||
* @param _lockedSeconds time in seconds locked
|
||||
* @return _bonusMP bonus multiplier points for given `_amount` and `_lockedSeconds`
|
||||
*/
|
||||
function _calculateBonusMP(uint256 _amount, uint256 _lockedSeconds) public pure returns (uint256 _bonusMP) {
|
||||
function _calculateBonusMP(uint256 _amount, uint256 _lockedSeconds) internal pure returns (uint256 _bonusMP) {
|
||||
return _calculateAccuredMP(_amount, _lockedSeconds);
|
||||
}
|
||||
|
||||
|
@ -50,7 +49,7 @@ abstract contract MultiplierPointMath {
|
|||
* the amount of balance added.
|
||||
* @param _amount Represents the change in balance.
|
||||
*/
|
||||
function _calculateInitialMP(uint256 _amount) public pure returns (uint256 _initialMP) {
|
||||
function _calculateInitialMP(uint256 _amount) internal pure returns (uint256 _initialMP) {
|
||||
return _amount;
|
||||
}
|
||||
|
||||
|
@ -81,8 +80,8 @@ abstract contract MultiplierPointMath {
|
|||
* @param _balance quantity of tokens
|
||||
* @return _maxMPAccured maximum quantity of muliplier points that can be generated for given `_amount`
|
||||
*/
|
||||
function _calculateMaxAccuredMP(uint256 _balance) public pure returns (uint256 _maxMPAccured) {
|
||||
return Math.mulDiv(_balance, MAX_MULTIPLIER * MP_APY, 100);
|
||||
function _calculateMaxAccuredMP(uint256 _balance) internal pure returns (uint256 _maxMPAccured) {
|
||||
return Math.mulDiv(_balance, MP_MPY, 100);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -92,21 +91,10 @@ abstract contract MultiplierPointMath {
|
|||
* @param _lockTime The time duration for which the balance is locked
|
||||
* @return _maxMP Maximum multiplier points that can be generated for given `_balance` and `_lockTime`
|
||||
*/
|
||||
function _calculateMaxMP(uint256 _balance, uint256 _lockTime) public pure returns (uint256 _maxMP) {
|
||||
function _calculateMaxMP(uint256 _balance, uint256 _lockTime) internal pure returns (uint256 _maxMP) {
|
||||
return _balance + Math.mulDiv(_balance * MP_APY, (MAX_MULTIPLIER * YEAR) + _lockTime, YEAR * 100);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Caution: This value is estimated and can be incorrect due precision loss.
|
||||
* @notice Estimates the time an account set as locked time.
|
||||
* @param _mpMax Maximum multiplier points calculated from the current balance.
|
||||
* @param _currentBalance Current balance used to calculate the maximum multiplier points.
|
||||
*/
|
||||
function _estimateLockTime(uint256 _mpMax, uint256 _currentBalance) public pure returns (uint256 _lockTime) {
|
||||
return Math.mulDiv((_mpMax - _currentBalance) * 100, YEAR, _currentBalance * MP_APY, Math.Rounding.Ceil)
|
||||
- MAX_LOCKUP_PERIOD;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Caution: This value is estimated and can be incorrect due precision loss.
|
||||
* @notice Calculates the remaining lock time available for a given `_mpMax` and `_currentBalance`
|
||||
|
@ -121,15 +109,15 @@ abstract contract MultiplierPointMath {
|
|||
pure
|
||||
returns (uint256 _lockTime)
|
||||
{
|
||||
return Math.mulDiv((_currentBalance * MAX_MULTIPLIER_ABSOLUTE) - _mpMax, YEAR, _currentBalance);
|
||||
return Math.mulDiv((_currentBalance * MP_MPY_ABSOLUTE) - _mpMax, YEAR, _currentBalance * 100);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice Calculates the lock time for a given bonus multiplier points and current balance.
|
||||
* @notice Calculates the lock time for a given bonus multiplier points\ and current balance.
|
||||
* @param _bonusMP bonus multiplier points intended to be generated
|
||||
* @param _currentBalance current balance
|
||||
*/
|
||||
function _calculateLockTime(uint256 _bonusMP, uint256 _currentBalance) public pure returns (uint256 _lockTime) {
|
||||
function _calculateLockTime(uint256 _bonusMP, uint256 _currentBalance) internal pure returns (uint256 _lockTime) {
|
||||
return Math.mulDiv(_bonusMP * 100, YEAR, _currentBalance * MP_APY);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +1,18 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.8.18;
|
||||
pragma solidity ^0.8.27;
|
||||
|
||||
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
||||
import { Math } from "@openzeppelin/contracts/utils/math/Math.sol";
|
||||
|
||||
import { TrustedCodehashAccess } from "./access/TrustedCodehashAccess.sol";
|
||||
import { ExpiredStakeStorage } from "./storage/ExpiredStakeStorage.sol";
|
||||
import { IStakeManager } from "./IStakeManager.sol";
|
||||
import { IStakeManager } from "./interfaces/IStakeManager.sol";
|
||||
import { MultiplierPointMath } from "./MultiplierPointMath.sol";
|
||||
import { StakeMath } from "./StakeMath.sol";
|
||||
import { StakeVault } from "./StakeVault.sol";
|
||||
|
||||
contract StakeManager is IStakeManager, MultiplierPointMath, TrustedCodehashAccess {
|
||||
contract StakeManager is StakeMath, TrustedCodehashAccess, IStakeManager {
|
||||
error StakeManager__NoPendingMigration();
|
||||
error StakeManager__PendingMigration();
|
||||
error StakeManager__SenderIsNotPreviousStakeManager();
|
||||
|
@ -38,10 +39,6 @@ contract StakeManager is IStakeManager, MultiplierPointMath, TrustedCodehashAcce
|
|||
uint256 potentialMP;
|
||||
}
|
||||
|
||||
uint256 public constant EPOCH_SIZE = 1 weeks;
|
||||
uint256 public constant MIN_LOCKUP_PERIOD = 2 weeks;
|
||||
uint256 public constant MAX_LOCKUP_PERIOD = 4 * YEAR; // 4 years
|
||||
|
||||
mapping(address index => Account value) public accounts;
|
||||
mapping(uint256 index => Epoch value) public epochs;
|
||||
|
||||
|
@ -60,7 +57,8 @@ contract StakeManager is IStakeManager, MultiplierPointMath, TrustedCodehashAcce
|
|||
|
||||
StakeManager public migration;
|
||||
StakeManager public immutable previousManager;
|
||||
IERC20 public immutable rewardToken;
|
||||
IERC20 public immutable REWARD_TOKEN;
|
||||
IERC20 public immutable STAKING_TOKEN;
|
||||
|
||||
modifier onlyAccountInitialized(address account) {
|
||||
if (accounts[account].lockUntil == 0) {
|
||||
|
@ -131,7 +129,8 @@ contract StakeManager is IStakeManager, MultiplierPointMath, TrustedCodehashAcce
|
|||
constructor(address _REWARD_TOKEN, address _previousManager) {
|
||||
startTime = (_previousManager == address(0)) ? block.timestamp : StakeManager(_previousManager).startTime();
|
||||
previousManager = StakeManager(_previousManager);
|
||||
rewardToken = IERC20(_REWARD_TOKEN);
|
||||
REWARD_TOKEN = IERC20(_REWARD_TOKEN);
|
||||
STAKING_TOKEN = IERC20(_REWARD_TOKEN);
|
||||
if (address(previousManager) != address(0)) {
|
||||
expiredStakeStorage = previousManager.expiredStakeStorage();
|
||||
} else {
|
||||
|
@ -158,7 +157,7 @@ contract StakeManager is IStakeManager, MultiplierPointMath, TrustedCodehashAcce
|
|||
}
|
||||
|
||||
//mp estimation
|
||||
uint256 mpPerEpoch = _calculateAccuredMP(_amount, EPOCH_SIZE);
|
||||
uint256 mpPerEpoch = _calculateAccuredMP(_amount, ACCURE_RATE);
|
||||
if (mpPerEpoch < 1) {
|
||||
revert StakeManager__StakeIsTooLow();
|
||||
}
|
||||
|
@ -167,7 +166,7 @@ contract StakeManager is IStakeManager, MultiplierPointMath, TrustedCodehashAcce
|
|||
uint256 epochAmountToReachMpLimit = (maxMpToMint) / mpPerEpoch;
|
||||
uint256 mpLimitEpoch = currentEpoch + epochAmountToReachMpLimit;
|
||||
uint256 lastEpochAmountToMint = ((mpPerEpoch * (epochAmountToReachMpLimit + 1)) - maxMpToMint);
|
||||
uint256 bonusMP = _calculateBonusMP(_amount, _seconds);
|
||||
uint256 bonusMP = _calculateInitialMP(_amount) + _calculateBonusMP(_amount, _seconds);
|
||||
|
||||
// account initialization
|
||||
accounts[msg.sender] = Account({
|
||||
|
@ -212,7 +211,7 @@ contract StakeManager is IStakeManager, MultiplierPointMath, TrustedCodehashAcce
|
|||
uint256 reducedMP = Math.mulDiv(_amount, account.totalMP, account.balance);
|
||||
uint256 reducedInitialMP = Math.mulDiv(_amount, account.bonusMP, account.balance);
|
||||
|
||||
uint256 mpPerEpoch = _calculateAccuredMP(account.balance, EPOCH_SIZE);
|
||||
uint256 mpPerEpoch = _calculateAccuredMP(account.balance, ACCURE_RATE);
|
||||
expiredStakeStorage.decrementExpiredMP(account.mpLimitEpoch, mpPerEpoch);
|
||||
if (account.mpLimitEpoch < currentEpoch) {
|
||||
totalMPPerEpoch -= mpPerEpoch;
|
||||
|
@ -322,7 +321,7 @@ contract StakeManager is IStakeManager, MultiplierPointMath, TrustedCodehashAcce
|
|||
revert StakeManager__InvalidMigration();
|
||||
}
|
||||
migration = _migration;
|
||||
rewardToken.transfer(address(migration), epochReward());
|
||||
REWARD_TOKEN.transfer(address(migration), epochReward());
|
||||
expiredStakeStorage.transferOwnership(address(_migration));
|
||||
migration.migrationInitialize(
|
||||
currentEpoch, totalMP, totalStaked, startTime, totalMPPerEpoch, potentialMP, currentEpochTotalExpiredMP
|
||||
|
@ -368,7 +367,7 @@ contract StakeManager is IStakeManager, MultiplierPointMath, TrustedCodehashAcce
|
|||
* @notice Transfer current epoch funds for migrated manager
|
||||
*/
|
||||
function transferNonPending() external onlyPendingMigration {
|
||||
rewardToken.transfer(address(migration), epochReward());
|
||||
REWARD_TOKEN.transfer(address(migration), epochReward());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -448,7 +447,7 @@ contract StakeManager is IStakeManager, MultiplierPointMath, TrustedCodehashAcce
|
|||
while (userEpoch < _limitEpoch) {
|
||||
Epoch storage iEpoch = epochs[userEpoch];
|
||||
//mint multiplier points to that epoch
|
||||
_mintMP(account, startTime + (EPOCH_SIZE * (userEpoch + 1)), iEpoch);
|
||||
_mintMP(account, startTime + (ACCURE_RATE * (userEpoch + 1)), iEpoch);
|
||||
uint256 userSupply = account.balance + account.totalMP;
|
||||
uint256 userEpochReward = Math.mulDiv(userSupply, iEpoch.epochReward, iEpoch.totalSupply);
|
||||
userReward += userEpochReward;
|
||||
|
@ -463,7 +462,7 @@ contract StakeManager is IStakeManager, MultiplierPointMath, TrustedCodehashAcce
|
|||
account.epoch = userEpoch;
|
||||
if (userReward > 0) {
|
||||
pendingReward -= userReward;
|
||||
rewardToken.transfer(account.rewardAddress, userReward);
|
||||
REWARD_TOKEN.transfer(account.rewardAddress, userReward);
|
||||
}
|
||||
if (address(migration) != address(0)) {
|
||||
mpDifference = account.totalMP - mpDifference;
|
||||
|
@ -565,7 +564,7 @@ contract StakeManager is IStakeManager, MultiplierPointMath, TrustedCodehashAcce
|
|||
* @return _epochReward current epoch reward
|
||||
*/
|
||||
function epochReward() public view returns (uint256 _epochReward) {
|
||||
return rewardToken.balanceOf(address(this)) - pendingReward;
|
||||
return REWARD_TOKEN.balanceOf(address(this)) - pendingReward;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -573,7 +572,7 @@ contract StakeManager is IStakeManager, MultiplierPointMath, TrustedCodehashAcce
|
|||
* @return _epochEnd end time of current epoch
|
||||
*/
|
||||
function epochEnd() public view returns (uint256 _epochEnd) {
|
||||
return startTime + (EPOCH_SIZE * (currentEpoch + 1));
|
||||
return startTime + (ACCURE_RATE * (currentEpoch + 1));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -581,6 +580,6 @@ contract StakeManager is IStakeManager, MultiplierPointMath, TrustedCodehashAcce
|
|||
* @return _newEpoch the number of the epoch after all epochs that can be processed
|
||||
*/
|
||||
function newEpoch() public view returns (uint256 _newEpoch) {
|
||||
_newEpoch = (block.timestamp - startTime) / EPOCH_SIZE;
|
||||
_newEpoch = (block.timestamp - startTime) / ACCURE_RATE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
// SPDX-License-Identifier: MIT-1.0
|
||||
pragma solidity ^0.8.26;
|
||||
pragma solidity ^0.8.27;
|
||||
|
||||
import { Math } from "@openzeppelin/contracts/utils/math/Math.sol";
|
||||
import { MultiplierPointMath } from "./MultiplierPointMath.sol";
|
||||
|
||||
abstract contract StakeMath is MultiplierPointMath {
|
||||
/// @notice Minimal lockup time
|
||||
uint256 public constant MIN_LOCKUP_TIME = 1 weeks;
|
||||
uint256 public constant MIN_LOCKUP_PERIOD = 1 weeks;
|
||||
/// @notice Maximum lockup period
|
||||
uint256 public constant MAX_LOCKUP_PERIOD = MAX_MULTIPLIER * YEAR;
|
||||
|
||||
/**
|
||||
* @notice Calculates the bonus multiplier points earned when a balance Δa is increased an optionally locked for a
|
||||
|
@ -29,7 +31,7 @@ abstract contract StakeMath is MultiplierPointMath {
|
|||
uint256 _increasedAmount,
|
||||
uint256 _increasedLockSeconds
|
||||
)
|
||||
public
|
||||
internal
|
||||
pure
|
||||
returns (uint256 _deltaMpTotal, uint256 _newMaxMP, uint256 _newLockEnd)
|
||||
{
|
||||
|
@ -37,7 +39,7 @@ abstract contract StakeMath is MultiplierPointMath {
|
|||
require(newBalance >= MIN_BALANCE, "StakeMath: balance too low");
|
||||
_newLockEnd = Math.max(_lockEndTime, _processTime) + _increasedLockSeconds;
|
||||
uint256 dt_lock = _newLockEnd - _processTime;
|
||||
require(dt_lock == 0 || dt_lock >= MIN_LOCKUP_TIME, "StakeMath: lockup time too low");
|
||||
require(dt_lock == 0 || dt_lock >= MIN_LOCKUP_PERIOD, "StakeMath: lockup time too low");
|
||||
require(dt_lock <= MAX_LOCKUP_PERIOD, "StakeMath: lockup time too high");
|
||||
|
||||
uint256 deltaMpBonus;
|
||||
|
@ -52,9 +54,7 @@ abstract contract StakeMath is MultiplierPointMath {
|
|||
_deltaMpTotal = _calculateInitialMP(_increasedAmount) + deltaMpBonus;
|
||||
_newMaxMP = _maxMP + _deltaMpTotal + _calculateAccuredMP(_balance, MAX_MULTIPLIER * YEAR);
|
||||
|
||||
require(
|
||||
_newMaxMP <= MAX_MULTIPLIER_ABSOLUTE * (_balance + _increasedAmount), "StakeMath: max multiplier exceeded"
|
||||
);
|
||||
require(_newMaxMP <= MP_MPY_ABSOLUTE * (_balance + _increasedAmount), "StakeMath: max multiplier exceeded");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -75,7 +75,7 @@ abstract contract StakeMath is MultiplierPointMath {
|
|||
uint256 _processTime,
|
||||
uint256 _increasedLockSeconds
|
||||
)
|
||||
public
|
||||
internal
|
||||
pure
|
||||
returns (uint256 _deltaMpTotal, uint256 _newMaxMP, uint256 _newLockEnd)
|
||||
{
|
||||
|
@ -84,13 +84,13 @@ abstract contract StakeMath is MultiplierPointMath {
|
|||
|
||||
_newLockEnd = Math.max(_lockEndTime, _processTime) + _increasedLockSeconds;
|
||||
uint256 dt_lock = _newLockEnd - _processTime;
|
||||
require(dt_lock == 0 || dt_lock >= MIN_LOCKUP_TIME, "StakeMath: lockup time too low");
|
||||
require(dt_lock == 0 || dt_lock >= MIN_LOCKUP_PERIOD, "StakeMath: lockup time too low");
|
||||
require(dt_lock <= MAX_LOCKUP_PERIOD, "StakeMath: lockup time too high");
|
||||
|
||||
_deltaMpTotal += _calculateBonusMP(_balance, _increasedLockSeconds);
|
||||
_newMaxMP = _maxMP + _deltaMpTotal;
|
||||
|
||||
require(_newMaxMP <= MAX_MULTIPLIER_ABSOLUTE * (_balance), "StakeMath: max multiplier exceeded");
|
||||
require(_newMaxMP <= MP_MPY_ABSOLUTE * (_balance), "StakeMath: max multiplier exceeded");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -112,7 +112,7 @@ abstract contract StakeMath is MultiplierPointMath {
|
|||
uint256 _maxMP,
|
||||
uint256 _reducedAmount
|
||||
)
|
||||
public
|
||||
internal
|
||||
pure
|
||||
returns (uint256 _deltaMpTotal, uint256 _deltaMpMax)
|
||||
{
|
||||
|
@ -140,7 +140,7 @@ abstract contract StakeMath is MultiplierPointMath {
|
|||
uint256 _lastAccrualTime,
|
||||
uint256 _processTime
|
||||
)
|
||||
public
|
||||
internal
|
||||
pure
|
||||
returns (uint256 _deltaMpTotal)
|
||||
{
|
||||
|
@ -150,4 +150,15 @@ abstract contract StakeMath is MultiplierPointMath {
|
|||
_deltaMpTotal = Math.min(_calculateAccuredMP(_balance, dt), _maxMP - _totalMP);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Caution: This value is estimated and can be incorrect due precision loss.
|
||||
* @notice Estimates the time an account set as locked time.
|
||||
* @param _mpMax Maximum multiplier points calculated from the current balance.
|
||||
* @param _currentBalance Current balance used to calculate the maximum multiplier points.
|
||||
*/
|
||||
function _estimateLockTime(uint256 _mpMax, uint256 _currentBalance) internal pure returns (uint256 _lockTime) {
|
||||
return Math.mulDiv((_mpMax - _currentBalance) * 100, YEAR, _currentBalance * MP_APY, Math.Rounding.Up)
|
||||
- MAX_LOCKUP_PERIOD;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.8.26;
|
||||
pragma solidity ^0.8.27;
|
||||
|
||||
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
|
||||
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
||||
import { IStakeManager } from "./IStakeManager.sol";
|
||||
import { IStakeManager } from "./interfaces/IStakeManager.sol";
|
||||
import { StakeManager } from "./StakeManager.sol";
|
||||
|
||||
/**
|
||||
|
@ -54,7 +54,7 @@ contract StakeVault is Ownable {
|
|||
}
|
||||
|
||||
function leave() external onlyOwner {
|
||||
if (StakeManager(stakeManager).leave()) {
|
||||
if (StakeManager(address(stakeManager)).leave()) {
|
||||
STAKING_TOKEN.transferFrom(address(this), msg.sender, STAKING_TOKEN.balanceOf(address(this)));
|
||||
}
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ contract StakeVault is Ownable {
|
|||
* @notice Opt-in migration to a new IStakeManager contract.
|
||||
*/
|
||||
function acceptMigration() external onlyOwner {
|
||||
IStakeManager migrated = StakeManager(stakeManager).acceptUpdate();
|
||||
IStakeManager migrated = StakeManager(address(stakeManager)).acceptUpdate();
|
||||
if (address(migrated) == address(0)) revert StakeVault__MigrationNotAvailable();
|
||||
stakeManager = migrated;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.8.26;
|
||||
pragma solidity ^0.8.27;
|
||||
|
||||
import { Ownable2Step } from "@openzeppelin/contracts/access/Ownable2Step.sol";
|
||||
import { StakeManager } from "./StakeManager.sol";
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.26;
|
||||
pragma solidity ^0.8.27;
|
||||
|
||||
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
|
||||
import { ITrustedCodehashAccess } from "../interfaces/ITrustedCodehashAccess.sol";
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// SPDX-License-Identifier: CC0-1.0
|
||||
|
||||
pragma solidity ^0.8.26;
|
||||
pragma solidity ^0.8.27;
|
||||
|
||||
/**
|
||||
* @title Singleton Factory (EIP-2470)
|
||||
|
@ -21,10 +21,6 @@ library AddressLib {
|
|||
}
|
||||
}
|
||||
|
||||
function computeAddress(bytes memory, bytes32 _salt) public view returns (address payable) {
|
||||
return payable(hashToAddress(abi.encodePacked(bytes1(0xff), address(this), _salt, _initCode)));
|
||||
}
|
||||
|
||||
function computeAddress(address _deployer, bytes32 _salt, bytes memory _initCode) public pure returns (address) {
|
||||
return hashToAddress(abi.encodePacked(bytes1(0xff), _deployer, _salt, _initCode));
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// SPDX-License-Identifier: CC0-1.0
|
||||
|
||||
pragma solidity ^0.8.26;
|
||||
pragma solidity ^0.8.27;
|
||||
|
||||
/**
|
||||
* @title Singleton Factory (EIP-2470)
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.27;
|
||||
|
||||
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
||||
import { ITrustedCodehashAccess } from "./ITrustedCodehashAccess.sol";
|
||||
|
||||
interface IStakeConstants {
|
||||
function MIN_LOCKUP_PERIOD() external view returns (uint256);
|
||||
function MAX_LOCKUP_PERIOD() external view returns (uint256);
|
||||
function MP_APY() external view returns (uint256);
|
||||
function MAX_MULTIPLIER() external view returns (uint256);
|
||||
}
|
|
@ -1,28 +1,25 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.26;
|
||||
pragma solidity ^0.8.27;
|
||||
|
||||
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
||||
import { ITrustedCodehashAccess } from "./ITrustedCodehashAccess.sol";
|
||||
import { IStakeConstants } from "./IStakeConstants.sol";
|
||||
|
||||
interface IStakeManager is ITrustedCodehashAccess {
|
||||
interface IStakeManager is IStakeConstants, ITrustedCodehashAccess {
|
||||
error StakeManager__FundsLocked();
|
||||
error StakeManager__InvalidLockTime();
|
||||
error StakeManager__InsufficientFunds();
|
||||
error StakeManager__StakeIsTooLow();
|
||||
|
||||
function STAKING_TOKEN() external view returns (IERC20);
|
||||
function REWARD_TOKEN() external view returns (IERC20);
|
||||
|
||||
function stake(uint256 _amount, uint256 _seconds) external;
|
||||
function lock(uint256 _seconds) external;
|
||||
function unstake(uint256 _amount) external;
|
||||
|
||||
function totalStaked() external view returns (uint256);
|
||||
function totalMP() external view returns (uint256);
|
||||
function totalMaxMP() external view returns (uint256);
|
||||
//function totalMaxMP() external view returns (uint256);
|
||||
function getStakedBalance(address _vault) external view returns (uint256 _balance);
|
||||
|
||||
function STAKING_TOKEN() external view returns (IERC20);
|
||||
function REWARD_TOKEN() external view returns (IERC20);
|
||||
function MIN_LOCKUP_PERIOD() external view returns (uint256);
|
||||
function MAX_LOCKUP_PERIOD() external view returns (uint256);
|
||||
function MP_RATE_PER_YEAR() external view returns (uint256);
|
||||
function MAX_MULTIPLIER() external view returns (uint256);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.26;
|
||||
pragma solidity ^0.8.27;
|
||||
|
||||
/**
|
||||
* @title TrustedCodehashAccess
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.26;
|
||||
pragma solidity ^0.8.27;
|
||||
|
||||
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
optimizer_runs = 10_000
|
||||
out = "out"
|
||||
script = "script"
|
||||
solc = "0.8.26"
|
||||
solc = "0.8.27"
|
||||
src = "contracts"
|
||||
test = "test"
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity >=0.8.26 <=0.9.0;
|
||||
pragma solidity >=0.8.27 <=0.9.0;
|
||||
|
||||
import { Script } from "forge-std/Script.sol";
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity >=0.8.26 <=0.9.0;
|
||||
pragma solidity >=0.8.27 <=0.9.0;
|
||||
|
||||
import { BaseScript } from "./Base.s.sol";
|
||||
import { DeploymentConfig } from "./DeploymentConfig.s.sol";
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity >=0.8.26 <=0.9.0;
|
||||
pragma solidity >=0.8.27 <=0.9.0;
|
||||
|
||||
import { BaseScript } from "./Base.s.sol";
|
||||
import { StakeManager } from "../contracts/StakeManager.sol";
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
//// SPDX-License-Identifier: UNLICENSED
|
||||
|
||||
pragma solidity >=0.8.26 <=0.9.0;
|
||||
pragma solidity >=0.8.27 <=0.9.0;
|
||||
|
||||
import { Script } from "forge-std/Script.sol";
|
||||
import { MockERC20 } from "../test/mocks/MockERC20.sol";
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// SPDX-License-Identifier: CC0-1.0
|
||||
pragma solidity ^0.8.26;
|
||||
pragma solidity ^0.8.27;
|
||||
|
||||
import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
||||
|
||||
|
@ -8,11 +8,11 @@ import { Deploy } from "../script/Deploy.s.sol";
|
|||
import { DeployMigrationStakeManager } from "../script/DeployMigrationStakeManager.s.sol";
|
||||
import { DeploymentConfig } from "../script/DeploymentConfig.s.sol";
|
||||
import { TrustedCodehashAccess, StakeManager, ExpiredStakeStorage } from "../contracts/StakeManager.sol";
|
||||
import { MultiplierPointMath } from "../contracts/MultiplierPointMath.sol";
|
||||
import { StakeMath } from "../contracts/StakeMath.sol";
|
||||
import { StakeVault } from "../contracts/StakeVault.sol";
|
||||
import { VaultFactory } from "../contracts/VaultFactory.sol";
|
||||
|
||||
contract DynamicTest is MultiplierPointMath, Test {
|
||||
contract DynamicTest is StakeMath, Test {
|
||||
DeploymentConfig internal deploymentConfig;
|
||||
StakeManager internal stakeManager;
|
||||
VaultFactory internal vaultFactory;
|
||||
|
@ -35,7 +35,7 @@ contract DynamicTest is MultiplierPointMath, Test {
|
|||
}
|
||||
|
||||
modifier fuzz_stake(uint256 _amount) {
|
||||
vm.assume(_amount > _calculateMinimumStake(stakeManager.EPOCH_SIZE()));
|
||||
vm.assume(_amount > stakeManager.MIN_BALANCE());
|
||||
vm.assume(_amount < 1e20);
|
||||
_;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity ^0.8.26;
|
||||
pragma solidity ^0.8.27;
|
||||
|
||||
import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
||||
|
||||
|
@ -8,7 +8,7 @@ import { Deploy } from "../script/Deploy.s.sol";
|
|||
import { DeployMigrationStakeManager } from "../script/DeployMigrationStakeManager.s.sol";
|
||||
import { DeploymentConfig } from "../script/DeploymentConfig.s.sol";
|
||||
import { StakeManager, IStakeManager, ExpiredStakeStorage } from "../contracts/StakeManager.sol";
|
||||
import { ITrustedCodehashAccess } from "../contracts/access/ITrustedCodehashAccess.sol";
|
||||
import { ITrustedCodehashAccess } from "../contracts/interfaces/ITrustedCodehashAccess.sol";
|
||||
import { MultiplierPointMath } from "../contracts/MultiplierPointMath.sol";
|
||||
import { StakeVault } from "../contracts/StakeVault.sol";
|
||||
import { VaultFactory } from "../contracts/VaultFactory.sol";
|
||||
|
@ -325,7 +325,7 @@ contract LockTest is StakeManagerTest {
|
|||
StakeVault userVault = _createStakingAccount(testUser, 1000, minLockup, 1000);
|
||||
|
||||
vm.warp(block.timestamp + stakeManager.MIN_LOCKUP_PERIOD() - 1);
|
||||
stakeManager.executeAccount(address(userVault), 1);
|
||||
stakeManager.executeAccount(address(userVault));
|
||||
(, uint256 balance, uint256 bonusMP, uint256 totalMP,, uint256 lockUntil,,) =
|
||||
stakeManager.accounts(address(userVault));
|
||||
|
||||
|
@ -485,7 +485,7 @@ contract ExecuteAccountTest is StakeManagerTest {
|
|||
vm.expectRevert(StakeManager.StakeManager__InvalidLimitEpoch.selector);
|
||||
stakeManager.executeAccount(address(userVault), currentEpoch + 1);
|
||||
|
||||
vm.warp(stakeManager.epochEnd() + stakeManager.EPOCH_SIZE() - 1);
|
||||
vm.warp(stakeManager.epochEnd() + stakeManager.ACCURE_RATE() - 1);
|
||||
|
||||
vm.expectRevert(StakeManager.StakeManager__InvalidLimitEpoch.selector);
|
||||
stakeManager.executeEpoch(currentEpoch + 2);
|
||||
|
@ -516,9 +516,10 @@ contract ExecuteAccountTest is StakeManagerTest {
|
|||
stakeManager.executeEpoch();
|
||||
vm.warp(stakeManager.epochEnd());
|
||||
|
||||
//expected MP is, the starting totalMP + the calculatedMPToMint of user balance for one EPOCH_SIZE multiplied by
|
||||
//expected MP is, the starting totalMP + the calculatedMPToMint of user balance for one ACCURE_RATE multiplied
|
||||
// by
|
||||
// 2.
|
||||
uint256 expectedMP = totalMP + (stakeManager.calculateMP(stakeAmount, stakeManager.EPOCH_SIZE()) * 2);
|
||||
uint256 expectedMP = totalMP + (stakeManager.calculateMP(stakeAmount, stakeManager.ACCURE_RATE()) * 2);
|
||||
stakeManager.executeAccount(address(userVaults[0]), stakeManager.currentEpoch() + 1);
|
||||
(,,, totalMP, lastMint,, epoch,) = stakeManager.accounts(address(userVaults[0]));
|
||||
|
||||
|
@ -569,7 +570,7 @@ contract ExecuteAccountTest is StakeManagerTest {
|
|||
console.log("--=======#=======");
|
||||
console.log("--# TOTAL_SUPPLY", stakeManager.totalSupply());
|
||||
console.log("--# PND_REWARDS", stakeManager.pendingReward());
|
||||
assertEq(lastMint, lastMintBefore + stakeManager.EPOCH_SIZE(), "must increaase lastMint");
|
||||
assertEq(lastMint, lastMintBefore + stakeManager.ACCURE_RATE(), "must increaase lastMint");
|
||||
assertEq(epoch, epochBefore + 1, "must increase epoch");
|
||||
assertGt(totalMP, totalMPBefore, "must increase MPs");
|
||||
assertGt(rewards, rewardsBefore, "must increase rewards");
|
||||
|
@ -585,25 +586,25 @@ contract ExecuteAccountTest is StakeManagerTest {
|
|||
|
||||
uint256 epochsAmountToReachCap = stakeManager.calculateMP(
|
||||
stakeAmount, stakeManager.MAX_MULTIPLIER() * stakeManager.YEAR()
|
||||
) / stakeManager.calculateMP(stakeAmount, stakeManager.EPOCH_SIZE());
|
||||
) / stakeManager.calculateMP(stakeAmount, stakeManager.ACCURE_RATE());
|
||||
|
||||
deal(stakeToken, testUser, stakeAmount);
|
||||
|
||||
userVaults.push(_createStakingAccount(makeAddr("testUser"), stakeAmount, 0));
|
||||
|
||||
vm.warp(stakeManager.epochEnd() - (stakeManager.EPOCH_SIZE() - 1));
|
||||
vm.warp(stakeManager.epochEnd() - (stakeManager.ACCURE_RATE() - 1));
|
||||
userVaults.push(_createStakingAccount(makeAddr("testUser2"), stakeAmount, 0));
|
||||
|
||||
vm.warp(stakeManager.epochEnd() - (stakeManager.EPOCH_SIZE() - 2));
|
||||
vm.warp(stakeManager.epochEnd() - (stakeManager.ACCURE_RATE() - 2));
|
||||
userVaults.push(_createStakingAccount(makeAddr("testUser3"), stakeAmount, 0));
|
||||
|
||||
vm.warp(stakeManager.epochEnd() - ((stakeManager.EPOCH_SIZE() / 4) * 3));
|
||||
vm.warp(stakeManager.epochEnd() - ((stakeManager.ACCURE_RATE() / 4) * 3));
|
||||
userVaults.push(_createStakingAccount(makeAddr("testUser4"), stakeAmount, 0));
|
||||
|
||||
vm.warp(stakeManager.epochEnd() - ((stakeManager.EPOCH_SIZE() / 4) * 2));
|
||||
vm.warp(stakeManager.epochEnd() - ((stakeManager.ACCURE_RATE() / 4) * 2));
|
||||
userVaults.push(_createStakingAccount(makeAddr("testUser5"), stakeAmount, 0));
|
||||
|
||||
vm.warp(stakeManager.epochEnd() - ((stakeManager.EPOCH_SIZE() / 4) * 1));
|
||||
vm.warp(stakeManager.epochEnd() - ((stakeManager.ACCURE_RATE() / 4) * 1));
|
||||
userVaults.push(_createStakingAccount(makeAddr("testUser6"), stakeAmount, 0));
|
||||
|
||||
vm.warp(stakeManager.epochEnd() - 2);
|
||||
|
@ -647,7 +648,7 @@ contract ExecuteAccountTest is StakeManagerTest {
|
|||
//solhint-disable-next-line max-line-length
|
||||
(,,, uint256 totalMP, uint256 lastMint,, uint256 epoch,) = stakeManager.accounts(address(userVaults[j]));
|
||||
uint256 rewards = ERC20(stakeToken).balanceOf(rewardAddress);
|
||||
assertEq(lastMint, lastMintBefore + stakeManager.EPOCH_SIZE(), "must increaase lastMint");
|
||||
assertEq(lastMint, lastMintBefore + stakeManager.ACCURE_RATE(), "must increaase lastMint");
|
||||
assertEq(epoch, epochBefore + 1, "must increase epoch");
|
||||
// MPs will still be minted in mpLimitEpoch + 1 when accounts
|
||||
// started staking at any point *inside* of an epoch, so we
|
||||
|
@ -728,7 +729,7 @@ contract UserFlowsTest is StakeManagerTest {
|
|||
);
|
||||
uint256 thisAccReachCapIn = stakeManager.calculateMP(
|
||||
thisAccStake, stakeManager.MAX_MULTIPLIER() * stakeManager.YEAR()
|
||||
) / stakeManager.calculateMP(thisAccStake, stakeManager.EPOCH_SIZE());
|
||||
) / stakeManager.calculateMP(thisAccStake, stakeManager.ACCURE_RATE());
|
||||
if (thisAccReachCapIn > epochsAmountToReachCap) {
|
||||
epochsAmountToReachCap = thisAccReachCapIn; //uses the amount to reach cap from the account that takes
|
||||
// longer to reach cap
|
||||
|
@ -813,7 +814,7 @@ contract ExecuteEpochTest is MigrationStakeManagerTest {
|
|||
stakeManager.executeEpoch();
|
||||
assertEq(stakeManager.currentEpoch(), 1, "Current epoch should increase if 1 second after epochend of 1");
|
||||
|
||||
vm.warp(firstEpochEnd + (stakeManager.EPOCH_SIZE() * 99));
|
||||
vm.warp(firstEpochEnd + (stakeManager.ACCURE_RATE() * 99));
|
||||
assertEq(stakeManager.newEpoch(), 100);
|
||||
stakeManager.executeEpoch();
|
||||
assertEq(stakeManager.currentEpoch(), 100);
|
||||
|
@ -822,7 +823,7 @@ contract ExecuteEpochTest is MigrationStakeManagerTest {
|
|||
function test_ExecuteEpochExecuteEpochAfterEnd() public {
|
||||
StakeVault userVault = _createStakingAccount(makeAddr("testUser"), 100_000, 0);
|
||||
|
||||
vm.warp(stakeManager.epochEnd() + (stakeManager.EPOCH_SIZE() / 2));
|
||||
vm.warp(stakeManager.epochEnd() + (stakeManager.ACCURE_RATE() / 2));
|
||||
stakeManager.executeEpoch();
|
||||
stakeManager.executeAccount(address(userVault), stakeManager.currentEpoch());
|
||||
vm.warp(stakeManager.epochEnd());
|
||||
|
@ -830,7 +831,7 @@ contract ExecuteEpochTest is MigrationStakeManagerTest {
|
|||
stakeManager.executeEpoch();
|
||||
stakeManager.executeAccount(address(userVault), stakeManager.currentEpoch());
|
||||
|
||||
vm.warp(stakeManager.epochEnd() + (stakeManager.EPOCH_SIZE() * 2));
|
||||
vm.warp(stakeManager.epochEnd() + (stakeManager.ACCURE_RATE() * 2));
|
||||
stakeManager.executeEpoch();
|
||||
stakeManager.executeAccount(address(userVault), stakeManager.currentEpoch());
|
||||
}
|
||||
|
@ -868,7 +869,7 @@ contract ExecuteEpochTest is MigrationStakeManagerTest {
|
|||
StakeVault userVault = _createStakingAccount(makeAddr("testUser"), 100_000, 0);
|
||||
|
||||
for (uint256 i = 0; i < 10; i++) {
|
||||
vm.warp(stakeManager.epochEnd() + (stakeManager.EPOCH_SIZE() / 10 - i));
|
||||
vm.warp(stakeManager.epochEnd() + (stakeManager.ACCURE_RATE() / 10 - i));
|
||||
stakeManager.executeEpoch();
|
||||
}
|
||||
stakeManager.executeAccount(address(userVault), stakeManager.currentEpoch());
|
||||
|
@ -878,7 +879,7 @@ contract ExecuteEpochTest is MigrationStakeManagerTest {
|
|||
StakeVault userVault = _createStakingAccount(makeAddr("testUser"), 100_000, 0);
|
||||
|
||||
for (uint256 i = 0; i < 10; i++) {
|
||||
vm.warp(stakeManager.epochEnd() + (stakeManager.EPOCH_SIZE() / 10 - i));
|
||||
vm.warp(stakeManager.epochEnd() + (stakeManager.ACCURE_RATE() / 10 - i));
|
||||
}
|
||||
stakeManager.executeEpoch();
|
||||
stakeManager.executeAccount(address(userVault), stakeManager.currentEpoch());
|
||||
|
@ -888,7 +889,7 @@ contract ExecuteEpochTest is MigrationStakeManagerTest {
|
|||
StakeVault userVault = _createStakingAccount(makeAddr("testUser"), 100_000, 0);
|
||||
|
||||
for (uint256 i = 0; i < 10; i++) {
|
||||
vm.warp(stakeManager.epochEnd() + (stakeManager.EPOCH_SIZE() / 10 - i));
|
||||
vm.warp(stakeManager.epochEnd() + (stakeManager.ACCURE_RATE() / 10 - i));
|
||||
}
|
||||
stakeManager.executeAccount(address(userVault));
|
||||
}
|
||||
|
@ -896,13 +897,13 @@ contract ExecuteEpochTest is MigrationStakeManagerTest {
|
|||
function test_ExecuteEpochExecuteAccountAfterEpochEnd() public {
|
||||
StakeVault userVault = _createStakingAccount(makeAddr("testUser"), 100_000, 0);
|
||||
|
||||
vm.warp(stakeManager.epochEnd() + (stakeManager.EPOCH_SIZE() / 2));
|
||||
vm.warp(stakeManager.epochEnd() + (stakeManager.ACCURE_RATE() / 2));
|
||||
stakeManager.executeAccount(address(userVault), stakeManager.currentEpoch());
|
||||
|
||||
vm.warp(stakeManager.epochEnd());
|
||||
stakeManager.executeAccount(address(userVault), stakeManager.currentEpoch());
|
||||
|
||||
vm.warp(stakeManager.epochEnd() + (stakeManager.EPOCH_SIZE() * 2));
|
||||
vm.warp(stakeManager.epochEnd() + (stakeManager.ACCURE_RATE() * 2));
|
||||
stakeManager.executeAccount(address(userVault), stakeManager.currentEpoch());
|
||||
}
|
||||
|
||||
|
@ -910,7 +911,7 @@ contract ExecuteEpochTest is MigrationStakeManagerTest {
|
|||
StakeVault userVault = _createStakingAccount(makeAddr("testUser"), 100_000, 0);
|
||||
|
||||
for (uint256 i = 0; i < 10; i++) {
|
||||
vm.warp(stakeManager.epochEnd() + (stakeManager.EPOCH_SIZE() / 10 - i));
|
||||
vm.warp(stakeManager.epochEnd() + (stakeManager.ACCURE_RATE() / 10 - i));
|
||||
stakeManager.executeAccount(address(userVault), stakeManager.currentEpoch());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity ^0.8.26;
|
||||
pragma solidity ^0.8.27;
|
||||
|
||||
import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity ^0.8.26;
|
||||
pragma solidity ^0.8.27;
|
||||
|
||||
import { Test } from "forge-std/Test.sol";
|
||||
import { Deploy } from "../script/Deploy.s.sol";
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity ^0.8.26;
|
||||
pragma solidity ^0.8.27;
|
||||
|
||||
import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity ^0.8.26;
|
||||
pragma solidity ^0.8.27;
|
||||
|
||||
import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity ^0.8.26;
|
||||
pragma solidity ^0.8.27;
|
||||
|
||||
import { BaseScript } from "../../script/Base.s.sol";
|
||||
import { StakeManager } from "../../contracts/StakeManager.sol";
|
||||
|
|
Loading…
Reference in New Issue