DEV Community

TateLyman
TateLyman

Posted on

Building a Production Solana Trading Bot: Architecture Deep Dive

I built a production Solana trading bot that runs on Telegram. Here's the complete architecture — what worked, what didn't, and lessons learned from 4,100 lines of Node.js.

Architecture

bot.js (single file)
├── Telegram Bot API (long-polling)
├── Jupiter V6 (swap routing)
├── Pump.fun (bonding curve trades)
├── Jito (MEV bundles)
├── Helius RPC (Solana access)
├── DexScreener (token discovery)
└── JSON file persistence
Enter fullscreen mode Exit fullscreen mode

Why Single-File?

For bots under 5,000 lines, a single file beats multi-file architecture:

  • Zero import overhead
  • Easy deployment — scp bot.js server:~/ done
  • Easy debugging — one file, one stack trace
  • Ctrl+F finds everything

Telegram: Long-Polling > Webhooks

I use long-polling instead of webhooks:

  • No HTTPS certificate needed
  • Works behind NAT
  • Simpler error handling
  • No webhook URL to manage

Jupiter V6 Integration

Get quote → build swap transaction → sign → send via Jito for MEV protection. The key insight: always use dynamicComputeUnitLimit: true and prioritizationFeeLamports: 'auto' for reliable execution.

Copy Trading via Snapshot-Diff

  1. Snapshot target wallet's token holdings
  2. Wait 60 seconds
  3. New snapshot
  4. Diff: new tokens = buys, missing = sells
  5. Execute matching trades

Simpler and more reliable than WebSocket monitoring.

12 Background Workers

All run in the main event loop on staggered intervals — no separate processes, no job queues. Check limit orders every 3 polls, copy trades every 2, DCA every 3, alerts every 5, premium expiry every 60.

Key Lessons

  1. JSON file persistence is fine for <10K users
  2. Jito is essential — sandwich attacks eat your users without it
  3. Pump.fun direct trading is 10x faster than Jupiter for new tokens
  4. Show exact savings on every upsell
  5. Auto-reconnect with exponential backoff is critical

Get the Source Code

The full 4,100-line source code with all 42 commands and 7 revenue streams: 2 SOL →

Live demo: @solscanitbot

Top comments (0)