Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Rekard0 committed Feb 7, 2025
1 parent b7d7d36 commit 865ddd8
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 29 deletions.
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,5 @@ deployments

generated

# artifacts
temp_repo
packages/artifacts/src/abis/abis.ts
#artifacts
packages/artifacts/src/abi.ts
36 changes: 14 additions & 22 deletions packages/artifacts/prepare-abi.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env bash

set -e # Exit on error
# Exit on error
set -e

# Define directories
# Constants
CONTRACTS_FOLDER="../contracts"
JSON_ABI_FOLDER="./src/abi"
TARGET_ABI_FILE="./src/abi.ts"

# Move into contracts package and install dependencies
Expand All @@ -15,29 +15,21 @@ yarn install && yarn build
# Move back to artifacts package
cd - > /dev/null

# Ensure the output directory exists
rm -Rf $JSON_ABI_FOLDER
mkdir -p $JSON_ABI_FOLDER
# Wipe the destination file
echo > $TARGET_ABI_FILE

# Extract the abi field into new JSON files
for SRC_CONTRACT in $(ls $CONTRACTS_FOLDER/src/*.sol )
# Extract the abi field and create a TS file
for SRC_CONTRACT_FILE in $(ls $CONTRACTS_FOLDER/src/*.sol )
do
FILE=$(basename $(echo $SRC_CONTRACT))
cat $CONTRACTS_FOLDER/artifacts/src/$FILE/${FILE%".sol"}.json | jq ".abi" > $JSON_ABI_FOLDER/${FILE%".sol"}.json
done

# Write the main ABI file
echo "// NOTE: This file is autogenerated. Do not manually edit it" > $TARGET_ABI_FILE
echo "" >> $TARGET_ABI_FILE
SRC_FILE_NAME=$(basename $(echo $SRC_CONTRACT_FILE))
SRC_FILE_PATH=$CONTRACTS_FOLDER/artifacts/src/$SRC_FILE_NAME/${SRC_FILE_NAME%".sol"}.json

for ABI_FILE in $(ls $JSON_ABI_FOLDER)
do
CONTRACT_NAME=${ABI_FILE%".json"}
echo "Importing $CONTRACT_NAME from $TARGET_ABI_FILE"
ABI=$(node -e "console.log(JSON.stringify(JSON.parse(fs.readFileSync(\"$SRC_FILE_PATH\").toString()).abi))")
CONTRACT_NAME=${SRC_FILE_NAME%".sol"}

echo "import * as ${CONTRACT_NAME}ABI from \"./abi/$ABI_FILE\";" >> $TARGET_ABI_FILE
echo "export {${CONTRACT_NAME}ABI}" >> $TARGET_ABI_FILE
echo "const ${CONTRACT_NAME}ABI = $ABI as const;" >> $TARGET_ABI_FILE
echo "export {${CONTRACT_NAME}ABI};" >> $TARGET_ABI_FILE
echo "" >> $TARGET_ABI_FILE
done

echo "ABI prepared: $JSON_ABI_FOLDER"
echo "ABI prepared: $TARGET_ABI_FILE"
2 changes: 1 addition & 1 deletion packages/artifacts/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './abis/abis';
export * from './abi';
export { default as addresses } from './addresses.json';
5 changes: 3 additions & 2 deletions packages/artifacts/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
"compilerOptions": {
"target": "ES6",
"module": "commonjs",
"declaration": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"declaration": true,
"outDir": "./dist"
"outDir": "./dist",
},
"include": ["src"]
}

2 changes: 1 addition & 1 deletion packages/artifacts/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# yarn lockfile v1


typescript@^5.5.4:
typescript@^5.7.3:
version "5.7.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.7.3.tgz#919b44a7dbb8583a9b856d162be24a54bf80073e"
integrity sha512-84MVSjMEHP+FQRPy3pX9sTVV/INIex71s9TL2Gm5FG/WG1SqXeKyZ0k7/blY/4FdOzI12CBy1vGc4og/eus0fw==

0 comments on commit 865ddd8

Please sign in to comment.