Add a fixturenet-payments stack #540

Merged
prathamesh0 merged 20 commits from pm-payments-stack into main 2023-10-03 12:10:35 +00:00
14 changed files with 174 additions and 10 deletions
Showing only changes of commit fadb6ac422 - Show all commits

View File

@ -0,0 +1,32 @@
version: '3.7'
services:
ponder-app:
restart: unless-stopped
image: cerc/ponder:local
workdir: /app/examples/token-erc20
environment:
PONDER_CHAIN_ID: ${PONDER_CHAIN_ID:-99}
PONDER_RPC_URL_1: ${PONDER_RPC_URL_1:-http://nitro-reverse-payment-proxy:8081}
CERC_PONDER_NITRO_PK: ${CERC_PONDER_NITRO_PK}
CERC_PONDER_NITRO_CHAIN_PK: ${CERC_PONDER_NITRO_CHAIN_PK}
CERC_PONDER_NITRO_CHAIN_URL: ${CERC_PONDER_NITRO_CHAIN_URL:-http://fixturenet-eth-geth-1:8545}
CERC_RELAY_MULTIADDR: ${CERC_RELAY_MULTIADDR}
CERC_UPSTREAM_NITRO_ADDRESS: ${CERC_UPSTREAM_NITRO_ADDRESS}
CERC_UPSTREAM_NITRO_MULTIADDR: ${CERC_UPSTREAM_NITRO_MULTIADDR}
CERC_UPSTREAM_NITRO_PAY_AMOUNT: ${CERC_UPSTREAM_NITRO_PAY_AMOUNT}
command: ["bash", "ponder-app-start.sh"]
volumes:
- ../config/ponder/ponder-app-start.sh:/app/ponder-app-start.sh
- ../config/ponder/ponder.config.ts:/app/ponder.config.ts
- ../config/ponder/.env.local:/app/.env.local
- peers_ids:/peers
- nitro_deployment:/nitro
- ponder_nitro_data:/app/.ponder/nitro-db
extra_hosts:
- "host.docker.internal:host-gateway"
volumes:
peers_ids:
nitro_deployment:
ponder_nitro_data:

View File

@ -84,7 +84,7 @@ services:
CERC_VPA_ADDRESS: ${CERC_VPA_ADDRESS}
CERC_CA_ADDRESS: ${CERC_CA_ADDRESS}
CERC_PRIVATE_KEY_PEER: ${CERC_PRIVATE_KEY_PEER}
CERC_PRIVATE_KEY_NITRO: ${CERC_PRIVATE_KEY_NITRO}
CERC_WATCHER_NITRO_PK: ${CERC_WATCHER_NITRO_PK}
CERC_PEER_ID: ${CERC_PEER_ID}
CERC_UPSTREAM_NITRO_ADDRESS: ${CERC_UPSTREAM_NITRO_ADDRESS}
CERC_UPSTREAM_NITRO_MULTIADDR: ${CERC_UPSTREAM_NITRO_MULTIADDR}
@ -95,7 +95,7 @@ services:
- ../config/watcher-mobymask-v3/watcher-config-rates.toml:/app/environments/rates.toml
- ../config/watcher-mobymask-v3/keys:/app/keys
- ../config/watcher-mobymask-v3/start-server.sh:/app/start-server.sh
- nitro_data:/app/out/nitro-db
- watcher_nitro_data:/app/out/nitro-db
- peers_ids:/app/peers
- nitro_deployment:/nitro
- mobymask_deployment:/server
@ -118,4 +118,4 @@ volumes:
peers_ids:
mobymask_deployment:
nitro_deployment:
nitro_data:
watcher_nitro_data:

View File

@ -7,7 +7,7 @@ fi
nitro_addresses_file="/app/deployment/nitro-addresses.json"
# Check if CERC_NA_ADDRESS environment variable set to skip contract deployment
# Check if CERC_NA_ADDRESS environment variable is set
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'"

View File

@ -0,0 +1,67 @@
#!/bin/bash
set -e
if [ -n "$CERC_SCRIPT_DEBUG" ]; then
set -x
fi
nitro_addresses_file="/nitro/nitro-addresses.json"
nitro_addresses_destination_file="/app/nitro-addresses.json"
# Check if CERC_NA_ADDRESS environment variable is set
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 Nitro addresses"
# 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_destination_file}"
elif [ -f ${nitro_addresses_file} ]; then
echo "Using Nitro addresses from ${nitro_addresses_file}:"
cat "$nitro_addresses_file"
cat "$nitro_addresses_file" > "$nitro_addresses_destination_file"
else
echo "Nitro addresses not available"
exit 1
fi
echo "Using CERC_PONDER_NITRO_PK from env for Nitro account"
echo "Using CERC_PONDER_NITRO_CHAIN_PK (account with funds) from env for sending Nitro txs"
echo "Using ${CERC_PONDER_NITRO_CHAIN_URL} as the RPC endpoint for Nitro txs"
# If not set, check the mounted volume for relay peer id
if [ -z "$CERC_RELAY_MULTIADDR" ]; then
echo "CERC_RELAY_MULTIADDR not provided, taking from the mounted volume"
CERC_RELAY_MULTIADDR="[\"/ip4/127.0.0.1/tcp/9090/ws/p2p/$(jq -r '.id' /peers/relay-id.json)\"]"
fi
# Wait till RPC endpoint is available
retry_interval=5
while true; do
rpc_response=$(curl -s -o /dev/null -w '%{http_code}' ${PONDER_RPC_URL_1})
if [ ${rpc_response} = 200 ]; then
break
fi
echo "RPC endpoint not yet available, retrying in $retry_interval seconds..."
sleep $retry_interval
done
env_file='.env.local'
echo "PONDER_CHAIN_ID=\"$PONDER_CHAIN_ID\"" > "$env_file"
echo "PONDER_RPC_URL_1=\"$PONDER_RPC_URL_1\"" >> "$env_file"
echo "CERC_PONDER_NITRO_PK=\"$CERC_PONDER_NITRO_PK\"" >> "$env_file"
echo "CERC_PONDER_NITRO_CHAIN_PK=\"$CERC_PONDER_NITRO_CHAIN_PK\"" >> "$env_file"
echo "CERC_PONDER_NITRO_CHAIN_URL=\"$CERC_PONDER_NITRO_CHAIN_URL\"" >> "$env_file"
echo "CERC_RELAY_MULTIADDR=\"$CERC_RELAY_MULTIADDR\"" >> "$env_file"
echo "CERC_UPSTREAM_NITRO_ADDRESS=\"$CERC_UPSTREAM_NITRO_ADDRESS\"" >> "$env_file"
echo "CERC_UPSTREAM_NITRO_MULTIADDR=\"$CERC_UPSTREAM_NITRO_MULTIADDR\"" >> "$env_file"
echo "CERC_UPSTREAM_NITRO_PAY_AMOUNT=\"$CERC_UPSTREAM_NITRO_PAY_AMOUNT\"" >> "$env_file"
pnpm start

View File

@ -0,0 +1,37 @@
import type { Config } from "@ponder/core";
import contractAddresses from "./nitro-addresses.json";
export const config: Config = {
networks: [
{
name: "fixturenet",
chainId: Number(process.env.PONDER_CHAIN_ID),
rpcUrl: process.env.PONDER_RPC_URL_1,
maxRpcRequestConcurrency: 1,
},
],
contracts: [
{
name: "AdventureGold",
network: "fixturenet",
abi: "./abis/AdventureGold.json",
address: "0x32353A6C91143bfd6C7d363B546e62a9A2489A20",
startBlock: 5,
maxBlockRange: 100,
},
],
nitro: {
privateKey: process.env.CERC_PONDER_NITRO_PK!,
chainPrivateKey: process.env.CERC_PONDER_NITRO_CHAIN_PK!,
chainURL: process.env.CERC_PONDER_NITRO_CHAIN_URL!,
contractAddresses,
relayMultiAddr: process.env.CERC_RELAY_MULTIADDR!,
store: "./.ponder/nitro-db",
rpcNitroNode: {
address: process.env.CERC_UPSTREAM_NITRO_ADDRESS!,
multiAddr: process.env.CERC_UPSTREAM_NITRO_MULTIADDR!,
},
payAmount: process.env.CERC_UPSTREAM_NITRO_PAY_AMOUNT!,
},
};

View File

@ -69,7 +69,7 @@ fi
yarn build
echo "Using CERC_PRIVATE_KEY_PEER (account with funds) from env for sending txs to L2"
echo "Using CERC_PRIVATE_KEY_NITRO from env for Nitro account"
echo "Using CERC_WATCHER_NITRO_PK from env for Nitro account"
if [ -n "$CERC_PEER_ID" ]; then
echo "Using CERC_PEER_ID ${CERC_PEER_ID} from env for watcher fixture"
@ -137,7 +137,7 @@ WATCHER_CONFIG=$(echo "$WATCHER_CONFIG_TEMPLATE" | \
s|REPLACE_WITH_PEER_ID_FILE|${PEER_ID_FILE}|g; \
s/REPLACE_WITH_CERC_ENABLE_PEER_L2_TXS/${CERC_ENABLE_PEER_L2_TXS}/g; \
s/REPLACE_WITH_CERC_PRIVATE_KEY_PEER/${CERC_PRIVATE_KEY_PEER}/g; \
s/REPLACE_WITH_CERC_PRIVATE_KEY_NITRO/${CERC_PRIVATE_KEY_NITRO}/g; \
s/REPLACE_WITH_CERC_WATCHER_NITRO_PK/${CERC_WATCHER_NITRO_PK}/g; \
s/REPLACE_WITH_CONTRACT_ADDRESS/${CONTRACT_ADDRESS}/g; \
s/REPLACE_WITH_CONSENSUS_ENABLED/${CONSENSUS_ENABLED}/g; \
s/REPLACE_WITH_CONSENSUS_PUBLIC_KEY/${CONSENSUS_PUBLIC_KEY}/g; \

View File

@ -54,7 +54,7 @@
[server.p2p.nitro]
store = './out/nitro-db'
privateKey = 'REPLACE_WITH_CERC_PRIVATE_KEY_NITRO'
privateKey = 'REPLACE_WITH_CERC_WATCHER_NITRO_PK'
chainPrivateKey = 'REPLACE_WITH_CERC_PRIVATE_KEY_PEER'
[server.p2p.nitro.payments]

View File

@ -0,0 +1,13 @@
FROM node:18.15.0-alpine3.16
RUN apk --update --no-cache add git alpine-sdk bash jq curl
RUN curl -L https://unpkg.com/@pnpm/self-installer | node
WORKDIR /app
COPY . .
RUN echo "Installing dependencies and building..." && \
pnpm install && pnpm build && \
cd examples/token-erc20 && \
pnpm install

View File

@ -0,0 +1,7 @@
#!/usr/bin/env bash
# Build cerc/ponder
source ${CERC_CONTAINER_BASE_DIR}/build-base.sh
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
docker build -t cerc/ponder:local -f ${SCRIPT_DIR}/Dockerfile ${build_command_args} ${CERC_REPO_BASE_DIR}/ponder

View File

@ -54,3 +54,4 @@ cerc/watcher-mobymask-v3
cerc/go-nitro
cerc/nitro-contracts
cerc/mobymask-snap
cerc/ponder

View File

@ -41,3 +41,4 @@ go-nitro
nitro-contracts
nitro-reverse-payment-proxy
mobymask-snap
ponder

View File

@ -46,3 +46,4 @@ github.com/sushiswap/subgraphs
github.com/cerc-io/go-nitro
github.com/cerc-io/ts-nitro
github.com/cerc-io/mobymask-snap
github.com/cerc-io/ponder

View File

@ -9,14 +9,16 @@ repos:
- github.com/cerc-io/ipld-eth-server
# nitro repos
- github.com/cerc-io/ts-nitro
- github.com/cerc-io/go-nitro@pm-disable-compression
- github.com/cerc-io/go-nitro@pm-disable-compression # TODO: Update
# mobymask watcher repos
- github.com/cerc-io/watcher-ts@v0.2.61
- github.com/cerc-io/mobymask-v2-watcher-ts@v0.2.0 # TODO: Update
- github.com/cerc-io/mobymask-v2-watcher-ts@pm-upstream-payments # TODO: Update
- github.com/cerc-io/MobyMask@v0.1.3
# mobymask app repos
- github.com/cerc-io/mobymask-snap
- github.com/cerc-io/mobymask-ui@v0.2.0
# ponder repo
- github.com/cerc-io/ponder@paid-eth-rpc # TODO: Update
containers:
# fixturenet images
- cerc/go-ethereum
@ -36,6 +38,8 @@ containers:
# mobymask app images
- cerc/mobymask-snap
- cerc/mobymask-ui
# ponder image
- cerc/ponder
pods:
- fixturenet-eth
- ipld-eth-server
@ -46,3 +50,4 @@ pods:
- watcher-mobymask-v3
- mobymask-snap
- mobymask-app-v3
- ponder

View File

@ -64,7 +64,7 @@ Create and update an env file to be used in the next step ([defaults](../../conf
CERC_PRIVATE_KEY_PEER=
# Specify private key for the Nitro account
CERC_PRIVATE_KEY_NITRO=
CERC_WATCHER_NITRO_PK=
# (Optional) Set a pre-existing peer id to be used (enables consensus)
# Uses a generated peer id if not set (disables consensus)