Skip to content

Chore/arb to gnosis subgraphs and veascan config #426

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion veascan-subgraph-inbox/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kleros/veascan-subgraph-inbox",
"version": "0.2.3",
"version": "0.2.4",
"license": "MIT",
"engines": {
"node": ">=18.0.0"
Expand Down
8 changes: 4 additions & 4 deletions veascan-subgraph-inbox/src/VeaInbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
BigInt,
ByteArray,
Bytes,
log,
dataSource,
} from "@graphprotocol/graph-ts";
import { Snapshot, Message, Ref, Fallback, Inbox } from "../generated/schema";
import {
Expand Down Expand Up @@ -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;
Expand Down
56 changes: 56 additions & 0 deletions veascan-subgraph-inbox/subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
126 changes: 86 additions & 40 deletions veascan-subgraph-outbox/scripts/update.sh
Original file line number Diff line number Diff line change
@@ -1,45 +1,91 @@
#!/usr/bin/env bash
set -euo pipefail

#
# scripts/update.sh
#
# Usage:
# ./scripts/update.sh <hardhatNetwork> <graphNetwork> [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 <hardhatNetwork> <graphNetwork> [contractFileSuffix]"}"
graphNetwork="${2:?"Usage: $0 <hardhatNetwork> <graphNetwork> [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.<timestamp>."
6 changes: 3 additions & 3 deletions veascan-subgraph-outbox/src/VeaOutbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
MessageRelayed,
Verified,
VerificationStarted,
} from "../generated/VeaOutboxArbToEthDevnet/VeaOutboxArbToEthDevnet";
} from "../generated/VeaOutboxArbToGnosisDevnet/VeaOutboxArbToGnosisDevnet";
import {
Challenge,
Claim,
Expand Down Expand Up @@ -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;
Expand All @@ -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();

Expand Down
30 changes: 14 additions & 16 deletions veascan-subgraph-outbox/subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions veascan-web/.env.public
Original file line number Diff line number Diff line change
@@ -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
5 changes: 3 additions & 2 deletions veascan-web/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
28 changes: 26 additions & 2 deletions veascan-web/src/consts/bridges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<React.SVGAttributes<SVGElement>>;
}
Expand Down Expand Up @@ -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}`,
},
];

Expand Down
Loading