22
33SCRIPT_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
2944for contract in $( yq .dataSources[].name " $SCRIPT_DIR " /../subgraph.yaml)
3045do
31- update " $SCRIPT_DIR /../../contracts/deployments/ $ hardhatNetwork/ $contract .json " $i $graphNetwork
46+ update $ hardhatNetwork $graphNetwork $i $contract
3247 (( ++ i ))
3348done
0 commit comments