Skip to content
This repository was archived by the owner on Nov 9, 2022. It is now read-only.

Commit 9810923

Browse files
committed
chore: build subgraph schema
1 parent 2e41de7 commit 9810923

File tree

4 files changed

+307
-10
lines changed

4 files changed

+307
-10
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
## (2021-01-22)
22

3+
- chore: generate first changelog ([2e41de7](https://github.com/kleros/governor-web/commit/2e41de7))
34
- chore: set up project and architecture ([d28fb74](https://github.com/kleros/governor-web/commit/d28fb74))

subgraph/schema.graphql

Lines changed: 262 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,267 @@
1+
enum Status {
2+
"""
3+
Session has no dispute.
4+
"""
5+
NoDispute
6+
"""
7+
Session has an active dispute.
8+
"""
9+
DisputeCreated
10+
"""
11+
Session has a resolved dispute.
12+
"""
13+
Resolved
14+
}
15+
16+
type MetaEvidence @entity {
17+
"""
18+
Meta evidence ID.
19+
"""
20+
id: ID!
21+
"""
22+
URI of the meta evidence file.
23+
"""
24+
URI: String!
25+
}
26+
127
type Contract @entity {
228
"""
3-
The singleton entity's ID, "0".
29+
Singleton entity ID, "0".
430
"""
531
id: ID!
32+
"""
33+
Deployer.
34+
"""
35+
deployer: Bytes!
36+
"""
37+
Sum of reserved ETH for rewards.
38+
"""
39+
reservedETH: BigInt!
40+
"""
41+
Base deposit required for submission.
42+
"""
43+
submissionBaseDeposit: BigInt!
44+
"""
45+
Time in seconds for submission.
46+
"""
47+
submissionTimeout: BigInt!
48+
"""
49+
Time in seconds for execution.
50+
"""
51+
executionTimeout: BigInt!
52+
"""
53+
Time in seconds for withdrawal.
54+
"""
55+
withdrawTimeout: BigInt!
56+
"""
57+
Multiplier for calculating the fee stake that must be paid in a case where there is no winner or loser.
58+
"""
59+
sharedMultiplier: BigInt!
60+
"""
61+
Multiplier for calculating the fee stake paid by the party that won the previous round.
62+
"""
63+
winnerMultiplier: BigInt!
64+
"""
65+
Multiplier for calculating the fee stake paid by the party that lost the previous round.
66+
"""
67+
loserMultiplier: BigInt!
68+
"""
69+
Time of the last approval of a submission.
70+
"""
71+
lastApprovalTime: BigInt!
72+
"""
73+
Number of times the meta evidence has been updated. Used to track the latest meta evidence ID.
74+
"""
75+
metaEvidenceUpdates: BigInt!
76+
"""
77+
First submission that paid appeal fees in the last dispute.
78+
"""
79+
shadowWinner: Submission
80+
"""
81+
The current meta evidence.
82+
"""
83+
metaEvidence: MetaEvidence!
84+
}
85+
86+
type Session @entity {
87+
"""
88+
Creation time.
89+
"""
90+
creationTime: BigInt!
91+
"""
92+
Session ID.
93+
"""
94+
id: ID!
95+
"""
96+
Ruling, if any.
97+
"""
98+
ruling: BigInt
99+
"""
100+
Dispute ID, if any.
101+
"""
102+
disputeID: BigInt
103+
"""
104+
Total deposits balance. This is used to calculate rewards.
105+
"""
106+
sumDeposit: BigInt!
107+
"""
108+
Status.
109+
"""
110+
status: Status!
111+
"""
112+
Cooldown period after every submission. This gives time for people to inspect and potentially challenge submissions.
113+
"""
114+
durationOffset: BigInt!
115+
"""
116+
Submissions.
117+
"""
118+
submissions: [Submission!]! @derivedFrom(field: "session")
119+
"""
120+
Number of submissions.
121+
"""
122+
submissionsLength: BigInt!
123+
"""
124+
Rounds.
125+
"""
126+
rounds: [Round!]! @derivedFrom(field: "session")
127+
"""
128+
Number of rounds.
129+
"""
130+
roundsLength: BigInt!
131+
}
132+
133+
type Submission @entity {
134+
"""
135+
Creation time.
136+
"""
137+
creationTime: BigInt!
138+
"""
139+
Session the submission is for.
140+
"""
141+
session: Session!
142+
"""
143+
Submission ID.
144+
"""
145+
id: ID!
146+
"""
147+
Submitter.
148+
"""
149+
submitter: Bytes!
150+
"""
151+
Deposit.
152+
"""
153+
deposit: BigInt!
154+
"""
155+
Transactions hashed in a chain.
156+
"""
157+
listHash: Bytes!
158+
"""
159+
True, if the submission was accepted for execution.
160+
"""
161+
approved: Boolean!
162+
"""
163+
Time when the submission was approved, if any.
164+
"""
165+
approvalTime: BigInt
166+
"""
167+
Transactions.
168+
"""
169+
transactions: [Transaction!]! @derivedFrom(field: "submission")
170+
"""
171+
Number of transactions.
172+
"""
173+
transactionsLength: BigInt!
174+
}
175+
176+
type Transaction @entity {
177+
"""
178+
Creation time.
179+
"""
180+
creationTime: BigInt!
181+
"""
182+
Submission the transaction is for.
183+
"""
184+
submission: Submission!
185+
"""
186+
Transaction ID, keccak256(submissionID) + submissionTransactionsLength.
187+
"""
188+
id: ID!
189+
"""
190+
Address to call.
191+
"""
192+
target: Bytes!
193+
"""
194+
Value to call with.
195+
"""
196+
value: BigInt!
197+
"""
198+
Data to call with.
199+
"""
200+
data: Bytes!
201+
"""
202+
True, if the transaction was executed.
203+
"""
204+
executed: Boolean!
205+
}
206+
207+
type Round @entity {
208+
"""
209+
Creation time.
210+
"""
211+
creationTime: BigInt!
212+
"""
213+
Session the round is for.
214+
"""
215+
session: Session!
216+
"""
217+
Round ID, keccak256(sessionID, sessionRoundsLength).
218+
"""
219+
id: ID!
220+
"""
221+
Fees paid by each side in the round.
222+
"""
223+
paidFees: [BigInt!]!
224+
"""
225+
True, for sides that have fully paid their fee.
226+
"""
227+
hasPaid: [Boolean!]!
228+
"""
229+
Sum of reimbursable fees and stake rewards available to the parties that made contributions to the side that ultimately won.
230+
"""
231+
feeRewards: BigInt!
232+
"""
233+
Sum of already reimbursed fees and rewarded stakes.
234+
"""
235+
successfullyPaid: BigInt!
236+
"""
237+
Contributions for the round.
238+
"""
239+
contributions: [Contribution!]! @derivedFrom(field: "round")
240+
"""
241+
Number of contributions.
242+
"""
243+
contributionsLength: BigInt!
244+
}
245+
246+
type Contribution @entity {
247+
"""
248+
Creation time.
249+
"""
250+
creationTime: BigInt!
251+
"""
252+
Round the contribution is for.
253+
"""
254+
round: Round!
255+
"""
256+
Contribution's ID, keccak256(roundID, contributor).
257+
"""
258+
id: ID!
259+
"""
260+
Address of the contributor.
261+
"""
262+
contributor: Bytes!
263+
"""
264+
Contributions for each side.
265+
"""
266+
values: [BigInt!]!
6267
}

subgraph/src/mapping.ts

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,44 @@
1-
import { BigInt } from "@graphprotocol/graph-ts";
2-
import { ListSubmitted } from "../generated/Governor/Governor";
3-
import { Contract } from "../generated/schema";
1+
import { ByteArray } from "@graphprotocol/graph-ts";
42

5-
export function listSubmitted(event: ListSubmitted): void {
6-
let ID = new BigInt(0);
7-
let contract = new Contract(ID.toString());
3+
import { Governor, SetMetaEvidenceCall } from "../generated/Governor/Governor";
4+
import { Contract, MetaEvidence } from "../generated/schema";
5+
6+
function getStatus(status: number): string {
7+
if (status == 0) return "NoDispute";
8+
if (status == 1) return "DisputeCreated";
9+
if (status == 2) return "Resolved";
10+
return "Error";
11+
}
12+
13+
function concatByteArrays(a: ByteArray, b: ByteArray): ByteArray {
14+
let out = new Uint8Array(a.length + b.length);
15+
for (let i = 0; i < a.length; i++) out[i] = a[i];
16+
for (let j = 0; j < b.length; j++) out[a.length + j] = b[j];
17+
return out as ByteArray;
18+
}
19+
20+
export function setMetaEvidence(call: SetMetaEvidenceCall): void {
21+
let governor = Governor.bind(call.to);
22+
23+
let contract = new Contract("0");
24+
contract.deployer = call.from;
25+
contract.reservedETH = governor.reservedETH();
26+
contract.submissionBaseDeposit = governor.submissionBaseDeposit();
27+
contract.submissionTimeout = governor.submissionTimeout();
28+
contract.executionTimeout = governor.executionTimeout();
29+
contract.withdrawTimeout = governor.withdrawTimeout();
30+
contract.sharedMultiplier = governor.sharedMultiplier();
31+
contract.winnerMultiplier = governor.winnerMultiplier();
32+
contract.loserMultiplier = governor.loserMultiplier();
33+
contract.lastApprovalTime = governor.lastApprovalTime();
34+
contract.metaEvidenceUpdates = governor.metaEvidenceUpdates();
35+
36+
let metaEvidence = new MetaEvidence(
37+
contract.metaEvidenceUpdates.toHexString()
38+
);
39+
metaEvidence.URI = call.inputs._metaEvidence;
40+
metaEvidence.save();
41+
42+
contract.metaEvidence = metaEvidence.id;
843
contract.save();
944
}

subgraph/subgraph.template.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ dataSources:
1818
abis:
1919
- name: Governor
2020
file: ./abis/governor.json
21-
eventHandlers:
22-
- event: ListSubmitted(indexed uint256,indexed address,indexed uint256,string)
23-
handler: listSubmitted
21+
callHandlers:
22+
- function: setMetaEvidence(string)
23+
handler: setMetaEvidence
2424
file: ./src/mapping.ts

0 commit comments

Comments
 (0)