feat: create v2-prep branch with comprehensive planning
Restructured project for V2 refactor: **Structure Changes:** - Moved all V1 code to orig/ folder (preserved with git mv) - Created docs/planning/ directory - Added orig/README_V1.md explaining V1 preservation **Planning Documents:** - 00_V2_MASTER_PLAN.md: Complete architecture overview - Executive summary of critical V1 issues - High-level component architecture diagrams - 5-phase implementation roadmap - Success metrics and risk mitigation - 07_TASK_BREAKDOWN.md: Atomic task breakdown - 99+ hours of detailed tasks - Every task < 2 hours (atomic) - Clear dependencies and success criteria - Organized by implementation phase **V2 Key Improvements:** - Per-exchange parsers (factory pattern) - Multi-layer strict validation - Multi-index pool cache - Background validation pipeline - Comprehensive observability **Critical Issues Addressed:** - Zero address tokens (strict validation + cache enrichment) - Parsing accuracy (protocol-specific parsers) - No audit trail (background validation channel) - Inefficient lookups (multi-index cache) - Stats disconnection (event-driven metrics) Next Steps: 1. Review planning documents 2. Begin Phase 1: Foundation (P1-001 through P1-010) 3. Implement parsers in Phase 2 4. Build cache system in Phase 3 5. Add validation pipeline in Phase 4 6. Migrate and test in Phase 5 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
139
orig/pkg/dex/config.go
Normal file
139
orig/pkg/dex/config.go
Normal file
@@ -0,0 +1,139 @@
|
||||
package dex
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Config represents DEX configuration
|
||||
type Config struct {
|
||||
// Feature flags
|
||||
Enabled bool `yaml:"enabled" json:"enabled"`
|
||||
EnabledProtocols []string `yaml:"enabled_protocols" json:"enabled_protocols"`
|
||||
|
||||
// Profitability thresholds
|
||||
MinProfitETH float64 `yaml:"min_profit_eth" json:"min_profit_eth"` // Minimum profit in ETH
|
||||
MinProfitUSD float64 `yaml:"min_profit_usd" json:"min_profit_usd"` // Minimum profit in USD
|
||||
MaxPriceImpact float64 `yaml:"max_price_impact" json:"max_price_impact"` // Maximum acceptable price impact (0-1)
|
||||
MinConfidence float64 `yaml:"min_confidence" json:"min_confidence"` // Minimum confidence score (0-1)
|
||||
|
||||
// Multi-hop configuration
|
||||
MaxHops int `yaml:"max_hops" json:"max_hops"` // Maximum number of hops (2-4)
|
||||
EnableMultiHop bool `yaml:"enable_multi_hop" json:"enable_multi_hop"` // Enable multi-hop arbitrage
|
||||
|
||||
// Performance settings
|
||||
ParallelQueries bool `yaml:"parallel_queries" json:"parallel_queries"` // Query DEXes in parallel
|
||||
TimeoutSeconds int `yaml:"timeout_seconds" json:"timeout_seconds"` // Query timeout
|
||||
CacheTTLSeconds int `yaml:"cache_ttl_seconds" json:"cache_ttl_seconds"` // Pool cache TTL
|
||||
MaxConcurrent int `yaml:"max_concurrent" json:"max_concurrent"` // Max concurrent queries
|
||||
|
||||
// Gas settings
|
||||
MaxGasPrice uint64 `yaml:"max_gas_price" json:"max_gas_price"` // Maximum gas price in gwei
|
||||
GasBuffer float64 `yaml:"gas_buffer" json:"gas_buffer"` // Gas estimate buffer multiplier
|
||||
|
||||
// Monitoring
|
||||
EnableMetrics bool `yaml:"enable_metrics" json:"enable_metrics"`
|
||||
MetricsInterval int `yaml:"metrics_interval" json:"metrics_interval"`
|
||||
}
|
||||
|
||||
// DefaultConfig returns default DEX configuration
|
||||
func DefaultConfig() *Config {
|
||||
return &Config{
|
||||
Enabled: true,
|
||||
EnabledProtocols: []string{"uniswap_v3", "sushiswap", "curve", "balancer"},
|
||||
|
||||
MinProfitETH: 0.0001, // $0.25 @ $2500/ETH
|
||||
MinProfitUSD: 0.25, // $0.25
|
||||
MaxPriceImpact: 0.05, // 5%
|
||||
MinConfidence: 0.5, // 50%
|
||||
|
||||
MaxHops: 4,
|
||||
EnableMultiHop: true,
|
||||
|
||||
ParallelQueries: true,
|
||||
TimeoutSeconds: 5,
|
||||
CacheTTLSeconds: 30, // 30 second cache
|
||||
MaxConcurrent: 10, // Max 10 concurrent queries
|
||||
|
||||
MaxGasPrice: 100, // 100 gwei max
|
||||
GasBuffer: 1.2, // 20% gas buffer
|
||||
|
||||
EnableMetrics: true,
|
||||
MetricsInterval: 60, // 60 seconds
|
||||
}
|
||||
}
|
||||
|
||||
// ProductionConfig returns production-optimized configuration
|
||||
func ProductionConfig() *Config {
|
||||
return &Config{
|
||||
Enabled: true,
|
||||
EnabledProtocols: []string{"uniswap_v3", "sushiswap", "curve", "balancer"},
|
||||
|
||||
MinProfitETH: 0.0002, // $0.50 @ $2500/ETH - higher threshold for production
|
||||
MinProfitUSD: 0.50,
|
||||
MaxPriceImpact: 0.03, // 3% - stricter for production
|
||||
MinConfidence: 0.7, // 70% - higher confidence required
|
||||
|
||||
MaxHops: 3, // Limit to 3 hops for lower gas
|
||||
EnableMultiHop: true,
|
||||
|
||||
ParallelQueries: true,
|
||||
TimeoutSeconds: 3, // Faster timeout for production
|
||||
CacheTTLSeconds: 15, // Shorter cache for fresher data
|
||||
MaxConcurrent: 20, // More concurrent for speed
|
||||
|
||||
MaxGasPrice: 50, // 50 gwei max for production
|
||||
GasBuffer: 1.3, // 30% gas buffer for safety
|
||||
|
||||
EnableMetrics: true,
|
||||
MetricsInterval: 30, // More frequent metrics
|
||||
}
|
||||
}
|
||||
|
||||
// Validate validates configuration
|
||||
func (c *Config) Validate() error {
|
||||
if c.MinProfitETH < 0 {
|
||||
return fmt.Errorf("min_profit_eth must be >= 0")
|
||||
}
|
||||
if c.MaxPriceImpact < 0 || c.MaxPriceImpact > 1 {
|
||||
return fmt.Errorf("max_price_impact must be between 0 and 1")
|
||||
}
|
||||
if c.MinConfidence < 0 || c.MinConfidence > 1 {
|
||||
return fmt.Errorf("min_confidence must be between 0 and 1")
|
||||
}
|
||||
if c.MaxHops < 2 || c.MaxHops > 4 {
|
||||
return fmt.Errorf("max_hops must be between 2 and 4")
|
||||
}
|
||||
if c.TimeoutSeconds < 1 {
|
||||
return fmt.Errorf("timeout_seconds must be >= 1")
|
||||
}
|
||||
if c.CacheTTLSeconds < 0 {
|
||||
return fmt.Errorf("cache_ttl_seconds must be >= 0")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetTimeout returns timeout as duration
|
||||
func (c *Config) GetTimeout() time.Duration {
|
||||
return time.Duration(c.TimeoutSeconds) * time.Second
|
||||
}
|
||||
|
||||
// GetCacheTTL returns cache TTL as duration
|
||||
func (c *Config) GetCacheTTL() time.Duration {
|
||||
return time.Duration(c.CacheTTLSeconds) * time.Second
|
||||
}
|
||||
|
||||
// GetMetricsInterval returns metrics interval as duration
|
||||
func (c *Config) GetMetricsInterval() time.Duration {
|
||||
return time.Duration(c.MetricsInterval) * time.Second
|
||||
}
|
||||
|
||||
// IsProtocolEnabled checks if a protocol is enabled
|
||||
func (c *Config) IsProtocolEnabled(protocol string) bool {
|
||||
for _, p := range c.EnabledProtocols {
|
||||
if p == protocol {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
Reference in New Issue
Block a user