Onchain Atlas

Hooks

Small custom pieces of code that plug into an AMM pool's lifecycle and let developers change how swaps, fees, or liquidity behave without forking the whole exchange.

Also called: AMM hooks · pool plugins · programmable pool logic

What it is

Hooks are a plugin architecture for automated market makers (AMMs) that let developers attach custom smart contract logic to specific moments in a pool's life — before or after a swap, before or after liquidity is added or removed, and so on — instead of having to modify or fork the core AMM code. Rather than every new idea (dynamic fees, on-chain limit orders, custom oracles) requiring a brand-new exchange, hooks let a single, audited core AMM support many different pool behaviors as add-on modules.

How it works

  1. When a liquidity pool is created, its creator optionally specifies a hook contract address along with which lifecycle events that hook should be called for (e.g., "before swap" and "after add liquidity").
  2. The core AMM contract enforces, at the protocol level, that the specified hook functions are called at the right point in every relevant transaction — the hook can't be skipped once the pool is configured to use it.
  3. Before a swap executes, a beforeSwap hook can run custom logic: for example, adjusting the fee dynamically based on volatility, blocking the trade under certain conditions, or pulling in an external price feed.
  4. After a swap, an afterSwap hook might redirect a portion of the output, trigger a limit-order fill, or update some on-chain state the hook contract is tracking.
  5. Similar hook points exist around liquidity provision and removal, letting pools implement things like time-locked liquidity, custom LP reward structures, or automatic rebalancing.
  6. Because hooks are separate, permissionless contracts, anyone can write and deploy one, and pool creators choose which hook (if any) to attach — the core AMM stays lean and battle-tested while innovation happens in the hook layer.

Why designers use it

  • Lets developers build new AMM features (dynamic fees, on-chain limit orders, MEV protection, custom oracles) without redeploying or forking the underlying exchange contract.
  • Keeps the security-critical core AMM logic small, stable, and reusable across many different pool behaviors, reducing the audit surface for the base protocol.
  • Enables permissionless experimentation: anyone can deploy a new hook and a new pool using it, without needing protocol governance approval.
  • Allows pools to be tailored to specific asset pairs or use cases (e.g., stablecoin pairs, volatile pairs, RWA tokens) with logic suited to that pair's actual risk profile.

Failure modes

  • Malicious or buggy hooks: because hooks are external, permissionless contracts, a poorly written or intentionally malicious hook attached to a pool can drain funds, brick swaps, or manipulate pricing — the core AMM's safety doesn't guarantee hook safety.
  • False sense of security: users may assume "it's built on a well-audited AMM" means the pool is safe, without realizing the attached hook is unaudited or newly deployed.
  • Composability confusion: routers and aggregators that don't specifically account for a given hook's behavior may mis-simulate trades, leading to unexpected slippage or failed transactions.
  • Centralization of hook logic: if a hook has an upgradeable or admin-controlled component, the "permissionless pool" can secretly have a privileged party who can change fee logic or block trades after the fact.
  • Gas overhead: chaining multiple hook calls into every swap adds execution cost, which can make hook-enabled pools noticeably more expensive to use than simple, hook-free pools.

What to check before using it

  • Read (or have audited) the specific hook contract attached to a pool before providing liquidity or trading — the core AMM's reputation does not extend to third-party hooks.
  • Check whether the hook is upgradeable or has an admin key, and if so, understand what that key can do to your funds or the pool's behavior.
  • Verify whether the router or interface you're using correctly simulates the hook's effect on price and fees, to avoid surprise slippage.
  • Look at how long the hook has been live and whether it's been used by other pools without incident, as a rough proxy for battle-testing.
  • Confirm gas costs for hook-enabled swaps are acceptable for your expected trade sizes, since added logic increases per-transaction cost.

Experiments that used it · 2

Shown oldest first, so you can watch the design evolve.

Uniswap
The first widely adopted constant-product automated market maker, replacing order books with permissionless x*y=k liquidity pools on Ethereum.
2018 major success
Uniswap V4 Hooks
A programmable AMM architecture that lets developers attach custom smart-contract logic ('hooks') to liquidity pools at key lifecycle points, turning Uniswap from a fixed AMM into an extensible platform.
2025 major success