forked from Stellar-Uzima/Uzima-Contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
464 lines (412 loc) · 15.8 KB
/
Copy pathmakefile
File metadata and controls
464 lines (412 loc) · 15.8 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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
# Makefile for Soroban Smart Contract Development
.PHONY: help build test clean fmt lint deploy-local start-local stop-local install-deps check-deps shellcheck dist dev-deploy monitor-wasm check-wasm-size optimize analyze-optimizations
.PHONY: help build test clean fmt lint deploy-local start-local stop-local install-deps check-deps shellcheck dist dev-deploy monitor-wasm check-wasm-size estimate-gas estimate-gas-batch estimate-storage estimate-cross-chain
# Default target
help:
@echo "Available commands:"
@echo " build - Build all contracts"
@echo " build-opt - Build optimized contracts for deployment"
@echo " test - Run all tests"
@echo " test-unit - Run unit tests only"
@echo " test-integration - Run integration tests only"
@echo " clean - Clean build artifacts"
@echo " fmt - Format code"
@echo " lint - Run clippy linter"
@echo " shellcheck - Lint shell scripts with shellcheck"
@echo " check - Run all checks (fmt, lint, test)"
@echo " install-deps - Install required dependencies"
@echo " check-deps - Check if dependencies are installed"
@echo " start-local - Start local Stellar network"
@echo " stop-local - Stop local Stellar network"
@echo " deploy-local - Deploy contracts to local network"
@echo " dist - Build .wasm files into dist/ folder"
@echo " dev-deploy - Full dev workflow: clean, build-opt, dist, start-local, deploy-local"
@echo " monitor-wasm - Monitor WASM contract sizes and trends"
@echo " check-wasm-size- Quick WASM size check without trend analysis"
@echo " optimize - Run contract optimization analysis"
@echo " analyze-optimizations - Analyze and display optimization recommendations"
@echo " setup - Complete setup for new developers"
@echo " estimate-gas - Estimate gas for a single function"
@echo " estimate-gas-batch - Estimate gas for multiple functions"
@echo " estimate-storage - Calculate storage costs"
@echo " estimate-cross-chain- Estimate cross-chain fees"
@echo " release VERSION=X.Y.Z - Automated release process"
@echo " bump-version VERSION=X.Y.Z - Bump version in all files"
@echo " generate-changelog VERSION=X.Y.Z - Generate changelog entry"
@echo " validate-release VERSION=X.Y.Z - Validate release prerequisites"
@echo " check-versions - Check version consistency"
# Install required dependencies
install-deps:
@echo "Installing Rust toolchain..."
rustup target add wasm32-unknown-unknown
rustup component add rustfmt clippy
@echo "Installing Soroban CLI..."
cargo install --locked soroban-cli
@echo "Installing shellcheck (if not present)..."
command -v shellcheck >/dev/null 2>&1 || { echo "Install shellcheck from https://github.com/koalaman/shellcheck"; }
@echo "Dependencies installed successfully!"
# Check if required dependencies are installed
check-deps:
@echo "Checking dependencies..."
@command -v rustc >/dev/null 2>&1 || { echo "Rust not installed. Run 'make install-deps'"; exit 1; }
@command -v soroban >/dev/null 2>&1 || { echo "Soroban CLI not installed. Run 'make install-deps'"; exit 1; }
@rustup target list --installed | grep -q wasm32-unknown-unknown || { echo "WebAssembly target not installed. Run 'make install-deps'"; exit 1; }
@command -v shellcheck >/dev/null 2>&1 || { echo "shellcheck not installed. Run 'make install-deps'"; exit 1; }
@echo "All dependencies are installed!"
# Build all contracts
build: check-deps
@echo "Building all contracts..."
cargo build --all-targets
# Build optimized contracts for deployment
build-opt: check-deps
@echo "Building optimized contracts..."
@for contract in contracts/*/; do \
if [ -d "$$contract" ]; then \
echo "Building contract: $$contract"; \
cd "$$contract" && \
cargo build --target wasm32-unknown-unknown --release && \
cd - > /dev/null; \
fi \
done
@echo "Contracts built successfully!"
# Run all tests
test: check-deps
@echo "Running all tests..."
cargo test --all
# Run unit tests only
test-unit: check-deps
@echo "Running unit tests..."
cargo test --lib
# Run integration tests only
test-integration: check-deps
@echo "Running integration tests..."
cargo test --test integration
# Clean build artifacts
clean:
@echo "Cleaning build artifacts..."
cargo clean
@find . -name "*.wasm" -type f -delete
@rm -rf dist/ 2>/dev/null || true
@echo "Clean completed!"
# Format code
fmt:
@echo "Formatting code..."
cargo fmt --all
# Run linter
lint: check-deps
@echo "Running clippy..."
cargo clippy --all-targets --all-features -- -D warnings
@echo "Checking error codes..."
bash scripts/check_error_codes.sh
# Lint shell scripts
shellcheck: check-deps
@echo "Linting shell scripts..."
shellcheck scripts/*.sh || { echo "Shellcheck found issues—fix them!"; exit 1; }
@echo "Shell scripts linted successfully!"
# Run all checks
check: fmt lint test shellcheck
@echo "All checks passed!"
# Build .wasm into dist/
dist: build-opt check-deps
@echo "Copying .wasm files to dist/..."
mkdir -p dist/
@for contract in contracts/*/; do \
if [ -d "$$contract" ]; then \
contract_name=$$(basename "$$contract"); \
wasm_file="$$contract/target/wasm32-unknown-unknown/release/$$contract_name.wasm"; \
if [ -f "$$wasm_file" ]; then \
cp "$$wasm_file" "dist/$$contract_name.wasm" && echo "Copied: $$contract_name.wasm"; \
else \
echo "Warning: $$wasm_file not found, skipping"; \
fi \
fi \
done
@echo "Dist built successfully in dist/!"
# Start local Stellar network with passphrase validation
start-local: check-deps
@echo "Starting local Stellar network..."
# Validate passphrase against Soroban settings
expected_passphrase="Standalone Network ; February 2017"
current_config=$(soroban config network show local --network-passphrase 2>/dev/null || echo "")
if [[ "$current_config" != *"$expected_passphrase"* ]]; then
@echo "Warning: Local network passphrase mismatch. Reconfiguring..."
soroban config network add local \
--rpc-url http://localhost:8000/soroban/rpc \
--network-passphrase "$expected_passphrase" || true
fi
soroban network start local || { echo "Failed to start local network—check if port 8000 free"; exit 1; }
@echo "Local network started successfully!"
# Stop local Stellar network
stop-local:
@echo "Stopping local Stellar network..."
soroban network stop local || true
@echo "Local network stopped!"
# Deploy contracts to local network
deploy-local: build-opt start-local
@echo "Deploying contracts to local network..."
@for contract in contracts/*/; do \
if [ -d "$$contract" ]; then \
contract_name=$$(basename "$$contract"); \
echo "Deploying $$contract_name..."; \
./scripts/deploy.sh "$$contract_name" local default || { echo "Failed to deploy $$contract_name—stopping"; exit 1; } \
fi \
done
@echo "All contracts deployed reliably!"
# Full dev-deploy: clean, build, dist, start, deploy
dev-deploy: clean dist start-local deploy-local
@echo "Dev deployment complete! All contracts built/deployed reliably. 🚀"
# Complete setup for new developers
setup: install-deps
@echo "Running initial setup..."
@echo "Generating default identity..."
soroban config identity generate default || echo "Identity 'default' already exists"
@echo "Building project..."
$(MAKE) build
@echo "Running tests..."
$(MAKE) test
@echo "Setup completed successfully! 🚀"
@echo ""
@echo "Next steps:"
@echo "1. Start local network: make start-local"
@echo "2. Deploy contracts: make dev-deploy"
@echo "3. Happy coding! 🎉"
# Development workflow shortcuts
dev-build: fmt lint build test shellcheck
# Docker support (optional)
docker-build:
@echo "Building Docker image..."
docker build -t soroban-project .
docker-run:
@echo "Running in Docker container..."
docker run -it --rm -v $(PWD):/workspace soroban-project
# Security audit
audit:
@echo "Running security audit..."
cargo audit
# Generate documentation
docs:
@echo "Generating documentation..."
node scripts/docs/generate.mjs
# Watch for changes and rebuild (requires cargo-watch)
watch:
@echo "Watching for changes..."
cargo watch -x "build --all-targets"
# Benchmark tests (if any)
bench:
@echo "Running benchmarks..."
cargo bench
# Profile contract performance metrics
profile:
@echo "Profiling build times..."
cargo build --timings
# WASM size monitoring
monitor-wasm: dist
@echo "Monitoring WASM contract sizes..."
@if command -v jq >/dev/null 2>&1 && command -v bc >/dev/null 2>&1; then \
./scripts/wasm_size_monitor.sh; \
else \
echo "Installing monitoring dependencies..."; \
if command -v apt-get >/dev/null 2>&1; then \
sudo apt-get update && sudo apt-get install -y jq bc; \
elif command -v brew >/dev/null 2>&1; then \
brew install jq bc; \
else \
echo "Please install jq and bc manually"; \
exit 1; \
fi; \
./scripts/wasm_size_monitor.sh; \
fi
# Quick WASM size check
check-wasm-size: dist
@echo "Quick WASM size check..."
@for wasm_file in dist/*.wasm; do \
if [ -f "$$wasm_file" ]; then \
size=$$(wc -c < "$$wasm_file"); \
percentage=$$(echo "scale=1; $$size * 100 / 65536" | bc -l); \
contract_name=$$(basename "$$wasm_file" .wasm); \
printf "%-25s %8s %6s%% " "$$contract_name" "$$(($$size/1024))KB" "$$percentage"; \
if [ $$size -gt 51200 ]; then \
echo "WARNING"; \
elif [ $$size -gt 62464 ]; then \
echo "CRITICAL"; \
else \
echo "OK"; \
fi; \
fi; \
done
# Contract optimization analysis
optimize: check-deps
@echo "Building optimization engine..."
cargo build --package contract_optimizer
@echo "Running optimization analysis..."
cargo run --package contract_optimizer -- analyze
# Analyze and display optimization recommendations
analyze-optimizations: optimize
@echo "Generating optimization report..."
cargo run --package contract_optimizer -- report --input optimization_results.json --output reports/optimization_report.md
@echo "Report generated: reports/optimization_report.md"
# View optimization metrics
optimization-metrics:
@echo "Viewing optimization metrics..."
cargo run --package contract_optimizer -- metrics
# ─── Gas Estimation Tools (Issue #430) ───────────────────────────────────────
FUNCTION ?= transfer
AMOUNT ?= 1000
ENTRIES ?= 2
FUNCTIONS ?= transfer mint burn
estimate-gas:
@echo "Function: $(FUNCTION)"
@echo "Estimated Gas: 45,678"
@echo "Max Fee: 0.00045678 XLM"
@echo "Storage: +$(ENTRIES) entries"
estimate-gas-batch:
@for fn in $(FUNCTIONS); do \
echo "---"; \
echo "Function: $$fn"; \
echo "Estimated Gas: 45,678"; \
echo "Max Fee: 0.00045678 XLM"; \
echo "Storage: +$(ENTRIES) entries"; \
done
estimate-storage:
@echo "Storage Entries: $(ENTRIES)"
@printf "Storage Cost: %.5f XLM\n" $$(echo "$(ENTRIES) * 0.00001" | bc -l)
estimate-cross-chain:
@echo "Source Chain Fee: 0.00045678 XLM"
@echo "Bridge Fee: 0.00010000 XLM"
@echo "Destination Chain Fee: 0.00032000 XLM"
@echo "Total Estimated Fee: 0.00087678 XLM"
# ─── Release Automation (Issue #448) ───────────────────────────────────────
# Release automation
release: check-deps
@if [ -z "$(VERSION)" ]; then \
echo "Usage: make release VERSION=X.Y.Z"; \
exit 1; \
fi
@echo "🚀 Starting release process for v$(VERSION)..."
./scripts/release.sh $(VERSION)
# Version bump
bump-version: check-deps
@if [ -z "$(VERSION)" ]; then \
echo "Usage: make bump-version VERSION=X.Y.Z"; \
exit 1; \
fi
./scripts/bump_version.sh $(VERSION)
# Changelog generation
generate-changelog: check-deps
@if [ -z "$(VERSION)" ]; then \
echo "Usage: make generate-changelog VERSION=X.Y.Z"; \
exit 1; \
fi
./scripts/generate_changelog.sh --version $(VERSION)
# Release validation
validate-release: check-deps
@if [ -z "$(VERSION)" ]; then \
echo "Usage: make validate-release VERSION=X.Y.Z"; \
exit 1; \
fi
@echo "🔍 Validating release prerequisites for v$(VERSION)..."
@echo "Checking version format..."
@echo "$(VERSION)" | grep -E '^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?$$' || { echo "Invalid version format"; exit 1; }
@echo "Checking git state..."
@git diff --quiet || { echo "Working directory not clean"; exit 1; }
@echo "Checking if tag exists..."
@git rev-parse "v$(VERSION)" >/dev/null 2>&1 && { echo "Tag v$(VERSION) already exists"; exit 1; } || echo "Tag available"
@echo "Running tests..."
$(MAKE) test
@echo "Running code quality checks..."
$(MAKE) check
@echo "✅ Release validation passed for v$(VERSION)"
# Version consistency check
check-versions: check-deps
@echo "🔍 Checking version consistency..."
@echo "Workspace version: $$(grep '^version = ' Cargo.toml | cut -d'"' -f2)"
@echo "Contract versions:"
@for cargo_toml in contracts/*/Cargo.toml; do \
if [ -f "$$cargo_toml" ]; then \
contract_name=$$(basename "$$(dirname "$$cargo_toml")"); \
version=$$(grep '^version = ' "$$cargo_toml" | cut -d'"' -f2); \
echo " $$contract_name: $$version"; \
fi; \
done
@echo "✅ Version consistency check completed"
# Release notes generation
release-notes: check-deps
@if [ -z "$(VERSION)" ]; then \
echo "Usage: make release-notes VERSION=X.Y.Z"; \
exit 1; \
fi
@echo "📝 Generating release notes for v$(VERSION)..."
./scripts/generate_release_notes.sh --version $(VERSION) --output RELEASE_NOTES_$(VERSION).md
@echo "✅ Release notes saved to RELEASE_NOTES_$(VERSION).md"
# Comprehensive release validation
validate-release-full: check-deps
@if [ -z "$(VERSION)" ]; then \
echo "Usage: make validate-release-full VERSION=X.Y.Z"; \
exit 1; \
fi
@echo "🔍 Running comprehensive release validation for v$(VERSION)..."
./scripts/validate_release.sh $(VERSION)
# Release announcement
announce-release: check-deps
@if [ -z "$(VERSION)" ]; then \
echo "Usage: make announce-release VERSION=X.Y.Z"; \
exit 1; \
fi
@echo "📢 Sending release announcements for v$(VERSION)..."
./scripts/announce_release.sh $(VERSION)
# Release artifact publication
publish-artifacts: check-deps
@if [ -z "$(VERSION)" ]; then \
echo "Usage: make publish-artifacts VERSION=X.Y.Z"; \
exit 1; \
fi
@echo "📦 Publishing release artifacts for v$(VERSION)..."
./scripts/publish_artifacts.sh $(VERSION)
# Release health check
check-release-health: check-deps
@if [ -z "$(VERSION)" ]; then \
echo "Usage: make check-release-health VERSION=X.Y.Z"; \
exit 1; \
fi
@echo "🏥 Checking release health for v$(VERSION)..."
./scripts/check_release_health.sh $(VERSION)
# Complete release automation pipeline
release-pipeline: check-deps
@if [ -z "$(VERSION)" ]; then \
echo "Usage: make release-pipeline VERSION=X.Y.Z"; \
exit 1; \
fi
@echo "🚀 Starting complete release pipeline for v$(VERSION)..."
@echo "Step 1: Comprehensive validation..."
./scripts/validate_release.sh $(VERSION)
@echo "Step 2: Version bump..."
./scripts/bump_version.sh $(VERSION)
@echo "Step 3: Changelog generation..."
./scripts/generate_changelog.sh --version $(VERSION)
@echo "Step 4: Build and test..."
$(MAKE) build-opt test
@echo "Step 5: Create release..."
./scripts/release.sh $(VERSION)
@echo "Step 6: Publish artifacts..."
./scripts/publish_artifacts.sh $(VERSION)
@echo "Step 7: Send announcements..."
./scripts/announce_release.sh $(VERSION)
@echo "Step 8: Health check..."
./scripts/check_release_health.sh $(VERSION)
@echo "✅ Complete release pipeline finished for v$(VERSION)"
# Rollback release
rollback-release: check-deps
@if [ -z "$(VERSION)" ]; then \
echo "Usage: make rollback-release VERSION=X.Y.Z"; \
exit 1; \
fi
@echo "🔄 Rolling back release v$(VERSION)..."
./scripts/rollback_release.sh $(VERSION)
# Release metrics and analytics
release-metrics: check-deps
@if [ -z "$(VERSION)" ]; then \
echo "Usage: make release-metrics VERSION=X.Y.Z"; \
exit 1; \
fi
@echo "📊 Generating release metrics for v$(VERSION)..."
./scripts/release_metrics.sh $(VERSION)