You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 18, 2023. It is now read-only.
LI-306: Containerization of Local Subgraph Deployment (#1)
* Initial containerization refactor
* Move scripts out of docker folder since independent of Docker
* Update README with subgraph endpoint access instructions
* Refactored containerization to include Hardhat and graph-node deployments, and default env var file
Using Graph Subgraph Studio (Future steps once Subgraph studio supports more networks):
34
-
1.`graph auth --studio <API KEY>` (see more at https://thegraph.com/studio/subgraph/set-protocol-v2/)
35
-
2.`yarn gen-deployment <NETWORK_NAME>` hardhat or mainnet or matic or staging-mainnet
36
-
3.`cp generated/addresses.ts .` Copy generated addresses file to root location
37
-
3.`graph codegen && graph build`
38
-
4.`graph deploy --studio set-protocol-v2` for mainnet or `graph deploy --studio set-protocol-v2-matic` for Matic/Polygon or `graph deploy --studio set-protocol-v2-staging` for staging mainnet
17
+
1. Deploy a Hardhat node (use `task deploy-hardhat -- detach` to start container in detached mode)
39
18
19
+
`task deploy-hardhat`
40
20
41
-
## Commands
21
+
1. Monitor the Hardhat node until fully deployed and tests are executed, e.g., if running detached use
42
22
43
-
Usage:
23
+
`docker logs docker-hardhat-1 --follow`
44
24
45
-
`yarn <COMMAND>`
25
+
1. Compile the Set Protocol ABIs
46
26
47
-
Commands:
27
+
`task gen-abi`
48
28
49
-
`build` - Compile subgraph
29
+
1. Deploy local subgraph
50
30
51
-
`codegen` - Generate types (if schema or ABI changed)
31
+
`task deploy-local`
52
32
53
-
`deploy-local` - Deploy subgraph to localhost
33
+
1. Once deployed, query the subgraph in the browser at (by default) http://127.0.0.1:8000/subgraphs/name/SetProtocol/set-protocol-v2
54
34
55
-
`deploy-to <IP>` - Deploy subgraph to Graph Node by IP
35
+
### [TO-DO] External Deployment (Graph Hosted Service / Subgraph Studio)
56
36
57
-
`deploy-hosted` - Deploy subgraph to hosted service
37
+
TBD
58
38
59
-
`gen-abis` - Pull contract ABIs from Set Protocol V2 repo (only needed if changed)
|`clean [-- all]`| Clean up local subgraph deployment; `all` arg additionally removes all volumes and the Hardhat node. |
46
+
|`deploy-hardhat [-- detach]`| Deploy a Hardhat node and subgraph tests; `detach` runs container detached. |
47
+
|`deploy-hosted [-- detach]`| Build and deploy subgraph on Hosted Service; `detach` runs container detached. |
48
+
|`deploy-local [-- detach]`| Build and deploy subgraph on local network; `detach` runs container detached. |
49
+
|`destroy-hardhat`| Tear down the deployed Hardhat node. |
50
+
|`docker-build`| Build subgraph Docker image on defined node version base (default: 16-slim). |
51
+
|`gen-abi`| Pull latest Set Protocol ABIs into the build environment. |
64
52
65
-
## Local development (hardhat)
53
+
## [TO-DO] ADVANCED DEPLOYMENT GUIDES
66
54
67
-
### Clone Set Protocol v2 fork
55
+
TBD: Things to be covered in this section
68
56
69
-
In separate directory:
57
+
- custom override of args (requires custom untracked .env configs or CLI arg overrides)
58
+
- 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.
59
+
- 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.
60
+
- 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.
70
61
71
-
1.`git clone https://github.com/jgrizzled/set-protocol-v2.git -b subgraph-dev && cd set-protocol-v2`
72
-
2.`cp .env.default .env`
73
-
3.`yarn install`
62
+
## [TO-DO] SUBGRAPH DEVELOPMENT
74
63
75
-
To run the hardhat node:
64
+
### Tutorial
76
65
77
-
1.`yarn chain --hostname 0.0.0.0`
78
-
2. Wait for node to start
79
-
3. (in separate terminal) `yarn deploy-mock`
66
+
TBD
80
67
81
-
### Install Graph Node
68
+
### Reference Guide
82
69
83
-
In separate directory:
70
+
To Be Completed
84
71
85
-
1.`git clone -q --depth=1 https://github.com/graphprotocol/graph-node.git && cd graph-node/docker`
86
-
2. Edit line 20 of docker-compose.yml to `ethereum: hardhat:http://host.docker.internal:8545` (May need to replace host.docker.internal with LAN IP)
87
-
3. Run with `sudo docker-compose up`
88
-
89
-
`rm -rf ./data` and restart containers if blockchain changes.
90
-
91
-
`sudo docker-compose build` if updated via `git pull`
92
-
93
-
### Deploy subgraph locally
94
-
95
-
From subgraph repo:
96
-
97
-
1.`yarn gen-deployment hardhat`
98
-
2.`yarn deploy-local`
99
-
100
-
Graph-node may take a few minutes to sync the subgraph.
101
-
102
-
Visit `http://localhost:8000/subgraphs/name/desert-defi/setprotocolv2/graphql` to view subgraph data
103
-
104
-
## Syncing to mainnet
105
-
106
-
Syncing the subgraph to mainnet requires an Ethereum archive node. We recommend [Turbogeth](https://github.com/ledgerwatch/turbo-geth) as it syncs fast and will fit on a 2TB SSD at present. Note that it takes a few hours for the subgraph to sync and re-deploying the subgraph will re-sync from scratch.
107
-
108
-
### Turbogeth
109
-
110
-
In separate directory:
111
-
112
-
1.`git clone -q --depth=1 https://github.com/ledgerwatch/turbo-geth.git && cd turbo-geth`
113
-
2.`sudo docker-compose build` (re-run if updated via `git pull`)
114
-
3.`sudo XDG_DATA_HOME=/preferred/data/folder docker-compose up -d`
2.`yarn deploy-local` or `yarn deploy-to <IP>` if Graph Node on another machine.
145
-
146
-
Watch graph-node logs for sync status and errors. Subgraph URL same as above.
147
-
148
-
## Files
72
+
#### Key Files
149
73
150
74
`schema.graphql` - Subgraph schema
151
75
@@ -159,25 +83,23 @@ Watch graph-node logs for sync status and errors. Subgraph URL same as above.
159
83
160
84
`src/entities/` - Entity helper functions
161
85
162
-
## Design
163
-
164
-
### Historical Entities
86
+
#### Historical Entities
165
87
166
-
#### Events
88
+
#####Events
167
89
168
90
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.
169
91
170
-
#### States
92
+
#####States
171
93
172
94
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.
173
95
174
96
Events are better for tracking important actions while States are better for timeseries data in which multiple data points per timestamp would be inconveinent.
175
97
176
-
### Current Entities
98
+
#####Current Entities
177
99
178
100
Tracks the most recent state of a contract. Usually references the latest event or state update entity.
179
101
180
-
### Entity Helpers
102
+
#####Entity Helpers
181
103
182
104
Most of the logic regarding manipulation of entities should be in helper functions. Create helper functions based on the following nomenclature as needed.
183
105
@@ -190,16 +112,16 @@ Prefixes:
190
112
- ensure: create or update existing entity. Useful for states
191
113
- track: execute contract call and store result in new entity. Useful for data that is not provided via event logs.
192
114
193
-
### Event Handlers
115
+
####Event/Call/Block Handlers
194
116
195
-
Process event data and call entity helper functions to update the subgraph. Must register event handlers in `templates/subgraph.yaml`.
117
+
Process events, function calls, and block data to update the subgraph. Must register handlers in `templates/subgraph.yaml`.
196
118
197
-
### Template spawners
119
+
####Template spawners
198
120
199
121
Not all contract addresses are known at the time of subgraph deployment. To track contracts as they are deployed, use contract templates.
200
122
Tell the subgraph to watch a newly created contract by calling create() on imports from `generated/templates`. Ex 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`.
201
123
202
-
## Reference
124
+
## References
203
125
204
126
[Discord: Index Co-op #set-subgraph](https://discord.gg/8FYPP7ebbw)
0 commit comments