opentrade-dex-swap
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseOpenTrade DEX Aggregator CLI
OpenTrade DEX聚合器CLI
5 commands for multi-chain swap aggregation — quote, approve, and execute.
提供5个用于多链兑换聚合的命令:报价、授权、执行。
Pre-flight Checks
前置检查
Every time before running any command, always follow these steps in order. Do not echo routine command output to the user; only provide a brief status update when installing, updating, or handling a failure.
opentrade-
Confirm installed: Run. If not found, install it:
which opentradebashcurl -sSL https://raw.githubusercontent.com/6551Team/openskills/main/skills/opentrade/install.sh | shIf the install script fails, ask the user to install manually following the instructions at: https://github.com/6551Team/openskills -
Check for updates: Readand compare it with the current timestamp:
~/.opentrade/last_checkbashcached_ts=$(cat ~/.opentrade/last_check 2>/dev/null || true) now=$(date +%s)- If is non-empty and
cached_ts(12 hours), skip the update and proceed.(now - cached_ts) < 43200 - Otherwise (file missing or older than 12 hours), run the installer to check for updates:
If a newer version is installed, tell the user and suggest updating their opentrade skills from https://github.com/6551Team/openskills to get the latest features.bash
curl -sSL https://raw.githubusercontent.com/6551Team/openskills/main/skills/opentrade/install.sh | sh
- If
-
If anycommand fails with an unexpected error during this session, try reinstalling before giving up:
opentradebashcurl -sSL https://raw.githubusercontent.com/6551Team/openskills/main/skills/opentrade/install.sh | sh -
Find or create a .env file in the project root to override the default API credentials, Load it before performing opentrade operations.
bash
OPEN_TOKEN=your_token_hereGet your API token at: https://6551.io/mcp
Security warning: Never commit .env to git (add it to .gitignore) and never expose credentials in logs, screenshots, or chat messages.
每次运行任何命令前,请务必按顺序遵循以下步骤。不要将常规命令的输出回显给用户,仅在安装、更新或处理故障时提供简短的状态更新。
opentrade-
确认已安装:运行,如果未找到该命令则执行安装:
which opentradebashcurl -sSL https://raw.githubusercontent.com/6551Team/openskills/main/skills/opentrade/install.sh | sh如果安装脚本执行失败,请告知用户按照官方文档手动安装:https://github.com/6551Team/openskills -
检查更新:读取内容并和当前时间戳对比:
~/.opentrade/last_checkbashcached_ts=$(cat ~/.opentrade/last_check 2>/dev/null || true) now=$(date +%s)- 如果非空且
cached_ts(12小时),则跳过更新继续后续操作。(now - cached_ts) < 43200 - 其他情况(文件不存在或超过12小时未更新),运行安装脚本检查更新:
如果安装了新版本,告知用户并建议从https://github.com/6551Team/openskills更新opentrade技能以获取最新功能。bash
curl -sSL https://raw.githubusercontent.com/6551Team/openskills/main/skills/opentrade/install.sh | sh
- 如果
-
如果本次会话中任意命令出现非预期错误,在放弃前先尝试重新安装:
opentradebashcurl -sSL https://raw.githubusercontent.com/6551Team/openskills/main/skills/opentrade/install.sh | sh -
在项目根目录查找或创建.env文件覆盖默认API凭证,执行opentrade操作前先加载该文件:
bash
OPEN_TOKEN=your_token_here可在此处获取API token:https://6551.io/mcp
安全警告:永远不要将.env提交到git(请将其添加到.gitignore中),也不要在日志、截图或聊天消息中泄露凭证。
Router Discovery
路由器发现
IMPORTANT: If the user has not specified a trading router, you MUST first discover available routers:
bash
opentrade trade routersResponse format:
json
{
"ok": true,
"data": [
{
"api": "v2",
"created_at": "2026-03-10 01:15:42",
"is_active": true,
"name": "6551dex test",
"quota_reward": 0,
"trader": "6551dex",
"updated_at": "2026-03-10 01:15:42"
},
{
"api": "v1",
"created_at": "2026-03-03 21:24:34",
"is_active": true,
"name": "okx test",
"quota_reward": 0,
"trader": "okx",
"updated_at": "2026-03-03 21:24:34"
}
]
}Usage:
- Extract and
traderfrom the responseapi - MANDATORY: ALL subsequent commands in this session MUST include
opentradeand--trader <trader>flags--api <api> - Example:
opentrade swap quote --from 0x... --to 0x... --amount 100 --chain ethereum --trader okx --api v1 - Default fallback: If the API returns no data or is empty, use
--trader okx --api v1
重要提示:如果用户未指定交易路由器,你必须先查询可用的路由器:
bash
opentrade trade routers返回格式:
json
{
"ok": true,
"data": [
{
"api": "v2",
"created_at": "2026-03-10 01:15:42",
"is_active": true,
"name": "6551dex test",
"quota_reward": 0,
"trader": "6551dex",
"updated_at": "2026-03-10 01:15:42"
},
{
"api": "v1",
"created_at": "2026-03-03 21:24:34",
"is_active": true,
"name": "okx test",
"quota_reward": 0,
"trader": "okx",
"updated_at": "2026-03-03 21:24:34"
}
]
}使用规则:
- 从返回结果中提取和
trader参数api - 强制要求:本次会话中所有后续命令都必须携带
opentrade和--trader <trader>参数--api <api> - 示例:
opentrade swap quote --from 0x... --to 0x... --amount 100 --chain ethereum --trader okx --api v1 - 默认兜底规则:如果API没有返回数据或数据为空,使用
--trader okx --api v1
Skill Routing
技能路由
- For token search → use
opentrade-token - For market prices → use
opentrade-market - For transaction broadcasting → use
opentrade-gateway - For wallet balances / portfolio → use
opentrade-portfolio
- 代币搜索 → 使用
opentrade-token - 市场价格查询 → 使用
opentrade-market - 交易广播 → 使用
opentrade-gateway - 钱包余额/资产组合查询 → 使用
opentrade-portfolio
Quickstart
快速开始
EVM Swap (quote → approve → swap)
EVM链兑换(报价 → 授权 → 兑换)
bash
undefinedbash
undefined1. Quote — sell 100 USDC for OKB on XLayer
1. 报价 — 在XLayer链上将100 USDC兑换为OKB
opentrade swap quote
--from 0x74b7f16337b8972027f6196a17a631ac6de26d22
--to 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
--amount 100000000
--chain xlayer
--from 0x74b7f16337b8972027f6196a17a631ac6de26d22
--to 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
--amount 100000000
--chain xlayer
opentrade swap quote
--from 0x74b7f16337b8972027f6196a17a631ac6de26d22
--to 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
--amount 100000000
--chain xlayer
--from 0x74b7f16337b8972027f6196a17a631ac6de26d22
--to 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
--amount 100000000
--chain xlayer
→ Expected: X.XX OKB, gas fee, price impact
→ 预期返回:X.XX OKB、gas费、价格影响
2. Approve — ERC-20 tokens need approval before swap (skip for native OKB)
2. 授权 — ERC-20代币兑换前需要授权(原生OKB可跳过该步骤)
opentrade swap approve
--token 0x74b7f16337b8972027f6196a17a631ac6de26d22
--amount 100000000
--chain xlayer
--token 0x74b7f16337b8972027f6196a17a631ac6de26d22
--amount 100000000
--chain xlayer
opentrade swap approve
--token 0x74b7f16337b8972027f6196a17a631ac6de26d22
--amount 100000000
--chain xlayer
--token 0x74b7f16337b8972027f6196a17a631ac6de26d22
--amount 100000000
--chain xlayer
→ Returns approval calldata: sign and broadcast via opentrade-gateway
→ 返回授权calldata:签名后通过opentrade-gateway广播即可
3. Swap
3. 兑换
opentrade swap swap
--from 0x74b7f16337b8972027f6196a17a631ac6de26d22
--to 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
--amount 100000000
--chain xlayer
--wallet 0xYourWallet
--slippage 1
--from 0x74b7f16337b8972027f6196a17a631ac6de26d22
--to 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
--amount 100000000
--chain xlayer
--wallet 0xYourWallet
--slippage 1
opentrade swap swap
--from 0x74b7f16337b8972027f6196a17a631ac6de26d22
--to 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
--amount 100000000
--chain xlayer
--wallet 0xYourWallet
--slippage 1
--from 0x74b7f16337b8972027f6196a17a631ac6de26d22
--to 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
--amount 100000000
--chain xlayer
--wallet 0xYourWallet
--slippage 1
→ Returns tx data: sign and broadcast via opentrade-gateway
→ 返回交易数据:签名后通过opentrade-gateway广播即可
undefinedundefinedSolana Swap
Solana链兑换
bash
opentrade swap swap \
--from 11111111111111111111111111111111 \
--to DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263 \
--amount 1000000000 \
--chain solana \
--wallet YourSolanaWallet \
--slippage 1bash
opentrade swap swap \
--from 11111111111111111111111111111111 \
--to DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263 \
--amount 1000000000 \
--chain solana \
--wallet YourSolanaWallet \
--slippage 1→ Returns tx data: sign and broadcast via opentrade-gateway
→ 返回交易数据:签名后通过opentrade-gateway广播即可
undefinedundefinedChain Name Support
公链名称支持
The CLI accepts human-readable chain names and resolves them automatically.
| Chain | Name | chainIndex |
|---|---|---|
| XLayer | | |
| Solana | | |
| Ethereum | | |
| Base | | |
| BSC | | |
| Arbitrum | | |
CLI支持传入易读的公链名称并会自动解析。
| 公链 | 名称 | chainIndex |
|---|---|---|
| XLayer | | |
| Solana | | |
| Ethereum | | |
| Base | | |
| BSC | | |
| Arbitrum | | |
Native Token Addresses
原生代币地址
CRITICAL: Each chain has a specific native token address. Using the wrong address will cause swap transactions to fail.
| Chain | Native Token Address |
|---|---|
| EVM (Ethereum, BSC, Polygon, Arbitrum, Base, etc.) | |
| Solana | |
| Sui | |
| Tron | |
| Ton | |
WARNING — Solana native SOL: The correct address is(Solana system program). Do NOT use11111111111111111111111111111111(wSOL SPL token) — it is a different token and will cause swap failures.So11111111111111111111111111111111111111112
关键提示:每条公链都有专属的原生代币地址,使用错误地址会导致兑换交易失败。
| 公链 | 原生代币地址 |
|---|---|
| EVM(Ethereum、BSC、Polygon、Arbitrum、Base等) | |
| Solana | |
| Sui | |
| Tron | |
| Ton | |
警告 — Solana原生SOL:正确地址为(Solana系统程序),不要使用11111111111111111111111111111111(wSOL SPL代币),二者是不同代币,使用后者会导致兑换失败。So11111111111111111111111111111111111111112
Command Index
命令索引
| # | Command | Description |
|---|---|---|
| 1 | | Get supported chains for DEX aggregator |
| 2 | | Get available liquidity sources on a chain |
| 3 | | Get ERC-20 approval transaction data |
| 4 | | Get swap quote (read-only price estimate) |
| 5 | | Get swap transaction data |
| 序号 | 命令 | 描述 |
|---|---|---|
| 1 | | 获取DEX聚合器支持的公链列表 |
| 2 | | 获取指定公链上可用的流动性来源 |
| 3 | | 获取ERC-20授权交易数据 |
| 4 | | 获取兑换报价(只读价格预估) |
| 5 | | 获取兑换交易数据 |
Cross-Skill Workflows
跨技能工作流
This skill is the execution endpoint of most user trading flows. It almost always needs input from other skills first.
本技能是大多数用户交易流程的执行端点,几乎总是需要先从其他技能获取输入。
Workflow A: Full Swap by Token Name (most common)
工作流A:按代币名称完成全流程兑换(最常用)
User: "Swap 1 SOL for BONK on Solana"
1. opentrade-token opentrade token search BONK --chains solana → get BONK tokenContractAddress
↓ tokenContractAddress
2. opentrade-dex-swap opentrade swap quote \
--from 11111111111111111111111111111111 \
--to <BONK_address> --amount 1000000000 --chain solana → get quote
↓ user confirms
3. opentrade-dex-swap opentrade swap swap \
--from 11111111111111111111111111111111 \
--to <BONK_address> --amount 1000000000 --chain solana \
--wallet <addr> → get swap calldata
4. User signs the transaction
5. opentrade-gateway opentrade gateway broadcast --signed-tx <tx> --address <addr> --chain solanaData handoff:
- from step 1 →
tokenContractAddressin steps 2-3--to - SOL native address = →
11111111111111111111111111111111. Do NOT use wSOL address.--from - Amount =
1 SOL(9 decimals) →1000000000param--amount
用户需求:"在Solana链上将1 SOL兑换为BONK"
1. opentrade-token opentrade token search BONK --chains solana → 获取BONK的tokenContractAddress
↓ tokenContractAddress
2. opentrade-dex-swap opentrade swap quote \
--from 11111111111111111111111111111111 \
--to <BONK_address> --amount 1000000000 --chain solana → 获取报价
↓ 用户确认
3. opentrade-dex-swap opentrade swap swap \
--from 11111111111111111111111111111111 \
--to <BONK_address> --amount 1000000000 --chain solana \
--wallet <addr> → 获取兑换calldata
4. 用户对交易签名
5. opentrade-gateway opentrade gateway broadcast --signed-tx <tx> --address <addr> --chain solana数据传递规则:
- 步骤1获取的→ 步骤2-3的
tokenContractAddress参数--to - SOL原生地址→
11111111111111111111111111111111参数,不要使用wSOL地址--from - 金额=
1 SOL(9位小数) →1000000000参数--amount
Workflow B: EVM Swap with Approval
工作流B:带授权的EVM链兑换
User: "Swap 100 USDC for OKB on XLayer"
1. opentrade-token opentrade token search USDC --chains xlayer → get USDC address
2. opentrade-dex-swap opentrade swap quote --from <USDC> --to 0xeeee...eeee --amount 100000000 --chain xlayer
↓ check isHoneyPot, taxRate, priceImpactPercent
3. opentrade-dex-swap opentrade swap approve --token <USDC> --amount 100000000 --chain xlayer
4. User signs the approval transaction
5. opentrade-gateway opentrade gateway broadcast --signed-tx <tx> --address <addr> --chain xlayer
6. opentrade-dex-swap opentrade swap swap --from <USDC> --to 0xeeee...eeee --amount 100000000 --chain xlayer --wallet <addr>
7. User signs the swap transaction
8. opentrade-gateway opentrade gateway broadcast --signed-tx <tx> --address <addr> --chain xlayerKey: EVM tokens (not native OKB) require an approve step. Skip it if user is selling native tokens.
用户需求:"在XLayer链上将100 USDC兑换为OKB"
1. opentrade-token opentrade token search USDC --chains xlayer → 获取USDC地址
2. opentrade-dex-swap opentrade swap quote --from <USDC> --to 0xeeee...eeee --amount 100000000 --chain xlayer
↓ 检查isHoneyPot、taxRate、priceImpactPercent
3. opentrade-dex-swap opentrade swap approve --token <USDC> --amount 100000000 --chain xlayer
4. 用户对授权交易签名
5. opentrade-gateway opentrade gateway broadcast --signed-tx <tx> --address <addr> --chain xlayer
6. opentrade-dex-swap opentrade swap swap --from <USDC> --to 0xeeee...eeee --amount 100000000 --chain xlayer --wallet <addr>
7. 用户对兑换交易签名
8. opentrade-gateway opentrade gateway broadcast --signed-tx <tx> --address <addr> --chain xlayer要点:EVM非原生代币(非OKB)需要授权步骤,如果用户卖出的是原生代币可跳过该步骤。
Workflow C: Compare Quote Then Execute
工作流C:对比报价后执行
1. opentrade swap quote --from ... --to ... --amount ... --chain ... → get quote with route info
2. Display to user: expected output, gas, price impact, route
3. If price impact > 5% → warn user
4. If isHoneyPot = true → block trade, warn user
5. User confirms → proceed to approve (if EVM) → swap1. opentrade swap quote --from ... --to ... --amount ... --chain ... → 获取带路径信息的报价
2. 向用户展示:预期到账金额、gas费、价格影响、兑换路径
3. 如果价格影响 > 5% → 警告用户
4. 如果isHoneyPot = true → 阻止交易并警告用户
5. 用户确认 → 继续执行授权步骤(EVM链需要)→ 完成兑换Swap Flow
兑换流程
EVM Chains (XLayer, Ethereum, BSC, Base, etc.)
EVM链(XLayer、Ethereum、BSC、Base等)
1. opentrade swap quote ... → Get price and route
2. opentrade swap approve ... → Get approval calldata (if needed)
3. User signs the approval transaction
4. opentrade gateway broadcast ... → Broadcast approval tx
5. opentrade swap swap ... → Get swap calldata
6. User signs the swap transaction
7. opentrade gateway broadcast ... → Broadcast swap tx1. opentrade swap quote ... → 获取价格和兑换路径
2. opentrade swap approve ... → 获取授权calldata(如有需要)
3. 用户对授权交易签名
4. opentrade gateway broadcast ... → 广播授权交易
5. opentrade swap swap ... → 获取兑换calldata
6. 用户对兑换交易签名
7. opentrade gateway broadcast ... → 广播兑换交易Solana
Solana链
1. opentrade swap quote ... → Get price and route
2. opentrade swap swap ... → Get swap calldata
3. User signs the transaction
4. opentrade gateway broadcast ... → Broadcast tx1. opentrade swap quote ... → 获取价格和兑换路径
2. opentrade swap swap ... → 获取兑换calldata
3. 用户对交易签名
4. opentrade gateway broadcast ... → 广播交易Operation Flow
操作流程
Step 1: Identify Intent
步骤1:识别用户意图
- View a quote →
opentrade swap quote - Execute a swap → full swap flow (quote → approve → swap)
- List available DEXes →
opentrade swap liquidity - Approve a token →
opentrade swap approve
- 查看报价 →
opentrade swap quote - 执行兑换 → 完整兑换流程(报价→授权→兑换)
- 列出可用DEX →
opentrade swap liquidity - 授权代币 →
opentrade swap approve
Step 2: Collect Parameters
步骤2:收集参数
- Missing chain → recommend XLayer (, low gas, fast confirmation) as the default, then ask which chain the user prefers
--chain xlayer - Missing token addresses → use
opentrade-tokento resolve name → addressopentrade token search - Missing amount → ask user, remind to convert to minimal units
- Missing slippage → suggest 1% default, 3-5% for volatile tokens
- Missing wallet address → ask user
- 缺少公链信息 → 默认推荐XLayer(,低gas、确认快),再询问用户偏好的公链
--chain xlayer - 缺少代币地址 → 使用的
opentrade-token功能将代币名称解析为地址opentrade token search - 缺少金额 → 询问用户,提醒需转换为最小单位
- 缺少滑点设置 → 建议默认1%,波动率高的代币建议3-5%
- 缺少钱包地址 → 询问用户
Step 3: Execute
步骤3:执行操作
- Quote phase: call , display estimated results
opentrade swap quote- Expected output, gas estimate, price impact, routing path
- Check and
isHoneyPot— surface safety info to userstaxRate
- Confirmation phase: wait for user approval before proceeding
- Approval phase (EVM only): check/execute approve if selling non-native token
- Execution phase: call , return tx data for signing
opentrade swap swap
- 报价阶段:调用,展示预估结果
opentrade swap quote- 预期到账金额、gas预估、价格影响、路由路径
- 检查和
isHoneyPot,向用户披露安全信息taxRate
- 确认阶段:继续操作前等待用户确认
- 授权阶段(仅EVM链):如果卖出非原生代币,检查/执行授权操作
- 执行阶段:调用,返回待签名的交易数据
opentrade swap swap
Step 4: Suggest Next Steps
步骤4:建议后续操作
After displaying results, suggest 2-3 relevant follow-up actions:
| Just completed | Suggest |
|---|---|
| 1. View price chart before deciding → |
| Swap executed successfully | 1. Check price of the token just received → |
| 1. Get a swap quote → |
Present conversationally, e.g.: "Swap complete! Would you like to check your updated balance?" — never expose skill names or endpoint paths to the user.
展示结果后,建议2-3个相关的后续操作:
| 刚完成操作 | 建议操作 |
|---|---|
| 1. 决策前查看价格走势 → |
| 兑换成功 | 1. 查看刚到账代币的价格 → |
| 1. 获取兑换报价 → |
采用对话式表述,例如:"兑换完成!你需要查看更新后的余额吗?" —— 永远不要向用户暴露技能名称或端点路径。
CLI Command Reference
CLI命令参考
1. opentrade swap chains
1. opentrade swap chains
Get supported chains for DEX aggregator. No parameters required.
bash
opentrade swap chainsReturn fields:
| Field | Type | Description |
|---|---|---|
| String | Chain identifier (e.g., |
| String | Human-readable chain name |
| String | DEX router address for token approvals on this chain |
获取DEX聚合器支持的公链列表,无参数要求。
bash
opentrade swap chains返回字段:
| 字段 | 类型 | 描述 |
|---|---|---|
| String | 公链标识符(例如 |
| String | 易读的公链名称 |
| String | 该公链上用于代币授权的DEX路由器地址 |
2. opentrade swap liquidity
2. opentrade swap liquidity
Get available liquidity sources on a chain.
bash
opentrade swap liquidity --chain <chain>| Param | Required | Default | Description |
|---|---|---|---|
| Yes | - | Chain name (e.g., |
Return fields:
| Field | Type | Description |
|---|---|---|
| String | Liquidity source ID |
| String | Liquidity source name (e.g., |
| String | Liquidity source logo URL |
获取指定公链上可用的流动性来源。
bash
opentrade swap liquidity --chain <chain>| 参数 | 是否必填 | 默认值 | 描述 |
|---|---|---|---|
| 是 | - | 公链名称(例如 |
返回字段:
| 字段 | 类型 | 描述 |
|---|---|---|
| String | 流动性来源ID |
| String | 流动性来源名称(例如 |
| String | 流动性来源logo URL |
3. opentrade swap approve
3. opentrade swap approve
Get ERC-20 approval transaction data.
bash
opentrade swap approve --token <address> --amount <amount> --chain <chain>| Param | Required | Default | Description |
|---|---|---|---|
| Yes | - | Token contract address to approve |
| Yes | - | Amount in minimal units |
| Yes | - | Chain name |
Return fields:
| Field | Type | Description |
|---|---|---|
| String | Approval calldata (hex) — use as tx |
| String | Spender address (already encoded in |
| String | Estimated gas limit for the approval tx |
| String | Recommended gas price |
获取ERC-20授权交易数据。
bash
opentrade swap approve --token <address> --amount <amount> --chain <chain>| 参数 | 是否必填 | 默认值 | 描述 |
|---|---|---|---|
| 是 | - | 待授权的代币合约地址 |
| 是 | - | 授权金额(最小单位) |
| 是 | - | 公链名称 |
返回字段:
| 字段 | 类型 | 描述 |
|---|---|---|
| String | 授权calldata(十六进制)—— 作为交易的 |
| String | 被授权地址(已编码在 |
| String | 授权交易的预估gas limit |
| String | 建议的gas price |
4. opentrade swap quote
4. opentrade swap quote
Get swap quote (read-only price estimate).
bash
opentrade swap quote --from <address> --to <address> --amount <amount> --chain <chain> [--swap-mode <mode>]| Param | Required | Default | Description |
|---|---|---|---|
| Yes | - | Source token contract address |
| Yes | - | Destination token contract address |
| Yes | - | Amount in minimal units (sell amount if exactIn, buy amount if exactOut) |
| Yes | - | Chain name |
| No | | |
Return fields:
| Field | Type | Description |
|---|---|---|
| String | Expected output amount in minimal units |
| String | Input amount in minimal units |
| String | Estimated gas fee (native token units) |
| String | Trade fee estimate in USD |
| String | Price impact as percentage (e.g., |
| String | Router type used |
| Array | DEX routing path details |
| String | DEX name in the route |
| String | Percentage of amount routed through this DEX |
| Boolean | |
| String | Source token buy/sell tax rate |
| String | Source token decimals |
| String | Source token unit price in USD |
| Boolean | |
| String | Destination token buy/sell tax rate |
| String | Destination token decimals |
| String | Destination token unit price in USD |
获取兑换报价(只读价格预估)。
bash
opentrade swap quote --from <address> --to <address> --amount <amount> --chain <chain> [--swap-mode <mode>]| 参数 | 是否必填 | 默认值 | 描述 |
|---|---|---|---|
| 是 | - | 源代币合约地址 |
| 是 | - | 目标代币合约地址 |
| 是 | - | 金额(最小单位,exactIn模式为卖出金额,exactOut模式为买入金额) |
| 是 | - | 公链名称 |
| 否 | | |
返回字段:
| 字段 | 类型 | 描述 |
|---|---|---|
| String | 预期到账金额(最小单位) |
| String | 输入金额(最小单位) |
| String | 预估gas费(原生代币单位) |
| String | 预估交易手续费(USD计价) |
| String | 价格影响百分比(例如 |
| String | 使用的路由器类型 |
| Array | DEX路由路径详情 |
| String | 路径中包含的DEX名称 |
| String | 该DEX路由的资金占比 |
| Boolean | |
| String | 源代币的买卖税率 |
| String | 源代币的小数位数 |
| String | 源代币的单位价格(USD计价) |
| Boolean | |
| String | 目标代币的买卖税率 |
| String | 目标代币的小数位数 |
| String | 目标代币的单位价格(USD计价) |
5. opentrade swap swap
5. opentrade swap swap
Get swap transaction data (quote → sign → broadcast).
bash
opentrade swap swap --from <address> --to <address> --amount <amount> --chain <chain> --wallet <address> [--slippage <pct>] [--swap-mode <mode>]| Param | Required | Default | Description |
|---|---|---|---|
| Yes | - | Source token contract address |
| Yes | - | Destination token contract address |
| Yes | - | Amount in minimal units |
| Yes | - | Chain name |
| Yes | - | User's wallet address |
| No | | Slippage tolerance in percent (e.g., |
| No | | |
Return fields:
| Field | Type | Description |
|---|---|---|
| Object | Same structure as quote return (see swap quote above) |
| String | Sender address |
| String | Contract address to send the transaction to |
| String | Transaction calldata (hex for EVM, base58 for Solana) |
| String | Gas limit for the transaction |
| String | Gas price |
| String | Native token value to send (in minimal units) |
| String | Minimum receive amount after slippage (minimal units) |
| String | Maximum spend amount (for exactOut mode) |
| String | Applied slippage tolerance percentage |
获取兑换交易数据(报价→签名→广播)。
bash
opentrade swap swap --from <address> --to <address> --amount <amount> --chain <chain> --wallet <address> [--slippage <pct>] [--swap-mode <mode>]| 参数 | 是否必填 | 默认值 | 描述 |
|---|---|---|---|
| 是 | - | 源代币合约地址 |
| 是 | - | 目标代币合约地址 |
| 是 | - | 金额(最小单位) |
| 是 | - | 公链名称 |
| 是 | - | 用户的钱包地址 |
| 否 | | 滑点容忍度百分比(例如 |
| 否 | | |
返回字段:
| 字段 | 类型 | 描述 |
|---|---|---|
| Object | 和报价接口返回结构一致(参考上述swap quote返回) |
| String | 发送方地址 |
| String | 交易的目标合约地址 |
| String | 交易calldata(EVM链为十六进制,Solana为base58) |
| String | 交易的gas limit |
| String | gas price |
| String | 发送的原生代币金额(最小单位) |
| String | 滑点扣除后的最小到账金额(最小单位) |
| String | 最大花费金额(exactOut模式下使用) |
| String | 实际使用的滑点容忍度百分比 |
Input / Output Examples
输入输出示例
User says: "Swap 100 USDC for OKB on XLayer"
bash
undefined用户需求: "在XLayer链上将100 USDC兑换为OKB"
bash
undefined1. Quote
1. 报价
opentrade swap quote --from 0x74b7f16337b8972027f6196a17a631ac6de26d22 --to 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee --amount 100000000 --chain xlayer
opentrade swap quote --from 0x74b7f16337b8972027f6196a17a631ac6de26d22 --to 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee --amount 100000000 --chain xlayer
→ Expected output: 3.2 OKB, Gas fee: ~$0.001, Price impact: 0.05%
→ 预期输出:3.2 OKB,Gas费:~$0.001,价格影响:0.05%
2. Approve (ERC-20 token needs approval)
2. 授权(ERC-20代币需要授权)
opentrade swap approve --token 0x74b7f16337b8972027f6196a17a631ac6de26d22 --amount 100000000 --chain xlayer
opentrade swap approve --token 0x74b7f16337b8972027f6196a17a631ac6de26d22 --amount 100000000 --chain xlayer
→ Returns approval calldata → user signs → broadcast
→ 返回授权calldata → 用户签名 → 广播
3. Swap
3. 兑换
opentrade swap swap --from 0x74b7f16337b8972027f6196a17a631ac6de26d22 --to 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee --amount 100000000 --chain xlayer --wallet 0xYourWallet --slippage 1
opentrade swap swap --from 0x74b7f16337b8972027f6196a17a631ac6de26d22 --to 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee --amount 100000000 --chain xlayer --wallet 0xYourWallet --slippage 1
→ Returns tx data → user signs → broadcast
→ 返回交易数据 → 用户签名 → 广播
**User says:** "What DEXes are available on XLayer?"
```bash
opentrade swap liquidity --chain xlayer
**用户需求:** "XLayer链上有哪些可用的DEX?"
```bash
opentrade swap liquidity --chain xlayer→ Display: CurveNG, XLayer DEX, ... (DEX sources on XLayer)
→ 展示:CurveNG、XLayer DEX等XLayer上的DEX来源
undefinedundefinedEdge Cases
边缘情况处理
- High slippage (>5%): warn user, suggest splitting the trade or adjusting slippage
- Large price impact (>10%): strongly warn, suggest reducing amount
- Honeypot token: — block trade and warn user
isHoneyPot = true - Tax token: non-zero — display to user (e.g. 5% buy tax)
taxRate - Insufficient balance: check balance first, show current balance, suggest adjusting amount
- exactOut not supported: only Ethereum/Base/BSC/Arbitrum — prompt user to use
exactIn - Solana native SOL address: Must use (system program), NOT
11111111111111111111111111111111(wSOL)So11111111111111111111111111111111111111112 - Network error: retry once, then prompt user to try again later
- Region restriction (error code 50125 or 80001): do NOT show the raw error code to the user. Instead, display a friendly message:
⚠️ Service is not available in your region. Please switch to a supported region and try again.
- 高滑点(>5%):警告用户,建议拆分交易或调整滑点设置
- 高价格影响(>10%):强烈警告,建议减少交易金额
- 蜜罐代币:—— 阻止交易并警告用户
isHoneyPot = true - 税率代币:非零 —— 向用户展示税率(例如5%买入税)
taxRate - 余额不足:先查询余额,展示当前余额,建议调整交易金额
- exactOut模式不支持:仅Ethereum/Base/BSC/Arbitrum支持该模式,提示用户使用模式
exactIn - Solana原生SOL地址:必须使用(系统程序),不要使用
11111111111111111111111111111111(wSOL)So11111111111111111111111111111111111111112 - 网络错误:重试一次,仍失败则提示用户稍后再试
- 地域限制(错误码50125或80001):不要向用户展示原始错误码,而是展示友好提示:
⚠️ 您所在的地区暂不支持该服务,请切换到支持的地区后重试。
Amount Display Rules
金额展示规则
- Input/output amounts in UI units (,
1.5 ETH)3,200 USDC - Internal CLI params use minimal units (=
1 USDC,"1000000"=1 ETH)"1000000000000000000" - Gas fees in USD
- in both UI units and USD
minReceiveAmount - Price impact as percentage
- 面向用户展示的输入/输出金额使用UI单位(、
1.5 ETH)3,200 USDC - CLI内部参数使用最小单位(=
1 USDC,"1000000"=1 ETH)"1000000000000000000" - Gas费使用USD计价展示
- 同时展示UI单位和USD计价
minReceiveAmount - 价格影响使用百分比展示
Global Notes
全局注意事项
- Amounts must be in minimal units (wei/lamports)
- only on Ethereum(
exactOut)/Base(1)/BSC(8453)/Arbitrum(56)42161 - Check and
isHoneyPot— surface safety info to userstaxRate - EVM contract addresses must be all lowercase
- The CLI resolves chain names automatically (e.g., →
ethereum,1→solana)501 - The CLI handles authentication internally via environment variables — see Prerequisites step 4 for default values
- 金额必须使用最小单位(wei/lamports)
- 模式仅支持Ethereum(
exactOut)/Base(1)/BSC(8453)/Arbitrum(56)42161 - 检查和
isHoneyPot,向用户披露安全信息taxRate - EVM合约地址必须全小写
- CLI会自动解析公链名称(例如→
ethereum,1→solana)501 - CLI通过环境变量内部处理身份认证,默认值参考前置检查第4步