From 116d3c8ab5d18c1fc065db8e28bb1f5ded6648ee Mon Sep 17 00:00:00 2001 From: prathamesh0 Date: Fri, 11 Aug 2023 10:02:36 +0530 Subject: [PATCH 01/10] Add a sushiswap-graph stack --- .../docker-compose-contract-sushiswap.yml | 14 +++++++ app/data/pod-list.txt | 1 + app/data/stacks/sushiswap-graph/README.md | 41 +++++++++++++++++++ app/data/stacks/sushiswap-graph/stack.yml | 18 ++++++++ 4 files changed, 74 insertions(+) create mode 100644 app/data/compose/docker-compose-contract-sushiswap.yml create mode 100644 app/data/stacks/sushiswap-graph/README.md create mode 100644 app/data/stacks/sushiswap-graph/stack.yml diff --git a/app/data/compose/docker-compose-contract-sushiswap.yml b/app/data/compose/docker-compose-contract-sushiswap.yml new file mode 100644 index 00000000..aad5c85a --- /dev/null +++ b/app/data/compose/docker-compose-contract-sushiswap.yml @@ -0,0 +1,14 @@ +version: '3.2' + +services: + # Deploys the core (UniswapV3Factory) contract + sushiswap-v3-core: + image: cerc/sushiswap-v3-core:local + env_file: + - ../config/watcher-sushiswap/lotus-params.env + + # Deploys the periphery (NFPM, token, etc.) contracts + sushiswap-v3-periphery: + image: cerc/sushiswap-v3-periphery:local + env_file: + - ../config/watcher-sushiswap/lotus-params.env diff --git a/app/data/pod-list.txt b/app/data/pod-list.txt index 5355c90e..c6e55b8d 100644 --- a/app/data/pod-list.txt +++ b/app/data/pod-list.txt @@ -31,3 +31,4 @@ mainnet-go-opera lasso reth watcher-sushiswap +contract-sushiswap diff --git a/app/data/stacks/sushiswap-graph/README.md b/app/data/stacks/sushiswap-graph/README.md new file mode 100644 index 00000000..76ee04ad --- /dev/null +++ b/app/data/stacks/sushiswap-graph/README.md @@ -0,0 +1,41 @@ +# SushiSwap Graph + +## Setup + +Clone required repositories: + +```bash +laconic-so --stack sushiswap-graph setup-repositories +``` + +Build the container images: + +```bash +laconic-so --stack sushiswap-graph build-containers +``` + +## Deploy + +Deploy the stack: + +```bash +laconic-so --stack sushiswap-graph deploy --cluster sushigraph up +``` + +## Clean up + +Stop all the services running in background run: + +```bash +laconic-so --stack sushiswap-graph deploy --cluster sushigraph down +``` + +Clear volumes created by this stack: + +```bash +# List all relevant volumes +docker volume ls -q --filter "name=sushigraph" + +# Remove all the listed volumes +docker volume rm $(docker volume ls -q --filter "name=sushigraph") +``` diff --git a/app/data/stacks/sushiswap-graph/stack.yml b/app/data/stacks/sushiswap-graph/stack.yml new file mode 100644 index 00000000..427fed51 --- /dev/null +++ b/app/data/stacks/sushiswap-graph/stack.yml @@ -0,0 +1,18 @@ +version: "1.0" +name: sushiswap-graph +description: "An end-to-end SushiSwap Graph stack" +repos: + ## fixturenet-lotus repo + - github.com/filecoin-project/lotus + ## sushiswap repos + - github.com/cerc-io/sushiswap-v3-core@watcher-ts + - github.com/cerc-io/sushiswap-v3-periphery@watcher-ts +containers: + ## fixturenet-lotus image + - cerc/lotus + ## sushiswap contract deployment images + - cerc/sushiswap-v3-core + - cerc/sushiswap-v3-periphery +pods: + - fixturenet-lotus + - contract-sushiswap -- 2.45.2 From f853b303c4c851860633985504ed6ad658230793 Mon Sep 17 00:00:00 2001 From: prathamesh0 Date: Fri, 11 Aug 2023 10:08:15 +0530 Subject: [PATCH 02/10] Fix shared volume name in fixturenet-lotus --- app/data/compose/docker-compose-fixturenet-lotus.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/data/compose/docker-compose-fixturenet-lotus.yml b/app/data/compose/docker-compose-fixturenet-lotus.yml index ff54e897..b04795f9 100644 --- a/app/data/compose/docker-compose-fixturenet-lotus.yml +++ b/app/data/compose/docker-compose-fixturenet-lotus.yml @@ -10,7 +10,7 @@ services: - ../config/fixturenet-lotus/setup-miner.sh:/docker-entrypoint-scripts.d/setup-miner.sh - ../config/fixturenet-lotus/fund-account.sh:/fund-account.sh - lotus_miner_params:/var/tmp/filecoin-proof-parameters - - lotus-shared:/root/.lotus-shared + - lotus_shared:/root/.lotus-shared - lotus_miner_data:/root/data entrypoint: ["sh", "/docker-entrypoint-scripts.d/setup-miner.sh"] ports: @@ -30,7 +30,7 @@ services: volumes: - ../config/fixturenet-lotus/setup-node.sh:/docker-entrypoint-scripts.d/setup-node.sh - lotus_node_1_params:/var/tmp/filecoin-proof-parameters - - lotus-shared:/root/.lotus-shared + - lotus_shared:/root/.lotus-shared - lotus_node_1_data:/root/data healthcheck: test: ["CMD", "nc", "-vz", "localhost", "1234"] @@ -58,7 +58,7 @@ services: volumes: - ../config/fixturenet-lotus/setup-node.sh:/docker-entrypoint-scripts.d/setup-node.sh - lotus_node_2_params:/var/tmp/filecoin-proof-parameters - - lotus-shared:/root/.lotus-shared + - lotus_shared:/root/.lotus-shared - lotus_node_2_data:/root/data healthcheck: test: ["CMD", "nc", "-vz", "localhost", "1234"] @@ -79,7 +79,7 @@ volumes: lotus_miner_params: lotus_node_1_params: lotus_node_2_params: - lotus-shared: + lotus_shared: lotus_miner_data: lotus_node_1_data: lotus_node_2_data: -- 2.45.2 From 0e1e3d67e13a63c667c425e3f8d19a442fa8884b Mon Sep 17 00:00:00 2001 From: prathamesh0 Date: Fri, 11 Aug 2023 12:18:27 +0530 Subject: [PATCH 03/10] Export Lotus miner node multiaddr after initialization --- app/data/config/fixturenet-lotus/setup-miner.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/data/config/fixturenet-lotus/setup-miner.sh b/app/data/config/fixturenet-lotus/setup-miner.sh index de1cc4c2..2e9efb0a 100644 --- a/app/data/config/fixturenet-lotus/setup-miner.sh +++ b/app/data/config/fixturenet-lotus/setup-miner.sh @@ -33,8 +33,8 @@ while ! grep -q "started ChainNotify channel" /var/log/lotus.log ; do done echo "Daemon started." -# publish bootnode peer info to shared volume -lotus net listen | grep "$(ip addr | grep inet | grep -v '127.0.0.1' | sort | head -1 | awk '{print $2}' | cut -d '/' -f1)" | head -1 > /root/.lotus-shared/miner.addr +# copy genesis file to shared volume +cp /devgen.car /root/.lotus-shared # if miner not already initialized if [ ! -d $LOTUS_MINER_PATH ]; then @@ -47,6 +47,9 @@ if [ ! -d $LOTUS_MINER_PATH ]; then lotus-miner init --genesis-miner --actor=t01000 --sector-size=2KiB --pre-sealed-sectors=/root/data/.genesis-sectors --pre-sealed-metadata=/root/data/.genesis-sectors/pre-seal-t01000.json --nosync fi +# publish bootnode peer info to shared volume +lotus net listen | grep "$(ip addr | grep inet | grep -v '127.0.0.1' | sort | head -1 | awk '{print $2}' | cut -d '/' -f1)" | head -1 > /root/.lotus-shared/miner.addr + # start miner nohup lotus-miner run --nosync & -- 2.45.2 From 3eaf20877b22759496b16ca8c145c08c6daad7b9 Mon Sep 17 00:00:00 2001 From: prathamesh0 Date: Fri, 11 Aug 2023 12:21:10 +0530 Subject: [PATCH 04/10] Add deployment scripts for sushiswap contracts --- .../docker-compose-contract-sushiswap.yml | 33 ++++++++++++- .../deploy-core-contracts.sh | 34 ++++++++++++++ .../deploy-periphery-contracts.sh | 47 +++++++++++++++++++ .../contract-sushiswap/deployment-params.env | 11 +++++ .../cerc-sushiswap-v3-core/Dockerfile | 2 +- .../cerc-sushiswap-v3-periphery/Dockerfile | 2 +- 6 files changed, 125 insertions(+), 4 deletions(-) create mode 100755 app/data/config/contract-sushiswap/deploy-core-contracts.sh create mode 100755 app/data/config/contract-sushiswap/deploy-periphery-contracts.sh create mode 100644 app/data/config/contract-sushiswap/deployment-params.env diff --git a/app/data/compose/docker-compose-contract-sushiswap.yml b/app/data/compose/docker-compose-contract-sushiswap.yml index aad5c85a..f56e98cc 100644 --- a/app/data/compose/docker-compose-contract-sushiswap.yml +++ b/app/data/compose/docker-compose-contract-sushiswap.yml @@ -5,10 +5,39 @@ services: sushiswap-v3-core: image: cerc/sushiswap-v3-core:local env_file: - - ../config/watcher-sushiswap/lotus-params.env + - ../config/contract-sushiswap/deployment-params.env + environment: + ETH_RPC_ENDPOINT: ${ETH_RPC_ENDPOINT} + CHAIN_ID: ${CHAIN_ID} + ACCOUNT_PRIVATE_KEY: ${ACCOUNT_PRIVATE_KEY} + DEPLOY: ${DEPLOY} + volumes: + - ../config/network/wait-for-it.sh:/app/wait-for-it.sh + - ../config/contract-sushiswap/deploy-core-contracts.sh:/app/deploy-core-contracts.sh + - sushiswap_core_deployment:/app/deployments/docker + command: ["bash", "-c", "/app/deploy-core-contracts.sh && tail -f"] + extra_hosts: + - "host.docker.internal:host-gateway" # Deploys the periphery (NFPM, token, etc.) contracts sushiswap-v3-periphery: image: cerc/sushiswap-v3-periphery:local env_file: - - ../config/watcher-sushiswap/lotus-params.env + - ../config/contract-sushiswap/deployment-params.env + environment: + ETH_RPC_ENDPOINT: ${ETH_RPC_ENDPOINT} + CHAIN_ID: ${CHAIN_ID} + ACCOUNT_PRIVATE_KEY: ${ACCOUNT_PRIVATE_KEY} + DEPLOY: ${DEPLOY} + volumes: + - ../config/network/wait-for-it.sh:/app/wait-for-it.sh + - ../config/contract-sushiswap/deploy-periphery-contracts.sh:/app/deploy-periphery-contracts.sh + - sushiswap_core_deployment:/app/core-deployments/docker + - sushiswap_periphery_deployment:/app/deployments/docker + command: ["bash", "-c", "/app/deploy-periphery-contracts.sh && tail -f"] + extra_hosts: + - "host.docker.internal:host-gateway" + +volumes: + sushiswap_core_deployment: + sushiswap_periphery_deployment: diff --git a/app/data/config/contract-sushiswap/deploy-core-contracts.sh b/app/data/config/contract-sushiswap/deploy-core-contracts.sh new file mode 100755 index 00000000..707e7b38 --- /dev/null +++ b/app/data/config/contract-sushiswap/deploy-core-contracts.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +set -e + +# Chain config +ETH_RPC_ENDPOINT="${ETH_RPC_ENDPOINT:-${DEFAULT_ETH_RPC_ENDPOINT}}" +CHAIN_ID="${CHAIN_ID:-${DEFAULT_CHAIN_ID}}" +ACCOUNT_PRIVATE_KEY="${ACCOUNT_PRIVATE_KEY:-${DEFAULT_ACCOUNT_PRIVATE_KEY}}" + +# Option +DEPLOY="${DEPLOY:-${DEFAULT_DEPLOY}}" + +# Create a .env file +echo "ETH_RPC_ENDPOINT=$ETH_RPC_ENDPOINT" > .env +echo "CHAIN_ID=$CHAIN_ID" >> .env +echo "ACCOUNT_PRIVATE_KEY=$ACCOUNT_PRIVATE_KEY" >> .env + +echo "Using RPC endpoint ${ETH_RPC_ENDPOINT}" + +# Wait for the RPC endpoint to be up +endpoint=${ETH_RPC_ENDPOINT#http://} +endpoint=${endpoint#https://} +RPC_HOST=$(echo "$endpoint" | awk -F'[:/]' '{print $1}') +RPC_PORT=$(echo "$endpoint" | awk -F'[:/]' '{print $2}') +./wait-for-it.sh -h "${RPC_HOST}" -p "${RPC_PORT}" -s -t 0 + +if [ "$DEPLOY" ]; then + echo "Performing core contract deployments..." + pnpm hardhat --network docker deploy --tags UniswapV3Factory +else + echo "Skipping contract deployments" +fi + +echo "Done" diff --git a/app/data/config/contract-sushiswap/deploy-periphery-contracts.sh b/app/data/config/contract-sushiswap/deploy-periphery-contracts.sh new file mode 100755 index 00000000..fc423251 --- /dev/null +++ b/app/data/config/contract-sushiswap/deploy-periphery-contracts.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +set -e + +# Chain config +ETH_RPC_ENDPOINT="${ETH_RPC_ENDPOINT:-${DEFAULT_ETH_RPC_ENDPOINT}}" +CHAIN_ID="${CHAIN_ID:-${DEFAULT_CHAIN_ID}}" +ACCOUNT_PRIVATE_KEY="${ACCOUNT_PRIVATE_KEY:-${DEFAULT_ACCOUNT_PRIVATE_KEY}}" + +# Option +DEPLOY="${DEPLOY:-${DEFAULT_DEPLOY}}" + +# Create a .env file +echo "ETH_RPC_ENDPOINT=$ETH_RPC_ENDPOINT" > .env +echo "CHAIN_ID=$CHAIN_ID" >> .env +echo "ACCOUNT_PRIVATE_KEY=$ACCOUNT_PRIVATE_KEY" >> .env + + +echo "Using RPC endpoint $ETH_RPC_ENDPOINT" + +# Wait for the RPC endpoint to be up +endpoint=${ETH_RPC_ENDPOINT#http://} +endpoint=${endpoint#https://} +RPC_HOST=$(echo "$endpoint" | awk -F'[:/]' '{print $1}') +RPC_PORT=$(echo "$endpoint" | awk -F'[:/]' '{print $2}') +./wait-for-it.sh -h "${RPC_HOST}" -p "${RPC_PORT}" -s -t 0 + +if [ "$DEPLOY" ]; then + # Loop until the factory deployment is detected + echo "Waiting for core deployments to occur" + while [ ! -f /app/core-deployments/docker/UniswapV3Factory.json ]; do + sleep 5 + done + + echo "Reading factory address from core deployments" + FACTORY_ADDRESS=$(jq -r '.address' /app/core-deployments/docker/UniswapV3Factory.json) + + echo "Using UniswapV3Factory at $FACTORY_ADDRESS" + echo "FACTORY_ADDRESS=$FACTORY_ADDRESS" >> .env + + echo "Performing periphery contract deployments..." + yarn hardhat --network docker deploy --tags NonfungiblePositionManager +else + echo "Skipping contract deployments" +fi + +echo "Done" diff --git a/app/data/config/contract-sushiswap/deployment-params.env b/app/data/config/contract-sushiswap/deployment-params.env new file mode 100644 index 00000000..f9854e88 --- /dev/null +++ b/app/data/config/contract-sushiswap/deployment-params.env @@ -0,0 +1,11 @@ +# Chain config + +DEFAULT_ETH_RPC_ENDPOINT="http://lotus-node-1:1234/rpc/v1" +DEFAULT_CHAIN_ID=31415926 + +# From app/data/config/fixturenet-lotus/fund-account.sh +DEFAULT_ACCOUNT_PRIVATE_KEY="0xc05fd3613bcd62a4f25e5eba1f464d0b76d74c3f771a7c2f13e26ad6439444b3" + +# Options + +DEFAULT_DEPLOY=true diff --git a/app/data/container-build/cerc-sushiswap-v3-core/Dockerfile b/app/data/container-build/cerc-sushiswap-v3-core/Dockerfile index 993897d4..8d85d602 100644 --- a/app/data/container-build/cerc-sushiswap-v3-core/Dockerfile +++ b/app/data/container-build/cerc-sushiswap-v3-core/Dockerfile @@ -1,6 +1,6 @@ FROM node:18.15.0-alpine3.16 -RUN apk --update --no-cache add git python3 alpine-sdk bash +RUN apk --update --no-cache add git python3 alpine-sdk bash jq RUN curl -L https://unpkg.com/@pnpm/self-installer | node WORKDIR /app diff --git a/app/data/container-build/cerc-sushiswap-v3-periphery/Dockerfile b/app/data/container-build/cerc-sushiswap-v3-periphery/Dockerfile index 4fcf712c..a033c39e 100644 --- a/app/data/container-build/cerc-sushiswap-v3-periphery/Dockerfile +++ b/app/data/container-build/cerc-sushiswap-v3-periphery/Dockerfile @@ -1,6 +1,6 @@ FROM node:18.15.0-alpine3.16 -RUN apk --update --no-cache add git python3 alpine-sdk bash +RUN apk --update --no-cache add git python3 alpine-sdk bash jq WORKDIR /app -- 2.45.2 From e227726191857fa54d986783a0b2b7903acfdeb8 Mon Sep 17 00:00:00 2001 From: prathamesh0 Date: Fri, 11 Aug 2023 14:34:54 +0530 Subject: [PATCH 05/10] Skip contracts deployment if already exists --- app/data/config/contract-sushiswap/deploy-core-contracts.sh | 2 +- .../config/contract-sushiswap/deploy-periphery-contracts.sh | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/data/config/contract-sushiswap/deploy-core-contracts.sh b/app/data/config/contract-sushiswap/deploy-core-contracts.sh index 707e7b38..0bf3b8fe 100755 --- a/app/data/config/contract-sushiswap/deploy-core-contracts.sh +++ b/app/data/config/contract-sushiswap/deploy-core-contracts.sh @@ -24,7 +24,7 @@ RPC_HOST=$(echo "$endpoint" | awk -F'[:/]' '{print $1}') RPC_PORT=$(echo "$endpoint" | awk -F'[:/]' '{print $2}') ./wait-for-it.sh -h "${RPC_HOST}" -p "${RPC_PORT}" -s -t 0 -if [ "$DEPLOY" ]; then +if [ "$DEPLOY" = true ] && [ ! -e "/app/deployments/docker/UniswapV3Factory.json" ]; then echo "Performing core contract deployments..." pnpm hardhat --network docker deploy --tags UniswapV3Factory else diff --git a/app/data/config/contract-sushiswap/deploy-periphery-contracts.sh b/app/data/config/contract-sushiswap/deploy-periphery-contracts.sh index fc423251..3586b867 100755 --- a/app/data/config/contract-sushiswap/deploy-periphery-contracts.sh +++ b/app/data/config/contract-sushiswap/deploy-periphery-contracts.sh @@ -15,7 +15,6 @@ echo "ETH_RPC_ENDPOINT=$ETH_RPC_ENDPOINT" > .env echo "CHAIN_ID=$CHAIN_ID" >> .env echo "ACCOUNT_PRIVATE_KEY=$ACCOUNT_PRIVATE_KEY" >> .env - echo "Using RPC endpoint $ETH_RPC_ENDPOINT" # Wait for the RPC endpoint to be up @@ -25,7 +24,7 @@ RPC_HOST=$(echo "$endpoint" | awk -F'[:/]' '{print $1}') RPC_PORT=$(echo "$endpoint" | awk -F'[:/]' '{print $2}') ./wait-for-it.sh -h "${RPC_HOST}" -p "${RPC_PORT}" -s -t 0 -if [ "$DEPLOY" ]; then +if [ "$DEPLOY" = true ] && [ ! -e "/app/deployments/docker/NonfungiblePositionManager.json" ]; then # Loop until the factory deployment is detected echo "Waiting for core deployments to occur" while [ ! -f /app/core-deployments/docker/UniswapV3Factory.json ]; do -- 2.45.2 From b7a76aae574a0c08e2f20689deeba7572c9f5065 Mon Sep 17 00:00:00 2001 From: prathamesh0 Date: Fri, 11 Aug 2023 14:44:01 +0530 Subject: [PATCH 06/10] Rename stack to sushiswap-subgraph --- .../{sushiswap-graph => sushiswap-subgraph}/README.md | 8 ++++---- .../{sushiswap-graph => sushiswap-subgraph}/stack.yml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) rename app/data/stacks/{sushiswap-graph => sushiswap-subgraph}/README.md (64%) rename app/data/stacks/{sushiswap-graph => sushiswap-subgraph}/stack.yml (94%) diff --git a/app/data/stacks/sushiswap-graph/README.md b/app/data/stacks/sushiswap-subgraph/README.md similarity index 64% rename from app/data/stacks/sushiswap-graph/README.md rename to app/data/stacks/sushiswap-subgraph/README.md index 76ee04ad..1da6573a 100644 --- a/app/data/stacks/sushiswap-graph/README.md +++ b/app/data/stacks/sushiswap-subgraph/README.md @@ -5,13 +5,13 @@ Clone required repositories: ```bash -laconic-so --stack sushiswap-graph setup-repositories +laconic-so --stack sushiswap-subgraph setup-repositories ``` Build the container images: ```bash -laconic-so --stack sushiswap-graph build-containers +laconic-so --stack sushiswap-subgraph build-containers ``` ## Deploy @@ -19,7 +19,7 @@ laconic-so --stack sushiswap-graph build-containers Deploy the stack: ```bash -laconic-so --stack sushiswap-graph deploy --cluster sushigraph up +laconic-so --stack sushiswap-subgraph deploy --cluster sushigraph up ``` ## Clean up @@ -27,7 +27,7 @@ laconic-so --stack sushiswap-graph deploy --cluster sushigraph up Stop all the services running in background run: ```bash -laconic-so --stack sushiswap-graph deploy --cluster sushigraph down +laconic-so --stack sushiswap-subgraph deploy --cluster sushigraph down ``` Clear volumes created by this stack: diff --git a/app/data/stacks/sushiswap-graph/stack.yml b/app/data/stacks/sushiswap-subgraph/stack.yml similarity index 94% rename from app/data/stacks/sushiswap-graph/stack.yml rename to app/data/stacks/sushiswap-subgraph/stack.yml index 427fed51..a26e63c9 100644 --- a/app/data/stacks/sushiswap-graph/stack.yml +++ b/app/data/stacks/sushiswap-subgraph/stack.yml @@ -1,5 +1,5 @@ version: "1.0" -name: sushiswap-graph +name: sushiswap-subgraph description: "An end-to-end SushiSwap Graph stack" repos: ## fixturenet-lotus repo -- 2.45.2 From fda74e5c335d3b15718409819928be90051ed3a6 Mon Sep 17 00:00:00 2001 From: Nabarun Date: Fri, 11 Aug 2023 15:13:21 +0530 Subject: [PATCH 07/10] Fix postgres and use Lotus fixturenet in graph-node stack --- .../docker-compose-fixturenet-graph-node.yml | 18 ++++++++++++++++++ .../stacks/fixturenet-graph-node/stack.yml | 4 +++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/app/data/compose/docker-compose-fixturenet-graph-node.yml b/app/data/compose/docker-compose-fixturenet-graph-node.yml index 4f30961f..bde6c138 100644 --- a/app/data/compose/docker-compose-fixturenet-graph-node.yml +++ b/app/data/compose/docker-compose-fixturenet-graph-node.yml @@ -1,6 +1,15 @@ services: graph-node: image: cerc/graph-node:local + depends_on: + db: + condition: service_healthy + ipfs: + condition: service_healthy + lotus-node-1: + condition: service_healthy + extra_hosts: + - host.docker.internal:host-gateway environment: ipfs: ipfs:5001 postgres_host: db @@ -8,6 +17,9 @@ services: postgres_user: graph-node postgres_pass: password postgres_db: graph-node + # TODO: Get endpoint from env + ethereum: 'lotus-fixturenet:http://lotus-node-1:1234/rpc/v1' + GRAPH_LOG: info ports: - "8000" - "8001" @@ -30,6 +42,12 @@ services: POSTGRES_USER: "graph-node" POSTGRES_DB: "graph-node" POSTGRES_PASSWORD: "password" + POSTGRES_INITDB_ARGS: "-E UTF8 --locale=C" + command: + [ + "postgres", + "-cshared_preload_libraries=pg_stat_statements" + ] healthcheck: test: ["CMD", "nc", "-v", "localhost", "5432"] interval: 30s diff --git a/app/data/stacks/fixturenet-graph-node/stack.yml b/app/data/stacks/fixturenet-graph-node/stack.yml index 727cceb4..e7ab10f3 100644 --- a/app/data/stacks/fixturenet-graph-node/stack.yml +++ b/app/data/stacks/fixturenet-graph-node/stack.yml @@ -2,9 +2,11 @@ version: "1.0" name: fixturenet-graph-node description: "A graph-node fixturenet" repos: + - github.com/filecoin-project/lotus - github.com/graphprotocol/graph-node containers: + - cerc/lotus - cerc/graph-node pods: + - fixturenet-lotus - fixturenet-graph-node - -- 2.45.2 From 4f6c3529aa192b5d9b10e239b5e479de77d89cd6 Mon Sep 17 00:00:00 2001 From: Nabarun Date: Mon, 14 Aug 2023 11:03:47 +0530 Subject: [PATCH 08/10] Add sushiswap v3 subgraph stack --- .../docker-compose-contract-sushiswap.yml | 4 ++ .../docker-compose-fixturenet-graph-node.yml | 6 +++ .../docker-compose-sushiswap-subgraph-v3.yml | 25 ++++++++++++ .../sushiswap-subgraph-v3/lotus-fixturenet.js | 20 ++++++++++ .../config/sushiswap-subgraph-v3/run-v3.sh | 39 +++++++++++++++++++ .../cerc-sushiswap-subgraph/Dockerfile | 11 ++++++ .../cerc-sushiswap-subgraph/build.sh | 7 ++++ app/data/container-image-list.txt | 1 + app/data/repository-list.txt | 1 + app/data/stacks/sushiswap-subgraph/stack.yml | 8 +++- 10 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 app/data/compose/docker-compose-sushiswap-subgraph-v3.yml create mode 100644 app/data/config/sushiswap-subgraph-v3/lotus-fixturenet.js create mode 100644 app/data/config/sushiswap-subgraph-v3/run-v3.sh create mode 100644 app/data/container-build/cerc-sushiswap-subgraph/Dockerfile create mode 100755 app/data/container-build/cerc-sushiswap-subgraph/build.sh diff --git a/app/data/compose/docker-compose-contract-sushiswap.yml b/app/data/compose/docker-compose-contract-sushiswap.yml index f56e98cc..f6456f2a 100644 --- a/app/data/compose/docker-compose-contract-sushiswap.yml +++ b/app/data/compose/docker-compose-contract-sushiswap.yml @@ -5,8 +5,10 @@ services: sushiswap-v3-core: image: cerc/sushiswap-v3-core:local env_file: + # Defaults - ../config/contract-sushiswap/deployment-params.env environment: + # Overrides ETH_RPC_ENDPOINT: ${ETH_RPC_ENDPOINT} CHAIN_ID: ${CHAIN_ID} ACCOUNT_PRIVATE_KEY: ${ACCOUNT_PRIVATE_KEY} @@ -23,8 +25,10 @@ services: sushiswap-v3-periphery: image: cerc/sushiswap-v3-periphery:local env_file: + # Defaults - ../config/contract-sushiswap/deployment-params.env environment: + # Overrides ETH_RPC_ENDPOINT: ${ETH_RPC_ENDPOINT} CHAIN_ID: ${CHAIN_ID} ACCOUNT_PRIVATE_KEY: ${ACCOUNT_PRIVATE_KEY} diff --git a/app/data/compose/docker-compose-fixturenet-graph-node.yml b/app/data/compose/docker-compose-fixturenet-graph-node.yml index bde6c138..8d66c491 100644 --- a/app/data/compose/docker-compose-fixturenet-graph-node.yml +++ b/app/data/compose/docker-compose-fixturenet-graph-node.yml @@ -25,6 +25,12 @@ services: - "8001" - "8020" - "8030" + healthcheck: + test: ["CMD", "nc", "-v", "localhost", "8020"] + interval: 30s + timeout: 10s + retries: 10 + start_period: 3s ipfs: image: ipfs/kubo:master-2023-02-20-714a968 volumes: diff --git a/app/data/compose/docker-compose-sushiswap-subgraph-v3.yml b/app/data/compose/docker-compose-sushiswap-subgraph-v3.yml new file mode 100644 index 00000000..d65ba601 --- /dev/null +++ b/app/data/compose/docker-compose-sushiswap-subgraph-v3.yml @@ -0,0 +1,25 @@ +version: '3.2' + +services: + # Deploys the sushiswap v3 subgraph + sushiswap-subgraph-v3: + image: cerc/sushiswap-subgraphs:local + restart: on-failure + depends_on: + graph-node + environment: + - APP=v3 + - NETWORK=lotus-fixturenet + command: ["./run-v3.sh"] + working_dir: /app/subgraphs/v3 + volumes: + - ../config/sushiswap-subgraph-v3/lotus-fixturenet.js:/app/config/lotus-fixturenet.js + - ../config/sushiswap-subgraph-v3/run-v3.sh:/app/subgraphs/v3/run-v3.sh + - sushiswap_core_deployment:/app/subgraphs/v3/core-deployments/docker + - sushiswap_periphery_deployment:/app/subgraphs/v3/deployments/docker + extra_hosts: + - "host.docker.internal:host-gateway" + +volumes: + sushiswap_core_deployment: + sushiswap_periphery_deployment: diff --git a/app/data/config/sushiswap-subgraph-v3/lotus-fixturenet.js b/app/data/config/sushiswap-subgraph-v3/lotus-fixturenet.js new file mode 100644 index 00000000..aee2cf97 --- /dev/null +++ b/app/data/config/sushiswap-subgraph-v3/lotus-fixturenet.js @@ -0,0 +1,20 @@ +module.exports = { + network: 'lotus-fixturenet', + v3: { + factory: { + address: 'FACTORY_ADDRESS', + startBlock: FACTORY_BLOCK + }, + positionManager: { + address: 'NFPM_ADDRESS', + startBlock: NFPM_BLOCK + }, + native: { address: 'NATIVE_ADDRESS' }, + whitelistedTokenAddresses: [ + 'NATIVE_ADDRESS', + ], + stableTokenAddresses: [ + ], + minimumEthLocked: 1.5 + } +} diff --git a/app/data/config/sushiswap-subgraph-v3/run-v3.sh b/app/data/config/sushiswap-subgraph-v3/run-v3.sh new file mode 100644 index 00000000..d1ede176 --- /dev/null +++ b/app/data/config/sushiswap-subgraph-v3/run-v3.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +set -e + +# Loop until the NFPM deployment is detected +echo "Waiting for sushiswap-periphery deployments to occur" +while [ ! -f /app/deployments/docker/NonfungiblePositionManager.json ]; do + sleep 5 +done + +echo "Reading contract addresses and block numbers from deployments" +FACTORY_ADDRESS=$(jq -r '.address' /app/core-deployments/docker/UniswapV3Factory.json) +FACTORY_BLOCK=$(jq -r '.receipt.blockNumber' /app/core-deployments/docker/UniswapV3Factory.json) +NATIVE_ADDRESS=$(jq -r '.address' /app/deployments/docker/WFIL.json) +NFPM_ADDRESS=$(jq -r '.address' /app/deployments/docker/NonfungiblePositionManager.json) +NFPM_BLOCK=$(jq -r '.receipt.blockNumber' /app/deployments/docker/NonfungiblePositionManager.json) + +# Read the JavaScript file content +file_content=$( /app/config/lotus-fixturenet.js + + +echo "Building subgraph and deploying to graph-node..." +pnpm run generate +pnpm run build +pnpm exec graph create --node http://graph-node:8020/ sushiswap/v3-lotus +pnpm exec graph deploy --node http://graph-node:8020/ --ipfs http://ipfs:5001 --version-label 0.1.0 sushiswap/v3-lotus + +echo "Done" diff --git a/app/data/container-build/cerc-sushiswap-subgraph/Dockerfile b/app/data/container-build/cerc-sushiswap-subgraph/Dockerfile new file mode 100644 index 00000000..2196882c --- /dev/null +++ b/app/data/container-build/cerc-sushiswap-subgraph/Dockerfile @@ -0,0 +1,11 @@ +FROM node:18.15.0-alpine3.16 + +RUN apk --update --no-cache add git alpine-sdk bash jq +RUN curl -L https://unpkg.com/@pnpm/self-installer | node + +WORKDIR /app + +COPY . . + +RUN echo "Installing dependencies..." && \ + pnpm install diff --git a/app/data/container-build/cerc-sushiswap-subgraph/build.sh b/app/data/container-build/cerc-sushiswap-subgraph/build.sh new file mode 100755 index 00000000..0d2f8633 --- /dev/null +++ b/app/data/container-build/cerc-sushiswap-subgraph/build.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +# Build cerc/sushiswap-subgraphs +source ${CERC_CONTAINER_BASE_DIR}/build-base.sh +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +docker build -t cerc/sushiswap-subgraphs:local -f ${SCRIPT_DIR}/Dockerfile ${build_command_args} ${CERC_REPO_BASE_DIR}/subgraphs diff --git a/app/data/container-image-list.txt b/app/data/container-image-list.txt index 751b40a3..b674baf8 100644 --- a/app/data/container-image-list.txt +++ b/app/data/container-image-list.txt @@ -48,3 +48,4 @@ cerc/sushiswap-v3-core cerc/sushiswap-v3-periphery cerc/watcher-sushiswap cerc/graph-node +cerc/sushiswap-subgraphs diff --git a/app/data/repository-list.txt b/app/data/repository-list.txt index 7069850b..de696335 100644 --- a/app/data/repository-list.txt +++ b/app/data/repository-list.txt @@ -42,3 +42,4 @@ git.vdb.to/cerc-io/plugeth-statediff github.com/cerc-io/sushiswap-v3-core github.com/cerc-io/sushiswap-v3-periphery github.com/graphprotocol/graph-node +github.com/sushiswap/subgraphs diff --git a/app/data/stacks/sushiswap-subgraph/stack.yml b/app/data/stacks/sushiswap-subgraph/stack.yml index a26e63c9..0a12880c 100644 --- a/app/data/stacks/sushiswap-subgraph/stack.yml +++ b/app/data/stacks/sushiswap-subgraph/stack.yml @@ -1,12 +1,16 @@ version: "1.0" name: sushiswap-subgraph -description: "An end-to-end SushiSwap Graph stack" +description: "An end-to-end SushiSwap Subgraph stack" repos: ## fixturenet-lotus repo - github.com/filecoin-project/lotus + ## graph-node repo + - github.com/graphprotocol/graph-node ## sushiswap repos - github.com/cerc-io/sushiswap-v3-core@watcher-ts - github.com/cerc-io/sushiswap-v3-periphery@watcher-ts + ## subgraph repo + - github.com/sushiswap/subgraphs containers: ## fixturenet-lotus image - cerc/lotus @@ -15,4 +19,6 @@ containers: - cerc/sushiswap-v3-periphery pods: - fixturenet-lotus + - fixturenet-graph-node - contract-sushiswap + - sushiswap-subgraph-v3 -- 2.45.2 From 5fb8c3db8c2f56faf5af01b358e026a1c5815340 Mon Sep 17 00:00:00 2001 From: Nabarun Date: Mon, 14 Aug 2023 13:05:13 +0530 Subject: [PATCH 09/10] Fixes to deploy sushiswap subgraph to graph-node --- .../docker-compose-contract-sushiswap.yml | 2 ++ .../docker-compose-fixturenet-graph-node.yml | 2 +- .../docker-compose-fixturenet-lotus.yml | 4 ++-- .../docker-compose-sushiswap-subgraph-v3.yml | 7 +++--- ...urenet.js => lotus-fixturenet.js.template} | 0 .../config/sushiswap-subgraph-v3/run-v3.sh | 14 ++++++------ .../Dockerfile | 0 .../build.sh | 0 app/data/stacks/sushiswap-subgraph/README.md | 22 +++++++++++++++++++ app/data/stacks/sushiswap-subgraph/stack.yml | 2 ++ 10 files changed, 40 insertions(+), 13 deletions(-) rename app/data/config/sushiswap-subgraph-v3/{lotus-fixturenet.js => lotus-fixturenet.js.template} (100%) mode change 100644 => 100755 app/data/config/sushiswap-subgraph-v3/run-v3.sh rename app/data/container-build/{cerc-sushiswap-subgraph => cerc-sushiswap-subgraphs}/Dockerfile (100%) rename app/data/container-build/{cerc-sushiswap-subgraph => cerc-sushiswap-subgraphs}/build.sh (100%) diff --git a/app/data/compose/docker-compose-contract-sushiswap.yml b/app/data/compose/docker-compose-contract-sushiswap.yml index f6456f2a..96ee1a3e 100644 --- a/app/data/compose/docker-compose-contract-sushiswap.yml +++ b/app/data/compose/docker-compose-contract-sushiswap.yml @@ -4,6 +4,7 @@ services: # Deploys the core (UniswapV3Factory) contract sushiswap-v3-core: image: cerc/sushiswap-v3-core:local + restart: on-failure env_file: # Defaults - ../config/contract-sushiswap/deployment-params.env @@ -24,6 +25,7 @@ services: # Deploys the periphery (NFPM, token, etc.) contracts sushiswap-v3-periphery: image: cerc/sushiswap-v3-periphery:local + restart: on-failure env_file: # Defaults - ../config/contract-sushiswap/deployment-params.env diff --git a/app/data/compose/docker-compose-fixturenet-graph-node.yml b/app/data/compose/docker-compose-fixturenet-graph-node.yml index 8d66c491..eb47dc2b 100644 --- a/app/data/compose/docker-compose-fixturenet-graph-node.yml +++ b/app/data/compose/docker-compose-fixturenet-graph-node.yml @@ -26,7 +26,7 @@ services: - "8020" - "8030" healthcheck: - test: ["CMD", "nc", "-v", "localhost", "8020"] + test: ["CMD", "nc", "-vz", "localhost", "8020"] interval: 30s timeout: 10s retries: 10 diff --git a/app/data/compose/docker-compose-fixturenet-lotus.yml b/app/data/compose/docker-compose-fixturenet-lotus.yml index b04795f9..4eb27039 100644 --- a/app/data/compose/docker-compose-fixturenet-lotus.yml +++ b/app/data/compose/docker-compose-fixturenet-lotus.yml @@ -36,7 +36,7 @@ services: test: ["CMD", "nc", "-vz", "localhost", "1234"] interval: 30s timeout: 10s - retries: 10 + retries: 60 start_period: 3s depends_on: - lotus-miner @@ -64,7 +64,7 @@ services: test: ["CMD", "nc", "-vz", "localhost", "1234"] interval: 30s timeout: 10s - retries: 10 + retries: 60 start_period: 3s depends_on: - lotus-miner diff --git a/app/data/compose/docker-compose-sushiswap-subgraph-v3.yml b/app/data/compose/docker-compose-sushiswap-subgraph-v3.yml index d65ba601..b4a7b313 100644 --- a/app/data/compose/docker-compose-sushiswap-subgraph-v3.yml +++ b/app/data/compose/docker-compose-sushiswap-subgraph-v3.yml @@ -6,14 +6,15 @@ services: image: cerc/sushiswap-subgraphs:local restart: on-failure depends_on: - graph-node + graph-node: + condition: service_healthy environment: - APP=v3 - NETWORK=lotus-fixturenet - command: ["./run-v3.sh"] + command: ["bash", "-c", "./run-v3.sh"] working_dir: /app/subgraphs/v3 volumes: - - ../config/sushiswap-subgraph-v3/lotus-fixturenet.js:/app/config/lotus-fixturenet.js + - ../config/sushiswap-subgraph-v3/lotus-fixturenet.js.template:/app/config/lotus-fixturenet.js.template - ../config/sushiswap-subgraph-v3/run-v3.sh:/app/subgraphs/v3/run-v3.sh - sushiswap_core_deployment:/app/subgraphs/v3/core-deployments/docker - sushiswap_periphery_deployment:/app/subgraphs/v3/deployments/docker diff --git a/app/data/config/sushiswap-subgraph-v3/lotus-fixturenet.js b/app/data/config/sushiswap-subgraph-v3/lotus-fixturenet.js.template similarity index 100% rename from app/data/config/sushiswap-subgraph-v3/lotus-fixturenet.js rename to app/data/config/sushiswap-subgraph-v3/lotus-fixturenet.js.template diff --git a/app/data/config/sushiswap-subgraph-v3/run-v3.sh b/app/data/config/sushiswap-subgraph-v3/run-v3.sh old mode 100644 new mode 100755 index d1ede176..8ca01460 --- a/app/data/config/sushiswap-subgraph-v3/run-v3.sh +++ b/app/data/config/sushiswap-subgraph-v3/run-v3.sh @@ -4,19 +4,19 @@ set -e # Loop until the NFPM deployment is detected echo "Waiting for sushiswap-periphery deployments to occur" -while [ ! -f /app/deployments/docker/NonfungiblePositionManager.json ]; do +while [ ! -f ./deployments/docker/NonfungiblePositionManager.json ]; do sleep 5 done echo "Reading contract addresses and block numbers from deployments" -FACTORY_ADDRESS=$(jq -r '.address' /app/core-deployments/docker/UniswapV3Factory.json) -FACTORY_BLOCK=$(jq -r '.receipt.blockNumber' /app/core-deployments/docker/UniswapV3Factory.json) -NATIVE_ADDRESS=$(jq -r '.address' /app/deployments/docker/WFIL.json) -NFPM_ADDRESS=$(jq -r '.address' /app/deployments/docker/NonfungiblePositionManager.json) -NFPM_BLOCK=$(jq -r '.receipt.blockNumber' /app/deployments/docker/NonfungiblePositionManager.json) +FACTORY_ADDRESS=$(jq -r '.address' ./core-deployments/docker/UniswapV3Factory.json) +FACTORY_BLOCK=$(jq -r '.receipt.blockNumber' ./core-deployments/docker/UniswapV3Factory.json) +NATIVE_ADDRESS=$(jq -r '.address' ./deployments/docker/WFIL.json) +NFPM_ADDRESS=$(jq -r '.address' ./deployments/docker/NonfungiblePositionManager.json) +NFPM_BLOCK=$(jq -r '.receipt.blockNumber' ./deployments/docker/NonfungiblePositionManager.json) # Read the JavaScript file content -file_content=$( Date: Mon, 14 Aug 2023 13:33:45 +0530 Subject: [PATCH 10/10] Add graph-node container in sushiswap subgraph stack --- app/data/stacks/sushiswap-subgraph/stack.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/data/stacks/sushiswap-subgraph/stack.yml b/app/data/stacks/sushiswap-subgraph/stack.yml index 92d81a5e..e4b6915d 100644 --- a/app/data/stacks/sushiswap-subgraph/stack.yml +++ b/app/data/stacks/sushiswap-subgraph/stack.yml @@ -14,6 +14,8 @@ repos: containers: ## fixturenet-lotus image - cerc/lotus + ## fixturenet-graph-node image + - cerc/graph-node ## sushiswap contract deployment images - cerc/sushiswap-v3-core - cerc/sushiswap-v3-periphery -- 2.45.2