Skip to content

Commit

Permalink
fix: concat, upcast methods.
Browse files Browse the repository at this point in the history
fix: xdai to gnosis and added goerli
  • Loading branch information
kamikazebr committed Feb 14, 2023
1 parent 5696af5 commit 426b9ce
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 99 deletions.
9 changes: 4 additions & 5 deletions blacklisted-modules.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

module.exports = {
xdai: [
gnosis: [
"0x41ab49872ed459c840d0caecd47fcdc201c48307", // Subscriptions v1.0
],
rinkeby: [],
polygon: []
}
goerli: [],
polygon: [],
};
4 changes: 2 additions & 2 deletions helpers/blacklisted-modules.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// This file was autogenerated at deployment time picking the list of blacklisted modules defined in "blacklisted-modules.js" for network polygon
export const BLACKLISTED_MODULES: string[] = []
// This file was autogenerated at deployment time picking the list of blacklisted modules defined in "blacklisted-modules.js" for network gnosis
export const BLACKLISTED_MODULES: string[] = ["0x41ab49872ed459c840d0caecd47fcdc201c48307"]
22 changes: 15 additions & 7 deletions helpers/disputable.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import { concat } from './bytes';
import { Agreement } from '../generated/templates/DisputeManager/Agreement';
import { Disputable, Dispute } from '../generated/schema';
import { crypto, Bytes, Address, BigInt } from '@graphprotocol/graph-ts';
import { concat } from "./bytes";
import { Agreement } from "../generated/templates/DisputeManager/Agreement";
import { Disputable, Dispute } from "../generated/schema";
import {
crypto,
Bytes,
Address,
BigInt,
log,
ByteArray,
} 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 @@ -31,10 +38,11 @@ export function tryDecodingAgreementMetadata(dispute: Dispute): void {
);
let agreement = Agreement.bind(Address.fromString(dispute.subject));
let challengeData = agreement.try_getChallenge(challengeId);

if (
challengeData.reverted ||
challengeData.value.value1.toHexString() ==
'0x0000000000000000000000000000000000000000'
"0x0000000000000000000000000000000000000000"
)
return;

Expand Down Expand Up @@ -71,6 +79,6 @@ export function tryDecodingAgreementMetadata(dispute: Dispute): void {
function buildAgreementActionId(agreement: Address, actionId: BigInt): string {
// @ts-ignore BigInt is actually a BytesArray under the hood
return crypto
.keccak256(concat(agreement, new Bytes(actionId.toI32())))
.keccak256((agreement as ByteArray).concat(ByteArray.fromBigInt(actionId)))
.toHexString();
}
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,29 @@
"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",
"build:graph:xdai": "NETWORK=xdai npm run build:graph",
"build:graph:gnosis": "NETWORK=gnosis npm run build:graph",
"build:graph:polygon": "NETWORK=polygon npm run build:graph",
"build:manifest": "./scripts/build-manifest.sh",
"build:manifest:rpc": "NETWORK=rpc npm run build:manifest",
"build:manifest:staging": "NETWORK=staging npm run build:manifest",
"build:manifest:rinkeby": "NETWORK=rinkeby npm run build:manifest",
"build:manifest:goerli": "NETWORK=goerli npm run build:manifest",
"build:manifest:xdai": "NETWORK=xdai 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:rpc": "NETWORK=rpc npm run codegen",
"codegen:ropsten": "NETWORK=ropsten npm run codegen",
"codegen:staging": "NETWORK=staging npm run codegen",
"codegen:rinkeby": "NETWORK=rinkeby npm run codegen",
"codegen:goerli": "NETWORK=goerli npm run codegen",
"codegen:xdai": "NETWORK=xdai npm run codegen",
"codegen:gnosis": "NETWORK=gnosis npm run codegen",
"codegen:polygon": "NETWORK=polygon npm run codegen",
"deploy": "./scripts/deploy.sh",
"deploy:rpc": "NETWORK=rpc npm run deploy",
"deploy:staging": "NETWORK=staging npm run deploy",
"deploy:rinkeby": "NETWORK=rinkeby npm run deploy",
"deploy:goerli": "NETWORK=goerli npm run deploy",
"deploy:xdai": "NETWORK=xdai npm run deploy",
"deploy:gnosis": "NETWORK=gnosis npm run deploy",
"deploy:polygon": "NETWORK=polygon npm run deploy"
},
"devDependencies": {
Expand Down
13 changes: 7 additions & 6 deletions scripts/build-manifest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,29 @@ set -o errexit
# Court known addresses
court_staging=
court_rinkeby=0xC2224D785D4e4bc92D5be6767A82d026ca2813fD
court_xdai=0x44E4fCFed14E1285c9e0F6eae77D5fDd0F196f85
court_goerli=
court_gnosis=0x44E4fCFed14E1285c9e0F6eae77D5fDd0F196f85
court_goerli=0x15ea6e0ab085b8d7d899672f10f213d53ce02150
court_polygon=0xf0C8376065fadfACB706caFbaaC96B321069C015

# Known block numbers
start_block_staging=
start_block_rinkeby=8250225
start_block_xdai=14861364
start_block_goerli=8187465
start_block_gnosis=14861364
start_block_polygon=21936374

# Validate network
networks=(rpc staging rinkeby xdai polygon)
networks=(rpc staging goerli gnosis polygon)
if [[ -z $NETWORK || ! " ${networks[@]} " =~ " ${NETWORK} " ]]; then
echo 'Please make sure the network provided is either rpc, staging, rinkeby, xdai or polygon'
echo 'Please make sure the network provided is either rpc, staging, rinkeby, gnosis or polygon'
exit 1
fi

# Use mainnet network in case of local deployment
if [[ "$NETWORK" = "rpc" ]]; then
ENV='mainnet'
elif [[ "$NETWORK" = "staging" ]]; then
ENV='rinkeby'
ENV='goerli'
elif [[ "$NETWORK" = "polygon" ]]; then
ENV='matic'
else
Expand Down
72 changes: 37 additions & 35 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
#!/usr/bin/env bash

# Exit script as soon as a command fails.
set -o errexit

# Run graph build
npm run build:graph

# Require $GRAPHKEY to be set
if [[ -z "${GRAPHKEY}" ]]; then
echo "Please set \$GRAPHKEY to your The Graph access token to run this command."
exit 1
fi

# Use custom subgraph name based on target network
if [[ "$NETWORK" != "xdai" ]]; then
SUBGRAPH_EXT="-${NETWORK}"
else
SUBGRAPH_EXT=""
fi

# Select IPFS and The Graph nodes
if [[ "$NETWORK" = "rpc" ]]; then
IPFS_NODE="http://localhost:5001"
GRAPH_NODE="http://127.0.0.1:8020"
else
IPFS_NODE="https://api.thegraph.com/ipfs/"
GRAPH_NODE="https://api.thegraph.com/deploy/"
fi

# Deploy subgraph
graph deploy 1hive/celeste${SUBGRAPH_EXT} \
--ipfs ${IPFS_NODE} \
--node ${GRAPH_NODE} \
--access-token "$GRAPHKEY" > deploy-output.txt
# #!/usr/bin/env bash

# # Exit script as soon as a command fails.
# set -o errexit

# # Run graph build
# npm run build:graph

# # Require $GRAPHKEY to be set
# if [[ -z "${GRAPHKEY}" ]]; then
# echo "Please set \$GRAPHKEY to your The Graph access token to run this command."
# exit 1
# fi

# # Use custom subgraph name based on target network
# if [[ "$NETWORK" != "gnosis" ]]; then
# SUBGRAPH_EXT="-${NETWORK}"
# else
# SUBGRAPH_EXT=""
# fi

# graph deploy --studio celeste-${SUBGRAPH_EXT}

# # # Select IPFS and The Graph nodes
# # if [[ "$NETWORK" = "rpc" ]]; then
# # IPFS_NODE="http://localhost:5001"
# # GRAPH_NODE="http://127.0.0.1:8020"
# # else
# # IPFS_NODE="https://api.thegraph.com/ipfs/"
# # GRAPH_NODE="https://api.thegraph.com/deploy/"
# # fi

# # # Deploy subgraph
# # graph deploy 1hive/celeste${SUBGRAPH_EXT} \
# # --ipfs ${IPFS_NODE} \
# # --node ${GRAPH_NODE} \
# # --access-token "$GRAPHKEY" > deploy-output.txt

59 changes: 30 additions & 29 deletions src/DisputeManager.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { concat } from '../helpers/bytes';
import { buildId } from '../helpers/id';
import { createFeeMovement } from './Treasury';
import { tryDecodingAgreementMetadata } from '../helpers/disputable';
import { concat } from "../helpers/bytes";
import { buildId } from "../helpers/id";
import { createFeeMovement } from "./Treasury";
import { tryDecodingAgreementMetadata } from "../helpers/disputable";
import {
crypto,
Bytes,
BigInt,
Address,
ethereum,
} from '@graphprotocol/graph-ts';
log,
} from "@graphprotocol/graph-ts";
import {
AdjudicationRound,
Arbitrable,
Expand All @@ -17,7 +18,7 @@ import {
Appeal,
JurorDispute,
JurorDraft,
} from '../generated/schema';
} from "../generated/schema";
import {
DisputeManager,
NewDispute,
Expand All @@ -31,10 +32,10 @@ import {
RulingAppealed,
RulingAppealConfirmed,
RulingComputed,
} from '../generated/templates/DisputeManager/DisputeManager';
} from "../generated/templates/DisputeManager/DisputeManager";

const JUROR_FEES = 'Juror';
const APPEAL_FEES = 'Appeal';
const JUROR_FEES = "Juror";
const APPEAL_FEES = "Appeal";

export function handleNewDispute(event: NewDispute): void {
let manager = DisputeManager.bind(event.address);
Expand All @@ -44,7 +45,7 @@ export function handleNewDispute(event: NewDispute): void {
dispute.metadata = event.params.metadata.toString();
dispute.rawMetadata = event.params.metadata;
dispute.possibleRulings = disputeResult.value1;
dispute.state = 'Evidence';
dispute.state = "Evidence";
dispute.settledPenalties = false;
dispute.finalRuling = disputeResult.value3;
dispute.lastRoundId = disputeResult.value4;
Expand Down Expand Up @@ -73,7 +74,7 @@ export function handleEvidenceSubmitted(event: EvidenceSubmitted): void {

export function handleEvidencePeriodClosed(event: EvidencePeriodClosed): void {
let dispute = Dispute.load(event.params.disputeId.toString())!;
dispute.state = 'Drafting';
dispute.state = "Drafting";
dispute.save();

updateRound(event.params.disputeId, dispute.lastRoundId, event);
Expand Down Expand Up @@ -188,7 +189,7 @@ export function handleAppealDepositSettled(event: AppealDepositSettled): void {

export function handleRulingComputed(event: RulingComputed): void {
let dispute = Dispute.load(event.params.disputeId.toString())!;
dispute.state = 'Ruled';
dispute.state = "Ruled";
dispute.finalRuling = event.params.ruling;
dispute.ruledAt = event.block.timestamp;
dispute.save();
Expand Down Expand Up @@ -303,14 +304,14 @@ function createAppealFeesForDeposits(
maker,
appeal.appealDeposit.minus(feesRefund),
event,
id.concat('-maker')
id.concat("-maker")
);
createFeeMovement(
APPEAL_FEES,
taker,
appeal.confirmAppealDeposit.minus(feesRefund),
event,
id.concat('-taker')
id.concat("-taker")
);
}
}
Expand Down Expand Up @@ -347,14 +348,14 @@ function createAppealFeesForJurorFees(
Address.fromString(appeal.maker.toHexString()),
refundFees,
event,
id.concat('-maker')
id.concat("-maker")
);
createFeeMovement(
APPEAL_FEES,
Address.fromString(appeal.taker.toHexString()),
refundFees,
event,
id.concat('-taker')
id.concat("-taker")
);
}
}
Expand Down Expand Up @@ -416,14 +417,14 @@ 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(concat(new Bytes(roundId.toI32()), juror))
.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(concat(new Bytes(disputeId.toI32()), juror))
.keccak256(Bytes.fromBigInt(disputeId).concat(juror))
.toHexString();
}

Expand All @@ -435,31 +436,31 @@ function buildAppealId(disputeId: BigInt, roundId: BigInt): BigInt {
function castDisputeState(state: Bytes): string {
switch (state.toI32()) {
case 0:
return 'Drafting';
return "Drafting";
case 1:
return 'Adjudicating';
return "Adjudicating";
case 2:
return 'Ruled';
return "Ruled";
default:
return 'Unknown';
return "Unknown";
}
}

function castAdjudicationState(state: Bytes): string {
switch (state.toI32()) {
case 0:
return 'Invalid';
return "Invalid";
case 1:
return 'Committing';
return "Committing";
case 2:
return 'Revealing';
return "Revealing";
case 3:
return 'Appealing';
return "Appealing";
case 4:
return 'ConfirmingAppeal';
return "ConfirmingAppeal";
case 5:
return 'Ended';
return "Ended";
default:
return 'Unknown';
return "Unknown";
}
}
Loading

0 comments on commit 426b9ce

Please sign in to comment.