Skip to content
This repository was archived by the owner on Jan 18, 2023. It is now read-only.

Commit 26a76f1

Browse files
authored
Sim 165 update subgraph schema and mappings (#10)
* Clean up Hardhat Docker build script * add DelegatedManager migration to EOAmanager test case * update imports * update calls to initializeModuleAndExtension with module parameters * Refactor contract ABI deployment in support set-protocol-v2 v0.4.0 and set-v2-strategies v0.0.7 * add WIP deployment script for DelegatedManagerSystem test environment * add updated abi generation for DelegatedManagerSystem contracts * * Restructure subgraph in support of DelegatedManager integration * Refactor local deployments to improve developer experience * Refactor Taskfile tasks to use docker-compose * Update deployments.json with new contract addresses * Replace setTokens String type with SetToken on Owner, Methodologist, and Operator for expanded querying capability * Add entity to track template instantiation to eliminate warnings on duplicates * Clean up deployments.json target names in line with set-v2-deployments repo; add Controller and ManagerCore addresses for available deployments * Minor update to README and update sample query examples
1 parent 81cbab2 commit 26a76f1

38 files changed

+1298
-922
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,13 @@ cache/
4141

4242
# Generated subgraph manifest and addresses
4343
subgraph.yaml
44+
!templates/subgraph.yaml
4445
addresses.ts
4546

4647
# User dotenv
4748
docker/custom.env
4849

4950
# Non-explicitly-committed tests
50-
test/
51+
test/
52+
53+
abis/

README.md

Lines changed: 18 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,6 @@
22

33
Indexer of Set Protocol v2 events. Built on [The Graph](https://thegraph.com/).
44

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-
245
## SETUP
256

267
### Requirements:
@@ -67,7 +48,7 @@ Indexer of Set Protocol v2 events. Built on [The Graph](https://thegraph.com/).
6748

6849
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.
6950

70-
**NOTE**
51+
**IMPORTANT NOTE**
7152

7253
Per the [documentation](https://thegraph.com/docs/en/hosted-service/deploy-subgraph-hosted/#subgraph-archive-policy) on the Hosted Service:
7354

@@ -81,111 +62,40 @@ TBD
8162

8263
Available tasks for this project:
8364

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. |
8869
| `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. |
11276

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
12478

12579
`schema.graphql` - Subgraph schema
12680

12781
`templates/subgraph.yaml` - configure watched contracts and events
12882

129-
`deployments.json` - configure deployed contract addresses
83+
`deployments.json` - configure deployed contract addresses on each chain
13084

13185
`src/` - [AssemblyScript](https://www.assemblyscript.org) code for subgraph handlers
13286

13387
`src/mappings/` - Event handlers
13488

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
14490

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
14692

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/)
14894

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)
18496

18597
[Set Protocol V2 Docs](https://docs.tokensets.com/)
18698

18799
[Set Protocol V2 Contracts](https://github.com/SetProtocol/set-protocol-v2)
188100

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)

Taskfile.yml

Lines changed: 73 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ dotenv: [
88
tasks:
99

1010
clean:
11-
desc: "Clean up deployments. Options: 'subgraph' (default), 'hardhat', or 'all'."
11+
desc: "Clean up deployments. Options: 'subgraph' (default), 'graphnode', 'hardhat', or 'all'."
1212
dir: docker/
1313
cmds:
1414
- docker-compose -f {{.TARGET}} down --volumes {{.ARGS}}
@@ -17,6 +17,8 @@ tasks:
1717
TARGET:
1818
sh: if [ "{{.CLI_ARGS}}" = "hardhat" ]; then
1919
echo "docker-compose.hardhat.yml";
20+
elif [ "{{.CLI_ARGS}}" = "graphnode" ]; then
21+
echo "docker-compose.graphnode.yml";
2022
else
2123
echo "docker-compose.local.yml";
2224
fi
@@ -37,33 +39,63 @@ tasks:
3739
sh: basename "{{.CLI_ARGS}}"
3840
env:
3941
DEPLOY_SCRIPT: "{{.DEPLOY_SCRIPT}}"
42+
preconditions:
43+
- sh: if [ -z "{{.CLI_ARGS}}" ]; then
44+
echo "No test deployment script provided.";
45+
exit 1;
46+
fi
4047

4148
deploy-hosted:
42-
# TO-DO: untested
4349
desc: "Build and deploy subgraph on Hosted Service."
4450
dir: docker/
4551
cmds:
4652
- docker-compose -f docker-compose.hosted.yml up
4753
vars:
4854
NETWORK_NAME:
49-
sh: if [ $(echo "{{.CLI_ARGS}}" | cut -d" " -f1) ]; then echo "{{.CLI_ARGS}}" | cut -d" " -f1; else echo "{{.NETWORK_HOSTED}}"; fi
55+
sh: if [ $(echo "{{.CLI_ARGS}}" | cut -d" " -f1) ]; then
56+
echo "{{.CLI_ARGS}}" | cut -d" " -f1;
57+
else
58+
echo "{{.NETWORK_HOSTED}}";
59+
fi
5060
SUBGRAPH_ACCESS_TOKEN:
51-
sh: if [ $(echo "{{.CLI_ARGS}}" | cut -d" " -s -f2) ]; then echo "{{.CLI_ARGS}}" | cut -d" " -s -f2; else echo "{{.SUBGRAPH_ACCESS_TOKEN}}"; fi
61+
sh: if [ $(echo "{{.CLI_ARGS}}" | cut -d" " -s -f2) ]; then
62+
echo "{{.CLI_ARGS}}" | cut -d" " -s -f2;
63+
else
64+
echo "{{.SUBGRAPH_ACCESS_TOKEN}}";
65+
fi
5266
env:
5367
ACCESS_TOKEN: "{{.SUBGRAPH_ACCESS_TOKEN}}"
5468
DEPLOYMENT: "hosted"
5569
NETWORK_NAME: "{{.NETWORK_NAME}}"
5670
preconditions:
57-
- sh: if [ -z "$(ls -A ../abis)" ]; then exit -1; fi
71+
- sh: if [ -z "$(ls -A ../abis)" ]; then exit 1; fi
5872
msg: "ERROR: No ABIs found. Run 'task gen-abi' first."
5973

6074
deploy-local:
61-
desc: "Build and deploy subgraph on local network."
75+
desc: "Build graph-node and ipfs services then deploy subgraph on local network."
6276
dir: docker/
6377
cmds:
64-
- docker-compose -f docker-compose.local.yml up {{.ARGS}}
78+
- docker-compose -f docker-compose.graphnode.yml -f docker-compose.local.yml up {{.DETACH}}
6579
vars:
66-
ARGS:
80+
DETACH:
81+
sh: if [ "{{.CLI_ARGS}}" = "detach" ]; then echo "-d"; else echo ""; fi
82+
env:
83+
DEPLOYMENT: "local"
84+
ACCESS_TOKEN: "{{.LOCAL_ACCESS_TOKEN}}"
85+
IPFS_IP: "{{.IPFS_CONTAINER}}:{{.IPFS_PORT}}"
86+
GRAPH_NODE_IP: "{{.GRAPH_NODE_CONTAINER}}:{{.GRAPH_NODE_PORT}}"
87+
NETWORK_NAME: "{{.NETWORK_LOCAL}}"
88+
preconditions:
89+
- sh: if [ -z "$(ls -A ../abis)" ]; then exit 1; fi
90+
msg: "ERROR: No ABIs found. Run 'task gen-abi' first."
91+
92+
deploy-local-graphnode:
93+
desc: "Build and deploy graph-node and ipfs services on local network."
94+
dir: docker/
95+
cmds:
96+
- docker-compose -f docker-compose.graphnode.yml up {{.DETACH}}
97+
vars:
98+
DETACH:
6799
sh: if [ "{{.CLI_ARGS}}" = "detach" ]; then echo "-d"; else echo ""; fi
68100
env:
69101
DEPLOYMENT: "local"
@@ -72,7 +104,34 @@ tasks:
72104
GRAPH_NODE_IP: "{{.GRAPH_NODE_CONTAINER}}:{{.GRAPH_NODE_PORT}}"
73105
NETWORK_NAME: "{{.NETWORK_LOCAL}}"
74106
preconditions:
75-
- sh: if [ -z "$(ls -A ../abis)" ]; then exit -1; fi
107+
- sh: if [ -z "$(ls -A ../abis)" ]; then exit 1; fi
108+
msg: "ERROR: No ABIs found. Run 'task gen-abi' first."
109+
110+
deploy-local-subgraph:
111+
desc: "Deploy subgraph on running local graph-node and ipfs network."
112+
dir: docker/
113+
cmds:
114+
- if [ "{{.REFRESH}}" = "true" ]; then echo "Deleting IPFS database and re-building..."; else echo "Skipping IPFS refresh..."; fi
115+
- if [ "{{.REFRESH}}" = "true" ]; then docker-compose -f docker-compose.graphnode.yml exec ipfs rm -rf /data/ipfs/*; fi
116+
- if [ "{{.REFRESH}}" = "true" ]; then docker-compose -f docker-compose.graphnode.yml restart ipfs; fi
117+
- if [ "{{.REFRESH}}" = "true" ]; then docker-compose -f docker-compose.graphnode.yml restart graph-node; fi
118+
- docker-compose -f docker-compose.local.yml run setprotocol-subgraph
119+
- docker-compose -f docker-compose.local.yml rm -f setprotocol-subgraph
120+
vars:
121+
REFRESH:
122+
sh: if [ "{{.CLI_ARGS}}" = "refresh" ]; then echo "true"; else echo "false"; fi
123+
env:
124+
DEPLOYMENT: "local"
125+
ACCESS_TOKEN: "{{.LOCAL_ACCESS_TOKEN}}"
126+
IPFS_IP: "{{.IPFS_CONTAINER}}:{{.IPFS_PORT}}"
127+
GRAPH_NODE_IP: "{{.GRAPH_NODE_CONTAINER}}:{{.GRAPH_NODE_PORT}}"
128+
NETWORK_NAME: "{{.NETWORK_LOCAL}}"
129+
preconditions:
130+
- sh: if [ $( docker container inspect -f '{{.State.Status}}' {{.GRAPH_NODE_CONTAINER}} ) != "running" ]; then exit 1; fi
131+
msg: "ERROR: Docker container '{{.GRAPH_NODE_CONTAINER}}' is not running."
132+
- sh: if [ $( docker container inspect -f '{{.State.Status}}' {{.IPFS_CONTAINER}} ) != "running" ]; then exit 1; fi
133+
msg: "ERROR: Docker container '{{.IPFS_CONTAINER}}' is not running."
134+
- sh: if [ -z "$(ls -A ../abis)" ]; then exit 1; fi
76135
msg: "ERROR: No ABIs found. Run 'task gen-abi' first."
77136

78137
docker-build:
@@ -96,9 +155,13 @@ tasks:
96155
desc: "Generate schema intermediate artifacts for development without a full deploy."
97156
cmds:
98157
- rm -rf generated/ build/
99-
- docker run --rm -e NETWORK_NAME={{.NETWORK_NAME}} -v $(pwd)/:/subgraph -v setprotocol-subgraph-node_modules:/subgraph/node_modules -w /subgraph {{.SET_IMAGE_NAME}}:node-{{.NODE_VER}} sh scripts/gen-schema.sh
158+
- docker-compose -f docker/docker-compose.schema.yml run gen-schema
159+
- docker-compose -f docker/docker-compose.schema.yml rm -f gen-schema
100160
vars:
101161
NETWORK_NAME:
102162
sh: if [ "{{.CLI_ARGS}}" = "hosted" ]; then echo "{{.NETWORK_HOSTED}}"; else echo "{{.NETWORK_LOCAL}}"; fi
103163
env:
104164
NETWORK_NAME: "{{.NETWORK_NAME}}"
165+
preconditions:
166+
- sh: if [ -z "$(ls -A ./abis)" ]; then exit 1; fi
167+
msg: "ERROR: No ABIs found. Run 'task gen-abi' first."

0 commit comments

Comments
 (0)