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: add an example for the upgrade flow #98

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
69 changes: 69 additions & 0 deletions contracts/script/ExampleUpgrade.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

import {Script} from "forge-std/Script.sol";
import {console2} from "forge-std/Test.sol";
import {UpgradeableProxyLib} from "./utils/UpgradeableProxyLib.sol";
import {HelloWorldDeploymentLib} from "./utils/HelloWorldDeploymentLib.sol";
import {CoreDeploymentLib} from "./utils/CoreDeploymentLib.sol";
import {ECDSAStakeRegistry} from "@eigenlayer-middleware/src/unaudited/ECDSAStakeRegistry.sol";
import {HelloWorldServiceManager} from "../src/HelloWorldServiceManager.sol";
import {IDelegationManager} from "@eigenlayer/contracts/interfaces/IDelegationManager.sol";

contract ExampleUpgrade is Script {
using UpgradeableProxyLib for address;
using CoreDeploymentLib for *;

address private deployer;
address proxyAdmin;
HelloWorldDeploymentLib.DeploymentData helloWorldDeployment;
CoreDeploymentLib.DeploymentData coreDeployment;

function setUp() public virtual {
deployer = vm.rememberKey(vm.envUint("PRIVATE_KEY"));
vm.label(deployer, "Deployer");

// Read existing deployments based on chain id
coreDeployment = CoreDeploymentLib.readDeploymentJson("deployments/core/", block.chainid);
helloWorldDeployment = HelloWorldDeploymentLib.readDeploymentJson(block.chainid);
proxyAdmin = helloWorldDeployment.proxyAdmin;
}

function run() external {
vm.startBroadcast(deployer);

/// Deploy new implementation contracts
address newStakeRegistryImpl = address(
new ECDSAStakeRegistry(IDelegationManager(coreDeployment.delegationManager))
);

address newHelloWorldServiceManagerImpl = address(
new HelloWorldServiceManager(
coreDeployment.avsDirectory,
helloWorldDeployment.stakeRegistry,
coreDeployment.rewardsCoordinator,
coreDeployment.delegationManager
)
);

/// This is where you will actually perform your upgrade
helloWorldDeployment.helloWorldServiceManager.upgrade(newHelloWorldServiceManagerImpl);
helloWorldDeployment.stakeRegistry.upgrade(newStakeRegistryImpl);

vm.stopBroadcast();

verifyUpgrade();
HelloWorldDeploymentLib.writeDeploymentJson(helloWorldDeployment);
}

function verifyUpgrade() internal view {
require(
helloWorldDeployment.helloWorldServiceManager.getImplementation() != address(0),
"HelloWorldServiceManager implementation cannot be zero"
);
require(
helloWorldDeployment.stakeRegistry.getImplementation() != address(0),
"StakeRegistry implementation cannot be zero"
);
}
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"deploy:hello-world": "cd contracts && forge script script/HelloWorldDeployer.s.sol --rpc-url http://localhost:8545 --broadcast",
"deploy:core-debug": "cd contracts && forge script script/DeployEigenLayerCore.s.sol --rpc-url http://localhost:8545 --broadcast --revert-strings debug",
"deploy:hello-world-debug": "cd contracts && forge script script/HelloWorldDeployer.s.sol --rpc-url http://localhost:8545 --broadcast --revert-strings debug",
"upgrade:hello-world": "cd contracts && forge script script/ExampleUpgrade.s.sol --rpc-url http://localhost:8545 --broadcast",
"upgrade:hello-world-debug": "cd contracts && forge script script/HelloWorldDeployer.s.sol --rpc-url http://localhost:8545 --broadcast --revert-strings debug",
"build": "cd contracts && forge build",
"extract:abis": "node utils/abis.js",
"test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest"
Expand Down
Loading