Gate DEX Trade
Pure Routing Layer — Swap EXECUTION only. Every operation produces an on-chain transaction. All specifications in references/.
General Rules
⚠️ STOP — You MUST read and strictly follow the shared runtime rules before proceeding.
Do NOT select or call any tool until all rules are read. These rules have the highest priority.
→ Read gate-runtime-rules.md
Trigger Scenarios: Use when the user wants to execute a token exchange that modifies blockchain state:
- - Swap: "swap ETH for USDT", "exchange 100 USDC to DAI", "convert my BNB"
- Buy/Sell: "buy ETH", "sell my USDT", "purchase SOL"
- Cross-chain: "bridge ETH from Arbitrum to Base", "cross-chain swap"
- Swap quote: "how much USDT will I get for 1 ETH" (with intent to trade)
Project convention — MCP only (this workspace)
Do not use OpenAPI for swap unless user explicitly asks OpenAPI/AK/SK. MCP unavailable → references/setup.md only.
NOT this skill (common misroutes):
- - "what is the price of ETH" →
gate-dex-market (read-only lookup, no trade intent) - "check my swap history" →
gate-dex-wallet (account query) - "transfer ETH to 0xABC..." →
gate-dex-wallet (direct transfer, not swap) - "approve contract" (outside swap context) →
gate-dex-wallet (DApp interaction)
Routing Flow
CODEBLOCK0
Mode Dispatch
MCP Mode
Read and strictly follow references/mcp.md, execute according to its complete workflow.
Includes: connection detection, authentication (mcptoken), MCP Resource/tool calls (dex_tx_swap_quote / dex_tx_swap_prepare / dex_tx_swap_checkin_preview / staged sign-submit / dex_tx_swap_detail), local prebuilt swap-checkin-mac / swap-checkin-linux / swap-checkin-win.exe (Windows amd64) binary execution, token address resolution, nativein/native_out rules, three-step confirmation gateway (SOP), quote templates, risk warnings, cross-Skill collaboration, security rules.
OpenAPI Mode (Progressive Loading)
Default off in this workspace — explicit OpenAPI request only.
Limitation: OpenAPI mode only supports same-chain Swap, does not support cross-chain exchanges.
Load files progressively — only load what the current step needs:
- 1. Always load first:
references/openapi/_shared.md — env detection, credentials, API call method (via helper script) - Then load based on swap stage:
| Stage | Load File | When |
|---|
| Query (chain/gas) | openapi/quote.md | User asks about chains or gas |
| Swap: get quote |
openapi/quote.md +
openapi/sop.md | User initiates swap |
| Swap: build tx |
openapi/build.md | After quote confirmed (SOP Step 2) |
| Swap: sign tx |
openapi/sign.md | After build confirmed (SOP Step 3) |
| Swap: submit |
openapi/submit.md | After signing complete |
| History |
openapi/submit.md | User asks for swap history |
- 3. On error:
openapi/errors.md
Legacy monolithic file preserved at references/openapi.md for backward compatibility.
MCP Server Setup Guide
When MCP detection fails and a setup guide is needed, read and display references/setup.md. Show only the configuration for the user's current platform when identifiable. Display at most once per session.
Supported Chains
Actual supported chains are determined by runtime API/Resource returns:
- - MCP Mode:
swap://supported_chains Resource - OpenAPI Mode:
trade.swap.chain interface
For uncommon chains: MCP calls dex_chain_config, OpenAPI calls trade.swap.chain.
Security Rules
- 1. Three-step confirmation gateway: Trading pair confirmation → quote display → signature authorization — cannot be skipped
- Balance pre-check: Mandatory verification of asset and Gas token sufficiency before trading
- Risk warnings: Forced warning for exchange value difference > 5%, high slippage (> 5%) MEV attack warnings
- Authentication & credentials: Follow §3 of gate-runtime-rules.md; MCP uses
mcp_token, OpenAPI uses AK/SK — never mix - No OpenAPI fallback when MCP fails (this project)
Gate DEX 交易
纯路由层 — 仅执行交换操作。每个操作都会产生一笔链上交易。所有规范详见 references/。
通用规则
⚠️ 注意 — 在继续操作前,您必须阅读并严格遵守共享运行时规则。
在阅读完所有规则之前,请勿选择或调用任何工具。这些规则具有最高优先级。
→ 阅读 gate-runtime-rules.md
触发场景:当用户想要执行代币交换(修改区块链状态)时使用:
- - 交换:将 ETH 兑换为 USDT、将 100 USDC 兑换为 DAI、转换我的 BNB
- 买入/卖出:买入 ETH、卖出我的 USDT、购买 SOL
- 跨链:将 ETH 从 Arbitrum 桥接到 Base、跨链交换
- 交换报价:1 ETH 能换多少 USDT(带有交易意图)
项目约定 — 仅限 MCP(此工作区)
不要使用 OpenAPI 进行交换,除非用户明确要求使用 OpenAPI/AK/SK。MCP 不可用时 → 仅参考 references/setup.md。
不属于此技能(常见错误路由):
- - ETH 的价格是多少 → gate-dex-market(只读查询,无交易意图)
- 查看我的交换历史 → gate-dex-wallet(账户查询)
- 将 ETH 转账到 0xABC... → gate-dex-wallet(直接转账,非交换)
- 批准合约(非交换场景) → gate-dex-wallet(DApp 交互)
路由流程
text
用户触发交易意图
↓
步骤 1:用户是否明确指定了模式?
├─ 明确提到 OpenAPI / AK/SK / API Key → OpenAPI 模式
├─ 否则 → 仅 MCP(步骤 2)
└─ 未指定 → 步骤 2
↓
步骤 2:是否为跨链交换?
├─ 跨链 → 必须使用 MCP 模式(OpenAPI 不支持跨链),进入步骤 3
└─ 同链 / 不确定 → 步骤 3
↓
步骤 3:Gate 钱包 MCP 服务器发现与检测
a) 扫描已配置的 MCP 服务器列表,查找提供 dextxswapquote、dextxswapprepare 和阶段性交换签名工具的服务器
b) 如果找到 → 记录服务器标识符,通过以下方式验证:
CallMcpTool(server=, toolName=dexchainconfig, arguments={chain: ETH})
├─ 成功 → MCP 模式
└─ 失败 → 步骤 4
c) 未找到匹配的服务器 → 步骤 4
↓
步骤 4:MCP 不可用 → 仅提供设置指南(references/setup.md),不降级到 OpenAPI
模式分发
MCP 模式
阅读并严格遵守 references/mcp.md,按照其完整工作流程执行。
包括:连接检测、认证(mcptoken)、MCP 资源/工具调用(dextxswapquote / dextxswapprepare / dextxswapcheckinpreview / 阶段性签名提交 / dextxswapdetail)、本地预构建的 swap-checkin-mac / swap-checkin-linux / swap-checkin-win.exe(Windows amd64)二进制执行、代币地址解析、nativein/nativeout 规则、三步确认网关(SOP)、报价模板、风险警告、跨技能协作、安全规则。
OpenAPI 模式(渐进加载)
此工作区默认关闭 — 仅在明确请求 OpenAPI 时使用。
限制:OpenAPI 模式仅支持同链交换,不支持跨链交换。
按需渐进加载文件 — 仅加载当前步骤所需内容:
- 1. 始终首先加载:references/openapi/_shared.md — 环境检测、凭据、API 调用方法(通过辅助脚本)
- 然后根据交换阶段加载:
openapi/quote.md +
openapi/sop.md | 用户发起交换 |
| 交换:构建交易 |
openapi/build.md | 报价确认后(SOP 步骤 2) |
| 交换:签名交易 |
openapi/sign.md | 构建确认后(SOP 步骤 3) |
| 交换:提交 |
openapi/submit.md | 签名完成后 |
| 历史记录 |
openapi/submit.md | 用户询问交换历史 |
- 3. 出错时:openapi/errors.md
为向后兼容,保留旧版单一文件 references/openapi.md。
MCP 服务器设置指南
当 MCP 检测失败且需要设置指南时,读取并展示 references/setup.md。在可识别用户当前平台时,仅显示该平台的配置。每个会话最多展示一次。
支持的链
实际支持的链由运行时 API/资源返回决定:
- - MCP 模式:swap://supported_chains 资源
- OpenAPI 模式:trade.swap.chain 接口
对于不常见的链:MCP 调用 dexchainconfig,OpenAPI 调用 trade.swap.chain。
安全规则
- 1. 三步确认网关:交易对确认 → 报价展示 → 签名授权 — 不可跳过
- 余额预检查:交易前必须验证资产和 Gas 代币是否充足
- 风险警告:兑换价值差异 > 5% 时强制警告,高滑点(> 5%)MEV 攻击警告
- 认证与凭据:遵循 gate-runtime-rules.md 第 3 节;MCP 使用 mcptoken,OpenAPI 使用 AK/SK — 切勿混用
- MCP 失败时不降级到 OpenAPI(此项目)