Skip to content

Commit

Permalink
chore: polish deploy-multi-chain script
Browse files Browse the repository at this point in the history
  • Loading branch information
smol-ninja committed Dec 13, 2023
1 parent 1cd1788 commit 7706379
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 21 deletions.
8 changes: 6 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ export MNEMONIC="YOUR_MNEMONIC"
export ARBITRUM_RPC_URL="YOUR_RPC_URL"
export AVALANCHE_RPC_URL="YOUR_RPC_URL"
export BASE_RPC_URL="YOUR_RPC_URL"
export BINANCE_RPC_URL="YOUR_RPC_URL"
export BSC_RPC_URL="YOUR_RPC_URL"
export GNOSIS_RPC_URL="YOUR_RPC_URL"
export MAINNET_RPC_URL="YOUR_RPC_URL"
export RPC_URL_MAINNET="YOUR_RPC_URL"
export OPTIMISM_RPC_URL="YOUR_RPC_URL"
export POLYGON_RPC_URL="YOUR_RPC_URL"
export SCROLL_RPC_URL="YOUR_RPC_URL"
export SEPOLIA_RPC_URL="YOUR_RPC_URL"

# Etherscan API keys
export ARBISCAN_API_KEY="YOUR_API_KEY"
Expand All @@ -37,4 +38,7 @@ export MAINNET_ADMIN="YOUR_ADMIN_ADDRESS"
export OPTIMISM_ADMIN="YOUR_ADMIN_ADDRESS"
export POLYGON_ADMIN="YOUR_ADMIN_ADDRESS"
export SCROLL_ADMIN="YOUR_ADMIN_ADDRESS"
export SEPOLIA_ADMIN="YOUR_ADMIN_ADDRESS"

# The maximum number of segments allowed in a stream
export MAX_SEGMENTS_COUNT="THE_MAX_SEGMENT_COUNT"
2 changes: 1 addition & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
bnb_smart_chain = "https://bsc-dataseed.binance.org"
gnosis_chain = "https://rpc.gnosischain.com"
localhost = "http://localhost:8545"
mainnet = "${MAINNET_RPC_URL}"
mainnet = "${RPC_URL_MAINNET}"
optimism = "https://optimism-mainnet.infura.io/v3/${API_KEY_INFURA}"
polygon = "https://polygon-mainnet.infura.io/v3/${API_KEY_INFURA}"
sepolia = "https://sepolia.infura.io/v3/${API_KEY_INFURA}"
65 changes: 47 additions & 18 deletions shell/deploy-multi-chains.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@

#!/usr/bin/env bash

# Usage: ./shell/deploy-multi-chains.sh [options] [chain1 [chain2 ...]]
# Options:
# --deterministic Deploy using the deterministic script.
# --broadcast Broadcast the deployment and verify on Etherscan.
# --with-gas-price Specify gas price for transaction.
# --all Deploy on all chains.
# Example: ./shell/deploy-multi-chains.sh # Default deploys only to Sepolia
# Example: ./shell/deploy-multi-chains.sh --broadcast arbitrum_one mainnet
# Example: ./shell/deploy-multi-chains.sh --deterministic --broadcast mainnet
Expand All @@ -13,10 +14,21 @@

# Pre-requisites:
# - foundry (https://getfoundry.sh)
# - bash version >=4.0.0

# Strict mode: https://gist.github.com/vncsna/64825d5609c146e80de8b1fd623011ca
set -euo pipefail

# color codes
EC='\033[0;31m' # Error Color
SC='\033[0;32m' # Success Color
WC='\033[0;33m' # Warn Color
IC='\033[0;36m' # Info Color
NC='\033[0m' # No Color

# Unicode characters for tick
TICK="\xE2\x9C\x94"

# Create deployments directory
deployments=./deployments
rm -rf $deployments
Expand All @@ -39,15 +51,26 @@ ARBITRUM_CHAIN_ID="42161"
AVALANCHE_CHAIN_ID="43114"
BASE_CHAIN_ID="8453"
BSC_CHAIN_ID="56"
GOERLI_CHAIN_ID="5"
GNOSIS_CHAIN_ID="100"
MAINNET_CHAIN_ID="1"
OPTIMISM_CHAIN_ID="10"
POLYGON_CHAIN_ID="137"
SCROLL_CHAIN_ID="534352"
SEPOLIA_CHAIN_ID="11155111"

echo $BASH_VERSION
# Source the .env file to load the variables
if [ -f .env ]; then
source .env
else
echo -e "${EC}Error: .env file not found${NC}"
exit 1
fi

# Check: required Bash >=4.0.0 for associative arrays
if ((BASH_VERSINFO[0] < 4)); then
echo -e "${EC}Error:\nThis script requires Bash version 4.0.0 or higher.\nYou are currently using Bash version ${BASH_VERSINFO[0]}.${BASH_VERSINFO[1]}.${BASH_VERSINFO[2]}.\nPlease upgrade your Bash version and try again.${NC}"
exit 1
fi

# Define chain configurations
declare -A chains
Expand All @@ -56,7 +79,7 @@ chains["avalanche"]="$AVALANCHE_RPC_URL $SNOWTRACE_API_KEY $AVALANCHE_CHAIN_ID $
chains["base"]="$BASE_RPC_URL $BASESCAN_API_KEY $BASE_CHAIN_ID $BASE_ADMIN"
chains["bnb_smart_chain"]="$BSC_RPC_URL $BSCSCAN_API_KEY $BSC_CHAIN_ID $BSC_ADMIN"
chains["gnosis"]="$GNOSIS_RPC_URL $GNOSISSCAN_API_KEY $GNOSIS_CHAIN_ID $GNOSIS_ADMIN"
chains["mainnet"]="$MAINNET_RPC_URL $ETHERSCAN_API_KEY $MAINNET_CHAIN_ID $MAINNET_ADMIN"
chains["mainnet"]="$RPC_URL_MAINNET $ETHERSCAN_API_KEY $MAINNET_CHAIN_ID $MAINNET_ADMIN"
chains["optimism"]="$OPTIMISM_RPC_URL $OPTIMISTIC_API_KEY $OPTIMISM_CHAIN_ID $OPTIMISM_ADMIN"
chains["polygon"]="$POLYGON_RPC_URL $POLYGONSCAN_API_KEY $POLYGON_CHAIN_ID $POLYGON_ADMIN"
chains["scroll"]="$SCROLL_RPC_URL $SCROLL_API_KEY $SCROLL_CHAIN_ID $SCROLL_ADMIN"
Expand All @@ -72,6 +95,9 @@ DETERMINISTIC_DEPLOYMENT=false
WITH_GAS_PRICE=false
GAS_PRICE=0

# Flag for all chains
ON_ALL_CHAINS=false

# Requested chains
requested_chains=()

Expand All @@ -87,7 +113,7 @@ for ((i=1; i<=$#; i++)); do
# Check for '--broadcast' flag in the arguments
if [[ $arg == "--deterministic" ]]; then
DETERMINISTIC_DEPLOYMENT=true
fi
fi

# Check for '--with-gas-price' flag in the arguments
if [[ $arg == "--with-gas-price" ]]; then
Expand All @@ -96,18 +122,19 @@ for ((i=1; i<=$#; i++)); do
((i++))
GAS_PRICE=${!i}
if ! [[ $GAS_PRICE =~ ^[0-9]+$ ]]; then
echo "Error: Gas price must be a number."
echo -e "${EC}Error: Invalid value for --with-gas-price, must be number${NC}"
exit 1
fi
fi

# Check for '--all' flag in the arguments
if [[ $arg == "--all" ]]; then
ON_ALL_CHAINS=true
requested_chains=("${!chains[@]}")
fi

# Check for passed chains
if [[ $arg != "--all" && $arg != "--deterministic" && $arg != "--broadcast" && $arg != "--with-gas-price" ]]; then
if [[ $arg != "--all" && $arg != "--deterministic" && $arg != "--broadcast" && $arg != "--with-gas-price" && $ON_ALL_CHAINS == false ]]; then
requested_chains+=("$arg")
fi
done
Expand All @@ -125,7 +152,7 @@ FOUNDRY_PROFILE=optimized forge build
for chain in "${requested_chains[@]}"; do
# Check if the requested chain is defined
if [[ ! -v "chains[$chain]" ]]; then
echo "Chain configuration for '$chain' not found."
echo -e "\n${WC}Warning: Chain configuration for '$chain' not found.${NC}"
continue
fi

Expand All @@ -137,36 +164,38 @@ for chain in "${requested_chains[@]}"; do

# Choose the script based on the flag
if [[ $DETERMINISTIC_DEPLOYMENT == true ]]; then
echo "Deploying deterministic contracts to $chain..."
echo -e "\n${IC}Deploying deterministic contracts to $chain...${NC}"
# Construct the command
deployment_command="forge script script/DeployDeterministicCore.s.sol \
--rpc-url $rpc_url \
--sig run(string,address,uint256) \
\"ChainID $chain_id, Version 1.1.0\" \
\'ChainID $chain_id, Version 1.1.0\' \
$admin \
$MAX_SEGMENTS_COUNT \
-vv"
-vvv"
else
echo "Deploying contracts to $chain..."
echo -e "\n${IC}Deploying contracts to $chain...${NC}"
# Construct the command
deployment_command="forge script script/DeployCore.s.sol \
--rpc-url $rpc_url \
--sig run(address,uint256) \
$admin \
$MAX_SEGMENTS_COUNT \
-vv"
-vvv"
fi

# Append additional options if broadcast is enabled
if [[ $BROADCAST_DEPLOYMENT == true ]]; then
echo "This deployment is broadcasted on $chain"
if [[ $BROADCAST_DEPLOYMENT == true ]]; then
echo -e "${SC}+${NC} Broadcasting on $chain"
deployment_command+=" --broadcast --verify --etherscan-api-key \"$api_key\""
else
echo -e "${SC}+${NC} Simulating on $chain"
fi

# Append additional options if gas price is enabled
if [[ $WITH_GAS_PRICE == true ]]; then
gas_price_in_gwei=$(echo "scale=2; $GAS_PRICE / 1000000000" | bc)
echo "This deployment is using gas price of $gas_price_in_gwei gwei"
echo -e "${SC}+${NC} Using gas price of $gas_price_in_gwei gwei"
deployment_command+=" --with-gas-price $GAS_PRICE"
fi

Expand All @@ -191,7 +220,7 @@ for chain in "${requested_chains[@]}"; do
echo "SablierV2NFTDescriptor = $nftDescriptor_address"
} >> "$chain_file"

echo "Deployment for $chain done. Addresses saved in $chain_file"
echo -e "${SC}$TICK Deployed on $chain. Addresses saved in $chain_file${NC}"
done

echo "All deployments completed."
echo -e "\nAll deployments completed."

0 comments on commit 7706379

Please sign in to comment.