deployer.sh 2.06 KB
Newer Older
1
#!/bin/bash
2
set -euo
3

4
RETRIES=${RETRIES:-20}
5 6
JSON='{"jsonrpc":"2.0","id":0,"method":"net_version","params":[]}'

7 8 9 10 11
if [ -z "$CONTRACTS_RPC_URL" ]; then
    echo "Must specify \$CONTRACTS_RPC_URL."
    exit 1
fi

12
# wait for the base layer to be up
13
curl \
14 15
    --fail \
    --show-error \
16 17 18 19 20 21
    --silent \
    -H "Content-Type: application/json" \
    --retry-connrefused \
    --retry $RETRIES \
    --retry-delay 1 \
    -d $JSON \
22
    $CONTRACTS_RPC_URL > /dev/null
23

24 25
echo "Connected to L1."
echo "Building deployment command."
26

27
DEPLOY_CMD="npx hardhat deploy --network $CONTRACTS_TARGET_NETWORK"
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

echo "Deploying contracts. Deployment command:"
echo "$DEPLOY_CMD"
eval "$DEPLOY_CMD"

echo "Building addresses.json."
export ADDRESS_MANAGER_ADDRESS=$(cat "./deployments/$CONTRACTS_TARGET_NETWORK/Lib_AddressManager.json" | jq -r .address)

# First, create two files. One of them contains a list of addresses, the other contains a list of contract names.
find "./deployments/$CONTRACTS_TARGET_NETWORK" -maxdepth 1 -name '*.json' | xargs cat | jq -r '.address' > addresses.txt
find "./deployments/$CONTRACTS_TARGET_NETWORK" -maxdepth 1 -name '*.json' | sed -e "s/.\/deployments\/$CONTRACTS_TARGET_NETWORK\///g" | sed -e 's/.json//g' > filenames.txt

# Start building addresses.json.
echo "{" >> addresses.json
# Zip the two files describe above together, then, switch their order and format as JSON.
paste addresses.txt filenames.txt | sed -e "s/^\([^ ]\+\)\s\+\([^ ]\+\)/\"\2\": \"\1\",/" >> addresses.json
# Add the address manager alias.
echo "\"AddressManager\": \"$ADDRESS_MANAGER_ADDRESS\"" >> addresses.json
# End addresses.json
echo "}" >> addresses.json

echo "Built addresses.json. Content:"
jq . addresses.json

echo "Building dump file."
53 54 55
npx hardhat take-dump --network $CONTRACTS_TARGET_NETWORK
mv addresses.json ./genesis
cp ./genesis/$CONTRACTS_TARGET_NETWORK.json ./genesis/state-dump.latest.json
56

57 58 59
# expose the deployments
cp -rf ./deployments ./genesis/deployments

60
# service the addresses and dumps
61
echo "Starting server."
62 63
python3 -m http.server \
    --bind "0.0.0.0" 8081 \
64
    --directory ./genesis