MEV保护Skill mev

这个skill用于保护区块链交易免受MEV(最大可提取价值)攻击,如三明治攻击和前置运行。它提供API和工具来启用、配置和执行保护,支持以太坊和Solana等链,使用Flashbots、MEV Blocker和Jito等提供商。关键特性包括风险模拟、交易分析和最佳实践指导。关键词:MEV保护, 区块链, DeFi, 交易安全, 三明治攻击, 前置运行, Flashbots, MEV Blocker, Jito, TypeScript API

DeFi 0 次安装 0 次浏览 更新于 3/9/2026

name: mev description: “针对三明治攻击和前置运行的MEV保护” emoji: “🛡️”

MEV保护 - 完整API参考

保护交易免受MEV(最大可提取价值)攻击,包括三明治攻击和前置运行。


聊天命令

保护设置

/mev                                显示当前保护
/mev status                         保护状态
/mev enable                         启用保护
/mev disable                        禁用保护

配置保护

/mev level aggressive               最大保护
/mev level standard                 平衡保护
/mev level minimal                  基本保护
/mev provider flashbots             使用Flashbots
/mev provider mev-blocker           使用MEV Blocker

检查交易

/mev check <tx-hash>                检查交易是否被攻击
/mev simulate <order>               模拟MEV风险

TypeScript API参考

创建MEV保护

import { createMEVProtection } from 'clodds/mev';

const mev = createMEVProtection({
  // 默认等级
  level: 'standard',

  // 提供商
  providers: {
    ethereum: 'flashbots',    // 'flashbots' | 'mev-blocker'
    solana: 'jito',           // 'jito' | 'standard'
  },

  // 设置
  maxPriorityFee: 5,  // gwei
  bundleTimeout: 60,  // 秒
});

执行受保护交易

// EVM交易带保护
const result = await mev.executeProtected({
  chain: 'ethereum',
  type: 'swap',
  tokenIn: 'USDC',
  tokenOut: 'ETH',
  amountIn: 10000,
  minAmountOut: calculateMinOut(10000, 0.5),  // 0.5%滑点
});

console.log(`交易哈希: ${result.txHash}`);
console.log(`受保护: ${result.protected}`);
console.log(`捆绑ID: ${result.bundleId}`);
console.log(`节省: $${result.estimatedSavings}`);

Flashbots (以太坊)

// 通过Flashbots Protect提交
const result = await mev.flashbots({
  to: routerAddress,
  data: swapCalldata,
  value: 0,
  maxFeePerGas: parseGwei('50'),
  maxPriorityFeePerGas: parseGwei('2'),
});

console.log(`已提交到Flashbots`);
console.log(`捆绑哈希: ${result.bundleHash}`);

// 等待包含
const status = await mev.waitForInclusion(result.bundleHash);
console.log(`包含在区块: ${status.blockNumber}`);

MEV Blocker (以太坊)

// 使用CoW协议的MEV Blocker
const result = await mev.mevBlocker({
  to: routerAddress,
  data: swapCalldata,
  value: 0,
});

// MEV Blocker自动:
// - 保护免受三明治攻击
// - 将有利可图的MEV回运给你
// - 返回任何捕获的MEV
console.log(`捕获的MEV: $${result.mevCaptured}`);

Jito (Solana)

// 通过Jito捆绑提交
const result = await mev.jito({
  instructions: swapInstructions,
  tip: 10000,  // lamports给验证者的提示
});

console.log(`捆绑ID: ${result.bundleId}`);
console.log(`状态: ${result.status}`);

检查交易

// 检查过去的交易是否被攻击
const analysis = await mev.analyzeTransaction(txHash);

console.log(`是否被攻击: ${analysis.wasAttacked}`);
if (analysis.wasAttacked) {
  console.log(`攻击类型: ${analysis.attackType}`);
  console.log(`攻击者: ${analysis.attacker}`);
  console.log(`损失: $${analysis.estimatedLoss}`);
  console.log(`前置运行交易: ${analysis.frontrunTx}`);
  console.log(`后置运行交易: ${analysis.backrunTx}`);
}

模拟MEV风险

// 交易前,检查MEV风险
const risk = await mev.simulateRisk({
  chain: 'ethereum',
  type: 'swap',
  tokenIn: 'USDC',
  tokenOut: 'PEPE',
  amountIn: 50000,
});

console.log(`MEV风险: ${risk.level}`);  // 'low' | 'medium' | 'high'
console.log(`估计最大损失: $${risk.maxLoss}`);
console.log(`推荐: ${risk.recommendation}`);

if (risk.level === 'high') {
  console.log('⚠️ 高MEV风险 - 使用保护!');
}

保护等级

// 积极 - 最大保护,较慢
mev.setLevel('aggressive', {
  usePrivateMempool: true,
  bundleOnly: true,
  maxSlippage: 0.1,
  waitForProtection: true,
});

// 标准 - 平衡保护
mev.setLevel('standard', {
  usePrivateMempool: true,
  bundleOnly: false,
  maxSlippage: 0.5,
});

// 最小 - 基本保护
mev.setLevel('minimal', {
  usePrivateMempool: false,
  bundleOnly: false,
  maxSlippage: 1.0,
});

MEV攻击类型

攻击 描述 保护
三明治攻击 前置 + 后置运行你的交易 私密内存池
前置运行 先复制你的交易 私密内存池
后置运行 在你交易后获利 Jito/Flashbots
JIT流动性 操纵池子 滑点限制

保护提供商

提供商 方法
以太坊 Flashbots Protect 私密中继
以太坊 MEV Blocker CoW协议
Solana Jito 捆绑提交
L2s Native 排序器保护

何时使用保护

交易大小 代币 推荐
< $1,000 主要代币 最小
$1,000 - $10,000 主要代币 标准
> $10,000 主要代币 积极
任何大小 迷因代币/低流动性 积极

最佳实践

  1. 始终保护大交易 — MEV机器人监控一切
  2. 使用紧滑点 — 限制攻击盈利能力
  3. 交易前检查 — 模拟MEV风险
  4. 审查交易 — 从过去的攻击中学习
  5. L2s更安全 — 排序器提供自然保护