Skip to content

Commit 02941a7

Browse files
committed
Merge branch 'feat(web)/demo-staging' of github.com:kleros/kleros-v2 into feat(web)/demo-staging
2 parents 1a3bbea + c5877c2 commit 02941a7

File tree

16 files changed

+182
-92
lines changed

16 files changed

+182
-92
lines changed

subgraph/schema.graphql

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -156,22 +156,6 @@ type DisputeKit @entity {
156156
courts: [Court!]! @derivedFrom(field: "supportedDisputeKits")
157157
}
158158

159-
type GatewayDispute @entity {
160-
id: ID!
161-
homeDispute: Dispute!
162-
arbitrator: Bytes!
163-
disputeHash: Bytes!
164-
arbitrationCost: BigInt!
165-
relayer: Bytes!
166-
}
167-
168-
type OutgoingBatch @entity {
169-
id: ID! # messageHash
170-
size: BigInt!
171-
epoch: BigInt!
172-
batchMerkleRoot: String!
173-
}
174-
175159
type Counter @entity {
176160
id: ID! # Will be the timestamp except for the counter which will be 0
177161
stakedPNK: BigInt!

subgraph/src/DisputeKitClassic.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { ensureClassicEvidenceGroup } from "./entities/ClassicEvidenceGroup";
2020
import {
2121
createClassicRound,
2222
updateChoiceFundingFromContributionEvent,
23+
updateCounts,
2324
} from "./entities/ClassicRound";
2425
import { createClassicVote } from "./entities/ClassicVote";
2526
import { ONE, ZERO } from "./utils";
@@ -29,7 +30,8 @@ export const DISPUTEKIT_ID = "1";
2930
export function handleDisputeCreation(event: DisputeCreation): void {
3031
const disputeID = event.params._coreDisputeID.toString();
3132
createClassicDisputeFromEvent(event);
32-
createClassicRound(disputeID, ZERO);
33+
const numberOfChoices = event.params._numberOfChoices;
34+
createClassicRound(disputeID, numberOfChoices, ZERO);
3335
}
3436

3537
export function handleEvidenceEvent(event: EvidenceEvent): void {
@@ -52,9 +54,9 @@ export function handleJustificationEvent(event: JustificationEvent): void {
5254
const classicDisputeID = `${DISPUTEKIT_ID}-${coreDisputeID}`;
5355
const classicDispute = ClassicDispute.load(classicDisputeID);
5456
if (!classicDispute) return;
55-
const currentLocalRoundID = `${
56-
classicDispute.id
57-
}-${classicDispute.currentLocalRoundIndex.toString()}`;
57+
const currentLocalRoundID =
58+
classicDispute.id + "-" + classicDispute.currentLocalRoundIndex.toString();
59+
updateCounts(currentLocalRoundID, event.params._choice);
5860
createClassicVote(currentLocalRoundID, event);
5961
}
6062

@@ -88,7 +90,8 @@ export function handleChoiceFunded(event: ChoiceFunded): void {
8890
);
8991
if (!localDispute) return;
9092
const newRoundIndex = localDispute.currentLocalRoundIndex.plus(ONE);
91-
createClassicRound(coreDisputeID, newRoundIndex);
93+
const numberOfChoices = localDispute.numberOfChoices;
94+
createClassicRound(coreDisputeID, numberOfChoices, newRoundIndex);
9295
}
9396

9497
localRound.save();

subgraph/src/KlerosCore.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
updateRedistributedPNK,
2727
getDelta,
2828
} from "./datapoint";
29-
import { ensureUser } from "./entities/Juror";
29+
import { ensureUser } from "./entities/User";
3030
import {
3131
ensureJurorTokensPerCourt,
3232
updateJurorStake,
@@ -169,6 +169,6 @@ export function handleTokenAndETHShift(event: TokenAndETHShiftEvent): void {
169169
event.block.timestamp
170170
);
171171
court.paidETH = court.paidETH.plus(ethAmount);
172-
court.paidPNK = court.paidETH.plus(tokenAmount);
172+
court.paidPNK = court.paidPNK.plus(tokenAmount);
173173
court.save();
174174
}

subgraph/src/datapoint.ts

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,34 @@ function updateDataPoint(
2020
timestamp: BigInt,
2121
variable: string
2222
): void {
23-
let counter = store.get("Counter", "0");
24-
if (!counter) {
25-
counter = new Entity();
26-
for (let i = 0; i < VARIABLES.length; i++) {
27-
counter.set(VARIABLES[i], Value.fromBigInt(ZERO));
28-
}
23+
const newCounter = new Entity();
24+
const counter = store.get("Counter", "0");
25+
for (let i = 0; i < VARIABLES.length; i++) {
26+
const currentVar = VARIABLES[i];
27+
newCounter.set(
28+
currentVar,
29+
getNewValue(currentVar, variable, delta, counter)
30+
);
2931
}
3032
const dayID = timestamp.toI32() / 86400;
3133
const dayStartTimestamp = dayID * 86400;
32-
const newValue = counter.get(variable)!.toBigInt().plus(delta);
33-
counter.set(variable, Value.fromBigInt(newValue));
34-
store.set("Counter", dayStartTimestamp.toString(), counter);
35-
store.set("Counter", "0", counter);
34+
store.set("Counter", dayStartTimestamp.toString(), newCounter);
35+
store.set("Counter", "0", newCounter);
36+
}
37+
38+
function getNewValue(
39+
currentVar: string,
40+
targetVar: string,
41+
delta: BigInt,
42+
counter: Entity | null
43+
): Value {
44+
if (currentVar === targetVar) {
45+
return !counter
46+
? Value.fromBigInt(delta)
47+
: Value.fromBigInt(counter.get(currentVar)!.toBigInt().plus(delta));
48+
} else {
49+
return !counter ? Value.fromBigInt(ZERO) : counter.get(currentVar)!;
50+
}
3651
}
3752

3853
export function updateStakedPNK(delta: BigInt, timestamp: BigInt): void {

subgraph/src/entities/ClassicRound.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,50 @@
11
import { BigInt } from "@graphprotocol/graph-ts";
22
import { Contribution } from "../../generated/DisputeKitClassic/DisputeKitClassic";
33
import { ClassicRound } from "../../generated/schema";
4-
import { ZERO } from "../utils";
4+
import { ONE, ZERO } from "../utils";
55

66
export function createClassicRound(
77
disputeID: string,
8+
numberOfChoices: BigInt,
89
roundIndex: BigInt
910
): void {
11+
const choicesLength = numberOfChoices.plus(ONE);
1012
const localDisputeID = `1-${disputeID}`;
1113
const id = `${localDisputeID}-${roundIndex.toString()}`;
1214
const classicRound = new ClassicRound(id);
1315
classicRound.localDispute = localDisputeID;
1416
classicRound.votes = [];
1517
classicRound.winningChoice = ZERO;
16-
classicRound.counts = [];
18+
classicRound.counts = new Array<BigInt>(choicesLength.toI32()).fill(ZERO);
1719
classicRound.tied = true;
1820
classicRound.totalVoted = ZERO;
1921
classicRound.totalCommited = ZERO;
20-
classicRound.paidFees = [];
22+
classicRound.paidFees = new Array<BigInt>(choicesLength.toI32()).fill(ZERO);
2123
classicRound.feeRewards = ZERO;
2224
classicRound.fundedChoices = [];
2325
classicRound.save();
2426
}
2527

28+
export function updateCounts(id: string, choice: BigInt): void {
29+
const round = ClassicRound.load(id);
30+
if (!round) return;
31+
const choiceNum = choice.toI32();
32+
const updatedCount = round.counts[choiceNum].plus(ONE);
33+
round.counts[choiceNum] = updatedCount;
34+
const currentWinningCount = round.counts[round.winningChoice.toI32()];
35+
if (choice.equals(round.winningChoice)) {
36+
if (round.tied) round.tied = false;
37+
} else {
38+
if (updatedCount.equals(currentWinningCount)) {
39+
if (!round.tied) round.tied = true;
40+
} else if (updatedCount.gt(currentWinningCount)) {
41+
round.winningChoice = choice;
42+
round.tied = false;
43+
}
44+
}
45+
round.save();
46+
}
47+
2648
export function updateChoiceFundingFromContributionEvent(
2749
event: Contribution
2850
): void {

subgraph/src/entities/JurorTokensPerCourt.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { BigInt, Address } from "@graphprotocol/graph-ts";
22
import { KlerosCore } from "../../generated/KlerosCore/KlerosCore";
33
import { Court, JurorTokensPerCourt } from "../../generated/schema";
44
import { updateActiveJurors, getDelta } from "../datapoint";
5-
import { ensureUser } from "./Juror";
5+
import { ensureUser } from "./User";
66
import { ZERO } from "../utils";
77

88
export function ensureJurorTokensPerCourt(
@@ -61,7 +61,7 @@ export function updateJurorStake(
6161
jurorTokens.staked = jurorBalance.value0;
6262
jurorTokens.locked = jurorBalance.value1;
6363
jurorTokens.save();
64-
const stakeDelta = getDelta(jurorTokens.staked, previousStake);
64+
const stakeDelta = getDelta(previousStake, jurorTokens.staked);
6565
juror.totalStake = juror.totalStake.plus(stakeDelta);
6666
court.stake = court.stake.plus(stakeDelta);
6767
let activeJurorsDelta: BigInt;

subgraph/src/entities/Juror.ts renamed to subgraph/src/entities/User.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { User } from "../../generated/schema";
2+
import { ZERO } from "../utils";
23

34
export function ensureUser(id: string): User {
4-
let user = User.load(id);
5+
const user = User.load(id);
56

67
if (user) {
78
return user;
@@ -12,6 +13,7 @@ export function ensureUser(id: string): User {
1213

1314
export function createUserFromAddress(id: string): User {
1415
const user = new User(id);
16+
user.totalStake = ZERO;
1517
user.save();
1618

1719
return user;

subgraph/subgraph.yaml

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,16 @@ dataSources:
1414
apiVersion: 0.0.6
1515
language: wasm/assemblyscript
1616
entities:
17-
- Court
18-
- Juror
17+
- User
18+
- Arbitrable
1919
- TokenAndETHShift
2020
- JurorTokensPerCourt
21+
- Court
22+
- Dispute
2123
- Round
2224
- Draw
23-
- Dispute
2425
- DisputeKit
25-
- PNKStakedDataPoint
26-
- ETHPaidDataPoint
27-
- PNKRedistributedDataPoint
28-
- ActiveJurorsDataPoint
29-
- CasesDataPoint
26+
- Counter
3027
abis:
3128
- name: KlerosCore
3229
file: ../contracts/deployments/arbitrumGoerli/KlerosCore.json
@@ -84,8 +81,12 @@ dataSources:
8481
apiVersion: 0.0.6
8582
language: wasm/assemblyscript
8683
entities:
87-
- EvidenceGroup
88-
- Evidence
84+
- ClassicDispute
85+
- ClassicRound
86+
- ClassicVote
87+
- ClassicEvidenceGroup
88+
- ClassicEvidence
89+
- ClassicContribution
8990
abis:
9091
- name: DisputeKitClassic
9192
file: ../contracts/deployments/arbitrumGoerli/DisputeKitClassic.json
@@ -94,8 +95,8 @@ dataSources:
9495
handler: handleDisputeCreation
9596
- event: Contribution(indexed uint256,indexed uint256,uint256,indexed address,uint256)
9697
handler: handleContributionEvent
97-
# - event: Withdrawal(indexed uint256,indexed uint256,uint256,indexed address,uint256)
98-
# handler: handleWithdrawal
98+
- event: Withdrawal(indexed uint256,indexed uint256,uint256,indexed address,uint256)
99+
handler: handleWithdrawal
99100
- event: ChoiceFunded(indexed uint256,indexed uint256,indexed uint256)
100101
handler: handleChoiceFunded
101102
- event: Evidence(indexed address,indexed uint256,indexed address,string)

web/src/consts/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { BigNumber } from "ethers";
2+
3+
export const ONE_BASIS_POINT = BigNumber.from("1000");

web/src/graphql/generated.ts

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ export type ClassicRound = DisputeKitRound & {
430430
tied: Scalars["Boolean"];
431431
totalCommited: Scalars["BigInt"];
432432
totalVoted: Scalars["BigInt"];
433-
votes: Array<ClassicVote>;
433+
votes: Array<Vote>;
434434
winningChoice: Scalars["BigInt"];
435435
};
436436

@@ -444,10 +444,10 @@ export type ClassicRoundContributionsArgs = {
444444

445445
export type ClassicRoundVotesArgs = {
446446
first?: InputMaybe<Scalars["Int"]>;
447-
orderBy?: InputMaybe<ClassicVote_OrderBy>;
447+
orderBy?: InputMaybe<Vote_OrderBy>;
448448
orderDirection?: InputMaybe<OrderDirection>;
449449
skip?: InputMaybe<Scalars["Int"]>;
450-
where?: InputMaybe<ClassicVote_Filter>;
450+
where?: InputMaybe<Vote_Filter>;
451451
};
452452

453453
export type ClassicRound_Filter = {
@@ -529,13 +529,7 @@ export type ClassicRound_Filter = {
529529
totalVoted_lte?: InputMaybe<Scalars["BigInt"]>;
530530
totalVoted_not?: InputMaybe<Scalars["BigInt"]>;
531531
totalVoted_not_in?: InputMaybe<Array<Scalars["BigInt"]>>;
532-
votes?: InputMaybe<Array<Scalars["String"]>>;
533-
votes_?: InputMaybe<ClassicVote_Filter>;
534-
votes_contains?: InputMaybe<Array<Scalars["String"]>>;
535-
votes_contains_nocase?: InputMaybe<Array<Scalars["String"]>>;
536-
votes_not?: InputMaybe<Array<Scalars["String"]>>;
537-
votes_not_contains?: InputMaybe<Array<Scalars["String"]>>;
538-
votes_not_contains_nocase?: InputMaybe<Array<Scalars["String"]>>;
532+
votes_?: InputMaybe<Vote_Filter>;
539533
winningChoice?: InputMaybe<Scalars["BigInt"]>;
540534
winningChoice_gt?: InputMaybe<Scalars["BigInt"]>;
541535
winningChoice_gte?: InputMaybe<Scalars["BigInt"]>;
@@ -1223,6 +1217,15 @@ export enum DisputeKitDispute_OrderBy {
12231217
export type DisputeKitRound = {
12241218
id: Scalars["ID"];
12251219
localDispute: DisputeKitDispute;
1220+
votes: Array<Vote>;
1221+
};
1222+
1223+
export type DisputeKitRoundVotesArgs = {
1224+
first?: InputMaybe<Scalars["Int"]>;
1225+
orderBy?: InputMaybe<Vote_OrderBy>;
1226+
orderDirection?: InputMaybe<OrderDirection>;
1227+
skip?: InputMaybe<Scalars["Int"]>;
1228+
where?: InputMaybe<Vote_Filter>;
12261229
};
12271230

12281231
export type DisputeKitRound_Filter = {
@@ -1257,11 +1260,13 @@ export type DisputeKitRound_Filter = {
12571260
localDispute_not_starts_with_nocase?: InputMaybe<Scalars["String"]>;
12581261
localDispute_starts_with?: InputMaybe<Scalars["String"]>;
12591262
localDispute_starts_with_nocase?: InputMaybe<Scalars["String"]>;
1263+
votes_?: InputMaybe<Vote_Filter>;
12601264
};
12611265

12621266
export enum DisputeKitRound_OrderBy {
12631267
Id = "id",
12641268
LocalDispute = "localDispute",
1269+
Votes = "votes",
12651270
}
12661271

12671272
export type DisputeKit_Filter = {
@@ -3136,6 +3141,11 @@ export type CourtTreeQuery = {
31363141
__typename?: "Court";
31373142
name?: string | null;
31383143
id: string;
3144+
children: Array<{
3145+
__typename?: "Court";
3146+
name?: string | null;
3147+
id: string;
3148+
}>;
31393149
}>;
31403150
}>;
31413151
}>;
@@ -3215,6 +3225,7 @@ export type VotingHistoryQuery = {
32153225
__typename?: "Query";
32163226
dispute?: {
32173227
__typename?: "Dispute";
3228+
id: string;
32183229
rounds: Array<{ __typename?: "Round"; nbVotes: any }>;
32193230
disputeKitDispute?: {
32203231
__typename?: "ClassicDispute";
@@ -3223,9 +3234,9 @@ export type VotingHistoryQuery = {
32233234
totalVoted: any;
32243235
votes: Array<{
32253236
__typename?: "ClassicVote";
3226-
id: string;
32273237
choice: any;
32283238
justification: string;
3239+
id: string;
32293240
juror: { __typename?: "User"; id: string };
32303241
}>;
32313242
}>;

web/src/hooks/queries/useVotingHistory.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export type { VotingHistoryQuery };
66
const votingHistoryQuery = gql`
77
query VotingHistory($disputeID: ID!) {
88
dispute(id: $disputeID) {
9+
id
910
rounds {
1011
nbVotes
1112
}
@@ -15,11 +16,13 @@ const votingHistoryQuery = gql`
1516
totalVoted
1617
votes {
1718
id
18-
choice
19-
justification
2019
juror {
2120
id
2221
}
22+
... on ClassicVote {
23+
choice
24+
justification
25+
}
2326
}
2427
}
2528
}

0 commit comments

Comments
 (0)