Skip to content

Commit a861cc3

Browse files
committed
fix: subgraph update script
1 parent 5c75b57 commit a861cc3

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

subgraph/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"update:arbitrum-goerli": "./scripts/update.sh arbitrumGoerli arbitrum-goerli",
66
"update:arbitrum-goerli-devnet": "./scripts/update.sh arbitrumGoerliDevnet arbitrum-goerli",
77
"update:arbitrum": "./scripts/update.sh arbitrum arbitrum",
8+
"update:local": "./scripts/update.sh localhost mainnet",
89
"codegen": "graph codegen",
910
"build": "graph build",
1011
"clean": "graph clean && rm subgraph.yaml.bak.*",
@@ -14,7 +15,7 @@
1415
"create-local": "graph create --node http://localhost:8020/ kleros/kleros-v2-core-local",
1516
"remove-local": "graph remove --node http://localhost:8020/ kleros/kleros-v2-core-local",
1617
"deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 kleros/kleros-v2-core-local --version-label v$(date +%s)",
17-
"rebuild-deploy-local": "./scripts/update.sh localhost mainnet && yarn codegen && yarn create-local && yarn deploy-local",
18+
"rebuild-deploy-local": "yarn update:local && yarn codegen && yarn create-local && yarn deploy-local",
1819
"start-local-indexer": "docker compose -f ../services/graph-node/docker-compose.yml up -d && docker compose -f ../services/graph-node/docker-compose.yml logs -f",
1920
"stop-local-indexer": "docker compose -f ../services/graph-node/docker-compose.yml down && rm -rf ../services/graph-node/data"
2021
},

subgraph/scripts/update.sh

+25-10
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,33 @@
22

33
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
44

5-
function update() #file #dataSourceIndex #graphNetwork
5+
function update() #hardhatNetwork #graphNetwork #dataSourceIndex #contract
66
{
7-
local f="$1"
8-
local dataSourceIndex="$2"
9-
10-
graphNetwork=$3 yq -i ".dataSources[$dataSourceIndex].network=env(graphNetwork)" "$SCRIPT_DIR"/../subgraph.yaml
7+
local hardhatNetwork="$1"
8+
local graphNetwork="$2"
9+
local dataSourceIndex="$3"
10+
local contract="$4"
11+
local artifact="$SCRIPT_DIR/../../contracts/deployments/$hardhatNetwork/$contract.json"
12+
13+
# Set the address
14+
address=$(cat "$artifact" | jq '.address')
15+
yq -i ".dataSources[$dataSourceIndex].source.address=$address" "$SCRIPT_DIR"/../subgraph.yaml
16+
17+
# Set the start block
18+
blockNumber="$(cat "$artifact" | jq '.receipt.blockNumber')"
19+
yq -i ".dataSources[$dataSourceIndex].source.startBlock=$blockNumber" "$SCRIPT_DIR"/../subgraph.yaml
1120

12-
address=$(cat "$f" | jq '.address')
13-
yq -i ".dataSources[$dataSourceIndex].source.address=$address" "$SCRIPT_DIR"/../subgraph.yaml
21+
# Set the Graph network
22+
graphNetwork=$graphNetwork yq -i ".dataSources[$dataSourceIndex].network=env(graphNetwork)" "$SCRIPT_DIR"/../subgraph.yaml
1423

15-
blockNumber="$(cat "$f" | jq '.receipt.blockNumber')"
16-
yq -i ".dataSources[$dataSourceIndex].source.startBlock=$blockNumber" "$SCRIPT_DIR"/../subgraph.yaml
24+
# Set the ABIs path for this Hardhat network
25+
abiIndex=0
26+
for f in $(yq e .dataSources[$dataSourceIndex].mapping.abis[].file subgraph.yaml -o json -I 0 | jq -sr '.[]')
27+
do
28+
f2=$(echo $f | sed "s|\(.*\/deployments\/\).*\/|\1$hardhatNetwork\/|")
29+
yq -i ".dataSources[$dataSourceIndex].mapping.abis[$abiIndex].file=\"$f2\"" "$SCRIPT_DIR"/../subgraph.yaml
30+
(( ++abiIndex ))
31+
done
1732
}
1833

1934
# as per ../contracts/hardhat.config.js
@@ -28,6 +43,6 @@ cp "$SCRIPT_DIR"/../subgraph.yaml "$SCRIPT_DIR"/../subgraph.yaml.bak.$(date +%s)
2843

2944
for contract in $(yq .dataSources[].name "$SCRIPT_DIR"/../subgraph.yaml)
3045
do
31-
update "$SCRIPT_DIR/../../contracts/deployments/$hardhatNetwork/$contract.json" $i $graphNetwork
46+
update $hardhatNetwork $graphNetwork $i $contract
3247
(( ++i ))
3348
done

0 commit comments

Comments
 (0)