From 4bae93ca6f6b8ebd4bac59889474eb9dec83b0c5 Mon Sep 17 00:00:00 2001 From: Dylan DesRosier Date: Fri, 13 Sep 2024 15:30:00 -0400 Subject: [PATCH] feat: add simple scripts for verifying contracts on etherscan(s) --- script/verify-contract.sh | 56 ++++++++++++++++++++++++++++ script/verify-enforcer-contracts.sh | 58 +++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100755 script/verify-contract.sh create mode 100755 script/verify-enforcer-contracts.sh diff --git a/script/verify-contract.sh b/script/verify-contract.sh new file mode 100755 index 0000000..a80ac56 --- /dev/null +++ b/script/verify-contract.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +################################################################################ +# Verifies a contract across multiple chains +# - Requires the contract to be at the same address on every chain +# - Requires the appropriate API keys to be set in .env +################################################################################ + +# Example usage: +# CONTRACT=DelegationManager +# ADDRESS=0x0000000000000000000000000000000000000000 +# CONSTRUCTOR="constructor(string,string,uint256,uint256)" "ForgeUSD" "FUSD" 18 1000000000000000000000 + +CONTRACT=NativeTokenPaymentEnforcer +ADDRESS=0x87Fe18EbF99e42fcE8A03a25F1d20E119407f8e7 +CONSTRUCTOR_ARGS=$(cast abi-encode "constructor(address, address)" "0x56D56e07e3d6Ee5a24e30203A37a0a460f42D7A3" "0x7378dE585998d3E18Ce147867C335C25B3dB8Ee5") + +# sepolia, linea-sepolia, linea, base, optimism, arbitrum, polygon +CHAIN_IDS=(11155111 59141 59144 8453 10 42161 137) + +set -o allexport +source .env +set +o allexport + +# Function to get the appropriate API key based on chain ID +get_api_key() { + case $1 in + 11155111) echo "$ETHERSCAN_API_KEY" ;; + 59144) echo "$LINEASCAN_API_KEY" ;; + 59141) echo "$LINEASCAN_API_KEY" ;; + 8453) echo "$BASESCAN_API_KEY" ;; + 10) echo "$OPTIMISTIC_ETHERSCAN_API_KEY" ;; + 42161) echo "$ARBISCAN_API_KEY" ;; + 137) echo "$POLYGONSCAN_API_KEY" ;; + *) echo "Unknown chain ID" && return 1 ;; + esac +} + +for CHAIN_ID in "${CHAIN_IDS[@]}" + do + API_KEY=$(get_api_key $CHAIN_ID) + + echo "Verifying $CONTRACT at $ADDRESS on $CHAIN_ID..." + + forge verify-contract \ + --chain-id $CHAIN_ID \ + --num-of-optimizations 200 \ + --watch \ + --constructor-args $CONSTRUCTOR_ARGS \ + --etherscan-api-key $API_KEY \ + $ADDRESS \ + src/enforcers/$CONTRACT.sol:$CONTRACT + + echo "Verification of $CONTRACT on $CHAIN_ID completed." + echo "-------------------------------------------" + done diff --git a/script/verify-enforcer-contracts.sh b/script/verify-enforcer-contracts.sh new file mode 100755 index 0000000..dbfdf6a --- /dev/null +++ b/script/verify-enforcer-contracts.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +################################################################################ +# Verifies contracts across multiple chains +# - Requires contracts to be at the same address on every chain +# - Requires the appropriate API keys to be set in .env +# - Requires the contracts to have no constructor arguments +################################################################################ + +# Note: Array lengths must line up +ENFORCERS=() +ADDRESSES=() + +# sepolia, linea-sepolia, linea, base, optimism, arbitrum, polygon +CHAIN_IDS=(11155111 59141 59144 8453 10 42161 137) + +set -o allexport +source .env +set +o allexport + +# Function to get the appropriate API key based on chain ID +get_api_key() { + case $1 in + 11155111) echo "$ETHERSCAN_API_KEY" ;; + 59144) echo "$LINEASCAN_API_KEY" ;; + 59141) echo "$LINEASCAN_API_KEY" ;; + 8453) echo "$BASESCAN_API_KEY" ;; + 10) echo "$OPTIMISTIC_ETHERSCAN_API_KEY" ;; + 42161) echo "$ARBISCAN_API_KEY" ;; + 137) echo "$POLYGONSCAN_API_KEY" ;; + *) echo "Unknown chain ID" && return 1 ;; + esac +} +for ((i=0; i<${#ENFORCERS[@]}; i++)); do + echo "Iteration $i" + echo "-------------------------------------------" + + CONTRACT=${ENFORCERS[i]} + ADDRESS=${ADDRESSES[i]} + + for CHAIN_ID in "${CHAIN_IDS[@]}" + do + API_KEY=$(get_api_key $CHAIN_ID) + + echo "Verifying $CONTRACT at $ADDRESS on $CHAIN_ID..." + + forge verify-contract \ + --chain-id $CHAIN_ID \ + --num-of-optimizations 200 \ + --watch \ + --etherscan-api-key $API_KEY \ + $ADDRESS \ + src/enforcers/$CONTRACT.sol:$CONTRACT + + echo "Verification of $CONTRACT on $CHAIN_ID completed." + echo "-------------------------------------------" + done +done