Uniswap is the backbone of DeFi. Over $2 trillion in cumulative trading volume has flowed through its contracts. But despite its dominance, Uniswap's architecture has always been relatively rigid: pools have fixed fee tiers, no on-chain logic beyond the core AMM, and no way to customize behavior without deploying an entirely separate protocol.

Uniswap v4, launched in January 2025, changes everything with a single architectural innovation: hooks. Hooks allow developers to attach custom smart contract logic to pool lifecycle events โ€” swaps, liquidity additions and removals, and pool initialization โ€” without forking Uniswap or building a separate DEX.

TL;DR: Uniswap v4 introduces hooks (custom contracts that execute at pool events) and a singleton architecture (all pools in one contract). Together, these enable TWAP oracles, dynamic fees, on-chain limit orders, MEV protection, KYC-gated pools, and dozens of other features โ€” all composable and permissionless.

The Uniswap Version History

v1
ETH-only pairs
Separate contracts
Manual routing
v2
ERC-20/ERC-20 pairs
TWAP oracle built-in
Flash swaps
v3
Concentrated liquidity
Multiple fee tiers
NFT LP positions
v4 โœฆ
Hooks system
Singleton contract
Dynamic fees
Flash accounting

What Are Hooks? The Core Innovation

A hook is a smart contract that a pool deployer specifies at creation time. Uniswap v4 calls into this contract at specific moments during pool operations, allowing arbitrary logic to execute before or after each action. If no hook is specified, the pool behaves exactly like Uniswap v3.

There are eight hook points, each with a "before" and "after" variant:

beforeInitialize / afterInitialize

Pool Creation Hooks

Execute custom logic when a new pool is deployed. Use cases: KYC checks, initial liquidity requirements, whitelist validation.

beforeSwap / afterSwap

Swap Hooks

The most powerful hook points. Execute before and after every swap. Use cases: dynamic fees, MEV protection, TWAP updates, referral tracking.

beforeAddLiquidity / afterAddLiquidity

Liquidity Add Hooks

Trigger on LP deposits. Use cases: LP token rewards, liquidity caps, anti-manipulation logic, emissions distribution.

beforeRemoveLiquidity / afterRemoveLiquidity

Liquidity Remove Hooks

Trigger on LP withdrawals. Use cases: time-locks on liquidity, withdrawal fees, auto-compounding on exit.

The hook address itself encodes which hooks are enabled using a clever address prefix system โ€” the leading bits of the hook contract address determine which callbacks Uniswap v4 will invoke, eliminating the need for a separate registry.

The Singleton Architecture: One Contract to Rule All Pools

In Uniswap v2 and v3, every pool is a separate smart contract. This means cross-pool swaps require external calls between contracts, increasing gas costs significantly. Uniswap v4 moves all pools into a single contract โ€” the PoolManager.

This enables a new pattern called flash accounting: instead of performing token transfers after every swap, the PoolManager tracks a "delta" (net balance change) for each token across an entire transaction. At the end of the transaction, only the net amounts are transferred, not intermediate amounts.

// Simplified Uniswap v4 Hook Interface interface IHooks { // Called before every swap โ€” can modify fee or block the swap function beforeSwap( address sender, PoolKey calldata key, IPoolManager.SwapParams calldata params, bytes calldata hookData ) external returns (bytes4 selector, BeforeSwapDelta delta, uint24 lpFeeOverride); // Called after swap โ€” receives actual amounts in/out function afterSwap( address sender, PoolKey calldata key, IPoolManager.SwapParams calldata params, BalanceDelta delta, bytes calldata hookData ) external returns (bytes4 selector, int128 hookDeltaUnspecified); }

What Hooks Enable: Real Use Cases

1. Dynamic Fees

v3 pools have fixed fee tiers (0.01%, 0.05%, 0.3%, 1%). With v4 hooks, fees can adjust dynamically based on volatility, time of day, pool utilization, or any on-chain signal. A hook could implement fees that increase during high-volatility periods (protecting LPs from impermanent loss) and decrease during calm markets (attracting more volume).

2. On-Chain Limit Orders

The afterSwap hook can check if a price target has been crossed and automatically execute limit orders stored in the hook contract. This brings CEX-style limit order functionality directly into an AMM without centralized infrastructure.

3. MEV Protection

A beforeSwap hook can implement time-weighted average price protection, commit-reveal schemes, or batch auction mechanics to protect users from sandwich attacks and other forms of MEV extraction.

4. TWAP Oracles

While v2 had TWAP oracles built-in and v3 improved them, v4 hooks allow custom oracle implementations with arbitrary accumulation logic โ€” useful for exotic price feeds, manipulation-resistant oracles, or cross-asset TWAPs.

5. Compliance and KYC Pools

A hook can check whether a user's wallet has passed KYC verification (via Polygon ID, WorldID, or similar) before allowing a swap. This enables compliant DeFi pools that only allow verified users โ€” a requirement many institutional participants need before entering DeFi.

Hooks are to Uniswap what the App Store was to the iPhone. We've built the infrastructure. Now thousands of teams will build things we haven't imagined yet. The AMM becomes a platform.

โ€” Hayden Adams, Uniswap founder, Devcon 7

Gas Cost Improvements

The singleton + flash accounting architecture delivers substantial gas savings on multi-hop swaps. A three-hop swap in v3 requires three separate contract calls and up to six token transfers. In v4, the same swap requires one contract interaction and two token transfers (the net inputs and outputs).

Benchmark results from Uniswap Labs show:

For Developers: The Uniswap v4 Hook Foundry Template provides a complete starting point for hook development, including test fixtures and deployment scripts. The hooks ecosystem is already thriving with 200+ experimental hooks on GitHub within weeks of mainnet launch.

Risks and Considerations

Hooks introduce new risks. A malicious or buggy hook contract could drain pool funds, block swaps, or manipulate prices. Users should:

The Bottom Line

Uniswap v4 is the most significant upgrade to AMM architecture since concentrated liquidity in v3. Hooks transform Uniswap from a fixed protocol into a programmable platform โ€” one where the DEX itself becomes customizable infrastructure rather than a black box.

For developers, this is an extraordinary opportunity: build novel financial primitives on top of the most liquid on-chain venue in DeFi, without forking the entire protocol. The hooks ecosystem is just getting started, and the best applications likely haven't been built yet.