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.

23 stars

Best use case

uniswap-swap-simulation is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

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.

Teams using uniswap-swap-simulation should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/uniswap-swap-simulation/SKILL.md --create-dirs "https://raw.githubusercontent.com/jiayaoqijia/cryptoskill/main/skills/defi/uniswap-swap-simulation/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/uniswap-swap-simulation/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How uniswap-swap-simulation Compares

Feature / Agentuniswap-swap-simulationStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

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.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# 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:

```typescript
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

```typescript
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:

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

## Multi-hop Routing

For tokens without direct pools, route through intermediary tokens:

```typescript
// 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

Related Skills

okx-dex-swap

23
from jiayaoqijia/cryptoskill

Use this skill to 'swap tokens', 'trade OKB for USDC', 'buy tokens', 'sell tokens', 'exchange crypto', 'convert tokens', 'swap SOL for USDC', 'get a swap quote', 'execute a trade', 'find the best swap route', 'cheapest way to swap', 'optimal swap', 'compare swap rates', '换币', '买币', '卖币', '兑换', '交易', '代币兑换', '最优路径', '滑点', or mentions swapping, trading, buying, selling, or exchanging tokens on XLayer, Solana, Ethereum, Base, BSC, Arbitrum, Polygon, or any of 20+ supported chains. Aggregates liquidity from 500+ DEX sources for optimal routing and price. Supports slippage control, price impact protection, and cross-DEX route optimization. Do NOT use for questions about HOW TO implement, code, or integrate swaps into an application — only for actually executing swap operations. Do NOT use for analytical questions about historical swap volume. Do NOT use when the user says only a single word like 'swap' or 'trade' without specifying tokens, amounts, or any other context.

ethy-swap-agent

23
from jiayaoqijia/cryptoskill

Intelligent on-chain swap and trade execution agent optimized for the most reliable and smoothest swapping experience on Base.

uniswap-v4

23
from jiayaoqijia/cryptoskill

Swap tokens and read pool state on Uniswap V4 (Base, Ethereum). Use when the agent needs to: (1) swap ERC20 tokens or ETH via Uniswap V4, (2) get pool info (price, tick, liquidity, fees), (3) find the best pool for a token pair, (4) quote expected swap output via the on-chain V4Quoter, (5) set up Permit2 approvals for the Universal Router, or (6) execute exact-input swaps with proper slippage protection. Supports Base and Ethereum mainnet, plus Base Sepolia testnet. TypeScript with strict types. Write operations need a private key via env var.

uniswap-v4-tools

23
from jiayaoqijia/cryptoskill

Tools for querying V4 pools, swap quotes, and hook-enabled liquidity pools.

uniswap-v4-pools

23
from jiayaoqijia/cryptoskill

Query and execute swaps on Uniswap V4 pools with hook-enabled custom logic and advanced pool configurations.

uniswap-v4-hooks

23
from jiayaoqijia/cryptoskill

Query and execute swaps on Uniswap V4 pools with custom hooks architecture.

uniswap-v4-agent

23
from jiayaoqijia/cryptoskill

Execute swaps and query pool info on Uniswap V4 with hooks support across Ethereum, Base, Arbitrum, and Optimism.

uniswap-v4-agent-hooks

23
from jiayaoqijia/cryptoskill

Toolkit for AI agents to interact with Uniswap V4 hooks and custom pool configurations.

uniswap-poolspy

23
from jiayaoqijia/cryptoskill

Track newly created Uniswap liquidity pools across 9 networks. Monitor new token listings and early liquidity events in real-time.

uniswap-pool-analysis

23
from jiayaoqijia/cryptoskill

Analyze Uniswap pool data including liquidity distribution, fee tiers, tick ranges, and TVL. Use when the user asks about pool metrics, liquidity analysis, or wants to query on-chain pool state.

swap-planner

23
from jiayaoqijia/cryptoskill

This skill should be used when the user asks to "swap tokens", "trade ETH for USDC", "exchange tokens on Uniswap", "buy tokens", "sell tokens", "convert ETH to stablecoins", "find memecoins", "discover tokens", "research tokens", "tokens to buy", "find tokens to swap", "what should I buy", or mentions swapping, trading, researching, discovering, buying, or exchanging tokens on any Uniswap-supported chain. Supports both known token swaps and token discovery workflows (discovery uses keyword search and web search — there is no live "trending" feed). Generates deep links to execute swaps in the Uniswap interface.

swap-integration

23
from jiayaoqijia/cryptoskill

Integrate Uniswap swaps into applications. Use when user says "integrate swaps", "uniswap", "trading api", "add swap functionality", "build a swap frontend", "create a swap script", "smart contract swap integration", "use Universal Router", "Trading API", or mentions swapping tokens via Uniswap.