rizalcodes/mev-detector
GitHub: rizalcodes/mev-detector
一款实时监控以太坊主网区块的 MEV 检测器,能识别三明治攻击、套利和抢跑行为并通过 Telegram 推送告警。
Stars: 0 | Forks: 0
# 🎯 MEV 检测器





## 🔍 什么是 MEV?
**最大可提取价值 (MEV)** 是指通过在区块内对交易进行重新排序、插入或审查所可提取的利润。常见的 MEV 策略包括:
- 🥪 **三明治攻击 (Sandwich Attacks)** — 对受害者的 DEX 交易进行抢跑和尾跑,从价格影响中获利
- 💱 **套利** — 在单个区块内利用不同 DEX 之间的价格差异获利
- 🏃 **抢跑** — 以更高的 gas 复制有利可图的交易以优先执行
## ✨ 功能
- 🥪 **三明治攻击检测** — 识别攻击者、受害者交易及使用的 DEX
- 💱 **套利检测** — 追踪已知的 MEV 机器人和高 gas 溢价交易
- 🏃 **抢跑检测** — 检测连续 DEX 交易之间的 gas 溢价模式
- 🤖 **已知 MEV 机器人数据库** — 预加载已知的 MEV 机器人地址
- 📡 **自动区块监控** — 持续扫描每个新的 Ethereum 区块
- 🔔 **Telegram 提醒** — 为检测到的每个 MEV 事件发送实时通知
## 🚀 快速开始
### 1. 安装依赖
```
pip install web3 requests
```
### 2. 设置环境变量
```
# Windows PowerShell
$env:ETHERSCAN_API_KEY = "your_etherscan_api_key"
$env:INFURA_URL = "https://mainnet.infura.io/v3/your_infura_key"
$env:TELEGRAM_TOKEN = "your_telegram_bot_token"
$env:TELEGRAM_CHAT_ID = "your_chat_id"
```
```
# Linux / Mac
export ETHERSCAN_API_KEY="your_etherscan_api_key"
export INFURA_URL="https://mainnet.infura.io/v3/your_infura_key"
export TELEGRAM_TOKEN="your_telegram_bot_token"
export TELEGRAM_CHAT_ID="your_chat_id"
```
### 3. 作为 Telegram 机器人运行
```
python mev_detector.py
```
### 4. 快速扫描(单次)
```
python mev_detector.py scan 25140000
```
## 🤖 Telegram 命令
| 命令 | 描述 |
|---------|-------------|
| `/start` | 欢迎与使用说明 |
| `/scan [block]` | 扫描特定区块的 MEV |
| `/latest` | 扫描最新区块 |
| `/monitor on/off` | 开启/关闭自动区块监控 |
| `/status` | 当前区块与 gas 价格 |
| `/bots` | 列出已知的 MEV 机器人地址 |
| `/help` | 显示所有命令 |
### 示例
```
/scan 25140000
/latest
/monitor on
/bots
```
## 📊 输出示例
```
🎯 MEV DETECTED — Block #25140000
━━━━━━━━━━━━━━━━━━━━━━
📦 Total TXs : 234
🔄 DEX TXs : 18
⚡ MEV Found : 3
🥪 Sandwiches : 1
💱 Arbitrages : 2
🔴 High Risk : 2
🔴 SANDWICH ATTACK
👤 Attacker: 0xae2fc483...
🏊 DEX: Uniswap V2
🎯 Victims: 1
⚠️ Known Bot: Jaredfromsubway.eth
🔴 ARBITRAGE — MEV Bot (Generalized)
🤖 Bot: 0x00000000...
🏊 DEX: Uniswap V3
🔧 Fn: exactInputSingle (V3)
```
## 🏗️ 架构
```
mev_detector.py
├── Web3Client → Web3.py RPC (block & TX data)
├── EtherscanClient → Etherscan V2 API (internal TXs)
├── MEVAnalyzer → Core detection engine
│ ├── detect_sandwich() → sandwich attack detection
│ ├── detect_arbitrage() → arbitrage detection
│ ├── detect_frontrun() → frontrunning detection
│ └── scan_block() → full block MEV scan
├── MEVReporter → Format & send Telegram alerts
└── MEVBot → Telegram bot with commands
```
## 🎯 检测逻辑
### 三明治攻击
```
Pattern: [buy TX] → [victim TX] → [sell TX]
- Same attacker address
- Same DEX router
- Victim TX sandwiched between attacker's buy/sell
- Window: 3 transactions
```
### 套利
```
Pattern: Known MEV bot + DEX interaction
- Address matches known MEV bot database
- High gas premium (>3x average)
```
### 抢跑
```
Pattern: High gas TX before similar TX
- Same DEX router & function
- Gas premium > 1.5x next TX
- Different sender addresses
```
## 🤖 已知 MEV 机器人
| 地址 | 标签 |
|---------|-------|
| `0x00000000003b...` | MEV 机器人 (通用) |
| `0x00000000003...` | MEV 机器人 (三明治) |
| `0xae2fc483...` | Jaredfromsubway.eth |
| `0x6b75d8af...` | MEV 机器人 (套利) |
## 🔧 API 密钥
| 服务 | 获取密钥 | 免费额度 |
|---------|---------|-----------|
| Infura | [infura.io](https://infura.io) | 10万次请求/天 |
| Etherscan | [etherscan.io/apis](https://etherscan.io/apis) | 5次请求/秒 |
| Telegram 机器人 | [@BotFather](https://t.me/BotFather) | 免费 |
## 👤 作者
**Rizal** — [@rizalcodes](https://github.com/rizalcodes)
## 📄 许可证
MIT 许可证 — 可免费使用、修改和分发。
标签:MEV检测, Python, Web3, 以太坊, 区块链, 无后门, 逆向工具, 量化分析