uniswap

Implement Uniswap V3 and V4 swaps, liquidity positions, and hooks using viem and Solidity.

6|20|Updated Mar 14, 2026
One-click install
npx skills add https://github.com/andresdefi/cryptoskills --skill uniswap-andresdefi
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: uniswap
Source: https://github.com/andresdefi/cryptoskills/tree/main/skills/uniswap
Command: npx skills add https://github.com/andresdefi/cryptoskills --skill uniswap-andresdefi

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires viem, @uniswap/v3-sdk, @uniswap/sdk-core, @uniswap/universal-router-sdk.

What problem does it solve? AI agents frequently produce outdated or incorrect Uniswap integration code — confusing V2/V3/V4 patterns, mishandling sqrtPriceX96 price math, using deprecated routers, or hallucinating contract addresses — which can cause failed transactions or lost funds. This Skill provides verified contract addresses, correct V3/V4 integration patterns, and production-ready code examples. ## Core Features & Use Cases - Swap Execution: Exact input/output swaps via SwapRouter02 and UniversalRouter, multi-hop path encoding, quoting with QuoterV2, and slippage protection across Ethereum, Arbitrum, Base, and Optimism. - Concentrated Liquidity Management: Mint, increase, decrease, and collect fees on V3 positions via NonfungiblePositionManager with correct tick alignment and price conversion math. - V4 Hook Development: Build, mine addresses for, deploy, and test custom V4 hooks (dynamic fees, volume tracking, access control) using Foundry and the PoolManager singleton. - Use Case: An agent asked to "swap 1 WETH for USDC with 0.5% slippage" can quote via QuoterV2, compute amountOutMinimum, approve the correct spender, and execute through SwapRouter02 — all with verified addresses and error handling. ## Quick Start Ask the agent to swap 1 WETH for USDC on Ethereum mainnet with 0.5% slippage tolerance using the Uniswap V3 SwapRouter02.

Frequently Asked Questions about uniswap

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I swap tokens on Uniswap V3 with viem?

Call exactInputSingle on SwapRouter02 (0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45) with tokenIn, tokenOut, fee tier, amountIn, and amountOutMinimum. Quote first with QuoterV2, then apply slippage tolerance to compute amountOutMinimum before executing.

What is the difference between Uniswap V3 and V4 pool architecture?

V3 deploys one contract per pool via a factory, while V4 uses a singleton PoolManager holding all pools identified by a PoolKey (currency0, currency1, fee, tickSpacing, hooks). V4 also supports hook contracts that customize behavior at swap and liquidity lifecycle points.

How do I convert sqrtPriceX96 to a readable token price?

Compute price as (sqrtPriceX96 / 2^96)^2, then adjust for token decimal differences by multiplying by 10^(decimals0 - decimals1). Always verify token ordering by reading pool.token0(), since the numerically smaller address is token0.

Why does my Uniswap swap revert with STF or allowance errors?

STF means the token transfer into the pool failed due to insufficient balance or missing approval. Approve the correct spender: SwapRouter02 for direct swaps, or Permit2 (0x000000000022D473030F116dDEE9F6B43aC78BA3) when using UniversalRouter, capped at uint160 max.

How do I deploy a Uniswap V4 hook with the correct address?

Hook addresses must encode enabled callback flags in their leading bits. Use HookMiner.find with CREATE2 to mine a salt producing an address matching your getHookPermissions flags, deploy the hook at that address, then initialize the pool referencing it.

Which Uniswap V3 fee tier should I use for a token pair?

Use 100 (0.01%) for stablecoin pairs, 500 (0.05%) for major pairs like WETH/USDC, 3000 (0.3%) for standard pairs, and 10000 (1%) for volatile or exotic tokens. Query the factory's getPool across all tiers to find where liquidity exists.