uniswap

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

1|1|Updated May 21, 2026
One-click install
npx skills add https://github.com/naruto11eth/cryptoskills --skill uniswap-naruto11eth
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: uniswap
Source: https://github.com/naruto11eth/cryptoskills/tree/main/skills/uniswap
Command: npx skills add https://github.com/naruto11eth/cryptoskills --skill uniswap-naruto11eth

SYSTEM DOCUMENTATION & REQUIREMENTS

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: Create, increase, decrease, and collect fees from V3 positions via NonfungiblePositionManager with correct tick alignment and price 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 on Base" can use the verified SwapRouter02 address for Base, quote via QuoterV2, apply 0.5% slippage tolerance, and execute with proper Permit2 approvals — avoiding deprecated routers and zero-slippage pitfalls. ## Quick Start Ask the agent to swap 1 WETH for USDC on Uniswap V3 with 0.5% slippage tolerance using the verified SwapRouter02 contract.

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 a slippage tolerance such as 0.5% to compute amountOutMinimum.

What is the difference between Uniswap V3 and V4 pools?▼

V3 deploys one contract per pool identified by (token0, token1, fee), while V4 uses a singleton PoolManager holding all pools identified by a PoolKey. V4 also supports hooks — contracts attached at pool creation that run custom logic on swaps and liquidity changes.

How do I convert sqrtPriceX96 to a readable price?▼

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

Why does my Uniswap swap revert with STF or Too little received?▼

STF means the token transfer failed — check balance and that the router or Permit2 is approved. 'Too little received' means slippage exceeded amountOutMinimum; re-quote before executing and widen tolerance or use Flashbots Protect to avoid sandwich attacks.

Does UniversalRouter use normal ERC-20 approvals?▼

No. UniversalRouter requires tokens approved to the Permit2 contract (0x000000000022D473030F116dDEE9F6B43aC78BA3), not the router itself. Approve Permit2 once with a uint160 maximum, then sign gasless permits per transaction.

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

The hook address must encode its callback permissions in leading address bits. Use HookMiner.find from v4-periphery to mine a CREATE2 salt matching your flags, deploy the hook at that address, then initialize the pool referencing it.