Skip to content

Commit 740cb2e

Browse files
authored
Merge pull request #11 from kleros/feat(subgraph)/curate-subgraph
feat(web): initial-subgraph-setup
2 parents 653f175 + 2782155 commit 740cb2e

28 files changed

+1120
-108
lines changed

subgraph/package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@
33
"version": "2.0.0",
44
"license": "MIT",
55
"scripts": {
6-
"clean": "graph clean",
6+
"update:arbitrum-sepolia-devnet": "./scripts/update.sh arbitrumSepoliaDevnet arbitrum-sepolia",
7+
"update:arbitrum-sepolia": "./scripts/update.sh arbitrumSepolia arbitrum-sepolia",
8+
"update:arbitrum": "./scripts/update.sh arbitrum arbitrum",
9+
"update:local": "./scripts/update.sh localhost mainnet",
710
"codegen": "graph codegen",
811
"build": "graph build",
12+
"test": "graph test",
13+
"clean": "graph clean && rm subgraph.yaml.bak.*",
14+
" ": "----------------------------------------------------------------------------------------",
915
"create-local": "graph create --node http://localhost:8020/ kleros/curate-v2-local",
1016
"remove-local": "graph remove --node http://localhost:8020/ kleros/curate-v2-local",
1117
"deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 kleros/curate-v2-local --version-label v$(date +%s)",

subgraph/schema.graphql

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
enum Status {
2+
"The item is not registered on the TCR and there are no pending requests."
3+
absent
4+
"The item is registered and there are no pending requests."
5+
registered
6+
"The item is not registered on the TCR, but there is a pending registration request."
7+
registrationRequested
8+
"The item is registered on the TCR, but there is a pending removal request. These are sometimes also called removal requests."
9+
clearingRequested
10+
}
11+
12+
enum Ruling {
13+
"The arbitrator did not rule or refused to rule."
14+
None
15+
"The arbitrator ruled in favor of the requester."
16+
Accept
17+
"The arbitrator in favor of the challenger."
18+
Reject
19+
}
20+
21+
type Arbitrator @entity {
22+
"The address of the arbitrator"
23+
id: ID!
24+
}
25+
26+
type Counter @entity {
27+
id: ID!
28+
totalRegistries: BigInt!
29+
totalItems: BigInt!
30+
totalDeposits: BigInt!
31+
numberOfCurators: BigInt!
32+
}
33+
34+
type User @entity {
35+
id: ID! # address
36+
registry: [Registry!]! @derivedFrom(field: "registerer")
37+
items: [Item!]! @derivedFrom(field: "registerer")
38+
requests: [Request!]! @derivedFrom(field: "requester")
39+
challenges: [Request!]! @derivedFrom(field: "challenger")
40+
}
41+
42+
type Registry @entity {
43+
"The registry address"
44+
id: ID!
45+
"The items submitted to this list"
46+
items: [Item!]! @derivedFrom(field: "registry")
47+
"The requests submitted to this list"
48+
requests: [Request!]! @derivedFrom(field: "registry")
49+
"Connected TCR. Can be the 0 address. In practice, will never be null."
50+
connectedTCR: Bytes
51+
"The address that registered the curate"
52+
registerer: User!
53+
}
54+
55+
type Item @entity {
56+
"The id of the item in the subgraph entity. Format: <itemID>@<listaddress_lowercase>"
57+
id: ID!
58+
"The ID of the item in the registry. Also the keccak256 hash of the data."
59+
itemID: Bytes!
60+
"The data describing the item."
61+
data: String!
62+
"The parsed data describing the item."
63+
props: [ItemProp!]! @derivedFrom(field: "item")
64+
"First indexable value of the json file."
65+
key0: String
66+
"Second indexable value of the json file."
67+
key1: String
68+
"Third indexable value of the json file."
69+
key2: String
70+
"Fourth indexable value of the json file."
71+
key3: String
72+
"Fifth indexable value of the json file."
73+
key4: String
74+
"The item identifiers combined as a single string."
75+
keywords: String
76+
"The current status of the item."
77+
status: Status!
78+
"List of status change requests made for the item in the form requests[requestID]."
79+
requests: [Request!]! @derivedFrom(field: "item")
80+
"The total number of requests for this item."
81+
numberOfRequests: BigInt!
82+
"The registry where this item was submitted."
83+
registry: Registry!
84+
"The address of the registry this item was submitted. Redundant with registry field to allow use in conditionals."
85+
registryAddress: Bytes!
86+
"Time when the latest request was made."
87+
latestRequestSubmissionTime: BigInt!
88+
"The time the latest request was resolved."
89+
latestRequestResolutionTime: BigInt!
90+
"Whether the item is currently disputed."
91+
disputed: Boolean!
92+
"The account that made the latest request to the item."
93+
latestRequester: User
94+
"The account that challenged the latest request, if any."
95+
latestChallenger: User
96+
"The user that requested the first request / registration"
97+
registerer: User!
98+
}
99+
100+
type _Schema_
101+
@fulltext(
102+
name: "itemSearch"
103+
language: en
104+
algorithm: rank
105+
include: [{ entity: "Item", fields: [{ name: "keywords" }] }]
106+
)
107+
108+
type ItemProp @entity {
109+
id: ID!
110+
type: String!
111+
label: String!
112+
description: String!
113+
isIdentifier: Boolean!
114+
value: String
115+
item: Item!
116+
}
117+
118+
type Request @entity {
119+
"The item ID (which is the keccak256 hash of its data)."
120+
id: ID!
121+
"True if a dispute was raised."
122+
disputed: Boolean!
123+
"ID of the dispute, if any."
124+
disputeID: BigInt!
125+
"Time when the request was made. Used to track when the challenge period ends."
126+
submissionTime: BigInt!
127+
"True if the request was executed and/or any raised disputes were resolved."
128+
resolved: Boolean!
129+
"The party that made a request"
130+
requester: User!
131+
"The party that challenged the request"
132+
challenger: User
133+
"The arbitrator trusted to solve disputes for this request."
134+
arbitrator: Bytes!
135+
"The extra data for the trusted arbitrator of this request."
136+
arbitratorExtraData: Bytes!
137+
"The deposit that would be awarded to the challenger if challenge is successful"
138+
deposit: BigInt!
139+
"The outcome of the dispute, if any. Note that unsuccessful appeal fundings can invert the arbitrator ruling (so this may differ from the ruling given by the arbitrator)."
140+
disputeOutcome: Ruling!
141+
"Whether it was requested to add or remove the item to/from the list."
142+
requestType: Status!
143+
"The item this request belongs to."
144+
item: Item!
145+
"The registry where this request was submitted."
146+
registry: Registry!
147+
"The address of the registry this item was submitted. Redundant with registry field to allow use in conditionals."
148+
registryAddress: Bytes!
149+
"The time the request was resolved."
150+
resolutionTime: BigInt!
151+
"Only set if the request was settled by a dispute. Used by the twitter bot"
152+
finalRuling: BigInt
153+
"The hash of the transaction that created this request."
154+
creationTx: Bytes!
155+
"The hash of the transaction that solved this request."
156+
resolutionTx: Bytes
157+
}

subgraph/scripts/update.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env bash
2+
3+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
4+
5+
function update() #hardhatNetwork #graphNetwork #dataSourceIndex #contract
6+
{
7+
local hardhatNetwork="$1"
8+
local graphNetwork="$2"
9+
local dataSourceIndex="$3"
10+
local contract="$4"
11+
local artifact="$SCRIPT_DIR/../../contracts/deployments/$hardhatNetwork/$contract.json"
12+
13+
# Set the address
14+
address=$(cat "$artifact" | jq '.address')
15+
yq -i ".dataSources[$dataSourceIndex].source.address=$address" "$SCRIPT_DIR"/../subgraph.yaml
16+
17+
# Set the start block
18+
blockNumber="$(cat "$artifact" | jq '.receipt.blockNumber')"
19+
yq -i ".dataSources[$dataSourceIndex].source.startBlock=$blockNumber" "$SCRIPT_DIR"/../subgraph.yaml
20+
21+
# Set the Graph network
22+
graphNetwork=$graphNetwork yq -i ".dataSources[$dataSourceIndex].network=env(graphNetwork)" "$SCRIPT_DIR"/../subgraph.yaml
23+
24+
# Set the ABIs path for this Hardhat network
25+
abiIndex=0
26+
for f in $(yq e .dataSources[$dataSourceIndex].mapping.abis[].file subgraph.yaml -o json -I 0 | jq -sr '.[]')
27+
do
28+
f2=$(echo $f | sed "s|\(.*\/deployments\/\).*\/|\1$hardhatNetwork\/|")
29+
yq -i ".dataSources[$dataSourceIndex].mapping.abis[$abiIndex].file=\"$f2\"" "$SCRIPT_DIR"/../subgraph.yaml
30+
(( ++abiIndex ))
31+
done
32+
}
33+
34+
# as per ../contracts/hardhat.config.js
35+
hardhatNetwork=${1:-arbitrumSepolia}
36+
37+
# as per https://thegraph.com/docs/en/developing/supported-networks/
38+
graphNetwork=${2:-arbitrum\-sepolia}
39+
i=0
40+
41+
# backup
42+
cp "$SCRIPT_DIR"/../subgraph.yaml "$SCRIPT_DIR"/../subgraph.yaml.bak.$(date +%s)
43+
44+
for contract in $(yq .dataSources[].name "$SCRIPT_DIR"/../subgraph.yaml)
45+
do
46+
update $hardhatNetwork $graphNetwork $i $contract
47+
(( ++i ))
48+
done

0 commit comments

Comments
 (0)