Skip to content

Commit

Permalink
fix-bad-dispute-state
Browse files Browse the repository at this point in the history
  • Loading branch information
Corantin committed Aug 27, 2023
1 parent 4c7316a commit 95f0f49
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 48 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ package-lock.json
# Production
build
types
generated
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"
}
4 changes: 2 additions & 2 deletions helpers/disputable.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { concat } from './bytes'
import { Agreement } from '../types/templates/DisputeManager/Agreement'
import { Disputable, Dispute } from '../types/schema'
import { Agreement } from '../generated/templates/DisputeManager/Agreement'
import { Disputable, Dispute } from '../generated/schema'
import {
crypto,
Bytes,
Expand Down
7 changes: 4 additions & 3 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": "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",
"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 Down
12 changes: 6 additions & 6 deletions src/AragonCourt.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { BigInt, Bytes, Address, ethereum, log } from "@graphprotocol/graph-ts"
import { BLACKLISTED_MODULES } from "../helpers/blacklisted-modules"
import { updateCurrentSubscriptionPeriod } from "./Subscriptions"
import { ERC20 as ERC20Contract } from "../types/AragonCourt/ERC20"
import { JurorsRegistry as JurorsRegistryContract } from "../types/templates/JurorsRegistry/JurorsRegistry"
import { BrightIdRegister as BrightIdRegisterContract } from "../types/AragonCourt/BrightIdRegister"
import { ERC20 as ERC20Contract } from "../generated/AragonCourt/ERC20"
import { JurorsRegistry as JurorsRegistryContract } from "../generated/templates/JurorsRegistry/JurorsRegistry"
import { BrightIdRegister as BrightIdRegisterContract } from "../generated/AragonCourt/BrightIdRegister"
import {
ERC20,
CourtModule,
CourtConfig,
CourtTerm,
BrightIdRegisterModule,
JurorsRegistryModule,
} from "../types/schema"
} from "../generated/schema"
import {
BrightIdRegister,
DisputeManager,
JurorsRegistry,
Treasury,
Voting,
Subscriptions,
} from "../types/templates"
} from "../generated/templates"
import {
AragonCourt,
Heartbeat,
Expand All @@ -28,7 +28,7 @@ import {
ConfigGovernorChanged,
FeesUpdaterChanged,
ModulesGovernorChanged,
} from "../types/AragonCourt/AragonCourt"
} from "../generated/AragonCourt/AragonCourt"

let DISPUTE_MANAGER_TYPE = "DisputeManager"
let JURORS_REGISTRY_TYPE = "JurorsRegistry"
Expand Down
4 changes: 2 additions & 2 deletions src/Arbitrable.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Evidence } from "../types/schema"
import { Evidence } from "../generated/schema"
import { ethereum, Bytes, BigInt, Address } from "@graphprotocol/graph-ts"
import { EvidenceSubmitted } from "../types/templates/DisputeManager/Arbitrable"
import { EvidenceSubmitted } from "../generated/templates/DisputeManager/Arbitrable"

export function handleEvidenceSubmittedWithArbitrator(
event: EvidenceSubmitted
Expand Down
6 changes: 3 additions & 3 deletions src/BrightIdRegister.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Address, BigInt, ethereum } from "@graphprotocol/graph-ts"
import { Juror } from "../types/schema"
import { BrightIdRegister as BrightIdRegisterContract } from "../types/AragonCourt/BrightIdRegister"
import { Register } from "../types/templates/BrightIdRegister/BrightIdRegister"
import { Juror } from "../generated/schema"
import { BrightIdRegister as BrightIdRegisterContract } from "../generated/AragonCourt/BrightIdRegister"
import { Register } from "../generated/templates/BrightIdRegister/BrightIdRegister"

export function handleUserRegistered(event: Register): void {
updateJuror(event.params.sender, event)
Expand Down
42 changes: 21 additions & 21 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 All @@ -17,7 +18,7 @@ import {
Appeal,
JurorDispute,
JurorDraft,
} from "../types/schema"
} from "../generated/schema"
import {
DisputeManager,
NewDispute,
Expand All @@ -31,7 +32,7 @@ import {
RulingAppealed,
RulingAppealConfirmed,
RulingComputed,
} from "../types/templates/DisputeManager/DisputeManager"
} from "../generated/templates/DisputeManager/DisputeManager"

const JUROR_FEES = "Juror"
const APPEAL_FEES = "Appeal"
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,24 +418,20 @@ 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()
return crypto.keccak256(Bytes.fromBigInt(disputeId).concat(juror)).toHexString()
}

function buildAppealId(disputeId: BigInt, roundId: BigInt): BigInt {
// There can be only one appeal per dispute round, seems safe doing the same math
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 +443,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
4 changes: 2 additions & 2 deletions src/JurorsRegistry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { buildId } from "../helpers/id"
import { Juror, ANJMovement, JurorsRegistryModule } from "../types/schema"
import { Juror, ANJMovement, JurorsRegistryModule } from "../generated/schema"
import { ethereum, Address, BigInt } from "@graphprotocol/graph-ts"
import {
Staked,
Expand All @@ -14,7 +14,7 @@ import {
JurorTokensCollected,
JurorSlashed,
JurorsRegistry,
} from "../types/templates/JurorsRegistry/JurorsRegistry"
} from "../generated/templates/JurorsRegistry/JurorsRegistry"

let STAKE = "Stake"
let UNSTAKE = "Unstake"
Expand Down
4 changes: 2 additions & 2 deletions src/Subscriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import {
JurorSubscriptionFee,
SubscriptionModule,
SubscriptionPeriod,
} from "../types/schema"
} from "../generated/schema"
import {
FeesClaimed,
FeeTokenChanged,
PeriodPercentageYieldChanged,
Subscriptions,
} from "../types/templates/Subscriptions/Subscriptions"
} from "../generated/templates/Subscriptions/Subscriptions"

let SUBSCRIPTIONS = "Subscriptions"

Expand Down
4 changes: 2 additions & 2 deletions src/Treasury.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { concat } from "../helpers/bytes"
import { buildId } from "../helpers/id"
import { FeeMovement, TreasuryBalance } from "../types/schema"
import { FeeMovement, TreasuryBalance } from "../generated/schema"
import {
Assign,
Withdraw,
Treasury,
} from "../types/templates/Treasury/Treasury"
} from "../generated/templates/Treasury/Treasury"
import { crypto, BigInt, Address, ethereum } from "@graphprotocol/graph-ts"

let WITHDRAW = "Withdraw"
Expand Down
8 changes: 4 additions & 4 deletions src/Voting.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { JurorDraft, Vote } from "../types/schema"
import { JurorDraft, Vote } from "../generated/schema"
import {
buildDraftId,
decodeDisputeRoundId,
Expand All @@ -8,10 +8,10 @@ import {
VoteCommitted,
VoteLeaked,
VoteRevealed,
} from "../types/templates/Voting/Voting"
} from "../generated/templates/Voting/Voting"
import { Address, BigInt, ByteArray, ethereum } from "@graphprotocol/graph-ts"
import { Voting } from "../types/templates/Voting/Voting"
import { Controller } from "../types/templates/JurorsRegistry/Controller"
import { Voting } from "../generated/templates/Voting/Voting"
import { Controller } from "../generated/templates/JurorsRegistry/Controller"

export function handleVoteCommitted(event: VoteCommitted): void {
let disputeRoundId = event.params.voteId
Expand Down

0 comments on commit 95f0f49

Please sign in to comment.