Project Structure

Understand the project structure of a subgraph and important files (schema.graphql, subgraph.yaml).

Overview

Top-level folders

NameDescription
abis/Used for .json ABI files.
build/Built assets that are uploaded to IPFS upon deploy
generated/Generated AssemblyScript types after running graph codegen. Do not edit!
src/AssemblyScript handlers and helpers for processing data
tests/Unit tests powered by Matchstick

Top-level files

NameDescription
networks.jsonChain-specific metadata (i.e. contract addresses, start blocks). Use with graph build or graph deploy
schema.graphqlSchema for your GraphQL API
subgraph.yamlYAML file for all subgraph metadata (i.e. input data sources, triggers, handlers)

Subgraph Manifest (subgraph.yaml)

The subgraph.yaml file serves as the blueprint for your subgraph. It outlines the input data sources, triggers you’d like to handle, and the handlers that should respond to triggers. By configuring the subgraph.yaml file, you provide all the necessary instructions for Alchemy Subgraphs to index and serve your GraphQL API.

See the full specification here.

subgraph.yaml
1specVersion: 0.0.5
2schema:
3 file: ./schema.graphql
4dataSources:
5 - kind: ethereum
6 name: Comet
7 network: mainnet
8 source:
9 address: "0xc3d688B66703497DAA19211EEdff47f25384cdc3"
10 abi: Comet
11 startBlock: 15331586
12 mapping:
13 kind: ethereum/events
14 apiVersion: 0.0.7
15 language: wasm/assemblyscript
16 entities:
17 - AbsorbCollateral
18 - AbsorbDebt
19 - BuyCollateral
20 - PauseAction
21 - Supply
22 - SupplyCollateral
23 - Transfer
24 - TransferCollateral
25 - Withdraw
26 - WithdrawCollateral
27 - WithdrawReserves
28 abis:
29 - name: Comet
30 file: ./abis/Comet.json
31 eventHandlers:
32 - event: AbsorbCollateral(indexed address,indexed address,indexed address,uint256,uint256)
33 handler: handleAbsorbCollateral
34 - event: AbsorbDebt(indexed address,indexed address,uint256,uint256)
35 handler: handleAbsorbDebt
36 - event: BuyCollateral(indexed address,indexed address,uint256,uint256)
37 handler: handleBuyCollateral
38 - event: PauseAction(bool,bool,bool,bool,bool)
39 handler: handlePauseAction
40 - event: Supply(indexed address,indexed address,uint256)
41 handler: handleSupply
42 - event: SupplyCollateral(indexed address,indexed address,indexed address,uint256)
43 handler: handleSupplyCollateral
44 - event: Transfer(indexed address,indexed address,uint256)
45 handler: handleTransfer
46 - event: TransferCollateral(indexed address,indexed address,indexed address,uint256)
47 handler: handleTransferCollateral
48 - event: Withdraw(indexed address,indexed address,uint256)
49 handler: handleWithdraw
50 - event: WithdrawCollateral(indexed address,indexed address,indexed address,uint256)
51 handler: handleWithdrawCollateral
52 - event: WithdrawReserves(indexed address,uint256)
53 handler: handleWithdrawReserves
54 file: ./src/comet.ts

GraphQL Schema (schema.graphql)

The schema.graphql file contains the schema for your GraphQL API. See the GraphQL docs or The Graph’s docs for more details.

schema.graphql
1type AbsorbCollateral @entity(immutable: true) {
2 id: Bytes!
3 absorber: Bytes! # address
4 borrower: Bytes! # address
5 asset: Bytes! # address
6 collateralAbsorbed: BigInt! # uint256
7 usdValue: BigInt! # uint256
8 blockNumber: BigInt!
9 blockTimestamp: BigInt!
10 transactionHash: Bytes!
11}
12
13type AbsorbDebt @entity(immutable: true) {
14 id: Bytes!
15 absorber: Bytes! # address
16 borrower: Bytes! # address
17 basePaidOut: BigInt! # uint256
18 usdValue: BigInt! # uint256
19 blockNumber: BigInt!
20 blockTimestamp: BigInt!
21 transactionHash: Bytes!
22}
23
24type BuyCollateral @entity(immutable: true) {
25 id: Bytes!
26 buyer: Bytes! # address
27 asset: Bytes! # address
28 baseAmount: BigInt! # uint256
29 collateralAmount: BigInt! # uint256
30 blockNumber: BigInt!
31 blockTimestamp: BigInt!
32 transactionHash: Bytes!
33}
34
35type PauseAction @entity(immutable: true) {
36 id: Bytes!
37 supplyPaused: Boolean! # bool
38 transferPaused: Boolean! # bool
39 withdrawPaused: Boolean! # bool
40 absorbPaused: Boolean! # bool
41 buyPaused: Boolean! # bool
42 blockNumber: BigInt!
43 blockTimestamp: BigInt!
44 transactionHash: Bytes!
45}
46
47type Supply @entity(immutable: true) {
48 id: Bytes!
49 from: Bytes! # address
50 dst: Bytes! # address
51 amount: BigInt! # uint256
52 blockNumber: BigInt!
53 blockTimestamp: BigInt!
54 transactionHash: Bytes!
55}
56
57type SupplyCollateral @entity(immutable: true) {
58 id: Bytes!
59 from: Bytes! # address
60 dst: Bytes! # address
61 asset: Bytes! # address
62 amount: BigInt! # uint256
63 blockNumber: BigInt!
64 blockTimestamp: BigInt!
65 transactionHash: Bytes!
66}
67
68type Transfer @entity(immutable: true) {
69 id: Bytes!
70 from: Bytes! # address
71 to: Bytes! # address
72 amount: BigInt! # uint256
73 blockNumber: BigInt!
74 blockTimestamp: BigInt!
75 transactionHash: Bytes!
76}
77
78type TransferCollateral @entity(immutable: true) {
79 id: Bytes!
80 from: Bytes! # address
81 to: Bytes! # address
82 asset: Bytes! # address
83 amount: BigInt! # uint256
84 blockNumber: BigInt!
85 blockTimestamp: BigInt!
86 transactionHash: Bytes!
87}
88
89type Withdraw @entity(immutable: true) {
90 id: Bytes!
91 src: Bytes! # address
92 to: Bytes! # address
93 amount: BigInt! # uint256
94 blockNumber: BigInt!
95 blockTimestamp: BigInt!
96 transactionHash: Bytes!
97}
98
99type WithdrawCollateral @entity(immutable: true) {
100 id: Bytes!
101 src: Bytes! # address
102 to: Bytes! # address
103 asset: Bytes! # address
104 amount: BigInt! # uint256
105 blockNumber: BigInt!
106 blockTimestamp: BigInt!
107 transactionHash: Bytes!
108}
109
110type WithdrawReserves @entity(immutable: true) {
111 id: Bytes!
112 to: Bytes! # address
113 amount: BigInt! # uint256
114 blockNumber: BigInt!
115 blockTimestamp: BigInt!
116 transactionHash: Bytes!
117}