Skip to content

Commit 95965a0

Browse files
authored
Merge pull request #1699 from kleros/feat/add-stats-court-page
feat: add four new stat variables, stake simulator
2 parents 6e71e9d + 4ceb55a commit 95965a0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+932
-237
lines changed

subgraph/core/schema.graphql

+1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ type JurorTokensPerCourt @entity {
120120
id: ID! # user.id-court.id
121121
juror: User!
122122
court: Court!
123+
effectiveStake: BigInt!
123124
staked: BigInt!
124125
locked: BigInt!
125126
delayed: BigInt!

subgraph/core/src/entities/JurorTokensPerCourt.ts

+33
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export function createJurorTokensPerCourt(jurorAddress: string, courtID: string)
2323
const jurorTokens = new JurorTokensPerCourt(id);
2424
jurorTokens.juror = jurorAddress;
2525
jurorTokens.court = courtID;
26+
jurorTokens.effectiveStake = ZERO;
2627
jurorTokens.staked = ZERO;
2728
jurorTokens.locked = ZERO;
2829
jurorTokens.delayed = ZERO;
@@ -31,6 +32,37 @@ export function createJurorTokensPerCourt(jurorAddress: string, courtID: string)
3132
return jurorTokens;
3233
}
3334

35+
export function updateJurorEffectiveStake(jurorAddress: string, courtID: string): void {
36+
let court = Court.load(courtID);
37+
if (!court) {
38+
return;
39+
}
40+
41+
while (court) {
42+
const jurorTokensPerCourt = ensureJurorTokensPerCourt(jurorAddress, court.id);
43+
let totalStake = jurorTokensPerCourt.staked;
44+
const childrenCourts = court.children.load();
45+
46+
for (let i = 0; i < childrenCourts.length; i++) {
47+
const childCourtID = childrenCourts[i].id;
48+
const childCourt = Court.load(childCourtID);
49+
if (childCourt) {
50+
const childJurorTokensPerCourt = ensureJurorTokensPerCourt(jurorAddress, childCourt.id);
51+
totalStake = totalStake.plus(childJurorTokensPerCourt.effectiveStake);
52+
}
53+
}
54+
55+
jurorTokensPerCourt.effectiveStake = totalStake;
56+
jurorTokensPerCourt.save();
57+
58+
if (court.parent && court.parent !== null) {
59+
court = Court.load(court.parent as string);
60+
} else {
61+
break;
62+
}
63+
}
64+
}
65+
3466
export function updateJurorStake(
3567
jurorAddress: string,
3668
courtID: string,
@@ -61,6 +93,7 @@ export function updateJurorStake(
6193
juror.save();
6294
court.save();
6395
updateEffectiveStake(courtID);
96+
updateJurorEffectiveStake(jurorAddress, courtID);
6497
}
6598

6699
export function updateJurorDelayedStake(jurorAddress: string, courtID: string, amount: BigInt): void {

subgraph/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@kleros/kleros-v2-subgraph",
3-
"version": "0.8.6",
3+
"version": "0.8.8",
44
"license": "MIT",
55
"scripts": {
66
"update:core:arbitrum-sepolia-devnet": "./scripts/update.sh arbitrumSepoliaDevnet arbitrum-sepolia core/subgraph.yaml",
+10
Loading

web/src/assets/svgs/icons/chart.svg

+15
Loading

web/src/assets/svgs/icons/clock.svg

+1-1
Loading

web/src/assets/svgs/icons/dice.svg

+27-3
Loading

web/src/assets/svgs/icons/dollar.svg

+10
Loading
+1-1
Loading
Loading

web/src/assets/svgs/icons/law-balance.svg

+1-1
Loading

web/src/assets/svgs/icons/min-stake.svg

+1-1
Loading

0 commit comments

Comments
 (0)