defi-mev-battletest
Expert knowledge for DeFi/MEV bot development including critical pitfalls, backtesting realities, AMM mechanics, MEV extraction strategies, and production failure modes
What this skill does
# DeFi/MEV Battle-Tested Expert Skill
**MANDATORY CONSULTATION**: This skill MUST be consulted for ANY DeFi bot development, MEV strategy implementation, or automated trading system. Real-world failures and lessons learned here prevent catastrophic losses.
## Trigger Keywords
- arbitrage, MEV, searcher, bot, automated trading
- backtest, simulation, paper trading
- flash loan, sandwich, frontrun
- slippage, price impact, execution
- reorg, race condition, mempool
- market making, liquidity provision
---
## 1. CRITICAL PITFALL #1: "Arbitrage is Risk-Free" MYTH
**Reality**: Theoretical 0% risk, practical tail risk = DEATH
### Hidden Risks in "Risk-Free" Arbitrage:
```
❌ Execution Risk
- Transaction reverts after gas spent
- Partial fills leave you with unwanted inventory
- Contract bugs in target protocols
❌ Reorg Risk (CRITICAL)
- Your profitable tx can be uncle'd
- 1-2 block reorgs happen DAILY on Ethereum
- Your "profit" disappears, gas cost remains
❌ Gas Spike Risk
- Base fee can 10x mid-execution
- Priority fee auctions drain profits
- Failed tx still costs full gas
❌ Latency Risk
- Block already mined before your tx lands
- State changed between simulation and execution
- Other searchers front-ran you
```
### Real Numbers:
```typescript
// What you see in backtest:
const theoreticalProfit = 0.05; // 5% clean profit
// What actually happens:
const executionCosts = {
gasOnSuccess: 0.01, // 1% gas
failureRate: 0.30, // 30% of txs fail
gasOnFailure: 0.01, // Still pay gas
reorgRate: 0.02, // 2% get reorg'd
slippageSlip: 0.005, // 0.5% unexpected slippage
};
// Real expected value:
// 0.70 * (0.05 - 0.01) - 0.30 * 0.01 - 0.02 * 0.04 = 0.0238
// 47% of theoretical profit GONE before MEV competition
```
---
## 2. CRITICAL PITFALL #2: Backtest Overconfidence
**80% of bots that fail in production looked great in backtests**
### Why Backtests Lie:
```
❌ Historical State ≠ Future Block State
- You're simulating against KNOWN state
- Live: state changes between blocks
- Mempool competition invisible in historical data
❌ Gas & Latency are Ex-Post Unknowable
- You backtest with actual gas prices
- Live: you must PREDICT gas prices
- Priority fee auctions are adversarial games
❌ Survivorship Bias
- You only see successful historical arbitrages
- Failed attempts not recorded on-chain
- "Found" opportunities may have been contested
❌ Market Impact Ignored
- Your own txs change the market
- Liquidity dries up when you need it most
- Large trades move price against you
```
### Correct Approach:
```typescript
// BAD: Backtest with perfect information
async function badBacktest(historicalData) {
for (const block of historicalData) {
const profit = simulateWithPerfectState(block);
totalProfit += profit;
}
return totalProfit; // LIES
}
// GOOD: Block simulation with realistic conditions
async function realisticTest(pendingBlock) {
// 1. Simulate against PENDING state (not confirmed)
// 2. Add realistic latency (50-200ms)
// 3. Assume 30% failure rate
// 4. Assume 20% of "opportunities" are bait
// 5. Add gas price uncertainty (±30%)
const simResult = await simulateOnPendingState(pendingBlock);
const adjustedProfit = simResult.profit
* 0.70 // success rate
* 0.80 // not bait
- estimatedGas * 1.30; // gas uncertainty
return adjustedProfit;
}
```
---
## 3. CRITICAL PITFALL #3: AMM ≠ Order Book
**Wrong slippage model = silent bleeding**
### Uniswap V3 Specific Gotchas:
```typescript
// V3 Tick Liquidity is NON-UNIFORM
// Liquidity can be ZERO between ticks!
interface V3Reality {
// What you expect:
linearSlippage: false,
// What actually happens:
tickCrossing: 'each tick = separate fee payment',
liquidityGaps: 'can skip ticks with 0 liquidity',
concentratedLiquidity: 'most liquidity in narrow range',
// Price impact is STEP FUNCTION not curve:
// Small trade: 0.01% impact
// Medium trade: 0.5% impact (crossed tick)
// Large trade: 5% impact (crossed multiple ticks)
}
// Fee Tier Selection MATTERS ENORMOUSLY
const feeTiers = {
'0.01%': 'stablecoins only, ultra-tight spread',
'0.05%': 'correlated pairs (ETH/stETH)',
'0.30%': 'most pairs, default choice',
'1.00%': 'exotic pairs, low liquidity',
};
// WRONG: Using 0.3% pool for stablecoin swap
// You're paying 6x more fees than necessary
// WRONG: Using 0.05% pool for volatile pair
// Pool doesn't exist or has no liquidity
```
### Curve-Specific Gotchas:
```typescript
// Curve StableSwap has DIFFERENT math
// A-factor determines curve shape
interface CurveReality {
amplificationFactor: number, // A = 100 typical
// Low A: more like constant-product (Uniswap V2)
// High A: more like constant-sum (1:1 swap)
// Price impact is MUCH LOWER for stables
// But MUCH HIGHER at depegs
depegRisk: 'curve pools can trap you during depegs',
}
// USDC depeg example (March 2023):
// Expected: swap USDC→DAI at 0.99
// Reality: pool drained, 10%+ slippage
```
---
## 4. CRITICAL PITFALL #4: MEV Underestimation
**Public mempool = free alpha donation**
### The MEV Food Chain:
```
Your transaction → Public Mempool → Searchers see it
↓
Sandwich Attack (you're the meat)
↓
Your "profit" becomes their profit
```
### Private Orderflow is TABLE STAKES:
```typescript
// If you're not using private submission, you have NO edge
const submissionMethods = {
// PUBLIC (you will be extracted)
publicRPC: 'eth_sendRawTransaction', // NEVER for arb
// PRIVATE (minimum viable)
flashbotsProtect: 'protect.flashbots.net', // Free, basic
mevBlocker: 'rpc.mevblocker.io', // Free, good
// COMPETITIVE (for serious searchers)
flashbotsBundle: 'relay.flashbots.net', // Bundle submission
mevShare: 'share MEV with users', // Required for some flow
// BUILDER DIRECT (advanced)
builderAPI: 'direct to block builders', // Lowest latency
};
```
### MEV-Share Reality:
```typescript
// New paradigm: users get kickbacks
// Searchers must share profits
interface MEVShareEconomics {
userShare: '50-90% of MEV',
searcherShare: '10-50% of MEV',
// This means:
// Your arbitrage opportunity is SMALLER
// Competition is HIGHER
// Only ultra-efficient searchers survive
}
```
---
## 5. MUST-READ RESOURCES (10 articles = 1 year experience)
### Tier 1: Foundational (READ FIRST)
```
📚 Paradigm Research
- "Liquidity Book" - AMM math from first principles
- "MEV... Wat Do?" - MEV taxonomy
- Every post on research.paradigm.xyz
📚 Flashbots Docs
- "MEV-Share" - orderflow auction design
- "Searching Post-Merge" - new MEV landscape
- docs.flashbots.net (entire site)
```
### Tier 2: Practical Failures (LEARN FROM OTHERS' LOSSES)
```
Search Twitter/X for:
- "post-mortem"
- "we lost money because"
- "unexpected behavior"
- "exploit" + protocol name
Real lessons come from lost money.
```
### Tier 3: Code Study (Skip star count, check content)
```
GitHub search for:
- MEV searcher bots (with reorg handling)
- Uniswap V3 math libraries
- Bundle simulation code
README keywords that indicate quality:
✅ "reorg handling"
✅ "race condition"
✅ "bundle simulation"
✅ "private mempool"
❌ "simple arbitrage"
❌ "guaranteed profit"
❌ "no risk"
```
### Tier 4: Follow These Accounts
```
@bertcmiller - MEV searcher, practical insights
@hasufl - DeFi economics, mechanism design
@samczsun - Security, exploits, real failures
@0xfoobar - Technical MEV, searcher perspective
@barnabe_monnot - PBS, MEV-Boost internals
```
---
## 6. ARCHITECTURE PRINCIPLES (Non-Negotiable)
### Separation of Concerns:
```typescript
// CRITICAL: Execution engine SEPARATE from strategy
class Architecture {
// Strategy Layer (what to do)
strategyEngine: {
findOpportunities(): Opportunity[],
evaluateRisk(): RiskAssessment,
calculateSize(): PositionSize,
};
// Execution Layer (how to do it)
executionEngine: {
Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.