OpenZeppelin Uniswap Hooks
Modular Solidity hooks and base contracts for Uniswap v4 from OpenZeppelin.
OpenZeppelin Uniswap Hooks is a Solidity library of secure, modular building blocks for Uniswap v4 hooks. It bundles base contracts, ready-to-use hooks, and utilities so teams can ship custom pool extensions on top of audited primitives.
This library is maintained by OpenZeppelin and is not an official Uniswap Labs product. It is provided as is, without warranties of any kind, including backward compatibility. Pin and audit any version used in production, and review release notes before upgrading.
What it provides
- Base implementations for custom accounting, async swaps, and custom curves
- Fee management contracts such as
BaseDynamicFeeto update LP fees programmatically - Ready-to-use hooks such as sandwich protection
- Utilities and libraries for common hook development patterns
Installation
forge install OpenZeppelin/uniswap-hooksAdd the remapping to remappings.txt:
@openzeppelin/uniswap-hooks/=lib/uniswap-hooks/src/Quick start
The example below uses BaseDynamicFee together with Ownable to let an owner update the LP fee at runtime.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
import {BaseDynamicFee, IPoolManager, PoolKey} from "src/fee/BaseDynamicFee.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
/**
* @dev A hook that allows the owner to dynamically update the LP fee.
*/
contract DynamicLPFeeHook is BaseDynamicFee, Ownable {
uint24 public fee;
constructor(IPoolManager _poolManager) BaseDynamicFee(_poolManager) Ownable(msg.sender) {
}
/**
* @inheritdoc BaseDynamicFee
*/
function _getFee(PoolKey calldata) internal view override returns (uint24) {
return fee;
}
/**
* @notice Sets the LP fee, denominated in hundredths of a bip.
*/
function setFee(uint24 _fee) external onlyOwner {
fee = _fee;
}
}BaseDynamicFee.poke() is publicly callable. If your fee logic depends on external conditions, restrict access or design _getFee to resist short-term manipulation.