Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(scripts): add upgrade script #96

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 46 additions & 12 deletions .gas-report
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,19 @@
| script/DeploymentConfig.s.sol:DeploymentConfig contract | | | | | |
|---------------------------------------------------------|-----------------|-----|--------|-----|---------|
| Deployment Cost | Deployment Size | | | | |
| 0 | 7132 | | | | |
| 0 | 0 | | | | |
| Function Name | min | avg | median | max | # calls |
| activeNetworkConfig | 454 | 454 | 454 | 454 | 126 |


| script/UpgradeRewardsStreamerMP.s.sol:UpgradeRewardsStreamerMPScript contract | | | | | |
|-------------------------------------------------------------------------------|-----------------|---------|---------|---------|---------|
| Deployment Cost | Deployment Size | | | | |
| 2845816 | 14079 | | | | |
| Function Name | min | avg | median | max | # calls |
| run | 2383391 | 2383391 | 2383391 | 2383391 | 3 |


| src/RewardsStreamer.sol:RewardsStreamer contract | | | | | |
|--------------------------------------------------|-----------------|--------|--------|--------|---------|
| Deployment Cost | Deployment Size | | | | |
Expand Down Expand Up @@ -66,16 +74,42 @@
| unstake | 60382 | 60919 | 60382 | 63877 | 13 |
| updateAccountMP | 15396 | 18474 | 17898 | 34998 | 21 |
| updateGlobalState | 11088 | 28045 | 25249 | 110284 | 21 |
| upgradeToAndCall | 3225 | 9387 | 10926 | 10936 | 5 |


| src/StakeManagerProxy.sol:StakeManagerProxy contract | | | | | |
|------------------------------------------------------|-----------------|------|--------|--------|---------|
| Deployment Cost | Deployment Size | | | | |
| 256467 | 1231 | | | | |
| Function Name | min | avg | median | max | # calls |
| fallback | 678 | 7210 | 2115 | 136272 | 823 |
| implementation | 343 | 775 | 343 | 2343 | 412 |
| upgradeToAndCall | 3225 | 7887 | 8426 | 10936 | 5 |


| src/StakeManagerProxy.sol:StakeManagerProxy contract | | | | | |
|------------------------------------------------------|-----------------|-------|--------|--------|---------|
| Deployment Cost | Deployment Size | | | | |
| 256467 | 1263 | | | | |
| Function Name | min | avg | median | max | # calls |
| MAX_LOCKUP_PERIOD | 776 | 3776 | 5276 | 5276 | 6 |
| MAX_MULTIPLIER | 678 | 1905 | 678 | 5178 | 33 |
| MIN_LOCKUP_PERIOD | 724 | 3424 | 5224 | 5224 | 15 |
| MP_RATE_PER_YEAR | 680 | 1180 | 680 | 5180 | 9 |
| STAKING_TOKEN | 855 | 6083 | 7355 | 7355 | 322 |
| emergencyModeEnabled | 7347 | 7347 | 7347 | 7347 | 7 |
| enableEmergencyMode | 28480 | 45381 | 50665 | 50665 | 8 |
| getAccount | 2115 | 2115 | 2115 | 2115 | 72 |
| getStakedBalance | 7559 | 7559 | 7559 | 7559 | 1 |
| getUserTotalMP | 9660 | 9660 | 9660 | 9660 | 1 |
| getUserTotalMaxMP | 3553 | 3553 | 3553 | 3553 | 1 |
| getUserTotalStakedBalance | 15548 | 15548 | 15548 | 15548 | 1 |
| getUserVaults | 5637 | 6762 | 5637 | 10137 | 4 |
| implementation | 343 | 775 | 343 | 2343 | 412 |
| lastRewardTime | 822 | 1822 | 1822 | 2822 | 2 |
| rewardEndTime | 800 | 1800 | 1800 | 2800 | 2 |
| rewardStartTime | 779 | 4029 | 4029 | 7279 | 2 |
| rewardsBalanceOf | 1747 | 1747 | 1747 | 1747 | 4 |
| setReward | 28863 | 77206 | 86636 | 128881 | 7 |
| setTrustedCodehash | 52889 | 52889 | 52889 | 52889 | 2 |
| totalMP | 800 | 800 | 800 | 800 | 81 |
| totalMaxMP | 777 | 777 | 777 | 777 | 81 |
| totalRewardsAccrued | 800 | 800 | 800 | 800 | 3 |
| totalRewardsSupply | 1387 | 2498 | 2151 | 11627 | 30 |
| totalStaked | 823 | 823 | 823 | 823 | 82 |
| updateAccountMP | 41755 | 44833 | 44257 | 61357 | 21 |
| updateGlobalState | 37076 | 54033 | 51237 | 136272 | 21 |
| upgradeToAndCall | 29868 | 33720 | 33720 | 37572 | 2 |


| src/StakeVault.sol:StakeVault contract | | | | | |
Expand Down Expand Up @@ -167,7 +201,7 @@
| test/mocks/MockToken.sol:MockToken contract | | | | | |
|---------------------------------------------|-----------------|-------|--------|-------|---------|
| Deployment Cost | Deployment Size | | | | |
| 625454 | 3260 | | | | |
| 625370 | 3260 | | | | |
| Function Name | min | avg | median | max | # calls |
| approve | 46330 | 46339 | 46342 | 46342 | 262 |
| balanceOf | 558 | 989 | 558 | 2558 | 139 |
Expand Down
6 changes: 3 additions & 3 deletions .gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ EmergencyExitTest:test_EmergencyExitWithLock() (gas: 391762)
EmergencyExitTest:test_EmergencyExitWithRewards() (gas: 377316)
EmergencyExitTest:test_OnlyOwnerCanEnableEmergencyMode() (gas: 39426)
IntegrationTest:testStakeFoo() (gas: 1178499)
LeaveTest:test_LeaveShouldProperlyUpdateAccounting() (gas: 2960876)
LeaveTest:test_LeaveShouldProperlyUpdateAccounting() (gas: 5626814)
LeaveTest:test_RevertWhenStakeManagerIsTrusted() (gas: 294826)
LeaveTest:test_TrustNewStakeManager() (gas: 3036018)
LeaveTest:test_TrustNewStakeManager() (gas: 5699451)
LockTest:test_LockFailsWithInvalidPeriod() (gas: 309911)
LockTest:test_LockFailsWithNoStake() (gas: 63730)
LockTest:test_LockWithoutPriorLock() (gas: 385915)
Expand Down Expand Up @@ -67,7 +67,7 @@ UnstakeTest:test_UnstakeOneAccountAndAccruedMP() (gas: 494565)
UnstakeTest:test_UnstakeOneAccountAndRewards() (gas: 404122)
UnstakeTest:test_UnstakeOneAccountWithLockUpAndAccruedMP() (gas: 523042)
UpgradeTest:test_RevertWhenNotOwner() (gas: 2602178)
UpgradeTest:test_UpgradeStakeManager() (gas: 2875664)
UpgradeTest:test_UpgradeStakeManager() (gas: 5541589)
VaultRegistrationTest:test_VaultRegistration() (gas: 62013)
WithdrawTest:test_CannotWithdrawStakedFunds() (gas: 310550)
XPNFTTokenTest:testApproveNotAllowed() (gas: 10500)
Expand Down
22 changes: 22 additions & 0 deletions script/UpgradeRewardsStreamerMP.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;

import { UUPSUpgradeable } from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import { BaseScript } from "./Base.s.sol";
import { RewardsStreamerMP } from "../src/RewardsStreamerMP.sol";
import { IStakeManagerProxy } from "../src/interfaces/IStakeManagerProxy.sol";

contract UpgradeRewardsStreamerMPScript is BaseScript {
function run(address admin, IStakeManagerProxy currentImplProxy) public {
address deployer = broadcaster;
if (admin != address(0)) {
deployer = admin;
}
vm.startBroadcast(deployer);
// Replace this with actual new version of the contract
address nextImpl = address(new RewardsStreamerMP());
bytes memory initializeData;
UUPSUpgradeable(address(currentImplProxy)).upgradeToAndCall(nextImpl, initializeData);
vm.stopBroadcast();
}
}
27 changes: 6 additions & 21 deletions test/RewardsStreamerMP.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity ^0.8.26;
import { Test } from "forge-std/Test.sol";
import { Math } from "@openzeppelin/contracts/utils/math/Math.sol";
import { DeployRewardsStreamerMPScript } from "../script/DeployRewardsStreamerMP.s.sol";
import { UpgradeRewardsStreamerMPScript } from "../script/UpgradeRewardsStreamerMP.s.sol";
import { DeploymentConfig } from "../script/DeploymentConfig.s.sol";
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { UUPSUpgradeable } from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
Expand Down Expand Up @@ -172,6 +173,11 @@ contract RewardsStreamerMPTest is Test {
uint256 mpPerYear = amount * streamer.MP_RATE_PER_YEAR();
return target * 365 days / mpPerYear;
}

function _upgradeStakeManager() internal {
UpgradeRewardsStreamerMPScript upgrade = new UpgradeRewardsStreamerMPScript();
upgrade.run(admin, IStakeManagerProxy(address(streamer)));
}
}

contract MathTest is RewardsStreamerMPTest {
Expand Down Expand Up @@ -1844,13 +1850,6 @@ contract EmergencyExitTest is RewardsStreamerMPTest {
}

contract UpgradeTest is RewardsStreamerMPTest {
function _upgradeStakeManager() internal {
address newImpl = address(new RewardsStreamerMP());
bytes memory initializeData;
vm.prank(admin);
UUPSUpgradeable(streamer).upgradeToAndCall(newImpl, initializeData);
}

function setUp() public override {
super.setUp();
}
Expand Down Expand Up @@ -1897,13 +1896,6 @@ contract UpgradeTest is RewardsStreamerMPTest {
}

contract LeaveTest is RewardsStreamerMPTest {
function _upgradeStakeManager() internal {
address newImpl = address(new RewardsStreamerMP());
bytes memory initializeData;
vm.prank(admin);
UUPSUpgradeable(streamer).upgradeToAndCall(newImpl, initializeData);
}

function setUp() public override {
super.setUp();
}
Expand Down Expand Up @@ -1996,13 +1988,6 @@ contract LeaveTest is RewardsStreamerMPTest {
}

contract MaliciousUpgradeTest is RewardsStreamerMPTest {
function _upgradeStakeManager() internal {
address newImpl = address(new RewardsStreamerMP());
bytes memory initializeData;
vm.prank(admin);
UUPSUpgradeable(streamer).upgradeToAndCall(newImpl, initializeData);
}

function setUp() public override {
super.setUp();
}
Expand Down
Loading