Skip to content

Commit

Permalink
feat(subgraph): add subgraph support
Browse files Browse the repository at this point in the history
- [x] Use the same subgraph from maci
- [x] Add registry related entities
- [x] Update events for contracts
  • Loading branch information
0xmad committed Sep 3, 2024
1 parent 4647014 commit a7cd78a
Show file tree
Hide file tree
Showing 34 changed files with 1,728 additions and 45 deletions.
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ zkeys
public/mockServiceWorker.js
playwright-report/
test-results/
packages/subgraph/templates/subgraph.template.yaml
packages/subgraph/subgraph.yaml

Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ interface IRecipientRegistry {
}

/// @notice Events
event RecipientAdded(uint256 indexed index, bytes32 id, bytes32 indexed metadataUrl, address indexed recipient);
event RecipientRemoved(uint256 indexed index, bytes32 id, address indexed recipient);
event RecipientChanged(uint256 indexed index, bytes32 id, bytes32 indexed metadataUrl, address indexed newAddress);
event RecipientAdded(uint256 indexed index, bytes32 id, bytes32 indexed metadataUrl, address indexed payout);
event RecipientRemoved(uint256 indexed index, bytes32 id, address indexed payout);
event RecipientChanged(uint256 indexed index, bytes32 id, bytes32 indexed metadataUrl, address indexed newPayout);

/// @notice Custom errors
error MaxRecipientsReached();
Expand Down
12 changes: 6 additions & 6 deletions packages/contracts/contracts/interfaces/IRegistryManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,25 @@ interface IRegistryManager {
event RequestSent(
address indexed registry,
RequestType indexed requestType,
address indexed recipient,
bytes32 indexed recipient,
uint256 index,
bytes32 id,
address payout,
bytes32 metadataUrl
);
event RequestApproved(
address indexed registry,
RequestType indexed requestType,
address indexed recipient,
bytes32 indexed recipient,
uint256 index,
bytes32 id,
address payout,
bytes32 metadataUrl
);
event RequestRejected(
address indexed registry,
RequestType indexed requestType,
address indexed recipient,
bytes32 indexed recipient,
uint256 index,
bytes32 id,
address payout,
bytes32 metadataUrl
);

Expand Down
12 changes: 6 additions & 6 deletions packages/contracts/contracts/registryManager/RegistryManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ contract RegistryManager is Ownable, IRegistryManager, ICommon {
emit RequestSent(
request.registry,
request.requestType,
request.recipient.recipient,
request.index,
request.recipient.id,
request.index,
request.recipient.recipient,
request.recipient.metadataUrl
);
}
Expand All @@ -83,9 +83,9 @@ contract RegistryManager is Ownable, IRegistryManager, ICommon {
emit RequestApproved(
request.registry,
request.requestType,
request.recipient.recipient,
request.index,
request.recipient.id,
request.index,
request.recipient.recipient,
request.recipient.metadataUrl
);

Expand All @@ -106,9 +106,9 @@ contract RegistryManager is Ownable, IRegistryManager, ICommon {
emit RequestRejected(
request.registry,
request.requestType,
request.recipient.recipient,
request.index,
request.recipient.id,
request.index,
request.recipient.recipient,
request.recipient.metadataUrl
);
}
Expand Down
12 changes: 6 additions & 6 deletions packages/contracts/tests/EASRegistryManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ describe("EASRegistryManager", () => {
.withArgs(
addRequest.registry,
addRequest.requestType,
addRequest.recipient.recipient,
addRequest.index,
addRequest.recipient.id,
addRequest.index,
addRequest.recipient.recipient,
addRequest.recipient.metadataUrl,
);

Expand All @@ -96,9 +96,9 @@ describe("EASRegistryManager", () => {
.withArgs(
changeRequest.registry,
changeRequest.requestType,
changeRequest.recipient.recipient,
changeRequest.index,
changeRequest.recipient.id,
changeRequest.index,
changeRequest.recipient.recipient,
changeRequest.recipient.metadataUrl,
);

Expand All @@ -107,9 +107,9 @@ describe("EASRegistryManager", () => {
.withArgs(
changeRequest.registry,
changeRequest.requestType,
changeRequest.recipient.recipient,
changeRequest.index,
changeRequest.recipient.id,
changeRequest.index,
changeRequest.recipient.recipient,
changeRequest.recipient.metadataUrl,
);

Expand Down
40 changes: 20 additions & 20 deletions packages/contracts/tests/RegistryManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ describe("RegistryManager", () => {
.withArgs(
addRequest.registry,
addRequest.requestType,
addRequest.recipient.recipient,
addRequest.index,
addRequest.recipient.id,
addRequest.index,
addRequest.recipient.recipient,
addRequest.recipient.metadataUrl,
);

Expand Down Expand Up @@ -175,9 +175,9 @@ describe("RegistryManager", () => {
.withArgs(
addRequest.registry,
addRequest.requestType,
addRequest.recipient.recipient,
addRequest.index,
addRequest.recipient.id,
addRequest.index,
addRequest.recipient.recipient,
addRequest.recipient.metadataUrl,
);

Expand All @@ -198,9 +198,9 @@ describe("RegistryManager", () => {
.withArgs(
changeRequest.registry,
changeRequest.requestType,
changeRequest.recipient.recipient,
changeRequest.index,
changeRequest.recipient.id,
changeRequest.index,
changeRequest.recipient.recipient,
changeRequest.recipient.metadataUrl,
);

Expand All @@ -209,9 +209,9 @@ describe("RegistryManager", () => {
.withArgs(
changeRequest.registry,
changeRequest.requestType,
changeRequest.recipient.recipient,
changeRequest.index,
changeRequest.recipient.id,
changeRequest.index,
changeRequest.recipient.recipient,
changeRequest.recipient.metadataUrl,
);

Expand Down Expand Up @@ -272,9 +272,9 @@ describe("RegistryManager", () => {
.withArgs(
addRequest.registry,
addRequest.requestType,
addRequest.recipient.recipient,
addRequest.index,
addRequest.recipient.id,
addRequest.index,
addRequest.recipient.recipient,
addRequest.recipient.metadataUrl,
);

Expand All @@ -283,9 +283,9 @@ describe("RegistryManager", () => {
.withArgs(
changeRequest.registry,
changeRequest.requestType,
changeRequest.recipient.recipient,
changeRequest.index,
changeRequest.recipient.id,
changeRequest.index,
changeRequest.recipient.recipient,
changeRequest.recipient.metadataUrl,
);

Expand All @@ -294,9 +294,9 @@ describe("RegistryManager", () => {
.withArgs(
addRequest.registry,
addRequest.requestType,
addRequest.recipient.recipient,
addRequest.index,
addRequest.recipient.id,
addRequest.index,
addRequest.recipient.recipient,
addRequest.recipient.metadataUrl,
);

Expand All @@ -305,9 +305,9 @@ describe("RegistryManager", () => {
.withArgs(
changeRequest.registry,
changeRequest.requestType,
changeRequest.recipient.recipient,
changeRequest.index,
changeRequest.recipient.id,
changeRequest.index,
changeRequest.recipient.recipient,
changeRequest.recipient.metadataUrl,
);

Expand Down Expand Up @@ -350,9 +350,9 @@ describe("RegistryManager", () => {
.withArgs(
removeRequest.registry,
removeRequest.requestType,
removeRequest.recipient.recipient,
removeRequest.index,
removeRequest.recipient.id,
removeRequest.index,
removeRequest.recipient.recipient,
removeRequest.recipient.metadataUrl,
);

Expand All @@ -363,9 +363,9 @@ describe("RegistryManager", () => {
.withArgs(
removeRequest.registry,
removeRequest.requestType,
removeRequest.recipient.recipient,
removeRequest.index,
removeRequest.recipient.id,
removeRequest.index,
removeRequest.recipient.recipient,
removeRequest.recipient.metadataUrl,
);

Expand Down
44 changes: 44 additions & 0 deletions packages/subgraph/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const path = require("path");

module.exports = {
root: true,
extends: ["../../.eslintrc.js"],
parser: "@typescript-eslint/parser",
parserOptions: {
project: path.resolve(__dirname, "./tsconfig.json"),
sourceType: "module",
typescript: true,
ecmaVersion: 2022,
experimentalDecorators: true,
requireConfigFile: false,
ecmaFeatures: {
classes: true,
impliedStrict: true,
},
warnOnUnsupportedTypeScriptVersion: true,
},
rules: {
"@typescript-eslint/no-shadow": [
"error",
{
builtinGlobals: true,
allow: [
"BigInt",
"location",
"event",
"history",
"name",
"status",
"Option",
"Request",
"test",
"expect",
"describe",
"afterEach",
"beforeEach",
"beforeAll",
],
},
],
},
};
9 changes: 9 additions & 0 deletions packages/subgraph/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
node_modules
data
build
generated
subgraph.yaml
schema.graphql
tests/.bin/
tests/.latest.json

19 changes: 19 additions & 0 deletions packages/subgraph/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# maci-platform-subgraph

1. Make sure you have `{network}.json` file in `config` folder, where network is a CLI name supported for subgraph network [https://thegraph.com/docs/en/developing/supported-networks/](https://thegraph.com/docs/en/developing/supported-networks/).

2. Add network, maci contract address and maci contract deployed block.

```json
{
"network": "optimism-sepolia",
"maciContractAddress": "0xD18Ca45b6cC1f409380731C40551BD66932046c3",
"registryManagerContractAddress": "0xbE6e250bf8B5F689c65Cc79667589A9EBF6Fe8E3",
"registryManagerContractStartBlock": 13160483,
"maciContractStartBlock": 11052407
}
```

3. Run `pnpm run build`. You can use env variables `NETWORK` and `VERSION` to switch config files.
4. Run `graph auth --studio {key}`. You can find the key in subgraph studio dashboard.
5. Run `pnpm run deploy` to deploy subgraph
7 changes: 7 additions & 0 deletions packages/subgraph/config/network.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"network": "optimism-sepolia",
"maciContractAddress": "0xbE6e250bf8B5F689c65Cc79667589A9EBF6Fe8E3",
"registryManagerContractAddress": "0xbE6e250bf8B5F689c65Cc79667589A9EBF6Fe8E3",
"registryManagerContractStartBlock": 13160483,
"maciContractStartBlock": 13160483
}
40 changes: 40 additions & 0 deletions packages/subgraph/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
version: "3"
services:
graph-node:
image: graphprotocol/graph-node
ports:
- "8000:8000"
- "8001:8001"
- "8020:8020"
- "8030:8030"
- "8040:8040"
depends_on:
- ipfs
- postgres
environment:
postgres_host: postgres
postgres_user: graph-node
postgres_pass: let-me-in
postgres_db: graph-node
ipfs: "ipfs:5001"
ethereum: "localhost:http://host.docker.internal:8545"
GRAPH_LOG: info
ipfs:
image: ipfs/kubo:v0.14.0
ports:
- "5001:5001"
volumes:
- ./data/ipfs:/data/ipfs
postgres:
image: postgres:14-alpine
ports:
- "5432:5432"
command: ["postgres", "-cshared_preload_libraries=pg_stat_statements", "-cmax_connections=200"]
environment:
POSTGRES_USER: graph-node
POSTGRES_PASSWORD: let-me-in
POSTGRES_DB: graph-node
PGDATA: "/var/lib/postgresql/data"
POSTGRES_INITDB_ARGS: "-E UTF8 --locale=C"
volumes:
- ./data/postgres:/var/lib/postgresql/data
3 changes: 3 additions & 0 deletions packages/subgraph/matchstick.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
testsFolder: ./tests
libsFolder: ./node_modules
manifestPath: ./subgraph.yaml
Loading

0 comments on commit a7cd78a

Please sign in to comment.