Skip to content

Commit

Permalink
Merge pull request #1699 from kleros/feat/add-stats-court-page
Browse files Browse the repository at this point in the history
feat: add four new stat variables, stake simulator
  • Loading branch information
jaybuidl authored Oct 30, 2024
2 parents 6e71e9d + 4ceb55a commit 95965a0
Show file tree
Hide file tree
Showing 41 changed files with 932 additions and 237 deletions.
1 change: 1 addition & 0 deletions subgraph/core/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ type JurorTokensPerCourt @entity {
id: ID! # user.id-court.id
juror: User!
court: Court!
effectiveStake: BigInt!
staked: BigInt!
locked: BigInt!
delayed: BigInt!
Expand Down
33 changes: 33 additions & 0 deletions subgraph/core/src/entities/JurorTokensPerCourt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export function createJurorTokensPerCourt(jurorAddress: string, courtID: string)
const jurorTokens = new JurorTokensPerCourt(id);
jurorTokens.juror = jurorAddress;
jurorTokens.court = courtID;
jurorTokens.effectiveStake = ZERO;
jurorTokens.staked = ZERO;
jurorTokens.locked = ZERO;
jurorTokens.delayed = ZERO;
Expand All @@ -31,6 +32,37 @@ export function createJurorTokensPerCourt(jurorAddress: string, courtID: string)
return jurorTokens;
}

export function updateJurorEffectiveStake(jurorAddress: string, courtID: string): void {
let court = Court.load(courtID);
if (!court) {
return;
}

while (court) {
const jurorTokensPerCourt = ensureJurorTokensPerCourt(jurorAddress, court.id);
let totalStake = jurorTokensPerCourt.staked;
const childrenCourts = court.children.load();

for (let i = 0; i < childrenCourts.length; i++) {
const childCourtID = childrenCourts[i].id;
const childCourt = Court.load(childCourtID);
if (childCourt) {
const childJurorTokensPerCourt = ensureJurorTokensPerCourt(jurorAddress, childCourt.id);
totalStake = totalStake.plus(childJurorTokensPerCourt.effectiveStake);
}
}

jurorTokensPerCourt.effectiveStake = totalStake;
jurorTokensPerCourt.save();

if (court.parent && court.parent !== null) {
court = Court.load(court.parent as string);
} else {
break;
}
}
}

export function updateJurorStake(
jurorAddress: string,
courtID: string,
Expand Down Expand Up @@ -61,6 +93,7 @@ export function updateJurorStake(
juror.save();
court.save();
updateEffectiveStake(courtID);
updateJurorEffectiveStake(jurorAddress, courtID);
}

export function updateJurorDelayedStake(jurorAddress: string, courtID: string, amount: BigInt): void {
Expand Down
2 changes: 1 addition & 1 deletion subgraph/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kleros/kleros-v2-subgraph",
"version": "0.8.6",
"version": "0.8.8",
"license": "MIT",
"scripts": {
"update:core:arbitrum-sepolia-devnet": "./scripts/update.sh arbitrumSepoliaDevnet arbitrum-sepolia core/subgraph.yaml",
Expand Down
10 changes: 10 additions & 0 deletions web/src/assets/svgs/icons/arrow-right.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions web/src/assets/svgs/icons/chart.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion web/src/assets/svgs/icons/clock.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 27 additions & 3 deletions web/src/assets/svgs/icons/dice.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions web/src/assets/svgs/icons/dollar.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion web/src/assets/svgs/icons/ethereum.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions web/src/assets/svgs/icons/law-balance-with-pnk.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion web/src/assets/svgs/icons/law-balance.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion web/src/assets/svgs/icons/min-stake.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 95965a0

Please sign in to comment.