uniswap
Installation
SKILL.md
Uniswap
Uniswap is the dominant on-chain DEX across Ethereum and L2s. V3 introduced concentrated liquidity — LPs allocate capital to specific price ranges instead of the full curve. V4 introduced a singleton PoolManager architecture with customizable hooks that modify pool behavior at every lifecycle point (swap, add/remove liquidity, donate).
What You Probably Got Wrong
AI agents trained before mid-2024 confuse V2, V3, and V4 patterns. These are the critical corrections.
- V3 concentrated liquidity is NOT V2 — V3 positions specify a
tickLowerandtickUpperprice range. Liquidity outside the current tick earns zero fees. There is no "full range" default. If you want full-range, you must explicitly set tickLower/tickUpper toMIN_TICK/MAX_TICK(which is capital-inefficient). sqrtPriceX96is not a price — V3/V4 store price assqrt(price) * 2^96, a Q64.96 fixed-point number. To get the human-readable price:(sqrtPriceX96 / 2^96)^2. You must also adjust for token decimal differences. Getting this wrong produces prices off by orders of magnitude.- Tick math uses
int24, notuint256— Ticks range from -887272 to 887272. Each tick represents a 0.01% price change. Tick spacing varies by fee tier: 1 (1bp), 10 (5bp), 60 (30bp), 200 (100bp). Positions must align to tick spacing boundaries. - V4 is a singleton — one contract holds all pools — Unlike V3 (one contract per pool), V4's
PoolManagerholds all pool state. Pools are identified by aPoolKey(currency0, currency1, fee, tickSpacing, hooks address), not by a contract address. There is no pool factory in V4. - V4 hooks are not optional middleware — Hooks are smart contracts attached to a pool at creation. The hook contract address encodes which callbacks it implements via specific bit flags in the leading bytes. You cannot add or remove hooks after pool creation.
- SwapRouter02 is the current V3 router, not SwapRouter — The original
SwapRouter(0xE592...) is deprecated. UseSwapRouter02(0x68b3...) which supports both V2 and V3 in a single interface. Even better: useUniversalRouterfor V3+V4+Permit2 in one transaction. - Fee tiers are in hundredths of a basis point — The fee parameter
3000means 0.30%, not 30%. Common tiers:100(0.01%),500(0.05%),3000(0.30%),10000(1.00%). - Permit2 replaces individual token approvals — Uniswap's UniversalRouter requires tokens to be approved to the Permit2 contract, not the router. You approve Permit2 once, then sign gasless permits per transaction.