Skip to content

Commit

Permalink
fix(subgraph): active jurors counting error
Browse files Browse the repository at this point in the history
  • Loading branch information
alcercu committed Mar 6, 2023
1 parent a87edbd commit 6b98c40
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions subgraph/src/entities/JurorTokensPerCourt.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { BigInt, Address } from "@graphprotocol/graph-ts";
import { BigInt, Address, log } from "@graphprotocol/graph-ts";
import { KlerosCore } from "../../generated/KlerosCore/KlerosCore";
import { Court, JurorTokensPerCourt } from "../../generated/schema";
import { updateActiveJurors, getDelta, updateStakedPNK } from "../datapoint";
import { ensureUser } from "./User";
import { ZERO } from "../utils";
import { ONE, ZERO } from "../utils";

export function ensureJurorTokensPerCourt(
jurorAddress: string,
Expand Down Expand Up @@ -62,25 +62,25 @@ export function updateJurorStake(
jurorTokens.locked = jurorBalance.value1;
jurorTokens.save();
const stakeDelta = getDelta(previousStake, jurorTokens.staked);
juror.totalStake = juror.totalStake.plus(stakeDelta);
const newTotalStake = juror.totalStake.plus(stakeDelta);
juror.totalStake = newTotalStake;
court.stake = court.stake.plus(stakeDelta);
updateStakedPNK(stakeDelta, timestamp);
let activeJurorsDelta: BigInt;
let numberStakedJurorsDelta: BigInt;
if (previousTotalStake.equals(ZERO)) {
activeJurorsDelta = BigInt.fromI32(1);
numberStakedJurorsDelta = BigInt.fromI32(1);
} else if (previousStake.equals(ZERO)) {
activeJurorsDelta = ZERO;
numberStakedJurorsDelta = BigInt.fromI32(1);
} else {
activeJurorsDelta = ZERO;
numberStakedJurorsDelta = ZERO;
}
court.numberStakedJurors = court.numberStakedJurors.plus(
numberStakedJurorsDelta
const activeJurorsDelta = getActivityDelta(previousTotalStake, newTotalStake);
const stakedJurorsDelta = getActivityDelta(
previousStake,
jurorBalance.value0
);
court.numberStakedJurors = court.numberStakedJurors.plus(stakedJurorsDelta);
updateActiveJurors(activeJurorsDelta, timestamp);
juror.save();
court.save();
}

function getActivityDelta(previousStake: BigInt, newStake: BigInt): BigInt {
if (previousStake.gt(ZERO)) {
return newStake.gt(ZERO) ? ZERO : BigInt.fromI32(-1);
} else {
return newStake.gt(ZERO) ? ONE : ZERO;
}
}

0 comments on commit 6b98c40

Please sign in to comment.