Skip to content

Commit c94dea8

Browse files
Add testnet governance deployment and testing scripts (#3870)
* Add testnet governance deployment and testing scripts * add scripts, do not commit governance env as not needed in main * wait for user input if not deploying and testing on localhost * added retry_until_true helper for state checks, add 1s cooldown afyments to avoid RPC rate limiting, added --ledger flag in the test scripts, added timelock cancellation check * update readme and add env file acceptance to scripts * comment grant roles for now * update readme * updated readme, made some flow changes to the deployment script and improved the .env file by referencing the multisig address whre needed * give user option to set output file * clippy fix * ensur that the read_proxy_impl can read addresses that are not proxies * Update README.md for ENV_FILE instructions Clarified instructions for updating the ENV_FILE. * Update README to reference OUTPUT_FILE instead of ENV_FILE * refactor retry_until_true * updates to the readme * ci fix * clippy fix * clipy fix * make some vars optional * Update contracts/rust/deployer/scripts/testnet-governance-deploy.sh Co-authored-by: Mathis <[email protected]> * fix: add bc to nix flake * Update contracts/rust/deployer/scripts/testnet-governance-flows.sh Co-authored-by: Mathis <[email protected]> --------- Co-authored-by: Mathis <[email protected]>
1 parent 67c2885 commit c94dea8

File tree

9 files changed

+661
-32
lines changed

9 files changed

+661
-32
lines changed

.env

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ ESPRESSO_NASTY_CLIENT_PORT=24011
155155
# which ensures that all services work correctly in the demo without admin access. In a real
156156
# deployment, we would set this to the address of a multisig wallet.
157157
ESPRESSO_SEQUENCER_ETH_MULTISIG_ADDRESS=8626f6940e2eb28930efb4cef49b2d1f2c9c1199
158-
ESPRESSO_SEQUENCER_ETH_MULTISIG_PAUSER_ADDRESS=8626f6940e2eb28930efb4cef49b2d1f2c9c1199
158+
ESPRESSO_SEQUENCER_ETH_MULTISIG_PAUSER_ADDRESS=${ESPRESSO_SEQUENCER_ETH_MULTISIG_ADDRESS}
159159

160160
# Set this to the number of blocks you would like to confirm the sequencer can reach
161161
INTEGRATION_TEST_EXPECTED_BLOCK_HEIGHT=10
@@ -176,6 +176,6 @@ ESPRESSO_OPS_TIMELOCK_ADMIN=${ESPRESSO_SEQUENCER_ETH_MULTISIG_ADDRESS}
176176
ESPRESSO_OPS_TIMELOCK_PROPOSERS=${ESPRESSO_SEQUENCER_ETH_MULTISIG_ADDRESS}
177177
ESPRESSO_OPS_TIMELOCK_EXECUTORS=${ESPRESSO_SEQUENCER_ETH_MULTISIG_ADDRESS}
178178
ESPRESSO_SAFE_EXIT_TIMELOCK_DELAY=1209600
179-
ESPRESSO_SAFE_EXIT_TIMELOCK_ADMIN=8626f6940e2eb28930efb4cef49b2d1f2c9c1199
179+
ESPRESSO_SAFE_EXIT_TIMELOCK_ADMIN=${ESPRESSO_SEQUENCER_ETH_MULTISIG_ADDRESS}
180180
ESPRESSO_SAFE_EXIT_TIMELOCK_PROPOSERS=${ESPRESSO_SEQUENCER_ETH_MULTISIG_ADDRESS}
181181
ESPRESSO_SAFE_EXIT_TIMELOCK_EXECUTORS=${ESPRESSO_SEQUENCER_ETH_MULTISIG_ADDRESS}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ data/*-actual.bin
5050
.env.contracts.water
5151
.env*.decaf
5252
.env.docker
53+
.env.governance.test
5354

5455
# Generated by nix-direnv
5556
.direnv/
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Governance script test
2+
3+
For testing purposes, use this to deploy POS contracts, with timelock ownership, and execute various timelock flows.
4+
5+
## Pre-requisites
6+
7+
- `nix` installed
8+
- in the root of the directory, enter `nix develop`
9+
10+
### Build Optimization
11+
12+
To avoid rebuilds during script execution, pre-build the deploy binary:
13+
14+
```bash
15+
cargo build --bin deploy
16+
```
17+
18+
## Deploying the contracts
19+
20+
1. Copy the env file
21+
22+
```bash
23+
export ENV_FILE={YOUR_ENV_FILE}
24+
cp .env $ENV_FILE
25+
```
26+
27+
- and replace the following fields in the `$ENV_FILE` if not deploying to a local network via anvil.
28+
- `ESPRESSO_SEQUENCER_ETH_MNEMONIC`
29+
- `ESPRESSO_SEQUENCER_ETH_MULTISIG_ADDRESS`
30+
31+
- The default ops and safe exit timelock delays in this script is 30 and 60 seconds respectively. If you want to change
32+
it then also add the following fields to the ENV_FILE:
33+
- `OPS_DELAY` (in seconds)
34+
- `SAFE_EXIT_DELAY` (in seconds)
35+
36+
2. set the RPC_URL, ACCOUNT_INDEX and OUTPUT_FILE
37+
38+
```bash
39+
export RPC_URL={YOUR_RPC_URL}
40+
export ACCOUNT_INDEX={YOUR_ACCOUNT_INDEX} # Optional: default value is zero
41+
export OUTPUT_FILE={YOUR_OUTPUT_FILE} # Optional: customize output file
42+
```
43+
44+
3. Run the script
45+
46+
```bash
47+
./contracts/rust/deployer/scripts/testnet-governance-deploy.sh --env-file $ENV_FILE
48+
```
49+
50+
## Running the test flow
51+
52+
1. Assuming the contracts are deployed and their proxy addresses are found `$OUTPUT_FILE`
53+
2. Ensure that you have an RPC URL for the network the contracts are deployed to
54+
3. Have your ledger connected (assumes account index = 0 otherwise set `export ACCOUNT_INDEX=YOUR_ACCOUNT_INDEX`)
55+
56+
```bash
57+
export RPC_URL={YOUR_RPC_URL}
58+
./contracts/rust/deployer/scripts/testnet-governance-flows.sh --ledger --env-file $OUTPUT_FILE
59+
```
60+
61+
**Note**: The `$OUTPUT_FILE` from the deploy script contains the deployed contract addresses and should be used as
62+
`--env-file` for the flows script.
63+
64+
## Notes
65+
66+
- The script will prompt for confirmation before each operation
67+
- Operations use a 30-second delay by default (configurable via OPS_DELAY env var)
68+
- For non-localhost RPCs, you'll be prompted to confirm before proceeding
69+
- to use a ledger with any command, use `--ledger`
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
#!/usr/bin/env bash
2+
# This script deploys the contracts to testnet so that governance flows can be tested
3+
set -euo pipefail
4+
5+
# Find repo root and source .env file
6+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
7+
REPO_ROOT="$(cd "$SCRIPT_DIR/../../../.." && pwd)"
8+
echo "REPO_ROOT: $REPO_ROOT"
9+
10+
# Parse command line arguments
11+
USE_LEDGER=false
12+
ENV_FILE=""
13+
while [[ $# -gt 0 ]]; do
14+
case $1 in
15+
--ledger)
16+
USE_LEDGER=true
17+
shift
18+
;;
19+
--env-file)
20+
ENV_FILE="$2"
21+
shift 2
22+
;;
23+
*)
24+
echo "Unknown option: $1"
25+
echo "Usage: $0 [--ledger] [--env-file FILE]"
26+
exit 1
27+
;;
28+
esac
29+
done
30+
31+
# Source env file if provided, otherwise try default .env
32+
if [[ -n "$ENV_FILE" ]]; then
33+
if [[ ! -f "$ENV_FILE" ]]; then
34+
echo "Error: env file not found: $ENV_FILE"
35+
exit 1
36+
fi
37+
set -a
38+
source "$ENV_FILE"
39+
set +a
40+
elif [[ -f "$REPO_ROOT/.env" ]]; then
41+
set -a
42+
source "$REPO_ROOT/.env"
43+
set +a
44+
fi
45+
46+
# Unset any variables containing "PROXY_ADDRESS" to force fresh deployment
47+
for var in $(env | grep -i "PROXY_ADDRESS" | cut -d= -f1); do
48+
unset "$var" 2>/dev/null || true
49+
done
50+
51+
52+
RPC_URL="${RPC_URL:-http://localhost:8545}"
53+
OUTPUT_FILE="${OUTPUT_FILE:-.env.governance.testnet}"
54+
ACCOUNT_INDEX="${ACCOUNT_INDEX:-0}"
55+
OPS_DELAY="${OPS_DELAY:-30}" # 30 seconds default
56+
SAFE_EXIT_DELAY="${SAFE_EXIT_DELAY:-60}" # 60 seconds default
57+
58+
# Helper function to check if RPC URL is localhost
59+
is_localhost_rpc() {
60+
local url="$1"
61+
# Check for localhost, 127.0.0.1
62+
[[ "$url" =~ ^https?://(localhost|127\.0\.0\.1)(:[0-9]+)?(/.*)?$ ]]
63+
}
64+
65+
if is_localhost_rpc "$RPC_URL"; then
66+
unset ESPRESSO_SEQUENCER_ETH_MULTISIG_ADDRESS
67+
fi
68+
69+
# Function to prompt user for confirmation on real testnets
70+
confirm() {
71+
local message="${1:-Continue?}"
72+
if is_localhost_rpc "$RPC_URL"; then
73+
return 0
74+
fi
75+
read -p "$message [y/N] " -r
76+
echo
77+
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
78+
echo "Aborted."
79+
exit 1
80+
fi
81+
}
82+
83+
# Use hardcoded anvil addresses only for localhost, otherwise use env vars
84+
if is_localhost_rpc "$RPC_URL"; then
85+
ESPRESSO_OPS_TIMELOCK_PROPOSERS="0xa0Ee7A142d267C1f36714E4a8F75612F20a79720"
86+
ESPRESSO_OPS_TIMELOCK_EXECUTORS="0xa0Ee7A142d267C1f36714E4a8F75612F20a79720"
87+
ESPRESSO_SAFE_EXIT_TIMELOCK_PROPOSERS="0xa0Ee7A142d267C1f36714E4a8F75612F20a79720"
88+
ESPRESSO_SAFE_EXIT_TIMELOCK_EXECUTORS="0xa0Ee7A142d267C1f36714E4a8F75612F20a79720"
89+
ESPRESSO_SEQUENCER_ETH_MULTISIG_PAUSER_ADDRESS="0xa0Ee7A142d267C1f36714E4a8F75612F20a79720"
90+
else
91+
ESPRESSO_OPS_TIMELOCK_PROPOSERS="${ESPRESSO_OPS_TIMELOCK_PROPOSERS:?ESPRESSO_OPS_TIMELOCK_PROPOSERS must be set for non-localhost deployments}"
92+
ESPRESSO_OPS_TIMELOCK_EXECUTORS="${ESPRESSO_OPS_TIMELOCK_EXECUTORS:?ESPRESSO_OPS_TIMELOCK_EXECUTORS must be set for non-localhost deployments}"
93+
ESPRESSO_SAFE_EXIT_TIMELOCK_PROPOSERS="${ESPRESSO_SAFE_EXIT_TIMELOCK_PROPOSERS:?ESPRESSO_SAFE_EXIT_TIMELOCK_PROPOSERS must be set for non-localhost deployments}"
94+
ESPRESSO_SAFE_EXIT_TIMELOCK_EXECUTORS="${ESPRESSO_SAFE_EXIT_TIMELOCK_EXECUTORS:?ESPRESSO_SAFE_EXIT_TIMELOCK_EXECUTORS must be set for non-localhost deployments}"
95+
ESPRESSO_SEQUENCER_ETH_MULTISIG_PAUSER_ADDRESS="${ESPRESSO_SEQUENCER_ETH_MULTISIG_PAUSER_ADDRESS:?ESPRESSO_SEQUENCER_ETH_MULTISIG_PAUSER_ADDRESS must be set for non-localhost deployments}"
96+
fi
97+
98+
DEPLOY_CMD="cargo run --bin deploy --"
99+
if $USE_LEDGER; then
100+
DEPLOY_CMD="$DEPLOY_CMD --ledger"
101+
unset ESPRESSO_SEQUENCER_ETH_MNEMONIC
102+
unset ESPRESSO_DEPLOYER_ACCOUNT_INDEX
103+
fi
104+
105+
echo "=== Deploying Governance Contracts ==="
106+
echo "RPC URL: $RPC_URL"
107+
if ! is_localhost_rpc "$RPC_URL"; then
108+
echo "WARNING: This will deploy to a non-localhost network!"
109+
confirm "Are you sure you want to proceed with deployment?"
110+
fi
111+
112+
echo ""
113+
echo "### Deploying Ops Timelock ###"
114+
$DEPLOY_CMD --rpc-url "$RPC_URL" --account-index "$ACCOUNT_INDEX" \
115+
--deploy-ops-timelock \
116+
--ops-timelock-admin "$ESPRESSO_OPS_TIMELOCK_ADMIN" \
117+
--ops-timelock-delay "$OPS_DELAY" \
118+
--ops-timelock-proposers "$ESPRESSO_OPS_TIMELOCK_PROPOSERS" \
119+
--ops-timelock-executors "$ESPRESSO_OPS_TIMELOCK_EXECUTORS" \
120+
--out "$OUTPUT_FILE"
121+
122+
set -a
123+
source "${OUTPUT_FILE}"
124+
set +a
125+
126+
echo ""
127+
echo "### Deploying Safe Exit Timelock ###"
128+
$DEPLOY_CMD --rpc-url "$RPC_URL" --account-index "$ACCOUNT_INDEX" \
129+
--deploy-safe-exit-timelock \
130+
--safe-exit-timelock-admin "$ESPRESSO_SAFE_EXIT_TIMELOCK_ADMIN" \
131+
--safe-exit-timelock-delay "$SAFE_EXIT_DELAY" \
132+
--safe-exit-timelock-proposers "$ESPRESSO_SAFE_EXIT_TIMELOCK_PROPOSERS" \
133+
--safe-exit-timelock-executors "$ESPRESSO_SAFE_EXIT_TIMELOCK_EXECUTORS" \
134+
--out "$OUTPUT_FILE"
135+
136+
set -a
137+
source "${OUTPUT_FILE}"
138+
set +a
139+
140+
echo ""
141+
echo "### Deploying Core Contracts (v1) ###"
142+
# Deploy contracts without timelock ownership
143+
BASE_ARGS=(
144+
--rpc-url "$RPC_URL"
145+
--account-index "$ACCOUNT_INDEX"
146+
--multisig-pauser-address "$ESPRESSO_SEQUENCER_ETH_MULTISIG_PAUSER_ADDRESS"
147+
--token-name "$ESP_TOKEN_NAME"
148+
--token-symbol "$ESP_TOKEN_SYMBOL"
149+
--initial-token-supply "$ESP_TOKEN_INITIAL_SUPPLY"
150+
--initial-token-grant-recipient "$ESP_TOKEN_INITIAL_GRANT_RECIPIENT_ADDRESS"
151+
--exit-escrow-period "$ESPRESSO_SEQUENCER_STAKE_TABLE_EXIT_ESCROW_PERIOD"
152+
--mock-espresso-live-network
153+
)
154+
155+
[[ -n "${ESPRESSO_SEQUENCER_PERMISSIONED_PROVER:-}" ]] && \
156+
BASE_ARGS+=(--permissioned-prover "$ESPRESSO_SEQUENCER_PERMISSIONED_PROVER")
157+
158+
$DEPLOY_CMD "${BASE_ARGS[@]}" \
159+
--deploy-light-client-v1 \
160+
--deploy-esp-token-v1 \
161+
--deploy-stake-table-v1 \
162+
--use-mock \
163+
--upgrade-light-client-v2 \
164+
--out "$OUTPUT_FILE"
165+
166+
set -a
167+
source "${OUTPUT_FILE}"
168+
set +a
169+
170+
echo ""
171+
echo "### Deploying Upgrades (v2/v3) ###"
172+
UPGRADE_OUTPUT_FILE="${OUTPUT_FILE}.upgrade"
173+
$DEPLOY_CMD "${BASE_ARGS[@]}" \
174+
--deploy-reward-claim-v1 \
175+
--upgrade-esp-token-v2 \
176+
--upgrade-light-client-v3 \
177+
--upgrade-stake-table-v2 \
178+
--use-timelock-owner \
179+
--out "${UPGRADE_OUTPUT_FILE}"
180+
181+
set -a
182+
source "${UPGRADE_OUTPUT_FILE}"
183+
set +a
184+
185+
echo ""
186+
echo "### Deploy Fee Contract with timelock owner"
187+
$DEPLOY_CMD "${BASE_ARGS[@]}" \
188+
--deploy-fee-v1 \
189+
--use-timelock-owner \
190+
--out "$OUTPUT_FILE"
191+
192+
echo ""
193+
echo "### Verifying Deployment ###"
194+
"${REPO_ROOT}/scripts/verify-pos-deployment.sh" --rpc-url "$RPC_URL"
195+
echo ""
196+
echo "Deployment complete!"

0 commit comments

Comments
 (0)