Uniswap V4 Hooks

Uniswap V4 hooks are smart contracts that can be attached to individual Uniswap V4 liquidity pools, executing custom logic at specific points in the pool’s transaction lifecycle. A hook contract can intercept execution before and after a swap and before and after any liquidity change — returning control to the core pool contract after the custom logic completes. This gives anyone the ability to build entirely new AMM behaviors on top of Uniswap’s core settlement layer without forking the protocol: custom fee structures, on-chain TWAP-based orders, KYC-gated pools, MEV capture mechanisms, or novel pricing curves can all be implemented as hooks attached to V4 pools.


How It Works

Lifecycle Hook Points:

Uniswap V4 defines eight potential hook callback points, each of which a developer can optionally implement:

Hook Point When Triggered Example Use
beforeInitialize Before pool creation Validate pool parameters
afterInitialize After pool creation Set up oracle or initial state
beforeSwap Before any swap Check KYC, adjust fee, set price
afterSwap After any swap Capture MEV, send fees elsewhere
beforeAddLiquidity Before LP add Restrict LP to whitelisted addresses
afterAddLiquidity After LP add Issue receipt NFT, update accounting
beforeRemoveLiquidity Before LP remove Time-lock enforcement
afterRemoveLiquidity After LP remove Trigger external settlement

Permissions via Hook Address:

  • Rather than a mapping of hook permissions, V4 uses the hook contract’s address prefix to encode which callbacks it uses
  • The specific bit pattern in the contract address determines what callbacks are enabled
  • This is enforced by the PoolManager at pool creation — you cannot attach a hook that claims permissions it wasn’t designed to use

Return Values:

  • Hooks can return modified amounts (e.g., swap fee override)
  • The beforeSwap hook can return a BeforeSwapDelta to adjust what tokens enter/exit the swap
  • This allows a hook to implement a completely different pricing curve and return results to the pool

Notable Hook Use Cases

TWAMM (Time-Weighted Average Market Maker):

  • Spread a large trade over time without a keeper
  • beforeSwap hook intercepts each swap, calculates how many “virtual” long-term order lots have accumulated since last swap, settles them against real pool liquidity, then allows the triggering swap to proceed
  • Enables low-slippage execution of large trades without MEV exposure

On-Chain Limit Orders:

  • Store limit order intents in the hook contract’s storage
  • beforeSwap: check if current price has crossed any stored limit orders → execute them
  • Creates a native limit order book on top of Uniswap V4 without a separate off-chain order system

Dynamic Fees:

  • beforeSwap hook calculates a fee based on oracle data, volatility, or time-of-day
  • Returns the dynamic fee to the PoolManager, which applies it to the swap
  • Enables volatility-adjusted fees: lower fees in calm markets, higher fees during high-volatility periods

KYC / Permissioned Pools:

  • beforeSwap and beforeAddLiquidity check an on-chain identity registry
  • Reject swaps or LP actions from addresses that haven’t completed KYC
  • Enables compliant trading pools for institutional participants without a separate DEX

MEV Capture Hooks:

  • afterSwap hook detects profitable arbitrage conditions
  • Captures the MEV in the hook’s own logic and returns proceeds to the pool or veUNI holders
  • Could route MEV profits to LPs directly rather than to external searchers

Key Concepts

Term Definition
Hook contract The smart contract implementing custom logic the pool calls
PoolManager Uniswap V4’s core singleton contract managing all pool state
Hook permissions Which callback points the hook uses, encoded in its address
Singleton All V4 pools live in one PoolManager contract (unlike V3 per-pool contracts)
ERC-6909 Multi-token standard for representing V4 LP positions and balances
Flash accounting V4 uses transient storage for in-flight balance tracking, enabling hook chains

History

  • June 2023: Uniswap V4 whitepaper released; hook architecture introduced publicly
  • 2023–2024: Community hook development begins; hackathons produce early hook demos
  • 2024: Uniswap V4 mainnet launch on Ethereum; hooks ecosystem goes live
  • 2024: First production hooks deployed — TWAMM, dynamic fee, and liquidity restriction hooks

Common Misconceptions

“Hooks can modify core pool math.”

Hooks can influence what enters and exits a swap (via BeforeSwapDelta return values) but cannot override the core invariant math of the pool’s underlying AMM. A hook implementing a completely different curve can do so by intercepting the full swap, but it must implement the accounting itself — the core pool won’t apply a different AMM formula just because a hook asks.

“Any hook can be attached to any V4 pool.”

Hooks are specified at pool creation and are immutable — a pool is permanently bound to its hook address. You cannot add or change a hook on an existing pool.


Criticisms

  • Security risk amplification: Hooks are arbitrary smart contracts attached to every swap and LP event — a malicious or buggy hook can drain user funds or cause unexpected behavior for every transaction in the pool
  • Composability complexity: Chained hook interactions (e.g., a swap routed through multiple pools each with different hooks) create complex interaction surfaces difficult to reason about
  • User trust requirement: Users must trust the hook contract in any pool they use — unlike V3 where all pools use identical core math, V4 pools with custom hooks have custom, user-auditable-but-not-necessarily-audited logic
  • Audit burden: Every hook is a custom contract that requires independent auditing; the proliferation of hooks could outpace audit capacity

Social Media Sentiment

Uniswap V4 and hooks generated significant excitement among DeFi developers. Hackathon projects immediately explored TWAMM, on-chain order books, and creator-economy hooks (e.g., “only wallets holding a specific NFT can LP in this pool”). Concerns from security researchers centered on the user trust implications. Among end users, hooks are mostly invisible — the UX impact is through better pricing, limit orders, or novel pool behaviors that emerge from the ecosystem.


Last updated: 2026-04

Related Terms


Sources

  1. Uniswap V4 Whitepaper — Uniswap Labs (June 2023). Original V4 design document introducing hooks, the singleton PoolManager, ERC-6909, and flash accounting.
  1. Uniswap V4 Developer Documentation — docs.uniswap.org/v4. Full technical documentation covering hook implementation guides, permission encoding via address, and example hook code.
  1. “TWAMM: Time-Weighted Average Market Maker” — Paradigm Research (2021). Original TWAMM paper describing virtual order settlement and long-term order mechanics — the concept later implemented as a V4 hook.
  1. “Security Considerations for Uniswap V4 Hooks” — OpenZeppelin Research (2024). Analysis of hook attack vectors — including malicious hooks, reentrancy via hook callbacks, and gas griefing — with recommended mitigations and user guidance.
  1. Uniswap V4 Audit Reports — ABDK Consulting and Trail of Bits (2024). Independent security audits of the PoolManager singleton and hook interaction model.