generated from KEI-finance/contracts-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
149 lines (127 loc) · 4.76 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# Makefile for deploying to multiple chains and environments
# Environment variables
ENV ?= develop
CHAIN ?= sepolia
# Source .env file globally if it exists
ifneq (,$(wildcard .env))
include .env
export
endif
# Decode secrets file if it exists
ifneq (,$(wildcard secrets/secrets.$(ENV).env))
$(shell (sops -d secrets/secrets.$(ENV).env > .env.secrets) || (echo "Error decoding secrets file" >&2))
-include .env.secrets
export
$(shell rm -f .env.secrets)
endif
# Phony targets
.PHONY: deploy deploy-resume typechain typechain-clean typechain-v5 typechain-v6 prepublish setup help test print-env sync compile
define set_etherscan_api_key
$(eval ETHERSCAN_API_KEY := $(shell \
if [ "$(CHAIN)" = "arbitrum" ] || [ "$(CHAIN)" = "arbitrum_sepolia" ]; then \
echo "$(ARB_ETHERSCAN_API_KEY)"; \
elif [ "$(CHAIN)" = "polygon" ] || [ "$(CHAIN)" = "polygon_sepolia" ]; then \
echo "$(POLYGON_ETHERSCAN_API_KEY)"; \
elif [ "$(CHAIN)" = "bsc" ]; then \
echo "$(BSC_ETHERSCAN_API_KEY)"; \
else \
echo "$(ETHERSCAN_API_KEY)"; \
fi \
))
endef
compile:
@echo "Compiling contracts..."
npx tsc >> /dev/null || true
# Deploy to selected chain and environment
deploy:
@echo "Deploying to $(CHAIN) in $(ENV) environment..."
$(call set_etherscan_api_key)
forge script script/Deploy.s.sol:DeployScript --broadcast --verify -vvvv --rpc-url $(CHAIN) --etherscan-api-key $(ETHERSCAN_API_KEY) --private-key $(PRIVATE_KEY)
$(MAKE) deploy-tag
# Resume deployment on selected chain and environment
deploy-resume:
@echo "Resuming deployment on $(CHAIN) in $(ENV) environment..."
$(call set_etherscan_api_key)
forge script script/Deploy.s.sol:DeployScript --broadcast --verify --resume -vvvv --rpc-url $(CHAIN) --etherscan-api-key $(ETHERSCAN_API_KEY) --private-key $(PRIVATE_KEY)
$(MAKE) deploy-tag
deploy-tag:
@echo "Tagging deployment to $(ENV) environment"
forge-utils append-meta --meta.env $(ENV) --new-files
git reset
git add broadcast
git commit -m "🚀🔥 DEPLOYED: $(CHAIN) network, $(ENV) environment 🌍💥"
# Clean TypeChain artifacts
typechain-clean:
@echo "Cleaning TypeChain artifacts..."
rm -rf typechain
# Generate TypeChain bindings for ethers-v6
typechain-v6:
@echo "Generating TypeChain bindings for ethers-v6..."
npx typechain --target ethers-v6 --out-dir typechain/ethers-v6 "./out/*.sol/*.json" --show-stack-traces
# Generate TypeChain bindings for ethers-v5
typechain-v5:
@echo "Generating TypeChain bindings for ethers-v5..."
npx typechain --target ethers-v5 --out-dir typechain/ethers-v5 "./out/*.sol/*.json" --show-stack-traces
clean-typechain-bytecode:
@echo "Cleaning TypeChain bytecode..."
forge-utils clean-typechain-bytecode
# Generate all TypeChain bindings
typechain: typechain-clean typechain-v6 typechain-v5 clean-typechain-bytecode
# Prepare for publishing
setup:
@echo "Setting up the project..."
pnpm install
forge clean
forge install
forge build --skip script test
$(MAKE) typechain
$(MAKE) compile
forge-utils deployments
git add deployments.json
# Clean build artifacts
clean:
@echo "Cleaning build artifacts..."
forge clean
# Run tests
test:
@echo "Running tests..."
forge test -vvv
# Print environment variables
print-env:
@echo "Current environment variables:"
@echo "ENV: $(ENV)"
@echo "CHAIN: $(CHAIN)"
# Sync with template/master
sync:
@echo "Syncing with template/master..."
@echo "Checking if template origin exists..."
@if ! git remote | grep -q '^template$$'; then \
echo "Adding template origin..."; \
git remote add template https://github.com/kei-finance/contracts-template.git; \
else \
echo "Template origin already exists."; \
fi
git fetch template master
git merge --no-edit template/master --allow-unrelated-histories
# Help target
help:
@echo "Available targets:"
@echo " deploy - Deploy contracts to selected chain and environment"
@echo " deploy-resume - Resume deployment on selected chain and environment"
@echo " typechain - Generate all TypeChain bindings"
@echo " typechain-clean - Clean TypeChain artifacts"
@echo " typechain-v5 - Generate TypeChain bindings for ethers-v5"
@echo " typechain-v6 - Generate TypeChain bindings for ethers-v6"
@echo " clean - Clean build artifacts"
@echo " setup - Setup the project"
@echo " compile - Compile contracts"
@echo " test - Run tests"
@echo " print-env - Print current environment variables"
@echo " sync - Sync with template/master"
@echo " help - Show this help message"
@echo ""
@echo "Usage:"
@echo " make [target] ENV=[develop|staging|production] CHAIN=[sepolia|mainnet|goerli]"
@echo " Example: make deploy ENV=staging CHAIN=sepolia"
# Default target
.DEFAULT_GOAL := setup