|
1 | 1 | #!/usr/bin/env bash
|
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +# |
| 5 | +# scripts/update.sh |
| 6 | +# |
| 7 | +# Usage: |
| 8 | +# ./scripts/update.sh <hardhatNetwork> <graphNetwork> [contractFileSuffix] |
| 9 | +# |
| 10 | +# hardhatNetwork: either "sepolia" or "chiado" |
| 11 | +# graphNetwork: the same string to write into subgraph.yaml → .network (e.g. "sepolia" or "chiado") |
| 12 | +# |
2 | 13 |
|
3 | 14 | SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
| 15 | +SUBGRAPH_YAML="$SCRIPT_DIR/../subgraph.yaml" |
| 16 | +VEAOUTBOX_TS="$SCRIPT_DIR/../src/VeaOutbox.ts" |
| 17 | + |
| 18 | +hardhatNetwork="${1:?"Usage: $0 <hardhatNetwork> <graphNetwork> [contractFileSuffix]"}" |
| 19 | +graphNetwork="${2:?"Usage: $0 <hardhatNetwork> <graphNetwork> [contractFileSuffix]"}" |
| 20 | +contractFileSuffix="${3:-}" |
| 21 | + |
| 22 | +# Back up the original subgraph.yaml |
| 23 | +cp "$SUBGRAPH_YAML" "$SUBGRAPH_YAML".bak."$(date +%s)" |
| 24 | + |
| 25 | +count=$(yq '.dataSources | length' "$SUBGRAPH_YAML") |
| 26 | + |
| 27 | +for i in $(seq 0 $((count - 1))); do |
| 28 | + origName="$(yq -r ".dataSources[$i].name" "$SUBGRAPH_YAML")" |
| 29 | + newName="$origName" |
| 30 | + |
| 31 | + if [[ "$hardhatNetwork" == "sepolia" ]]; then |
| 32 | + if [[ "$origName" == *"ArbToGnosisDevnet"* ]]; then |
| 33 | + newName="${origName/ArbToGnosisDevnet/ArbToEthDevnet}" |
| 34 | + elif [[ "$origName" == *"ArbToGnosisTestnet"* ]]; then |
| 35 | + newName="${origName/ArbToGnosisTestnet/ArbToEthTestnet}" |
| 36 | + fi |
| 37 | + |
| 38 | + # Patch VeaOutbox.ts: swap Gnosis imports to Eth imports when targeting sepolia |
| 39 | + sed -i "" \ |
| 40 | + -e 's|from "../generated/VeaOutboxArbToGnosisDevnet/VeaOutboxArbToGnosisDevnet";|from "../generated/VeaOutboxArbToEthDevnet/VeaOutboxArbToEthDevnet";|' \ |
| 41 | + -e 's|from "../generated/VeaOutboxArbToGnosisTestnet/VeaOutboxArbToGnosisTestnet";|from "../generated/VeaOutboxArbToEthTestnet/VeaOutboxArbToEthTestnet";|' \ |
| 42 | + "$VEAOUTBOX_TS" |
| 43 | + |
| 44 | + |
| 45 | + elif [[ "$hardhatNetwork" == "chiado" ]]; then |
| 46 | + if [[ "$origName" == *"ArbToEthDevnet"* ]]; then |
| 47 | + newName="${origName/ArbToEthDevnet/ArbToGnosisDevnet}" |
| 48 | + elif [[ "$origName" == *"ArbToEthTestnet"* ]]; then |
| 49 | + newName="${origName/ArbToEthTestnet/ArbToGnosisTestnet}" |
| 50 | + fi |
| 51 | + |
| 52 | + |
| 53 | + # Patch VeaOutbox.ts: swap Eth imports to Gnosis imports when targeting chiado |
| 54 | + sed -i "" \ |
| 55 | + -e 's|from "../generated/VeaOutboxArbToEthDevnet/VeaOutboxArbToEthDevnet";|from "../generated/VeaOutboxArbToGnosisDevnet/VeaOutboxArbToGnosisDevnet";|' \ |
| 56 | + -e 's|from "../generated/VeaOutboxArbToEthTestnet/VeaOutboxArbToEthTestnet";|from "../generated/VeaOutboxArbToGnosisTestnet/VeaOutboxArbToGnosisTestnet";|' \ |
| 57 | + "$VEAOUTBOX_TS" |
| 58 | + fi |
| 59 | + artifact="$SCRIPT_DIR/../../contracts/deployments/$hardhatNetwork/${newName}${contractFileSuffix}.json" |
| 60 | + |
| 61 | + if [[ ! -f "$artifact" ]]; then |
| 62 | + echo "Artifact not found for dataSource[$i]:" |
| 63 | + exit 1 |
| 64 | + fi |
| 65 | + |
| 66 | + yq -i ".dataSources[$i].name = \"$newName\"" "$SUBGRAPH_YAML" |
| 67 | + |
| 68 | + yq -i ".dataSources[$i].mapping.abis[0].name = \"$newName\"" "$SUBGRAPH_YAML" |
| 69 | + |
| 70 | + relative_abi_file="../contracts/deployments/$hardhatNetwork/${newName}${contractFileSuffix}.json" |
| 71 | + yq -i ".dataSources[$i].mapping.abis[0].file = \"$relative_abi_file\"" "$SUBGRAPH_YAML" |
| 72 | + |
| 73 | + yq -i ".dataSources[$i].source.abi = \"$newName\"" "$SUBGRAPH_YAML" |
| 74 | + |
| 75 | + if [[ "$graphNetwork" == "chiado" ]]; then |
| 76 | + yq -i ".dataSources[$i].network = \"gnosis-chiado\"" "$SUBGRAPH_YAML" |
| 77 | + else |
| 78 | + yq -i ".dataSources[$i].network = \"$graphNetwork\"" "$SUBGRAPH_YAML" |
| 79 | + fi |
| 80 | + |
| 81 | + address="$(jq -r '.address' "$artifact")" |
| 82 | + yq -i ".dataSources[$i].source.address = \"$address\"" "$SUBGRAPH_YAML" |
| 83 | + |
| 84 | + |
| 85 | + blockNumber="$(jq '.receipt.blockNumber' "$artifact")" |
| 86 | + yq -i ".dataSources[$i].source.startBlock = $blockNumber" "$SUBGRAPH_YAML" |
4 | 87 |
|
5 |
| -function update() { # Parameters: file, dataSourceIndex, graphNetwork |
6 |
| - local f="$1" |
7 |
| - local dataSourceIndex="$2" |
8 |
| - local graphNetwork="$3" |
9 |
| - |
10 |
| - # Compute the contract file path relative to the subgraph.yaml file. |
11 |
| - local contractFile="${f#$SCRIPT_DIR/../}" |
12 |
| - |
13 |
| - # Update the ABI file path in subgraph.yaml using an inline environment variable. |
14 |
| - contractFile="$contractFile" yq -i ".dataSources[$dataSourceIndex].mapping.abis[0].file = env(contractFile)" "$SCRIPT_DIR/../subgraph.yaml" |
15 |
| - |
16 |
| - # Update the network field using the provided graphNetwork value. |
17 |
| - graphNetwork="$graphNetwork" yq -i ".dataSources[$dataSourceIndex].network = env(graphNetwork)" "$SCRIPT_DIR/../subgraph.yaml" |
18 |
| - |
19 |
| - # Extract the address and start block from the artifact using jq. |
20 |
| - local address |
21 |
| - address=$(jq '.address' "$f") |
22 |
| - yq -i ".dataSources[$dataSourceIndex].source.address = $address" "$SCRIPT_DIR/../subgraph.yaml" |
23 |
| - |
24 |
| - local blockNumber |
25 |
| - blockNumber=$(jq '.receipt.blockNumber' "$f") |
26 |
| - yq -i ".dataSources[$dataSourceIndex].source.startBlock = $blockNumber" "$SCRIPT_DIR/../subgraph.yaml" |
27 |
| -} |
28 |
| - |
29 |
| -# Parameters: |
30 |
| -# $1: hardhatNetwork (default: sepolia) |
31 |
| -# $2: graphNetwork (default: sepolia) |
32 |
| -# $3: contractFileSuffix (optional; default: empty string) |
33 |
| -hardhatNetwork="${1:-sepolia}" |
34 |
| -graphNetwork="${2:-sepolia}" |
35 |
| -contractFileSuffix="${3:-}" # default is now an empty string |
36 |
| -i=0 |
37 |
| - |
38 |
| -# Backup the current subgraph.yaml file. |
39 |
| -cp "$SCRIPT_DIR/../subgraph.yaml" "$SCRIPT_DIR/../subgraph.yaml.bak.$(date +%s)" |
40 |
| - |
41 |
| -# Iterate over each data source defined in subgraph.yaml. |
42 |
| -for contract in $(yq .dataSources[].name "$SCRIPT_DIR/../subgraph.yaml"); do |
43 |
| - update "$SCRIPT_DIR/../../contracts/deployments/$hardhatNetwork/${contract}${contractFileSuffix}.json" "$i" "$graphNetwork" |
44 |
| - (( i++ )) |
45 | 88 | done
|
| 89 | + |
| 90 | +echo "Done! subgraph.yaml is now pointing at $hardhatNetwork artifacts. Backup saved as subgraph.yaml.bak.<timestamp>." |
0 commit comments