Add a mobymask-v3 stack

This commit is contained in:
Prathamesh Musale 2023-09-14 19:15:15 +05:30
parent 626cc17373
commit 9ccd2d7d43
8 changed files with 204 additions and 1 deletions

View File

@ -0,0 +1,73 @@
version: '3.2'
services:
# Starts the PostgreSQL database for watcher
mobymask-watcher-db:
restart: unless-stopped
image: postgres:14-alpine
environment:
- POSTGRES_USER=vdbm
- POSTGRES_MULTIPLE_DATABASES=mobymask-watcher,mobymask-watcher-job-queue
- POSTGRES_EXTENSION=mobymask-watcher-job-queue:pgcrypto
- POSTGRES_PASSWORD=password
volumes:
- ../config/postgresql/multiple-postgressql-databases.sh:/docker-entrypoint-initdb.d/multiple-postgressql-databases.sh
- mobymask_watcher_db_data:/var/lib/postgresql/data
ports:
- "127.0.0.1:15432:5432"
healthcheck:
test: ["CMD", "nc", "-v", "localhost", "5432"]
interval: 20s
timeout: 5s
retries: 15
start_period: 10s
# Deploys the MobyMask contract and generates an invite link
# Deployment is skipped if CERC_DEPLOYED_CONTRACT env is set
mobymask:
image: cerc/mobymask:local
working_dir: /app/packages/server
env_file:
- ../config/watcher-mobymask-v2/optimism-params.env
- ../config/watcher-mobymask-v2/mobymask-params.env
environment:
CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG}
ENV: "PROD"
CERC_L2_GETH_RPC: ${CERC_L2_GETH_RPC}
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
- mobymask_deployment:/app/packages/server
extra_hosts:
- "host.docker.internal:host-gateway"
# Creates peer-id files if they don't exist
peer-ids-gen:
image: cerc/watcher-ts:local
restart: on-failure
environment:
CERC_SCRIPT_DEBUG: ${CERC_SCRIPT_DEBUG}
# working_dir: /app/packages/peer
working_dir: /app/packages/
command: ["sh", "generate-peer-ids.sh && deploy-nitro-contracts.sh"]
volumes:
- ../config/watcher-mobymask-v2/generate-peer-ids.sh:/app/packages/peer/generate-peer-ids.sh
- peers_ids:/peer-ids
- ../config/watcher-mobymask-v3/deploy-nitro-contracts.sh:/app/packages/peer/deploy-nitro-contracts.sh
- nitro_addresses:/nitro
volumes:
mobymask_watcher_db_data:
peers_ids:
nitro_addresses:
mobymask_deployment:

View File

@ -0,0 +1,46 @@
#!/bin/sh
set -e
if [ -n "$CERC_SCRIPT_DEBUG" ]; then
set -x
fi
CERC_L2_GETH_RPC="${CERC_L2_GETH_RPC:-${DEFAULT_CERC_L2_GETH_RPC}}"
CERC_L1_ACCOUNTS_CSV_URL="${CERC_L1_ACCOUNTS_CSV_URL:-${DEFAULT_CERC_L1_ACCOUNTS_CSV_URL}}"
CERC_NITRO_CONTRACTS="${CERC_DEPLOYED_CONTRACT:-${DEFAULT_CERC_NITRO_CONTRACTS}}"
NITRO_ADDRESSES_FILE_PATH="/nitro/nitro-addresses.json"
# Check if CERC_NITRO_CONTRACTS environment variable set to skip contract deployment
if [ -n "$CERC_NITRO_CONTRACTS" ]; then
echo "CERC_NITRO_CONTRACTS is set to '$CERC_NITRO_CONTRACTS'"
echo "Skipping Nitro contracts deployment"
exit 0
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
# 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
export RPC_URL="${CERC_L2_GETH_RPC}"
export NITRO_ADDRESSES_FILE_PATH="${NITRO_ADDRESSES_FILE_PATH}"
export PRIVATE_KEY="${CERC_PRIVATE_KEY_DEPLOYER}"
yarn ts-node --esm ./src/deploy-nitro-contracts.ts

View File

@ -0,0 +1,48 @@
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);
});

View File

@ -37,7 +37,7 @@ RUN yarn global add http-server
WORKDIR /app
COPY . .
RUN npm install
RUN yarn install
# Expose port for http
EXPOSE 80

View File

@ -35,3 +35,5 @@ contract-sushiswap
graph-node
sushiswap-subgraph-v3
fixturenet-sushiswap-subgraph-v3
watcher-mobymask-v3
mobymask-app-v3

View File

@ -0,0 +1 @@
# MobyMask v3 watcher

View File

@ -0,0 +1,16 @@
version: "1.0"
description: "MobyMask v3 stack"
name: mobymask-v3
repos:
- github.com/cerc-io/watcher-ts@v0.2.57
- github.com/cerc-io/mobymask-v2-watcher-ts@v3
- github.com/cerc-io/MobyMask@v0.1.3
- github.com/cerc-io/mobymask-ui
containers:
- cerc/watcher-ts
- cerc/watcher-mobymask-v2
- cerc/mobymask-ui
- cerc/mobymask
pods:
- watcher-mobymask-v3
- mobymask-app-v3

View File

@ -0,0 +1,17 @@
# MobyMask v3 watcher
## Setup
Clone required repositories:
```bash
laconic-so --stack mobymask-v3 setup-repositories
```
Build the container images:
```bash
laconic-so --stack mobymask-v3 build-containers
```
## Deploy