From e9263a18702fb3d57023ece031bd253d15c21e24 Mon Sep 17 00:00:00 2001 From: kemuru <102478601+kemuru@users.noreply.github.com> Date: Thu, 27 Mar 2025 23:24:37 +0100 Subject: [PATCH 1/3] chore: revert stakeset handling in this subgraph --- subgraph/core-neo/subgraph.yaml | 1 - subgraph/core-university/src/SortitionModule.ts | 17 +++-------------- subgraph/core-university/subgraph.yaml | 1 - subgraph/core/schema.graphql | 11 ----------- subgraph/core/src/SortitionModule.ts | 17 +++-------------- subgraph/core/subgraph.yaml | 1 - subgraph/package.json | 2 +- 7 files changed, 7 insertions(+), 43 deletions(-) diff --git a/subgraph/core-neo/subgraph.yaml b/subgraph/core-neo/subgraph.yaml index 252098b54..37feb1f7d 100644 --- a/subgraph/core-neo/subgraph.yaml +++ b/subgraph/core-neo/subgraph.yaml @@ -149,7 +149,6 @@ 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 aae779fcb..53241f322 100644 --- a/subgraph/core-university/src/SortitionModule.ts +++ b/subgraph/core-university/src/SortitionModule.ts @@ -1,28 +1,17 @@ -import { SortitionModule, StakeLocked, StakeSet as StakeSetEvent } from "../generated/SortitionModule/SortitionModule"; -import { StakeSet as StakeSetEntity } from "../generated/schema"; +import { SortitionModule, StakeLocked, StakeSet } from "../generated/SortitionModule/SortitionModule"; import { updateJurorDelayedStake, updateJurorStake } from "./entities/JurorTokensPerCourt"; import { ensureUser } from "./entities/User"; import { ZERO } from "./utils"; -export function handleStakeSet(event: StakeSetEvent): void { +export function handleStakeSet(event: StakeSet): 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-university/subgraph.yaml b/subgraph/core-university/subgraph.yaml index 7adcb8249..7c95a47e2 100644 --- a/subgraph/core-university/subgraph.yaml +++ b/subgraph/core-university/subgraph.yaml @@ -149,7 +149,6 @@ 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 59fbd76de..956d102af 100644 --- a/subgraph/core/schema.graphql +++ b/subgraph/core/schema.graphql @@ -354,17 +354,6 @@ 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 5fcb150ff..bea10459a 100644 --- a/subgraph/core/src/SortitionModule.ts +++ b/subgraph/core/src/SortitionModule.ts @@ -4,9 +4,8 @@ import { StakeDelayedAlreadyTransferredWithdrawn, StakeDelayedNotTransferred, StakeLocked, - StakeSet as StakeSetEvent, + StakeSet, } from "../generated/SortitionModule/SortitionModule"; -import { StakeSet as StakeSetEntity } from "../generated/schema"; import { updateJurorDelayedStake, updateJurorStake } from "./entities/JurorTokensPerCourt"; import { ensureUser } from "./entities/User"; @@ -24,24 +23,14 @@ export function handleStakeDelayedNotTransferred(event: StakeDelayedNotTransferr updateJurorDelayedStake(event.params._address.toHexString(), event.params._courtID.toString(), event.params._amount); } -export function handleStakeSet(event: StakeSetEvent): void { +export function handleStakeSet(event: StakeSet): 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 74ff659e8..ba08525c9 100644 --- a/subgraph/core/subgraph.yaml +++ b/subgraph/core/subgraph.yaml @@ -149,7 +149,6 @@ 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 fcacbb475..638be7422 100644 --- a/subgraph/package.json +++ b/subgraph/package.json @@ -1,6 +1,6 @@ { "name": "@kleros/kleros-v2-subgraph", - "version": "0.12.0", + "version": "0.11.0", "drtVersion": "0.11.0", "license": "MIT", "scripts": { From c4b2cfee8d99f60cc1f372f68a9c8f600da9e927 Mon Sep 17 00:00:00 2001 From: kemuru <102478601+kemuru@users.noreply.github.com> Date: Thu, 27 Mar 2025 23:41:03 +0100 Subject: [PATCH 2/3] chore: more subgraph changes --- subgraph/core-neo/subgraph.yaml | 2 +- subgraph/core-university/subgraph.yaml | 2 +- subgraph/core/subgraph.yaml | 2 +- subgraph/core/tests/sortition-module-utils.ts | 10 +++++++++- subgraph/core/tests/sortition-module.test.ts | 3 ++- 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/subgraph/core-neo/subgraph.yaml b/subgraph/core-neo/subgraph.yaml index 37feb1f7d..cae476398 100644 --- a/subgraph/core-neo/subgraph.yaml +++ b/subgraph/core-neo/subgraph.yaml @@ -161,6 +161,6 @@ dataSources: handler: handleStakeDelayedNotTransferred - event: StakeLocked(indexed address,uint256,bool) handler: handleStakeLocked - - event: StakeSet(indexed address,uint256,uint256) + - event: StakeSet(indexed address,uint256,uint256,uint256) handler: handleStakeSet file: ./src/SortitionModule.ts diff --git a/subgraph/core-university/subgraph.yaml b/subgraph/core-university/subgraph.yaml index 7c95a47e2..a0398c2f8 100644 --- a/subgraph/core-university/subgraph.yaml +++ b/subgraph/core-university/subgraph.yaml @@ -155,6 +155,6 @@ dataSources: eventHandlers: - event: StakeLocked(indexed address,uint256,bool) handler: handleStakeLocked - - event: StakeSet(indexed address,uint256,uint256) + - event: StakeSet(indexed address,uint256,uint256,uint256) handler: handleStakeSet file: ./src/SortitionModule.ts diff --git a/subgraph/core/subgraph.yaml b/subgraph/core/subgraph.yaml index ba08525c9..f93fe2b1b 100644 --- a/subgraph/core/subgraph.yaml +++ b/subgraph/core/subgraph.yaml @@ -161,6 +161,6 @@ dataSources: handler: handleStakeDelayedNotTransferred - event: StakeLocked(indexed address,uint256,bool) handler: handleStakeLocked - - event: StakeSet(indexed address,uint256,uint256) + - event: StakeSet(indexed address,uint256,uint256,uint256) handler: handleStakeSet file: ./src/SortitionModule.ts diff --git a/subgraph/core/tests/sortition-module-utils.ts b/subgraph/core/tests/sortition-module-utils.ts index 2f999a75d..fad77415f 100644 --- a/subgraph/core/tests/sortition-module-utils.ts +++ b/subgraph/core/tests/sortition-module-utils.ts @@ -88,7 +88,12 @@ export function createStakeLockedEvent(_address: Address, _relativeAmount: BigIn return stakeLockedEvent; } -export function createStakeSetEvent(_address: Address, _courtID: BigInt, _amount: BigInt): StakeSet { +export function createStakeSetEvent( + _address: Address, + _courtID: BigInt, + _amount: BigInt, + _amountAllCourts: BigInt +): StakeSet { let stakeSetEvent = newMockEvent(); stakeSetEvent.parameters = new Array(); @@ -96,6 +101,9 @@ export function createStakeSetEvent(_address: Address, _courtID: BigInt, _amount stakeSetEvent.parameters.push(new ethereum.EventParam("_address", ethereum.Value.fromAddress(_address))); stakeSetEvent.parameters.push(new ethereum.EventParam("_courtID", ethereum.Value.fromUnsignedBigInt(_courtID))); stakeSetEvent.parameters.push(new ethereum.EventParam("_amount", ethereum.Value.fromUnsignedBigInt(_amount))); + stakeSetEvent.parameters.push( + new ethereum.EventParam("_amountAllCourts", ethereum.Value.fromUnsignedBigInt(_amountAllCourts)) + ); return stakeSetEvent; } diff --git a/subgraph/core/tests/sortition-module.test.ts b/subgraph/core/tests/sortition-module.test.ts index 8533bd894..6719aee57 100644 --- a/subgraph/core/tests/sortition-module.test.ts +++ b/subgraph/core/tests/sortition-module.test.ts @@ -10,8 +10,9 @@ describe("Describe event", () => { beforeAll(() => { let courtId = BigInt.fromI32(1); let amount = BigInt.fromI32(1000); + let amountAllCourts = BigInt.fromI32(1000); let jurorAddress = Address.fromString("0x922911F4f80a569a4425fa083456239838F7F003"); - let newStakeSetEvent = createStakeSetEvent(jurorAddress, courtId, amount); + let newStakeSetEvent = createStakeSetEvent(jurorAddress, courtId, amount, amountAllCourts); handleStakeSet(newStakeSetEvent); }); From 71bf6f47aebab702f7d082fe521845ad4f09132c Mon Sep 17 00:00:00 2001 From: kemuru <102478601+kemuru@users.noreply.github.com> Date: Thu, 27 Mar 2025 23:47:31 +0100 Subject: [PATCH 3/3] chore: bump package json version --- subgraph/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subgraph/package.json b/subgraph/package.json index 638be7422..c44d470c2 100644 --- a/subgraph/package.json +++ b/subgraph/package.json @@ -1,6 +1,6 @@ { "name": "@kleros/kleros-v2-subgraph", - "version": "0.11.0", + "version": "0.13.0", "drtVersion": "0.11.0", "license": "MIT", "scripts": {