#!/bin/bash set -e if [ -n "$CERC_SCRIPT_DEBUG" ]; then set -x fi addresses_deployment_file="packages/nitro-protocol/addresses.json" nitro_addresses_file="/app/deployment/nitro-addresses.json" bridge_assets_map_file="/app/deployment/bridge-assets-map.toml" echo "Using the following environment variables:" echo "CERC_GETH_URL: ${CERC_GETH_URL}" echo "CERC_OPTIMISM_URL: ${CERC_OPTIMISM_URL}" echo "CERC_GETH_CHAIN_ID: ${CERC_GETH_CHAIN_ID}" echo "CERC_OPTIMISM_CHAIN_ID: ${CERC_OPTIMISM_CHAIN_ID}" echo "CERC_GETH_DEPLOYER_PK: ${CERC_GETH_DEPLOYER_PK}" echo "CERC_OPTIMISM_DEPLOYER_PK: ${CERC_OPTIMISM_DEPLOYER_PK}" echo "CERC_TOKEN_NAME: ${CERC_TOKEN_NAME}" echo "CERC_TOKEN_SYMBOL: ${CERC_TOKEN_SYMBOL}" echo "CERC_INITIAL_TOKEN_SUPPLY: ${CERC_INITIAL_TOKEN_SUPPLY}" export GETH_URL=$CERC_GETH_URL export GETH_CHAIN_ID=$CERC_GETH_CHAIN_ID export OPTIMISM_CHAIN_ID=$CERC_OPTIMISM_CHAIN_ID export OPTIMISM_URL=$CERC_OPTIMISM_URL export GETH_DEPLOYER_PK=$CERC_GETH_DEPLOYER_PK export OPTIMISM_DEPLOYER_PK=$GETH_DEPLOYER_PK export DISABLE_DETERMINISTIC_DEPLOYMENT=true export TOKEN_NAME=$CERC_TOKEN_NAME export TOKEN_SYMBOL=$CERC_TOKEN_SYMBOL export INITIAL_TOKEN_SUPPLY=$CERC_INITIAL_TOKEN_SUPPLY # Check if L1 chain id key is present for L1 deployment if [ -f "$nitro_addresses_file" ] && jq -e "has(\"$GETH_CHAIN_ID\")" ${nitro_addresses_file} > /dev/null; then echo "L1 addresses found in ${nitro_addresses_file}, skipping deployment" else # Deploy Nitro contracts yarn contracts:deploy-geth # Deploy custom token yarn contracts:deploy-token-geth cp ${addresses_deployment_file} ${nitro_addresses_file} fi # Check if L1 chain id key is present for L1 deployment if [ -f "$nitro_addresses_file" ] && jq -e "has(\"$OPTIMISM_CHAIN_ID\")" ${nitro_addresses_file} > /dev/null; then echo "L2 addresses found in ${nitro_addresses_file}, skipping deployment" else # Deploy Nitro contracts yarn contracts:deploy-optimism # Deploy custom token yarn contracts:deploy-token-optimism cp ${addresses_deployment_file} ${nitro_addresses_file} fi L1_ASSET_ADDRESS=$(jq -r ".\"$GETH_CHAIN_ID\"[0].contracts.Token.address" ${nitro_addresses_file}) L2_ASSET_ADDRESS=$(jq -r ".\"$OPTIMISM_CHAIN_ID\"[0].contracts.Token.address" ${nitro_addresses_file}) # Deploy custom tokens and create bridge-assets-map.toml cat < "$bridge_assets_map_file" [[assets]] l1AssetAddress = "$L1_ASSET_ADDRESS" l2AssetAddress = "$L2_ASSET_ADDRESS" EOF echo "Done"