A Python-based tool for detecting and analyzing wide sandwich attacks on Solana DEXs (Raydium, Orca). This project scans on-chain transactions, identifies multi-slot MEV exploitation patterns, calculates profit extraction, and provides verification tools for blockchain forensics.
Wide sandwich attacks are a sophisticated MEV (Maximal Extractable Value) strategy where bots exploit user transactions across multiple slots:
- Frontrun (Slot N): Bot buys token, inflating price
- Victim (Slot N+1 to N+3): User transaction executes at worse price
- Backrun (Slot N+3 to N+8): Bot sells token for profit
Unlike single-slot sandwiches, wide attacks span 2-8 slots, evading basic MEV detectors.
- Multi-Block Scanner: Fetches and parses DEX transactions from 150+ recent Solana blocks
- Wide Sandwich Detection: Identifies bot patterns across multiple slots (not just single-slot)
- Profit Analysis: Calculates extracted value in SOL with profit percentages
- Token Swap Parser: Extracts signer, token pairs, and amounts from transaction metadata
- Verification Tools: Generates Solscan URLs for manual on-chain verification
python-dotenv
solana
asyncio- Clone the repository:
git clone <repository-url>
cd sandwich- Install dependencies:
pip install python-dotenv solana- Set up environment variables:
# Create .env file
echo "HELIUS_API_KEY=your_helius_api_key_here" > .envGet a free Helius API key from: https://www.helius.dev/
sandwich/
├── app.py # Main application entry point
├── utils.py # Block scanning and transaction parsing
├── sandwich.py # Wide sandwich detection algorithm
├── pnl.py # Profit/loss analysis
├── sandwich_simulate.py # Simulation generator
├── verification.py # Solscan verification report
├── multi_slot_simulation.py # Multi-slot strategy demonstration
├── config.py # DEX program IDs and constants
├── simulate.py # Multi-slot simulation (real + hypothetical)
├── simulations.json # Real wide sandwich simulations
├── dex_transactions.json # Raw DEX transaction data
├── sandwich_attacks.json # Detected sandwich patterns
├── profit_analysis.json # Profitability calculations
└── verification_report.json # Manual verification checklist
python3 app.pyOutput:
- Scans 150-200 blocks from current slot
- Detects 50+ DEX transactions (Raydium, Orca)
- Identifies wide sandwich patterns
- Calculates profit for each attack
- Saves results to JSON files
Example Output:
Connected: True
Current slot: 380464130
Total DEX transactions found: 75
Raydium: 43
Orca: 32
Sandwich attacks found: 62
Wide sandwiches (multi-slot): 58
Single-slot sandwiches: 4
Top profitable sandwich:
Bot: 5PZ8NyPC59bZBaC3rHG1RFubHDjyE9MFAwWVAZWF5bs9
Profit: 0.1055 SOL (20.12%)
Slot span: 6 slots
python3 verification.pyOutput:
- Solscan URLs for each transaction (frontrun, victim, backrun)
- Bot wallet explorer links
- Manual verification checklist
- Saves to
verification_report.json
Output:
- Demonstrates bot strategy across slots
- Shows victim slippage calculation
- Calculates MEV profit extraction
- Explains why multi-slot evades detectors
python3 simulate.pyPurpose: Demonstrates bot strategy for wide sandwich attacks across multiple slots (required for assignment simulation component).
Output:
- Analyzes real detected wide sandwiches from your dataset
- Shows 3 detailed examples with multi-slot execution
- Generates hypothetical simulation demonstrating bot strategy
- Calculates extracted value per sandwich
- Saves to
simulations.jsonandhypothetical_simulation.json
Main orchestrator that:
- Connects to Solana RPC
- Scans multiple blocks
- Detects sandwiches
- Runs profit analysis
- Generates reports
Core utilities:
scan_multiple_blocks(): Fetches transactions from consecutive slotsis_dex_transaction(): Identifies Raydium/Orca swapsextract_signer(): Gets wallet address from transaction- Token balance parser for swap amounts
Detection algorithm:
- Groups transactions by token pair and slot
- Identifies bot patterns (same signer in frontrun + backrun)
- Validates opposite token directions (buy → sell)
- Calculates slot span for wide vs single-slot classification
Profit calculation:
- Compares SOL in/out for bot transactions
- Calculates net profit and percentages
- Ranks sandwiches by profitability
- Generates summary statistics
Multi-slot simulation:
- Loads real detected wide sandwiches
- Displays 3 detailed examples with slot-by-slot breakdown
- Generates hypothetical scenario showing bot strategy
- Demonstrates why multi-slot execution evades detection
- Calculates victim loss and bot profit
-
5PZ8NyPC59bZBaC3rHG1RFubHDjyE9MFAwWVAZWF5bs9
- 4 sandwiches, 0.422 SOL profit
-
3RMKoab4zynw3fEvDUmfYfnep7nChuMComjjiHKBTFQg
- 5 sandwiches, 0.0021 SOL profit
-
23EfcUag2j2y5t8GXsT9SXYaGS76FyWVWKWkgkiJAh6a
- 6 sandwiches, 0.0028 SOL profit
- Automated Detection: Script identifies patterns
- Manual Verification: Visit Solscan URLs
- Cross-Reference: Check sandwiched.me database
- Validation Checklist:
- Slot numbers match
- Bot address consistent
- Token pairs align
- Profit calculation verified
Front-run: https://solscan.io/tx/4XjdNTkreMXH2JBhVY2WFncGZea91dP6jPNcpFLus5XQ7Y2bS48PjXd5Q7hyeJgns1yxZisMuUkR2T1rvNmC8pe7
Victim: https://solscan.io/tx/2maPAp3vJrrYdEzTLsrayQZMZ1bAKgtP8XeUPRVTnJPiT74wLpvHYAQUpmBie4ovJwNbyNReadcsUgsTMvgWHtqD
Back-run: https://solscan.io/tx/243aFPMncBctgb8hoCgFNjt76wyCkdf7h9UtTTYbHsv6MGnEsUuevvfQ7wqj3wGAnSsZ3Whdd7WJXGdd19iWWDQb
Bot wallet: https://solscan.io/account/E26WDGhBcUwuYBz5cC6jLvFegFRNW8oG7bbfMhPEBaUi
## Technical Details
### DEX Program IDs
```python
RAYDIUM_PROGRAM_ID = "675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8"
RAYDIUM_CLMM = "CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK"
ORCA_PROGRAM_ID = "whirLbMiicVdio4qvUfM5KAg6Ct8VwpYzGff3uctyCc"
A valid sandwich requires:
- Same bot address in frontrun and backrun
- Different victim address
- Same token pair traded
- Opposite swap directions
- Victim executed between bot transactions
- Slot span > 0 for wide classification
- Requires Helius RPC (rate limits apply)
- Only detects Raydium and Orca DEXs
- Token balance parsing may fail for complex instructions
- Profit calculation assumes SOL as base token
- Recent transactions may not appear on sandwiched.me yet
- Solana MEV dynamics: Jito Labs documentation
- Wide sandwich patterns: @0xGhostLogs Twitter analysis
- sandwiched.me: Real-time MEV tracking
- Helius RPC: Transaction parsing methods
Contributions welcome! Please open an issue or PR for:
- Bug fixes
- New DEX support
- Enhanced detection algorithms
- Documentation improvements
This tool is for educational and research purposes only. MEV extraction may be subject to network rules and ethical considerations. Always verify findings through multiple sources before making claims about specific transactions or actors.
- Instead of downloading full blocks, query transactions by DEX program addresses using
getSignaturesForAddress: returns only meta data + fetch only dex txns, there were some issues with slot ordering that is why i dropped.
