-
Notifications
You must be signed in to change notification settings - Fork 327
/
Copy pathdeploy-l1-contracts.sh
executable file
·82 lines (67 loc) · 2.63 KB
/
deploy-l1-contracts.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/bash
set -exu
# If REGISTRY_CONTRACT_ADDRESS is already set, skip deployment and just write the file
if [ -n "${REGISTRY_CONTRACT_ADDRESS:-}" ]; then
echo "Registry address already set. Skipping deployment."
# Write the addresses to a file in the shared volume
cat <<EOF >/shared/contracts/contracts.env
export REGISTRY_CONTRACT_ADDRESS=$REGISTRY_CONTRACT_ADDRESS
EOF
cat /shared/contracts/contracts.env
exit 0
fi
SALT=${1:-$RANDOM}
CHAIN_ID=$2
VALIDATOR_ADDRESSES=$3
# If the chain ID is 11155111 or 1, we are deploying to a public network, make sure that we do not use accelerated test deployments
PUBLIC_CHAIN_ID=false
if [ "$CHAIN_ID" = "11155111" -o "$CHAIN_ID" = "1" ]; then
PUBLIC_CHAIN_ID=true
fi
# Overwrite the value of ACCELERATED_TEST_DEPLOYMENTS env variable if we are deploying to a public network
if [ "$PUBLIC_CHAIN_ID" = "true" ]; then
ACCELERATED_TEST_DEPLOYMENTS=false
fi
# Run the deploy-l1-contracts command and capture the output
output=""
MAX_RETRIES=5
RETRY_DELAY=15
TEST_ACCOUNTS=${TEST_ACCOUNTS:-false}
TEST_ACCOUNTS_ARG=""
if [ "$TEST_ACCOUNTS" = "true" ]; then
TEST_ACCOUNTS_ARG="--test-accounts"
fi
ACCELERATED_TEST_DEPLOYMENTS_ARG=""
if [ "$ACCELERATED_TEST_DEPLOYMENTS" = "true" ]; then
ACCELERATED_TEST_DEPLOYMENTS_ARG="--accelerated-test-deployments"
fi
for attempt in $(seq 1 $MAX_RETRIES); do
# Construct base command
base_cmd="LOG_LEVEL=debug node --no-warnings /usr/src/yarn-project/aztec/dest/bin/index.js deploy-l1-contracts $TEST_ACCOUNTS_ARG $ACCELERATED_TEST_DEPLOYMENTS_ARG"
# Add account - use private key if set, otherwise use mnemonic
if [ -n "${L1_DEPLOYMENT_PRIVATE_KEY:-}" ]; then
base_cmd="$base_cmd --private-key $L1_DEPLOYMENT_PRIVATE_KEY"
else
base_cmd="$base_cmd --mnemonic '$MNEMONIC'"
fi
# Add validators if INIT_VALIDATORS is true
if [ "${INIT_VALIDATORS:-false}" = "true" ]; then
base_cmd="$base_cmd --validators $VALIDATOR_ADDRESSES"
fi
output=$(eval $base_cmd --l1-chain-id $CHAIN_ID --salt $SALT) && break
echo "Attempt $attempt failed. Retrying in $RETRY_DELAY seconds..."
sleep "$RETRY_DELAY"
done || {
echo "All l1 contract deploy attempts failed."
exit 1
}
echo "$output"
# Extract contract addresses using grep and regex
registry_address=$(echo "$output" | grep -oP 'Registry Address: \K0x[a-fA-F0-9]{40}')
slash_factory_address=$(echo "$output" | grep -oP 'SlashFactory Address: \K0x[a-fA-F0-9]{40}')
# Write the addresses to a file in the shared volume
cat <<EOF >/shared/contracts/contracts.env
export REGISTRY_CONTRACT_ADDRESS=$registry_address
export SLASH_FACTORY_CONTRACT_ADDRESS=$slash_factory_address
EOF
cat /shared/contracts/contracts.env