2
2
3
3
SCRIPT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " > /dev/null 2>&1 && pwd ) "
4
4
5
- function update() # file # dataSourceIndex #graphNetwork
5
+ function update() # hardhatNetwork #graphNetwork # dataSourceIndex #contract
6
6
{
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
11
20
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
14
23
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
17
32
}
18
33
19
34
# as per ../contracts/hardhat.config.js
@@ -28,6 +43,6 @@ cp "$SCRIPT_DIR"/../subgraph.yaml "$SCRIPT_DIR"/../subgraph.yaml.bak.$(date +%s)
28
43
29
44
for contract in $( yq .dataSources[].name " $SCRIPT_DIR " /../subgraph.yaml)
30
45
do
31
- update " $SCRIPT_DIR /../../contracts/deployments/ $ hardhatNetwork/ $contract .json " $i $graphNetwork
46
+ update $ hardhatNetwork $graphNetwork $i $contract
32
47
(( ++ i ))
33
48
done
0 commit comments