diff --git a/subgraph/core-neo/subgraph.yaml b/subgraph/core-neo/subgraph.yaml index 252098b54..cae476398 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 @@ -162,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/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..a0398c2f8 100644 --- a/subgraph/core-university/subgraph.yaml +++ b/subgraph/core-university/subgraph.yaml @@ -149,13 +149,12 @@ dataSources: language: wasm/assemblyscript entities: - JurorTokensPerCourt - - StakeSet abis: - name: SortitionModule file: ../../contracts/deployments/arbitrumSepoliaDevnet/SortitionModuleUniversity.json 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/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..f93fe2b1b 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 @@ -162,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); }); diff --git a/subgraph/package.json b/subgraph/package.json index fcacbb475..c44d470c2 100644 --- a/subgraph/package.json +++ b/subgraph/package.json @@ -1,6 +1,6 @@ { "name": "@kleros/kleros-v2-subgraph", - "version": "0.12.0", + "version": "0.13.0", "drtVersion": "0.11.0", "license": "MIT", "scripts": {