Update module name to github.com/fraktal/mev-beta and fix channel closing issues in pipeline stages
This commit is contained in:
@@ -10,8 +10,9 @@ The monitoring system connects to an Arbitrum RPC endpoint and continuously moni
|
||||
|
||||
### ArbitrumMonitor
|
||||
The main monitoring component that handles:
|
||||
- Connecting to the Arbitrum RPC endpoint
|
||||
- Polling for new blocks
|
||||
- Connecting to the arbitrum sequencer and parsing feed and filtering pool swaps and/or router swaps and the like (slight look into the future (very slight, as transations are processed every 250ms))
|
||||
- Connecting to the Arbitrum WSS endpoint, RPC as redundant backup (get actual values in realtime)
|
||||
- Subscribing to new blocks filtered based on filters (for pool discovery, addresses should not be filterd) ()
|
||||
- Processing transactions in new blocks
|
||||
- Identifying potential swap transactions
|
||||
|
||||
|
||||
201
docs/project-plan.md
Normal file
201
docs/project-plan.md
Normal file
@@ -0,0 +1,201 @@
|
||||
# MEV Bot Project Plan
|
||||
|
||||
## Overview
|
||||
This document outlines the comprehensive plan for developing a high-performance MEV (Maximal Extractable Value) bot with modular architecture supporting multiple transport mechanisms. The bot will monitor the Arbitrum sequencer for potential swap opportunities and identify profitable arbitrage opportunities.
|
||||
|
||||
## Project Goals
|
||||
1. Build a modular MEV bot with independent components
|
||||
2. Implement high-frequency, low-latency communication between modules
|
||||
3. Support multiple transport mechanisms (shared memory, Unix sockets, TCP, WebSockets, gRPC)
|
||||
4. Enable deployment as monolithic or distributed system
|
||||
5. Implement robust lifecycle management for all modules
|
||||
6. Ensure deterministic transaction ordering for arbitrage opportunities
|
||||
|
||||
## Architecture Summary
|
||||
|
||||
### Core Components
|
||||
1. **Configuration Manager** - Centralized configuration handling
|
||||
2. **Event Parser** - DEX event detection and parsing
|
||||
3. **Market Monitor** - Arbitrum sequencer monitoring
|
||||
4. **Market Pipeline** - Transaction processing pipeline
|
||||
5. **Market Scanner** - Arbitrage opportunity detection
|
||||
6. **Execution Engine** - Transaction execution
|
||||
7. **Risk Manager** - Risk assessment and management
|
||||
8. **Data Store** - Persistent storage for market data
|
||||
|
||||
### Communication Layer
|
||||
- **Universal Message Bus** supporting multiple transports
|
||||
- **Smart Router** for automatic transport selection
|
||||
- **Module Manager** for lifecycle control
|
||||
- **WebSockets/gRPC** for external interfaces
|
||||
|
||||
## Development Phases
|
||||
|
||||
### Phase 1: Foundation (Weeks 1-2)
|
||||
- [ ] Set up project structure and configuration management
|
||||
- [ ] Implement basic Arbitrum sequencer monitoring
|
||||
- [ ] Create event parser for DEX interactions
|
||||
- [ ] Establish core data structures and interfaces
|
||||
|
||||
### Phase 2: Pipeline & Scanner (Weeks 3-4)
|
||||
- [ ] Develop market processing pipeline
|
||||
- [ ] Implement market scanner with concurrency support
|
||||
- [ ] Add Uniswap V3 pricing calculations
|
||||
- [ ] Create basic arbitrage detection logic
|
||||
|
||||
### Phase 3: Communication Layer (Weeks 5-6)
|
||||
- [ ] Implement universal message bus
|
||||
- [ ] Add shared memory transport
|
||||
- [ ] Add Unix socket transport
|
||||
- [ ] Create smart router for transport selection
|
||||
|
||||
### Phase 4: Advanced Features (Weeks 7-8)
|
||||
- [ ] Add TCP/WebSocket transport support
|
||||
- [ ] Implement gRPC control interface
|
||||
- [ ] Develop module lifecycle management
|
||||
- [ ] Create transaction ordering system
|
||||
|
||||
### Phase 5: Execution & Risk (Weeks 9-10)
|
||||
- [ ] Build execution engine
|
||||
- [ ] Implement risk management module
|
||||
- [ ] Add data persistence layer
|
||||
- [ ] Create monitoring and metrics
|
||||
|
||||
### Phase 6: Testing & Optimization (Weeks 11-12)
|
||||
- [ ] Comprehensive unit and integration testing
|
||||
- [ ] Performance optimization
|
||||
- [ ] Security auditing
|
||||
- [ ] Documentation and examples
|
||||
|
||||
## Module Specifications
|
||||
|
||||
### Configuration Manager
|
||||
- Load configuration from YAML file
|
||||
- Override with environment variables
|
||||
- Support hot reloading of configuration
|
||||
- Validate configuration parameters
|
||||
|
||||
### Event Parser
|
||||
- Detect DEX interactions (Uniswap V2/V3, SushiSwap)
|
||||
- Parse transaction data for swap events
|
||||
- Identify token addresses and amounts
|
||||
- Extract price and liquidity information
|
||||
|
||||
### Market Monitor
|
||||
- Connect to Arbitrum RPC endpoint
|
||||
- Monitor sequencer for new blocks
|
||||
- Extract transactions from blocks
|
||||
- Rate limiting for RPC calls
|
||||
- Fallback endpoint support
|
||||
|
||||
### Market Pipeline
|
||||
- Multi-stage transaction processing
|
||||
- Concurrent processing with worker pools
|
||||
- Configurable pipeline stages
|
||||
- Error handling and recovery
|
||||
|
||||
### Market Scanner
|
||||
- Analyze swap events for price impact
|
||||
- Calculate arbitrage opportunities
|
||||
- Worker pool for concurrent processing
|
||||
- Caching for pool data
|
||||
- Profitability filtering
|
||||
|
||||
### Execution Engine
|
||||
- Sign and submit arbitrage transactions
|
||||
- Gas price optimization
|
||||
- Transaction nonce management
|
||||
- Error handling and retry logic
|
||||
|
||||
### Risk Manager
|
||||
- Position sizing
|
||||
- Portfolio risk limits
|
||||
- Market impact assessment
|
||||
- Emergency stop functionality
|
||||
|
||||
### Data Store
|
||||
- Persistent storage for market data
|
||||
- Configuration caching
|
||||
- Performance metrics storage
|
||||
- Historical data analysis
|
||||
|
||||
## Communication Architecture
|
||||
|
||||
### Transport Types
|
||||
1. **Shared Memory** - Ultra-low latency for same-process modules
|
||||
2. **Unix Sockets** - Low latency for local inter-process communication
|
||||
3. **TCP** - Standard networking for remote modules
|
||||
4. **WebSockets** - Real-time communication for monitoring
|
||||
5. **gRPC** - High-performance RPC for control plane
|
||||
|
||||
### Message Routing
|
||||
- Topic-based message routing
|
||||
- Automatic transport selection based on:
|
||||
- Message size
|
||||
- Destination location
|
||||
- Latency requirements
|
||||
- System load
|
||||
- Dead letter queue for failed messages
|
||||
- Message persistence for critical data
|
||||
|
||||
### Module Lifecycle
|
||||
- START/STOP/PAUSE/RESUME commands
|
||||
- Health checks and status reporting
|
||||
- Dependency management
|
||||
- Graceful shutdown procedures
|
||||
|
||||
## Performance Requirements
|
||||
- Latency < 10 microseconds for critical path
|
||||
- Throughput > 100,000 messages/second
|
||||
- Sub-millisecond processing for arbitrage detection
|
||||
- Deterministic transaction ordering
|
||||
- Horizontal scalability
|
||||
|
||||
## Security Considerations
|
||||
- Secure key management
|
||||
- Rate limiting and DoS protection
|
||||
- Input validation and sanitization
|
||||
- Audit logging
|
||||
- Secure communication channels
|
||||
|
||||
## Testing Strategy
|
||||
- Unit tests for each component
|
||||
- Integration tests for module interactions
|
||||
- Performance benchmarks
|
||||
- Chaos engineering for fault tolerance
|
||||
- Security penetration testing
|
||||
|
||||
## Deployment Options
|
||||
1. **Monolithic** - All modules in single process
|
||||
2. **Distributed** - Modules as separate processes/services
|
||||
3. **Hybrid** - Critical modules local, others remote
|
||||
4. **Clustered** - Multiple instances for load distribution
|
||||
|
||||
## Monitoring & Observability
|
||||
- Real-time status dashboards
|
||||
- Performance metrics collection
|
||||
- Alerting for critical events
|
||||
- Log aggregation and analysis
|
||||
- Tracing for transaction flow
|
||||
|
||||
## Documentation Requirements
|
||||
- Installation and setup guide
|
||||
- Configuration reference
|
||||
- API documentation
|
||||
- Deployment guides for each mode
|
||||
- Troubleshooting guide
|
||||
- Performance tuning guide
|
||||
|
||||
## Success Metrics
|
||||
- Transaction processing latency
|
||||
- Arbitrage detection accuracy
|
||||
- System uptime
|
||||
- Resource utilization
|
||||
- Profitability of executed trades
|
||||
|
||||
## Risk Mitigation
|
||||
- Circuit breakers for market volatility
|
||||
- Position limits to prevent excessive exposure
|
||||
- Graceful degradation under load
|
||||
- Backup systems for critical components
|
||||
- Regular security audits
|
||||
Reference in New Issue
Block a user