-
Notifications
You must be signed in to change notification settings - Fork 8
/
Makefile
121 lines (96 loc) · 3.66 KB
/
Makefile
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
SHELL = bash
.PHONY: all
all: build
export CGO_ENABLED=0
export GOOS ?= $(shell go env GOOS)
export GOARCH ?= $(shell go env GOARCH)
export GOPATH ?= $(shell go env GOPATH)
PROTOC := ${GOPATH}/bin/protoc-gen-go
${PROTOC}:
go install google.golang.org/protobuf/cmd/[email protected]
go install google.golang.org/grpc/cmd/[email protected]
ABIGEN ?= ${GOPATH}/bin/abigen
${ABIGEN}: ${PROTOC_BREW}
go install github.com/ethereum/go-ethereum/cmd/[email protected]
%/node_modules/.bin/hardhat:
cd $* && npm install
%/package-lock.json: %/package.json
cd $* && npm install
.PHONY: prepare
prepare: ${ABIGEN} ${HARDHAT}
include hardhat/contracts/.deps.mk
include examples/contracts/.deps.mk
hardhat/contracts/.deps.mk: $(shell find hardhat/contracts -name '*.sol')
examples/contracts/.deps.mk: $(shell find examples/contracts -name '*.sol')
%/.deps.mk:
echo '$^' | \
xargs -n1 basename -s .sol | \
tr ' ' "\n" | \
awk -v ROOT='$(shell dirname $$(dirname $@))' -v STEM='$(shell basename $$(dirname $@))' \
'BEGIN { print "MKDEPS += $@"; } {\
print ROOT "/artifacts/" STEM "/" $$1 ".sol/" $$1 ".json: " ROOT "/" STEM "/" $$1 ".sol" \
" | " ROOT "/node_modules/.bin/hardhat"; \
print toupper(ROOT) "_ABIJSONS += " ROOT "/artifacts/" STEM "/" $$1 ".sol/" $$1 ".json"; \
print toupper(ROOT) "_ABIJSONS += " ROOT "/artifacts/" STEM "/" $$1 ".sol/" $$1 ".dbg.json"; \
print toupper(ROOT) "_PACKAGES += " ROOT "/artifacts/" STEM "/" $$1 ".sol/" $$1 ".go"; \
}' > $@
${HARDHAT_ABIJSONS}: hardhat/package-lock.json | ${HARDHAT}
cd hardhat && npx hardhat compile --force
${EXAMPLES_ABIJSONS}: examples/package-lock.json | ${HARDHAT}
cd examples && npx hardhat compile --force
%.go: %.json | ${ABIGEN}
${ABIGEN} \
--abi <(cat $< | jq -rc '.abi') \
--bin <(cat $< | jq -rc '.bytecode') \
--pkg $(shell dirname $@ | xargs basename -s .sol) \
> $@
OSES := darwin linux
ARCHES := arm64 amd64
BASENAME := $(shell pwd | xargs basename)
BINARY := bin/${BASENAME}-${GOOS}-${GOARCH}
BINARIES := $(foreach OS,${OSES}, $(foreach ARCH,${ARCHES},bin/${BASENAME}-${OS}-${ARCH}))
bin:
mkdir -p $@
bin/${BASENAME}-%: ${HARDHAT_PACKAGES} $(shell find pkg -name '*.go') main.go | bin
GOOS=$(shell echo $@ | cut -f2 -d'-') GOARCH=$(shell echo $@ | cut -f3 -d'-') go build -o $@ .
.PHONY: build
build: ${EXAMPLES_ABIJSONS} ${BINARIES}
NETWORKS ?= mainnet calibration mantle-testnet polygon-mumbai sepolia-testnet
PROPERTIES = WALLET_PRIVATE_KEY DEPLOYED_CONTRACT_ADDRESS RPC_ENDPOINT CHAIN_ID
ENV_FILES = $(patsubst %,hardhat/%.env,${NETWORKS})
ENV_FILE ?= hardhat/.env
ifeq ($(shell cat ${ENV_FILE} | grep WALLET_PRIVATE_KEY),)
$(warning No WALLET_PRIVATE_KEY in ${ENV_FILE})
endif
ifeq ($(shell cat ${ENV_FILE} | grep DEPLOYED_CONTRACT_ADDRESS),)
$(warning No DEPLOYED_CONTRACT_ADDRESS in ${ENV_FILE})
endif
.PHONY: deploy
deploy: ${BINARIES} | ops/deploy.sh ${ENV_FILES}
for ENV_FILE in ${ENV_FILES}; do \
if ! test -f $$ENV_FILE; then \
echo "$$ENV_FILE does not exist"; exit 1; \
fi; \
for PROPERTY in ${PROPERTIES}; do \
if test -z "$$(cat $$ENV_FILE | grep -o $$PROPERTY)"; then \
echo "$$ENV_FILE does not contain $$PROPERTY"; exit 1; \
fi; \
done; \
done; \
cd ops && ./deploy.sh ${NETWORKS}
.PHONY: run
run: ${BINARY} | ${ENV_FILE}
env $$(cat ${ENV_FILE}) ${BINARY}
.PHONY: key
key:
@openssl ecparam -name secp256k1 -genkey -noout | \
openssl ec -text -noout 2>/dev/null | \
grep priv -A 3 | tail -n +2 | tr -d ":\n[:space:]" | \
OFS='' xargs printf WALLET_PRIVATE_KEY=%s
.SECONDARY: ${HARDHAT_PACKAGES}
.PHONY: clean
clean:
-$(RM) ${MKDEPS}
-$(RM) ${HARDHAT_PACKAGES} ${EXAMPLES_PACKAGES}
-$(RM) ${HARDHAT_ABIJSONS} ${EXAMPLES_ABIJSONS}
-${RM} -r bin/