Skip to content

Commit 329602d

Browse files
NicolasRampolditaturosatiJuArce
authored
feat: add upgrade script for contracts (#203)
Co-authored-by: Santos Rosati <rosatisantos@gmail.com> Co-authored-by: JuArce <52429267+JuArce@users.noreply.github.com> Co-authored-by: Tatu <65305492+srosati@users.noreply.github.com>
1 parent d8af05b commit 329602d

8 files changed

Lines changed: 373 additions & 0 deletions

Makefile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ anvil_deploy_aligned_contracts:
4242
@echo "Deploying Aligned Contracts..."
4343
. contracts/scripts/anvil/deploy_aligned_contracts.sh
4444

45+
anvil_upgrade_aligned_contracts:
46+
@echo "Upgrading Aligned Contracts..."
47+
. contracts/scripts/anvil/upgrade_aligned_contracts.sh
48+
49+
anvil_upgrade_registry_coordinator:
50+
@echo "Upgrading Registry Coordinator Contracts..."
51+
. contracts/scripts/anvil/upgrade_registry_coordinator.sh
52+
4553
anvil_start:
4654
@echo "Starting Anvil..."
4755
anvil --load-state contracts/scripts/anvil/state/alignedlayer-deployed-anvil-state.json
@@ -441,6 +449,14 @@ deploy_aligned_contracts: ## Deploy Aligned Contracts
441449
@echo "Deploying Aligned Contracts..."
442450
@. contracts/scripts/.env && . contracts/scripts/deploy_aligned_contracts.sh
443451

452+
upgrade_aligned_contracts: ## Upgrade Aligned Contracts
453+
@echo "Upgrading Aligned Contracts..."
454+
@. contracts/scripts/.env && . contracts/scripts/upgrade_aligned_contracts.sh
455+
456+
upgrade_registry_coordinator: ## Upgrade Registry Coordinator
457+
@echo "Upgrading Registry Coordinator..."
458+
@. contracts/scripts/.env && . contracts/scripts/upgrade_registry_coordinator.sh
459+
444460
build_aligned_contracts:
445461
@cd contracts/src/core && forge build
446462

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,18 @@ When changing Aligned contracts, the anvil state needs to be updated with:
622622
make anvil_deploy_aligned_contracts
623623
```
624624

625+
To test the upgrade script for ServiceManager in the local devnet, run:
626+
627+
```bash
628+
make anvil_upgrade_aligned_contracts
629+
```
630+
631+
To test the upgrade script for RegistryCoordintator in the local devnet, run:
632+
633+
```bash
634+
make anvil_upgrade_registry_coordinator
635+
```
636+
625637
#### Aligned Contracts: Holesky/Mainnet
626638

627639
To deploy the contracts to Testnet/Mainnet, you will need to set environment variables in a `.env` file in the same directory as the deployment script (`contracts/scripts/`).
@@ -669,6 +681,20 @@ You need to complete the `DEPLOY_CONFIG_PATH` file with the following informatio
669681

670682
You can find an example config file in `contracts/script/deploy/config/holesky/aligned.holesky.config.json`.
671683

684+
To upgrade the Service Manager Contract in Testnet/Mainnet, run:
685+
686+
```bash
687+
make upgrade_aligned_contracts
688+
```
689+
690+
To upgrade the Registry Coordinator in Testnet/Mainnet, run:
691+
692+
```bash
693+
make upgrade_registry_coordinator
694+
```
695+
696+
Make sure to set environment variables in a `.env` file in the same directory as the upgrade script (`contracts/scripts/`).
697+
672698
### Bindings
673699

674700
Also make sure to re-generate the Go smart contract bindings:
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
pragma solidity =0.8.12;
3+
4+
import {Script} from "forge-std/Script.sol";
5+
import "eigenlayer-contracts/src/contracts/core/AVSDirectory.sol";
6+
import {RegistryCoordinator} from "eigenlayer-middleware/RegistryCoordinator.sol";
7+
import {StakeRegistry} from "eigenlayer-middleware/StakeRegistry.sol";
8+
import {AlignedLayerServiceManager} from "src/core/AlignedLayerServiceManager.sol";
9+
import "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol";
10+
import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
11+
import "forge-std/StdJson.sol";
12+
13+
contract AlignedLayerUpgrader is Script {
14+
function run(
15+
string memory eigenLayerDeploymentFilePath,
16+
string memory alignedLayerDeploymentFilePath
17+
) external returns (address, address) {
18+
string memory eigen_deployment_file = vm.readFile(
19+
eigenLayerDeploymentFilePath
20+
);
21+
22+
string memory aligned_deployment_file = vm.readFile(
23+
alignedLayerDeploymentFilePath
24+
);
25+
26+
ProxyAdmin alignedLayerProxyAdmin = ProxyAdmin(
27+
stdJson.readAddress(
28+
aligned_deployment_file,
29+
".addresses.alignedLayerProxyAdmin"
30+
)
31+
);
32+
33+
RegistryCoordinator registryCoordinator = RegistryCoordinator(
34+
stdJson.readAddress(
35+
aligned_deployment_file,
36+
".addresses.registryCoordinator"
37+
)
38+
);
39+
40+
AVSDirectory avsDirectory = AVSDirectory(
41+
stdJson.readAddress(
42+
eigen_deployment_file,
43+
".addresses.avsDirectory"
44+
)
45+
);
46+
47+
StakeRegistry stakeRegistry = StakeRegistry(
48+
stdJson.readAddress(
49+
aligned_deployment_file,
50+
".addresses.stakeRegistry"
51+
)
52+
);
53+
54+
vm.startBroadcast();
55+
56+
AlignedLayerServiceManager alignedLayerServiceManagerImplementation = new AlignedLayerServiceManager(
57+
avsDirectory,
58+
registryCoordinator,
59+
stakeRegistry
60+
);
61+
62+
vm.stopBroadcast();
63+
64+
// alignedLayerServiceManager is the proxy
65+
AlignedLayerServiceManager alignedLayerServiceManager = AlignedLayerServiceManager(
66+
stdJson.readAddress(
67+
aligned_deployment_file,
68+
".addresses.alignedLayerServiceManager"
69+
)
70+
);
71+
72+
vm.startBroadcast();
73+
74+
alignedLayerProxyAdmin.upgrade(
75+
TransparentUpgradeableProxy(
76+
payable(address(alignedLayerServiceManager))
77+
),
78+
address(alignedLayerServiceManagerImplementation)
79+
);
80+
81+
vm.stopBroadcast();
82+
83+
return (
84+
address(alignedLayerServiceManager),
85+
address(alignedLayerServiceManagerImplementation)
86+
);
87+
}
88+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
pragma solidity =0.8.12;
3+
4+
import {Script} from "forge-std/Script.sol";
5+
import "eigenlayer-contracts/src/contracts/core/AVSDirectory.sol";
6+
import {RegistryCoordinator} from "eigenlayer-middleware/RegistryCoordinator.sol";
7+
import {StakeRegistry} from "eigenlayer-middleware/StakeRegistry.sol";
8+
import {BLSApkRegistry} from "eigenlayer-middleware/BLSApkRegistry.sol";
9+
import {IndexRegistry} from "eigenlayer-middleware/IndexRegistry.sol";
10+
import {AlignedLayerServiceManager} from "src/core/AlignedLayerServiceManager.sol";
11+
import {IServiceManager} from "eigenlayer-middleware/interfaces/IServiceManager.sol";
12+
import "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol";
13+
import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
14+
import "forge-std/StdJson.sol";
15+
16+
contract RegistryCoordinatorUpgrader is Script {
17+
function run(
18+
string memory eigenLayerDeploymentFilePath,
19+
string memory alignedLayerDeploymentFilePath
20+
) external returns (address, address) {
21+
// Load files
22+
string memory eigen_deployment_file = vm.readFile(
23+
eigenLayerDeploymentFilePath
24+
);
25+
string memory aligned_deployment_file = vm.readFile(
26+
alignedLayerDeploymentFilePath
27+
);
28+
29+
// Load proxy admin
30+
ProxyAdmin alignedLayerProxyAdmin = ProxyAdmin(
31+
stdJson.readAddress(
32+
aligned_deployment_file,
33+
".addresses.alignedLayerProxyAdmin"
34+
)
35+
);
36+
37+
// Load RegistryCoordinator Proxy
38+
TransparentUpgradeableProxy registryCoordinator = TransparentUpgradeableProxy(
39+
payable(stdJson.readAddress(
40+
aligned_deployment_file,
41+
".addresses.registryCoordinator"
42+
))
43+
);
44+
45+
// Load RegistryCoordinator dependencies
46+
AlignedLayerServiceManager alignedLayerServiceManager = AlignedLayerServiceManager(
47+
stdJson.readAddress(
48+
aligned_deployment_file,
49+
".addresses.alignedLayerServiceManager"
50+
)
51+
);
52+
StakeRegistry stakeRegistry = StakeRegistry(
53+
stdJson.readAddress(
54+
aligned_deployment_file,
55+
".addresses.stakeRegistry"
56+
)
57+
);
58+
BLSApkRegistry apkRegistry = BLSApkRegistry(
59+
stdJson.readAddress(
60+
aligned_deployment_file,
61+
".addresses.blsApkRegistry"
62+
)
63+
);
64+
IndexRegistry indexRegistry = IndexRegistry(
65+
stdJson.readAddress(
66+
aligned_deployment_file,
67+
".addresses.indexRegistry"
68+
)
69+
);
70+
71+
// Create a new instance of the RegistryCoordinatorImplementation
72+
vm.startBroadcast();
73+
RegistryCoordinator registryCoordinatorImplementation = new RegistryCoordinator(
74+
IServiceManager(address(alignedLayerServiceManager)),
75+
stakeRegistry,
76+
apkRegistry,
77+
indexRegistry
78+
);
79+
vm.stopBroadcast();
80+
81+
vm.startBroadcast();
82+
alignedLayerProxyAdmin.upgrade(
83+
registryCoordinator,
84+
address(registryCoordinatorImplementation)
85+
);
86+
vm.stopBroadcast();
87+
88+
return (
89+
address(registryCoordinator),
90+
address(registryCoordinatorImplementation)
91+
);
92+
}
93+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
3+
# cd to the directory of this script so that this can be run from anywhere
4+
parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
5+
6+
cd "$parent_path"
7+
8+
cd ../../
9+
10+
jq 'del(.block)' scripts/anvil/state/alignedlayer-deployed-anvil-state.json > scripts/anvil/state/alignedlayer-deployed-anvil-state-tmp.json
11+
12+
cp -f scripts/anvil/state/alignedlayer-deployed-anvil-state-tmp.json scripts/anvil/state/alignedlayer-deployed-anvil-state.json
13+
14+
rm scripts/anvil/state/alignedlayer-deployed-anvil-state-tmp.json
15+
16+
anvil --load-state scripts/anvil/state/alignedlayer-deployed-anvil-state.json --dump-state scripts/anvil/state/alignedlayer-deployed-anvil-state.json &
17+
18+
sleep 2
19+
20+
# Save the output to a variable to later extract the address of the new deployed contract
21+
forge_output=$(forge script script/upgrade/AlignedLayerUpgrader.s.sol \
22+
"./script/output/devnet/eigenlayer_deployment_output.json" \
23+
"./script/output/devnet/alignedlayer_deployment_output.json" \
24+
--rpc-url "http://localhost:8545" \
25+
--private-key "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" \
26+
--broadcast \
27+
--sig "run(string memory eigenLayerDeploymentFilePath, string memory alignedLayerDeploymentFilePath)")
28+
29+
echo "$forge_output"
30+
31+
pkill anvil
32+
33+
# Extract the alignedLayerServiceManagerImplementation value from the output
34+
new_aligned_layer_service_manager_implementation=$(echo "$forge_output" | awk '/1: address/ {print $3}')
35+
36+
# Use the extracted value to replace the alignedLayerServiceManagerImplementation value in alignedlayer_deployment_output.json and save it to a temporary file
37+
jq --arg new_aligned_layer_service_manager_implementation "$new_aligned_layer_service_manager_implementation" '.addresses.alignedLayerServiceManagerImplementation = $new_aligned_layer_service_manager_implementation' "script/output/devnet/alignedlayer_deployment_output.json" > "script/output/devnet/alignedlayer_deployment_output.temp.json"
38+
39+
# Replace the original file with the temporary file
40+
mv "script/output/devnet/alignedlayer_deployment_output.temp.json" "script/output/devnet/alignedlayer_deployment_output.json"
41+
42+
# Delete the temporary file
43+
rm -f "script/output/devnet/alignedlayer_deployment_output.temp.json"
44+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
3+
# cd to the directory of this script so that this can be run from anywhere
4+
parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
5+
6+
cd "$parent_path"
7+
8+
cd ../../
9+
10+
jq 'del(.block)' scripts/anvil/state/alignedlayer-deployed-anvil-state.json > scripts/anvil/state/alignedlayer-deployed-anvil-state-tmp.json
11+
12+
cp -f scripts/anvil/state/alignedlayer-deployed-anvil-state-tmp.json scripts/anvil/state/alignedlayer-deployed-anvil-state.json
13+
14+
rm scripts/anvil/state/alignedlayer-deployed-anvil-state-tmp.json
15+
16+
anvil --load-state scripts/anvil/state/alignedlayer-deployed-anvil-state.json --dump-state scripts/anvil/state/alignedlayer-deployed-anvil-state.json &
17+
18+
sleep 2
19+
20+
# Save the output to a variable to later extract the address of the new deployed contract
21+
forge_output=$(forge script script/upgrade/RegistryCoordinatorUpgrader.s.sol \
22+
"./script/output/devnet/eigenlayer_deployment_output.json" \
23+
"./script/output/devnet/alignedlayer_deployment_output.json" \
24+
--rpc-url "http://localhost:8545" \
25+
--private-key "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" \
26+
--broadcast \
27+
--sig "run(string memory eigenLayerDeploymentFilePath, string memory alignedLayerDeploymentFilePath)")
28+
29+
echo "$forge_output"
30+
31+
pkill anvil
32+
33+
# Extract the alignedLayerServiceManagerImplementation value from the output
34+
new_registry_coordinator_implementation=$(echo "$forge_output" | awk '/1: address/ {print $3}')
35+
36+
# Use the extracted value to replace the alignedLayerServiceManagerImplementation value in alignedlayer_deployment_output.json and save it to a temporary file
37+
jq --arg new_registry_coordinator_implementation "$new_registry_coordinator_implementation" '.addresses.registryCoordinatorImplementation = $new_registry_coordinator_implementation' "script/output/devnet/alignedlayer_deployment_output.json" > "script/output/devnet/alignedlayer_deployment_output.temp.json"
38+
39+
# Replace the original file with the temporary file
40+
mv "script/output/devnet/alignedlayer_deployment_output.temp.json" "script/output/devnet/alignedlayer_deployment_output.json"
41+
42+
# Delete the temporary file
43+
rm -f "script/output/devnet/alignedlayer_deployment_output.temp.json"
44+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
3+
# cd to the directory of this script so that this can be run from anywhere
4+
parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
5+
6+
cd "$parent_path"
7+
8+
cd ../
9+
10+
# Save the output to a variable to later extract the address of the new deployed contract
11+
forge_output=$(forge script script/upgrade/AlignedLayerUpgrader.s.sol \
12+
$EXISTING_DEPLOYMENT_INFO_PATH \
13+
$OUTPUT_PATH \
14+
--rpc-url $RPC_URL \
15+
--private-key $PRIVATE_KEY \
16+
--broadcast \
17+
--sig "run(string memory eigenLayerDeploymentFilePath, string memory alignedLayerDeploymentFilePath, )")
18+
19+
echo "$forge_output"
20+
21+
# Extract the alignedLayerServiceManagerImplementation value from the output
22+
new_aligned_layer_service_manager_implementation=$(echo "$forge_output" | awk '/1: address/ {print $3}')
23+
24+
# Use the extracted value to replace the alignedLayerServiceManagerImplementation value in alignedlayer_deployment_output.json and save it to a temporary file
25+
jq --arg new_aligned_layer_service_manager_implementation "$new_aligned_layer_service_manager_implementation" '.addresses.alignedLayerServiceManagerImplementation = $new_aligned_layer_service_manager_implementation' "script/output/holesky/alignedlayer_deployment_output.json" > "script/output/holesky/alignedlayer_deployment_output.temp.json"
26+
27+
# Replace the original file with the temporary file
28+
mv "script/output/holesky/alignedlayer_deployment_output.temp.json" "script/output/holesky/alignedlayer_deployment_output.json"
29+
30+
# Delete the temporary file
31+
rm -f "script/output/holesky/alignedlayer_deployment_output.temp.json"

0 commit comments

Comments
 (0)