Skip to content

Commit f16a0e2

Browse files
committedFeb 22, 2025··
fix: newtotalstake is juror specific
1 parent 2277793 commit f16a0e2

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,32 @@
1-
import { SortitionModule, StakeLocked, StakeSet } from "../generated/SortitionModule/SortitionModule";
1+
import { SortitionModule, StakeLocked, StakeSet as StakeSetEvent } from "../generated/SortitionModule/SortitionModule";
2+
import { StakeSet as StakeSetEntity, User } from "../generated/schema";
23

34
import { updateJurorDelayedStake, updateJurorStake } from "./entities/JurorTokensPerCourt";
45
import { ensureUser } from "./entities/User";
56
import { ZERO } from "./utils";
67

7-
export function handleStakeSet(event: StakeSet): void {
8+
export function handleStakeSet(event: StakeSetEvent): void {
89
const jurorAddress = event.params._address.toHexString();
910
ensureUser(jurorAddress);
1011
const courtID = event.params._courtID.toString();
1112

1213
updateJurorStake(jurorAddress, courtID.toString(), SortitionModule.bind(event.address), event.block.timestamp);
1314
//stake is updated instantly so no delayed amount, set delay amount to zero
1415
updateJurorDelayedStake(jurorAddress, courtID, ZERO);
16+
17+
const juror = User.load(jurorAddress);
18+
if (!juror) return;
19+
const stakeSet = new StakeSetEntity(event.transaction.hash.toHex() + "-" + event.logIndex.toString());
20+
stakeSet.address = jurorAddress;
21+
stakeSet.courtID = event.params._courtID;
22+
stakeSet.stake = event.params._amount;
23+
stakeSet.newTotalStake = juror.totalStake;
24+
stakeSet.blocknumber = event.block.number;
25+
stakeSet.timestamp = event.block.timestamp;
26+
stakeSet.logIndex = event.logIndex;
27+
stakeSet.save();
1528
}
29+
1630
export function handleStakeLocked(event: StakeLocked): void {
1731
// NOP
1832
}

‎subgraph/core/schema.graphql

+1-1
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ type ClassicContribution implements Contribution @entity {
356356

357357
type StakeSet @entity {
358358
id: ID! # event.transaction.hash.toHex() + - + event.logIndex.toString()
359-
address: Bytes!
359+
address: String!
360360
courtID: BigInt!
361361
stake: BigInt!
362362
newTotalStake: BigInt!

‎subgraph/core/src/SortitionModule.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
StakeLocked,
77
StakeSet as StakeSetEvent,
88
} from "../generated/SortitionModule/SortitionModule";
9-
import { Court, StakeSet as StakeSetEntity } from "../generated/schema";
9+
import { StakeSet as StakeSetEntity, User } from "../generated/schema";
1010

1111
import { updateJurorDelayedStake, updateJurorStake } from "./entities/JurorTokensPerCourt";
1212
import { ensureUser } from "./entities/User";
@@ -33,13 +33,13 @@ export function handleStakeSet(event: StakeSetEvent): void {
3333
//stake is updated instantly so no delayed amount, set delay amount to zero
3434
updateJurorDelayedStake(jurorAddress, courtID, ZERO);
3535

36-
const generalCourt = Court.load("1");
37-
if (!generalCourt) return;
36+
const juror = User.load(jurorAddress);
37+
if (!juror) return;
3838
const stakeSet = new StakeSetEntity(event.transaction.hash.toHex() + "-" + event.logIndex.toString());
39-
stakeSet.address = event.params._address;
39+
stakeSet.address = jurorAddress;
4040
stakeSet.courtID = event.params._courtID;
4141
stakeSet.stake = event.params._amount;
42-
stakeSet.newTotalStake = generalCourt.effectiveStake;
42+
stakeSet.newTotalStake = juror.totalStake;
4343
stakeSet.blocknumber = event.block.number;
4444
stakeSet.timestamp = event.block.timestamp;
4545
stakeSet.logIndex = event.logIndex;

0 commit comments

Comments
 (0)
Please sign in to comment.