-
Notifications
You must be signed in to change notification settings - Fork 11
/
build_abi.sh
executable file
·69 lines (52 loc) · 1.73 KB
/
build_abi.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
# generates go bindings from contracts, to paste into abi/bridge_abi.go
# compile artifacts in /contracts folder with `forge build`` first
if [ $# != 1 ]; then
echo "Usage: ./build_abi.sh <contracts_path>"
exit
fi
contracts_path=$1;
echo "contracts path: $contracts_path"
if [ ! -d "$contracts_path" ]; then
echo "Directory $contracts don't exists"
exit
fi
# cd contract path
cd $contracts_path && forge build
# switch to current workdir
cd -
if [ -d contracts_tmp ]; then
rm -rf contracts_tmp
fi
mkdir contracts_tmp
mv $contracts_path/artifacts ./contracts_tmp
# l1 messenger
l1_messenger=("IL1ScrollMessenger")
# l1 gateway
l1_gateway=("IL1ETHGateway" "IL1ERC20Gateway" "IL1ERC721Gateway" "IL1ERC1155Gateway")
# l2 messenger
l2_messenger=("IL2ScrollMessenger")
# l2 gateway
l2_gateway=("IL2ETHGateway" "IL2ERC20Gateway" "IL2ERC721Gateway" "IL2ERC1155Gateway")
# token list
token_list=("IScrollERC20" "IScrollERC721" "IScrollERC1155")
if [ -d "internal/logic/contracts/abi/" ]; then
rm -rf internal/logic/contracts/abi/
fi
mkdir internal/logic/contracts/abi/
mkdir -p tmp
contracts=("${l1_messenger[@]}" "${l1_gateway[@]}" "${l2_messenger[@]}" "${l2_gateway[@]}" "${token_list[@]}")
for abi_name in "${contracts[@]}"; do
echo "Generating code for: $abi_name"
abi="tmp/$abi_name.json"
cat ./contracts_tmp/artifacts/src/$abi_name.sol/$abi_name.json | jq '.abi' > $abi
pkg=`echo $abi_name | tr 'A-Z' 'a-z'`
out="internal/logic/contracts/abi/${pkg}/${pkg}.go"
echo $out
echo "generating ${out} from ${abi}"
mkdir -p internal/logic/contracts/abi/$pkg
abigen --abi=$abi --pkg=$pkg --out=$out
awk '{sub("github.com/ethereum","github.com/scroll-tech")}1' $out > temp && mv temp $out
done
rm -rf tmp
rm -rf contracts_tmp