|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# output will be a dictionary of the form |
| 4 | +# { "contract1": "addr1", "contract2": "addr2", ... } |
| 5 | + |
| 6 | +# Parse command line arguments |
| 7 | +while [ $# -gt 0 ]; do |
| 8 | + case "$1" in |
| 9 | + --private-key) |
| 10 | + export PK="$2" |
| 11 | + shift 2 |
| 12 | + ;; |
| 13 | + --rpc-url) |
| 14 | + export NODE_URL="$2" |
| 15 | + shift 2 |
| 16 | + ;; |
| 17 | + --contracts-output) |
| 18 | + export OUTPUT="$2" |
| 19 | + shift 2 |
| 20 | + ;; |
| 21 | + *) |
| 22 | + echo "Unknown option: $1" |
| 23 | + echo "Usage: $0 --private-key <key> --rpc-url <url> --contracts-output <file>" |
| 24 | + exit 1 |
| 25 | + ;; |
| 26 | + esac |
| 27 | +done |
| 28 | + |
| 29 | +# Validate required arguments |
| 30 | +if [ -z "$PK" ] || [ -z "$NODE_URL" ] || [ -z "$OUTPUT" ]; then |
| 31 | + echo "Missing required arguments" |
| 32 | + echo "Usage: $0 --private-key <key> --rpc-url <url> --contracts-output <file>" |
| 33 | + exit 1 |
| 34 | +fi |
| 35 | + |
| 36 | +export PATH=/root/.foundry/bin:$PATH |
| 37 | +export RPC=$NODE_URL |
| 38 | + |
| 39 | +# silence stupid telemetry interactive question. |
| 40 | +export CI=1 |
| 41 | + |
| 42 | +# create a hash of the versions involved |
| 43 | +SINGLETON_SHA1=$(git --git-dir /safe-singleton-factory/.git rev-parse HEAD) |
| 44 | +CONTRACT_SHA1=$(git --git-dir /safe-smart-account/.git rev-parse HEAD) |
| 45 | + |
| 46 | +# a seed for new-mnemonic entropy. It doesn't have to be super robust, just to |
| 47 | +# differentiate between successive runs if we operate under different |
| 48 | +# conditions. |
| 49 | +SEED=$(jq -n \ |
| 50 | + --arg funded_wallet "$PK" \ |
| 51 | + --arg singleton_sha1 "$SINGLETON_SHA1" \ |
| 52 | + --arg contract_sha1 "$CONTRACT_SHA1" \ |
| 53 | + '{ |
| 54 | + "singleton_sha1": $singleton_sha1, |
| 55 | + "contract_sha1": $contract_sha1, |
| 56 | + "funded_wallet": $funded_wallet |
| 57 | + }' | md5sum | cut -d' ' -f1) |
| 58 | + |
| 59 | +# we need a fresh mnemonic to own the singleton factory, because the installer requires its NONCE to be 0 to succeed. |
| 60 | +TMP_MNEMONIC=$(cast wallet new-mnemonic -e "0x$SEED" --json | jq -r '.mnemonic') |
| 61 | + |
| 62 | +# owner of the singleton factory |
| 63 | +OWNER_ADDR=$(cast wallet address --mnemonic "$TMP_MNEMONIC") |
| 64 | + |
| 65 | +NONCE=$(cast nonce --rpc-url "$NODE_URL" "$OWNER_ADDR") |
| 66 | +if [ "$NONCE" -eq 0 ]; then # otherwise, we need to assume the singleton factory is already deployed |
| 67 | + # fund the owner of the singleton factory |
| 68 | + cast send --rpc-url "$NODE_URL" --private-key "$PK" --value 1ether "$OWNER_ADDR" |
| 69 | + |
| 70 | + # deploy the singleton factory |
| 71 | + pushd /safe-singleton-factory || exit 1 |
| 72 | + MNEMONIC="$TMP_MNEMONIC" npm run estimate-compile |
| 73 | + MNEMONIC="$TMP_MNEMONIC" npm run submit |
| 74 | + popd || exit |
| 75 | +fi |
| 76 | + |
| 77 | +# This part is idempotent, so for clarify let's leave it alone. Worst case it's |
| 78 | +# slightly wasteful when re-running. |
| 79 | +pushd /safe-smart-account || exit 1 |
| 80 | +npx --yes hardhat --network custom deploy \ |
| 81 | + | grep 0x \ |
| 82 | + | jq -Rn '[inputs | |
| 83 | + if contains("reusing") then |
| 84 | + capture("reusing \"(?<key>.*)\" at (?<value>.*)") |
| 85 | + else |
| 86 | + capture("deploying \"(?<key>.*)\" \\(tx: [^)]+\\)\\.\\.\\.: deployed at (?<value>[0-9a-fA-Fx]+)") |
| 87 | + end |
| 88 | + ] | from_entries' \ |
| 89 | + | tee "$OUTPUT" |
| 90 | +npx hardhat --network custom local-verify |
| 91 | +popd || exit |
0 commit comments