opentrade-dex-swap

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

OpenTrade 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
opentrade
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.
  1. Confirm installed: Run
    which opentrade
    . If not found, install it:
    bash
    curl -sSL https://raw.githubusercontent.com/6551Team/openskills/main/skills/opentrade/install.sh | sh
    If the install script fails, ask the user to install manually following the instructions at: https://github.com/6551Team/openskills
  2. Check for updates: Read
    ~/.opentrade/last_check
    and compare it with the current timestamp:
    bash
    cached_ts=$(cat ~/.opentrade/last_check 2>/dev/null || true)
    now=$(date +%s)
    • If
      cached_ts
      is non-empty and
      (now - cached_ts) < 43200
      (12 hours), skip the update and proceed.
    • Otherwise (file missing or older than 12 hours), run the installer to check for updates:
      bash
      curl -sSL https://raw.githubusercontent.com/6551Team/openskills/main/skills/opentrade/install.sh | sh
      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.
  3. If any
    opentrade
    command fails with an unexpected error during this session, try reinstalling before giving up:
    bash
    curl -sSL https://raw.githubusercontent.com/6551Team/openskills/main/skills/opentrade/install.sh | sh
  4. 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_here
Get 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
命令前,请务必按顺序遵循以下步骤。不要将常规命令的输出回显给用户,仅在安装、更新或处理故障时提供简短的状态更新。
  1. 确认已安装:运行
    which opentrade
    ,如果未找到该命令则执行安装:
    bash
    curl -sSL https://raw.githubusercontent.com/6551Team/openskills/main/skills/opentrade/install.sh | sh
    如果安装脚本执行失败,请告知用户按照官方文档手动安装:https://github.com/6551Team/openskills
  2. 检查更新:读取
    ~/.opentrade/last_check
    内容并和当前时间戳对比:
    bash
    cached_ts=$(cat ~/.opentrade/last_check 2>/dev/null || true)
    now=$(date +%s)
    • 如果
      cached_ts
      非空且
      (now - cached_ts) < 43200
      (12小时),则跳过更新继续后续操作。
    • 其他情况(文件不存在或超过12小时未更新),运行安装脚本检查更新:
      bash
      curl -sSL https://raw.githubusercontent.com/6551Team/openskills/main/skills/opentrade/install.sh | sh
      如果安装了新版本,告知用户并建议从https://github.com/6551Team/openskills更新opentrade技能以获取最新功能。
  3. 如果本次会话中任意
    opentrade
    命令出现非预期错误,在放弃前先尝试重新安装:
    bash
    curl -sSL https://raw.githubusercontent.com/6551Team/openskills/main/skills/opentrade/install.sh | sh
  4. 在项目根目录查找或创建.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 routers
Response 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
    trader
    and
    api
    from the response
  • MANDATORY: ALL subsequent
    opentrade
    commands in this session MUST include
    --trader <trader>
    and
    --api <api>
    flags
  • 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
undefined
bash
undefined

1. Quote — sell 100 USDC for OKB on XLayer

1. 报价 — 在XLayer链上将100 USDC兑换为OKB

opentrade swap quote
--from 0x74b7f16337b8972027f6196a17a631ac6de26d22
--to 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
--amount 100000000
--chain xlayer
opentrade swap quote
--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
opentrade swap approve
--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
opentrade swap swap
--from 0x74b7f16337b8972027f6196a17a631ac6de26d22
--to 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
--amount 100000000
--chain xlayer
--wallet 0xYourWallet
--slippage 1

→ Returns tx data: sign and broadcast via opentrade-gateway

→ 返回交易数据:签名后通过opentrade-gateway广播即可

undefined
undefined

Solana Swap

Solana链兑换

bash
opentrade swap swap \
  --from 11111111111111111111111111111111 \
  --to DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263 \
  --amount 1000000000 \
  --chain solana \
  --wallet YourSolanaWallet \
  --slippage 1
bash
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广播即可

undefined
undefined

Chain Name Support

公链名称支持

The CLI accepts human-readable chain names and resolves them automatically.
ChainNamechainIndex
XLayer
xlayer
196
Solana
solana
501
Ethereum
ethereum
1
Base
base
8453
BSC
bsc
56
Arbitrum
arbitrum
42161
CLI支持传入易读的公链名称并会自动解析。
公链名称chainIndex
XLayer
xlayer
196
Solana
solana
501
Ethereum
ethereum
1
Base
base
8453
BSC
bsc
56
Arbitrum
arbitrum
42161

Native Token Addresses

原生代币地址

CRITICAL: Each chain has a specific native token address. Using the wrong address will cause swap transactions to fail.
ChainNative Token Address
EVM (Ethereum, BSC, Polygon, Arbitrum, Base, etc.)
0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
Solana
11111111111111111111111111111111
Sui
0x2::sui::SUI
Tron
T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb
Ton
EQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAM9c
WARNING — Solana native SOL: The correct address is
11111111111111111111111111111111
(Solana system program). Do NOT use
So11111111111111111111111111111111111111112
(wSOL SPL token) — it is a different token and will cause swap failures.
关键提示:每条公链都有专属的原生代币地址,使用错误地址会导致兑换交易失败。
公链原生代币地址
EVM(Ethereum、BSC、Polygon、Arbitrum、Base等)
0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
Solana
11111111111111111111111111111111
Sui
0x2::sui::SUI
Tron
T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb
Ton
EQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAM9c
警告 — Solana原生SOL:正确地址为
11111111111111111111111111111111
(Solana系统程序),不要使用
So11111111111111111111111111111111111111112
(wSOL SPL代币),二者是不同代币,使用后者会导致兑换失败。

Command Index

命令索引

#CommandDescription
1
opentrade swap chains
Get supported chains for DEX aggregator
2
opentrade swap liquidity --chain <chain>
Get available liquidity sources on a chain
3
opentrade swap approve --token ... --amount ... --chain ...
Get ERC-20 approval transaction data
4
opentrade swap quote --from ... --to ... --amount ... --chain ...
Get swap quote (read-only price estimate)
5
opentrade swap swap --from ... --to ... --amount ... --chain ... --wallet ...
Get swap transaction data
序号命令描述
1
opentrade swap chains
获取DEX聚合器支持的公链列表
2
opentrade swap liquidity --chain <chain>
获取指定公链上可用的流动性来源
3
opentrade swap approve --token ... --amount ... --chain ...
获取ERC-20授权交易数据
4
opentrade swap quote --from ... --to ... --amount ... --chain ...
获取兑换报价(只读价格预估)
5
opentrade swap swap --from ... --to ... --amount ... --chain ... --wallet ...
获取兑换交易数据

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 solana
Data handoff:
  • tokenContractAddress
    from step 1 →
    --to
    in steps 2-3
  • SOL native address =
    11111111111111111111111111111111
    --from
    . Do NOT use wSOL address.
  • Amount
    1 SOL
    =
    1000000000
    (9 decimals) →
    --amount
    param
用户需求:"在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获取的
    tokenContractAddress
    → 步骤2-3的
    --to
    参数
  • SOL原生地址
    11111111111111111111111111111111
    --from
    参数,不要使用wSOL地址
  • 金额
    1 SOL
    =
    1000000000
    (9位小数) →
    --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 xlayer
Key: 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) → swap
1. 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 tx
1. 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 tx
1. 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 (
    --chain xlayer
    , low gas, fast confirmation) as the default, then ask which chain the user prefers
  • Missing token addresses → use
    opentrade-token
    opentrade token search
    to resolve name → address
  • 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(
    --chain xlayer
    ,低gas、确认快),再询问用户偏好的公链
  • 缺少代币地址 → 使用
    opentrade-token
    opentrade token search
    功能将代币名称解析为地址
  • 缺少金额 → 询问用户,提醒需转换为最小单位
  • 缺少滑点设置 → 建议默认1%,波动率高的代币建议3-5%
  • 缺少钱包地址 → 询问用户

Step 3: Execute

步骤3:执行操作

  • Quote phase: call
    opentrade swap quote
    , display estimated results
    • Expected output, gas estimate, price impact, routing path
    • Check
      isHoneyPot
      and
      taxRate
      — surface safety info to users
  • Confirmation phase: wait for user approval before proceeding
  • Approval phase (EVM only): check/execute approve if selling non-native token
  • Execution phase: call
    opentrade swap swap
    , return tx data for signing
  • 报价阶段:调用
    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 completedSuggest
swap quote
(not yet confirmed)
1. View price chart before deciding →
opentrade-market
2. Proceed with swap → continue approve + swap (this skill)
Swap executed successfully1. Check price of the token just received →
opentrade-market
2. Swap another token → new swap flow (this skill)
swap liquidity
1. Get a swap quote →
opentrade swap quote
(this skill)
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个相关的后续操作:
刚完成操作建议操作
swap quote
(尚未确认兑换)
1. 决策前查看价格走势 →
opentrade-market
2. 继续兑换流程 → 执行授权+兑换(本技能)
兑换成功1. 查看刚到账代币的价格 →
opentrade-market
2. 兑换其他代币 → 开启新的兑换流程(本技能)
swap liquidity
1. 获取兑换报价 →
opentrade swap quote
(本技能)
采用对话式表述,例如:"兑换完成!你需要查看更新后的余额吗?" —— 永远不要向用户暴露技能名称或端点路径。

CLI Command Reference

CLI命令参考

1. opentrade swap chains

1. opentrade swap chains

Get supported chains for DEX aggregator. No parameters required.
bash
opentrade swap chains
Return fields:
FieldTypeDescription
chainIndex
StringChain identifier (e.g.,
"1"
,
"501"
)
chainName
StringHuman-readable chain name
dexTokenApproveAddress
StringDEX router address for token approvals on this chain
获取DEX聚合器支持的公链列表,无参数要求。
bash
opentrade swap chains
返回字段
字段类型描述
chainIndex
String公链标识符(例如
"1"
"501"
chainName
String易读的公链名称
dexTokenApproveAddress
String该公链上用于代币授权的DEX路由器地址

2. opentrade swap liquidity

2. opentrade swap liquidity

Get available liquidity sources on a chain.
bash
opentrade swap liquidity --chain <chain>
ParamRequiredDefaultDescription
--chain
Yes-Chain name (e.g.,
ethereum
,
solana
,
xlayer
)
Return fields:
FieldTypeDescription
id
StringLiquidity source ID
name
StringLiquidity source name (e.g.,
"Uniswap V3"
,
"CurveNG"
)
logo
StringLiquidity source logo URL
获取指定公链上可用的流动性来源。
bash
opentrade swap liquidity --chain <chain>
参数是否必填默认值描述
--chain
-公链名称(例如
ethereum
solana
xlayer
返回字段
字段类型描述
id
String流动性来源ID
name
String流动性来源名称(例如
"Uniswap V3"
"CurveNG"
logo
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>
ParamRequiredDefaultDescription
--token
Yes-Token contract address to approve
--amount
Yes-Amount in minimal units
--chain
Yes-Chain name
Return fields:
FieldTypeDescription
data
StringApproval calldata (hex) — use as tx
data
field
dexContractAddress
StringSpender address (already encoded in
data
). NOT the tx
to
— send tx to the token contract
gasLimit
StringEstimated gas limit for the approval tx
gasPrice
StringRecommended gas price
获取ERC-20授权交易数据。
bash
opentrade swap approve --token <address> --amount <amount> --chain <chain>
参数是否必填默认值描述
--token
-待授权的代币合约地址
--amount
-授权金额(最小单位)
--chain
-公链名称
返回字段
字段类型描述
data
String授权calldata(十六进制)—— 作为交易的
data
字段
dexContractAddress
String被授权地址(已编码在
data
中)。不是交易的
to
地址,交易需发送到代币合约地址
gasLimit
String授权交易的预估gas limit
gasPrice
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>]
ParamRequiredDefaultDescription
--from
Yes-Source token contract address
--to
Yes-Destination token contract address
--amount
Yes-Amount in minimal units (sell amount if exactIn, buy amount if exactOut)
--chain
Yes-Chain name
--swap-mode
No
exactIn
exactIn
or
exactOut
Return fields:
FieldTypeDescription
toTokenAmount
StringExpected output amount in minimal units
fromTokenAmount
StringInput amount in minimal units
estimateGasFee
StringEstimated gas fee (native token units)
tradeFee
StringTrade fee estimate in USD
priceImpactPercent
StringPrice impact as percentage (e.g.,
"0.05"
)
router
StringRouter type used
dexRouterList[]
ArrayDEX routing path details
dexRouterList[].dexName
StringDEX name in the route
dexRouterList[].percentage
StringPercentage of amount routed through this DEX
fromToken.isHoneyPot
Boolean
true
= source token is a honeypot (cannot sell)
fromToken.taxRate
StringSource token buy/sell tax rate
fromToken.decimal
StringSource token decimals
fromToken.tokenUnitPrice
StringSource token unit price in USD
toToken.isHoneyPot
Boolean
true
= destination token is a honeypot (cannot sell)
toToken.taxRate
StringDestination token buy/sell tax rate
toToken.decimal
StringDestination token decimals
toToken.tokenUnitPrice
StringDestination token unit price in USD
获取兑换报价(只读价格预估)。
bash
opentrade swap quote --from <address> --to <address> --amount <amount> --chain <chain> [--swap-mode <mode>]
参数是否必填默认值描述
--from
-源代币合约地址
--to
-目标代币合约地址
--amount
-金额(最小单位,exactIn模式为卖出金额,exactOut模式为买入金额)
--chain
-公链名称
--swap-mode
exactIn
exactIn
exactOut
返回字段
字段类型描述
toTokenAmount
String预期到账金额(最小单位)
fromTokenAmount
String输入金额(最小单位)
estimateGasFee
String预估gas费(原生代币单位)
tradeFee
String预估交易手续费(USD计价)
priceImpactPercent
String价格影响百分比(例如
"0.05"
router
String使用的路由器类型
dexRouterList[]
ArrayDEX路由路径详情
dexRouterList[].dexName
String路径中包含的DEX名称
dexRouterList[].percentage
String该DEX路由的资金占比
fromToken.isHoneyPot
Boolean
true
表示源代币是蜜罐代币(无法卖出)
fromToken.taxRate
String源代币的买卖税率
fromToken.decimal
String源代币的小数位数
fromToken.tokenUnitPrice
String源代币的单位价格(USD计价)
toToken.isHoneyPot
Boolean
true
表示目标代币是蜜罐代币(无法卖出)
toToken.taxRate
String目标代币的买卖税率
toToken.decimal
String目标代币的小数位数
toToken.tokenUnitPrice
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>]
ParamRequiredDefaultDescription
--from
Yes-Source token contract address
--to
Yes-Destination token contract address
--amount
Yes-Amount in minimal units
--chain
Yes-Chain name
--wallet
Yes-User's wallet address
--slippage
No
"1"
Slippage tolerance in percent (e.g.,
"1"
for 1%)
--swap-mode
No
"exactIn"
exactIn
or
exactOut
Return fields:
FieldTypeDescription
routerResult
ObjectSame structure as quote return (see swap quote above)
tx.from
StringSender address
tx.to
StringContract address to send the transaction to
tx.data
StringTransaction calldata (hex for EVM, base58 for Solana)
tx.gas
StringGas limit for the transaction
tx.gasPrice
StringGas price
tx.value
StringNative token value to send (in minimal units)
tx.minReceiveAmount
StringMinimum receive amount after slippage (minimal units)
tx.maxSpendAmount
StringMaximum spend amount (for exactOut mode)
tx.slippagePercent
StringApplied slippage tolerance percentage
获取兑换交易数据(报价→签名→广播)。
bash
opentrade swap swap --from <address> --to <address> --amount <amount> --chain <chain> --wallet <address> [--slippage <pct>] [--swap-mode <mode>]
参数是否必填默认值描述
--from
-源代币合约地址
--to
-目标代币合约地址
--amount
-金额(最小单位)
--chain
-公链名称
--wallet
-用户的钱包地址
--slippage
"1"
滑点容忍度百分比(例如
"1"
表示1%)
--swap-mode
"exactIn"
exactIn
exactOut
返回字段
字段类型描述
routerResult
Object和报价接口返回结构一致(参考上述swap quote返回)
tx.from
String发送方地址
tx.to
String交易的目标合约地址
tx.data
String交易calldata(EVM链为十六进制,Solana为base58)
tx.gas
String交易的gas limit
tx.gasPrice
Stringgas price
tx.value
String发送的原生代币金额(最小单位)
tx.minReceiveAmount
String滑点扣除后的最小到账金额(最小单位)
tx.maxSpendAmount
String最大花费金额(exactOut模式下使用)
tx.slippagePercent
String实际使用的滑点容忍度百分比

Input / Output Examples

输入输出示例

User says: "Swap 100 USDC for OKB on XLayer"
bash
undefined
用户需求: "在XLayer链上将100 USDC兑换为OKB"
bash
undefined

1. 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来源

undefined
undefined

Edge Cases

边缘情况处理

  • High slippage (>5%): warn user, suggest splitting the trade or adjusting slippage
  • Large price impact (>10%): strongly warn, suggest reducing amount
  • Honeypot token:
    isHoneyPot = true
    — block trade and warn user
  • Tax token:
    taxRate
    non-zero — display to user (e.g. 5% buy tax)
  • 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
    11111111111111111111111111111111
    (system program), NOT
    So11111111111111111111111111111111111111112
    (wSOL)
  • 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
    —— 阻止交易并警告用户
  • 税率代币
    taxRate
    非零 —— 向用户展示税率(例如5%买入税)
  • 余额不足:先查询余额,展示当前余额,建议调整交易金额
  • exactOut模式不支持:仅Ethereum/Base/BSC/Arbitrum支持该模式,提示用户使用
    exactIn
    模式
  • Solana原生SOL地址:必须使用
    11111111111111111111111111111111
    (系统程序),不要使用
    So11111111111111111111111111111111111111112
    (wSOL)
  • 网络错误:重试一次,仍失败则提示用户稍后再试
  • 地域限制(错误码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
  • minReceiveAmount
    in both UI units and USD
  • Price impact as percentage
  • 面向用户展示的输入/输出金额使用UI单位(
    1.5 ETH
    3,200 USDC
  • CLI内部参数使用最小单位(
    1 USDC
    =
    "1000000"
    1 ETH
    =
    "1000000000000000000"
  • Gas费使用USD计价展示
  • minReceiveAmount
    同时展示UI单位和USD计价
  • 价格影响使用百分比展示

Global Notes

全局注意事项

  • Amounts must be in minimal units (wei/lamports)
  • exactOut
    only on Ethereum(
    1
    )/Base(
    8453
    )/BSC(
    56
    )/Arbitrum(
    42161
    )
  • Check
    isHoneyPot
    and
    taxRate
    — surface safety info to users
  • 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)
  • exactOut
    模式仅支持Ethereum(
    1
    )/Base(
    8453
    )/BSC(
    56
    )/Arbitrum(
    42161
    )
  • 检查
    isHoneyPot
    taxRate
    ,向用户披露安全信息
  • EVM合约地址必须全小写
  • CLI会自动解析公链名称(例如
    ethereum
    1
    solana
    501
  • CLI通过环境变量内部处理身份认证,默认值参考前置检查第4步