Skip to content

Commit

Permalink
Merge pull request #20 from Corantin/fix-bad-dispute-state
Browse files Browse the repository at this point in the history
Fix bad dispute state
  • Loading branch information
kamikazebr authored Aug 27, 2023
2 parents 4c7316a + fb712e9 commit 64640b0
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ package-lock.json
build
types
subgraph.yaml
deploy-output.txt
deploy-output.txt
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"prettier.semi": false,
"typescript.preferences.quoteStyle": "double"
}
12 changes: 6 additions & 6 deletions helpers/disputable.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { concat } from './bytes'
import { Agreement } from '../types/templates/DisputeManager/Agreement'
import { Disputable, Dispute } from '../types/schema'
import { concat } from "./bytes"
import { Agreement } from "../types/templates/DisputeManager/Agreement"
import { Disputable, Dispute } from "../types/schema"
import {
crypto,
Bytes,
Address,
BigInt,
log,
ByteArray,
} from '@graphprotocol/graph-ts'
} from "@graphprotocol/graph-ts"

// Rinkeby agreement-1hive.open.aragonpm.eth:
// const AGREEMENT_OPEN_APP_ID = '41dd0b999b443a19321f2f34fe8078d1af95a1487b49af4c2ca57fb9e3e5331e'

// xDai agreement.open.aragonpm.eth:
const AGREEMENT_OPEN_APP_ID =
'34c62f3aec3073826f39c2c35e9a1297d9dbf3cc77472283106f09eee9cf47bf'
"34c62f3aec3073826f39c2c35e9a1297d9dbf3cc77472283106f09eee9cf47bf"

const AGREEMENT_APP_ID_LENGTH = AGREEMENT_OPEN_APP_ID.length
const AGREEMENT_DISPUTE_METADATA_LENGTH = 64 // "[APP_ID][CHALLENGE_ID]" = 32 + 32
Expand All @@ -42,7 +42,7 @@ export function tryDecodingAgreementMetadata(dispute: Dispute): void {
if (
challengeData.reverted ||
challengeData.value.value1.toHexString() ==
'0x0000000000000000000000000000000000000000'
"0x0000000000000000000000000000000000000000"
)
return

Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.1",
"scripts": {
"draw-schema": "./scripts/draw-schema.sh",
"build:graph": "./scripts/build-graph.sh",
"build": "graph build",
"build:graph:rpc": "NETWORK=rpc npm run build:graph",
"build:graph:staging": "NETWORK=staging npm run build:graph",
"build:graph:rinkeby": "NETWORK=rinkeby npm run build:graph",
Expand All @@ -16,7 +16,7 @@
"build:manifest:goerli": "NETWORK=goerli npm run build:manifest",
"build:manifest:gnosis": "NETWORK=gnosis npm run build:manifest",
"build:manifest:polygon": "NETWORK=polygon npm run build:manifest",
"codegen": "./scripts/codegen.sh",
"codegen": "graph codegen -o types",
"codegen:rpc": "NETWORK=rpc npm run codegen",
"codegen:ropsten": "NETWORK=ropsten npm run codegen",
"codegen:staging": "NETWORK=staging npm run codegen",
Expand All @@ -30,7 +30,8 @@
"deploy:rinkeby": "NETWORK=rinkeby npm run deploy",
"deploy:goerli": "NETWORK=goerli npm run deploy",
"deploy:gnosis": "NETWORK=gnosis npm run deploy",
"deploy:polygon": "NETWORK=polygon npm run deploy"
"deploy:polygon": "NETWORK=polygon npm run deploy",
"graph": "graph"
},
"devDependencies": {
"graphqlviz": "^3.1.0"
Expand All @@ -41,4 +42,4 @@
"@graphprotocol/graph-cli": "^0.37.2",
"@graphprotocol/graph-ts": "^0.29.3"
}
}
}
10 changes: 0 additions & 10 deletions scripts/build-graph.sh

This file was deleted.

10 changes: 0 additions & 10 deletions scripts/codegen.sh

This file was deleted.

34 changes: 18 additions & 16 deletions src/DisputeManager.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { concat } from "../helpers/bytes"
import { buildId } from "../helpers/id"
import { createFeeMovement } from "./Treasury"
import { tryDecodingAgreementMetadata } from "../helpers/disputable"
Expand All @@ -7,7 +8,7 @@ import {
BigInt,
Address,
ethereum,
log,
ByteArray,
} from "@graphprotocol/graph-ts"
import {
AdjudicationRound,
Expand Down Expand Up @@ -96,7 +97,7 @@ export function handleJurorDrafted(event: JurorDrafted): void {

export function handleDisputeStateChanged(event: DisputeStateChanged): void {
let dispute = Dispute.load(event.params.disputeId.toString())!
dispute.state = castDisputeState(Bytes.fromI32(event.params.state))
dispute.state = castDisputeState(event.params.state)
dispute.save()

updateRound(event.params.disputeId, dispute.lastRoundId, event)
Expand All @@ -107,7 +108,7 @@ export function handleDisputeStateChanged(event: DisputeStateChanged): void {
event.params.disputeId,
dispute.lastRoundId,
event
)
)!
round.draftedTermId = round.draftTermId.plus(round.delayedTerms)
round.save()
}
Expand All @@ -124,7 +125,7 @@ export function handleRulingAppealConfirmed(
let manager = DisputeManager.bind(event.address)
let dispute = new Dispute(event.params.disputeId.toString())
let disputeResult = manager.getDispute(event.params.disputeId)
dispute.state = castDisputeState(new Bytes(disputeResult.value2))
dispute.state = castDisputeState(disputeResult.value2)
dispute.lastRoundId = disputeResult.value4
dispute.save()

Expand Down Expand Up @@ -199,7 +200,7 @@ function updateRound(
roundNumber: BigInt,
event: ethereum.Event
): void {
let round = loadOrCreateRound(disputeId, roundNumber, event)
let round = loadOrCreateRound(disputeId, roundNumber, event)!
let manager = DisputeManager.bind(event.address)
let result = manager.getRound(disputeId, roundNumber)
round.number = roundNumber
Expand All @@ -212,7 +213,7 @@ function updateRound(
round.settledPenalties = result.value5
round.collectedTokens = result.value6
round.coherentJurors = result.value7
round.state = castAdjudicationState(Bytes.fromI32(result.value8))
round.state = castAdjudicationState(result.value8)
round.stateInt = result.value8
round.save()
}
Expand All @@ -221,7 +222,7 @@ function loadOrCreateRound(
disputeId: BigInt,
roundNumber: BigInt,
event: ethereum.Event
): AdjudicationRound {
): AdjudicationRound | null {
let id = buildRoundId(disputeId, roundNumber).toString()
let round = AdjudicationRound.load(id)

Expand All @@ -234,7 +235,10 @@ function loadOrCreateRound(
return round
}

function createJurorDispute(disputeId: BigInt, juror: Address): JurorDispute {
function createJurorDispute(
disputeId: BigInt,
juror: Address
): JurorDispute | null {
let id = buildJurorDisputeId(disputeId, juror).toString()
let jurorDispute = JurorDispute.load(id)

Expand All @@ -253,7 +257,7 @@ function updateAppeal(
roundNumber: BigInt,
event: ethereum.Event
): void {
let appeal = loadOrCreateAppeal(disputeId, roundNumber, event)
let appeal = loadOrCreateAppeal(disputeId, roundNumber, event)!
let manager = DisputeManager.bind(event.address)
let result = manager.getAppeal(disputeId, roundNumber)
let nextRound = manager.getNextRoundDetails(disputeId, roundNumber)
Expand Down Expand Up @@ -364,7 +368,7 @@ function loadOrCreateAppeal(
disputeId: BigInt,
roundNumber: BigInt,
event: ethereum.Event
): Appeal {
): Appeal | null {
let id = buildAppealId(disputeId, roundNumber).toString()
let appeal = Appeal.load(id)

Expand Down Expand Up @@ -414,12 +418,10 @@ export function decodeDisputeRoundId(disputeRoundId: BigInt): BigInt[] {
}

export function buildDraftId(roundId: BigInt, juror: Address): string {
// @ts-ignore BigInt is actually a BytesArray under the hood
return crypto.keccak256(Bytes.fromBigInt(roundId).concat(juror)).toHexString()
}

export function buildJurorDisputeId(disputeId: BigInt, juror: Address): string {
// @ts-ignore BigInt is actually a BytesArray under the hood
return crypto
.keccak256(Bytes.fromBigInt(disputeId).concat(juror))
.toHexString()
Expand All @@ -430,8 +432,8 @@ function buildAppealId(disputeId: BigInt, roundId: BigInt): BigInt {
return buildRoundId(disputeId, roundId)
}

function castDisputeState(state: Bytes): string {
switch (state.toI32()) {
function castDisputeState(state: i32): string {
switch (state) {
case 0:
return "Drafting"
case 1:
Expand All @@ -443,8 +445,8 @@ function castDisputeState(state: Bytes): string {
}
}

function castAdjudicationState(state: Bytes): string {
switch (state.toI32()) {
function castAdjudicationState(state: i32): string {
switch (state) {
case 0:
return "Invalid"
case 1:
Expand Down

0 comments on commit 64640b0

Please sign in to comment.