Install
$ agentstack add skill-brainbytes-dev-everything-claude-trading-mev-strategies ✓ scanned · ✓ verified, works with Claude Code, Cursor, and more.
Security review
✓ PassedNo issues found. Passed automated security review. · v0.1.0 How review works →
- ✓ Prompt-injection patterns
- ✓ Secret / credential exfiltration
- ✓ Dangerous shell & filesystem operations
- ✓ Untrusted network calls
- ✓ Known-malicious package signatures
What it can access
- ✓ Network access No
- ✓ Filesystem access No
- ✓ Shell / process execution No
- ✓ Environment & secrets No
- ✓ Dynamic code execution No
From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.
Verified badge
Passed review? Show it. Paste this badge into your README, it links to the public security report.
Reliability & compatibility
Declared compatibility
Compatibility is declared by the source manifest. End-to-end runtime verification is coming, see below.
We're building live execution health for every listing: tool-call success rate, median latency, uptime, and last-checked timestamps, measured, not self-reported. It isn't live yet, so we don't show numbers we can't stand behind.
How agent discovery & health will work →About
MEV Strategies
When to Activate
- Analyzing Maximal Extractable Value (MEV) opportunities or risks in DeFi transactions
- Understanding frontrunning, sandwich attacks, and DEX arbitrage mechanics
- Evaluating MEV mitigation strategies (Flashbots, MEV-boost, private mempools)
- Designing transactions to minimize MEV extraction or to participate in MEV capture
- Assessing proposer-builder separation (PBS) and its implications for protocol design
Core Concepts
MEV Taxonomy
Definition: MEV is the maximum value that can be extracted from block production beyond the standard block reward and gas fees, by including, excluding, or reordering transactions within a block.
Primary MEV Types:
- DEX Arbitrage — exploiting price differences between DEXs or between DEX pools
- Atomic: execute in a single transaction using flash loans
- Cross-DEX: Uniswap pool price differs from SushiSwap
- Cross-pool: triangular arbitrage across 3+ pools (ETH->USDC->DAI->ETH)
- Estimated 60-70% of all MEV by volume
- Sandwich Attacks — frontrunning and backrunning a victim's swap
- Attacker sees pending swap in mempool
- Frontrun: buy the token before victim, pushing price up
- Victim's swap executes at worse price
- Backrun: sell the token after victim at higher price
- Profit = price impact created minus gas costs
- Victim loses: their effective slippage exceeds expected slippage
- Liquidation MEV — racing to liquidate undercollateralized positions
- Monitor health factors on Aave, Compound, MakerDAO
- First to call liquidate() captures the liquidation bonus (5-10%)
- Gas priority auctions among competing liquidation bots
- Flash loans enable liquidation without upfront capital
- NFT MEV — sniping underpriced listings, frontrunning mints
- Less systematic, more event-driven
- Mint sniping during popular launches
- Long-tail MEV — protocol-specific extraction (governance, oracle manipulation)
Sandwich Attack Mechanics (Detailed)
Mempool state: Victim wants to swap 10 ETH -> USDC on Uniswap
Pool state: 1000 ETH / 2,000,000 USDC (price = 2000 USDC/ETH)
Victim slippage tolerance: 1%
Attacker frontrun:
- Buy with 50 ETH -> receives ~95,238 USDC
- New pool: 1050 ETH / 1,904,762 USDC (price = 1814 USDC/ETH)
Victim swap executes:
- 10 ETH -> receives ~17,878 USDC (vs ~19,802 without sandwich)
- Victim loses ~$1,924
Attacker backrun:
- Sell 95,238 USDC -> receives ~51.8 ETH
- Profit: ~1.8 ETH minus gas costs (~0.1 ETH)
- Net MEV extracted: ~1.7 ETH ($3,400)
Flashbots and MEV Infrastructure
Flashbots Ecosystem:
- Flashbots Protect — private transaction submission, bypasses public mempool
- Flashbots Auction (MEV-Auction) — searchers bid for bundle inclusion
- MEV-boost — out-of-protocol PBS implementation for Ethereum
- MEV-Share — redistributes MEV back to users who originated the transactions
MEV-Boost Architecture:
Transaction flow:
User -> Mempool -> Searchers (find MEV) -> Builders (construct blocks)
-> Relays (validate blocks) -> Proposers (select highest-bid block)
Key actors:
- Searchers: find MEV opportunities, create bundles
- Builders: aggregate bundles into full blocks, bid for inclusion
- Relays: trusted intermediaries that validate builder blocks
- Proposers: validators who select the winning block
Proposer-Builder Separation (PBS):
- Separates block building (selecting/ordering transactions) from block proposing (validating)
- Prevents validators from directly extracting MEV
- Enables competitive block building market
- Enshrined PBS: protocol-level implementation (in Ethereum roadmap)
- Current MEV-boost is out-of-protocol, trusted relay model
MEV Mitigation Strategies
For Users:
- Use Flashbots Protect or MEV-blocker for private transaction submission
- Set tight slippage tolerance (but not so tight trades fail)
- Use limit orders instead of market swaps where possible
- Break large trades into smaller chunks via TWAP
- Use DEX aggregators that route through private pools (CoW Swap, 1inch Fusion)
For Protocols:
- Batch auctions — CoW Protocol: all trades in a batch settle at uniform clearing price
- Encrypted mempools — threshold encryption, commit-reveal schemes
- Fair ordering — Chainlink FSS (Fair Sequencing Services)
- MEV redistribution — MEV-Share, protocol-owned MEV capture
- Time-weighted average pricing — reduce single-block manipulation
- Backrunning-only auctions — allow beneficial arbitrage, block harmful frontrunning
Methodology
MEV Opportunity Assessment
- Identify the MEV type — arbitrage, liquidation, sandwich, or protocol-specific
- Estimate gross revenue — price discrepancy trade size, liquidation bonus position size
- Calculate costs — gas cost, priority fee/bid, flash loan fee, capital cost
- Assess competition — how many other searchers target this opportunity? Profit margins compress with competition
- Evaluate risk — failed transactions cost gas, smart contract risk, inventory risk for non-atomic strategies
- Determine infrastructure — latency requirements, builder relationships, private mempool access
Searcher Profitability Analysis
Expected profit per opportunity:
E[profit] = P(win_auction) * (gross_MEV - gas - bid) - P(lose_auction) * wasted_gas
Where:
- P(win_auction) decreases as more searchers compete
- Bid converges toward gross_MEV in competitive markets
- Wasted gas = cost of failed/reverted transactions
- Mature MEV types (DEX arb) have thin margins; novel types have wide margins
MEV Risk Assessment for DeFi Users
1. Estimate trade size relative to pool liquidity
2. Calculate expected price impact without MEV
3. Add MEV extraction estimate (typically 20-80% of available sandwich profit)
4. Compare total execution cost vs. using private transaction channels
5. For large trades: evaluate TWAP, RFQ, or batch auction alternatives
Examples
Example 1: Atomic DEX Arbitrage
Opportunity:
- Uniswap ETH/USDC pool: ETH price = $2,010
- SushiSwap ETH/USDC pool: ETH price = $2,000
- Price discrepancy: $10 per ETH
Execution:
1. Flash loan 100 ETH from Aave
2. Sell 100 ETH on Uniswap at $2,010 = $201,000
3. Buy ~100.5 ETH on SushiSwap for $201,000
4. Repay 100 ETH flash loan + 0.05 ETH fee
5. Profit: 0.45 ETH (~$900) minus gas and builder tip
Bundle submission:
- Submit via Flashbots to avoid mempool exposure
- Bid 60% of profit to builder ($540) to ensure inclusion
- Net profit: ~$360 per opportunity
Example 2: Liquidation Bot Strategy
Monitoring:
- Track 10,000+ Aave positions continuously
- Pre-compute liquidation prices for each position
- Subscribe to pending block headers for price updates
Execution when position becomes liquidatable:
- Health factor drops below 1.0
- Flash loan the debt asset
- Call liquidate() repaying debt, receiving collateral + bonus
- Swap collateral back to debt asset
- Repay flash loan
Economics:
- Average liquidation bonus: 5%
- Average liquidation size: $50,000
- Gross profit: $2,500
- Gas + builder tip: $500-1,000
- Net profit: $1,500-2,000 per liquidation
- Competition: high, latency-sensitive (sub-block timing)
Example 3: MEV Protection Comparison
Trade: Swap 50 ETH -> USDC
Route 1 — Public mempool (Uniswap directly):
- Expected output: 99,500 USDC
- Sandwich extraction: -$800 (estimated)
- Actual output: ~98,700 USDC
Route 2 — Flashbots Protect:
- Expected output: 99,500 USDC
- No sandwich possible (private submission)
- Actual output: ~99,400 USDC (normal slippage only)
Route 3 — CoW Swap (batch auction):
- Expected output: 99,600 USDC (surplus from batch matching)
- No MEV extraction + potential price improvement
- Actual output: ~99,550 USDC
Recommendation: For trades >$10K, always use MEV protection.
CoW Swap provides best execution for large stablecoin swaps.
Quality Gate
Before engaging with MEV strategies or assessing MEV risk, verify:
- [ ] MEV type is correctly identified — arbitrage is constructive (improves pricing), sandwich is extractive
- [ ] All costs are accounted for — gas, priority fees, builder bids, flash loan fees, failed transaction costs
- [ ] Competition level is assessed — mature MEV types have razor-thin margins, often negative EV for new entrants
- [ ] Smart contract interactions are audited — flash loan callbacks and complex multi-hop swaps carry exploit risk
- [ ] Regulatory considerations noted — some MEV activities may face legal scrutiny (particularly sandwich attacks)
- [ ] Infrastructure requirements are realistic — sub-second latency, dedicated builder relationships, custom node setup
- [ ] MEV protection recommendations for users match their trade size and frequency
- [ ] PBS architecture understanding is current — the MEV supply chain evolves rapidly
- [ ] Cross-chain MEV is considered — bridges and L2 sequencers introduce new MEV dynamics
Source & license
This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.
- Author: brainbytes-dev
- Source: brainbytes-dev/everything-claude-trading
- License: MIT
Install and usage instructions live in the source repository linked above.
Reviews
No reviews yet, be the first.
Write a review
Versions
- v0.1.0 Imported from the upstream source.