Skip to content

Fix(subgraph): Handle rule event #555

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
merged 6 commits into from
Feb 3, 2023
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
2 changes: 1 addition & 1 deletion subgraph/src/DisputeKitClassic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function handleDisputeCreation(event: DisputeCreation): void {
}

export function handleEvidenceEvent(event: EvidenceEvent): void {
const evidenceGroupID = event.params._evidenceGroupID.toHexString();
const evidenceGroupID = event.params._evidenceGroupID.toString();
const evidenceGroup = ensureClassicEvidenceGroup(evidenceGroupID);
const evidenceIndex = evidenceGroup.nextEvidenceIndex;
evidenceGroup.nextEvidenceIndex = evidenceGroup.nextEvidenceIndex.plus(ONE);
Expand Down
20 changes: 19 additions & 1 deletion subgraph/src/KlerosCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
NewPeriod,
StakeSet,
TokenAndETHShift as TokenAndETHShiftEvent,
Ruling,
} from "../generated/KlerosCore/KlerosCore";
import { ZERO, ONE } from "./utils";
import { createCourtFromEvent, getFeeForJuror } from "./entities/Court";
Expand All @@ -24,6 +25,8 @@ import {
updatePaidETH,
updateStakedPNK,
updateRedistributedPNK,
updateCasesRuled,
updateCasesVoting,
getDelta,
} from "./datapoint";
import { ensureUser } from "./entities/User";
Expand All @@ -35,6 +38,7 @@ import { createDrawFromEvent } from "./entities/Draw";
import { createTokenAndEthShiftFromEvent } from "./entities/TokenAndEthShift";
import { updateArbitrableCases } from "./entities/Arbitrable";
import { Court, Dispute } from "../generated/schema";
import { BigInt } from "@graphprotocol/graph-ts";

function getPeriodName(index: i32): string {
const periodArray = ["evidence", "commit", "vote", "appeal", "execution"];
Expand Down Expand Up @@ -95,11 +99,25 @@ export function handleNewPeriod(event: NewPeriod): void {
const disputeID = event.params._disputeID.toString();
const dispute = Dispute.load(disputeID);
if (!dispute) return;
dispute.period = getPeriodName(event.params._period);
const newPeriod = getPeriodName(event.params._period);
if (dispute.period === "vote") {
updateCasesVoting(BigInt.fromI32(-1), event.block.timestamp);
} else if (newPeriod === "vote") {
updateCasesVoting(ONE, event.block.timestamp);
}
dispute.period = newPeriod;
dispute.lastPeriodChange = event.block.timestamp;
dispute.save();
}

export function handleRuling(event: Ruling): void {
const disputeID = event.params._disputeID.toString();
const dispute = Dispute.load(disputeID);
if (!dispute) return;
dispute.ruled = true;
updateCasesRuled(ONE, event.block.timestamp);
}

export function handleAppealDecision(event: AppealDecision): void {
const contract = KlerosCore.bind(event.address);
const disputeID = event.params._disputeID;
Expand Down
16 changes: 9 additions & 7 deletions subgraph/subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ dataSources:
name: KlerosCore
network: arbitrum-goerli
source:
address: "0x4d7858e73a8842b5e6422D08a3349924dD062AbB"
address: "0x3eED6aaCa43f4Bb98C591e4A0d2C4a124efF9C24"
abi: KlerosCore
startBlock: 4027978
startBlock: 6456845
mapping:
kind: ethereum/events
apiVersion: 0.0.6
Expand Down Expand Up @@ -48,14 +48,16 @@ dataSources:
handler: handleStakeSet
- event: TokenAndETHShift(indexed address,indexed uint256,int256,int256)
handler: handleTokenAndETHShift
- event: Ruling(indexed address,indexed uint256,uint256)
handler: handleRuling
file: ./src/KlerosCore.ts
- kind: ethereum
name: PolicyRegistry
network: arbitrum-goerli
source:
address: "0xAF0F49Fe110b48bd512F00d51D141F023c9a9106"
address: "0xC5655728387Ce5E2aAA22138114E5777370aBDae"
abi: PolicyRegistry
startBlock: 4027973
startBlock: 6456907
mapping:
kind: ethereum/events
apiVersion: 0.0.6
Expand All @@ -73,9 +75,9 @@ dataSources:
name: DisputeKitClassic
network: arbitrum-goerli
source:
address: "0xde31F2245d164620d08f5b0f8D43dCe8B9708373"
address: "0x86734488ABF0E1AD40bc4DE4F820e808f39Bea09"
abi: DisputeKitClassic
startBlock: 4027976
startBlock: 6456825
mapping:
kind: ethereum/events
apiVersion: 0.0.6
Expand All @@ -99,7 +101,7 @@ dataSources:
handler: handleWithdrawal
- event: ChoiceFunded(indexed uint256,indexed uint256,indexed uint256)
handler: handleChoiceFunded
- event: Evidence(indexed address,indexed uint256,indexed address,string)
- event: Evidence(indexed uint256,indexed address,string)
handler: handleEvidenceEvent
- event: Justification(indexed uint256,indexed address,indexed uint256,string)
handler: handleJustificationEvent
Expand Down