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:
- Detect a victim trade (usually a large buy/sell) in the mempool.
- Front-run it (buy before the victim).
- Let the victim push the price up/down.
- 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
- π Watch mempool via Jito.
- π¦ Detect a high-impact swap.
- π Simulate profit from sandwiching.
- π§ Craft a bundle: [front-run, victim, back-run].
- π Submit via Jito with high priority.
- π Monitor performance, adjust for slippage, latency.