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

Commit 89fa10b

Browse files
comcColin McRaepblivin0x
authored
Lev 116 add support for external deployments (#3)
* Initial refactor for supporting external deployment to Hosted Service. * Minor refactoring of SetTokenTemplate creation * Minor code format fixes * Update gitignore context * [lev-192-dynamically-populate-deprecated] Dynamically populate the subgraph.yaml targets based on dotenv subgraph network to handle deprecated Ethereum mainnet+staging SetTokenCreator contracts * [lev-191-auto-populate-subgraph-name-in] Dynamically populate subgraph name based on target network and clean up deploy scripts * Fixed hosted deployment commands and improved error handling * [sim-164-add-delegatemanager-abi-to-subgraph] Add DelegatedManager contract from set-v2-strategies repo to subgraph ABI generator * Clean up deployments.json unneeded contract addresses and add deprecated SetTokenCreator contract for Polygon staging * Add documentation about Hosted Subgraph inactivity policy * [lev-204-diagnose-and-fix-polygon-deployments]: - Add documentation about Hosted Subgraph inactivity policy - Clean up deployments.json unneeded contract addresses and add deprecated SetTokenCreator contract for Matic staging * Resolve issue with SetTokenCreator start block in Matic deployment * [Sim 163 create local hardhat node testable state (#6)] - add DelegatedManager abi - add template for delegated manager deployment script - Refactored Hardhat node state deployment to target set-v2-strategies repo - Fixed deploy-state script import - fix imports in existing scripts - add events for delegated manager role changes - fix header comment - add additional manager test cases Co-authored-by: Colin McRae <[email protected]> Co-authored-by: Pranav Bhardwaj <[email protected]>
1 parent 9606a86 commit 89fa10b

28 files changed

+1179
-369
lines changed

.gitignore

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ pids
1111
*.seed
1212
*.pid.lock
1313

14-
# Dependency directories
14+
# Dependency files and directories
1515
node_modules/
16+
# These should be explicitly committed if we want to lock versions
17+
package.json
18+
package-lock.json
1619

1720
# Yarn Integrity file
1821
.yarn-integrity
@@ -38,4 +41,10 @@ cache/
3841

3942
# Generated subgraph manifest and addresses
4043
subgraph.yaml
41-
addresses.ts
44+
addresses.ts
45+
46+
# User dotenv
47+
docker/custom.env
48+
49+
# Non-explicitly-committed tests
50+
test/

README.md

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Indexer of Set Protocol v2 events. Built on [The Graph](https://thegraph.com/).
44

55
<!--
6-
TO-DO:
6+
[TO-DO] CONTENTS (herein or external):
77
- Tutorials
88
- Deploy a local subgraph
99
- Deploy a subgraph to Hosted Service
@@ -55,23 +55,41 @@ TO-DO:
5555

5656
Example query to run can be found in `test/sample-query.txt`
5757

58-
### [TO-DO] External Deployment (Graph Hosted Service / Subgraph Studio)
58+
### External Deployment to Hosted Service
59+
60+
1. Build the Set Protocol Docker base and hardhat images
61+
62+
`task docker-build`
63+
64+
1. Deploy hosted subgraph to network specified by the `NETWORK_HOSTED` argument
65+
66+
`task deploy-hosted [-- NETWORK_HOSTED [SUBGRAPH_ACCESS_TOKEN]]`
67+
68+
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+
70+
**NOTE**
71+
72+
Per the [documentation](https://thegraph.com/docs/en/hosted-service/deploy-subgraph-hosted/#subgraph-archive-policy) on the Hosted Service:
73+
74+
> A subgraph is defined as "inactive" if it was deployed to the Hosted Service more than 45 days ago, and if it has received 0 queries in the last 30 days.
75+
76+
### [TO-DO] External Deployment to Subgraph Studio
5977

6078
TBD
6179

6280
## USAGE
6381

6482
Available tasks for this project:
6583

66-
| COMMAND [OPTS] | DESCRIPTION |
67-
|--------------------------------------|---------------------------------------------------------------------------------|
68-
| `clean [-- all\|subgraph\|hardhat]` | Clean up local subgraph deployment; `all` arg additionally removes all volumes and the Hardhat node. |
69-
| `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. |
70-
| `deploy-hosted [-- detach]` | Build and deploy subgraph on Hosted Service; `detach` runs container detached. |
71-
| `deploy-local [-- detach]` | Build and deploy subgraph on local network; `detach` runs container detached. |
72-
| `docker-build` | Build subgraph Docker image on defined node version base (default: 16-slim). |
73-
| `gen-abi` | Pull latest Set Protocol ABIs into the build environment. |
74-
| `gen-schema` | Compile the subgraph schema but do not deploy the subgraph. |
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. |
88+
| `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. |
7593

7694
## [TO-DO] ADVANCED DEPLOYMENT GUIDES
7795

@@ -91,6 +109,13 @@ TBD: Ideas to be covered in this section
91109
- Use `setToken` for schema fields, not `set` as will conflict will built-in callers
92110
- Templates must be initialized appropriately (see `ModuleInitialize` event handler for example)
93111

112+
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+
94119
### Reference Guide
95120

96121
To Be Completed

Taskfile.yml

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
version: "3"
22

3-
dotenv: ["./docker/.env"]
3+
dotenv: [
4+
"./docker/custom.env",
5+
"./docker/.env",
6+
]
47

58
tasks:
69

@@ -40,13 +43,16 @@ tasks:
4043
desc: "Build and deploy subgraph on Hosted Service."
4144
dir: docker/
4245
cmds:
43-
- docker-compose -f docker-compose.hosted.yml up {{.ARGS}}
46+
- docker-compose -f docker-compose.hosted.yml up
4447
vars:
45-
ARGS:
46-
sh: if [ "{{.CLI_ARGS}}" = "detach" ]; then echo "-d"; else echo ""; fi
48+
NETWORK_NAME:
49+
sh: if [ $(echo "{{.CLI_ARGS}}" | cut -d" " -f1) ]; then echo "{{.CLI_ARGS}}" | cut -d" " -f1; else echo "{{.NETWORK_HOSTED}}"; fi
50+
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
4752
env:
53+
ACCESS_TOKEN: "{{.SUBGRAPH_ACCESS_TOKEN}}"
4854
DEPLOYMENT: "hosted"
49-
NETWORK_NAME: "{{.NETWORK_HOSTED}}"
55+
NETWORK_NAME: "{{.NETWORK_NAME}}"
5056
preconditions:
5157
- sh: if [ -z "$(ls -A ../abis)" ]; then exit -1; fi
5258
msg: "ERROR: No ABIs found. Run 'task gen-abi' first."
@@ -61,7 +67,7 @@ tasks:
6167
sh: if [ "{{.CLI_ARGS}}" = "detach" ]; then echo "-d"; else echo ""; fi
6268
env:
6369
DEPLOYMENT: "local"
64-
ACCESS_TOKEN: "{{.ACCESS_TOKEN}}"
70+
ACCESS_TOKEN: "{{.LOCAL_ACCESS_TOKEN}}"
6571
IPFS_IP: "{{.IPFS_CONTAINER}}:{{.IPFS_PORT}}"
6672
GRAPH_NODE_IP: "{{.GRAPH_NODE_CONTAINER}}:{{.GRAPH_NODE_PORT}}"
6773
NETWORK_NAME: "{{.NETWORK_LOCAL}}"
@@ -85,6 +91,9 @@ tasks:
8591
desc: "Generate schema intermediate artifacts for development without a full deploy."
8692
cmds:
8793
- rm -rf generated/ build/
88-
- docker run --rm -e NETWORK_NAME={{.NETWORK_LOCAL}} -v $(pwd)/:/subgraph -v setprotocol-subgraph-node_modules:/subgraph/node_modules -w /subgraph {{.SET_IMAGE_NAME}}:node-{{.NODE_VER}} sh scripts/gen-schema.sh
94+
- 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
8995
vars:
90-
NETWORK_NAME: "{{.NETWORK_LOCAL}}"
96+
NETWORK_NAME:
97+
sh: if [ "{{.CLI_ARGS}}" = "hosted" ]; then echo "{{.NETWORK_HOSTED}}"; else echo "{{.NETWORK_LOCAL}}"; fi
98+
env:
99+
NETWORK_NAME: "{{.NETWORK_NAME}}"

deployments.json

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,56 @@
11
{
22
"mainnet": {
33
"network": "mainnet",
4+
"subgraphName": "set-protocol-v2",
45
"startBlock": 10830495,
56
"SetTokenCreator": "0xef72d3278dc3eba6dc2614965308d1435ffd748a"
67
},
7-
"hardhat": {
8-
"network": "hardhat",
9-
"startBlock": 0,
10-
"Controller": "0x1dc4c1cefef38a777b15aa20260a54e584b16c48",
11-
"SetTokenCreator": "0x8d61158a366019ac78db4149d75fff9dda51160d",
12-
"IntegrationRegistry": "0xb69e673309512a9d726f87304c6984054f87a93b",
13-
"PriceOracle": "0x131855dda0aaff096f6854854c55a4debf61077a",
14-
"SetValuer": "0xe86bb98fcf9bff3512c74589b78fb168200cc546",
15-
"BasicIssuanceModule": "0x1d7022f5b17d2f8b695918fb48fa1089c9f85401",
16-
"StreamingFeeModule": "0xdc688d29394a3f1e6f1e5100862776691afaf3d2",
17-
"NavIssuanceModule": "0xb7c9b454221e26880eb9c3101b3295ca7d8279ef",
18-
"TradeModule": "0x59adefa01843c627ba5d6aa350292b4b7ccae67a"
19-
},
20-
"matic": {
21-
"network": "matic",
22-
"startBlock": 0,
23-
"Controller": "0x75FBBDEAfE23a48c0736B2731b956b7a03aDcfB2",
24-
"SetTokenCreator": "0x14f0321be5e581abF9d5BC76260bf015Dc04C53d",
25-
"IntegrationRegistry": "0x4c4C649455c6433dC48ff1571C9e50aC58f0CeFA",
26-
"PriceOracle": "0x9378Ad514c00E4869656eE27b634d852DD48feAD",
27-
"SetValuer": "0x3700414Bb6716FcD8B14344fb10DDd91FdEA59eC",
28-
"BasicIssuanceModule": "0x38E5462BBE6A72F79606c1A0007468aA4334A92b",
29-
"StreamingFeeModule": "0x8440f6a2c42118bed0D6E6A89Bf170ffd13e21c0",
30-
"TradeModule": "0xd04AabadEd11e92Fefcd92eEdbBC81b184CdAc82"
31-
},
328
"staging-mainnet": {
339
"network": "mainnet",
10+
"subgraphName": "set-protocol-v2-staging",
3411
"startBlock": 10819027,
3512
"SetTokenCreator": "0x026d25C2B70Ddbb8D759f1f38d6fD6e23b60B6DF"
3613
},
14+
"matic": {
15+
"network": "matic",
16+
"subgraphName": "set-protocol-v2-matic",
17+
"startBlock": 0,
18+
"SetTokenCreator": "0x14f0321be5e581abF9d5BC76260bf015Dc04C53d"
19+
},
3720
"matic-staging-mainnet": {
3821
"network": "matic",
22+
"subgraphName": "set-protocol-v2-matic-staging",
3923
"startBlock": 16655167,
4024
"SetTokenCreator": "0x2907206b253665eef4776b8e684d61afd957b974"
4125
},
4226
"arbitrum-staging-mainnet": {
4327
"network": "arbitrum-one",
28+
"subgraphName": "set-protocol-v2-arbitrum-staging",
4429
"startBlock": 1168154,
4530
"SetTokenCreator": "0xCF786472d37f557A80fE6daFF6f2672bfDa728a3"
4631
},
4732
"avalanche-staging-mainnet": {
4833
"network": "avalanche",
34+
"subgraphName": "set-protocol-v2-avax-staging",
4935
"startBlock": 6097319,
5036
"SetTokenCreator": "0xE99447aBbD5A7730b26D2D16fCcB2086319e4bC3"
5137
},
38+
"optimism-mainnet": {
39+
"network": "optimism",
40+
"subgraphName": "set-protocol-v2-optimism",
41+
"startBlock": 900529,
42+
"SetTokenCreator": "0x0bc84D31f11D90156c30B4f19509Ede969A0B840"
43+
},
5244
"optimism-staging-mainnet": {
5345
"network": "optimism",
46+
"subgraphName": "set-protocol-v2-optimism-staging",
5447
"startBlock": 593299,
5548
"SetTokenCreator": "0xCF786472d37f557A80fE6daFF6f2672bfDa728a3"
5649
},
57-
"optimism-mainnet": {
58-
"network": "optimism",
59-
"startBlock": 900529,
60-
"SetTokenCreator": "0x0bc84D31f11D90156c30B4f19509Ede969A0B840"
50+
"hardhat": {
51+
"network": "hardhat",
52+
"subgraphName": "set-protocol-v2",
53+
"startBlock": 0,
54+
"SetTokenCreator": "0x8d61158a366019ac78db4149d75fff9dda51160d"
6155
}
6256
}

docker/.env

Lines changed: 53 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,69 @@
1-
# Node version to use for deployment
2-
NODE_VER=16
1+
#---------------------------------
2+
# SUBGRAPH CONFIGURATION SETTINGS
3+
#---------------------------------
4+
# This file defines the default and optional configuration parameters for
5+
# subgraph development and both local and external deployment targets.
6+
#
7+
# It is suggested to create a copy of this file with, e.g.,
8+
# cp docker/.env docker/custom.env
9+
# and uncomment and configure custom parameters and settings in the copy rather
10+
# than directly editing this file. The custom dotenv file sohuld be prepended
11+
# into the Taskfile.yml dotenv array to take precedence over any settings in
12+
# this file.
313

4-
# Docker image names to target for builds and container deployments
5-
HARDHAT_IMAGE_NAME=setprotocol/hardhat
6-
SET_IMAGE_NAME=setprotocol/base
14+
# USER CONFIGURABLE SETTINGS
15+
#----------------------------
716

8-
# Subgraph version label to deploy
17+
# Subgraph Version Label for Deployment
918
# See: https://thegraph.com/docs/en/studio/deploy-subgraph-studio#deploying-a-subgraph-to-subgraph-studio
10-
SUBGRAPH_VERSION=test-0.0.1
19+
# SUBGRAPH_VERSION="0.0.1"
20+
21+
# Hosted Service Target Network (see deployments.json for options)
22+
#NETWORK_HOSTED="mainnet"
23+
24+
# Hosted Service Subgraph Access Token
25+
# This private access key is required to deploy a subgraph to the Hosted
26+
# Service and is tied to the original Github account (GITHUB_REPO) used to
27+
# deploy the subgraph. It must not be committed or shared publicly.
28+
# See: https://thegraph.com/docs/en/hosted-service/deploy-subgraph-hosted/#store-the-access-token
29+
#SUBGRAPH_ACCESS_TOKEN=
30+
31+
# Github Repository Name for Hosted Service Deployments
32+
# Defaults to `justinkchen` as the original deployment linked repo tied to
33+
# the Set company ACCESS_TOKEN. Uncomment to override only if necessary.
34+
#GITHUB_REPO="justinkchen"
35+
36+
# SetProtocol Subgraph Name for Deployment
37+
# Defaults to the existing name based on the target graph network if empty.
38+
# Uncomment and specify a name to override only if necessary.
39+
#SUBGRAPH_NAME=
1140

12-
GITHUB_REPO=SetProtocol
13-
GRAPH_NAME=set-protocol-v2
1441

15-
# HARDHAT NODE (LOCAL)
16-
# --------------------
42+
# DEFAULT CONFIGURATION SETTINGS
43+
#--------------------------------
44+
# Do not change settings below unless you understand the consequences.
45+
46+
# Node Version for Docker Images
47+
NODE_VER=16
48+
49+
# SetProtocol Base Docker Image Name
50+
SET_IMAGE_NAME=setprotocol/base
51+
# SetProtocol Hardhat Node Docker Image Name
52+
HARDHAT_IMAGE_NAME=setprotocol/hardhat
53+
54+
# Hardhat Node Configuration
1755
HARDHAT_IP=docker-hardhat-1
18-
# HARDHAT_IP=docker_hardhat_run_45d1437ad006
1956
HARDHAT_PORT=8545
2057

21-
# LOCAL DEPLOYMENT PARAMS
22-
# -----------------------
23-
ACCESS_TOKEN=test
58+
# Local Deployment Configuration
59+
LOCAL_ACCESS_TOKEN=test # note: only used locally, ignored in hosted deployments
2460
IPFS_CONTAINER=docker-ipfs-1
2561
IPFS_PORT=5001
2662
GRAPH_NODE_CONTAINER=docker-graph-node-1
2763
GRAPH_NODE_PORT=8020
2864
NETWORK_LOCAL=hardhat
29-
GRAPHQL_PORT=8000 # port on host for TCP access to Subgraph GraphQL
65+
GRAPHQL_PORT=8000 # port on host for TCP access to Subgraph GraphQL query tool
3066

31-
# HOSTED DEPLOYMENT PARAMS
32-
# ------------------------
67+
# Hosted Service Deployment Configuration
3368
IPFS_HOSTED=https://api.thegraph.com/ipfs/
3469
GRAPH_NODE_HOSTED=https://api.thegraph.com/deploy/
35-
# External network to deploy on (see deployments.json for options)
36-
NETWORK_HOSTED=mainnet

docker/Dockerfile.base

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ ARG NODE_VER=16
1212
FROM node:${NODE_VER}-slim as base
1313

1414
RUN apt update \
15-
&& apt install -y python3 make gcc g++ openssl git libsecret-1-dev \
15+
&& apt install -y python3 make gcc g++ openssl git libsecret-1-dev jq \
1616
&& rm -rf /var/lib/apt/lists/* /tmp/*

docker/docker-compose.hosted.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,19 @@ services:
55
setprotocol-subgraph:
66
image: ${SET_IMAGE_NAME}:node-${NODE_VER}
77
environment:
8-
DEPLOYMENT: ${DEPLOYMENT:-""}
8+
DEPLOYMENT: ${DEPLOYMENT:-hosted}
99
IPFS_IP: ${IPFS_HOSTED:-""}
1010
GRAPH_NODE_IP: ${GRAPH_NODE_HOSTED:-""}
11-
ACCESS_TOKEN: ${ACCESS_TOKEN:-""}
11+
ACCESS_TOKEN: ${ACCESS_TOKEN}
1212
SUBGRAPH_VERSION: ${SUBGRAPH_VERSION:-""}
13-
NETWORK_NAME: ${NETWORK_NAME:-""}
14-
GITHUB_REPO: ${GITHUB_REPO:-""}
15-
GRAPH_NAME: ${GRAPH_NAME:-""}
13+
NETWORK_NAME: ${NETWORK_NAME}
14+
GITHUB_REPO: ${GITHUB_REPO:-justinkchen}
15+
SUBGRAPH_NAME: ${SUBGRAPH_NAME}
1616
volumes:
1717
- ../:/subgraph
1818
- setprotocol-subgraph-node_modules:/subgraph/node_modules
1919
working_dir: /subgraph
2020
command: "sh ./scripts/deploy.sh"
21-
# restart: on-failure:max-retries 5
2221

2322
volumes:
2423
setprotocol-subgraph-node_modules:

docker/docker-compose.local.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,21 @@ services:
3131
POSTGRES_PASSWORD: let-me-in
3232
POSTGRES_DB: graph-node
3333
volumes:
34-
- graph-node-postgres:/var/lib/postgresql/data
34+
- graph-node-postgres:/var/lib/postgresql/data
3535

3636
setprotocol-subgraph:
3737
image: ${SET_IMAGE_NAME}:node-${NODE_VER}
3838
depends_on:
3939
- graph-node
4040
environment:
41-
DEPLOYMENT: ${DEPLOYMENT:-""}
41+
DEPLOYMENT: ${DEPLOYMENT:-local}
4242
IPFS_IP: ${IPFS_IP:-""}
4343
GRAPH_NODE_IP: ${GRAPH_NODE_IP:-""}
44-
ACCESS_TOKEN: ${ACCESS_TOKEN:-""}
44+
ACCESS_TOKEN: ${ACCESS_TOKEN:-test}
4545
SUBGRAPH_VERSION: ${SUBGRAPH_VERSION:-""}
46-
NETWORK_NAME: ${NETWORK_NAME:-""}
47-
GITHUB_REPO: ${GITHUB_REPO:-""}
48-
GRAPH_NAME: ${GRAPH_NAME:-""}
46+
NETWORK_NAME: ${NETWORK_NAME:-hardhat}
47+
GITHUB_REPO: ${GITHUB_REPO:-SetProtocol}
48+
SUBGRAPH_NAME: ${SUBGRAPH_NAME}
4949
volumes:
5050
- ../:/subgraph
5151
- setprotocol-subgraph-node_modules:/subgraph/node_modules

0 commit comments

Comments
 (0)