|
| 1 | +#!/bin/bash |
| 2 | +set -eu |
| 3 | + |
| 4 | +# Setting Infura or Alchemy key to use for convenience here |
| 5 | +#export INFURA_KEY="f88abc181a4a45a6bc47bdda05a94944" |
| 6 | +export ALCHEMY_KEY="fbS06B9gi4kYSsliFu_Hj5gamIShXt9I" |
| 7 | + |
| 8 | +# Example usage: |
| 9 | +# $ scripts/deployment/guardedRun.sh --network goerli --dry-run |
| 10 | +# PRIVATE_KEY=0x123..64 |
| 11 | + |
| 12 | +network='mainnet' |
| 13 | +args="$@" |
| 14 | +dry_run='false' |
| 15 | +force='false' |
| 16 | + |
| 17 | +while [[ "$@" ]]; do |
| 18 | + case "$1" in |
| 19 | + --network) |
| 20 | + if [ "$2" ]; then |
| 21 | + network="$2" |
| 22 | + shift 1 |
| 23 | + fi |
| 24 | + ;; |
| 25 | + --dry-run) |
| 26 | + dry_run='true' |
| 27 | + ;; |
| 28 | + --force) |
| 29 | + force='true' |
| 30 | + ;; |
| 31 | + -?) |
| 32 | + # ignore |
| 33 | + ;; |
| 34 | + esac |
| 35 | + shift 1 |
| 36 | +done |
| 37 | + |
| 38 | +# Setting Etherscan key to use for convenience here |
| 39 | +if [[ $network == optimism* ]]; then |
| 40 | + export ETHERSCAN_KEY="RPKYAHCE6R2YI7TRV51WS5N8R885RRNXG3" # Use for Optimism & optimistic testnets |
| 41 | +else |
| 42 | + export ETHERSCAN_KEY="XQPPJGFR4J3I6PEISYEG4JPETFZ2EF56EX" # Use for Ethereum & testnets |
| 43 | +fi |
| 44 | + |
| 45 | +if [[ "${dry_run}" == 'false' ]]; then |
| 46 | + if [[ "$(git status --porcelain)" ]]; then |
| 47 | + echo "Error: git working directory must be empty to run deploy script." |
| 48 | + exit 1 |
| 49 | + fi |
| 50 | + |
| 51 | + if [[ "$(git log --pretty=format:'%H' -n 1)" != "$(cat ./build/canary.hash)" ]]; then |
| 52 | + echo "Error: Build canary does not match current commit hash. Please run pnpm run build." |
| 53 | + exit 1 |
| 54 | + fi |
| 55 | +fi |
| 56 | + |
| 57 | +# Skip prompt if PRIVATE_KEY variable already exists |
| 58 | +if [[ -z "${PRIVATE_KEY:-}" ]]; then |
| 59 | + # Prompt the user for a PRIVATE_KEY without echoing to bash output. |
| 60 | + # Then export PRIVATE_KEY to an environment variable that won't get |
| 61 | + # leaked to bash history. |
| 62 | + # |
| 63 | + # WARNING: environment variables are still leaked to the process table |
| 64 | + # while a process is running, and hence visible in a call to `ps -E`. |
| 65 | + echo "Enter a private key (0x{64 hex chars}) for contract deployment," |
| 66 | + echo "or leave blank if performing a dry run without authorization." |
| 67 | + read -s -p "PRIVATE_KEY=" PRIVATE_KEY |
| 68 | + export PRIVATE_KEY |
| 69 | +fi |
| 70 | + |
| 71 | +# Log file name |
| 72 | +network_log="-${network}" |
| 73 | +dry_run_log='' |
| 74 | +if [[ "${dry_run}" == 'true' ]]; then |
| 75 | + dry_run_log='-dry-run' |
| 76 | +fi |
| 77 | +timestamp_log="-$(date +%s)" |
| 78 | + |
| 79 | +ts-node ./scripts/deploy.ts \ |
| 80 | + --waffle-config ./waffle.json \ |
| 81 | + ${args} \ |
| 82 | + --out-file "deployments-${network}.json" \ |
| 83 | + --log "./cache/deploy${network_log}${dry_run_log}${timestamp_log}.log" |
0 commit comments