How chainstacklabs/pump-fun-bot works
Project type and purpose
• Type: An event-driven, CLI-based trading/sniping tool (open-source bot)
• Purpose: Listen to on-chain events (new token mint, migrations), calculate bonding-curve details, and automatically submit buy/sell transactions on Solana.
File structure
• Top-level folders:
– bots/ (YAML configuration templates for each bot instance)
– idl/ (JSON IDL definitions for interacting with Solana programs)
– src/
· bot_runner.py (entry point)
· config_loader.py (loads .env and YAML)
· core/ (RPC client, curve math, wallet abstraction, priority-fee management)
· monitoring/ (listeners & event processors for blockSubscribe, logsSubscribe, Geyser)
· trading/ (buyer, seller, trader orchestration)
· cleanup/ (post-trade account cleanup manager)
· utils/ (logging)
– learning-examples/ (sample scripts and deep-dive code; not part of core runtime)
– tests/ (unit tests for listeners)
Key external dependencies
• Solana RPC endpoints (e.g., Chainstack Solana Trader nodes)
• Geyser gRPC streams (via proto in src/geyser)
• YAML bot definitions (configure strategy, endpoints, keys)
Main components & relationships
A. Configuration Layer
– .env loader & bots/*.yaml → config_loader
– Supplies RPC URLs, private key, RPS settings, strategy parameters
B. Bot Runner (Orchestrator)
– Reads configuration
– Initializes Monitoring, Trading, and Cleanup subsystems
C. Monitoring Subsystem (Event Sources)
– BlockListener (uses blockSubscribe via RPC)
– LogsListener (uses logsSubscribe via RPC)
– GeyserListener (gRPC subscription)
→ Each listener pushes raw events to its corresponding EventProcessor
D. Event Processing Layer
– block_event_processor, logs_event_processor, geyser_event_processor
– Decode events, parse relevant data (e.g., token mint, bonding curve address) via IDL
– Emit standardized “TokenMinted” or “CurveMigrated” events
E. Trading Engine
– Trader class subscribes to processed events
– Computes on-the-fly PDAs (compute_associated_bonding_curve)
– Buyer/Seller modules build and sign transactions via core.client & core.wallet
– PriorityFeeManager adjusts dynamic or fixed fees
– Sends transactions to RPC endpoints
F. Cleanup Manager
– Runs in parallel or post-trade
– Closes or reclaims associated accounts upon failures
G. Logging & Metrics
– utils.logger captures debug/trade logs → trades/trades.log
– (Optional) Extend to Prometheus or external monitoring
Architectural patterns & design principles
• Modular, layered architecture (Config → Source → Process → Act → Cleanup)
• Event-driven pipeline with interchangeable listeners (Strategy pattern)
• Separation of concerns: core Solana math & client abstracted from trading logic
• Plugin-like extensibility: add new listeners or trading strategies via subclassing
Final checklist
– [ ] Clear labels: component names & responsibility