Skip to content

Commit

Permalink
fix: subgraph update script
Browse files Browse the repository at this point in the history
  • Loading branch information
jaybuidl committed Sep 9, 2023
1 parent 66dce00 commit 7d90db7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
3 changes: 2 additions & 1 deletion subgraph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"update:arbitrum-goerli": "./scripts/update.sh arbitrumGoerli arbitrum-goerli",
"update:arbitrum-goerli-devnet": "./scripts/update.sh arbitrumGoerliDevnet arbitrum-goerli",
"update:arbitrum": "./scripts/update.sh arbitrum arbitrum",
"update:local": "./scripts/update.sh localhost mainnet",
"codegen": "graph codegen",
"build": "graph build",
"clean": "graph clean && rm subgraph.yaml.bak.*",
Expand All @@ -14,7 +15,7 @@
"create-local": "graph create --node http://localhost:8020/ kleros/kleros-v2-core-local",
"remove-local": "graph remove --node http://localhost:8020/ kleros/kleros-v2-core-local",
"deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 kleros/kleros-v2-core-local --version-label v$(date +%s)",
"rebuild-deploy-local": "./scripts/update.sh localhost mainnet && yarn codegen && yarn create-local && yarn deploy-local",
"rebuild-deploy-local": "yarn update:local && yarn codegen && yarn create-local && yarn deploy-local",
"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",
"stop-local-indexer": "docker compose -f ../services/graph-node/docker-compose.yml down && rm -rf ../services/graph-node/data"
},
Expand Down
35 changes: 25 additions & 10 deletions subgraph/scripts/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,33 @@

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

function update() #file #dataSourceIndex #graphNetwork
function update() #hardhatNetwork #graphNetwork #dataSourceIndex #contract
{
local f="$1"
local dataSourceIndex="$2"

graphNetwork=$3 yq -i ".dataSources[$dataSourceIndex].network=env(graphNetwork)" "$SCRIPT_DIR"/../subgraph.yaml
local hardhatNetwork="$1"
local graphNetwork="$2"
local dataSourceIndex="$3"
local contract="$4"
local artifact="$SCRIPT_DIR/../../contracts/deployments/$hardhatNetwork/$contract.json"

# Set the address
address=$(cat "$artifact" | jq '.address')
yq -i ".dataSources[$dataSourceIndex].source.address=$address" "$SCRIPT_DIR"/../subgraph.yaml

# Set the start block
blockNumber="$(cat "$artifact" | jq '.receipt.blockNumber')"
yq -i ".dataSources[$dataSourceIndex].source.startBlock=$blockNumber" "$SCRIPT_DIR"/../subgraph.yaml

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

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

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

for contract in $(yq .dataSources[].name "$SCRIPT_DIR"/../subgraph.yaml)
do
update "$SCRIPT_DIR/../../contracts/deployments/$hardhatNetwork/$contract.json" $i $graphNetwork
update $hardhatNetwork $graphNetwork $i $contract
(( ++i ))
done

0 comments on commit 7d90db7

Please sign in to comment.