Skip to content

Bug: Withdrawing PNK seems to stake PNK? #1319

Closed
@kemuru

Description

@kemuru

Shown in the video. Another thing to note is that balances are not the same in Courts than in Dashboard/MyCourts. Probably because of different hooks giving different balances. Maybe thats the cause of this issue? in my experience the one I used at Dashboard/MyCourts seems to give accurate user balance results (One thing to note is that the query from Courts is a contract call, while the one on Dashboard/MyCourts is a subgraph query)

2023-11-07.18-12-15.mp4

Update: I unstaked everything from all courts via frontend, balance is 0 on Courts, but balance is still existing on Dashboard/MyCourts

2023-11-08.09-51-51.mp4

In the subgraph, this is the only handler modifying the court.stake field:

export function updateJurorStake(jurorAddress: string, courtID: string, contract: KlerosCore, timestamp: BigInt): void {
  const juror = ensureUser(jurorAddress);
  const court = Court.load(courtID);
  if (!court) return;
  const jurorTokens = ensureJurorTokensPerCourt(jurorAddress, courtID);
  const jurorBalance = contract.getJurorBalance(Address.fromString(jurorAddress), BigInt.fromString(courtID));
  const previousStake = jurorTokens.staked;
  const previousTotalStake = juror.totalStake;
  jurorTokens.staked = jurorBalance.value0;
  jurorTokens.locked = jurorBalance.value1;
  jurorTokens.save();
  const stakeDelta = getDelta(previousStake, jurorTokens.staked);
  const newTotalStake = juror.totalStake.plus(stakeDelta);
  juror.totalStake = newTotalStake;
  court.stake = court.stake.plus(stakeDelta);
  updateStakedPNK(stakeDelta, timestamp);
  const activeJurorsDelta = getActivityDelta(previousTotalStake, newTotalStake);
  const stakedJurorsDelta = getActivityDelta(previousStake, jurorBalance.value0);
  court.numberStakedJurors = court.numberStakedJurors.plus(stakedJurorsDelta);
  updateActiveJurors(activeJurorsDelta, timestamp);
  juror.save();
  court.save();
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions