agentleFS
SperaxSperax/sperax-skills/skills/mev-protection-guide/SKILL.md

mev-protection-guide

Skill8 starsChanged 9 months agoMITView on GitHub

Guide to MEV (Maximal Extractable Value) — sandwich attacks, frontrunning, backrunning, and how to protect transactions. Use when explaining MEV to users, recommending swap protection, or analyzing suspicious transaction patterns.

The file

We split this skill into the rules it gives an agent

6 rules. About 0 are common, 6 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈6

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    After large swaps (price impact creates arb opportunity)

    line 37
  2. Distinctive:

    Place limit orders that execute when conditions are met — no mempool exposure:

    line 85
  3. Distinctive:

    No frontrunning possible (order isn't in mempool)

    line 87
  4. Distinctive:

    Look for this pattern around your transaction:

    line 97
  5. Distinctive:

    If actual slippage significantly exceeds the pool's fee tier, MEV extraction is likely.

    line 111
  6. Distinctive:

    When helping users with swaps:

    line 128

≈ “Common” is an estimate: at least 1 in 5 of the 364,980 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

MEV Protection Guide

MEV (Maximal Extractable Value) is profit that block builders and searchers extract by reordering, including, or excluding transactions. Understanding MEV helps protect your users' trades.

Types of MEV

1. Sandwich Attacks

The most common MEV attack on DEX swaps:

1. Attacker sees your swap in mempool
2. Attacker buys before you (frontrun) → pushes price up
3. Your swap executes at a worse price
4. Attacker sells after you (backrun) → profits from the price difference

Who gets hurt: Anyone swapping on DEXs with high slippage tolerance Typical loss: 0.3–2% of trade value

2. Frontrunning

A searcher copies your profitable transaction and submits it first with higher gas:

  • Arbitrage opportunities
  • NFT mints
  • Liquidation calls

3. Backrunning

Searcher submits a transaction immediately after yours to capture resulting arbitrage:

  • After large swaps (price impact creates arb opportunity)
  • After oracle updates
  • After liquidations

4. Just-In-Time (JIT) Liquidity

A sophisticated attack on V3 pools:

  1. Searcher adds concentrated liquidity just before your swap
  2. Your swap pays fees to the searcher's position
  3. Searcher removes liquidity immediately after

5. Time-Bandit Attacks

Block proposers reorganize past blocks to capture MEV. Rare but possible with proof-of-stake.

Protection Strategies

For Users

StrategyProtection LevelTradeoff
Low slippage (0.5%)MediumMay fail on volatile tokens
Private mempoolHighMay have slight delay
DEX aggregatorMedium–HighBest price routing
Limit ordersHighNo immediate execution

1. Use Low Slippage Tolerance

Set slippage to 0.5% or lower. This limits how much the price can move against you, making sandwich attacks unprofitable.

Caution: Too-low slippage on volatile tokens may cause transactions to fail.

2. Private Transaction Submission

Send transactions through private mempools that hide them from searchers:

ServiceHow It Works
Flashbots ProtectSends tx directly to block builders, skipping public mempool
MEV BlockerPrivate relay by CoW Protocol
MEV Shield (Sperax)Built-in protection in SperaxOS swap tool

3. Use DEX Aggregators

Aggregators like 1inch, 0x, and Paraswap split trades across pools to minimize price impact and MEV exposure.

4. Gasless Limit Orders

Place limit orders that execute when conditions are met — no mempool exposure:

  • 1inch Limit Order Protocol: EIP-712 signed, gasless
  • No frontrunning possible (order isn't in mempool)

5. Batch Auctions

Protocols like CoW Swap use batch auctions where all trades in a batch get the same price, preventing sandwich attacks entirely.

Detecting MEV

Signs of a Sandwich Attack

Look for this pattern around your transaction:

  1. Large buy of the same token (1–2 blocks before yours)
  2. Your swap (at a worse price than expected)
  3. Large sell of the same token (same block or next block)
  4. Same address in steps 1 and 3

Checking Transaction Impact

Expected output (from quote): 1,000 USDC
Actual output (on-chain):       985 USDC
Difference:                      15 USDC (1.5% slippage/MEV)

If actual slippage significantly exceeds the pool's fee tier, MEV extraction is likely.

MEV by Chain

ChainMEV LevelNotes
EthereumHighMost MEV activity, Flashbots dominant
ArbitrumLow–MediumSequencer ordering reduces MEV, but still possible
BaseLow–MediumSimilar to Arbitrum
PolygonMediumLess sophisticated but growing
BSCMediumMEV searchers active
SolanaMedium–HighJito MEV ecosystem

Arbitrum advantage: The centralized sequencer orders transactions FIFO (first-in-first-out), which significantly reduces sandwich attack opportunities. This is one reason Sperax chose Arbitrum for USDs.

Agent Tips

When helping users with swaps:

  1. Always recommend low slippage — 0.5% for standard swaps
  2. Large swaps (>$10K) should use private mempools or DEX aggregators
  3. Check if their wallet supports Flashbots Protect — many do now
  4. On Arbitrum: MEV is lower but not zero — still use reasonable slippage
  5. If a swap fails: suggest slightly higher slippage but explain the tradeoff
  6. Limit orders: for non-urgent trades, gasless limit orders eliminate MEV entirely

Links

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.