Skip to content

Commit

Permalink
feat: add example upgrade script
Browse files Browse the repository at this point in the history
  • Loading branch information
stevennevins committed Nov 22, 2024
1 parent 001dc6e commit 0f6f0fd
Showing 1 changed file with 69 additions and 0 deletions.
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
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"
);
}
}

0 comments on commit 0f6f0fd

Please sign in to comment.