Use a common contract deployment script from mobymask-v3 stack
This commit is contained in:
parent
f1cb56d0f1
commit
27e334c4f8
@ -32,20 +32,14 @@ services:
|
||||
environment:
|
||||
CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG}
|
||||
ENV: "PROD"
|
||||
CERC_L2_GETH_RPC: ${CERC_L2_GETH_RPC}
|
||||
CERC_ETH_RPC_ENDPOINT: ${CERC_ETH_RPC_ENDPOINT:-http://fixturenet-eth-geth-1:8545}
|
||||
CERC_L1_ACCOUNTS_CSV_URL: ${CERC_L1_ACCOUNTS_CSV_URL}
|
||||
CERC_PRIVATE_KEY_DEPLOYER: ${CERC_PRIVATE_KEY_DEPLOYER}
|
||||
CERC_MOBYMASK_APP_BASE_URI: ${CERC_MOBYMASK_APP_BASE_URI}
|
||||
CERC_DEPLOYED_CONTRACT: ${CERC_DEPLOYED_CONTRACT}
|
||||
CERC_L2_GETH_HOST: ${CERC_L2_GETH_HOST}
|
||||
CERC_L2_GETH_PORT: ${CERC_L2_GETH_PORT}
|
||||
CERC_L2_NODE_HOST: ${CERC_L2_NODE_HOST}
|
||||
CERC_L2_NODE_PORT: ${CERC_L2_NODE_PORT}
|
||||
command: ["sh", "deploy-and-generate-invite.sh"]
|
||||
volumes:
|
||||
- ../config/network/wait-for-it.sh:/app/packages/server/wait-for-it.sh
|
||||
- ../config/watcher-mobymask-v2/secrets-template.json:/app/packages/server/secrets-template.json
|
||||
- ../config/watcher-mobymask-v2/deploy-and-generate-invite.sh:/app/packages/server/deploy-and-generate-invite.sh
|
||||
- ../config/watcher-mobymask-v3/deploy-and-generate-invite.sh:/app/packages/server/deploy-and-generate-invite.sh
|
||||
- mobymask_deployment:/app/packages/server
|
||||
extra_hosts:
|
||||
- "host.docker.internal:host-gateway"
|
||||
@ -92,11 +86,8 @@ services:
|
||||
CERC_PRIVATE_KEY_PEER: ${CERC_PRIVATE_KEY_PEER}
|
||||
CERC_PRIVATE_KEY_NITRO: ${CERC_PRIVATE_KEY_NITRO}
|
||||
CERC_PEER_ID: ${CERC_PEER_ID}
|
||||
entrypoint: ["bash", "-c"]
|
||||
command: ["./deploy-nitro-contracts.sh && ./start-server.sh"]
|
||||
command: ["bash", "./start-server.sh"]
|
||||
volumes:
|
||||
- ../config/watcher-mobymask-v3/deploy-nitro-contracts.sh:/app/deploy-nitro-contracts.sh
|
||||
- ../config/watcher-mobymask-v3/deploy-nitro-contracts.ts:/app/deploy-nitro-contracts.ts
|
||||
- ../config/watcher-mobymask-v3/watcher-config-template.toml:/app/environments/watcher-config-template.toml
|
||||
- ../config/watcher-mobymask-v3/watcher-config-rates.toml:/app/environments/rates.toml
|
||||
- ../config/watcher-mobymask-v3/keys:/app/keys
|
||||
|
@ -25,7 +25,7 @@ fi
|
||||
|
||||
echo "Using ETH RPC endpoint ${CERC_ETH_RPC_ENDPOINT}"
|
||||
|
||||
# Wait till ETH RPC endpoint is available
|
||||
# Wait till ETH RPC endpoint is available with block number > 1
|
||||
retry_interval=5
|
||||
while true; do
|
||||
block_number_hex=$(curl -s -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' ${CERC_ETH_RPC_ENDPOINT} | jq -r '.result')
|
||||
|
88
app/data/config/watcher-mobymask-v3/deploy-and-generate-invite.sh
Executable file
88
app/data/config/watcher-mobymask-v3/deploy-and-generate-invite.sh
Executable file
@ -0,0 +1,88 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
if [ -n "$CERC_SCRIPT_DEBUG" ]; then
|
||||
set -x
|
||||
fi
|
||||
|
||||
CERC_MOBYMASK_APP_BASE_URI="${CERC_MOBYMASK_APP_BASE_URI:-${DEFAULT_CERC_MOBYMASK_APP_BASE_URI}}"
|
||||
CERC_DEPLOYED_CONTRACT="${CERC_DEPLOYED_CONTRACT:-${DEFAULT_CERC_DEPLOYED_CONTRACT}}"
|
||||
|
||||
# Check if CERC_DEPLOYED_CONTRACT environment variable set to skip contract deployment
|
||||
if [ -n "$CERC_DEPLOYED_CONTRACT" ]; then
|
||||
echo "CERC_DEPLOYED_CONTRACT is set to '$CERC_DEPLOYED_CONTRACT'"
|
||||
echo "Skipping contract deployment"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "Using ETH RPC endpoint ${CERC_ETH_RPC_ENDPOINT}"
|
||||
|
||||
# Wait till ETH RPC endpoint is available with block number > 1
|
||||
retry_interval=5
|
||||
while true; do
|
||||
block_number_hex=$(curl -s -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' ${CERC_ETH_RPC_ENDPOINT} | jq -r '.result')
|
||||
|
||||
# Check if the request call was successful
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "RPC endpoint not yet available, retrying in $retry_interval seconds..."
|
||||
sleep $retry_interval
|
||||
continue
|
||||
fi
|
||||
|
||||
# Convert hex to decimal
|
||||
block_number_dec=$(printf %u ${block_number_hex})
|
||||
|
||||
# Check if block number is > 1 to avoid failures in the deployment
|
||||
if [ "$block_number_dec" -ge 1 ]; then
|
||||
echo "RPC endpoint is up"
|
||||
break
|
||||
else
|
||||
echo "RPC endpoint not yet available, retrying in $retry_interval seconds..."
|
||||
sleep $retry_interval
|
||||
continue
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -n "$CERC_L1_ACCOUNTS_CSV_URL" ] && \
|
||||
l1_accounts_response=$(curl -L --write-out '%{http_code}' --silent --output /dev/null "$CERC_L1_ACCOUNTS_CSV_URL") && \
|
||||
[ "$l1_accounts_response" -eq 200 ];
|
||||
then
|
||||
echo "Fetching L1 account credentials using provided URL"
|
||||
mkdir -p /geth-accounts
|
||||
wget -O /geth-accounts/accounts.csv "$CERC_L1_ACCOUNTS_CSV_URL"
|
||||
|
||||
# Read the private key of an L1 account to deploy contract
|
||||
CERC_PRIVATE_KEY_DEPLOYER=$(head -n 1 /geth-accounts/accounts.csv | cut -d ',' -f 3)
|
||||
else
|
||||
echo "Couldn't fetch L1 account credentials, using CERC_PRIVATE_KEY_DEPLOYER from env"
|
||||
fi
|
||||
|
||||
# Create the required JSON and write it to a file
|
||||
secrets_file="secrets.json"
|
||||
secrets_json=$(jq -n \
|
||||
--arg privateKey "$CERC_PRIVATE_KEY_DEPLOYER" \
|
||||
--arg rpcUrl "$CERC_ETH_RPC_ENDPOINT" \
|
||||
--arg baseURI "$CERC_MOBYMASK_APP_BASE_URI" \
|
||||
'.privateKey = $privateKey | .rpcUrl = $rpcUrl | .baseURI = $baseURI')
|
||||
echo "$secrets_json" > "${secrets_file}"
|
||||
|
||||
export RPC_URL="${CERC_ETH_RPC_ENDPOINT}"
|
||||
|
||||
# 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)
|
||||
deployed_contract=$(echo "$deployment_details" | jq -r '.address')
|
||||
|
||||
cd ../hardhat
|
||||
if yarn verifyDeployment --network optimism --contract "${deployed_contract}"; then
|
||||
echo "Deployment verfication successful"
|
||||
cd ../server
|
||||
else
|
||||
echo "Deployment verfication failed, please clear MobyMask deployment volume before starting"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
npm run deployAndGenerateInvite
|
@ -1,58 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
if [ -n "$CERC_SCRIPT_DEBUG" ]; then
|
||||
set -x
|
||||
fi
|
||||
|
||||
CERC_NA_ADDRESS="${CERC_NA_ADDRESS:-${DEFAULT_CERC_NA_ADDRESS}}"
|
||||
CERC_VPA_ADDRESS="${CERC_VPA_ADDRESS:-${DEFAULT_CERC_VPA_ADDRESS}}"
|
||||
CERC_CA_ADDRESS="${CERC_CA_ADDRESS:-${DEFAULT_CERC_CA_ADDRESS}}"
|
||||
|
||||
NITRO_ADDRESSES_FILE_PATH="/nitro/nitro-addresses.json"
|
||||
|
||||
# Check if CERC_NA_ADDRESS environment variable set to skip contract deployment
|
||||
if [ -n "$CERC_NA_ADDRESS" ]; then
|
||||
echo "CERC_NA_ADDRESS is set to '$CERC_NA_ADDRESS'"
|
||||
echo "CERC_VPA_ADDRESS is set to '$CERC_VPA_ADDRESS'"
|
||||
echo "CERC_CA_ADDRESS is set to '$CERC_CA_ADDRESS'"
|
||||
echo "Using the above addresses and skipping Nitro contracts deployment"
|
||||
|
||||
# Create the required JSON and write it to a file
|
||||
nitro_addresses_json=$(jq -n \
|
||||
--arg na "$CERC_NA_ADDRESS" \
|
||||
--arg vpa "$CERC_VPA_ADDRESS" \
|
||||
--arg ca "$CERC_CA_ADDRESS" \
|
||||
'.nitroAdjudicatorAddress = $na | .virtualPaymentAppAddress = $vpa | .consensusAppAddress = $ca')
|
||||
echo "$nitro_addresses_json" > "${NITRO_ADDRESSES_FILE_PATH}"
|
||||
|
||||
exit
|
||||
fi
|
||||
|
||||
# Check and exit if a deployment already exists (on restarts)
|
||||
if [ -f ${NITRO_ADDRESSES_FILE_PATH} ]; then
|
||||
echo "${NITRO_ADDRESSES_FILE_PATH} already exists, skipping Nitro contracts deployment"
|
||||
exit
|
||||
fi
|
||||
|
||||
echo "Using L2 RPC endpoint ${CERC_L2_GETH_RPC}"
|
||||
|
||||
if [ -n "$CERC_L1_ACCOUNTS_CSV_URL" ] && \
|
||||
l1_accounts_response=$(curl -L --write-out '%{http_code}' --silent --output /dev/null "$CERC_L1_ACCOUNTS_CSV_URL") && \
|
||||
[ "$l1_accounts_response" -eq 200 ];
|
||||
then
|
||||
echo "Fetching L1 account credentials using provided URL"
|
||||
mkdir -p /geth-accounts
|
||||
wget -O /geth-accounts/accounts.csv "$CERC_L1_ACCOUNTS_CSV_URL"
|
||||
|
||||
# Read the private key of an L1 account to deploy contract
|
||||
CERC_PRIVATE_KEY_DEPLOYER=$(head -n 1 /geth-accounts/accounts.csv | cut -d ',' -f 3)
|
||||
else
|
||||
echo "Couldn't fetch L1 account credentials, using CERC_PRIVATE_KEY_DEPLOYER from env"
|
||||
fi
|
||||
|
||||
echo "RPC_URL=${CERC_L2_GETH_RPC}" > .env
|
||||
echo "NITRO_ADDRESSES_FILE_PATH=${NITRO_ADDRESSES_FILE_PATH}" >> .env
|
||||
echo "PRIVATE_KEY=${CERC_PRIVATE_KEY_DEPLOYER}" >> .env
|
||||
|
||||
yarn ts-node --esm deploy-nitro-contracts.ts
|
@ -1,49 +0,0 @@
|
||||
import 'dotenv/config';
|
||||
import fs from 'fs';
|
||||
import { providers, Wallet } from 'ethers';
|
||||
import { deployContracts } from '@cerc-io/nitro-util';
|
||||
|
||||
async function main () {
|
||||
const rpcURL = process.env.RPC_URL;
|
||||
const addressesFilePath = process.env.NITRO_ADDRESSES_FILE_PATH;
|
||||
const deployerKey = process.env.PRIVATE_KEY;
|
||||
|
||||
if (!rpcURL) {
|
||||
console.log('RPC_URL not set, skipping deployment');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!addressesFilePath) {
|
||||
console.log('NITRO_ADDRESSES_FILE_PATH not set, skipping deployment');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!deployerKey) {
|
||||
console.log('PRIVATE_KEY not set, skipping deployment');
|
||||
return;
|
||||
}
|
||||
|
||||
const provider = new providers.JsonRpcProvider(process.env.RPC_URL);
|
||||
const signer = new Wallet(deployerKey, provider);
|
||||
|
||||
const [
|
||||
nitroAdjudicatorAddress,
|
||||
virtualPaymentAppAddress,
|
||||
consensusAppAddress
|
||||
] = await deployContracts(signer as any);
|
||||
|
||||
const output = {
|
||||
nitroAdjudicatorAddress,
|
||||
virtualPaymentAppAddress,
|
||||
consensusAppAddress
|
||||
};
|
||||
|
||||
fs.writeFileSync(addressesFilePath, JSON.stringify(output, null, 2));
|
||||
console.log('Nitro contracts deployed, addresses written to', addressesFilePath);
|
||||
console.log('Result:', JSON.stringify(output, null, 2));
|
||||
}
|
||||
|
||||
main()
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
@ -2,7 +2,7 @@
|
||||
|
||||
## Setup
|
||||
|
||||
Prerequisite: L2 Optimism Geth and Node RPC endpoints
|
||||
Prerequisite: L2 Optimism Geth RPC endpoint
|
||||
|
||||
Clone required repositories:
|
||||
|
||||
@ -23,15 +23,8 @@ laconic-so --stack mobymask-v3 build-containers --exclude cerc/mobymask-ui
|
||||
Create and update an env file to be used in the next step ([defaults](../../config/watcher-mobymask-v3/mobymask-params.env)):
|
||||
|
||||
```bash
|
||||
# External L2 endpoints
|
||||
CERC_L2_GETH_RPC=
|
||||
|
||||
# Endpoints waited on before contract deployment
|
||||
CERC_L2_GETH_HOST=
|
||||
CERC_L2_GETH_PORT=
|
||||
|
||||
CERC_L2_NODE_HOST=
|
||||
CERC_L2_NODE_PORT=
|
||||
# External ETH RPC endpoint
|
||||
CERC_ETH_RPC_ENDPOINT=
|
||||
|
||||
# URL (fixturenet-eth-bootnode-lighthouse) to get CSV with credentials for accounts on L1 to perform txs on L2
|
||||
CERC_L1_ACCOUNTS_CSV_URL=
|
||||
|
Loading…
Reference in New Issue
Block a user