uniswap-swap-simulation

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.

Safety Notice

This listing is from the official public ClawHub registry. Review SKILL.md and referenced scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "uniswap-swap-simulation" with this command: npx skills add wpank/uniswap-swap-simulation

Uniswap Swap Simulation

Overview

This skill covers simulating Uniswap swaps, calculating price impact, and analyzing routing decisions.

Key Concepts

  • Price Impact: The change in pool price caused by a swap. Larger swaps have higher impact.
  • Slippage: Difference between expected and executed price, including price movement between submission and execution.
  • Routing: Finding the optimal path across pools and protocols for best execution.

Simulating a Swap

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]

Price Impact Calculation

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);
}

Slippage Tolerance

  • Stablecoin pairs: 0.01% - 0.05%
  • Major pairs (ETH/USDC): 0.1% - 0.5%
  • Volatile pairs: 0.5% - 1.0%
  • Low liquidity: 1% - 5%

Calculate minimum amount out:

const minAmountOut = (amountOut * (10000n - BigInt(slippageBps))) / 10000n;

Multi-hop Routing

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],
});

Gas Estimation

Typical gas costs by swap complexity:

  • Single hop: ~130,000 gas
  • Two hops: ~200,000 gas
  • Three hops: ~270,000 gas

Always add a 15-20% buffer to gas estimates.

MEV Considerations

When building swap tools:

  • Recommend private RPCs (Flashbots Protect) for large swaps
  • Warn users about sandwich attack risk for high-impact swaps
  • Suggest using deadline parameters to limit exposure

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

Novel Workshop

多模型命题小说创作工坊。用户给出写作命题,自动完成:AI 写初稿 → 三路并行审阅(逻辑/文学/锐评)→ AI 改稿 → 飞书文档完整存档。 一键启动,全程自动,零手动干预。支持飞书实时进度推送。 触发词:命题写作、写一篇小说、命题小说、创作工坊、novel workshop

Registry SourceRecently Updated
General

Openclaw Commerce Shopify

Shopify store management through OpenClaw Commerce API

Registry SourceRecently Updated
General

Article Extract

提取微信公众号、博客、新闻等网页的正文内容,绕过反爬机制,纯文本输出。

Registry SourceRecently Updated
General

Compensation & Salary Benchmarking

Build competitive compensation plans using market data, salary bands, equity, bonuses, geographic pay adjustments, and retention risk scoring.

Registry SourceRecently Updated
68901kalin