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.

MIT-0 · Free to use, modify, and redistribute. No attribution required.
0 · 689 · 0 current installs · 0 all-time installs
MIT-0
Security Scan
VirusTotalVirusTotal
Benign
View report →
OpenClawOpenClaw
Benign
high confidence
Purpose & Capability
Name/description (Uniswap swap simulation) matches the SKILL.md content: examples of using the Quoter contract, price impact/slippage calculations, routing and gas estimates. Nothing requested is unrelated to on-chain swap simulation.
Instruction Scope
The SKILL.md stays on-topic and only describes reading on-chain data (Quoter reads, pricing math, routing). It recommends using private RPCs / Flashbots for execution considerations, but it does not instruct reading unrelated system files or environment secrets. One omission: it presumes a web3/RPC client (viem + an RPC URL) but does not document how/where to provide that RPC endpoint or credentials.
Install Mechanism
Instruction-only skill (no install spec, no code files to execute). README shows suggested install commands that fetch the skill from a GitHub path or a registry, which is typical; the skill itself will not download or run arbitrary archives.
Credentials
The skill declares no required environment variables or credentials, which is proportional. Practically, users will need an RPC endpoint (and optionally private RPC/Flashbots credentials) to run live queries — these are not declared. The skill does not request private keys or unrelated cloud credentials.
Persistence & Privilege
Skill is user-invocable and not always-enabled. It does not request persistent system-level privileges, does not modify other skills' configs, and does not demand permanent presence.
Assessment
This skill appears to be what it says: a Uniswap swap-simulation guide. Before installing or using it, verify the source URL (the README references a GitHub path) and ensure you do not supply private keys to the skill. You will need an Ethereum RPC endpoint (and optionally private RPC/Flashbots credentials) to run live simulations — those credentials are not declared by the skill, so supply them only to trusted tooling. If you plan to install via the provided npx commands, inspect that remote repo first to confirm there are no unexpected install scripts. If you only need offline guidance or the math examples, no credentials are required.

Like a lobster shell, security has layers — review code before you run it.

Current versionv0.1.0
Download zip
latestvk97d6hvj2x2v20pnvkr0c2tx9s80wfg1

License

MIT-0
Free to use, modify, and redistribute. No attribution required.

SKILL.md

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

Files

2 total
Select a file
Select a file to preview.

Comments

Loading comments…