diff --git a/app/data/compose/docker-compose-fixturenet-sushiswap-subgraph-v3.yml b/app/data/compose/docker-compose-fixturenet-sushiswap-subgraph-v3.yml new file mode 100644 index 00000000..439190c3 --- /dev/null +++ b/app/data/compose/docker-compose-fixturenet-sushiswap-subgraph-v3.yml @@ -0,0 +1,27 @@ +version: '3.2' + +services: + # Deploys the sushiswap v3 subgraph + sushiswap-subgraph-v3: + image: cerc/sushiswap-subgraphs:local + restart: on-failure + depends_on: + graph-node: + condition: service_healthy + environment: + - APP=v3 + - NETWORK=lotus-fixturenet + command: ["bash", "-c", "./blocks/run-blocks.sh && ./v3/run-v3.sh"] + working_dir: /app/subgraphs + volumes: + - ../config/fixturenet-sushiswap-subgraph-v3/lotus-fixturenet.js.template:/app/config/lotus-fixturenet.js.template + - ../config/fixturenet-sushiswap-subgraph-v3/run-blocks.sh:/app/subgraphs/blocks/run-blocks.sh + - ../config/fixturenet-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/periphery-deployments/docker + extra_hosts: + - "host.docker.internal:host-gateway" + +volumes: + sushiswap_core_deployment: + sushiswap_periphery_deployment: diff --git a/app/data/config/fixturenet-sushiswap-subgraph-v3/lotus-fixturenet.js.template b/app/data/config/fixturenet-sushiswap-subgraph-v3/lotus-fixturenet.js.template new file mode 100644 index 00000000..6a8da152 --- /dev/null +++ b/app/data/config/fixturenet-sushiswap-subgraph-v3/lotus-fixturenet.js.template @@ -0,0 +1,24 @@ +module.exports = { + network: 'lotus-fixturenet', + blocks: { + address: '0x0000000000000000000000000000000000000000', + startBlock: 0, + }, + 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/fixturenet-sushiswap-subgraph-v3/run-blocks.sh b/app/data/config/fixturenet-sushiswap-subgraph-v3/run-blocks.sh new file mode 100755 index 00000000..72af062a --- /dev/null +++ b/app/data/config/fixturenet-sushiswap-subgraph-v3/run-blocks.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +set -e + +echo "Building blocks subgraph and deploying to graph-node..." + +cd blocks + +pnpm run generate +pnpm run build + +pnpm exec graph create --node http://graph-node:8020/ sushiswap/blocks +pnpm exec graph deploy --node http://graph-node:8020/ --ipfs http://ipfs:5001 --version-label 0.1.0 sushiswap/blocks + +echo "Done" diff --git a/app/data/config/fixturenet-sushiswap-subgraph-v3/run-v3.sh b/app/data/config/fixturenet-sushiswap-subgraph-v3/run-v3.sh new file mode 100755 index 00000000..402fa889 --- /dev/null +++ b/app/data/config/fixturenet-sushiswap-subgraph-v3/run-v3.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +set -e + +cd v3 + +# Loop until the NFPM deployment is detected +echo "Waiting for sushiswap-periphery deployments to occur" +while [ ! -f ./periphery-deployments/docker/NonfungiblePositionManager.json ]; do + sleep 5 +done + +echo "Reading contract addresses and block numbers from deployments" +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' ./periphery-deployments/docker/WFIL.json) +NFPM_ADDRESS=$(jq -r '.address' ./periphery-deployments/docker/NonfungiblePositionManager.json) +NFPM_BLOCK=$(jq -r '.receipt.blockNumber' ./periphery-deployments/docker/NonfungiblePositionManager.json) + +# Read the JavaScript file content +file_content=$( /app/config/lotus-fixturenet.js + +echo "Building v3 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/pod-list.txt b/app/data/pod-list.txt index 4c670532..d375fd8e 100644 --- a/app/data/pod-list.txt +++ b/app/data/pod-list.txt @@ -34,3 +34,4 @@ watcher-sushiswap contract-sushiswap graph-node sushiswap-subgraph-v3 +fixturenet-sushiswap-subgraph-v3 diff --git a/app/data/stacks/fixturenet-sushiswap-subgraph/README.md b/app/data/stacks/fixturenet-sushiswap-subgraph/README.md new file mode 100644 index 00000000..29ed6269 --- /dev/null +++ b/app/data/stacks/fixturenet-sushiswap-subgraph/README.md @@ -0,0 +1,177 @@ +# Fixturenet SushiSwap Subgraph + +## Setup + +Clone required repositories: + +```bash +laconic-so --stack fixturenet-sushiswap-subgraph setup-repositories --pull +``` + +Checkout to a non-default branch in the cloned repos if required: + +```bash +# Default repo base dir +cd ~/cerc + +# Example +cd graph-node +git checkout && git pull + +# Remove the corresponding docker image if it already exists +docker image rm cerc/graph-node:local +# Remove any dangling images +docker image prune +``` + +Build the container images: + +```bash +laconic-so --stack fixturenet-sushiswap-subgraph build-containers +``` + +## Deploy + + +Create an env file with the following contents to be used in the next step: + +```bash +# Network and ETH RPC endpoint to run graph-node against +NETWORK=lotus-fixturenet +ETH_RPC_ENDPOINT=http://lotus-node-1:1234/rpc/v1 +``` + +Deploy the stack: + +```bash +laconic-so --stack fixturenet-sushiswap-subgraph deploy --cluster sushigraph --env-file up + +# Note: Remove any existing volumes for the cluster for a fresh start +``` + +After all services have started: + +* Follow `graph-node` logs: + + ```bash + laconic-so --stack fixturenet-sushiswap-subgraph deploy --cluster sushigraph logs -f graph-node + ``` + +* Check that the subgraphs have been deployed: + + ```bash + laconic-so --stack fixturenet-sushiswap-subgraph deploy --cluster sushigraph logs -f sushiswap-subgraph-v3 + + # Expected output: + # . + # . + # sushigraph-sushiswap-subgraph-v3-1 | - Deploying to Graph node http://graph-node:8020/ + # sushigraph-sushiswap-subgraph-v3-1 | Deployed to http://graph-node:8000/subgraphs/name/sushiswap/blocks/graphql + # sushigraph-sushiswap-subgraph-v3-1 | + # sushigraph-sushiswap-subgraph-v3-1 | + # sushigraph-sushiswap-subgraph-v3-1 | Subgraph endpoints: + # sushigraph-sushiswap-subgraph-v3-1 | Queries (HTTP): http://graph-node:8000/subgraphs/name/sushiswap/blocks + # . + # . + # sushigraph-sushiswap-subgraph-v3-1 | - Deploying to Graph node http://graph-node:8020/ + # sushigraph-sushiswap-subgraph-v3-1 | Deployed to http://graph-node:8000/subgraphs/name/sushiswap/v3-filecoin/graphql + # sushigraph-sushiswap-subgraph-v3-1 | + # sushigraph-sushiswap-subgraph-v3-1 | + # sushigraph-sushiswap-subgraph-v3-1 | Subgraph endpoints: + # sushigraph-sushiswap-subgraph-v3-1 | Queries (HTTP): http://graph-node:8000/subgraphs/name/sushiswap/v3-filecoin + # sushigraph-sushiswap-subgraph-v3-1 | + # sushigraph-sushiswap-subgraph-v3-1 | + # sushigraph-sushiswap-subgraph-v3-1 | Done + ``` + +After `graph-node` has fetched the latest blocks from upstream, use the subgraph (GQL) endpoints for querying: + +```bash +# Find out the mapped host port for the subgraph endpoint +laconic-so --stack fixturenet-sushiswap-subgraph deploy --cluster sushigraph port graph-node 8000 +# 0.0.0.0:HOST_PORT + +# Blocks subgraph endpoint: +http://127.0.0.1:/subgraphs/name/sushiswap/blocks/graphql + +# v3 subgraph endpoint: +http://127.0.0.1:/subgraphs/name/sushiswap/v3-filecoin/graphql +``` + +## Run + +* Deploy an ERC20 token: + + ```bash + docker exec -it sushigraph-sushiswap-v3-periphery-1 yarn hardhat --network docker deploy --tags TestERC20 + + # Deploy two tokens and set the addresses to variables TOKEN1_ADDRESS and TOKEN2_ADDRESS + export TOKEN1_ADDRESS= + export TOKEN2_ADDRESS= + ``` + +* Get contract address of factory deployed: + + ```bash + docker exec -it sushigraph-sushiswap-v3-core-1 jq -r '.address' /app/deployments/docker/UniswapV3Factory.json + + # Set the address to variable FACTORY_ADDRESS + export FACTORY_ADDRESS= + ``` + +* Create a pool: + + ```bash + docker exec -it sushigraph-sushiswap-v3-core-1 pnpm run pool:create:docker --factory $FACTORY_ADDRESS --token0 $TOKEN1_ADDRESS --token1 $TOKEN2_ADDRESS --fee 500 + + # Set the created pool address to variable POOL_ADDRESS + export POOL_ADDRESS= + ``` + +* Initialize pool: + + ```bash + docker exec -it sushigraph-sushiswap-v3-core-1 pnpm run pool:initialize:docker --sqrt-price 4295128939 --pool $POOL_ADDRESS + ``` + +* Set the recipient address to the contract deployer: + + ```bash + export RECIPIENT=0xD375B03bd3A2434A9f675bEC4Ccd68aC5e67C743 + ``` + +* Trigger pool `Mint` event: + + ```bash + docker exec -it sushigraph-sushiswap-v3-core-1 pnpm run pool:mint:docker --pool $POOL_ADDRESS --recipient $RECIPIENT --amount 10 + ``` + +* Trigger pool `Burn` event: + + ```bash + docker exec -it sushigraph-sushiswap-v3-core-1 pnpm run pool:burn:docker --pool $POOL_ADDRESS --amount 10 + ``` + +## Clean up + +Stop all the services running in background run: + +```bash +laconic-so --stack fixturenet-sushiswap-subgraph 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") + +# WARNING: To avoid refetching the Lotus proof params on the next run, +# avoid removing the corresponding volumes + +# To remove volumes that do not contain Lotus params +docker volume rm $(docker volume ls -q --filter "name=sushigraph" | grep -v "params$") +``` diff --git a/app/data/stacks/fixturenet-sushiswap-subgraph/stack.yml b/app/data/stacks/fixturenet-sushiswap-subgraph/stack.yml new file mode 100644 index 00000000..d62f5dc6 --- /dev/null +++ b/app/data/stacks/fixturenet-sushiswap-subgraph/stack.yml @@ -0,0 +1,28 @@ +version: "1.0" +name: fixturenet-sushiswap-subgraph +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 + # sushiswap subgraph repo + - github.com/sushiswap/subgraphs +containers: + # fixturenet-lotus image + - cerc/lotus + # graph-node image + - cerc/graph-node + # sushiswap contract deployment images + - cerc/sushiswap-v3-core + - cerc/sushiswap-v3-periphery + # sushiswap subgraphs image + - cerc/sushiswap-subgraphs +pods: + - fixturenet-lotus + - graph-node + - contract-sushiswap + - sushiswap-subgraph-v3 diff --git a/app/data/stacks/sushiswap-subgraph/stack.yml b/app/data/stacks/sushiswap-subgraph/stack.yml index 2a6de57b..149ffe1e 100644 --- a/app/data/stacks/sushiswap-subgraph/stack.yml +++ b/app/data/stacks/sushiswap-subgraph/stack.yml @@ -2,14 +2,14 @@ version: "1.0" name: sushiswap-subgraph description: "SushiSwap Subgraph stack" repos: - ## graph-node repo + # graph-node repo - github.com/graphprotocol/graph-node - ## sushiswap subgraph repo + # sushiswap subgraph repo - github.com/sushiswap/subgraphs containers: - ## graph-node image + # graph-node image - cerc/graph-node - ## sushiswap subgraphs image + # sushiswap subgraphs image - cerc/sushiswap-subgraphs pods: - graph-node