← Back to Blog

Beginner's Guide to Writing Your Own Solana Arbitrage Bot

Building your own Solana arbitrage bot is a journey through four stages, from understanding the basics to building production-grade onchain programs.

Stage 1: Understanding Atomic Arbitrage

Atomic arbitrage exploits price differences between DEXes within a single transaction. The key lifecycle:

  1. State Read — Read current pool states across multiple DEXes
  2. Route Discovery — Find profitable arbitrage routes
  3. Transaction Crafting — Build the swap transaction
  4. Submission — Send the transaction to the network
  5. Settlement — Transaction executes atomically (all-or-nothing)

The "atomic" part is crucial: if any step in the arbitrage fails, the entire transaction reverts, so you never lose your principal.

Stage 2: Building with Jupiter V6

A good starting point is using the Jupiter aggregator API:

  • Reference implementation: sol-arb-bot
  • Jupiter provides quoting across all major Solana DEXes
  • Simple to get started but limited in speed and customization

Limitations

  • Depends on Jupiter API uptime and rate limits
  • Offchain quoting introduces latency
  • Limited control over routing logic

Stage 3: Advanced — Roll Your Own Router

For better performance, build your own routing engine:

  • Reference: Autobahn Router
  • Read pool states directly from on-chain accounts
  • Calculate optimal routes yourself
  • Eliminates dependency on third-party APIs

Stage 4: Advanced — Onchain Arbitrage Bots

The most advanced approach: move the entire calculation onchain.

Benefits

  • Zero latency — Calculations happen at execution time
  • No stale data — Pool states are read at the exact moment of swap
  • Minimal infrastructure — No high-spec machines or expensive RPCs needed
  • Battle-tested — This is the approach SolanaMevBot uses

Where SolanaMevBot Fits

SolanaMevBot is a Stage 4 bot — it uses an onchain program for all arbitrage calculations. You don't need to build your own; you can use SolanaMevBot directly. But understanding these stages helps you appreciate the architecture and make better configuration decisions.

Get started with SolanaMevBot →