How to create solana sandwich mev bot? - cryptoking-max/solana-sandwich-bot GitHub Wiki

Creating a Solana sandwich bot is complex and potentially controversial due to its association with MEV (Maximal Extractable Value) strategies. A sandwich bot attempts to:

  1. Detect a victim trade (usually a large buy/sell) in the mempool.
  2. Front-run it (buy before the victim).
  3. Let the victim push the price up/down.
  4. Back-run it (sell after the victim) to profit from the price movement.

⚠️ Disclaimer:

Sandwich attacks are considered exploitative and can harm normal users. They are often discouraged or prohibited on ethical platforms, and may be blocked by anti-MEV measures.

That said, here’s how you’d build one for educational purposes only, using Jito and Solana tools.


πŸ”§ Core Components

1. Mempool Access β€” Jito Bundle Subscription

You need to access the Solana mempool before transactions are confirmed.

  • Use [Jito Labs](https://www.jito.network/) to subscribe to mempool bundles.

  • They allow you to:

    • Observe pending transactions.
    • Simulate bundle performance.
    • Submit your own bundles.

Example (Rust or Python via gRPC):

# pseudo-code: listen to Jito bundle feed
from jito_client import MempoolClient

client = MempoolClient()
for bundle in client.subscribe_bundles():
    for tx in bundle.transactions:
        # Check for large token buys/sells

2. Transaction Decoding & Analysis

Identify large swap instructions in pending transactions.

Common DEXes:

  • Jupiter Aggregator (most common)
  • Raydium
  • Orca

Use Solana transaction parsers to decode instructions:

  • Detect swaps via program IDs.
  • Estimate their price impact.
  • Simulate what front-running them would do.

3. Simulate Front/Back-Run Profitability

Use Solana RPC or a simulation tool (e.g., Jito’s API or [Helius](https://www.helius.xyz/)) to:

  • Estimate your front-run buy
  • Let victim move price
  • Simulate your back-run sell

Profit = (back-run price - front-run price) Γ— amount


4. Bundle Submission to Jito

Once profitable:

  • Submit your own transaction bundle:

    • Your front-run tx
    • Victim tx
    • Your back-run tx
# pseudo-code
bundle = [
    front_run_tx,
    victim_tx,
    back_run_tx,
]
jito.submit_bundle(bundle)

🧠 Strategy Considerations

  • Speed: Use a private RPC and co-located validator for low latency.
  • Gas fees: Solana fees are low, but you compete with other MEV bots.
  • Slippage protection: Victims might use slippage guards.
  • Anti-MEV: Some platforms randomize orders or use fail-safes.
  • Token liquidity: Only attempt on pools with enough depth.

βš™οΈ Tools & Libraries

  • 🧠 Jito Labs SDK: https://docs.jito.network/
  • πŸ”„ Solana Transaction Parsers: Use @solana/web3.js or Python RPC
  • πŸ“ˆ Jupiter Swap Simulation: https://quote-api.jup.ag/
  • πŸ’Ύ Private Solana RPC (e.g., Helius, Triton, Syndica)
  • πŸ§ͺ Simulations: Jito Simulator or Helius simulateTransaction

πŸ‘Ž Risks

  • Transaction failure (race condition, invalid slot)
  • Loss of funds (slippage works against you)
  • Jito bundles rejected
  • Ban from RPC endpoints
  • Moral/ethical concerns

βœ… Summary: High-Level Flow

  1. πŸ”Ž Watch mempool via Jito.
  2. πŸ“¦ Detect a high-impact swap.
  3. πŸ“Š Simulate profit from sandwiching.
  4. 🧠 Craft a bundle: [front-run, victim, back-run].
  5. πŸš€ Submit via Jito with high priority.
  6. πŸ“‰ Monitor performance, adjust for slippage, latency.