Skip to content

Zup-Protocol/zup-dexs-subgraph

Repository files navigation

Zup Dexs Subgraph

This is the primary subgraph used by the Zup Protocol to calculate yields. It aggregates data from all protocols supported by Zup across different networks. For each network, it includes all Zup-supported DEXs in a single subgraph.

Table of Contents

  1. Dependencies
  2. Installation
  3. Running tests
  4. Adding a new network
  5. Adding a new DEX

Dependencies

  • Node.js

    • To know if Node.js is installed, run node --version you should see a response like vX.X.X.
    • If Node.js is not installed, head over to How to install Node.js
  • Docker (optional)

    • To know if Docker is installed, run docker --version you should see a response like Docker version X.X.X.
    • If Docker is not installed, head over to How to install Docker
  • Yarn

    • To know if Yarn is installed, run yarn --version you should see a response like yarn x.x.x.
    • If Yarn is not installed, head over to Yarn installation

Installation

  1. Clone the repository
  2. run yarn install

Running tests

To run all the tests, just open your terminal and type:

yarn test

Adding a new network

To add a new network to the subgraph, you need to do a few things:

  1. Add a new subgraph manifest in subgraph-manifests for the intended network with the DEXs supported in that network.
  2. Add a new constant with the network name (following the Network CLI Name from the Graph) in current-network.ts for the new network.
  3. Add a new entry for each function defined in current-network.ts that needs to be overriden for the new network.
  4. Modify the functions in utils/position-manager-address.ts to return the position manager address of each DEX supported in the new network.
  5. Add new scripts in package.json for the new network (following the pattern [script]:networkname), to make it easier to deploy, generate code and build the subgraph.

Adding a new DEX

To add a new DEX to the subgraph, you need to do a few things:

  1. Modify the manifest of the networks that should support the new DEX in subgraph-manifests:
  • The Factory contract of the DEX must be included in the manifest, at the dataSources section, following the same pattern as the other DEXs.
  • In case that the new DEX events or code is a little different from the UniswapV3 original one, some additional things are required:
    • You should add its ABI in the abis folder. For the Pool and the Factory.
    • A new template for this DEX must be added in the subgraph manifest, with the correct events and handlers.
    • You should create personalized handlers for this new DEX, to handle events emitted by this personalized template, following the pattern of the other ones at v3-pools/mappings/factory/dexs (WARNING: DON'T FORGET TO IMPORT THE EVENT FROM THE SAME DEX AS THE HANDLER, IMPORTING OTHER DEX EVENT CAN CAUSE BUGS).
  1. Create a factory handler specific for the new DEX in v3-pools/mappings/factory/dexs, following the pattern of the other ones (WARNING: Be sure to import the correct event from the same DEX, importing other DEX event can cause bugs)

  2. Create a new function in utils/position-manager-address.ts to return the address of the position manager for this new DEX for each network and attach it to its handler

  3. Modify the root subgraph manifest subgraph.yaml to include the new DEX in the subgraph, so tests can be ran without any compilation error, this is simply copying and pasting the newly added config from the others manifests, but changing the network to mainnet and changing the path of the handlers and files

  4. Code tests for this nex DEX handlers if possible :)

About

Zup's Subgraph to query DEXs Smart Contracts

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published