This repository contains the source code for the Spectra Protocol Subgraph. It indexes data from the Spectra Protocol smart contracts, including Futures, Pools (AMMs), Metavaults, Limit Orders, Access Management, and Blocks.
-
Clone the repository:
git clone https://github.com/perspectivefi/spectra-subgraph.git cd spectra-subgraph -
Install dependencies:
yarn install
This project uses a template-based approach to generate subgraph.yaml files for different networks.
To generate configurations for all supported networks (found in src/configs/*.json):
yarn gen:configThis script will generate files like subgraph.mainnet.yaml, subgraph.arbitrum.yaml, etc., in the root directory.
To add support for a new network:
- Create a new configuration file in
src/configs/<network-name>.json. - Populate it with the required contract addresses and start blocks. You can copy an existing config (e.g.,
src/configs/mainnet.json) as a template.startBlockis the block where the first Spectra-related contract was deployed on the target network. - Add the network to
src/utils/ChainIds.tsif it is not already present. - Run
yarn gen:configto generate the newsubgraph.<network-name>.yamlfile.
After generating the configuration file for your target network, generate the AssemblyScript types (identical for all networks):
yarn codegen subgraph.mainnet.yamlTo build the subgraph:
graph build <subgraph-file.yaml>To deploy to a Graph Node (hosted service or decentralized network), use the standard graph deploy command, or e.g. goldsky subgraph deploy. You will need an access token.
graph deploy --product hosted-service <GITHUB_USER>/<SUBGRAPH_NAME> <subgraph-file.yaml>abis/: Smart contract ABIs.src/: Source code for mappings and configurations.configs/: Network-specific configuration JSON files.mappings/: AssemblyScript handlers for contract events.scripts/: Helper scripts (e.g., config generator).
schema.graphql: The GraphQL schema defining the entities.subgraph.template.yaml: The Mustache template for the subgraph manifest.
- Future: Represents Future Vaults (PT/IBT).
- Pool: Represents AMM pools (Curve V1, NG, SNG).
- Metavault: Represents Metavaults and their wrappers.
- LimitOrder: Tracks limit orders via the LimitOrderEngine.
- Account: User accounts and their portfolios.
- Asset: Tokens and assets indexed by the subgraph.
Run unit tests using Matchstick:
yarn test