ASP源码
PHP源码
.NET源码
JSP源码
Uniswap 交易模拟技能为开发者提供了在不冒资金风险的情况下预测去中心化交易所交易结果的能力。通过与 Uniswap QuoterV2 合约交互,它能提供关于预期输出 额、价格影响和 Gas 费用的精确数据。作为 Openclaw Skills 生态系统的重要组成部分,它弥补了原始区块链数据与可操作交易情报之间的差距,从而实现更复杂的 DeFi 应用。
该技能专为需要评估交易效率的技术用户设计,考虑了流动性深度和路由复杂性等因素。它允许将专业级交易功能集成到任何 Agent 驱动的工作流中,确保用户在保持对常见链上风险的高度安全性的同时,能够优化获得最佳执行价格。
下载入口:https://github.com/openclaw/skills/tree/main/skills/wpank/uniswap-swap-simulation
从源直接安装技能的最快方式。
npx clawhub@latest install uniswap-swap-simulation
将技能文件夹复制到以下位置之一
全局模式~/.openclaw/skills/
工作区
/skills/
优先级:工作区 > 本地 > 内置
将此提示词复制到 OpenClaw 即可自动安装。
请帮我使用 Clawhub 安装 uniswap-swap-simulation。如果尚未安装 Clawhub,请先安装(npm i -g clawhub)。
要将此功能集成到您的环境中,请确保在 Openclaw Skills 设置中安装了必要的库:
npm install viem
初始化客户端和合约常量:
import { createPublicClient, http } from "viem";
import { mainnet } from "viem/chains";
const client = createPublicClient({
chain: mainnet,
transport: http(),
});
const quoterV2Address = "0x61fFE014bA17989E743c5F6cB21bF9697530B21e";
该技能利用结构化数据格式在 Openclaw Skills 框架内表示交易模拟和执行指标:
| 属性 | 描述 | 数据类型 |
|---|---|---|
| amountOut | 交易后预计收到的代币数量 | BigInt |
| priceImpact | 市场价格与执行价格之间的百分比差异 | Number |
| slippageBps | 允许的价格波动基点(例如 50 代表 0.5%) | Integer |
| path | 代表交易资金池序列的打包字节数组 | HexString |
| gasEstimate | 特定交易路径的预期 Gas 消耗量 | BigInt |
name: uniswap-swap-simulation
description: Simulate and analyze Uniswap swaps including price impact, slippage, optimal routing, and gas estimation. Use when the user asks about swap execution, routing, price impact, or MEV considerations.
This skill covers simulating Uniswap swaps, calculating price impact, and analyzing routing decisions.
Use the Quoter contract to simulate swaps without executing:
import { createPublicClient, http, encodeFunctionData } from "viem";
// QuoterV2 for v3 pools
const quote = await client.readContract({
address: quoterV2Address,
abi: quoterV2Abi,
functionName: "quoteExactInputSingle",
args: [
{
tokenIn,
tokenOut,
amountIn,
fee,
sqrtPriceLimitX96: 0n,
},
],
});
// Returns: [amountOut, sqrtPriceX96After, initializedTicksCrossed, gasEstimate]
function calculatePriceImpact(
amountIn: bigint,
amountOut: bigint,
marketPrice: number, // token1/token0
decimals0: number,
decimals1: number,
): number {
const executionPrice =
Number(amountOut) / 10 ** decimals1 / (Number(amountIn) / 10 ** decimals0);
return Math.abs(1 - executionPrice / marketPrice);
}
Calculate minimum amount out:
const minAmountOut = (amountOut * (10000n - BigInt(slippageBps))) / 10000n;
For tokens without direct pools, route through intermediary tokens:
// ETH -> USDC -> DAI (two hops)
const path = encodePacked(
["address", "uint24", "address", "uint24", "address"],
[WETH, 3000, USDC, 100, DAI],
);
const quote = await client.readContract({
address: quoterV2Address,
abi: quoterV2Abi,
functionName: "quoteExactInput",
args: [path, amountIn],
});
Typical gas costs by swap complexity:
Always add a 15-20% buffer to gas estimates.
When building swap tools: