diff --git a/.gitignore b/.gitignore index 010e26d..c710bc8 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,4 @@ package-lock.json build types subgraph.yaml -deploy-output.txt \ No newline at end of file +deploy-output.txt diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..3faccdc --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "prettier.semi": false, + "typescript.preferences.quoteStyle": "double" +} \ No newline at end of file diff --git a/helpers/disputable.ts b/helpers/disputable.ts index e821941..abd9e0d 100644 --- a/helpers/disputable.ts +++ b/helpers/disputable.ts @@ -1,6 +1,6 @@ -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, @@ -8,14 +8,14 @@ import { 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 @@ -42,7 +42,7 @@ export function tryDecodingAgreementMetadata(dispute: Dispute): void { if ( challengeData.reverted || challengeData.value.value1.toHexString() == - '0x0000000000000000000000000000000000000000' + "0x0000000000000000000000000000000000000000" ) return diff --git a/package.json b/package.json index 06706da..b8c86d6 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", @@ -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" @@ -41,4 +42,4 @@ "@graphprotocol/graph-cli": "^0.37.2", "@graphprotocol/graph-ts": "^0.29.3" } -} +} \ No newline at end of file diff --git a/scripts/build-graph.sh b/scripts/build-graph.sh deleted file mode 100644 index c09dd73..0000000 --- a/scripts/build-graph.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash - -# Exit script as soon as a command fails. -set -o errexit - -# Run codegen -npm run codegen - -# Run build -npx graph build diff --git a/scripts/codegen.sh b/scripts/codegen.sh deleted file mode 100644 index 8452d87..0000000 --- a/scripts/codegen.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash - -# Exit script as soon as a command fails. -set -o errexit - -# Create manifest -npm run build:manifest - -# Run codegen -rm -rf ./types && graph codegen -o types diff --git a/src/DisputeManager.ts b/src/DisputeManager.ts index babf90d..6c05604 100644 --- a/src/DisputeManager.ts +++ b/src/DisputeManager.ts @@ -1,3 +1,4 @@ +import { concat } from "../helpers/bytes" import { buildId } from "../helpers/id" import { createFeeMovement } from "./Treasury" import { tryDecodingAgreementMetadata } from "../helpers/disputable" @@ -7,7 +8,7 @@ import { BigInt, Address, ethereum, - log, + ByteArray, } from "@graphprotocol/graph-ts" import { AdjudicationRound, @@ -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) @@ -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() } @@ -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() @@ -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 @@ -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() } @@ -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) @@ -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) @@ -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) @@ -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) @@ -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() @@ -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: @@ -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: