Skip to content

Commit

Permalink
chore: generate openzeppelin go bindings from sources
Browse files Browse the repository at this point in the history
  • Loading branch information
leovct committed Nov 7, 2023
1 parent 6b97ff9 commit 8f8769e
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 304 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "contracts/lib/openzeppelin-contracts"]
path = contracts/lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
[submodule "contracts/lib/openzeppelin-contracts-v3.4.1-solc-0.7-2"]
path = contracts/lib/openzeppelin-contracts-v3.4.1-solc-0.7-2
url = https://github.com/OpenZeppelin/openzeppelin-contracts
22 changes: 20 additions & 2 deletions contracts/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,32 @@ gen:
$(call gen_go_binding,Swapper,src/tokens/Swapper,tokens,src/tokens)
$(call gen_go_binding,WETH9,src/tokens/WETH9,tokens,src/tokens)

# Generate go binding.
test:
$(call gen_go_binding_from_lib,openzeppelin-contracts-v3.4.1-solc-0.7-2,ProxyAdmin,src/openzeppelin/ProxyAdmin,openzeppelin,src/openzeppelin)
$(call gen_go_binding_from_lib,openzeppelin-contracts-v3.4.1-solc-0.7-2,TransparentUpgradeableProxy,src/openzeppelin/TransparentUpgradeableProxy,openzeppelin,src/openzeppelin)

# Generate simple go bindings.
# - $1: smart contract name.
# - $2: smart contract folder path.
# - $3: go package name.
# - $4: go file output path.
define gen_go_binding
echo "Generating ABI, bytecode and go bindings for $1..."
echo "Generating ABI, bytecode and go binding for $1..."
cat ./out/$1.sol/$1.json | jq -r '.abi' > ./$2/$1.abi
cat ./out/$1.sol/$1.json | jq -r '.bytecode.object' > ./$2/$1.bin
abigen --abi ./$2/$1.abi --bin ./$2/$1.bin --pkg $3 --type $1 --out ./$4/$1.go
endef

# Generate go bindings for smart contracts under `lib/`.
# - $1: library name.
# - $2: smart contract name.
# - $3: smart contract folder path.
# - $4: go package name.
# - $5: go file output path.
define gen_go_binding_from_lib
echo "Generating ABI, bytecode and go binding for $2..."
cd "./lib/$1" && forge build
cat "./lib/$1/out/$2.sol/$2.json" | jq -r '.abi' > "./$3/$2.abi"
cat "./lib/$1/out/$2.sol/$2.json" | jq -r '.bytecode.object' > "./$3/$2.bin"
abigen --abi "./$3/$2.abi" --bin "./$3/$2.bin" --pkg $4 --type $2 --out ./$5/$2.go
endef
1 change: 1 addition & 0 deletions contracts/lib/alias
Submodule alias added at 94697b
1 change: 1 addition & 0 deletions contracts/lib/openzeppelin-contracts
Submodule openzeppelin-contracts added at 1c3d6c
1 change: 1 addition & 0 deletions contracts/lib/openzeppelin-contracts-v3.4.1-solc-0.7-2
2 changes: 1 addition & 1 deletion contracts/src/openzeppelin/ProxyAdmin.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8f8769e

Please sign in to comment.