diff --git a/subgraph/core-neo/subgraph.yaml b/subgraph/core-neo/subgraph.yaml index 37feb1f7d..252098b54 100644 --- a/subgraph/core-neo/subgraph.yaml +++ b/subgraph/core-neo/subgraph.yaml @@ -149,6 +149,7 @@ dataSources: language: wasm/assemblyscript entities: - JurorTokensPerCourt + - StakeSet abis: - name: SortitionModule file: ../../contracts/deployments/arbitrum/SortitionModuleNeo.json diff --git a/subgraph/core-university/src/SortitionModule.ts b/subgraph/core-university/src/SortitionModule.ts index e71103482..aae779fcb 100644 --- a/subgraph/core-university/src/SortitionModule.ts +++ b/subgraph/core-university/src/SortitionModule.ts @@ -1,18 +1,30 @@ -import { SortitionModule, StakeLocked, StakeSet } from "../generated/SortitionModule/SortitionModule"; +import { SortitionModule, StakeLocked, StakeSet as StakeSetEvent } from "../generated/SortitionModule/SortitionModule"; +import { StakeSet as StakeSetEntity } from "../generated/schema"; import { updateJurorDelayedStake, updateJurorStake } from "./entities/JurorTokensPerCourt"; import { ensureUser } from "./entities/User"; import { ZERO } from "./utils"; -export function handleStakeSet(event: StakeSet): void { +export function handleStakeSet(event: StakeSetEvent): void { const jurorAddress = event.params._address.toHexString(); - ensureUser(jurorAddress); const courtID = event.params._courtID.toString(); updateJurorStake(jurorAddress, courtID.toString(), SortitionModule.bind(event.address), event.block.timestamp); //stake is updated instantly so no delayed amount, set delay amount to zero updateJurorDelayedStake(jurorAddress, courtID, ZERO); + + const stakeSet = new StakeSetEntity(event.transaction.hash.toHex() + "-" + event.logIndex.toString()); + const juror = ensureUser(jurorAddress); + stakeSet.juror = juror.id; + stakeSet.courtID = event.params._courtID; + stakeSet.stake = event.params._amount; + stakeSet.newTotalStake = juror.totalStake; + stakeSet.blocknumber = event.block.number; + stakeSet.timestamp = event.block.timestamp; + stakeSet.logIndex = event.logIndex; + stakeSet.save(); } + export function handleStakeLocked(event: StakeLocked): void { // NOP } diff --git a/subgraph/core-university/subgraph.yaml b/subgraph/core-university/subgraph.yaml index 7c95a47e2..7adcb8249 100644 --- a/subgraph/core-university/subgraph.yaml +++ b/subgraph/core-university/subgraph.yaml @@ -149,6 +149,7 @@ dataSources: language: wasm/assemblyscript entities: - JurorTokensPerCourt + - StakeSet abis: - name: SortitionModule file: ../../contracts/deployments/arbitrumSepoliaDevnet/SortitionModuleUniversity.json diff --git a/subgraph/core/schema.graphql b/subgraph/core/schema.graphql index 956d102af..59fbd76de 100644 --- a/subgraph/core/schema.graphql +++ b/subgraph/core/schema.graphql @@ -354,6 +354,17 @@ type ClassicContribution implements Contribution @entity { rewardWithdrawn: Boolean! } +type StakeSet @entity(immutable: true) { + id: ID! # event.transaction.hash.toHex() + - + event.logIndex.toString() + juror: User! + courtID: BigInt! + stake: BigInt! + newTotalStake: BigInt! + blocknumber: BigInt! + timestamp: BigInt! + logIndex: BigInt! +} + type _Schema_ @fulltext( name: "evidenceSearch" diff --git a/subgraph/core/src/SortitionModule.ts b/subgraph/core/src/SortitionModule.ts index 1625b6686..5fcb150ff 100644 --- a/subgraph/core/src/SortitionModule.ts +++ b/subgraph/core/src/SortitionModule.ts @@ -4,8 +4,9 @@ import { StakeDelayedAlreadyTransferredWithdrawn, StakeDelayedNotTransferred, StakeLocked, - StakeSet, + StakeSet as StakeSetEvent, } from "../generated/SortitionModule/SortitionModule"; +import { StakeSet as StakeSetEntity } from "../generated/schema"; import { updateJurorDelayedStake, updateJurorStake } from "./entities/JurorTokensPerCourt"; import { ensureUser } from "./entities/User"; @@ -23,13 +24,24 @@ export function handleStakeDelayedNotTransferred(event: StakeDelayedNotTransferr updateJurorDelayedStake(event.params._address.toHexString(), event.params._courtID.toString(), event.params._amount); } -export function handleStakeSet(event: StakeSet): void { +export function handleStakeSet(event: StakeSetEvent): void { const jurorAddress = event.params._address.toHexString(); - ensureUser(jurorAddress); const courtID = event.params._courtID.toString(); updateJurorStake(jurorAddress, courtID.toString(), SortitionModule.bind(event.address), event.block.timestamp); //stake is updated instantly so no delayed amount, set delay amount to zero updateJurorDelayedStake(jurorAddress, courtID, ZERO); + + const stakeSet = new StakeSetEntity(event.transaction.hash.toHex() + "-" + event.logIndex.toString()); + const juror = ensureUser(jurorAddress); + stakeSet.juror = juror.id; + stakeSet.courtID = event.params._courtID; + stakeSet.stake = event.params._amount; + stakeSet.newTotalStake = juror.totalStake; + stakeSet.blocknumber = event.block.number; + stakeSet.timestamp = event.block.timestamp; + stakeSet.logIndex = event.logIndex; + stakeSet.save(); } + export function handleStakeLocked(event: StakeLocked): void {} diff --git a/subgraph/core/subgraph.yaml b/subgraph/core/subgraph.yaml index ba08525c9..74ff659e8 100644 --- a/subgraph/core/subgraph.yaml +++ b/subgraph/core/subgraph.yaml @@ -149,6 +149,7 @@ dataSources: language: wasm/assemblyscript entities: - JurorTokensPerCourt + - StakeSet abis: - name: SortitionModule file: ../../contracts/deployments/arbitrumSepoliaDevnet/SortitionModule.json diff --git a/subgraph/package.json b/subgraph/package.json index 638be7422..fcacbb475 100644 --- a/subgraph/package.json +++ b/subgraph/package.json @@ -1,6 +1,6 @@ { "name": "@kleros/kleros-v2-subgraph", - "version": "0.11.0", + "version": "0.12.0", "drtVersion": "0.11.0", "license": "MIT", "scripts": {