
- Add detailed logging throughout the Solana client and scanner - Improve error handling in RPC client methods - Add debug endpoints to validate Solana connection - Add message field to scan status responses - Enhance health endpoint with RPC connectivity status - Handle invalid block ranges and API rate limits
Solana Arbitrage Detector
A FastAPI-based service that scans the Solana blockchain for arbitrage transactions. The detector analyzes recent blocks to identify and track potential arbitrage opportunities.
Features
- Blockchain Scanning: Monitors the latest Solana blocks for transactions
- Arbitrage Detection: Analyzes transactions to identify potential arbitrage patterns
- Database Storage: Persists blocks, transactions, and arbitrage events
- REST API: Provides endpoints to access arbitrage data and control scanning
- Background Processing: Automatic periodic scanning of the blockchain
- Health Monitoring: Health check endpoint for system monitoring
API Endpoints
Arbitrage API
POST /api/v1/arbitrage/scan
- Trigger a blockchain scan for arbitrageGET /api/v1/arbitrage/status
- Get current scan statusGET /api/v1/arbitrage/events
- List detected arbitrage eventsGET /api/v1/arbitrage/events/{event_id}
- Get details of a specific arbitrage event
Health Check
GET /health
- Check application health status
Setup and Configuration
Prerequisites
- Python 3.8+
- SQLite database
Installation
- Clone the repository
- Install dependencies:
pip install -r requirements.txt
Environment Variables
The application can be configured using the following environment variables:
SOLANA_RPC_URL
- Solana RPC URL (default: "https://api.mainnet-beta.solana.com")SOLANA_BLOCKS_TO_SCAN
- Number of blocks to scan (default: 10)SCAN_INTERVAL_SECONDS
- Interval between automatic scans in seconds (default: 60)
Running the Application
-
Start the application:
uvicorn main:app --host 0.0.0.0 --port 8000
-
Access the API documentation at
http://localhost:8000/docs
Implementation Details
Arbitrage Detection
The current implementation uses a simple pattern-matching approach to identify potential arbitrage transactions:
- Looks for transactions with multiple token swap operations
- Identifies circular patterns (A → B → C → A)
- Assigns a confidence score based on pattern recognition
In a production environment, this would be enhanced with:
- Token price data integration
- More sophisticated pattern matching
- Profit calculation algorithms
- Machine learning-based classification
Database Schema
blocks
- Stores block data from the Solana blockchaintransactions
- Records transactions from scanned blockstoken_transfers
- Tracks token transfers within transactionsarbitrage_events
- Stores detected arbitrage events with metadata
Future Enhancements
- Real-time profit calculation using token price feeds
- Support for specific DEX protocols (Raydium, Orca, Jupiter, etc.)
- User notifications for arbitrage opportunities
- Historical analytics and trend visualization
- Machine learning for improved detection accuracy
License
Description
Languages
Python
99.5%
Mako
0.5%