Skip to content

Commit

Permalink
Create deploy_gen_network_files.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
sambacha authored Dec 5, 2024
1 parent 1abd946 commit 104c181
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions scripts/deploy_gen_network_files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

set -o errexit -o pipefail -o nounset

repo_root_dir="$(git rev-parse --show-toplevel)"

for deployment in "$repo_root_dir/broadcast/"*"/"*"/"*".json"; do
# The subfolder name is the chain id
chain_id=${deployment%/*}
chain_id=${chain_id##*/}

# First, every single deployment is formatted as if it had its own networks.json
jq --arg chainId "$chain_id" '
.transactions[]
| select(.transactionType == "CREATE")
| select(.hash != null)
| {(.contractName): {($chainId): {address: .contractAddress, transactionHash: .hash }}}
' <"$deployment"
done \
| # Then, all these single-contract single-chain-id networks.jsons are merged. Note: in case the same contract is
# deployed twice in the same script run, the last deployed contract takes priority.
jq --sort-keys --null-input 'reduce inputs as $item ({}; . *= $item)'

# Todo: handle case where the same contract is deployed on multiple chains.

0 comments on commit 104c181

Please sign in to comment.