Skip to content

Commit

Permalink
update prepare-abi script
Browse files Browse the repository at this point in the history
  • Loading branch information
Rekard0 committed Feb 11, 2025
1 parent 931e22f commit eecd147
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/artifacts/prepare-abi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ cd - > /dev/null
echo "// NOTE: Do not edit this file. It is generated automatically and it will be eventually wiped." > $TARGET_ABI_FILE

# Extract the abi field and create a TS file
for SRC_CONTRACT_FILE in $(ls $CONTRACTS_FOLDER/src/*.sol )
find $CONTRACTS_FOLDER/src -type f -name "*.sol" ! -path "*/mocks/*" | while read -r SRC_CONTRACT_FILE
do
SRC_FILE_NAME=$(basename $(echo $SRC_CONTRACT_FILE))
SRC_FILE_PATH=$CONTRACTS_FOLDER/artifacts/src/$SRC_FILE_NAME/${SRC_FILE_NAME%".sol"}.json
SRC_FILE_NAME=$(basename "$SRC_CONTRACT_FILE")
RELATIVE_PATH=${SRC_CONTRACT_FILE#"$CONTRACTS_FOLDER/src/"}

# Adjusting the artifact path to match the directory structure
ARTIFACT_PATH="$CONTRACTS_FOLDER/artifacts/src/${RELATIVE_PATH%".sol"}.sol/${SRC_FILE_NAME%".sol"}.json"

ABI=$(node -e "console.log(JSON.stringify(JSON.parse(fs.readFileSync(\"$SRC_FILE_PATH\").toString()).abi))")
ABI=$(node -e "console.log(JSON.stringify(JSON.parse(fs.readFileSync(\"$ARTIFACT_PATH\").toString()).abi))")
CONTRACT_NAME=${SRC_FILE_NAME%".sol"}

echo "const ${CONTRACT_NAME}ABI = $ABI as const;" >> $TARGET_ABI_FILE
Expand Down

0 comments on commit eecd147

Please sign in to comment.