generated from KEI-finance/contracts-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
179 lines (152 loc) · 5.82 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# Makefile for deploying to multiple chains and environments
# Environment variables
# Source .env file globally if it exists
ifneq (,$(wildcard .env))
include .env
export
endif
ENV ?= develop
CHAIN ?= sepolia
ETHERSCAN_API_KEY ?= ""
INFURA_API_KEY ?= ""
# 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 forge-clean compile-clean clean soldeer-publish
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 🌍💥"
compile-clean:
@echo "Cleaning compiled utils..."
rm ./utils/**/*.js >> /dev/null || true
# 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 >> /dev/null || true
# 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 >> /dev/null || true
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..."
$(MAKE) clean
pnpm install
forge clean
forge install
forge build --skip script test
$(MAKE) typechain
$(MAKE) compile
forge-utils deployments
git add deployments.json > /dev/null || true
forge-clean:
@echo "Cleaning forge build..."
forge clean
# Clean build artifacts
clean:
$(MAKE) forge-clean >> /dev/null || true
$(MAKE) compile-clean >> /dev/null || true
$(MAKE) typechain-clean >> /dev/null || true
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
sync-foundry:
foundryup -v nightly-d14a7b44fc439407d761fccc4c1637216554bbb6
soldeer-publish:
@cp package.json ./src/package.json && \
cp README.md ./src/README.md && \
VERSION=$$(node -p "require('./src/package.json').version"); \
PACKAGE=$$(node -p "require('./src/package.json').name.replace(/[\.\-\/]/g, '-')"); \
if soldeer push $$PACKAGE~$$VERSION src/; then \
echo "Successfully published $$PACKAGE version $$VERSION"; \
else \
echo "Failed to publish $$PACKAGE version $$VERSION"; \
fi; \
rm ./src/package.json ./src/README.md;
# 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 " forge-clean - Clean forge build"
@echo " compile-clean - Clean compiled utils"
@echo " compile - Compile contracts"
@echo " test - Run tests"
@echo " soldeer-publish - Publish to Soldeer"
@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