7.2 KiB
MEV Bot Project - OpenCode Context
This file contains context information for OpenCode about the MEV Bot project.
Project Overview
This is an MEV (Maximal Extractable Value) bot written in Go 1.24+ that monitors the Arbitrum sequencer for potential swap opportunities. When a potential swap is detected, the bot scans the market to determine if the swap is large enough to move the price using off-chain methods.
Project Structure
cmd/- Main applications (specificallycmd/mev-bot/main.go)internal/- Private application and library codeinternal/config- Configuration managementinternal/logger- Logging functionalityinternal/ratelimit- Rate limiting implementationsinternal/utils- Utility functions
pkg/- Library code that can be used by external projectspkg/events- Event processing systempkg/market- Market data handlingpkg/monitor- Arbitrum sequencer monitoringpkg/scanner- Market scanning functionalitypkg/test- Test utilities and helperspkg/uniswap- Uniswap V3 specific implementations
config/- Configuration files@prompts/- AI prompts for development assistancedocs/- Documentationscripts/- Scripts for building, testing, and deployment
Key Integration Points
- Refer to @prompts/COMMON.md for core requirements and integration points
- Follow the modular architecture with independent components
- Use the universal message bus for inter-module communication
- Adhere to the standards defined in the project plan
Development Guidelines
- Focus on implementing the features outlined in the project plan
- Ensure all code follows Go best practices
- Write comprehensive tests for all functionality
- Document all public APIs and complex algorithms
- Follow the performance requirements outlined in COMMON.md
Code Quality and Testing Standards
Go Best Practices
-
Error Handling
- Use Go's error wrapping with context:
fmt.Errorf("failed to process transaction: %w", err) - Implement retry mechanisms with exponential backoff for transient failures
- Handle timeouts appropriately with context cancellation
- Log errors at appropriate levels (debug, info, warn, error)
- Use Go's error wrapping with context:
-
Concurrency Safety
- Use mutexes correctly to protect shared data
- Avoid race conditions with proper synchronization
- Use channels for communication between goroutines
- Implement graceful shutdown procedures
-
Code Structure
- Follow idiomatic Go patterns and conventions
- Use clear, descriptive names for variables, functions, and types
- Organize code into logical packages with clear responsibilities
- Implement interfaces for loose coupling between components
-
Performance Considerations
- Minimize memory allocations in hot paths
- Use appropriate data structures for the task
- Profile code regularly to identify bottlenecks
- Follow the performance requirements (latency < 10 microseconds for critical path)
Testing Standards
-
Unit Testing
- Write tests for all functions and methods
- Use table-driven tests for multiple test cases
- Mock external dependencies for deterministic testing
- Test edge cases and boundary conditions
-
Integration Testing
- Test component interactions and data flow
- Verify correct behavior with real (or realistic) data
- Test error conditions and recovery mechanisms
- Validate configuration loading and environment variable overrides
-
Property-Based Testing
- Use property-based testing for mathematical functions
- Verify invariants and mathematical relationships
- Test with randomized inputs to find edge cases
- Ensure numerical stability and precision
-
Benchmarking
- Create benchmarks for performance-critical code paths
- Measure latency and throughput for core functionality
- Compare performance before and after optimizations
- Identify bottlenecks in the processing pipeline
Documentation Standards
-
Code Comments
- Comment all exported functions, types, and variables
- Explain complex algorithms and mathematical calculations
- Document any non-obvious implementation decisions
- Keep comments up-to-date with code changes
-
API Documentation
- Provide clear usage examples for public APIs
- Document expected inputs and outputs
- Explain error conditions and return values
- Include performance characteristics where relevant
-
Architecture Documentation
- Maintain up-to-date architectural diagrams
- Document data flow between components
- Explain design decisions and trade-offs
- Provide deployment and configuration guides
Debugging and Troubleshooting
Common Issues and Solutions
-
Rate Limiting Problems
- Monitor RPC call rates and adjust configuration
- Implement proper fallback mechanisms for RPC endpoints
- Use caching to reduce duplicate requests
-
Concurrency Issues
- Use race detection tools during testing
- Implement proper locking for shared data
- Avoid deadlocks with careful resource ordering
-
Precision Errors
- Use appropriate data types for mathematical calculations
- Validate results against known test cases
- Handle overflow and underflow conditions properly
Debugging Tools and Techniques
-
Logging
- Use structured logging with appropriate levels
- Include contextual information in log messages
- Implement log sampling for high-frequency events
-
Profiling
- Use Go's built-in profiling tools (pprof)
- Monitor CPU, memory, and goroutine usage
- Identify hot paths and optimization opportunities
-
Testing Utilities
- Use the test utilities in
pkg/test - Create realistic test data for validation
- Implement integration tests for end-to-end validation
- Use the test utilities in
OpenCode's Primary Focus Areas
As OpenCode, you're particularly skilled at:
-
Writing and Debugging Go Code
- Implementing clean, idiomatic Go code
- Following established patterns and conventions
- Debugging complex concurrency issues
- Optimizing code for performance and readability
-
Implementing Test Cases and Ensuring Code Quality
- Writing comprehensive unit and integration tests
- Implementing property-based tests for mathematical functions
- Creating performance benchmarks for critical paths
- Ensuring proper error handling and recovery
-
Following Established Coding Patterns and Conventions
- Using appropriate design patterns (worker pools, pipelines, etc.)
- Following Go's idiomatic patterns and best practices
- Implementing consistent error handling and logging
- Maintaining code organization and package structure
-
Identifying and Fixing Bugs
- Debugging race conditions and concurrency issues
- Identifying performance bottlenecks
- Fixing precision errors in mathematical calculations
- Resolving configuration and deployment issues
-
Ensuring Code is Well-Structured and Readable
- Organizing code into logical packages with clear responsibilities
- Using clear, descriptive naming conventions
- Implementing proper abstraction and encapsulation
- Maintaining consistency across the codebase
When working on this project, please focus on these areas where your strengths will be most beneficial.