Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
278 lines (223 loc) · 13.9 KB
/
Copy pathMakefile
File metadata and controls
278 lines (223 loc) · 13.9 KB
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
#!/usr/bin/make
# ══════════════════════════════════════════════════════════════════════════════
# Configuration
# ══════════════════════════════════════════════════════════════════════════════
WASM_DIR := wasms
MOCKS_DIR := $(WASM_DIR)/mocks
DEPLOY_DIR := $(WASM_DIR)/deploy
DEPLOY_OPTIMIZED_DIR := $(WASM_DIR)/deploy_optimized
DOWNLOADS_DIR := $(WASM_DIR)/downloads
# Contracts
CONTRACTS := market market_manager aggregated_oracle soroswap_sep_40_adapter redstone_sep_40_adapter soroswap_swap_provider aqua_swap_provider controlled_insurance_fund
DEPLOY_CONTRACTS := market market_manager aggregated_oracle soroswap_sep_40_adapter redstone_sep_40_adapter soroswap_swap_provider aqua_swap_provider controlled_insurance_fund
MOCK_CONTRACTS := soroswap_router_mock flash_loan_taker_mock
# External dependencies
SOROSWAP_BASE_URL := https://github.com/soroswap/core/releases/download
SOROSWAP_ROUTER_URL := $(SOROSWAP_BASE_URL)/workflow%2FsorobanBuildForStellarExpert__contracts_router_soroswap-router_pkg0.0.1_cli21.0.0/soroswap-router_v0.0.1.wasm
SOROSWAP_PAIR_URL := $(SOROSWAP_BASE_URL)/workflow%2FsorobanBuildForStellarExpert__contracts_pair_soroswap-pair_pkg0.0.1_cli21.0.0/soroswap-pair_v0.0.1.wasm
# AQUA_BASE_URL := https://github.com/AquaToken/soroban-amm/releases/download
# AQUA_POOL_URL := $(AQUA_BASE_URL)/v2.0.2_soroban-liquidity-pool-contract_pkg2.0.1_cli25.1.0/soroban-liquidity-pool-contract_v2.0.1.wasm
# Network
NETWORK := testnet
# Tools
CARGO_NIGHTLY := cargo +nightly
LLVM_COV := $(CARGO_NIGHTLY) llvm-cov
LLVM_COV_FLAGS := --branch
# Metadata
VERSION := $(shell cargo metadata --format-version 1 --no-deps 2>/dev/null | jq -r '.packages[] | select(.name == "market") | .version' 2>/dev/null || echo "unknown")
# Colors
R := \033[0;31m
G := \033[0;32m
Y := \033[0;33m
B := \033[0;34m
C := \033[0;36m
N := \033[0m
.DEFAULT_GOAL := help
.SILENT: help
.PHONY: all build test clean help
# ══════════════════════════════════════════════════════════════════════════════
# Helpers
# ══════════════════════════════════════════════════════════════════════════════
define log
@printf "$(B)▸$(N) %s\n" $(1)
endef
define success
@printf "$(G)✓$(N) %s\n" $(1)
endef
define warn
@printf "$(Y)⚠$(N) %s\n" $(1)
endef
define download_wasm
@[ -f $(1) ] && printf "$(Y)⊘$(N) %s exists\n" "$(notdir $(1))" || \
{ printf "$(B)↓$(N) %s\n" "$(notdir $(1))" && curl -fsSL "$(2)" -o "$(1)"; }
endef
define build_contract
@printf "$(B)⚙$(N) %s\n" "$(1)"
@stellar contract build --package "$(1)" --out-dir "$(2)" $(3)
endef
define optimize_contract
@printf "$(B)◎$(N) %s\n" "$(1)"
@stellar contract optimize --wasm "$(DEPLOY_DIR)/$(1).wasm" --wasm-out "$(DEPLOY_OPTIMIZED_DIR)/$(1).optimized.wasm"
endef
# ══════════════════════════════════════════════════════════════════════════════
# Help
# ══════════════════════════════════════════════════════════════════════════════
help: ## Show this help
@printf "$(C)alula$(N) v$(VERSION) · $(G)$(NETWORK)$(N)\n\n"
@awk 'BEGIN {FS=":.*##"} /^[a-zA-Z0-9_\/.%-]+:.*##/ { \
gsub(/^[ \t]+|[ \t]+$$/, "", $$1); \
gsub(/^[ \t]+|[ \t]+$$/, "", $$2); \
printf " $(G)%-20s$(N) %s\n", $$1, $$2 \
}' $(MAKEFILE_LIST)
# ══════════════════════════════════════════════════════════════════════════════
# Setup
# ══════════════════════════════════════════════════════════════════════════════
setup: ## Install development tools
$(call log,"Installing tools...")
@cargo install cargo-audit cargo-outdated cargo-nextest cargo-watch cargo-sort cargo-llvm-cov
$(call success,"Done")
# ══════════════════════════════════════════════════════════════════════════════
# Build
# ══════════════════════════════════════════════════════════════════════════════
build/prepare:
@mkdir -p $(WASM_DIR) $(MOCKS_DIR) $(DEPLOY_DIR) $(DEPLOY_OPTIMIZED_DIR) $(DOWNLOADS_DIR)
$(call download_wasm,$(DOWNLOADS_DIR)/soroswap-router.wasm,$(SOROSWAP_ROUTER_URL))
$(call download_wasm,$(DOWNLOADS_DIR)/soroswap-pair.wasm,$(SOROSWAP_PAIR_URL))
# $(call download_wasm,$(DOWNLOADS_DIR)/aqua-pool.wasm,$(AQUA_POOL_URL))
build: build/prepare ## Build all contracts
$(call build_contract,soroswap_router_mock,$(MOCKS_DIR))
$(call build_contract,soroswap_sep_40_adapter,$(WASM_DIR))
$(call build_contract,redstone_sep_40_adapter,$(WASM_DIR))
$(call build_contract,soroswap_swap_provider,$(WASM_DIR))
$(call build_contract,aqua_swap_provider,$(WASM_DIR))
$(call build_contract,controlled_insurance_fund,$(WASM_DIR))
$(call build_contract,aggregated_oracle,$(WASM_DIR))
$(call build_contract,market,$(WASM_DIR))
$(call build_contract,market_manager,$(WASM_DIR))
$(call build_contract,farms,$(WASM_DIR))
$(call build_contract,flash_loan_taker_mock,$(MOCKS_DIR))
$(call success,"Build complete")
build/deploy: build/prepare ## Build for deployment
$(call build_contract,soroswap_sep_40_adapter,$(DEPLOY_DIR))
$(call build_contract,redstone_sep_40_adapter,$(DEPLOY_DIR))
$(call build_contract,soroswap_swap_provider,$(DEPLOY_DIR))
$(call build_contract,aqua_swap_provider,$(DEPLOY_DIR))
$(call build_contract,controlled_insurance_fund,$(DEPLOY_DIR))
$(call build_contract,aggregated_oracle,$(DEPLOY_DIR))
$(call build_contract,market,$(DEPLOY_DIR),--features deploy)
$(call build_contract,market_manager,$(DEPLOY_DIR),--features deploy)
$(call build_contract,farms,$(DEPLOY_DIR),--features deploy)
$(call success,"Deploy build complete")
build/optimize: build/deploy ## Build + optimize for production
$(call optimize_contract,soroswap_sep_40_adapter)
$(call optimize_contract,redstone_sep_40_adapter)
$(call optimize_contract,soroswap_swap_provider)
$(call optimize_contract,aqua_swap_provider)
$(call optimize_contract,controlled_insurance_fund)
$(call optimize_contract,aggregated_oracle)
$(call optimize_contract,market)
$(call optimize_contract,market_manager)
$(call optimize_contract,farms)
$(call success,"Optimization complete")
@printf "\n$(C)Sizes:$(N)\n"
@find $(DEPLOY_OPTIMIZED_DIR) -name "*.wasm" -exec sh -c 'printf " %-40s %s\n" "$$(basename {})" "$$(ls -lh {} | awk "{print \$$5}")"' \;
# ══════════════════════════════════════════════════════════════════════════════
# Testing
# ══════════════════════════════════════════════════════════════════════════════
test: build ## Run tests
@cargo nextest run --locked --workspace --lib --no-fail-fast
test/watch: build ## Run tests in watch mode
@cargo watch -x 'nextest run --workspace --lib'
test/fuzz: build ## Run fuzzing suite
@RUST_BACKTRACE=1 $(CARGO_NIGHTLY) fuzz run --fuzz-dir=tests/fuzz --sanitizer=none fuzz_target -- -max_len=1048576
# ── Coverage ──────────────────────────────────────────────────────────────────
cov: ## Generate coverage report
@$(LLVM_COV) nextest $(LLVM_COV_FLAGS) --no-tests=warn --no-report || true
@$(LLVM_COV) --doc --no-report || true
@$(LLVM_COV) report $(LLVM_COV_FLAGS)
cov/html: ## Generate HTML coverage report
@$(LLVM_COV) nextest $(LLVM_COV_FLAGS) --html --no-tests=warn || true
@$(LLVM_COV) --doc --html || true
$(call success,"Report: target/llvm-cov/html/index.html")
cov/missing: ## Show uncovered lines
@$(LLVM_COV) report $(LLVM_COV_FLAGS) --show-missing-lines
cov/lcov: ## Generate LCOV format
@$(LLVM_COV) nextest $(LLVM_COV_FLAGS) --lcov --output-path target/lcov.info --no-tests=warn || true
$(call success,"Output: target/lcov.info")
cov/json: ## Generate JSON coverage
@$(LLVM_COV) nextest $(LLVM_COV_FLAGS) --json --output-path target/coverage.json --no-tests=warn || true
$(call success,"Output: target/coverage.json")
# ══════════════════════════════════════════════════════════════════════════════
# Code Quality
# ══════════════════════════════════════════════════════════════════════════════
check: ## Run cargo check
@cargo check --locked --workspace
fmt: ## Format code
@cargo sort --workspace 2>/dev/null || true
@$(CARGO_NIGHTLY) fmt --all
fmt/check: ## Check formatting
@$(CARGO_NIGHTLY) fmt --all --check
lint: check ## Run clippy
@cargo clippy --workspace --all-targets -- -D warnings
lint/fix: ## Auto-fix lint issues
@cargo clippy --workspace --all-targets --fix --allow-dirty --allow-staged
@pnpm lint:fix
# Compound targets
ci: test lint fmt/check ## Run full CI pipeline
pre-commit: test lint fmt ## Pre-commit checks
# ══════════════════════════════════════════════════════════════════════════════
# SDK Generation
# ══════════════════════════════════════════════════════════════════════════════
sdk: build/optimize ## Generate TypeScript SDK
$(call log,"Generating SDK...")
@stellar contract bindings typescript --overwrite \
--wasm "$(DEPLOY_OPTIMIZED_DIR)/market.optimized.wasm" \
--output-dir ./packages/sdk/market --network "$(NETWORK)"
@stellar contract bindings typescript --overwrite \
--wasm "$(DEPLOY_OPTIMIZED_DIR)/market_manager.optimized.wasm" \
--output-dir ./packages/sdk/market_manager --network "$(NETWORK)"
@stellar contract bindings typescript --overwrite \
--wasm "$(DEPLOY_OPTIMIZED_DIR)/soroswap_swap_provider.optimized.wasm" \
--output-dir ./packages/sdk/soroswap_swap_provider --network "$(NETWORK)"
@stellar contract bindings typescript --overwrite \
--wasm "$(DEPLOY_OPTIMIZED_DIR)/aqua_swap_provider.optimized.wasm" \
--output-dir ./packages/sdk/aqua_swap_provider --network "$(NETWORK)"
@stellar contract bindings typescript --overwrite \
--wasm "$(DEPLOY_OPTIMIZED_DIR)/farms.optimized.wasm" \
--output-dir ./packages/sdk/farms --network "$(NETWORK)"
$(call success,"SDK generated")
# ══════════════════════════════════════════════════════════════════════════════
# Maintenance
# ══════════════════════════════════════════════════════════════════════════════
outdated: ## Check outdated deps
@cargo outdated
@pnpm outdated 2>/dev/null || true
update: ## Update dependencies
@cargo update
@pnpm update 2>/dev/null || true
audit: ## Security audit
@cargo audit
@pnpm audit 2>/dev/null || true
audit/fix: ## Fix vulnerabilities
@cargo audit fix || true
size: ## Show WASM sizes
@printf "$(C)WASM Sizes:$(N)\n"
@find $(WASM_DIR) -name "*.wasm" -type f | sort | while read f; do \
printf " %-45s %s\n" "$$(basename $$f)" "$$(ls -lh "$$f" | awk '{print $$5}')"; \
done
clean: ## Clean build artifacts
@cargo clean
@rm -rf $(WASM_DIR)/* target/llvm-cov 2>/dev/null || true
$(call success,"Cleaned")
clean/all: clean ## Deep clean (including downloads)
@rm -rf $(DOWNLOADS_DIR)/* ./packages/sdk/* node_modules 2>/dev/null || true
$(call success,"Deep cleaned")
# ══════════════════════════════════════════════════════════════════════════════
# Aliases
# ══════════════════════════════════════════════════════════════════════════════
b: build ## → build
t: test ## → test
c: check ## → check
l: lint ## → lint
f: fmt ## → fmt
w: test/watch ## → test/watch