Skip to content

sohailblockchain/Solana-Cluster-Monitoring-Backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

13 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Solana Cluster Monitoring Backend

Contributing

Contributions are welcome

A comprehensive FastAPI backend for real-time monitoring and detection of coordinated wallet clusters on the Solana blockchain. This system identifies parent wallets that fund multiple child wallets within short time windows, tracks their token trading activities, and provides detailed analytics for blockchain analysis.

🎯 Project Overview

This backend provides real-time on-chain monitoring capabilities for the Solana blockchain with the following core features:

  • Cluster Detection: Identifies parent wallets funding 5+ child wallets within configurable time windows
  • Token Activity Tracking: Monitors buy/sell activities of detected child wallets
  • Real-time Polling: Continuously polls Solana transactions every 10-30 seconds
  • Helius API Integration: Leverages Helius API for fast, decoded transaction data
  • RESTful API: Provides comprehensive endpoints for frontend dashboard integration

Use Cases

  • MEV Detection: Identify coordinated market manipulation strategies
  • Bot Activity Monitoring: Track automated trading patterns
  • Market Analysis: Analyze coordinated buying/selling behaviors
  • Security Research: Detect suspicious wallet clustering activities

πŸ—οΈ Project Structure

Solana-Cluster-Monitoring-Backend/
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ api/v1/                 # API version 1 endpoints
β”‚   β”‚   β”œβ”€β”€ endpoints/
β”‚   β”‚   β”‚   β”œβ”€β”€ auth.py         # Authentication endpoints
β”‚   β”‚   β”‚   └── wallets.py      # Wallet monitoring endpoints
β”‚   β”‚   └── api.py              # API router configuration
β”‚   β”œβ”€β”€ core/                   # Core application components
β”‚   β”‚   β”œβ”€β”€ config.py           # Configuration management
β”‚   β”‚   β”œβ”€β”€ database.py         # Database connection setup
β”‚   β”‚   └── security.py         # Security utilities
β”‚   β”œβ”€β”€ models/                 # SQLAlchemy database models
β”‚   β”‚   β”œβ”€β”€ parent_wallet.py    # Parent wallet model
β”‚   β”‚   └── child_wallet.py     # Child wallet model
β”‚   β”œβ”€β”€ schemas/                # Pydantic request/response schemas
β”‚   β”‚   β”œβ”€β”€ wallet.py           # Wallet schemas
β”‚   β”‚   └── transaction.py      # Transaction schemas
β”‚   β”œβ”€β”€ services/               # Business logic services
β”‚   β”‚   β”œβ”€β”€ helius_service.py   # Helius API integration
β”‚   β”‚   └── wallet_service.py   # Wallet detection logic
β”‚   └── main.py                 # FastAPI application entry point
β”œβ”€β”€ requirements.txt            # Python dependencies
β”œβ”€β”€ test_api.py                # API testing script
└── README.md                  # This documentation

πŸš€ Getting Started

Prerequisites

  • Python 3.8+: Ensure you have Python 3.8 or higher installed
  • Helius API Key: Sign up at Helius for API access
  • Git: For cloning the repository

Installation

  1. Clone the repository:

    git clone <repository-url>
    cd Solana-Cluster-Monitoring-Backend
  2. Create a virtual environment (recommended):

    # Windows
    python -m venv venv
    venv\Scripts\activate
    
    # macOS/Linux
    python3 -m venv venv
    source venv/bin/activate
  3. Install dependencies:

    pip install -r requirements.txt
  4. Configure environment (optional): Create a .env file in the root directory:

    HELIUS_API_KEY=your_helius_api_key_here
    DATABASE_URL=sqlite:///./app.db
    ENVIRONMENT=development
    DEBUG=True
    MIN_CHILD_WALLETS=5
    DETECTION_WINDOW_MINUTES=5

Running the Application

  1. Start the development server:

    uvicorn app.main:app --reload
  2. Access the application:

The server will start on http://localhost:8000 with auto-reload enabled for development.

πŸ“š API Documentation

Core Endpoints

Health Check

GET /health

Returns the health status of the API.

Response:

{
  "status": "healthy"
}

Raw Transactions

GET /api/v1/wallets/raw-transactions/{wallet_address}

Fetches raw transaction data for a specific Solana wallet address.

Parameters:

  • wallet_address (path): Solana wallet address

Response:

{
  "transactions": [...] // Array of transaction objects
}

Cluster Detection

GET /api/v1/wallets/cluster-detection/{wallet_address}

Detects wallet clusters where a parent wallet funds multiple child wallets.

Parameters:

  • wallet_address (path): Parent wallet address to analyze
  • min_children (query, optional): Minimum children required for cluster (3-20, default: 5)
  • funding_window (query, optional): Funding window in minutes (1-30, default: 5)

Response:

{
  "parent_wallet": "string",
  "cluster_type": "BUY_CLUSTER|SELL_CLUSTER",
  "child_wallets": [...],
  "total_sol_funded": 0.0,
  "coordination_score": 0.0
}

Interactive API Documentation

Visit http://localhost:8000/docs when the server is running to explore the full interactive API documentation with:

  • Complete endpoint specifications
  • Request/response examples
  • Try-it-out functionality
  • Schema definitions

πŸ§ͺ Testing

Running API Tests

The project includes a comprehensive test script to verify all endpoints:

python test_api.py

This script tests:

  • Health endpoint connectivity
  • Raw transaction fetching
  • Cluster detection functionality
  • API documentation accessibility

Manual Testing

You can also test individual endpoints using curl or any HTTP client:

# Health check
curl http://localhost:8000/health

# Raw transactions (replace with actual wallet address)
curl "http://localhost:8000/api/v1/wallets/raw-transactions/YourWalletAddressHere"

# Cluster detection with custom parameters
curl "http://localhost:8000/api/v1/wallets/cluster-detection/YourWalletAddressHere?min_children=3&funding_window=10"

βš™οΈ Configuration

Environment Variables

Variable Description Default
HELIUS_API_KEY Your Helius API key 29dce386-f700-47b7-a61d-6562b1145a45
HELIUS_BASE_URL Helius API base URL https://api.helius.xyz/v0
DATABASE_URL Database connection string sqlite:///./app.db
MIN_CHILD_WALLETS Minimum children for detection 5
DETECTION_WINDOW_MINUTES Detection time window 5
ENVIRONMENT Application environment development
DEBUG Enable debug mode True

Cluster Detection Parameters

  • Min Child Wallets: Configurable minimum number of child wallets (3-20) required to classify as a cluster
  • Funding Window: Time window in minutes (1-30) within which funding must occur to be considered coordinated
  • Detection Types:
    • BUY_CLUSTER: Parent funds children with SOL for token purchases
    • SELL_CLUSTER: Parent distributes tokens to children for coordinated selling

πŸ“Š Features

Current Implementation

  • βœ… FastAPI application with async support
  • βœ… Helius API integration for transaction data
  • βœ… Wallet cluster detection algorithms
  • βœ… SQLAlchemy database models
  • βœ… Pydantic schemas for data validation
  • βœ… Comprehensive API documentation
  • βœ… Health monitoring endpoints
  • βœ… Configurable detection parameters

Dashboard Analytics Support

The backend is designed to support frontend dashboards with:

  • Parent Wallet Tracking: Monitor funding patterns and distribution strategies
  • Token Activity Analysis: Track buy/sell activities across child wallets
  • DEX Usage Patterns: Identify preferred exchanges (Raydium, Meteora, Phoenix)
  • Timing Analysis: Calculate buy intervals and completion estimates
  • Health Scoring: Algorithmic scoring of cluster strength and coordination

πŸ› οΈ Development

Development Setup

  1. Enable development mode:

    export ENVIRONMENT=development
    export DEBUG=True
  2. Run with auto-reload:

    uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
  3. View logs: The application includes structured logging for debugging and monitoring.

Code Structure

  • Services: Business logic separated into service classes
  • Models: SQLAlchemy ORM models for data persistence
  • Schemas: Pydantic models for request/response validation
  • APIs: RESTful endpoints organized by functionality
  • Core: Configuration, database, and security utilities

Adding New Features

  1. Database Models: Add new models in app/models/
  2. API Endpoints: Create endpoints in app/api/v1/endpoints/
  3. Business Logic: Implement services in app/services/
  4. Schemas: Define request/response schemas in app/schemas/

πŸ”’ Security

  • API Key Management: Helius API keys configured via environment variables
  • Input Validation: Pydantic schemas validate all API inputs
  • Error Handling: Comprehensive error handling with appropriate HTTP status codes
  • Rate Limiting: Consider implementing rate limiting for production use

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“ž Support

For questions and support:

  • Check the API Documentation when running locally
  • Review the test examples in test_api.py
  • Examine the configuration options in app/core/config.py

Built with FastAPI, SQLAlchemy, and Helius API for comprehensive Solana blockchain monitoring.

About

Production-grade FastAPI backend for real-time Solana wallet cluster detection, coordinated trading analysis, and on-chain behavioral monitoring using Helius transaction indexing.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors