How chainbuff/open-sol-bot works
Main Components
• Telegram Bot Module (app/tg-bot):
– Handles user interactions via Telegram.
– Contains multiple conversation submodules (e.g., copytrade, wallet, home, monitor, swap, setting).
– Includes keyboards, middlewares, and notification logic.
• Trading Engine (app/trading):
– Implements trading functionality including “跟单” (copytrade), trade execution, settlements, and transaction building.
– Contains builders for different protocols (e.g., Raydium, Jupiter, Pump modules).
• Cache Preloader Service (app/cache-preloader):
– Responsible for preloading and caching important blockchain parameters like blockhashes, minimum balance (rent), and Raydium pool information.
• Wallet Tracker (app/wallet-tracker):
– Monitors wallet activities.
– Implements functionalities like transaction parsing, benchmarking, and subscription-based updates.
• Libraries (libs/):
– Contains several shared utilities and core libraries:
▫ Cache library (libs/cache) to encapsulate caching logic.
▫ Common functions and models (libs/common) used across modules.
▫ Database access (libs/db) with MySQL and Redis connectors.
▫ Services (libs/services) for higher-level business logic.
▫ gRPC interface (libs/yellowstone_grpc) for integration with external blockchain data sources (e.g., geyser protocol).
• External Dependencies and Infrastructure:
– MySQL and Redis, as defined in the configuration.
– RPC endpoints and API integrations (Helius, Shyft) for blockchain data.
– Docker infrastructure (Dockerfiles, docker-compose.yaml) to containerize components.
– Optional gRPC channels via the Yellowstone GRPC library.
Relationships and Data Flow
• The Telegram Bot module receives user commands (via conversations) and, through its various middlewares and services, routes these commands to the underlying Trading Engine.
• The Trading Engine communicates with:
– External APIs (Helius, Shyft) to get blockchain data.
– The Cache Preloader, which supplies fresh cached blockchain parameters needed for validation and rapid order execution.
• The Wallet Tracker independently monitors wallets (using websockets and/or gRPC subscriptions) and feeds data back to either the Telegram Bot (for live notifications) or to logging/alert systems.
• Libraries provide cross-cutting utilities:
– The DB library abstracts MySQL and Redis interactions.
– The Common library contains shared models and helper functions used by all modules.
– The gRPC library encapsulates connections to geyser and Solana storage endpoints.
• Each service is containerized (as indicated by Dockerfiles and docker-compose.yaml) and communicates through well-defined APIs or messaging channels.
Important Architectural Patterns and Design Principles
• Separation of Concerns: Different functionalities – Telegram interaction, trading logic, caching, and wallet tracking – are separated into distinct modules.
• Microservices/Containerization: Each component (tg-bot, trading, cache preloader, wallet tracker) can run as its own Docker container, easing deployment and scaling.
• Modular Libraries: The use of shared libraries promotes code reusability and clean separation between business logic and infrastructure concerns.
• Event-Driven Data Flow: Components (especially the wallet tracker and trading engine) likely use event-driven patterns for reacting to blockchain events.
Relevant Technologies, Frameworks, and Libraries
• Python 3.10+ (primary language)
• Docker & Docker Compose for containerization.
• MySQL and Redis as external data stores.
• gRPC (via the Yellowstone GRPC library)
• External APIs such as Helius and Shyft (for RPC endpoints)
• Telegram Bot API for interfacing with users (including conversation management, keyboards, and middlewares).