2025-05-28 21:53:03 +00:00

92 lines
2.9 KiB
Markdown

# 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 arbitrage
- `GET /api/v1/arbitrage/status` - Get current scan status
- `GET /api/v1/arbitrage/events` - List detected arbitrage events
- `GET /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
1. Clone the repository
2. 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
1. Start the application:
```
uvicorn main:app --host 0.0.0.0 --port 8000
```
2. 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:
1. Looks for transactions with multiple token swap operations
2. Identifies circular patterns (A → B → C → A)
3. 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 blockchain
- `transactions` - Records transactions from scanned blocks
- `token_transfers` - Tracks token transfers within transactions
- `arbitrage_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
[MIT License](LICENSE)