|
2 | 2 |
|
3 | 3 | Indexer of Set Protocol v2 events. Built on [The Graph](https://thegraph.com/).
|
4 | 4 |
|
5 |
| -<!-- |
6 |
| -[TO-DO] CONTENTS (herein or external): |
7 |
| -- Tutorials |
8 |
| - - Deploy a local subgraph |
9 |
| - - Deploy a subgraph to Hosted Service |
10 |
| - - Deploy a subgraph to Subgraph Studio |
11 |
| -- How-To Guides |
12 |
| - - Update the subgraph schema |
13 |
| - - Update the subgraph mappings |
14 |
| - - Test the subgraph locally |
15 |
| - - Set up a Postman query |
16 |
| -- Technical Reference |
17 |
| - - Docker compose usage |
18 |
| - - Task usage |
19 |
| -- Background Information |
20 |
| - - Schema structure |
21 |
| - - Query structure |
22 |
| ---> |
23 |
| - |
24 | 5 | ## SETUP
|
25 | 6 |
|
26 | 7 | ### Requirements:
|
@@ -67,7 +48,7 @@ Indexer of Set Protocol v2 events. Built on [The Graph](https://thegraph.com/).
|
67 | 48 |
|
68 | 49 | Note: `NETWORK_HOSTED` and `SUBGRAPH_ACCESS_TOKEN` must be provided as input arguments or defined in the dotenv configuration. Input arguments take precendence over dotenv configurations. For input arguments, you can specify just the network, or both the network and the access token, but you cannot provide the access token alone.
|
69 | 50 |
|
70 |
| -**NOTE** |
| 51 | +**IMPORTANT NOTE** |
71 | 52 |
|
72 | 53 | Per the [documentation](https://thegraph.com/docs/en/hosted-service/deploy-subgraph-hosted/#subgraph-archive-policy) on the Hosted Service:
|
73 | 54 |
|
|
81 | 62 |
|
82 | 63 | Available tasks for this project:
|
83 | 64 |
|
84 |
| -| COMMAND [OPTS] | DESCRIPTION | |
85 |
| -|---------------------------------------|---------------------------------------------------------------------------------| |
86 |
| -| `clean [-- all\|subgraph\|hardhat]` | Clean up local subgraph deployment; `all` arg additionally removes all volumes and the Hardhat node. | |
87 |
| -| `deploy-hardhat -- /path/to/file.ts` | Deploy a local Hardhat node and run a test script. Must specify full path to file as task input argument. | |
| 65 | +| COMMAND [OPTS] | DESCRIPTION | |
| 66 | +|--------------------------------------|---------------------------------------------------------------------------------| |
| 67 | +| `clean [-- all\|subgraph\|hardhat]` | Clean up local subgraph deployment; `all` arg additionally removes all volumes and the Hardhat node. | |
| 68 | +| `deploy-hardhat -- /path/to/file.ts` | Deploy a local Hardhat node and run a test script. Must specify full path to file as task input argument. | |
88 | 69 | | `deploy-hosted [-- NETWORK_HOSTED [SUBGRAPH_ACCESS_TOKEN]]` | Build and deploy subgraph to `NETWORK_HOSTED` on Hosted Service. `SUBGRAPH_ACCESS_TOKEN` must be provided or defined in a private dotenv. |
|
89 |
| -| `deploy-local [-- detach]` | Build and deploy subgraph on local network; `detach` runs container detached. | |
90 |
| -| `docker-build` | Build subgraph Docker image on defined node version base (default: 16-slim). | |
91 |
| -| `gen-abi` | Pull latest Set Protocol ABIs into the build environment. | |
92 |
| -| `gen-schema [-- hosted]` | Compile the subgraph schema but do not deploy the subgraph; default target subgraph network is hardhat. | |
93 |
| - |
94 |
| -## [TO-DO] ADVANCED DEPLOYMENT GUIDES |
95 |
| - |
96 |
| -TBD: Ideas to be covered in this section |
97 |
| - |
98 |
| -- custom override of args (requires custom untracked .env configs or CLI arg overrides) |
99 |
| -- the [Set Protocol V2 repo](https://github.com/SetProtocol/set-protocol-v2.git) currently requires node <= 16; therefore, Node 16 is the default target base image used in the Subgraph Docker image. |
100 |
| -- node dependencies installation into a named Docker volume, build the subgraph mappings, create the subgraph, then deploy it to the target graph node and IPFS database. Not that consecutive runs of this command will use the existing named volume for the `node_modules` unless it is manually removed. |
101 |
| -- the subgraph is deployed to the local graph-node and IPFS containers defined in the `subgraph.env` file. The subgraph endpoints given by the deployment are relative to the Docker container and not accessible externally as given. To access the subgraph, instead navigate to: http://127.0.0.1:8000/subgraphs/name/SetProtocol/setprotocolv2. |
102 |
| - |
103 |
| -## [TO-DO] SUBGRAPH DEVELOPMENT |
104 |
| - |
105 |
| -### [TEMP] Dev Notes |
106 |
| - |
107 |
| -- Each named dataSource or template entry should be in its own mappings/<entity>.ts file |
108 |
| -- Entity names cannot end with "s" due to conflict with query API (not currently documented) |
109 |
| -- Use `setToken` for schema fields, not `set` as will conflict will built-in callers |
110 |
| -- Templates must be initialized appropriately (see `ModuleInitialize` event handler for example) |
111 |
| - |
| 70 | +| `deploy-local [-- detach]` | Build and deploy graph-node and ipfs services on local network followed by deployment of the subgraph; `detach` runs containers in detached mode. | |
| 71 | +| `deploy-local-graphnode [-- detach]` | Build and deploy graph-node and ipfs services on local network; `detach` runs containers in detached mode. | |
| 72 | +| `deploy-local-subgraph [-- refresh]` | Compile and deploy the subgraph onto running graph-node and ipfs services on local network. `refresh` first deletes all IPFS data and restarts the service. | |
| 73 | +| `docker-build` | Build subgraph Docker image on defined node version base (default: 16-slim). | |
| 74 | +| `gen-abi` | Pull latest Set Protocol ABIs into the build environment. | |
| 75 | +| `gen-schema [-- hosted]` | Compile the subgraph schema but do not deploy the subgraph; default target subgraph network is local unless `hosted` argument is provided. | |
112 | 76 |
|
113 |
| -`ModuleInitialized` Event Notes |
114 |
| -- `event.address` - `ModuleInitialized` module contract address |
115 |
| -- `event.transaction.hash` - hash of the call transaction that triggered the event |
116 |
| -- `event.params._module` - the initialized module contract address |
117 |
| - |
118 |
| - |
119 |
| -### Reference Guide |
120 |
| - |
121 |
| -To Be Completed |
122 |
| - |
123 |
| -#### Key Files |
| 77 | +## KEY FILES |
124 | 78 |
|
125 | 79 | `schema.graphql` - Subgraph schema
|
126 | 80 |
|
127 | 81 | `templates/subgraph.yaml` - configure watched contracts and events
|
128 | 82 |
|
129 |
| -`deployments.json` - configure deployed contract addresses |
| 83 | +`deployments.json` - configure deployed contract addresses on each chain |
130 | 84 |
|
131 | 85 | `src/` - [AssemblyScript](https://www.assemblyscript.org) code for subgraph handlers
|
132 | 86 |
|
133 | 87 | `src/mappings/` - Event handlers
|
134 | 88 |
|
135 |
| -`src/utils/` - Entity helper functions and other utilities |
136 |
| - |
137 |
| -#### Historical Entities |
138 |
| - |
139 |
| -##### Events |
140 |
| - |
141 |
| -Individual transaction log events referenced by TxID and log index. Can have multiple events of the same type with the same timestamp (IE same block). Ex TradeEvent. |
142 |
| - |
143 |
| -##### States |
| 89 | +`src/utils/` - Entity mappings functions and other helper utilities |
144 | 90 |
|
145 |
| -Final state of an entity at the end of a block. Referenced by block number. Multiple events in the same block will be consolidated to one state update. Ex TotalSupplyState. |
| 91 | +## REFERENCES |
146 | 92 |
|
147 |
| -Events are better for tracking important actions while States are better for timeseries data in which multiple data points per timestamp would be inconveinent. |
| 93 | +[The Graph Docs](https://thegraph.com/docs/) |
148 | 94 |
|
149 |
| -##### Current Entities |
150 |
| - |
151 |
| -Tracks the most recent state of a contract. Usually references the latest event or state update entity. |
152 |
| - |
153 |
| -##### Entity Helpers |
154 |
| - |
155 |
| -Most of the logic regarding manipulation of entities should be in helper functions. Create helper functions based on the following nomenclature as needed. |
156 |
| - |
157 |
| -Prefixes: |
158 |
| - |
159 |
| -- create: create new entity |
160 |
| -- get: lookup entity by ID and return entity or throw error |
161 |
| -- update: update entity with new properties |
162 |
| -- delete: remove entity from subgraph store |
163 |
| -- ensure: create or update existing entity. Useful for states |
164 |
| -- track: execute contract call and store result in new entity. Useful for data that is not provided via event logs. |
165 |
| - |
166 |
| -#### Event/Call/Block Handlers |
167 |
| - |
168 |
| -Process events, smart contract function calls, and block data to update the subgraph. Must register handlers in `templates/subgraph.yaml`. |
169 |
| - |
170 |
| -#### Template spawners |
171 |
| - |
172 |
| -Not all contract addresses are known at the time of subgraph deployment. To track contracts as they are deployed, use contract templates. |
173 |
| -Tell the subgraph to watch a newly created contract by calling `create()` on imports from `generated/templates`. For example, the SetToken factory contract (SetTokenCreator) emits an event when a new SetToken is created, so we register that address as a new SetToken contract to watch. Templates are defined in `templates/subgraph.yaml`. |
174 |
| - |
175 |
| -## References |
176 |
| - |
177 |
| -[Discord: Index Co-op #set-subgraph](https://discord.gg/8FYPP7ebbw) |
178 |
| - |
179 |
| -[Subgraph Outline Sheet](https://docs.google.com/spreadsheets/d/1I3sk1kvfCPnnrUUCiBa35DZneeTx0vtGk04B-rKCJVE/edit?usp=sharing) |
180 |
| - |
181 |
| -[Subgraph notes doc](https://docs.google.com/document/d/1inFbQiskHoEKaNYdaHx69-quy8Y2xIva6N3673qw2jA/edit) |
182 |
| - |
183 |
| -[TheGraph Docs](https://thegraph.com/docs/) |
| 95 | +[Set Protocol Subgraph Docs](https://app.gitbook.com/o/-MGdl9Y5UCSpZPXC3ad7/s/-MGdlDDRsIRuOJOl7btN/function-tools-and-guides/engineering/development-guides/the-graph) |
184 | 96 |
|
185 | 97 | [Set Protocol V2 Docs](https://docs.tokensets.com/)
|
186 | 98 |
|
187 | 99 | [Set Protocol V2 Contracts](https://github.com/SetProtocol/set-protocol-v2)
|
188 | 100 |
|
189 |
| -[Set Protocol System Diagram](https://drive.google.com/file/d/15ETEqxkjkR29GmWH4gg4ob_OW9lb_Nly/view) |
190 |
| - |
191 |
| -[Hosted API](https://thegraph.com/explorer/subgraph/desert-defi/setprotocolv2) |
| 101 | +[Set Protocol V2 Strategies Contracts](https://github.com/SetProtocol/set-v2-strategies) |
0 commit comments