routing-dex-trades
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseRouting DEX Trades
DEX交易路由
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.
本Skill通过聚合多个来源(1inch、Paraswap、0x)的报价、发现多跳路径、计算大额订单的拆分方案以及评估MEV风险,提供去中心化交易所间的最优交易路由。它帮助交易者以最优价格执行交易,同时最大限度降低滑点和Gas成本。
Prerequisites
前置条件
Before using this skill, ensure you have:
- Python 3.9+ with ,
httpx, andpydanticpackagesrich - 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)
使用本Skill前,请确保您已具备:
- 安装Python 3.9+,并安装、
httpx和pydantic包rich - 可访问聚合器API(1inch、Paraswap、0x)的网络权限
- 可选:1inch和0x的API密钥(可提升速率限制)
- 在中配置环境变量
{baseDir}/config/settings.yaml - 了解DeFi交易概念(滑点、价格影响、MEV)
Instructions
使用说明
Step 1: Configure API Access
步骤1:配置API访问
- Copy settings template:
cp {baseDir}/config/settings.yaml.example {baseDir}/config/settings.yaml - Add optional API keys:
yaml
api_keys: oneinch: "your-1inch-api-key" # Optional, increases rate limits zerox: "your-0x-api-key" # Optional - Set preferred chain: ,
ethereum,arbitrum, orpolygonoptimism
- 复制设置模板:
cp {baseDir}/config/settings.yaml.example {baseDir}/config/settings.yaml - 添加可选的API密钥:
yaml
api_keys: oneinch: "your-1inch-api-key" # 可选,提升速率限制 zerox: "your-0x-api-key" # 可选 - 设置偏好链:、
ethereum、arbitrum或polygonoptimism
Step 2: Quick Quote (Single Best Price)
步骤2:快速报价(单一最优价格)
Use Bash(crypto:dex-router) to get the best price across aggregators:
bash
python {baseDir}/scripts/dex_router.py ETH USDC 1.0This returns the single best route with price, gas cost, and effective rate.
使用Bash(crypto:dex-router)获取所有聚合器中的最优价格:
bash
python {baseDir}/scripts/dex_router.py ETH USDC 1.0该命令会返回包含价格、Gas成本和实际汇率的单一最优路径。
Step 3: Compare All DEXs
步骤3:对比所有DEX
For detailed comparison across all sources:
bash
python {baseDir}/scripts/dex_router.py ETH USDC 5.0 --compareOutput includes quotes from each aggregator with:
- Output amount and rate
- Price impact percentage
- Gas cost in USD
- Effective rate (after gas)
如需在所有来源间进行详细对比:
bash
python {baseDir}/scripts/dex_router.py ETH USDC 5.0 --compare输出内容包含各聚合器的报价,具体信息:
- 输出金额与汇率
- 价格影响百分比
- 以USD计价的Gas成本
- 实际汇率(扣除Gas后)
Step 4: Analyze Routes (Multi-Hop Discovery)
步骤4:路径分析(多跳路径发现)
For trades where multi-hop might be cheaper:
bash
python {baseDir}/scripts/dex_router.py ETH USDC 10.0 --routesDiscovers and compares:
- Direct routes (single pool)
- Multi-hop routes (2-3 pools)
- Shows hop-by-hop breakdown with cumulative impact
对于多跳路径可能更划算的交易:
bash
python {baseDir}/scripts/dex_router.py ETH USDC 10.0 --routes发现并对比:
- 直接路径(单一资金池)
- 多跳路径(2-3个资金池)
- 展示逐跳明细及累计价格影响
Step 5: Split Large Orders
步骤5:拆分大额订单
For whale-sized trades ($10K+), optimize across multiple DEXs:
bash
python {baseDir}/scripts/dex_router.py ETH USDC 100.0 --splitCalculates 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)针对鲸鱼级交易(1万美元以上),在多个DEX间优化执行:
bash
python {baseDir}/scripts/dex_router.py ETH USDC 100.0 --split计算最优分配方案:
拆分建议:
60% 通过Uniswap V3 (60 ETH → 152,589 USDC)
40% 通过Curve (40 ETH → 101,843 USDC)
─────────────────────────────────────────────
总计:254,432 USDC(对比单一平台的251,200 USDC)
收益提升:+1.28%(节省3,232美元)Step 6: MEV Risk Assessment
步骤6:MEV风险评估
Check sandwich attack risk before executing:
bash
python {baseDir}/scripts/dex_router.py ETH USDC 50.0 --mev-checkReturns risk score and recommendations:
- LOW: Safe to execute via public mempool
- MEDIUM: Consider private transaction
- HIGH: Use Flashbots Protect or CoW Swap
执行前检查三明治攻击风险:
bash
python {baseDir}/scripts/dex_router.py ETH USDC 50.0 --mev-check返回风险评分及建议:
- LOW:可通过公共内存池安全执行
- MEDIUM:考虑使用私有交易
- HIGH:使用Flashbots Protect或CoW Swap
Step 7: Full Analysis
步骤7:全面分析
Combine all features for comprehensive analysis:
bash
python {baseDir}/scripts/dex_router.py ETH USDC 25.0 --full --output jsonSee for detailed output examples.
{baseDir}/references/examples.md组合所有功能进行综合分析:
bash
python {baseDir}/scripts/dex_router.py ETH USDC 25.0 --full --output json详细输出示例请查看。
{baseDir}/references/examples.mdOutput
输出内容
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.)
路由工具提供以下类型的输出:
快速报价模式:
- 所有聚合器中的最优价格
- 输出金额与实际汇率
- Gas成本估算
- 推荐交易平台
对比模式:
- 按实际汇率排序的所有平台
- 各平台的价格影响
- Gas成本对比
- 流动性深度指标
路径分析:
- 直接路径与多跳路径对比
- 逐跳明细
- 累计价格影响
- 不同路径类型的Gas成本
拆分模式:
- 最优分配比例
- 各平台的交易金额
- 总计与单一平台的对比
- 美元收益估算
MEV评估:
- 风险评分(LOW/MEDIUM/HIGH)
- 风险暴露估算
- 防护建议
- 替代平台(CoW Swap等)
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 |
| 交易规模 | 策略 | 说明 |
|---|---|---|
| < 1000美元 | 直接报价 | Gas成本可能超过优化带来的收益 |
| 1000-10000美元 | 对比+路径分析 | 多跳路径可节省0.1-0.5% |
| 10000-100000美元 | 拆分分析 | 2-3个平台拆分可降低价格影响 |
| > 100000美元 | 全面分析+MEV检查+私有交易 | 考虑OTC或算法执行 |
Error Handling
错误处理
See for comprehensive error handling.
{baseDir}/references/errors.mdCommon 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
详细错误处理请查看。
{baseDir}/references/errors.md常见问题:
- API速率限制:等待60秒或使用API密钥提升速率限制
- 报价过期:执行前刷新报价;报价有效期约30秒
- 未找到路径:代币流动性可能较低;尝试更大的DEX
- 网络超时:重试或检查聚合器状态
Examples
示例
See for detailed examples including:
{baseDir}/references/examples.md- Basic ETH→USDC swap comparison
- Multi-hop route discovery
- Large order splitting
- MEV-protected execution paths
详细示例请查看,包括:
{baseDir}/references/examples.md- 基础ETH→USDC兑换对比
- 多跳路径发现
- 大额订单拆分
- MEV防护执行路径