diff --git a/veascan-subgraph-inbox/package.json b/veascan-subgraph-inbox/package.json index 9c6ca694..5653ee0d 100644 --- a/veascan-subgraph-inbox/package.json +++ b/veascan-subgraph-inbox/package.json @@ -1,6 +1,6 @@ { "name": "@kleros/veascan-subgraph-inbox", - "version": "0.2.3", + "version": "0.2.4", "license": "MIT", "engines": { "node": ">=18.0.0" diff --git a/veascan-subgraph-inbox/src/VeaInbox.ts b/veascan-subgraph-inbox/src/VeaInbox.ts index ccf1e652..cc10f9b2 100644 --- a/veascan-subgraph-inbox/src/VeaInbox.ts +++ b/veascan-subgraph-inbox/src/VeaInbox.ts @@ -3,7 +3,7 @@ import { BigInt, ByteArray, Bytes, - log, + dataSource, } from "@graphprotocol/graph-ts"; import { Snapshot, Message, Ref, Fallback, Inbox } from "../generated/schema"; import { @@ -122,10 +122,10 @@ export function handleSnapshotSaved(event: SnapshotSaved): void { inbox = new Inbox(event.address); inbox.save(); } - const contract = VeaInboxArbToEthDevnet.bind(event.address); - const epochPeriod = contract.epochPeriod(); + const veaInbox = VeaInboxArbToEthDevnet.bind(event.address); + const epochPeriod = veaInbox.epochPeriod(); const epoch = event.block.timestamp.div(epochPeriod); - const stateRoot = contract.snapshots(epoch); + const stateRoot = veaInbox.snapshots(epoch); const currentSnapshot = getCurrentSnapshot(event.address); currentSnapshot.saved = true; currentSnapshot.caller = event.transaction.from; diff --git a/veascan-subgraph-inbox/subgraph.yaml b/veascan-subgraph-inbox/subgraph.yaml index 98677419..22f59558 100644 --- a/veascan-subgraph-inbox/subgraph.yaml +++ b/veascan-subgraph-inbox/subgraph.yaml @@ -58,3 +58,59 @@ dataSources: - event: SnapshotSent(indexed uint256,bytes32) handler: handleSnapshotSent file: ./src/VeaInbox.ts + - kind: ethereum + name: VeaInboxArbToGnosisDevnet + network: arbitrum-sepolia + source: + address: "0xF6286b9C6c7F1B33Ea976FA43434027c7b8421A7" + abi: VeaInboxArbToGnosisDevnet + startBlock: 129093812 + mapping: + kind: ethereum/events + apiVersion: 0.0.7 + language: wasm/assemblyscript + entities: + - Snapshot + - Message + - Refs + abis: + - name: VeaInboxArbToGnosisDevnet + file: ../contracts/deployments/arbitrumSepolia/VeaInboxArbToGnosisDevnet.json + - name: VeaInboxArbToEthDevnet + file: ../contracts/deployments/arbitrumSepolia/VeaInboxArbToEthDevnet.json + eventHandlers: + - event: MessageSent(bytes) + handler: handleMessageSent + - event: SnapshotSaved(bytes32,uint256,uint64) + handler: handleSnapshotSaved + - event: SnapshotSent(indexed uint256,bytes32) + handler: handleSnapshotSent + file: ./src/VeaInbox.ts + - kind: ethereum + name: VeaInboxArbToGnosisTestnet + network: arbitrum-sepolia + source: + address: "0xa0d410b202D69C36871d5135ce42fC7D379BBB1c" + abi: VeaInboxArbToGnosisTestnet + startBlock: 139057386 + mapping: + kind: ethereum/events + apiVersion: 0.0.7 + language: wasm/assemblyscript + entities: + - Snapshot + - Message + - Refs + abis: + - name: VeaInboxArbToGnosisTestnet + file: ../contracts/deployments/arbitrumSepolia/VeaInboxArbToGnosisTestnet.json + - name: VeaInboxArbToEthDevnet + file: ../contracts/deployments/arbitrumSepolia/VeaInboxArbToEthDevnet.json + eventHandlers: + - event: MessageSent(bytes) + handler: handleMessageSent + - event: SnapshotSaved(bytes32,uint256,uint64) + handler: handleSnapshotSaved + - event: SnapshotSent(indexed uint256,bytes32) + handler: handleSnapshotSent + file: ./src/VeaInbox.ts diff --git a/veascan-subgraph-outbox/scripts/update.sh b/veascan-subgraph-outbox/scripts/update.sh index 77bedfaf..d157d366 100755 --- a/veascan-subgraph-outbox/scripts/update.sh +++ b/veascan-subgraph-outbox/scripts/update.sh @@ -1,45 +1,91 @@ #!/usr/bin/env bash +set -euo pipefail + +# +# scripts/update.sh +# +# Usage: +# ./scripts/update.sh [contractFileSuffix] +# +# hardhatNetwork: either "sepolia" or "chiado" +# graphNetwork: the same string to write into subgraph.yaml → .network (e.g. "sepolia" or "chiado") +# SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +SUBGRAPH_YAML="$SCRIPT_DIR/../subgraph.yaml" +VEAOUTBOX_TS="$SCRIPT_DIR/../src/VeaOutbox.ts" + +hardhatNetwork="${1:?"Usage: $0 [contractFileSuffix]"}" +graphNetwork="${2:?"Usage: $0 [contractFileSuffix]"}" +contractFileSuffix="${3:-}" + +# Back up the original subgraph.yaml +cp "$SUBGRAPH_YAML" "$SUBGRAPH_YAML".bak."$(date +%s)" + +count=$(yq '.dataSources | length' "$SUBGRAPH_YAML") + +for i in $(seq 0 $((count - 1))); do + origName="$(yq -r ".dataSources[$i].name" "$SUBGRAPH_YAML")" + newName="$origName" + + if [[ "$hardhatNetwork" == "sepolia" ]]; then + if [[ "$origName" == *"ArbToGnosisDevnet"* ]]; then + newName="${origName/ArbToGnosisDevnet/ArbToEthDevnet}" + elif [[ "$origName" == *"ArbToGnosisTestnet"* ]]; then + newName="${origName/ArbToGnosisTestnet/ArbToEthTestnet}" + fi + + # Patch VeaOutbox.ts: swap Gnosis imports to Eth imports when targeting sepolia + sed -i.bak \ + -e 's|from "../generated/VeaOutboxArbToGnosisDevnet/VeaOutboxArbToGnosisDevnet";|from "../generated/VeaOutboxArbToEthDevnet/VeaOutboxArbToEthDevnet";|' \ + -e 's|from "../generated/VeaOutboxArbToGnosisTestnet/VeaOutboxArbToGnosisTestnet";|from "../generated/VeaOutboxArbToEthTestnet/VeaOutboxArbToEthTestnet";|' \ + "$VEAOUTBOX_TS" + rm -f "$VEAOUTBOX_TS.bak" + + elif [[ "$hardhatNetwork" == "chiado" ]]; then + if [[ "$origName" == *"ArbToEthDevnet"* ]]; then + newName="${origName/ArbToEthDevnet/ArbToGnosisDevnet}" + elif [[ "$origName" == *"ArbToEthTestnet"* ]]; then + newName="${origName/ArbToEthTestnet/ArbToGnosisTestnet}" + fi + + + # Patch VeaOutbox.ts: swap Eth imports to Gnosis imports when targeting chiado + sed -i.bak \ + -e 's|from "../generated/VeaOutboxArbToEthDevnet/VeaOutboxArbToEthDevnet";|from "../generated/VeaOutboxArbToGnosisDevnet/VeaOutboxArbToGnosisDevnet";|' \ + -e 's|from "../generated/VeaOutboxArbToEthTestnet/VeaOutboxArbToEthTestnet";|from "../generated/VeaOutboxArbToGnosisTestnet/VeaOutboxArbToGnosisTestnet";|' \ + "$VEAOUTBOX_TS" + rm -f "$VEAOUTBOX_TS.bak" + fi + artifact="$SCRIPT_DIR/../../contracts/deployments/$hardhatNetwork/${newName}${contractFileSuffix}.json" + + if [[ ! -f "$artifact" ]]; then + echo "Artifact not found for dataSource[$i]:" + exit 1 + fi + + yq -i ".dataSources[$i].name = \"$newName\"" "$SUBGRAPH_YAML" + + yq -i ".dataSources[$i].mapping.abis[0].name = \"$newName\"" "$SUBGRAPH_YAML" + + relative_abi_file="../contracts/deployments/$hardhatNetwork/${newName}${contractFileSuffix}.json" + yq -i ".dataSources[$i].mapping.abis[0].file = \"$relative_abi_file\"" "$SUBGRAPH_YAML" + + yq -i ".dataSources[$i].source.abi = \"$newName\"" "$SUBGRAPH_YAML" + + if [[ "$graphNetwork" == "chiado" ]]; then + yq -i ".dataSources[$i].network = \"gnosis-chiado\"" "$SUBGRAPH_YAML" + else + yq -i ".dataSources[$i].network = \"$graphNetwork\"" "$SUBGRAPH_YAML" + fi + + address="$(jq -r '.address' "$artifact")" + yq -i ".dataSources[$i].source.address = \"$address\"" "$SUBGRAPH_YAML" + + + blockNumber="$(jq '.receipt.blockNumber' "$artifact")" + yq -i ".dataSources[$i].source.startBlock = $blockNumber" "$SUBGRAPH_YAML" -function update() { # Parameters: file, dataSourceIndex, graphNetwork - local f="$1" - local dataSourceIndex="$2" - local graphNetwork="$3" - - # Compute the contract file path relative to the subgraph.yaml file. - local contractFile="${f#$SCRIPT_DIR/../}" - - # Update the ABI file path in subgraph.yaml using an inline environment variable. - contractFile="$contractFile" yq -i ".dataSources[$dataSourceIndex].mapping.abis[0].file = env(contractFile)" "$SCRIPT_DIR/../subgraph.yaml" - - # Update the network field using the provided graphNetwork value. - graphNetwork="$graphNetwork" yq -i ".dataSources[$dataSourceIndex].network = env(graphNetwork)" "$SCRIPT_DIR/../subgraph.yaml" - - # Extract the address and start block from the artifact using jq. - local address - address=$(jq '.address' "$f") - yq -i ".dataSources[$dataSourceIndex].source.address = $address" "$SCRIPT_DIR/../subgraph.yaml" - - local blockNumber - blockNumber=$(jq '.receipt.blockNumber' "$f") - yq -i ".dataSources[$dataSourceIndex].source.startBlock = $blockNumber" "$SCRIPT_DIR/../subgraph.yaml" -} - -# Parameters: -# $1: hardhatNetwork (default: sepolia) -# $2: graphNetwork (default: sepolia) -# $3: contractFileSuffix (optional; default: empty string) -hardhatNetwork="${1:-sepolia}" -graphNetwork="${2:-sepolia}" -contractFileSuffix="${3:-}" # default is now an empty string -i=0 - -# Backup the current subgraph.yaml file. -cp "$SCRIPT_DIR/../subgraph.yaml" "$SCRIPT_DIR/../subgraph.yaml.bak.$(date +%s)" - -# Iterate over each data source defined in subgraph.yaml. -for contract in $(yq .dataSources[].name "$SCRIPT_DIR/../subgraph.yaml"); do - update "$SCRIPT_DIR/../../contracts/deployments/$hardhatNetwork/${contract}${contractFileSuffix}.json" "$i" "$graphNetwork" - (( i++ )) done + +echo "Done! subgraph.yaml is now pointing at $hardhatNetwork artifacts. Backup saved as subgraph.yaml.bak.." diff --git a/veascan-subgraph-outbox/src/VeaOutbox.ts b/veascan-subgraph-outbox/src/VeaOutbox.ts index 53fdfd11..66106bd8 100644 --- a/veascan-subgraph-outbox/src/VeaOutbox.ts +++ b/veascan-subgraph-outbox/src/VeaOutbox.ts @@ -5,7 +5,7 @@ import { MessageRelayed, Verified, VerificationStarted, -} from "../generated/VeaOutboxArbToEthDevnet/VeaOutboxArbToEthDevnet"; +} from "../generated/VeaOutboxArbToGnosisDevnet/VeaOutboxArbToGnosisDevnet"; import { Challenge, Claim, @@ -78,7 +78,7 @@ export function handleVerificationStarted(event: VerificationStarted): void { ) { const claimId = event.address.toHexString() + "-" + i.toString(); const claim = Claim.load(claimId); - if (claim?.epoch.equals(event.params._epoch)) { + if (claim && claim.epoch.equals(event.params._epoch)) { const verification = new Verification(claim.id); verification.claim = claim.id; verification.startTimestamp = event.block.timestamp; @@ -99,7 +99,7 @@ export function handleVerified(event: Verified): void { ) { const claimId = event.address.toHexString() + "-" + i.toString(); const claim = Claim.load(claimId); - if (claim?.epoch.equals(event.params._epoch)) { + if (claim && claim.epoch.equals(event.params._epoch)) { claim.verified = true; claim.save(); diff --git a/veascan-subgraph-outbox/subgraph.yaml b/veascan-subgraph-outbox/subgraph.yaml index 4ee86650..d68c9363 100644 --- a/veascan-subgraph-outbox/subgraph.yaml +++ b/veascan-subgraph-outbox/subgraph.yaml @@ -3,12 +3,12 @@ schema: file: ./schema.graphql dataSources: - kind: ethereum - name: VeaOutboxArbToEthTestnet - network: sepolia + name: VeaOutboxArbToGnosisDevnet + network: gnosis-chiado source: - address: "0xC0574e973059e727E5E4bEB2e04F1D69F627faab" - abi: VeaOutboxArbToEthTestnet - startBlock: 8047848 + address: "0xE24B2838962207F585F4fa5C5bE3e1AcA43a1a1B" + abi: VeaOutboxArbToGnosisDevnet + startBlock: 14598540 mapping: kind: ethereum/events apiVersion: 0.0.7 @@ -18,10 +18,9 @@ dataSources: - Claimed - MessageRelayed - Verified - - VerificationStarted abis: - - name: VeaOutboxArbToEthTestnet - file: ../contracts/deployments/sepolia/VeaOutboxArbToEthTestnet.json + - name: VeaOutboxArbToGnosisDevnet + file: ../contracts/deployments/chiado/VeaOutboxArbToGnosisDevnet.json eventHandlers: - event: Challenged(indexed uint256,indexed address) handler: handleChallenged @@ -35,12 +34,12 @@ dataSources: handler: handleVerificationStarted file: ./src/VeaOutbox.ts - kind: ethereum - name: VeaOutboxArbToEthDevnet - network: sepolia + name: VeaOutboxArbToGnosisTestnet + network: gnosis-chiado source: - address: "0xb1f5125b52CE23D3763AC1C9ACEf0668825A66c0" - abi: VeaOutboxArbToEthDevnet - startBlock: 7825233 + address: "0x1c35dF16AAde8Fcf1D56Bca00B3c8Ef451113DfC" + abi: VeaOutboxArbToGnosisTestnet + startBlock: 15109734 mapping: kind: ethereum/events apiVersion: 0.0.7 @@ -50,10 +49,9 @@ dataSources: - Claimed - MessageRelayed - Verified - - VerificationStarted abis: - - name: VeaOutboxArbToEthDevnet - file: ../contracts/deployments/sepolia/VeaOutboxArbToEthDevnet.json + - name: VeaOutboxArbToGnosisTestnet + file: ../contracts/deployments/chiado/VeaOutboxArbToGnosisTestnet.json eventHandlers: - event: Challenged(indexed uint256,indexed address) handler: handleChallenged diff --git a/veascan-web/.env.public b/veascan-web/.env.public index a7f44f43..6abdeaa9 100644 --- a/veascan-web/.env.public +++ b/veascan-web/.env.public @@ -1,3 +1,4 @@ # Subgraph endpoints for veascan, Example: "85918/vea-inbox-arb-sepolia-devnet/version/latest" -export VEASCAN_INBOX_SUBGRAPH=61738/veascan-inbox-arb-sepolia/version/latest -export VEASCAN_OUTBOX_SUBGRAPH=61738/veascan-outbox-sepolia/version/latest +export VEASCAN_INBOX_SUBGRAPH_ARBSEPOLIA=61738/veascan-inbox-arb-sepolia/version/latest +export VEASCAN_OUTBOX_SUBGRAPH_CHIADO=61738/veascan-outbox-chiado/version/latest +export VEASCAN_OUTBOX_SUBGRAPH_SEPOLIA=61738/veascan-outbox-sepolia/version/latest diff --git a/veascan-web/codegen.ts b/veascan-web/codegen.ts index c276cd79..ab048131 100644 --- a/veascan-web/codegen.ts +++ b/veascan-web/codegen.ts @@ -3,8 +3,9 @@ import type { CodegenConfig } from "@graphql-codegen/cli"; const config: CodegenConfig = { overwrite: true, schema: [ - `https://api.studio.thegraph.com/query/${process.env.VEASCAN_INBOX_SUBGRAPH}`, - `https://api.studio.thegraph.com/query/${process.env.VEASCAN_OUTBOX_SUBGRAPH}`, + `https://api.studio.thegraph.com/query/${process.env.VEASCAN_INBOX_SUBGRAPH_ARBSEPOLIA}`, + `https://api.studio.thegraph.com/query/${process.env.VEASCAN_OUTBOX_SUBGRAPH_CHIADO}`, + `https://api.studio.thegraph.com/query/${process.env.VEASCAN_OUTBOX_SUBGRAPH_SEPOLIA}`, ], documents: "src/hooks/queries/*.ts", generates: { diff --git a/veascan-web/src/consts/bridges.ts b/veascan-web/src/consts/bridges.ts index 494e3f70..9a8708cb 100644 --- a/veascan-web/src/consts/bridges.ts +++ b/veascan-web/src/consts/bridges.ts @@ -3,6 +3,11 @@ import VeaOutboxSepoliaDevnet from "@kleros/vea-contracts/deployments/sepolia/Ve import VeaInboxArbitrumSepoliaTestnet from "@kleros/vea-contracts/deployments/arbitrumSepolia/VeaInboxArbToEthTestnet.json"; import VeaOutboxArbitrumSepoliaTestnet from "@kleros/vea-contracts/deployments/sepolia/VeaOutboxArbToEthTestnet.json"; +import VeaInboxArbitrumSepoliaDevnetGnosis from "@kleros/vea-contracts/deployments/arbitrumSepolia/VeaInboxArbToGnosisDevnet.json"; +import VeaOutboxSepoliaDevnetGnosis from "@kleros/vea-contracts/deployments/chiado/VeaOutboxArbToGnosisDevnet.json"; +import VeaInboxArbitrumSepoliaTestnetGnosis from "@kleros/vea-contracts/deployments/arbitrumSepolia/VeaInboxArbToGnosisTestnet.json"; +import VeaOutboxArbitrumSepoliaTestnetGnosis from "@kleros/vea-contracts/deployments/chiado/VeaOutboxArbToGnosisTestnet.json"; + import { Chain, arbitrumSepolia, @@ -34,6 +39,17 @@ const arbToEthContracts: { [key in Network]: VeaContracts } = { }, }; +const arbToGnosisContracts: { [key in Network]: VeaContracts } = { + [Network.DEVNET]: { + veaInbox: VeaInboxArbitrumSepoliaDevnetGnosis.address as `0x${string}`, + veaOutbox: VeaOutboxSepoliaDevnetGnosis.address as `0x${string}`, + }, + [Network.TESTNET]: { + veaInbox: VeaInboxArbitrumSepoliaTestnetGnosis.address as `0x${string}`, + veaOutbox: VeaOutboxArbitrumSepoliaTestnetGnosis.address as `0x${string}`, + }, +}; + export interface IChain extends Chain { logo: React.FC>; } @@ -62,8 +78,16 @@ export const bridges: IBridge[] = [ from: arbitrumSepolia.id, to: sepolia.id, contracts: arbToEthContracts, - inboxEndpoint: `https://api.studio.thegraph.com/query/${process.env.VEASCAN_INBOX_SUBGRAPH}`, - outboxEndpoint: `https://api.studio.thegraph.com/query/${process.env.VEASCAN_OUTBOX_SUBGRAPH}`, + inboxEndpoint: `https://api.studio.thegraph.com/query/${process.env.VEASCAN_INBOX_SUBGRAPH_ARBSEPOLIA}`, + outboxEndpoint: `https://api.studio.thegraph.com/query/${process.env.VEASCAN_OUTBOX_SUBGRAPH_SEPOLIA}`, + }, + { + id: 1, + from: arbitrumSepolia.id, + to: gnosisChiado.id, + contracts: arbToGnosisContracts, + inboxEndpoint: `https://api.studio.thegraph.com/query/${process.env.VEASCAN_INBOX_SUBGRAPH_ARBSEPOLIA}`, + outboxEndpoint: `https://api.studio.thegraph.com/query/${process.env.VEASCAN_OUTBOX_SUBGRAPH_CHIADO}`, }, ];