Professional Solana MEV Protection Infrastructure β Detect and prevent sandwich attacks, frontrunning, and backrunning across Jupiter, Raydium, Orca, and more.
Maximal Extractable Value (MEV) is the profit extracted by validators and bots by reordering, inserting, or censoring transactions in a block. On Solana DEXes like Jupiter and Raydium, the most common MEV attack is the sandwich attack:
- A bot sees your pending swap in the mempool
- It buys the same token before your transaction executes (frontrun), raising the price
- Your trade settles at a worse price
- The bot immediately sells (backrun), pocketing the difference
L2-MEV Shield is an open infrastructure platform that protects DeFi traders from these attacks by-
| Protection Layer | How it works |
|---|---|
| π Private Bundle Routing | Submits your trades via Jito bundles, bypassing the public mempool |
| π‘ Real-time MEV Detection | WebSocket feed monitoring pools on Jupiter/Raydium/Orca for sandwich patterns |
| β On-chain Slippage Guard | Anchor program that atomically validates execution price before settling |
| π οΈ CLI Shield | One-command protection for any Solana swap from your terminal |
| π Dashboard | Real-time analytics of blocked attacks, protected volume, and pool health |
npm install -g l2mevl2mev initThis wizard will ask for:
- Your Solana wallet keypair path (or create a new one)
- Your preferred RPC endpoint
- Default DEX preferences
Config is stored locally in ~/.l2mev/config.json β your keys never leave your machine.
# Shield a Jupiter swap: buy 10 SOL worth of BONK with max 0.5% slippage
l2mev shield --dex jupiter --pair SOL/BONK --amount 10 --slippage 0.5
# Shield a Raydium swap
l2mev shield --dex raydium --pair SOL/USDC --amount 100 --slippage 0.3# Watch top pools for live sandwich/frontrun activity
l2mev monitor --pools raydium:SOL/USDC,jupiter:SOL/BONK
# Alert-only mode (no sound, just logs)
l2mev monitor --quiet# Was your transaction sandwiched?
l2mev analyze --tx <TRANSACTION_SIGNATURE>l2mev config list
l2mev config set rpcUrl https://your-premium-rpc.com| Command | Description |
|---|---|
l2mev init |
Interactive setup wizard |
l2mev shield [options] |
Execute a MEV-protected swap |
l2mev monitor [options] |
Real-time pool surveillance |
l2mev analyze --tx <sig> |
Post-hoc sandwich attack forensics |
l2mev config list |
Show current configuration |
l2mev config set <key> <val> |
Update a config value |
l2mev status |
Check backend connectivity and health |
--dex <name> DEX to trade on (jupiter | raydium | orca) [required]
--pair <A/B> Token pair, e.g. SOL/USDC [required]
--amount <n> Input amount in units of token A [required]
--slippage <pct> Max allowed slippage in % (default: 0.5)
--private Force Jito bundle routing (default: auto)
--dry-run Simulate without broadcasting
--pools <list> Comma-separated dex:pair identifiers
--threshold <pct> Alert when price impact exceeds this % (default: 1.0)
--quiet Suppress UI, output structured JSON only
--output <path> Write alerts to JSON log file
L2-MEV/
βββ frontend/ # Next.js 14 docs site + dashboard
βββ backend/ # Express/TypeScript MEV protection API
βββ cli/ # npm CLI package (l2mev)
βββ programs/ # Anchor/Rust Solana on-chain programs
β βββ mev-shield/ # Slippage guard + commitment instructions
βββ devops/ # Dockerfiles, nginx config
βββ .github/workflows/ # CI (test + lint) and deploy pipelines
βββ docker-compose.yml # Full-stack local development
βββ .env.example # Environment variable template
User Terminal (CLI)
β
βΌ
l2mev shield βββΊ Backend API (/api/shield)
β
βββββββββββ΄βββββββββββ
β β
MEV Detector Transaction Shield
(pool surveillance) (private bundle builder)
β β
βΌ βΌ
Solana RPC Jito Block Engine
(pool state reads) (private submission)
β
βΌ
On-chain mev-shield
Anchor Program
(slippage guard CPI)
- Node.js β₯ 20, npm β₯ 10
- Rust + Anchor CLI
- Docker + Docker Compose (optional, for full-stack mode)
npm install# Frontend (http://localhost:3000)
npm run dev:frontend
# Backend API (http://localhost:4000)
npm run dev:backendcp .env.example .env # fill in your values
npm run docker:upStarts: frontend (3000), backend (4000), nginx reverse proxy (80/443).
The mev-shield Anchor program enforces a price commitment pattern:
- Your client pre-computes the expected execution price
- The program's
commit_priceinstruction records this commitment on-chain - The program's
validate_and_swapinstruction CPIs into the DEX and reverts if the actual execution price deviates beyond the committed slippage bound
This prevents any bot from sandwiching your transaction even if they manage to frontrun it β the transaction simply reverts.
cd programs
anchor build
anchor test
anchor deploy --provider.cluster devnet- All API routes require JWT authentication
- Rate limiting on all public endpoints (100 req/min)
- CORS restricted to configured origins
- Keypairs never transmitted to backend; all signing is done client-side in the CLI
- See SECURITY.md for responsible disclosure policy
Pull requests are welcome. Please read CONTRIBUTING.md first.
git clone https://github.com/mesayanroy/L2-MEV.git
cd L2-MEV
npm install
npm testMIT β see LICENSE.