Skip to content

Commit b9f62a5

Browse files
authored
feat(contracts): add upgrade scripts for Aggregation Mode Payments (#2251)
1 parent 3170684 commit b9f62a5

File tree

4 files changed

+178
-0
lines changed

4 files changed

+178
-0
lines changed

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ anvil_upgrade_batcher_payment_service: ## Upgrade BatcherPaymentService contract
133133
@echo "Upgrading BatcherPayments contract..."
134134
. contracts/scripts/anvil/upgrade_batcher_payment_service.sh
135135

136+
anvil_upgrade_aggregation_mode_payment_service: ## Upgrade AggregationModePaymentService contract on ANVIL
137+
@echo "Upgrading AggregationModePaymentService contract..."
138+
. contracts/scripts/anvil/upgrade_aggregation_mode_payment_service.sh
139+
136140
anvil_upgrade_registry_coordinator: ## Upgrade Registry Coordinator Contracts on ANVIL
137141
@echo "Upgrading Registry Coordinator Contracts..."
138142
. contracts/scripts/anvil/upgrade_registry_coordinator.sh
@@ -993,6 +997,10 @@ upgrade_proof_aggregator: ## Upgrade ProofAggregator contract. Parameters: NETWO
993997
@echo "Upgrading ProofAggregator Contract on $(NETWORK) network..."
994998
@. contracts/scripts/.env.$(NETWORK) && . contracts/scripts/upgrade_proof_aggregator.sh
995999

1000+
upgrade_aggregation_mode_payment_service: ## Upgrade AggregationModePaymentService. Parameters: NETWORK=<mainnet|holesky|sepolia>
1001+
@echo "Upgrading AggregationModePaymentService Contract on $(NETWORK) network..."
1002+
@. contracts/scripts/.env.$(NETWORK) && . contracts/scripts/upgrade_aggregation_mode_payment_service.sh
1003+
9961004
deploy_agg_mode_payment_service:
9971005
@echo "Deploying Agg Mode Payment Service contract on $(NETWORK) network..."
9981006
@. contracts/scripts/.env.$(NETWORK) && . contracts/scripts/deploy_agg_mode_payment_service.sh
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
pragma solidity ^0.8.12;
3+
4+
import {AggregationModePaymentService} from "../../src/core/AggregationModePaymentService.sol";
5+
6+
import "forge-std/Script.sol";
7+
import "forge-std/StdJson.sol";
8+
9+
contract AggregationModePaymentServiceUpgrader is Script {
10+
function run(
11+
string memory alignedLayerDeploymentFilePath
12+
) external returns (address, address) {
13+
string memory aligned_deployment_file = vm.readFile(
14+
alignedLayerDeploymentFilePath
15+
);
16+
17+
vm.startBroadcast();
18+
19+
AggregationModePaymentService aggregationModePaymentServiceProxy =
20+
AggregationModePaymentService(payable(
21+
stdJson.readAddress(
22+
aligned_deployment_file,
23+
".addresses.aggregationModePaymentService"
24+
)
25+
));
26+
27+
AggregationModePaymentService newAggregationModePaymentServiceImplementation =
28+
new AggregationModePaymentService();
29+
30+
// Not link the new implementation to the proxy
31+
// Because this must be executed in the multisig
32+
33+
vm.stopBroadcast();
34+
35+
return (
36+
address(aggregationModePaymentServiceProxy),
37+
address(newAggregationModePaymentServiceImplementation)
38+
);
39+
}
40+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
# Deploy new Aggregation Mode Payment Service implementation, but don't upgrade yet
21+
forge_output=$(forge script script/upgrade/AggregationModePaymentServiceUpgrader.s.sol \
22+
"./script/output/devnet/proof_aggregation_service_deployment_output.json" \
23+
--rpc-url "http://localhost:8545" \
24+
--private-key "0x4bbbf85ce3377467afe5d46f804f221813b2bb87f24d81f60f1fcdbf7cbf4356" \
25+
--broadcast \
26+
--legacy \
27+
--sig "run(string memory alignedLayerDeploymentFilePath)")
28+
29+
echo "$forge_output"
30+
31+
# Extract the aggregation mode payment service values from the output
32+
aggregation_mode_payment_service_proxy=$(echo "$forge_output" | awk '/0: address/ {print $3}')
33+
aggregation_mode_payment_service_implementation=$(echo "$forge_output" | awk '/1: address/ {print $3}')
34+
35+
data=$(cast calldata "upgradeTo(address)" $aggregation_mode_payment_service_implementation)
36+
37+
MULTISIG=false # hardcoding non-multisig for devnet
38+
if [ "$MULTISIG" = false ]; then
39+
echo "Executing upgrade transaction"
40+
cast send $aggregation_mode_payment_service_proxy $data \
41+
--rpc-url "http://localhost:8545" \
42+
--private-key "0x4bbbf85ce3377467afe5d46f804f221813b2bb87f24d81f60f1fcdbf7cbf4356"
43+
else
44+
echo "You can propose the upgrade transaction with the multisig using this calldata"
45+
echo $data
46+
fi
47+
48+
pkill anvil
49+
50+
# Use the extracted value to replace the aggregation mode payment service values and save it to a temporary file
51+
jq --arg aggregation_mode_payment_service_implementation "$aggregation_mode_payment_service_implementation" \
52+
'.addresses.aggregationModePaymentServiceImplementation = $aggregation_mode_payment_service_implementation' \
53+
"./script/output/devnet/proof_aggregation_service_deployment_output.json" > \
54+
"./script/output/devnet/proof_aggregation_service_deployment_output.temp.json"
55+
56+
# Replace the original file with the temporary file
57+
mv "./script/output/devnet/proof_aggregation_service_deployment_output.temp.json" \
58+
"./script/output/devnet/proof_aggregation_service_deployment_output.json"
59+
60+
# Delete the temporary file
61+
rm -f "./script/output/devnet/proof_aggregation_service_deployment_output.temp.json"
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/bin/bash
2+
3+
# ENV VARIABLES
4+
#
5+
# MULTISIG=true|false whether the contract is deployed under a multisig account
6+
#
7+
# PROOF_AGGREGATOR_OUTPUT_PATH: Path to the proof aggregator output file
8+
# - Holesky Stage: ./script/output/holesky/proof_aggregation_service_deployment_output.stage.json
9+
# - Holesky Prod: ./script/output/holesky/proof_aggregation_service_deployment_output.json
10+
#
11+
# RPC_URL: The RPC URL to connect to the Ethereum network
12+
#
13+
# PRIVATE_KEY: The private key to use for the deployment
14+
#
15+
# ETHERSCAN_API_KEY: The Etherscan API key to use for verification
16+
#
17+
18+
if [ -z "$MULTISIG" ]; then
19+
echo "Missing MULTISIG env variable"
20+
exit 1
21+
fi
22+
23+
# cd to the directory of this script so that this can be run from anywhere
24+
parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
25+
26+
cd "$parent_path"
27+
28+
cd ../
29+
30+
# Save the output to a variable to later extract the address of the new deployed contract
31+
forge_output=$(forge script script/upgrade/AggregationModePaymentServiceUpgrader.s.sol \
32+
$PROOF_AGGREGATOR_OUTPUT_PATH \
33+
--rpc-url $RPC_URL \
34+
--private-key $PRIVATE_KEY \
35+
--broadcast \
36+
--verify \
37+
--etherscan-api-key $ETHERSCAN_API_KEY \
38+
--sig "run(string memory alignedLayerDeploymentFilePath)")
39+
40+
echo "$forge_output"
41+
42+
# Extract the aggregation mode payment service values from the output
43+
aggregation_mode_payment_service_proxy=$(echo "$forge_output" | awk '/0: address/ {print $3}')
44+
aggregation_mode_payment_service_implementation=$(echo "$forge_output" | awk '/1: address/ {print $3}')
45+
46+
# Use the extracted value to replace the aggregation mode payment service values and save it to a temporary file
47+
jq --arg aggregation_mode_payment_service_implementation "$aggregation_mode_payment_service_implementation" \
48+
'.addresses.aggregationModePaymentServiceImplementation = $aggregation_mode_payment_service_implementation' \
49+
$PROOF_AGGREGATOR_OUTPUT_PATH > "$PROOF_AGGREGATOR_OUTPUT_PATH.temp"
50+
51+
# Replace the original file with the temporary file
52+
mv "$PROOF_AGGREGATOR_OUTPUT_PATH.temp" $PROOF_AGGREGATOR_OUTPUT_PATH
53+
54+
# Delete the temporary file
55+
rm -f "$PROOF_AGGREGATOR_OUTPUT_PATH.temp"
56+
57+
echo "The new Aggregation Mode Payment Service Implementation is $aggregation_mode_payment_service_implementation"
58+
59+
data=$(cast calldata "upgradeTo(address)" $aggregation_mode_payment_service_implementation)
60+
61+
if [ "$MULTISIG" = false ]; then
62+
echo "Executing upgrade transaction"
63+
cast send $aggregation_mode_payment_service_proxy $data \
64+
--rpc-url $RPC_URL \
65+
--private-key $PRIVATE_KEY
66+
else
67+
echo "You can propose the upgrade transaction with the multisig using this calldata"
68+
echo $data
69+
fi

0 commit comments

Comments
 (0)