forked from ethereum-optimism/optimism
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_bindings.sh
executable file
·51 lines (40 loc) · 1.08 KB
/
gen_bindings.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#/bin/bash
set -eu
CONTRACTS_PATH="../packages/contracts-bedrock/"
if [ "$#" -ne 2 ]; then
echo "This script takes 2 arguments - CONTRACT_NAME PACKAGE"
exit 1
fi
need_cmd() {
if ! command -v "$1" > /dev/null 2>&1; then
echo "need '$1' (command not found)"
exit 1
fi
}
need_cmd forge
need_cmd abigen
NAME=$1
# This can handle both fully qualified syntax or just
# the name of the contract.
# Fully qualified: path-to-contract-file:contract-name
TYPE=$(echo "$NAME" | cut -d ':' -f2)
PACKAGE=$2
# Convert to lower case to respect golang package naming conventions
TYPE_LOWER=$(echo ${TYPE} | tr '[:upper:]' '[:lower:]')
FILENAME="${TYPE_LOWER}_deployed.go"
mkdir -p bin
TEMP=$(mktemp -d)
CWD=$(pwd)
# Build contracts
cd ${CONTRACTS_PATH}
forge inspect ${NAME} abi > ${TEMP}/${TYPE}.abi
forge inspect ${NAME} bytecode > ${TEMP}/${TYPE}.bin
forge inspect ${NAME} deployedBytecode > ${CWD}/bin/${TYPE_LOWER}_deployed.hex
# Run ABIGEN
cd ${CWD}
abigen \
--abi ${TEMP}/${TYPE}.abi \
--bin ${TEMP}/${TYPE}.bin \
--pkg ${PACKAGE} \
--type ${TYPE} \
--out ./${PACKAGE}/${TYPE_LOWER}.go