Skip to content

Commit fe34418

Browse files
committed
feat: add stakeset entity and handler
1 parent ba621a8 commit fe34418

File tree

5 files changed

+30
-2
lines changed

5 files changed

+30
-2
lines changed

subgraph/core-neo/subgraph.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ dataSources:
149149
language: wasm/assemblyscript
150150
entities:
151151
- JurorTokensPerCourt
152+
- StakeSet
152153
abis:
153154
- name: SortitionModule
154155
file: ../../contracts/deployments/arbitrum/SortitionModuleNeo.json

subgraph/core-university/subgraph.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ dataSources:
149149
language: wasm/assemblyscript
150150
entities:
151151
- JurorTokensPerCourt
152+
- StakeSet
152153
abis:
153154
- name: SortitionModule
154155
file: ../../contracts/deployments/arbitrumSepoliaDevnet/SortitionModuleUniversity.json

subgraph/core/schema.graphql

+11
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,17 @@ type ClassicContribution implements Contribution @entity {
354354
rewardWithdrawn: Boolean!
355355
}
356356

357+
type StakeSet @entity {
358+
id: ID! # event.transaction.hash.toHex() + - + event.logIndex.toString()
359+
address: Bytes!
360+
courtID: BigInt!
361+
stake: BigInt!
362+
newTotalStake: BigInt!
363+
blocknumber: BigInt!
364+
timestamp: BigInt!
365+
logIndex: BigInt!
366+
}
367+
357368
type _Schema_
358369
@fulltext(
359370
name: "evidenceSearch"

subgraph/core/src/SortitionModule.ts

+16-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import {
44
StakeDelayedAlreadyTransferredWithdrawn,
55
StakeDelayedNotTransferred,
66
StakeLocked,
7-
StakeSet,
7+
StakeSet as StakeSetEvent,
88
} from "../generated/SortitionModule/SortitionModule";
9+
import { Court, StakeSet as StakeSetEntity } from "../generated/schema";
910

1011
import { updateJurorDelayedStake, updateJurorStake } from "./entities/JurorTokensPerCourt";
1112
import { ensureUser } from "./entities/User";
@@ -23,13 +24,26 @@ export function handleStakeDelayedNotTransferred(event: StakeDelayedNotTransferr
2324
updateJurorDelayedStake(event.params._address.toHexString(), event.params._courtID.toString(), event.params._amount);
2425
}
2526

26-
export function handleStakeSet(event: StakeSet): void {
27+
export function handleStakeSet(event: StakeSetEvent): void {
2728
const jurorAddress = event.params._address.toHexString();
2829
ensureUser(jurorAddress);
2930
const courtID = event.params._courtID.toString();
3031

3132
updateJurorStake(jurorAddress, courtID.toString(), SortitionModule.bind(event.address), event.block.timestamp);
3233
//stake is updated instantly so no delayed amount, set delay amount to zero
3334
updateJurorDelayedStake(jurorAddress, courtID, ZERO);
35+
36+
const generalCourt = Court.load("1");
37+
if (!generalCourt) return;
38+
const stakeSet = new StakeSetEntity(event.transaction.hash.toHex() + "-" + event.logIndex.toString());
39+
stakeSet.address = event.params._address;
40+
stakeSet.courtID = event.params._courtID;
41+
stakeSet.stake = event.params._amount;
42+
stakeSet.newTotalStake = generalCourt.effectiveStake;
43+
stakeSet.blocknumber = event.block.number;
44+
stakeSet.timestamp = event.block.timestamp;
45+
stakeSet.logIndex = event.logIndex;
46+
stakeSet.save();
3447
}
48+
3549
export function handleStakeLocked(event: StakeLocked): void {}

subgraph/core/subgraph.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ dataSources:
149149
language: wasm/assemblyscript
150150
entities:
151151
- JurorTokensPerCourt
152+
- StakeSet
152153
abis:
153154
- name: SortitionModule
154155
file: ../../contracts/deployments/arbitrumSepoliaDevnet/SortitionModule.json

0 commit comments

Comments
 (0)