From 4f6c3529aa192b5d9b10e239b5e479de77d89cd6 Mon Sep 17 00:00:00 2001 From: Nabarun Date: Mon, 14 Aug 2023 11:03:47 +0530 Subject: [PATCH] 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