chore(ai): add comprehensive CLI configurations for all AI assistants
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
275
.qwen/QWEN.md
Normal file
275
.qwen/QWEN.md
Normal file
@@ -0,0 +1,275 @@
|
||||
# Qwen Code CLI Configuration
|
||||
|
||||
This directory contains Qwen Code configuration and tools for the MEV Bot project.
|
||||
|
||||
## 🚀 Quick Start Commands
|
||||
|
||||
### Essential Build & Test Commands
|
||||
```bash
|
||||
# Build the MEV bot binary
|
||||
make build
|
||||
|
||||
# Run mathematical function tests
|
||||
.qwen/scripts/math-test.sh
|
||||
|
||||
# Run mathematical optimization analysis
|
||||
.qwen/scripts/math-optimize.sh
|
||||
|
||||
# Run benchmarks for mathematical functions
|
||||
make bench-math
|
||||
|
||||
# Run property-based tests
|
||||
make test-property
|
||||
|
||||
# Check for Go modules issues
|
||||
go mod tidy && go mod verify
|
||||
|
||||
# Run linter on mathematical functions
|
||||
golangci-lint run ./pkg/uniswap/... ./pkg/math/...
|
||||
```
|
||||
|
||||
### Development Workflow Commands
|
||||
```bash
|
||||
# Setup development environment
|
||||
export ARBITRUM_RPC_ENDPOINT="wss://arbitrum-mainnet.core.chainstack.com/73bc682fe9c5bd23b42ef40f752fa89a"
|
||||
export ARBITRUM_WS_ENDPOINT="wss://arbitrum-mainnet.core.chainstack.com/73bc682fe9c5bd23b42ef40f752fa89a"
|
||||
export METRICS_ENABLED="false"
|
||||
|
||||
# Run with timeout for testing
|
||||
timeout 30 ./mev-bot start
|
||||
|
||||
# Debug with verbose logging
|
||||
LOG_LEVEL=debug ./mev-bot start
|
||||
|
||||
# Profile performance
|
||||
go tool pprof http://localhost:6060/debug/pprof/profile
|
||||
```
|
||||
|
||||
## Qwen Commands Directory
|
||||
|
||||
The `.qwen/commands/` directory contains predefined commands for mathematical development tasks:
|
||||
|
||||
- `implement-algorithm.md` - Implement mathematical algorithms with precision
|
||||
- `optimize-math.md` - Optimize mathematical performance
|
||||
- `verify-precision.md` - Verify mathematical precision and correctness
|
||||
|
||||
## Qwen Settings
|
||||
|
||||
The `.qwen/settings.json` file contains Qwen's mathematical computation configuration:
|
||||
|
||||
```json
|
||||
{
|
||||
"focus_areas": [
|
||||
"Mathematical Computations",
|
||||
"Algorithmic Implementation",
|
||||
"Precision Handling",
|
||||
"Performance Optimization"
|
||||
],
|
||||
"primary_skills": [
|
||||
"Implementing precise Uniswap V3 pricing functions",
|
||||
"Ensuring numerical stability and precision",
|
||||
"Working with liquidity and fee calculations",
|
||||
"Creating efficient algorithms for arbitrage detection",
|
||||
"Implementing accurate tick and sqrtPriceX96 conversions",
|
||||
"Calculating price impact with proper precision handling"
|
||||
],
|
||||
"performance_optimization": {
|
||||
"enabled": true,
|
||||
"profiling": {
|
||||
"cpu": true,
|
||||
"memory": true,
|
||||
"goroutine": true
|
||||
},
|
||||
"optimization_targets": [
|
||||
"Minimize memory allocations in hot paths",
|
||||
"Optimize uint256 arithmetic operations",
|
||||
"Reduce garbage collection pressure",
|
||||
"Improve mathematical computation efficiency"
|
||||
]
|
||||
},
|
||||
"precision_requirements": {
|
||||
"math_library": "github.com/holiman/uint256",
|
||||
"floating_point": "math/big",
|
||||
"rounding_strategy": "bankers_rounding",
|
||||
"precision_target": "256_bits"
|
||||
},
|
||||
"testing": {
|
||||
"unit_test_coverage": 95,
|
||||
"property_based_testing": true,
|
||||
"fuzz_testing": true,
|
||||
"benchmarking": true
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 📋 Development Guidelines & Code Style
|
||||
|
||||
### Mathematical Implementation Guidelines
|
||||
- **Precision**: Always use `github.com/holiman/uint256` for uint256 arithmetic
|
||||
- **Error Handling**: Implement robust error handling with clear mathematical context
|
||||
- **Documentation**: Document all mathematical formulas and implementation decisions
|
||||
- **Testing**: Achieve >95% test coverage with property-based tests for mathematical functions
|
||||
- **Performance**: Profile regularly with `go tool pprof` while maintaining precision
|
||||
|
||||
### Code Organization Rules
|
||||
- **File Size**: Keep mathematical function files under 300 lines
|
||||
- **Package Structure**: Place mathematical functions in `pkg/uniswap/` or `pkg/math/`
|
||||
- **Naming**: Use descriptive names for mathematical functions (e.g., `CalculateSqrtPriceX96ToPrice`)
|
||||
- **Documentation**: Inline comments explaining mathematical formulas
|
||||
|
||||
### Required Checks Before Commit
|
||||
```bash
|
||||
# Run mathematical function tests
|
||||
.qwen/scripts/math-test.sh
|
||||
|
||||
# Run linter on mathematical functions
|
||||
golangci-lint run ./pkg/uniswap/... ./pkg/math/...
|
||||
|
||||
# Security scan for mathematical implementations
|
||||
gosec ./pkg/uniswap/... ./pkg/math/...
|
||||
```
|
||||
|
||||
## Qwen Code's Primary Focus Areas
|
||||
|
||||
As Qwen Code, you're particularly skilled at:
|
||||
|
||||
1. **Mathematical Computations**
|
||||
- Implementing precise Uniswap V3 pricing functions
|
||||
- Ensuring numerical stability and precision
|
||||
- Working with liquidity and fee calculations
|
||||
|
||||
2. **Algorithmic Implementation**
|
||||
- Creating efficient algorithms for arbitrage detection
|
||||
- Implementing accurate tick and sqrtPriceX96 conversions
|
||||
- Calculating price impact with proper precision handling
|
||||
|
||||
3. **Precision Handling**
|
||||
- Using appropriate data types for mathematical calculations
|
||||
- Implementing proper rounding strategies for financial calculations
|
||||
- Handling overflow and underflow conditions properly
|
||||
|
||||
4. **Performance Optimization**
|
||||
- Minimizing memory allocations in hot paths
|
||||
- Optimizing uint256 arithmetic operations
|
||||
- Reducing garbage collection pressure
|
||||
- Improving mathematical computation efficiency
|
||||
|
||||
## 🛠 Qwen Code Optimization Settings
|
||||
|
||||
### Workflow Preferences
|
||||
- **Always commit changes**: Use `git commit -am "math: descriptive message"` for mathematical implementations
|
||||
- **Branch naming**: Use prefixes (`math-sqrt-price`, `algo-liquidity-calc`, `perf-uniswap`)
|
||||
- **Context management**: Focus on mathematical precision and performance
|
||||
- **Parallel processing**: Leverage Go's concurrency patterns for independent calculations
|
||||
|
||||
### File Organization Preferences
|
||||
- **Mathematical functions**: Place in `pkg/uniswap/` or `pkg/math/`
|
||||
- **Test files**: Place alongside source files with `_test.go` suffix
|
||||
- **Documentation**: Inline comments explaining mathematical formulas
|
||||
- **Precision libraries**: Use `github.com/holiman/uint256` for uint256 arithmetic
|
||||
|
||||
### Performance Monitoring
|
||||
```bash
|
||||
# Enable metrics endpoint for performance tracking
|
||||
export METRICS_ENABLED="true"
|
||||
export METRICS_PORT="9090"
|
||||
|
||||
# Monitor memory usage of mathematical calculations
|
||||
go tool pprof http://localhost:9090/debug/pprof/heap
|
||||
|
||||
# Monitor CPU usage of mathematical functions
|
||||
go tool pprof http://localhost:9090/debug/pprof/profile?seconds=30
|
||||
|
||||
# Run benchmarks for mathematical functions
|
||||
.qwen/scripts/math-test.sh
|
||||
```
|
||||
|
||||
## 🔧 Environment Configuration
|
||||
|
||||
### Required Environment Variables
|
||||
```bash
|
||||
# Arbitrum RPC Configuration
|
||||
export ARBITRUM_RPC_ENDPOINT="wss://arbitrum-mainnet.core.chainstack.com/73bc682fe9c5bd23b42ef40f752fa89a"
|
||||
export ARBITRUM_WS_ENDPOINT="wss://arbitrum-mainnet.core.chainstack.com/73bc682fe9c5bd23b42ef40f752fa89a"
|
||||
|
||||
# Application Configuration
|
||||
export LOG_LEVEL="info"
|
||||
export METRICS_ENABLED="false"
|
||||
export METRICS_PORT="9090"
|
||||
|
||||
# Development Configuration
|
||||
export GO_ENV="development"
|
||||
export DEBUG="true"
|
||||
|
||||
# Mathematical Precision Configuration
|
||||
export MATH_LIBRARY="github.com/holiman/uint256"
|
||||
export FLOATING_POINT_LIBRARY="math/big"
|
||||
export ROUNDING_STRATEGY="bankers_rounding"
|
||||
export PRECISION_TARGET="256_bits"
|
||||
```
|
||||
|
||||
### Testing Environment Variables
|
||||
```bash
|
||||
# Test Configuration
|
||||
export TEST_COVERAGE_TARGET=95
|
||||
export TEST_TIMEOUT=30s
|
||||
export TEST_PARALLEL=4
|
||||
|
||||
# Mathematical Testing
|
||||
export MATH_TEST_PROPERTY=true
|
||||
export MATH_TEST_FUZZ=true
|
||||
export MATH_BENCHMARK=true
|
||||
```
|
||||
|
||||
## 📝 Commit Message Conventions
|
||||
|
||||
### Format
|
||||
```
|
||||
math(type): brief description
|
||||
|
||||
- Detailed explanation of mathematical implementation
|
||||
- Why the mathematical approach was chosen
|
||||
- Any precision considerations or trade-offs
|
||||
|
||||
🤖 Generated with [Qwen Code](https://tongyi.aliyun.com/)
|
||||
Co-Authored-By: Qwen <noreply@tongyi.aliyun.com>
|
||||
```
|
||||
|
||||
### Types
|
||||
- `sqrt-price`: sqrtPriceX96 related implementations
|
||||
- `tick`: Tick calculation implementations
|
||||
- `liquidity`: Liquidity-based calculation implementations
|
||||
- `price-impact`: Price impact calculation implementations
|
||||
- `arbitrage`: Arbitrage detection algorithm implementations
|
||||
- `perf`: Mathematical performance improvements
|
||||
- `test`: Mathematical function test implementations
|
||||
- `docs`: Mathematical documentation updates
|
||||
|
||||
## 🚨 Security Guidelines
|
||||
|
||||
### Never Commit
|
||||
- Private keys or wallet seeds
|
||||
- API keys or secrets
|
||||
- RPC endpoints with authentication
|
||||
- Personal configuration files
|
||||
|
||||
### Always Validate
|
||||
- Mathematical inputs for overflow conditions
|
||||
- Precision requirements for financial calculations
|
||||
- Edge cases in mathematical implementations
|
||||
- Memory allocations in mathematical functions
|
||||
|
||||
### Security Commands
|
||||
```bash
|
||||
# Scan for secrets
|
||||
git-secrets --scan
|
||||
|
||||
# Security audit for mathematical implementations
|
||||
gosec ./pkg/uniswap/... ./pkg/math/...
|
||||
|
||||
# Dependency vulnerabilities
|
||||
go list -json -m all | nancy sleuth
|
||||
|
||||
# Check for hardcoded credentials
|
||||
grep -r "password|secret|key" --exclude-dir=.git .
|
||||
```
|
||||
34
.qwen/commands/implement-algorithm.md
Normal file
34
.qwen/commands/implement-algorithm.md
Normal file
@@ -0,0 +1,34 @@
|
||||
# Implement Mathematical Algorithm
|
||||
|
||||
Implement the following mathematical algorithm for the MEV bot: $ARGUMENTS
|
||||
|
||||
## Implementation Framework:
|
||||
1. **Requirements Analysis**: Break down the mathematical requirements and precision needs
|
||||
2. **Formula Implementation**: Convert mathematical formulas to precise Go code
|
||||
3. **Precision Handling**: Use appropriate data types (uint256, big.Int) for calculations
|
||||
4. **Edge Case Handling**: Consider boundary conditions and error scenarios
|
||||
5. **Testing**: Create comprehensive tests including property-based tests
|
||||
6. **Optimization**: Optimize for performance while maintaining precision
|
||||
|
||||
## Implementation Standards:
|
||||
- **Numerical Precision**: Use github.com/holiman/uint256 for precise uint256 arithmetic
|
||||
- **Error Handling**: Implement robust error handling with clear error messages
|
||||
- **Documentation**: Document all mathematical formulas and implementation decisions
|
||||
- **Testing**: Achieve >95% test coverage with property-based tests for mathematical functions
|
||||
- **Performance**: Consider performance implications and benchmark critical paths
|
||||
|
||||
## File Organization:
|
||||
- **Core Logic**: Place in appropriate `pkg/uniswap/` or `pkg/math/` subdirectory
|
||||
- **Tests**: Co-locate with source files (`*_test.go`)
|
||||
- **Documentation**: Inline comments explaining mathematical formulas
|
||||
|
||||
## Integration Points:
|
||||
- **Uniswap Pricing**: Integrate with `pkg/uniswap/` for pricing calculations
|
||||
- **Market Analysis**: Connect to `pkg/market/` for market data processing
|
||||
- **Precision Libraries**: Use `github.com/holiman/uint256` for uint256 arithmetic
|
||||
|
||||
## Deliverables:
|
||||
- Working implementation with comprehensive tests
|
||||
- Documentation of mathematical formulas and implementation approach
|
||||
- Performance benchmarks for critical functions
|
||||
- Edge case handling and error scenarios
|
||||
65
.qwen/commands/optimize-math.md
Normal file
65
.qwen/commands/optimize-math.md
Normal file
@@ -0,0 +1,65 @@
|
||||
# Optimize Mathematical Performance
|
||||
|
||||
Optimize the performance of the following mathematical function in the MEV bot: $ARGUMENTS
|
||||
|
||||
## Performance Optimization Strategy:
|
||||
|
||||
### 1. **Profiling and Measurement**
|
||||
```bash
|
||||
# CPU profiling for mathematical functions
|
||||
go tool pprof http://localhost:9090/debug/pprof/profile?seconds=30
|
||||
|
||||
# Memory profiling for mathematical calculations
|
||||
go tool pprof http://localhost:9090/debug/pprof/heap
|
||||
|
||||
# Benchmark testing for mathematical functions
|
||||
go test -bench=. -benchmem ./pkg/uniswap/...
|
||||
```
|
||||
|
||||
### 2. **Optimization Areas**
|
||||
|
||||
#### **Precision Handling Optimization**
|
||||
- Uint256 arithmetic optimization
|
||||
- Object pooling for frequent calculations
|
||||
- Minimize memory allocations in hot paths
|
||||
- Efficient conversion between data types
|
||||
|
||||
#### **Algorithm Optimization**
|
||||
- Mathematical formula simplification
|
||||
- Lookup table implementation for repeated calculations
|
||||
- Caching strategies for expensive computations
|
||||
- Parallel processing opportunities
|
||||
|
||||
#### **Memory Optimization**
|
||||
- Pre-allocation of slices and buffers
|
||||
- Object pooling for mathematical objects
|
||||
- Minimize garbage collection pressure
|
||||
- Efficient data structure selection
|
||||
|
||||
### 3. **MEV Bot Specific Optimizations**
|
||||
|
||||
#### **Uniswap V3 Pricing Functions**
|
||||
- sqrtPriceX96 to price conversion optimization
|
||||
- Tick calculation performance improvements
|
||||
- Liquidity-based calculation efficiency
|
||||
- Price impact computation optimization
|
||||
|
||||
#### **Arbitrage Calculations**
|
||||
- Profit calculation optimization
|
||||
- Cross-pool comparison performance
|
||||
- Gas estimation accuracy and speed
|
||||
- Multi-hop arbitrage efficiency
|
||||
|
||||
## Implementation Guidelines:
|
||||
- Measure before optimizing (baseline metrics)
|
||||
- Focus on bottlenecks identified through profiling
|
||||
- Maintain mathematical precision while improving performance
|
||||
- Add performance tests for regressions
|
||||
- Document optimization strategies and results
|
||||
|
||||
## Deliverables:
|
||||
- Performance benchmark results (before/after)
|
||||
- Optimized code with maintained precision
|
||||
- Performance monitoring enhancements
|
||||
- Optimization documentation
|
||||
- Regression test suite
|
||||
54
.qwen/commands/verify-precision.md
Normal file
54
.qwen/commands/verify-precision.md
Normal file
@@ -0,0 +1,54 @@
|
||||
# Verify Mathematical Precision
|
||||
|
||||
Verify the precision and correctness of the following mathematical implementation in the MEV bot: $ARGUMENTS
|
||||
|
||||
## Verification Protocol:
|
||||
|
||||
### 1. **Mathematical Correctness Analysis**
|
||||
- Review mathematical formulas against official specifications
|
||||
- Validate implementation against known test cases
|
||||
- Check boundary conditions and edge cases
|
||||
- Verify precision handling for large numbers
|
||||
|
||||
### 2. **Property-Based Testing**
|
||||
```bash
|
||||
# Run property-based tests for mathematical functions
|
||||
go test -v -run=Property ./pkg/uniswap/...
|
||||
|
||||
# Run fuzz tests for mathematical calculations
|
||||
go test -fuzz=Fuzz ./pkg/uniswap/...
|
||||
```
|
||||
|
||||
### 3. **Precision Validation Areas**
|
||||
|
||||
#### **Uniswap V3 Calculations**
|
||||
- sqrtPriceX96 to price conversion accuracy
|
||||
- Tick calculation correctness
|
||||
- Liquidity-based calculation precision
|
||||
- Price impact computation validation
|
||||
|
||||
#### **Financial Calculations**
|
||||
- Profit calculation accuracy
|
||||
- Gas estimation precision
|
||||
- Slippage protection validation
|
||||
- Fee calculation correctness
|
||||
|
||||
### 4. **Comparison Testing**
|
||||
- Compare results with reference implementations
|
||||
- Validate against on-chain data when possible
|
||||
- Cross-check with other DeFi protocol implementations
|
||||
- Benchmark against established mathematical libraries
|
||||
|
||||
## Verification Steps:
|
||||
1. **Static Analysis**: Review code for mathematical correctness
|
||||
2. **Unit Testing**: Verify with known test cases
|
||||
3. **Property Testing**: Test mathematical invariants
|
||||
4. **Fuzz Testing**: Find edge cases with random inputs
|
||||
5. **Comparison Testing**: Validate against reference implementations
|
||||
|
||||
## Output Requirements:
|
||||
- Detailed correctness analysis report
|
||||
- Precision validation results
|
||||
- Edge case identification and handling
|
||||
- Recommendations for improvements
|
||||
- Test suite enhancements
|
||||
141
.qwen/config/Makefile
Normal file
141
.qwen/config/Makefile
Normal file
@@ -0,0 +1,141 @@
|
||||
# Makefile for Qwen Code Integration
|
||||
|
||||
# Variables
|
||||
BINARY=mev-bot
|
||||
MAIN_FILE=cmd/mev-bot/main.go
|
||||
BINARY_PATH=bin/$(BINARY)
|
||||
|
||||
# Default target
|
||||
.PHONY: all
|
||||
all: build
|
||||
|
||||
# Build the application
|
||||
.PHONY: build
|
||||
build:
|
||||
@echo "Building $(BINARY)..."
|
||||
@mkdir -p bin
|
||||
@go build -o $(BINARY_PATH) $(MAIN_FILE)
|
||||
@echo "Build successful!"
|
||||
|
||||
# Run the application
|
||||
.PHONY: run
|
||||
run: build
|
||||
@echo "Running $(BINARY)..."
|
||||
@$(BINARY_PATH)
|
||||
|
||||
# Run tests
|
||||
.PHONY: test
|
||||
test:
|
||||
@echo "Running tests..."
|
||||
@go test -v ./...
|
||||
|
||||
# Run tests for mathematical functions
|
||||
.PHONY: test-math
|
||||
test-math:
|
||||
@echo "Running mathematical function tests..."
|
||||
@go test -v ./pkg/uniswap/... ./pkg/math/...
|
||||
|
||||
# Run property-based tests
|
||||
.PHONY: test-property
|
||||
test-property:
|
||||
@echo "Running property-based tests..."
|
||||
@go test -v -run=Property ./pkg/uniswap/... ./pkg/math/...
|
||||
|
||||
# Run fuzz tests
|
||||
.PHONY: test-fuzz
|
||||
test-fuzz:
|
||||
@echo "Running fuzz tests..."
|
||||
@go test -fuzz=Fuzz ./pkg/uniswap/... ./pkg/math/...
|
||||
|
||||
# Run benchmarks for mathematical functions
|
||||
.PHONY: bench-math
|
||||
bench-math:
|
||||
@echo "Running mathematical function benchmarks..."
|
||||
@go test -bench=. -benchmem ./pkg/uniswap/... ./pkg/math/...
|
||||
|
||||
# Run benchmarks with CPU profiling
|
||||
.PHONY: bench-cpu
|
||||
bench-cpu:
|
||||
@echo "Running benchmarks with CPU profiling..."
|
||||
@go test -bench=. -cpuprofile=cpu.prof ./pkg/uniswap/... ./pkg/math/...
|
||||
|
||||
# Run benchmarks with memory profiling
|
||||
.PHONY: bench-mem
|
||||
bench-mem:
|
||||
@echo "Running benchmarks with memory profiling..."
|
||||
@go test -bench=. -memprofile=mem.prof ./pkg/uniswap/... ./pkg/math/...
|
||||
|
||||
# Clean build artifacts
|
||||
.PHONY: clean
|
||||
clean:
|
||||
@echo "Cleaning..."
|
||||
@rm -rf bin/
|
||||
@rm -f *.prof
|
||||
@rm -f coverage.out coverage.html
|
||||
@echo "Clean complete!"
|
||||
|
||||
# Install dependencies
|
||||
.PHONY: deps
|
||||
deps:
|
||||
@echo "Installing dependencies..."
|
||||
@go mod tidy
|
||||
@echo "Dependencies installed!"
|
||||
|
||||
# Format code
|
||||
.PHONY: fmt
|
||||
fmt:
|
||||
@echo "Formatting code..."
|
||||
@go fmt ./...
|
||||
|
||||
# Vet code
|
||||
.PHONY: vet
|
||||
vet:
|
||||
@echo "Vetting code..."
|
||||
@go vet ./...
|
||||
|
||||
# Lint code (requires golangci-lint)
|
||||
.PHONY: lint
|
||||
lint:
|
||||
@echo "Linting code..."
|
||||
@which golangci-lint > /dev/null || (echo "golangci-lint not found, installing..." && go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest)
|
||||
@golangci-lint run
|
||||
|
||||
# Update dependencies
|
||||
.PHONY: update
|
||||
update:
|
||||
@echo "Updating dependencies..."
|
||||
@go get -u ./...
|
||||
@go mod tidy
|
||||
@echo "Dependencies updated!"
|
||||
|
||||
# Install test dependencies
|
||||
.PHONY: test-deps
|
||||
test-deps:
|
||||
@echo "Installing test dependencies..."
|
||||
@go get github.com/stretchr/testify/assert
|
||||
@go get github.com/leanovate/gopter/...
|
||||
@go mod tidy
|
||||
@echo "Test dependencies installed!"
|
||||
|
||||
# Help
|
||||
.PHONY: help
|
||||
help:
|
||||
@echo "Available targets:"
|
||||
@echo " all - Build the application (default)"
|
||||
@echo " build - Build the application"
|
||||
@echo " run - Build and run the application"
|
||||
@echo " test - Run tests"
|
||||
@echo " test-math - Run tests for mathematical functions"
|
||||
@echo " test-property - Run property-based tests"
|
||||
@echo " test-fuzz - Run fuzz tests"
|
||||
@echo " bench-math - Run benchmarks for mathematical functions"
|
||||
@echo " bench-cpu - Run benchmarks with CPU profiling"
|
||||
@echo " bench-mem - Run benchmarks with memory profiling"
|
||||
@echo " clean - Clean build artifacts"
|
||||
@echo " deps - Install dependencies"
|
||||
@echo " test-deps - Install test dependencies"
|
||||
@echo " fmt - Format code"
|
||||
@echo " vet - Vet code"
|
||||
@echo " lint - Lint code (requires golangci-lint)"
|
||||
@echo " update - Update dependencies"
|
||||
@echo " help - Show this help"
|
||||
73
.qwen/config/focus-areas.md
Normal file
73
.qwen/config/focus-areas.md
Normal file
@@ -0,0 +1,73 @@
|
||||
# Qwen Code Focus Area Definitions
|
||||
|
||||
## Primary Focus Areas
|
||||
|
||||
### 1. Mathematical Computations
|
||||
As Qwen Code, you're particularly skilled at implementing precise mathematical functions with high accuracy and performance. Focus on:
|
||||
- Implementing complex financial calculations with proper precision handling
|
||||
- Ensuring numerical stability across large ranges of values
|
||||
- Working with specialized mathematical libraries like `github.com/holiman/uint256`
|
||||
|
||||
### 2. Algorithmic Implementation
|
||||
You excel at converting mathematical formulas and algorithms into efficient Go code. Focus on:
|
||||
- Creating efficient algorithms for arbitrage detection
|
||||
- Implementing accurate conversions between different mathematical representations
|
||||
- Calculating price impact with proper precision handling
|
||||
|
||||
### 3. Precision Handling
|
||||
Your expertise in precision handling is critical for the MEV bot's success. Focus on:
|
||||
- Using appropriate data types for mathematical calculations
|
||||
- Implementing proper rounding strategies for financial calculations
|
||||
- Handling overflow and underflow conditions properly
|
||||
|
||||
### 4. Performance Optimization
|
||||
While maintaining precision, you're also skilled at optimizing mathematical computations. Focus on:
|
||||
- Minimizing memory allocations in hot paths
|
||||
- Optimizing uint256 arithmetic operations
|
||||
- Reducing garbage collection pressure
|
||||
- Improving mathematical computation efficiency
|
||||
|
||||
## Integration Guidelines
|
||||
|
||||
### Working with Uniswap V3 Mathematics
|
||||
- Focus on sqrtPriceX96 to price conversions
|
||||
- Implement accurate tick calculations
|
||||
- Handle liquidity-based calculations with precision
|
||||
- Optimize price impact computations
|
||||
|
||||
### Performance vs. Precision Balance
|
||||
- Always prioritize precision over performance in mathematical calculations
|
||||
- Use profiling to identify bottlenecks without compromising accuracy
|
||||
- Implement caching strategies for expensive computations
|
||||
- Leverage Go's concurrency for independent mathematical operations
|
||||
|
||||
## Code Quality Standards
|
||||
|
||||
### Testing Requirements
|
||||
- Achieve >95% test coverage for mathematical functions
|
||||
- Implement property-based tests for mathematical invariants
|
||||
- Use fuzz testing to find edge cases
|
||||
- Create benchmarks for performance-critical functions
|
||||
|
||||
### Documentation Standards
|
||||
- Document all mathematical formulas with clear explanations
|
||||
- Comment on precision handling decisions
|
||||
- Explain algorithmic choices and trade-offs
|
||||
- Provide usage examples for complex mathematical functions
|
||||
|
||||
## Collaboration with Other AI Assistants
|
||||
|
||||
### Claude (Architecture & System Design)
|
||||
- Follow architectural patterns defined by Claude
|
||||
- Integrate mathematical functions with system components
|
||||
- Adhere to error handling and logging standards
|
||||
|
||||
### OpenCode (Testing & Quality Assurance)
|
||||
- Work with OpenCode to ensure comprehensive test coverage
|
||||
- Follow testing patterns and quality standards
|
||||
- Address test failures and edge cases identified
|
||||
|
||||
### Gemini (Performance Optimization)
|
||||
- Collaborate on performance optimization strategies
|
||||
- Share profiling results and optimization insights
|
||||
- Coordinate on memory allocation reduction techniques
|
||||
51
.qwen/config/optimization.md
Normal file
51
.qwen/config/optimization.md
Normal file
@@ -0,0 +1,51 @@
|
||||
# Qwen Code Performance Optimization Settings
|
||||
|
||||
## Workflow Preferences
|
||||
- **Always commit changes**: Use `git commit -am "math: descriptive message"` for mathematical implementations
|
||||
- **Branch naming**: Use prefixes (`math-sqrt-price`, `algo-liquidity-calc`, `perf-uniswap`)
|
||||
- **Context management**: Focus on mathematical precision and performance
|
||||
- **Parallel processing**: Leverage Go's concurrency patterns for independent calculations
|
||||
|
||||
## File Organization Preferences
|
||||
- **Mathematical functions**: Place in `pkg/uniswap/` or `pkg/math/`
|
||||
- **Test files**: Place alongside source files with `_test.go` suffix
|
||||
- **Documentation**: Inline comments explaining mathematical formulas
|
||||
- **Precision libraries**: Use `github.com/holiman/uint256` for uint256 arithmetic
|
||||
|
||||
## Performance Monitoring
|
||||
```bash
|
||||
# Enable metrics endpoint for performance tracking
|
||||
export METRICS_ENABLED="true"
|
||||
export METRICS_PORT="9090"
|
||||
|
||||
# Monitor memory usage of mathematical calculations
|
||||
go tool pprof http://localhost:9090/debug/pprof/heap
|
||||
|
||||
# Monitor CPU usage of mathematical functions
|
||||
go tool pprof http://localhost:9090/debug/pprof/profile?seconds=30
|
||||
|
||||
# Run benchmarks for mathematical functions
|
||||
go test -bench=. -benchmem ./pkg/uniswap/...
|
||||
```
|
||||
|
||||
## Precision Requirements
|
||||
- **Uint256 Arithmetic**: Use `github.com/holiman/uint256` for all uint256 calculations
|
||||
- **Floating Point**: Use `math/big` for floating-point calculations when needed
|
||||
- **Rounding**: Implement proper rounding strategies for financial calculations
|
||||
- **Overflow Handling**: Handle overflow and underflow conditions properly
|
||||
|
||||
## Optimization Focus Areas
|
||||
1. **Mathematical Computation Efficiency**
|
||||
- Minimize computational overhead in pricing functions
|
||||
- Optimize sqrtPriceX96 to price conversions
|
||||
- Efficient tick calculations
|
||||
|
||||
2. **Memory Allocation Reduction**
|
||||
- Object pooling for frequently created mathematical objects
|
||||
- Pre-allocation of slices and buffers
|
||||
- Minimize garbage collection pressure
|
||||
|
||||
3. **Algorithmic Optimization**
|
||||
- Mathematical formula simplification
|
||||
- Lookup table implementation for repeated calculations
|
||||
- Caching strategies for expensive computations
|
||||
42
.qwen/config/performance.json
Normal file
42
.qwen/config/performance.json
Normal file
@@ -0,0 +1,42 @@
|
||||
{
|
||||
"focus_areas": [
|
||||
"Mathematical Computations",
|
||||
"Algorithmic Implementation",
|
||||
"Precision Handling",
|
||||
"Performance Optimization"
|
||||
],
|
||||
"primary_skills": [
|
||||
"Implementing precise Uniswap V3 pricing functions",
|
||||
"Ensuring numerical stability and precision",
|
||||
"Working with liquidity and fee calculations",
|
||||
"Creating efficient algorithms for arbitrage detection",
|
||||
"Implementing accurate tick and sqrtPriceX96 conversions",
|
||||
"Calculating price impact with proper precision handling"
|
||||
],
|
||||
"performance_optimization": {
|
||||
"enabled": true,
|
||||
"profiling": {
|
||||
"cpu": true,
|
||||
"memory": true,
|
||||
"goroutine": true
|
||||
},
|
||||
"optimization_targets": [
|
||||
"Minimize memory allocations in hot paths",
|
||||
"Optimize uint256 arithmetic operations",
|
||||
"Reduce garbage collection pressure",
|
||||
"Improve mathematical computation efficiency"
|
||||
]
|
||||
},
|
||||
"precision_requirements": {
|
||||
"math_library": "github.com/holiman/uint256",
|
||||
"floating_point": "math/big",
|
||||
"rounding_strategy": "bankers_rounding",
|
||||
"precision_target": "256_bits"
|
||||
},
|
||||
"testing": {
|
||||
"unit_test_coverage": 0.95,
|
||||
"property_based_testing": true,
|
||||
"fuzz_testing": true,
|
||||
"benchmarking": true
|
||||
}
|
||||
}
|
||||
20
.qwen/prompts/algorithm-optimization.md
Normal file
20
.qwen/prompts/algorithm-optimization.md
Normal file
@@ -0,0 +1,20 @@
|
||||
# Mathematical Algorithm Optimization
|
||||
|
||||
Optimize the following mathematical algorithm for performance while maintaining precision: $ARGUMENTS
|
||||
|
||||
## Optimization Focus:
|
||||
1. Reduce memory allocations in hot paths
|
||||
2. Minimize computational overhead
|
||||
3. Improve cache efficiency
|
||||
4. Leverage concurrency where appropriate
|
||||
|
||||
## Profiling Approach:
|
||||
- Use `go tool pprof` to identify bottlenecks
|
||||
- Create benchmarks to measure improvements
|
||||
- Validate precision is maintained after optimization
|
||||
- Test with realistic data sets
|
||||
|
||||
## Constraints:
|
||||
- Do not compromise mathematical precision
|
||||
- Maintain code readability and maintainability
|
||||
- Follow Go best practices for concurrency and error handling
|
||||
16
.qwen/prompts/uniswap-pricing.md
Normal file
16
.qwen/prompts/uniswap-pricing.md
Normal file
@@ -0,0 +1,16 @@
|
||||
# Uniswap V3 Pricing Function Implementation
|
||||
|
||||
Implement the following Uniswap V3 pricing function with high precision: $ARGUMENTS
|
||||
|
||||
## Requirements:
|
||||
1. Use `github.com/holiman/uint256` for all uint256 arithmetic
|
||||
2. Ensure mathematical precision and numerical stability
|
||||
3. Handle edge cases and boundary conditions
|
||||
4. Include comprehensive test coverage
|
||||
5. Provide performance benchmarks
|
||||
|
||||
## Implementation Guidelines:
|
||||
- Follow the official Uniswap V3 whitepaper specifications
|
||||
- Implement proper error handling for invalid inputs
|
||||
- Document mathematical formulas and implementation decisions
|
||||
- Optimize for performance while maintaining precision
|
||||
36
.qwen/scripts/math-optimize.sh
Executable file
36
.qwen/scripts/math-optimize.sh
Executable file
@@ -0,0 +1,36 @@
|
||||
#!/bin/bash
|
||||
|
||||
# math-optimize.sh - Optimize mathematical functions for Qwen Code
|
||||
|
||||
echo "Optimizing mathematical functions for Qwen Code..."
|
||||
|
||||
# Create results directory if it doesn't exist
|
||||
mkdir -p .qwen/results
|
||||
|
||||
# Run benchmarks to establish baseline
|
||||
echo "Establishing performance baseline..."
|
||||
go test -bench=. -benchmem ./pkg/uniswap/... ./pkg/math/... > .qwen/results/baseline-benchmarks.log
|
||||
|
||||
# Run CPU profiling
|
||||
echo "Running CPU profiling..."
|
||||
go test -bench=. -cpuprofile=.qwen/results/baseline-cpu.prof ./pkg/uniswap/... ./pkg/math/... > .qwen/results/baseline-cpu.log
|
||||
|
||||
# Run memory profiling
|
||||
echo "Running memory profiling..."
|
||||
go test -bench=. -memprofile=.qwen/results/baseline-mem.prof ./pkg/uniswap/... ./pkg/math/... > .qwen/results/baseline-mem.log
|
||||
|
||||
# Analyze profiling results
|
||||
echo "Analyzing profiling results..."
|
||||
go tool pprof -top .qwen/results/baseline-cpu.prof > .qwen/results/cpu-top.log
|
||||
go tool pprof -top .qwen/results/baseline-mem.prof > .qwen/results/mem-top.log
|
||||
|
||||
# Generate flame graphs (if go-torch is available)
|
||||
if command -v go-torch &> /dev/null; then
|
||||
echo "Generating flame graphs..."
|
||||
go-torch .qwen/results/baseline-cpu.prof > .qwen/results/cpu-flame.svg
|
||||
go-torch --alloc_objects .qwen/results/baseline-mem.prof > .qwen/results/mem-flame.svg
|
||||
fi
|
||||
|
||||
echo "Mathematical optimization analysis complete!"
|
||||
echo "Baseline results saved to .qwen/results/"
|
||||
echo "Review .qwen/results/cpu-top.log and .qwen/results/mem-top.log for optimization opportunities"
|
||||
42
.qwen/scripts/math-test.sh
Executable file
42
.qwen/scripts/math-test.sh
Executable file
@@ -0,0 +1,42 @@
|
||||
#!/bin/bash
|
||||
|
||||
# math-test.sh - Run comprehensive mathematical tests for Qwen Code
|
||||
|
||||
echo "Running comprehensive mathematical tests for Qwen Code..."
|
||||
|
||||
# Create results directory if it doesn't exist
|
||||
mkdir -p .qwen/results
|
||||
|
||||
# Run unit tests for mathematical functions
|
||||
echo "Running unit tests for mathematical functions..."
|
||||
go test -v ./pkg/uniswap/... ./pkg/math/... | tee .qwen/results/math-unit-tests.log
|
||||
|
||||
# Run property-based tests
|
||||
echo "Running property-based tests..."
|
||||
go test -v -run=Property ./pkg/uniswap/... ./pkg/math/... | tee .qwen/results/math-property-tests.log
|
||||
|
||||
# Run fuzz tests (limited time)
|
||||
echo "Running fuzz tests (60 seconds)..."
|
||||
timeout 60s go test -fuzz=Fuzz ./pkg/uniswap/... ./pkg/math/... | tee .qwen/results/math-fuzz-tests.log
|
||||
|
||||
# Run benchmarks
|
||||
echo "Running mathematical function benchmarks..."
|
||||
go test -bench=. -benchmem ./pkg/uniswap/... ./pkg/math/... | tee .qwen/results/math-benchmarks.log
|
||||
|
||||
# Run benchmarks with CPU profiling
|
||||
echo "Running benchmarks with CPU profiling..."
|
||||
go test -bench=. -cpuprofile=.qwen/results/cpu.prof ./pkg/uniswap/... ./pkg/math/... | tee .qwen/results/math-cpu-bench.log
|
||||
|
||||
# Run benchmarks with memory profiling
|
||||
echo "Running benchmarks with memory profiling..."
|
||||
go test -bench=. -memprofile=.qwen/results/mem.prof ./pkg/uniswap/... ./pkg/math/... | tee .qwen/results/math-mem-bench.log
|
||||
|
||||
# Check for errors
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "All mathematical tests completed successfully!"
|
||||
echo "Results saved to .qwen/results/"
|
||||
else
|
||||
echo "Some mathematical tests failed!"
|
||||
echo "Check .qwen/results/ for details"
|
||||
exit 1
|
||||
fi
|
||||
42
.qwen/scripts/perf-test.sh
Executable file
42
.qwen/scripts/perf-test.sh
Executable file
@@ -0,0 +1,42 @@
|
||||
#!/bin/bash
|
||||
|
||||
# perf-test.sh - Run comprehensive performance tests for Qwen Code
|
||||
|
||||
echo "Running comprehensive mathematical performance tests for Qwen Code..."
|
||||
|
||||
# Create results directory if it doesn't exist
|
||||
mkdir -p .qwen/results
|
||||
|
||||
# Run unit tests for mathematical functions
|
||||
echo "Running unit tests for mathematical functions..."
|
||||
go test -v ./pkg/uniswap/... ./pkg/math/... | tee .qwen/results/math-unit-tests.log
|
||||
|
||||
# Run property-based tests
|
||||
echo "Running property-based tests..."
|
||||
go test -v -run=Property ./pkg/uniswap/... ./pkg/math/... | tee .qwen/results/math-property-tests.log
|
||||
|
||||
# Run fuzz tests (limited time)
|
||||
echo "Running fuzz tests (60 seconds)..."
|
||||
timeout 60s go test -fuzz=Fuzz ./pkg/uniswap/... ./pkg/math/... | tee .qwen/results/math-fuzz-tests.log
|
||||
|
||||
# Run benchmarks
|
||||
echo "Running mathematical function benchmarks..."
|
||||
go test -bench=. -benchmem ./pkg/uniswap/... ./pkg/math/... | tee .qwen/results/math-benchmarks.log
|
||||
|
||||
# Run benchmarks with CPU profiling
|
||||
echo "Running benchmarks with CPU profiling..."
|
||||
go test -bench=. -cpuprofile=.qwen/results/cpu.prof ./pkg/uniswap/... ./pkg/math/... | tee .qwen/results/math-cpu-bench.log
|
||||
|
||||
# Run benchmarks with memory profiling
|
||||
echo "Running benchmarks with memory profiling..."
|
||||
go test -bench=. -memprofile=.qwen/results/mem.prof ./pkg/uniswap/... ./pkg/math/... | tee .qwen/results/math-mem-bench.log
|
||||
|
||||
# Check for errors
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "All mathematical performance tests completed successfully!"
|
||||
echo "Results saved to .qwen/results/"
|
||||
else
|
||||
echo "Some mathematical performance tests failed!"
|
||||
echo "Check .qwen/results/ for details"
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user