Skip to content

Commit b2c609f

Browse files
committed
refactor(subgraph): simplify KlerosCore mappings
1 parent 11f3cd9 commit b2c609f

File tree

13 files changed

+508
-286
lines changed

13 files changed

+508
-286
lines changed

subgraph/schema.graphql

Lines changed: 79 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,100 @@
11
enum Period {
2-
Evidence
3-
Commit
4-
Vote
5-
Appeal
6-
Execution
2+
evidence
3+
commit
4+
vote
5+
appeal
6+
execution
77
}
88

99
type Court @entity {
1010
id: ID!
11-
policy: String
12-
hiddenVotes: Boolean!
1311
parent: Court
12+
hiddenVotes: Boolean!
1413
children: [Court!]! @derivedFrom(field: "parent")
1514
minStake: BigInt!
1615
alpha: BigInt!
1716
feeForJuror: BigInt!
1817
jurorsForCourtJump: BigInt!
1918
timesPerPeriod: [BigInt!]!
2019
supportedDisputeKits: [DisputeKit!]!
21-
disputes: [Dispute!]! @derivedFrom(field: "courtID")
20+
disputes: [Dispute!]! @derivedFrom(field: "court")
2221
numberDisputes: BigInt!
2322
stakedJurors: [JurorTokensPerCourt!]! @derivedFrom(field: "court")
2423
numberStakedJurors: BigInt!
25-
tokens: [JurorTokensPerCourt!]! @derivedFrom(field: "court")
2624
stake: BigInt!
2725
paidETH: BigInt!
2826
paidPNK: BigInt!
27+
policy: String
28+
}
29+
30+
type Dispute @entity {
31+
id: ID!
32+
court: Court!
33+
arbitrated: Bytes!
34+
period: Period!
35+
ruled: Boolean!
36+
lastPeriodChange: BigInt!
37+
rounds: [Round!]! @derivedFrom(field: "dispute")
38+
currentRound: Round!
39+
currentRoundIndex: BigInt!
40+
shifts: [TokenAndETHShift!]! @derivedFrom(field: "dispute")
41+
disputeKitDispute: DisputeKitDispute @derivedFrom(field: "coreDispute")
42+
}
43+
44+
type Round @entity {
45+
id: ID! # Set to `${dispute.id}-${dispute.rounds.length}`
46+
disputeKit: DisputeKit!
47+
tokensAtStakePerJuror: BigInt!
48+
totalFeesForJurors: BigInt!
49+
nbVotes: BigInt!
50+
repartitions: BigInt!
51+
penalties: BigInt!
52+
drawnJurors: [Draw!]! @derivedFrom(field: "round")
53+
dispute: Dispute!
54+
}
55+
56+
interface DisputeKitRound {
57+
id: ID! # Set to `${disputeKit.id}-{dispute.id}-{dispute.rounds.length}`
58+
}
59+
60+
type ClassicRound implements DisputeKitRound @entity {
61+
id: ID! # Set to `${disputeKit.id}-{dispute.id}-{dispute.rounds.length}`
62+
votes: [ClassicVote!]!
63+
winningChoice: BigInt!
64+
counts: [BigInt!]!
65+
tied: Boolean!
66+
totalVoted: BigInt!
67+
totalCommited: BigInt!
68+
paidFees: [BigInt!]!
69+
contributions: [Contribution!]! @derivedFrom(field: "round")
70+
feeRewards: BigInt!
71+
nbVotes: BigInt!
72+
}
73+
74+
type Contribution @entity {
75+
id: ID! # Set to `${dispute.id}-${round.id}-${contributor}-${choice}`
76+
contributor: Bytes!
77+
amount: BigInt!
78+
choice: BigInt!
79+
round: ClassicRound!
80+
}
81+
82+
type ClassicVote @entity {
83+
id: ID!
84+
}
85+
86+
interface DisputeKitDispute {
87+
id: ID! # Set to ${disputeKit.id}-{disputeKit.disputes.length}
88+
coreDispute: Dispute!
89+
}
90+
91+
type ClassicDispute implements DisputeKitDispute @entity {
92+
id: ID! # Set to ${disputeKit.id}-{disputeKit.disputes.length}
93+
coreDispute: Dispute!
94+
95+
numberOfChoices: BigInt!
96+
jumped: Boolean!
97+
extraData: Bytes!
2998
}
3099

31100
type Juror @entity {
@@ -66,21 +135,6 @@ type Evidence @entity {
66135
sender: Bytes!
67136
}
68137

69-
type Round @entity {
70-
id: ID! # Set to `${dispute.id}-${currentRound}`
71-
dispute: Dispute!
72-
disputeKitID: DisputeKit!
73-
tokensAtStakePerJuror: BigInt!
74-
totalFeesForJurors: BigInt!
75-
nbVotes: BigInt!
76-
totalVoted: BigInt!
77-
repartitions: BigInt!
78-
penalties: BigInt!
79-
drawnJurors: [Draw!]! @derivedFrom(field: "round")
80-
votes: [Vote!]! @derivedFrom(field: "round")
81-
currentDecision: BigInt
82-
}
83-
84138
type Vote @entity {
85139
id: ID! # Set to `${coreDisputeID}-${coreRoundID}-${jurorAddress}`
86140
dispute: Dispute!
@@ -98,29 +152,14 @@ type Draw @entity {
98152
voteID: BigInt!
99153
}
100154

101-
type Dispute @entity {
102-
id: ID!
103-
courtID: Court!
104-
arbitrated: Bytes!
105-
period: Period!
106-
ruled: Boolean!
107-
lastPeriodChange: BigInt!
108-
rounds: [Round!]! @derivedFrom(field: "dispute")
109-
draws: [Draw!]! @derivedFrom(field: "dispute")
110-
votes: [Vote!]! @derivedFrom(field: "dispute")
111-
currentRound: Int!
112-
shifts: [TokenAndETHShift!]! @derivedFrom(field: "dispute")
113-
gatewayDispute: GatewayDispute! @derivedFrom(field: "homeDispute")
114-
}
115-
116155
type DisputeKit @entity {
117156
id: ID!
118157
address: Bytes
119158
parent: DisputeKit
120159
children: [DisputeKit!]! @derivedFrom(field: "parent")
121160
needsFreezing: Boolean!
122161
depthLevel: BigInt!
123-
rounds: [Round!]! @derivedFrom(field: "disputeKitID")
162+
rounds: [Round!]! @derivedFrom(field: "disputeKit")
124163
courts: [Court!]! @derivedFrom(field: "supportedDisputeKits")
125164
}
126165

subgraph/src/DisputeKitClassic.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,6 @@ export function handleJustificationEvent(event: JustificationEvent): void {
3939
);
4040
if (currentRound) {
4141
const contract = DisputeKitClassic.bind(event.address);
42-
currentRound.totalVoted = contract.getRoundInfo(
43-
disputeID,
44-
BigInt.fromI32(dispute.currentRound),
45-
BigInt.fromI32(0)
46-
).value2;
47-
currentRound.currentDecision = contract.currentRuling(disputeID);
48-
currentRound.save();
4942
const juror = event.params._juror.toHexString();
5043
const vote = new Vote(
5144
`${disputeID.toString()}-${currentRoundIndex.toString()}-${juror}`

0 commit comments

Comments
 (0)