Skip to content

Commit f68fb49

Browse files
committed
fix(subgraph): fix-stake-handlers
1 parent 82994c5 commit f68fb49

File tree

3 files changed

+19
-30
lines changed

3 files changed

+19
-30
lines changed

subgraph/core/src/SortitionModule.ts

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,11 @@ import { ensureUser } from "./entities/User";
1212
import { ZERO } from "./utils";
1313

1414
export function handleStakeDelayedAlreadyTransferred(event: StakeDelayedAlreadyTransferred): void {
15-
const jurorAddress = event.params._address.toHexString();
16-
ensureUser(jurorAddress);
17-
const courtID = event.params._courtID.toString();
18-
19-
updateJurorStake(jurorAddress, courtID.toString(), SortitionModule.bind(event.address), event.block.timestamp);
20-
21-
//stake is updated instantly so no delayed amount, set delay amount to zero
22-
updateJurorDelayedStake(jurorAddress, courtID, ZERO);
15+
updateJurorDelayedStake(event.params._address.toHexString(), event.params._courtID.toString(), event.params._amount);
2316
}
2417

2518
export function handleStakeDelayedAlreadyTransferredWithdrawn(event: StakeDelayedAlreadyTransferredWithdrawn): void {
26-
const jurorAddress = event.params._address.toHexString();
27-
ensureUser(jurorAddress);
28-
const courtID = event.params._courtID.toString();
29-
30-
updateJurorStake(jurorAddress, courtID.toString(), SortitionModule.bind(event.address), event.block.timestamp);
31-
32-
updateJurorDelayedStake(jurorAddress, courtID, ZERO);
19+
updateJurorDelayedStake(event.params._address.toHexString(), event.params._courtID.toString(), event.params._amount);
3320
}
3421

3522
export function handleStakeDelayedNotTransferred(event: StakeDelayedNotTransferred): void {

subgraph/core/src/entities/JurorTokensPerCourt.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,21 @@ export function updateJurorStake(
4242
const jurorTokens = ensureJurorTokensPerCourt(jurorAddress, courtID);
4343

4444
// TODO: index the sortition module and handle these events there
45-
// const jurorBalance = contract.getJurorBalance(Address.fromString(jurorAddress), BigInt.fromString(courtID));
46-
// const previousStake = jurorTokens.staked;
47-
// const previousTotalStake = juror.totalStake;
48-
// jurorTokens.staked = jurorBalance.value2;
49-
// jurorTokens.locked = jurorBalance.value1;
50-
// jurorTokens.save();
51-
// const stakeDelta = getDelta(previousStake, jurorTokens.staked);
52-
// const newTotalStake = juror.totalStake.plus(stakeDelta);
53-
// juror.totalStake = newTotalStake;
54-
// court.stake = court.stake.plus(stakeDelta);
55-
// updateStakedPNK(stakeDelta, timestamp);
56-
// const activeJurorsDelta = getActivityDelta(previousTotalStake, newTotalStake);
57-
// const stakedJurorsDelta = getActivityDelta(previousStake, jurorBalance.value2);
58-
// court.numberStakedJurors = court.numberStakedJurors.plus(stakedJurorsDelta);
59-
// updateActiveJurors(activeJurorsDelta, timestamp);
45+
const jurorBalance = contract.getJurorBalance(Address.fromString(jurorAddress), BigInt.fromString(courtID));
46+
const previousStake = jurorTokens.staked;
47+
const previousTotalStake = juror.totalStake;
48+
jurorTokens.staked = jurorBalance.value2;
49+
jurorTokens.locked = jurorBalance.value1;
50+
jurorTokens.save();
51+
const stakeDelta = getDelta(previousStake, jurorTokens.staked);
52+
const newTotalStake = juror.totalStake.plus(stakeDelta);
53+
juror.totalStake = newTotalStake;
54+
court.stake = court.stake.plus(stakeDelta);
55+
updateStakedPNK(stakeDelta, timestamp);
56+
const activeJurorsDelta = getActivityDelta(previousTotalStake, newTotalStake);
57+
const stakedJurorsDelta = getActivityDelta(previousStake, jurorBalance.value2);
58+
court.numberStakedJurors = court.numberStakedJurors.plus(stakedJurorsDelta);
59+
updateActiveJurors(activeJurorsDelta, timestamp);
6060
juror.save();
6161
court.save();
6262
}

subgraph/core/subgraph.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ dataSources:
2525
- DisputeKit
2626
- Counter
2727
abis:
28+
- name: SortitionModule
29+
file: ../../contracts/deployments/arbitrumSepoliaDevnet/SortitionModule.json
2830
- name: DisputeKitClassic
2931
file: ../../contracts/deployments/arbitrumSepoliaDevnet/DisputeKitClassic.json
3032
- name: KlerosCore

0 commit comments

Comments
 (0)