Skip to content

chore: revert stakeset handling in this subgraph and add new event parameter #1936

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions subgraph/core-neo/subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ dataSources:
language: wasm/assemblyscript
entities:
- JurorTokensPerCourt
- StakeSet
abis:
- name: SortitionModule
file: ../../contracts/deployments/arbitrum/SortitionModuleNeo.json
Expand All @@ -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
17 changes: 3 additions & 14 deletions subgraph/core-university/src/SortitionModule.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions subgraph/core-university/subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 0 additions & 11 deletions subgraph/core/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
17 changes: 3 additions & 14 deletions subgraph/core/src/SortitionModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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 {}
3 changes: 1 addition & 2 deletions subgraph/core/subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ dataSources:
language: wasm/assemblyscript
entities:
- JurorTokensPerCourt
- StakeSet
abis:
- name: SortitionModule
file: ../../contracts/deployments/arbitrumSepoliaDevnet/SortitionModule.json
Expand All @@ -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
10 changes: 9 additions & 1 deletion subgraph/core/tests/sortition-module-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,22 @@ 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();

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;
}
3 changes: 2 additions & 1 deletion subgraph/core/tests/sortition-module.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down
2 changes: 1 addition & 1 deletion subgraph/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kleros/kleros-v2-subgraph",
"version": "0.12.0",
"version": "0.13.0",
"drtVersion": "0.11.0",
"license": "MIT",
"scripts": {
Expand Down
Loading