Automated Action 85b1f2a581 Enhance Solana RPC client with better error handling and debugging
- 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
2025-05-28 23:08:35 +00:00
2025-05-28 21:44:30 +00:00

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

Description
Project: Solana Arbitrage Detector
Readme 90 KiB
Languages
Python 99.5%
Mako 0.5%