Skip to content

Commit c2e94d6

Browse files
committed
Merge branch 'develop' into feature/hardhat-ignition
2 parents 2760952 + 6582e96 commit c2e94d6

File tree

9 files changed

+2799
-3156
lines changed

9 files changed

+2799
-3156
lines changed

packages/subgraph/.env.template

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
1-
# environment to use for configuration (prod/staging)
2-
ENV=prod
1+
# The name of the network (e.g., mainnet, arbitrum, etc.)
2+
NETWORK_NAME=...
33

4-
# override the starting block for indexation of all contracts events
5-
# START_BLOCK=0
4+
# The URL of the Graph Node endpoint for self-hosted Graph Node
5+
GRAPHNODE_URL=...
66

7-
# AppRegistry contract address override
8-
# APP_REGISTRY_ADDRESS=0x...
7+
# The URL of the IPFS endpoint for self-hosted IPFS
8+
IPFS_URL=...
99

10-
# DatasetRegistry contract address override
11-
# DATASET_REGISTRY_ADDRESS=0x...
12-
13-
# Dataprotector contract address override
14-
# DATAPROTECTOR_ADDRESS=0x...
15-
16-
# DataprotectorSharing contract address override
17-
# DATAPROTECTOR_SHARING_ADDRESS=0x...
18-
19-
# AddOnlyAppWhitelistRegistry contract address override
20-
# ADD_ONLY_APP_WHITELIST_REGISTRY_ADDRESS=0x...
10+
# The version label for the deployment (e.g., v1.0.0)
11+
VERSION_LABEL=...

packages/subgraph/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ coverage.json
1111
# subgraph
1212
generated
1313
subgraph.yaml
14+
tests/.latest.json

packages/subgraph/README.md

Lines changed: 58 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,69 @@
11
# Subgraph
22

3+
This repository contains the code for the DataProtector subgraph, which indexes blockchain events to make them queryable through a GraphQL API.
4+
35
## Build the Subgraph
46

5-
And you have finishing editing the schema.graphql & subgraph.yaml files. Type the following command
7+
After editing the schema.graphql & subgraph.yaml files, build the subgraph with:
68

79
```bash
810
npm run codegen
911
npm run build
1012
```
1113

12-
Then you have to write ./src/bays.ts files in order to update the graph when new events appear. In this way, it will always be up to date.
14+
Then implement event handlers in the ./src files to keep the graph updated when new events occur on the blockchain.
15+
16+
## Deployment Options
1317

14-
## Local
18+
### Local Development
1519

16-
### Deploy on Local Graph node
20+
To deploy on a local Graph Node:
1721

1822
```bash
1923
npm run create-local
2024
npm run deploy-local
2125
```
2226

23-
### Test Subgrah API
27+
The subgraph will be available at: http://localhost:8000/subgraphs/name/DataProtector/graphql
28+
29+
### Hosted Production Environments
30+
31+
We use CI/CD pipelines to deploy our subgraphs to hosted environments.
32+
33+
#### Docker Image Tags
34+
35+
When building and pushing Docker images, the following tag generation strategy is used:
36+
37+
| Trigger | Environment | Tag Format | Example | Push? |
38+
|---------|-------------|------------|---------|-------|
39+
| Manual workflow dispatch | Production | `{package.json version}` | `1.2.3` | Yes |
40+
| Manual workflow dispatch | Development | `dev-{commit SHA}` | `dev-8e7d3f2` | Yes |
41+
| Push to `main` branch | Production | `{package.json version}` | `1.2.3` | Yes |
42+
| Push to `develop` branch | Development | `dev-{commit SHA}` | `dev-8e7d3f2` | Yes |
43+
| Tag push | N/A | `{tag name}` | `v1.2.3-beta` | Yes |
44+
| Other branch push | Development | `dev-{commit SHA}` | `dev-8e7d3f2` | No |
2445

25-
Deployed to : <http://localhost:8000/subgraphs/name/DataProtector/graphql>
46+
### Self-Hosted Subgraph Deployment Process
2647

27-
Request Example on GraphiQL :
48+
For zero-downtime updates to the production subgraph:
2849

29-
Query for GraphiQL API
50+
1. **Index the New Version (Temporary Deployment)**
51+
- Trigger deployment with target: `subgraph-deploy-tmp`
52+
- This creates a separate instance for indexing
53+
54+
2. **Wait for Indexing Completion**
55+
- Monitor the temporary deployment until it's fully synced
56+
57+
3. **Deploy to Production (Zero Downtime)**
58+
- Once temporary deployment is ready, trigger: `subgraph-deploy-prod`
59+
- This swaps the deployments with no service interruption
60+
61+
4. **Verify the Deployment**
62+
- Access the production subgraph at: https://thegraph.iex.ec/subgraphs/name/bellecour/dataprotector-v2/graphql
63+
64+
## Query Examples
65+
66+
### Sample GraphQL Query
3067

3168
```graphql
3269
query MyQuery($requiredSchema: [String!]!, $start: Int!, $range: Int!) {
@@ -57,48 +94,27 @@ query MyQuery($requiredSchema: [String!]!, $start: Int!, $range: Int!) {
5794
}
5895
```
5996

60-
```graphql
61-
Query Variables :
97+
### Query Variables
6298

99+
```json
63100
{
64101
"start": 0,
65102
"range": 1000,
66103
"requiredSchema": []
67104
}
68105
```
69106

70-
## Hosted
71-
72-
You can trigger a deployment using the promote action on the CI.
73-
74-
### Self Hosted Subgraph
75-
76-
To deploy a new version of a subgraph on the iExec self-hosted service, follow these steps:
77-
78-
1. Index the New Subgraph
79-
80-
First, index the new version of the subgraph using the temporary subgraph deployment.
81-
Trigger its deployment with the target:
82-
83-
```sh
84-
subgraph-deploy-tmp
85-
```
86-
87-
2. Wait for Indexing Completion
88-
89-
Once the temporary subgraph has finished indexing, you can proceed to the production deployment.
90-
91-
3. Deploy to Production (No Downtime)
92-
93-
Trigger the production deployment with :
94-
95-
```sh
96-
subgraph-deploy-prod
97-
```
107+
## Development Workflow
98108

99-
This ensures a seamless transition with no downtime.
109+
1. Update schema.graphql and subgraph.yaml as needed
110+
2. Run codegen to generate TypeScript types: `npm run codegen`
111+
3. Implement mapping handlers in src/ files
112+
4. Build the subgraph: `npm run build`
113+
5. Test locally before deploying to production environments
100114

101-
4. Verify the Deployment
115+
## CI/CD Integration
102116

103-
Visit the following URL to check the new version of the subgraph:
104-
<https://thegraph.iex.ec/subgraphs/name/bellecour/dataprotector-v2/graphql>
117+
Our repository uses automated workflows to build, test, and deploy the subgraph:
118+
- ABI validation checks ensure contract ABIs are up-to-date
119+
- Docker images are built and pushed with appropriate tags based on the source branch
120+
- Deployment follows a staged approach to ensure zero downtime

packages/subgraph/config/env.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import 'dotenv/config';
2+
import { z } from 'zod';
3+
4+
const envSchema = z.object({
5+
NETWORK_NAME: z.string().min(1, 'NETWORK_NAME is required').default('bellecour'),
6+
7+
GRAPHNODE_URL: z
8+
.string()
9+
.url('GRAPHNODE_URL must be a valid URL')
10+
.default('http://localhost:8020'),
11+
12+
IPFS_URL: z.string().url('IPFS_URL must be a valid URL').default('http://localhost:5001'),
13+
14+
VERSION_LABEL: z.string().min(1, 'VERSION_LABEL is required').default('bellecour/poco-v5'),
15+
});
16+
17+
export const env = envSchema.parse(process.env);

packages/subgraph/networks.json

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{
2+
"fuji": {
3+
"DataProtector": {
4+
"address": "0x2296daeDD3090750a80fFB2D0147669984909ED2",
5+
"startBlock": 39768073
6+
},
7+
"DatasetRegistry": {
8+
"address": "0x3441A0C9FE488c51fcABa2bAAA048720f4D4F72D",
9+
"startBlock": 39768073
10+
},
11+
"DataProtectorSharing": {
12+
"address": "0x0000000000000000000000000000000000000000",
13+
"startBlock": 0
14+
},
15+
"AppRegistry": {
16+
"address": "0x4a6531ce5150ee716b2d93865D0fbB9ce5492D17",
17+
"startBlock": 0
18+
},
19+
"AddOnlyAppWhitelistRegistry": {
20+
"address": "0x0000000000000000000000000000000000000000",
21+
"startBlock": 0
22+
}
23+
},
24+
"arbitrum-sepolia": {
25+
"DataProtector": {
26+
"address": "0x2296daeDD3090750a80fFB2D0147669984909ED2",
27+
"startBlock": 145960686
28+
},
29+
"DatasetRegistry": {
30+
"address": "0x3441A0C9FE488c51fcABa2bAAA048720f4D4F72D",
31+
"startBlock": 145960686
32+
},
33+
"DataProtectorSharing": {
34+
"address": "0x0000000000000000000000000000000000000000",
35+
"startBlock": 0
36+
},
37+
"AppRegistry": {
38+
"address": "0x4a6531ce5150ee716b2d93865D0fbB9ce5492D17",
39+
"startBlock": 0
40+
},
41+
"AddOnlyAppWhitelistRegistry": {
42+
"address": "0x0000000000000000000000000000000000000000",
43+
"startBlock": 0
44+
}
45+
},
46+
"bellecour": {
47+
"DataProtector": {
48+
"address": "0x3a4Ab33F3D605e75b6D00A32A0Fa55C3628F6A59",
49+
"startBlock": 25455501
50+
},
51+
"DatasetRegistry": {
52+
"address": "0x0000000000000000000000000000000000000000",
53+
"startBlock": 25455501
54+
},
55+
"DataProtectorSharing": {
56+
"address": "0x1390c3c6a545198809F1C7c5Dd2600ef74D60925",
57+
"startBlock": 28566236
58+
},
59+
"AppRegistry": {
60+
"address": "0x0000000000000000000000000000000000000000",
61+
"startBlock": 28566236
62+
},
63+
"AddOnlyAppWhitelistRegistry": {
64+
"address": "0x498D324F711b8998Be81818742e268dEE30347c6",
65+
"startBlock": 28566234
66+
}
67+
}
68+
}

0 commit comments

Comments
 (0)