Skip to content

Commit

Permalink
added multichain deployer and adapters to bash script
Browse files Browse the repository at this point in the history
  • Loading branch information
MrDeadCe11 committed Sep 10, 2024
1 parent a0492d2 commit 2b6d1de
Show file tree
Hide file tree
Showing 3 changed files with 199 additions and 88 deletions.
2 changes: 1 addition & 1 deletion script/BaseScript.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ contract BaseScript is BaseData {
}

function _loadJson(string calldata _path) internal {
string memory filePath = string(abi.encodePacked(vm.projectRoot(), "/", _path));
string memory filePath = string(abi.encodePacked(vm.projectRoot(), _path));
string memory json = vm.readFile(filePath);

// Reset the baseInput struct
Expand Down
4 changes: 4 additions & 0 deletions script/DeployL1OFTAdapter.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ contract DeployL1OFTAdapter is BaseScript {

vm.startBroadcast();

require(
currentDeployment.multiChainDeployer != address(0), "Must deploy multiChainDeployer to this chain."
);

address l1OFTAdapterImpl = address(
new L1YnOFTAdapterUpgradeable{salt: implementationSalt}(
baseInput.l1ERC20Address, getAddresses().LZ_ENDPOINT
Expand Down
281 changes: 194 additions & 87 deletions script/scriptManager.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ echo "EXECUTING"
######################
## GLOBAL VARIABLES ##
######################
# // forge script script/DeployL1OFTAdapter.s.sol:DeployL1OFTAdapter \
# // --rpc-url ${rpc} --sig "run(string calldata)" ${path} \
# // --account ${deployerAccountName} --sender ${deployer} \
# // --broadcast --etherscan-api-key ${api} --verify

# unset private key as we are reading it from cast wallet
PRIVATE_KEY=""
Expand All @@ -27,19 +23,21 @@ fi
## FUNCTIONS ##
###############
function delimitier() {
echo '#################################################'
echo '###################################################'
}

function broadcast() {
forge script $1 -s $2 --rpc-url $3 --account $DEPLOYER_ACCOUNT_NAME --sender $DEPLOYER_ADDRESS --broadcast --etherscan-api-key $ETHERSCAN_API_KEY --verify
}

function simulate() {
echo "simulating..."
forge script $1 -s $2 --rpc-url $3 --account $DEPLOYER_ACCOUNT_NAME --sender $DEPLOYER_ADDRESS
}

function display_help() {
echo "Displaying help"
echo "Help: /n"

}

function getRpcEndpoints() {
Expand All @@ -49,43 +47,51 @@ function getRpcEndpoints() {
done
}

function searchArray() {
local match=$1
local array=$2

for i in "${!array[@]}"; do
[[ "${array[i]}" == "${match}" ]] && break
done
echo $i
}

function getEndpoint() {
INPUT_ID=$1
if [[ $INPUT_ID != "[" || $INPUT_ID != "]" ]]; then
case $INPUT_ID in
1)
echo ${MAINNET_RPC_URL}
;;
8453)
#base
echo ${BASE_RPC_URL}
;;
10)
#optimism
echo ${OPTIMISM_RPC_URL}
;;
42161)
#arbitrum
echo ${ARBITRUM_RPC_URL}
;;
252)
#fraxal
echo ${FRAX_RPC_URL}
;;
17000)
#holskey
echo ${HOLESKY_RPC_URL}
;;
2522)
#fraxalTestnet
echo ${FRAX_TESTNET_RPC_URL}
;;
*)
echo "Unrecognized Chain id"
exit 1
;;
esac
fi
case $INPUT_ID in
1)
echo ${MAINNET_RPC_URL}
;;
8453)
#base
echo ${BASE_RPC_URL}
;;
10)
#optimism
echo ${OPTIMISM_RPC_URL}
;;
42161)
#arbitrum
echo ${ARBITRUM_RPC_URL}
;;
252)
#fraxal
echo ${FRAX_RPC_URL}
;;
17000)
#holskey
echo ${HOLESKY_RPC_URL}
;;
2522)
#fraxalTestnet
echo ${FRAX_TESTNET_RPC_URL}
;;
*)
echo "Unrecognized Chain id"
break
;;
esac
}

# Function to handle errors
Expand All @@ -96,67 +102,168 @@ function error_exit() {
}

function checkInput() {
if [[ -z $2 || "$2" == -* ]]; then
if [[ -z $2 || $2 == -* ]]; then
error_exit "Missing value for parameter $1"
fi
}

FILE_PATH=$1
if [[ "$FILE_PATH" == "" ]]; then
echo ""
# if the first character of the path is a / trim it off
if [[ "${FILE_PATH:0:1}" == "/" ]]; then
echo "trimming: $FILE_PATH"
FILE_PATH="${FILE_PATH:1}"
fi
echo "$FILE_PATH"
# check that there is an arg
if [[ -z $FILE_PATH ]]; then
display_help
shift
elif [[ -z $FILE_PATH && -f $FILE_PATH ]]; then
exit 1
#if arg is a filepath and is a file set input json and shift down 1 arg
elif [[ -f $FILE_PATH ]]; then
INPUT_JSON=$1
INPUT_JSON=$FILE_PATH
shift
while [[ $# -gt 0 ]]; do
case $1 in
--l1-rpc-url | -l1)
checkInput $1 $2
L1_RPC_URL=${rpc}
shift 2
;;
--etherscan-api-key | -api)
checkInput $1 $2
ETHERSCAN_API_KEY=${api}
shift 2
;;
--deployer-account-name | -account)
checkInput $1 $2
DEPLOYER_ACCOUNT_NAME=${account}
shift 2
;;
--deployer-account-address | -sender)
checkInput $1 $2
DEPLOYER_ADDRESS=${sender}
shift 2
;;
--help | -h)
display_help
;;
*)
echo "Error, unrecognized flag" >&2
display_help
;;
esac
done
else
echo "unrecognized input"
exit 1
fi

# gather flags used if you want to override the .env vars
while [[ $# -gt 0 ]]; do
case $1 in
--l1-rpc-url | -l1)
checkInput $1 $2
L1_RPC_URL=$2
shift 2
;;
# pass in an array of rpc's
--l2-rpc-urls | -l2)
checkInput $1 $2
L2_ENDPOINTS_ARRAY=$2
shift 2
;;
--etherscan-api-key | -api)
checkInput $1 $2
ETHERSCAN_API_KEY=$2
shift 2
;;
--deployer-account-name | -a)
checkInput $1 $2
DEPLOYER_ACCOUNT_NAME=$2
shift 2
;;
--sender-account-address | -s)
checkInput $1 $2
DEPLOYER_ADDRESS=$2
shift 2
;;
--help | -h)
display_help
exit 0
;;
*)
echo "Error, unrecognized flag" >&2
display_help
exit 1
;;
esac
done

L1_CHAIN_ID=$(jq -r ".l1ChainId" "$INPUT_JSON")
ERC20_NAME=$(jq -r ".erc20Name" "$INPUT_JSON")
L2_CHAIN_IDS_ARRAY=$(jq -r ".l2ChainIds" "$INPUT_JSON" | jq -r ".[]")
L2_ENDPOINTS_ARRAY=$(< <(getRpcEndpoints $L2_CHAIN_IDS_ARRAY))
L1_RPC_URL=$(getEndpoint $L1_CHAIN_ID)
echo "$L2_ENDPOINTS_ARRAY"
# if rpc url is not set by flag set it here
if [[ -z $L1_RPC_URL ]]; then
L1_RPC_URL=$(getEndpoint $L1_CHAIN_ID)
fi

# if [[ -z L1_RPC_URL ]]; then
# echo "Valid rpc required"
# exit 1
# fi
# verify the l1 rpc has been set
if [[ -z $L1_RPC_URL || $L1_RPC_URL == "Unrecognized Chain Id" ]]; then
echo "Valid rpc required"
exit 1
fi

# if the number of rpc's is less than the number of L2 chain ids
if [[ "${#L2_CHAIN_IDS_ARRAY[@]}" != "${#L2_ENDPOINTS_ARRAY[@]}" ]]; then
echo "Invalid L2 RPCs"
exit 1
fi

# forge script script/DeployL1OFTAdapter.s.sol:DeployL1OFTAdapter \
# --rpc-url ${rpc} --sig "run(string calldata)" ${path} \
# --account ${deployerAccountName} --sender ${deployer} \
# --broadcast --etherscan-api-key ${api} --verify

CALLDATA=$(cast calldata "run(string)" "/$FILE_PATH")
clear
echo "What would you like to deploy?"
select deployOptions in new-MultiChainDeployer new-L1-adapter new-L2-adapter display-help exit; do
case $deployOptions in
new-MultiChainDeployer)
# call simulation
simulate script/MultiChainDeployer.s.sol:MultiChainDeployer $CALLDATA $L1_RPC_URL
read -p "Simulation complete. Would You like to broadcast the deployment? (y/n)" yn
case $yn in
[Yy]*)
broadcast script/MultiChainDeployer.s.sol:DeployMultiChainDeployer $CALLDATA $L1_RPC_URL
;;
[Nn]*)
echo "Exiting..."
exit 0
;;
esac
break
;;
new-L1-adapter)
simulate script/DeployL1OFTAdapter.s.sol:DeployL1OFTAdapter $CALLDATA $L1_RPC_URL
read -p "Simulation complete. Would You like to broadcast the deployment? (y/n)" yn
case $yn in
[Yy]*)
broadcast script/DeplL2_ENDPOINTS_ARRAYoyL1OFTAdapter.s.sol:DeployL1OFTAdapter $CALLDATA $L1_RPC_URL
;;
[Nn]*)
echo "Exiting..."
exit 0
;;
esac
break
;;
new-L2-adapter)
L2_RPC_URL=''
echo "Please enter the Chain Id you would like to deploy on."
echo "Chain ids: ${L2_CHAIN_IDS_ARRAY[@]}"
read -p "enter chain id: " $SELECTED_CHAIN
arrayIndex=$(searchArray $SELECTED_CHAIN $L2_CHAIN_IDS_ARRAY)
L2_RPC_URL="${L2_ENDPOINTS_ARRAY[${arrayIndex}]}"
if [[ -z $L2_RPC_URL ]]; then
echo "Chain RPC not ound for $SELECTED_CHAIN"
exit 1
fi

simulate script/DeployL2OFTAdapter.s.sol:DeployL2OFTAdapter $CALLDATA $L2_RPC_URL

read -p "Simulation complete. Would You like to broadcast the deployment? (y/n)" yn

case $yn in
[Yy]*)
broadcast script/DeployL2OFTAdapter.s.sol:DeployL2OFTAdapter $CALLDATA $L2_RPC_URL
;;
[Nn]*)
echo "Exiting..."
exit 0
;;
esac
break
echo "Exiting..."
exit 0
;;
display-help)
display_help
exit 0
;;
exit)
echo "Exiting..."
exit 0
;;
esac
done
echo "Input json: $INPUT_JSON"
echo "chain id: $L1_CHAIN_ID"
echo "erc20 name: $ERC20_NAME"
Expand Down

0 comments on commit 2b6d1de

Please sign in to comment.