V4HOOKSCUT SHEET DIRECTORY

Index / BaseHook

pattern · MIT · last updated 2026-08-27

BaseHook

Inherit this, declare permissions, gate callbacks with onlyPoolManager.

Start every custom Uniswap v4 hook from OpenZeppelin’s BaseHook (MIT). PoolManager only calls functions whose bits are set in the hook address. BaseHook stores the PoolManager, reverts NotPoolManager unless msg.sender is that singleton, and routes each IHooks entrypoint to an internal _callback that reverts HookNotImplemented until you override it. getHookPermissions must match those overrides or constructor validation fails. Flip the bits you need, implement the matching _beforeSwap (or other) function, and keep return-delta flags in sync. Listing is not an audit. The library is experimental — still run the secure-hooks checklist before you ship.

Permission bits

These bits must match the deployed address. Confirm on-chain before you route.

Initialize
ba
Liquidity
baba
Swap
ba
Donate
ba
Return delta
baaa

beforeSwap

Solidity

Excerpt from src/base/BaseHook.sol. Copy the full file to implement this. Not an audit.

// SPDX-License-Identifier: MIT
// OpenZeppelin Uniswap Hooks — excerpt. Full file: source.url
abstract contract BaseHook is IHooks {
    IPoolManager public immutable poolManager;
    error HookNotImplemented();
    error NotPoolManager();

    constructor(IPoolManager _poolManager) {
        poolManager = _poolManager;
        _validateHookAddress(this);
    }

    modifier onlyPoolManager() {
        if (msg.sender != address(poolManager)) revert NotPoolManager();
        _;
    }

    function getHookPermissions() public pure virtual returns (Hooks.Permissions memory permissions);

    function beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)
        external
        onlyPoolManager
        returns (bytes4, BeforeSwapDelta, uint24)
    {
        return _beforeSwap(sender, key, params, hookData);
    }

    function _beforeSwap(address, PoolKey calldata, SwapParams calldata, bytes calldata)
        internal
        virtual
        returns (bytes4, BeforeSwapDelta, uint24)
    {
        revert HookNotImplemented();
    }
}

Spec

Kindpattern
Statusexperimental
LicenseMIT
Sourcehttps://github.com/OpenZeppelin/uniswap-hooks
CategoriesWrappers
PropertiesVanilla swap
ChainsEthereum
Websitehttps://v4hooks.com/learn/openzeppelin-hooks
Docshttps://github.com/OpenZeppelin/uniswap-hooks

FAQ

Can I paste this into production? The snippet is an excerpt. Use the full file at the source URL, match flags to the address, and treat this page as a map, not a guarantee.

How do I build this safely? Start with secure v4 hooks and the OpenZeppelin hooks guide.