2023-04-03 07:03:47 +00:00
|
|
|
#!/bin/bash
|
|
|
|
set -e
|
2023-04-04 09:23:28 +00:00
|
|
|
if [ -n "$CERC_SCRIPT_DEBUG" ]; then
|
|
|
|
set -x
|
|
|
|
fi
|
2023-04-03 07:03:47 +00:00
|
|
|
|
2023-04-11 10:51:03 +00:00
|
|
|
CERC_L1_CHAIN_ID="${CERC_L1_CHAIN_ID:-${DEFAULT_CERC_L1_CHAIN_ID}}"
|
|
|
|
CERC_L1_RPC="${CERC_L1_RPC:-${DEFAULT_CERC_L1_RPC}}"
|
|
|
|
|
|
|
|
CERC_L1_ADDRESS="${CERC_L1_ADDRESS:-${DEFAULT_CERC_L1_ADDRESS}}"
|
|
|
|
CERC_L1_PRIV_KEY="${CERC_L1_PRIV_KEY:-${DEFAULT_CERC_L1_PRIV_KEY}}"
|
|
|
|
CERC_L1_ADDRESS_2="${CERC_L1_ADDRESS_2:-${DEFAULT_CERC_L1_ADDRESS_2}}"
|
|
|
|
CERC_L1_PRIV_KEY_2="${CERC_L1_PRIV_KEY_2:-${DEFAULT_CERC_L1_PRIV_KEY_2}}"
|
|
|
|
|
|
|
|
echo "Using L1 RPC endpoint ${CERC_L1_RPC}"
|
2023-04-04 09:23:28 +00:00
|
|
|
|
2023-04-05 04:55:50 +00:00
|
|
|
IMPORT_1="import './verify-contract-deployment'"
|
|
|
|
IMPORT_2="import './rekey-json'"
|
|
|
|
IMPORT_3="import './send-balance'"
|
|
|
|
|
|
|
|
# Append mounted tasks to tasks/index.ts file if not present
|
|
|
|
if ! grep -Fxq "$IMPORT_1" tasks/index.ts; then
|
|
|
|
echo "$IMPORT_1" >> tasks/index.ts
|
|
|
|
echo "$IMPORT_2" >> tasks/index.ts
|
|
|
|
echo "$IMPORT_3" >> tasks/index.ts
|
|
|
|
fi
|
2023-04-03 07:03:47 +00:00
|
|
|
|
|
|
|
# Update the chainId in the hardhat config
|
2023-04-11 10:51:03 +00:00
|
|
|
sed -i "/getting-started/ {n; s/.*chainId.*/ chainId: $CERC_L1_CHAIN_ID,/}" hardhat.config.ts
|
2023-04-03 07:03:47 +00:00
|
|
|
|
2023-04-05 04:55:50 +00:00
|
|
|
# Exit if a deployment already exists (on restarts)
|
|
|
|
# Note: fixturenet-eth-geth currently starts fresh on a restart
|
|
|
|
if [ -d "deployments/getting-started" ]; then
|
|
|
|
echo "Deployment directory deployments/getting-started found, checking SystemDictator deployment"
|
|
|
|
|
|
|
|
# Read JSON file into variable
|
|
|
|
SYSTEM_DICTATOR_DETAILS=$(cat deployments/getting-started/SystemDictator.json)
|
|
|
|
|
|
|
|
# Parse JSON into variables
|
|
|
|
SYSTEM_DICTATOR_ADDRESS=$(echo "$SYSTEM_DICTATOR_DETAILS" | jq -r '.address')
|
|
|
|
SYSTEM_DICTATOR_TXHASH=$(echo "$SYSTEM_DICTATOR_DETAILS" | jq -r '.transactionHash')
|
|
|
|
|
|
|
|
if yarn hardhat verify-contract-deployment --contract "${SYSTEM_DICTATOR_ADDRESS}" --transaction-hash "${SYSTEM_DICTATOR_TXHASH}"; then
|
|
|
|
echo "Deployment verfication successful, exiting"
|
|
|
|
exit 0
|
|
|
|
else
|
|
|
|
echo "Deployment verfication failed, please clear L1 deployment volume before starting"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2023-04-03 07:03:47 +00:00
|
|
|
# Generate the L2 account addresses
|
|
|
|
yarn hardhat rekey-json --output /l2-accounts/keys.json
|
|
|
|
|
|
|
|
# Read JSON file into variable
|
|
|
|
KEYS_JSON=$(cat /l2-accounts/keys.json)
|
|
|
|
|
|
|
|
# Parse JSON into variables
|
|
|
|
ADMIN_ADDRESS=$(echo "$KEYS_JSON" | jq -r '.Admin.address')
|
|
|
|
ADMIN_PRIV_KEY=$(echo "$KEYS_JSON" | jq -r '.Admin.privateKey')
|
|
|
|
PROPOSER_ADDRESS=$(echo "$KEYS_JSON" | jq -r '.Proposer.address')
|
|
|
|
BATCHER_ADDRESS=$(echo "$KEYS_JSON" | jq -r '.Batcher.address')
|
|
|
|
SEQUENCER_ADDRESS=$(echo "$KEYS_JSON" | jq -r '.Sequencer.address')
|
|
|
|
|
2023-04-03 12:43:29 +00:00
|
|
|
# Read the private key of L1 accounts
|
2023-04-04 09:23:28 +00:00
|
|
|
if [ -f /geth-accounts/accounts.csv ]; then
|
|
|
|
echo "Using L1 account credentials from the mounted volume"
|
2023-04-11 10:51:03 +00:00
|
|
|
CERC_L1_ADDRESS=$(head -n 1 /geth-accounts/accounts.csv | cut -d ',' -f 2)
|
|
|
|
CERC_L1_PRIV_KEY=$(head -n 1 /geth-accounts/accounts.csv | cut -d ',' -f 3)
|
|
|
|
CERC_L1_ADDRESS_2=$(awk -F, 'NR==2{print $(NF-1)}' /geth-accounts/accounts.csv)
|
|
|
|
CERC_L1_PRIV_KEY_2=$(awk -F, 'NR==2{print $NF}' /geth-accounts/accounts.csv)
|
2023-04-04 09:23:28 +00:00
|
|
|
else
|
|
|
|
echo "Using L1 account credentials from env"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Select a finalized L1 block as the starting point for roll ups
|
2023-04-11 10:51:03 +00:00
|
|
|
until FINALIZED_BLOCK=$(cast block finalized --rpc-url "$CERC_L1_RPC"); do
|
2023-04-04 09:23:28 +00:00
|
|
|
echo "Waiting for a finalized L1 block to exist, retrying after 10s"
|
|
|
|
sleep 10
|
|
|
|
done
|
|
|
|
|
|
|
|
L1_BLOCKNUMBER=$(echo "$FINALIZED_BLOCK" | awk '/number/{print $2}')
|
|
|
|
L1_BLOCKHASH=$(echo "$FINALIZED_BLOCK" | awk '/hash/{print $2}')
|
|
|
|
L1_BLOCKTIMESTAMP=$(echo "$FINALIZED_BLOCK" | awk '/timestamp/{print $2}')
|
|
|
|
|
|
|
|
echo "Selected L1 block ${L1_BLOCKNUMBER} as the starting block for roll ups"
|
2023-04-03 07:03:47 +00:00
|
|
|
|
|
|
|
# Send balances to the above L2 addresses
|
2023-04-11 10:51:03 +00:00
|
|
|
yarn hardhat send-balance --to "${ADMIN_ADDRESS}" --amount 2 --private-key "${CERC_L1_PRIV_KEY}" --network getting-started
|
|
|
|
yarn hardhat send-balance --to "${PROPOSER_ADDRESS}" --amount 5 --private-key "${CERC_L1_PRIV_KEY}" --network getting-started
|
|
|
|
yarn hardhat send-balance --to "${BATCHER_ADDRESS}" --amount 1000 --private-key "${CERC_L1_PRIV_KEY}" --network getting-started
|
2023-04-03 07:03:47 +00:00
|
|
|
|
|
|
|
echo "Balances sent to L2 accounts"
|
|
|
|
|
|
|
|
# Update the deployment config
|
|
|
|
sed -i 's/"l2OutputOracleStartingTimestamp": TIMESTAMP/"l2OutputOracleStartingTimestamp": '"$L1_BLOCKTIMESTAMP"'/g' deploy-config/getting-started.json
|
2023-04-11 10:51:03 +00:00
|
|
|
jq --arg chainid "$CERC_L1_CHAIN_ID" '.l1ChainID = ($chainid | tonumber)' deploy-config/getting-started.json > tmp.json && mv tmp.json deploy-config/getting-started.json
|
2023-04-03 07:03:47 +00:00
|
|
|
|
|
|
|
node update-config.js deploy-config/getting-started.json "$ADMIN_ADDRESS" "$PROPOSER_ADDRESS" "$BATCHER_ADDRESS" "$SEQUENCER_ADDRESS" "$L1_BLOCKHASH"
|
|
|
|
|
|
|
|
echo "Updated the deployment config"
|
|
|
|
|
|
|
|
# Create a .env file
|
2023-04-11 10:51:03 +00:00
|
|
|
echo "CERC_L1_RPC=$CERC_L1_RPC" > .env
|
2023-04-03 07:03:47 +00:00
|
|
|
echo "PRIVATE_KEY_DEPLOYER=$ADMIN_PRIV_KEY" >> .env
|
|
|
|
|
|
|
|
echo "Deploying the L1 smart contracts, this will take a while..."
|
|
|
|
|
|
|
|
# Deploy the L1 smart contracts
|
|
|
|
yarn hardhat deploy --network getting-started
|
|
|
|
|
|
|
|
echo "Deployed the L1 smart contracts"
|
|
|
|
|
2023-04-03 12:43:29 +00:00
|
|
|
# Read Proxy contract's JSON and get the address
|
2023-04-03 07:03:47 +00:00
|
|
|
PROXY_JSON=$(cat deployments/getting-started/Proxy__OVM_L1StandardBridge.json)
|
|
|
|
PROXY_ADDRESS=$(echo "$PROXY_JSON" | jq -r '.address')
|
|
|
|
|
2023-04-03 12:43:29 +00:00
|
|
|
# Send balance to the above Proxy contract in L1 for reflecting balance in L2
|
|
|
|
# First account
|
2023-04-11 10:51:03 +00:00
|
|
|
yarn hardhat send-balance --to "${PROXY_ADDRESS}" --amount 1 --private-key "${CERC_L1_PRIV_KEY}" --network getting-started
|
2023-04-03 12:43:29 +00:00
|
|
|
# Second account
|
2023-04-11 10:51:03 +00:00
|
|
|
yarn hardhat send-balance --to "${PROXY_ADDRESS}" --amount 1 --private-key "${CERC_L1_PRIV_KEY_2}" --network getting-started
|
2023-04-03 07:03:47 +00:00
|
|
|
|
|
|
|
echo "Balance sent to Proxy L2 contract"
|
2023-04-03 12:43:29 +00:00
|
|
|
echo "Use following accounts for transactions in L2:"
|
2023-04-11 10:51:03 +00:00
|
|
|
echo "${CERC_L1_ADDRESS}"
|
|
|
|
echo "${CERC_L1_ADDRESS_2}"
|
2023-04-03 07:03:47 +00:00
|
|
|
echo "Done"
|