stack-orchestrator/stack_orchestrator/data/stacks/fixturenet-sushiswap-subgraph
2024-04-26 15:43:25 +00:00
..
README.md Rename app -> stack_orchestrator (#625) 2023-11-07 00:06:55 -07:00
stack.yml changing image names for lotus 2024-04-26 15:43:25 +00:00

Fixturenet SushiSwap Subgraph

Setup

Clone required repositories:

laconic-so --stack fixturenet-sushiswap-subgraph setup-repositories --pull

Checkout to a non-default branch in the cloned repos if required:

# Default repo base dir
cd ~/cerc

# Example
cd graph-node
git checkout <your-branch> && 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:

laconic-so --stack fixturenet-sushiswap-subgraph build-containers

Deploy

Deploy the stack:

laconic-so --stack fixturenet-sushiswap-subgraph deploy --cluster sushigraph up

# Note: Remove any existing volumes for the cluster for a fresh start

After all services have started:

  • Follow graph-node logs:

    laconic-so --stack fixturenet-sushiswap-subgraph deploy --cluster sushigraph logs -f graph-node
    
  • Check that the subgraphs have been deployed:

    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/v3-lotus/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-lotus
    # .
    # .
    # 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  |
    # 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:

# 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:<HOST_PORT>/subgraphs/name/sushiswap/blocks/graphql

# v3 subgraph endpoint:
http://127.0.0.1:<HOST_PORT>/subgraphs/name/sushiswap/v3-lotus/graphql

Run

  • Deploy an ERC20 token:

    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=<TOKEN1_ADDRESS>
    export TOKEN2_ADDRESS=<TOKEN2_ADDRESS>
    
  • Get contract address of factory deployed:

    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=<FACTORY_ADDRESS>
    
  • Create a pool:

    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=<POOL_ADDRESS>
    
  • Initialize the pool:

    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:

    export RECIPIENT=0xD375B03bd3A2434A9f675bEC4Ccd68aC5e67C743
    
  • Trigger pool Mint event:

    docker exec -it sushigraph-sushiswap-v3-core-1 pnpm run pool:mint:docker --pool $POOL_ADDRESS --recipient $RECIPIENT --amount 10
    
  • Trigger pool Burn event:

    docker exec -it sushigraph-sushiswap-v3-core-1 pnpm run pool:burn:docker --pool $POOL_ADDRESS --amount 10
    
  • Query the sushiswap v3-lotus subgraph GQL after running above commands

    {
      _meta {
        block {
          number
        }
        deployment
        hasIndexingErrors
      }
    
      factories {
        poolCount
        id
      }
    
      pools {
        id
        token0 {
          id
          name
          symbol
        }
        mints {
          id
          owner
        }
        burns {
          id
          owner
        }
      }
    }
    

Clean up

Stop all the services running in background run:

laconic-so --stack fixturenet-sushiswap-subgraph deploy --cluster sushigraph down

Clear volumes created by this stack:

# 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$")