Subgraph for the Sovryn Core Protocol contracts including AMM, Staking, Vesting, Governance, FastBTC, Margin Trading and Borrowing. Other products like Perpetual Swaps and Zero have their own subgraphs.
This subgraph contains logic for transforming and storing blockchain events in the Sovryn Protocol, and serving up a publicly available graphQL API for this data. The iGraphQL explorer is deployed here, and you can find detailed schema documentation there or in the ./schema directory in this repo.
Please note that this is still an early version of the subgraph. While it has undergone testing, we are aware there may be some bugs. If you wish to report a bug, please contact us on discord through the tech-support or user-feedback channels to let us know.
For more information on The Graph protocol, head to the Graph documentation here: https://thegraph.com/docs/.
- have node v16 installed (higher versions may fail to deploy to the ipfs node)
- have Docker and Docker Compose installed
- clone repo
- Run
npm install
- Add a
.env.dev
file in the root of the project. Copy the contents of.env.example
into this file (you can change the password to your own password if you wish) - Run
npm run schema
to generate the schema.graphql file from the ./schema directory - Run
npm run prepare:RSK:testnet
. This will create the docker-compose.yml file and the subgraph.yaml file from the template files. - Run
npm run dev:up
. This will run docker compose up -d and pass in your environment file. (might need to rundocker pull arm64v8/docker
for M1 Macs) - Run
npm run codegen
. This will generate the ./generated folder with types and contract objects. - Run
npm run build
to generate the build folder - Run
npm run create-local
to start running the graph node locally - Run
npm run deploy-local
to deploy the contents of the build folder locally - Go to http:https://localhost:8000/subgraphs/name/DistributedCollective/sovryn-subgraph/graphql to see the iGraphQL GUI for your local subgraph
When adding a new abi to the subgraph, you can auto-generate the subgraph.yaml and initial mapping file by running a scaffold script:
-
npm run scaffold -- -fp <ABI_FILE_PATH> -gm -gs -a <CONTRACT_ADDRESS>
This will generate a mapping file in ./src with the name of the abi, a schema file in ./schema with an entity for each event, and a datasource in the subgraph.template.yml -
npm run scaffold -- --help
for more options
If you want to start the subgraph from a later block, you can run the following script to change all the start blocks of all data sources to the desired block. Note that this will mean that all data before that block will be absent from the subgraph.
To temporarily change the start block for testing:
npm run test-start-block -- -b [ BLOCK_NUMBER ]
To reset start blocks back to original state:
npm run prepare:RSK:testnet
While developing, you can partially build a subgraph if you don't need data to sync from all the contracts.
To build a partial manifest run:
npm run partial-manifest -- -sect [ SUBSECTION_NAME ]
To add a new manifest subsection (eg vesting, governance, bridges), go to utils/buildPartialManifest.js
and add an array of the contracts you want in your subsection to the manifestSections array.
You can also add to the keywords array if you want to filter the contracts by keyword, for example only keeping contracts that contain 'Vesting'.
- The subgraph mappings files are written in AssemblyScript, not Typescript. AssemblyScript docs can be found here: https://www.assemblyscript.org/. Pay particular attention to the difference in the equality operator -
===
compares referencess,==
compares values. - If you are having issues with postgres, try deleting the
data/
directory from the subgraph root - The block numbers for Orderbook contracts on mainnet are set to blocks far in the future, because these contracts only exist on testnet
- This subgraph takes approximately 40 hours to fully sync on mainnet
To contribute, open a PR to development branch using a branch name prefaced with feat/
, fix/
or hotfix/
, and request @creed-victor as the reviewer.
This project has adopted the Microsoft Open Source Code of Conduct. For more information, see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.
The Sovryn DApp is open-sourced software licensed under the MIT license.
Thanks to creators/contributors of the following repos for inspiration and code snippets:
- Blocklytics Bancor Subgraph: https://github.com/blocklytics/bancor-subgraph-v2
- Uniswap V3 Subgraph: https://github.com/Uniswap/v3-subgraph
- Protofire library: https://github.com/protofire/subgraph-toolkit