Uniswap 执行交换:自动化加密货币交易 - Openclaw Skills

作者:互联网

2026-03-26

AI教程

什么是 Uniswap 代币交换代理技能?

Uniswap 执行交换技能是为 Openclaw Skills 生态系统内的 AI 代理设计的尖端技术模块。它允许开发者和用户弥合自然语言命令与复杂去中心化金融操作之间的鸿沟。通过处理代币地址解析、流动性路由和交易模拟等繁重工作,它将“将 USDC 兑换为 ETH”等简单请求转化为安全的链上执行。

该技能以安全优先的理念构建,整合了飞行前安全验证,在移动任何资产之前检查支出限制和熔断机制。无论您是在构建个人交易助手还是复杂的自动化金库管理器,Openclaw Skills 的这一组件都为可靠的多链代币交换提供了必要的基础设施。

下载入口:https://github.com/openclaw/skills/tree/main/skills/wpank/execute-swap

安装与下载

1. ClawHub CLI

从源直接安装技能的最快方式。

npx clawhub@latest install execute-swap

2. 手动安装

将技能文件夹复制到以下位置之一

全局模式 ~/.openclaw/skills/ 工作区 /skills/

优先级:工作区 > 本地 > 内置

3. 提示词安装

将此提示词复制到 OpenClaw 即可自动安装。

请帮我使用 Clawhub 安装 execute-swap。如果尚未安装 Clawhub,请先安装(npm i -g clawhub)。

Uniswap 代币交换代理技能 应用场景

  • 在支持的链上交换 USDC、WETH 和数千种其他代币资产。
  • 根据特定的价格触发器或调仓策略执行自动化交易。
  • 使用 UniswapX 和原生协议执行跨链安全路由。
  • 使用 Openclaw Skills 将专业级 DeFi 交易功能集成到自定义 AI 代理工作流中。
Uniswap 代币交换代理技能 工作原理
  1. 输入解析:该技能提取代币符号和链数据,并使用 search_tokens 工具将其解析为精确的合约地址。
  2. 安全验证:它对支出限制、速率限制和全局熔断状态执行强制性检查。
  3. 模拟:对交易进行模拟,以确保存在足够的流动性且价格影响在可接受范围内。
  4. 执行委托:请求被传递给专门的交易执行子代理,由其管理特定的路由逻辑 (V2/V3/V4/UniswapX)。
  5. 最终报告:该技能返回详细的细分报告,包括 Gas 成本、价格影响和交易哈希链接。

Uniswap 代币交换代理技能 配置指南

要将此功能集成到您的代理中,必须运行 Agentic Uniswap MCP 服务器。通过 npm 安装:

npm install -g @agentic-uniswap/mcp-server

确保您的环境变量已配置 Openclaw Skills 框架所需的相应 RPC 提供商和钱包凭据。

Uniswap 代币交换代理技能 数据架构与分类体系

该技能使用以下参数结构组织交换数据:

参数 描述 要求
tokenIn 源资产的符号或地址 必填
tokenOut 目标资产的符号或地址 必填
amount 要交换的数值数量 必填
chain 目标区块链(默认:ethereum) 可选
slippage 以百分比表示的最大价格偏差 可选
routing 对 V2, V3, V4 或 UniswapX 的偏好 可选
description: >-
  Execute a Uniswap token swap. Use when user wants to swap, trade, buy, or sell
  tokens. Handles quotes, safety checks, simulation, and execution autonomously.
  Supports V2, V3, V4, UniswapX, and cross-chain routing on all supported chains.
allowed-tools: >-
  Read, Glob, Grep,
  Task(subagent_type:trade-executor),
  mcp__uniswap__get_supported_chains,
  mcp__uniswap__search_tokens,
  mcp__uniswap__check_safety_status
model: opus

Execute Swap

Execute a token swap on Uniswap with full safety validation.

Activation

Use this skill when the user says any of:

  • "Swap X for Y"
  • "Buy X with Y"
  • "Sell X for Y"
  • "Trade X for Y"
  • "Exchange X to Y"
  • "Convert X to Y"

Input Extraction

Extract these parameters from the user's message:

Parameter Required Default Source
tokenIn Yes Token name/symbol/address
tokenOut Yes Token name/symbol/address
amount Yes Numeric value
chain No ethereum Chain name or context
slippage No 0.5% Explicit percentage
routing No auto "via V3", "use UniswapX", etc.

Workflow

  1. Validate inputs: Resolve token symbols using search_tokens. Confirm chain is supported.

  2. Pre-flight safety check: Call check_safety_status to verify:

    • Spending limits have room for this trade
    • Rate limits are not exhausted
    • Circuit breaker is not tripped
  3. Delegate to trade-executor: Launch Task(subagent_type:trade-executor) with:

    • tokenIn, tokenOut, amount, chain
    • slippageTolerance (in bps)
    • routingPreference (auto/v2/v3/v4/uniswapx)
  4. Report result to the user in a clear format:

Swap Executed Successfully

  Input:  500.00 USDC
  Output: 0.1538 WETH ($499.55)
  Price:  1 WETH = $3,248.04
  Impact: 0.01%
  Gas:    $0.42

  Tx: https://basescan.org/tx/0xABC...

  Safety: All 7 checks passed

Error Handling

Error User Message Suggested Action
SAFETY_SPENDING_LIMIT_EXCEEDED "This swap would exceed your $X daily limit." Reduce amount or wait
SAFETY_TOKEN_NOT_ALLOWED "TOKEN is not on your allowlist." Add to config
SAFETY_SIMULATION_FAILED "Swap simulation failed: [reason]." Check addresses, try smaller
INSUFFICIENT_LIQUIDITY "Not enough liquidity at acceptable slippage." Try smaller amount

MCP server dependency

This skill relies on Uniswap MCP tools for chain support lookup, token search, safety checks, and swap execution. When used in isolation (for example, from a skills catalog), ensure the Agentic Uniswap MCP server is running:

  • Repo: Agentic-Uniswap MCP server
  • Package: @agentic-uniswap/mcp-server