Skill站外收录 @skilllib/skill-2117939930272416300
routing-dex-trades
实现跨多个去中心化交易所的智能交易路由,自动寻找最优兑换路径,在最小化滑点和 Gas 费用的同时,支持多跳路径发现、大额订单拆分、价格影响分析及 MEV 风险评估。
区块链 AI 技能
Skills.MD
# Routing DEX Trades
## Overview
This skill provides optimal trade routing across decentralized exchanges by aggregating quotes from multiple sources (1inch, Paraswap, 0x), discovering multi-hop routes, calculating split orders for large trades, and assessing MEV risk. It helps traders execute at the best prices while minimizing slippage and gas costs.
## Prerequisites
Before using this skill, ensure you have:
- Python 3.9+ with `httpx`, `pydantic`, and `rich` packages
- Network access to aggregator APIs (1inch, Paraswap, 0x)
- Optional: API keys for 1inch and 0x (higher rate limits)
- Environment variables configured in `{baseDir}/config/settings.yaml`
- Understanding of DeFi trading concepts (slippage, price impact, MEV)
## Instructions
### Step 1: Configure API Access
1. Copy settings template: `cp {baseDir}/config/settings.yaml.example {baseDir}/config/settings.yaml`
2. Add optional API keys:
```yaml
api_keys:
oneinch: "your-1inch-api-key" # Optional, increases rate limits
zerox: "your-0x-api-key" # Optional
```
3. Set preferred chain: `ethereum`, `arbitrum`, `polygon`, or `optimism`
### Step 2: Quick Quote (Single Best Price)
Use Bash(crypto:dex-router) to get the best price across aggregators:
```bash
python {baseDir}/scripts/dex_router.py ETH USDC 1.0
```
This returns the single best route with price, gas cost, and effective rate.
### Step 3: Compare All DEXs
For detailed comparison across all sources:
```bash
python {baseDir}/scripts/dex_router.py ETH USDC 5.0 --compare
```
Output includes quotes from each aggregator with:
- Output amount and rate
- Price impact percentage
- Gas cost in USD
- Effective rate (after gas)
### Step 4: Analyze Routes (Multi-Hop Discovery)
For trades where multi-hop might be cheaper:
```bash
python {baseDir}/scripts/dex_router.py ETH USDC 10.0 --routes
```
Discovers and compares:
- Direct routes (single pool)
- Multi-hop routes (2-3 pools)
- Shows hop-by-hop breakdown with cumulative impact
### Step 5: Split Large Orders
For whale-sized trades ($10K+), optimize across multiple DEXs:
```bash
python {baseDir}/scripts/dex_router.py ETH USDC 100.0 --split
```
Calculates optimal allocation:
```
Split Recommendation:
60% via Uniswap V3 (60 ETH → 152,589 USDC)
40% via Curve (40 ETH → 101,843 USDC)
─────────────────────────────────────────────
Total: 254,432 USDC (vs. 251,200 single-venue)
Improvement: +1.28% ($3,232 saved)
```
### Step 6: MEV Risk Assessment
Check sandwich attack risk before executing:
```bash
python {baseDir}/scripts/dex_router.py ETH USDC 50.0 --mev-check
```
Returns risk score and recommendations:
- LOW: Safe to execute via public mempool
- MEDIUM: Consider private transaction
- HIGH: Use Flashbots Protect or CoW Swap
### Step 7: Full Analysis
Combine all features for comprehensive analysis:
```bash
python {baseDir}/scripts/dex_router.py ETH USDC 25.0 --full --output json
```
See `{baseDir}/references/examples.md` for detailed output examples.
## Output
The router provides:
**Quick Quote Mode:**
- Best price across aggregators
- Output amount and effective rate
- Gas cost estimate
- Recommended venue
**Comparison Mode:**
- All venues ranked by effective rate
- Price impact per venue
- Gas costs compared
- Liquidity depth indicators
**Route Analysis:**
- Direct vs. multi-hop comparison
- Hop-by-hop breakdown
- Cumulative price impact
- Gas cost per route type
**Split Mode:**
- Optimal allocation percentages
- Per-venue amounts
- Total vs. single-venue comparison
- Dollar savings estimate
**MEV Assessment:**
- Risk score (LOW/MEDIUM/HIGH)
- Exposure estimate
- Protection recommendations
- Alternative venues (CoW Swap, etc.)
## Trade Size Recommendations
| Trade Size | Strategy | Notes |
|------------|----------|-------|
| < $1K | Direct quote | Gas may exceed savings from optimization |
| $1K - $10K | Compare + routes | Multi-hop can save 0.1-0.5% |
| $10K - $100K | Split analysis | 2-3 way splits reduce impact |
| > $100K | Full + MEV + private TX | Consider OTC or algorithmic execution |
## Error Handling
See `{baseDir}/references/errors.md` for comprehensive error handling.
Common issues:
- **API Rate Limited**: Wait 60s or use API key for higher limits
- **Quote Expired**: Refresh before execution; quotes valid ~30s
- **No Route Found**: Token may have low liquidity; try larger DEXs
- **Network Timeout**: Retry or check aggregator status
## Examples
See `{baseDir}/references/examples.md` for detailed examples including:
- Basic ETH→USDC swap comparison
- Multi-hop route discovery
- Large order splitting
- MEV-protected execution paths
## Resources
- [1inch API Documentation](https://docs.1inch.io/)
- [Paraswap API](https://developers.paraswap.network/)
- [0x API](https://0x.org/docs/api)
- [Flashbots Protect](https://docs.flashbots.net/flashbots-protect/overview)
- [CoW Swap](https://docs.cow.fi/)
评论 0
还没有评论,来抢沙发。
相关内容
同类或同场景的收录内容
building-with-kafka-strimzi
在 Kubernetes 上构建基于 Apache Kafka 的事件驱动系统,支持高可靠的消息传递、事务性处理与精确一次语义,结合 Strimzi 运营商实现集群自动化管理,利用 Schema Registry 保障事件模式演进,适用于微服务间解耦通信与实时数据流处理场景。
站外数据与分析
609 0.0
personal-tool-builder
专注于从个人真实痛点出发快速构建实用工具,涵盖命令行程序、本地优先应用和自动化脚本的开发与演进,强调先满足自身需求再逐步扩展,通过持续自用打磨功能,避免过度设计,确保工具简洁有效且长期可维护。
站外商业与营销
196 0.0
threejs-lighting
实现三维场景中的光照与阴影控制,支持多种光源类型及环境光照明,提供从基础布光到高级阴影优化的完整方案,适用于需要真实感渲染或性能平衡的可视化项目。
站外效率工具
442 0.0
aggregation-helper
提供数据聚合场景的自动化辅助能力,涵盖 SQL 查询编写、统计分析建模、可视化方案设计及商业智能配置,支持从需求理解到生产级代码生成的全流程指导。
站外效率工具数据与分析
217 0.0
举报「routing-dex-trades」
举报信息仅审核团队可见,同一资产 24 小时内仅可举报一次