Skip to content
Monpediaby Unity Nodes
Monad Docsguides › uniswap v4 hooks

Build with Uniswap v4 Hooks

From docs.monad.xyz/guides/uniswap-v4-hooksUpdated Nov 19, 2026read Nov 19, 2026

Contents4 sections

Build, test, and deploy custom Uniswap v4 pool behavior on Monad with Foundry.

Uniswap v4 hooks let you add custom logic to liquidity pools. In this guide, you will build and deploy a Counter hook on Monad Testnet, create a pool with two mock tokens, and run swaps that trigger its callbacks.

What are hooks?

Uniswap v4 stores pools in a shared contract called the PoolManager. A hook is a separate smart contract that the manager calls at selected points in a pool's lifecycle:

Operation Callbacks
Initialize a pool beforeInitialize, afterInitialize
Add liquidity beforeAddLiquidity, afterAddLiquidity
Remove liquidity beforeRemoveLiquidity, afterRemoveLiquidity
Swap beforeSwap, afterSwap
Donate to liquidity providers beforeDonate, afterDonate

You choose the hook when initializing a pool. Its address is part of the PoolKey, alongside the two currencies, fee, and tick spacing. Changing the hook address creates a different pool identity; it does not update an existing pool. One hook can serve multiple pools, so pool-specific state should be keyed by PoolId.

Hooks execute synchronously within the transaction. They do not run on a timer: scheduled strategies also need transactions from users or automation. See Uniswap's hooks overview and core contracts.

Common use cases

Use case Example behavior
Launch controls Reject swaps before a launch time or restrict who can add initial liquidity.
Dynamic fees Adjust swap fees based on pool activity or market conditions.
Limit orders and scheduled execution Execute an order when a swap reaches a target price. Time-based strategies still need an external transaction to trigger execution.
LP incentives and analytics Track liquidity changes and swaps to calculate rewards or collect pool statistics.

Testnet walkthrough

The example project contains the hook, Foundry scripts, and tests. It uses contracts already deployed on Monad Testnet (chain ID 10143):

Contract Purpose
PoolManager Stores pool state and calls the hook.
PositionManager Adds and removes liquidity; issues a position NFT to your account.
UniversalRouter Executes swaps.
Permit2 Handles token approvals and transfers for the router and position manager.
V4Quoter and StateView Quote swaps and read pool state.

Anyone can use these testnet contracts. Their addresses are in shared-infrastructure.json at the root of the example project. The PoolManager and periphery addresses differ from Uniswap’s official mainnet deployments.

You deploy your own hook and two mock tokens. The mock tokens are publicly mintable and have no monetary value.

Follow the guide

Follow the pages in order, running commands from the same monad-hook directory.

Setup

Clone the pinned example and its submodules, install Node dependencies, run local tests, and prepare a testnet account.

Deploy

Deploy the Counter hook and two mock tokens.

Pool lifecycle

Initialize a pool, mint an owned PositionManager NFT, swap through Universal Router, remove liquidity, and revoke approvals.

Customize and publish

Change the hook’s behavior and prepare it for mainnet.