2023-04-03 12:43:29 +00:00
|
|
|
#!/bin/sh
|
|
|
|
set -e
|
2023-04-05 11:56:38 +00:00
|
|
|
if [ -n "$CERC_SCRIPT_DEBUG" ]; then
|
|
|
|
set -x
|
|
|
|
fi
|
2023-04-03 12:43:29 +00:00
|
|
|
|
2023-04-06 09:47:00 +00:00
|
|
|
echo "Using L2 RPC endpoint ${L2_GETH_RPC}"
|
|
|
|
|
2023-04-05 11:56:38 +00:00
|
|
|
if [ -f /geth-accounts/accounts.csv ]; then
|
|
|
|
echo "Using L1 private key from the mounted volume"
|
|
|
|
# Read the private key of L1 account to deploy contract
|
|
|
|
PRIVATE_KEY_DEPLOYER=$(head -n 1 /geth-accounts/accounts.csv | cut -d ',' -f 3)
|
|
|
|
else
|
|
|
|
echo "Using PRIVATE_KEY_DEPLOYER from env"
|
|
|
|
fi
|
2023-04-03 12:43:29 +00:00
|
|
|
|
|
|
|
# Set the private key
|
2023-04-05 11:56:38 +00:00
|
|
|
jq --arg privateKey "$PRIVATE_KEY_DEPLOYER" '.privateKey = $privateKey' secrets-template.json > secrets.json
|
|
|
|
|
2023-04-05 12:22:12 +00:00
|
|
|
# Set the RPC URL
|
2023-04-06 09:47:00 +00:00
|
|
|
jq --arg rpcUrl "$L2_GETH_RPC" '.rpcUrl = $rpcUrl' secrets.json > secrets_updated.json && mv secrets_updated.json secrets.json
|
|
|
|
|
2023-04-10 05:12:56 +00:00
|
|
|
# Set the MobyMask app base URI
|
|
|
|
jq --arg baseURI "$MOBYMASK_APP_BASE_URI" '.baseURI = $baseURI' secrets.json > secrets_updated.json && mv secrets_updated.json secrets.json
|
|
|
|
|
2023-04-06 09:47:00 +00:00
|
|
|
export RPC_URL="${L2_GETH_RPC}"
|
2023-04-05 11:56:38 +00:00
|
|
|
|
2023-04-06 09:47:00 +00:00
|
|
|
# Check if DEPLOYED_CONTRACT environment variable set to skip contract deployment
|
|
|
|
if [[ -n "$DEPLOYED_CONTRACT" ]]; then
|
|
|
|
echo "DEPLOYED_CONTRACT is set to '$DEPLOYED_CONTRACT'"
|
|
|
|
echo "Exiting without deploying contract"
|
|
|
|
exit 0
|
|
|
|
fi
|
2023-04-05 11:56:38 +00:00
|
|
|
|
2023-04-05 12:22:12 +00:00
|
|
|
# Check and exit if a deployment already exists (on restarts)
|
|
|
|
if [ -f ./config.json ]; then
|
|
|
|
echo "config.json already exists, checking the contract deployment"
|
|
|
|
|
|
|
|
# Read JSON file
|
|
|
|
DEPLOYMENT_DETAILS=$(cat config.json)
|
|
|
|
CONTRACT_ADDRESS=$(echo "$DEPLOYMENT_DETAILS" | jq -r '.address')
|
|
|
|
|
|
|
|
cd ../hardhat
|
|
|
|
if yarn verifyDeployment --network optimism --contract "${CONTRACT_ADDRESS}"; then
|
|
|
|
echo "Deployment verfication successful"
|
|
|
|
cd ../server
|
|
|
|
else
|
|
|
|
echo "Deployment verfication failed, please clear MobyMask deployment volume before starting"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2023-04-06 09:47:00 +00:00
|
|
|
# Wait until balance for deployer account is updated
|
2023-04-05 12:22:12 +00:00
|
|
|
cd ../hardhat
|
2023-04-05 11:56:38 +00:00
|
|
|
while true; do
|
2023-04-06 09:47:00 +00:00
|
|
|
ACCOUNT_BALANCE=$(yarn balance --network optimism "$PRIVATE_KEY_DEPLOYER" | grep ETH)
|
2023-04-05 11:56:38 +00:00
|
|
|
|
|
|
|
if [ "$ACCOUNT_BALANCE" != "0.0 ETH" ]; then
|
|
|
|
echo "Account balance updated: $ACCOUNT_BALANCE"
|
|
|
|
break # exit the loop
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Account balance not updated: $ACCOUNT_BALANCE"
|
|
|
|
echo "Checking after 2 seconds"
|
|
|
|
sleep 2
|
|
|
|
done
|
2023-04-03 12:43:29 +00:00
|
|
|
|
2023-04-05 11:56:38 +00:00
|
|
|
cd ../server
|
|
|
|
npm run deployAndGenerateInvite
|