V4HOOKSCUT SHEET DIRECTORY

Index / BaseDynamicFee

pattern · MIT · last updated 2026-08-27

BaseDynamicFee

Set the pool LP fee afterInitialize, then poke updateDynamicLPFee when conditions change.

OpenZeppelin’s BaseDynamicFee (MIT) is the smallest dynamic-fee building block. afterInitialize reverts unless key.fee is the dynamic-fee flag, then calls poolManager.updateDynamicLPFee with _getFee(key). Inherit it, implement _getFee, and call _poke from a guarded keeper path when you want to refresh. Permissions are afterInitialize only — this does not override a per-swap fee in beforeSwap. Experimental library code. Copy the full file including the NotDynamicFee revert. Listing is not an audit.

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

afterInitialize

Solidity

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Uniswap Hooks — excerpt. Full file: source.url
function _getFee(PoolKey calldata key) internal virtual returns (uint24);

function _afterInitialize(address, PoolKey calldata key, uint160, int24)
    internal
    virtual
    override
    returns (bytes4)
{
    if (!key.fee.isDynamicFee()) revert NotDynamicFee();
    poolManager.updateDynamicLPFee(key, _getFee(key));
    return this.afterInitialize.selector;
}

function _poke(PoolKey calldata key) internal virtual {
    poolManager.updateDynamicLPFee(key, _getFee(key));
}

function getHookPermissions() public pure virtual override returns (Hooks.Permissions memory permissions) {
    return Hooks.Permissions({
        beforeInitialize: false,
        afterInitialize: true,
        beforeAddLiquidity: false,
        afterAddLiquidity: false,
        beforeRemoveLiquidity: false,
        afterRemoveLiquidity: false,
        beforeSwap: false,
        afterSwap: false,
        beforeDonate: false,
        afterDonate: false,
        beforeSwapReturnDelta: false,
        afterSwapReturnDelta: false,
        afterAddLiquidityReturnDelta: false,
        afterRemoveLiquidityReturnDelta: false
    });
}

Spec

Kindpattern
Statusexperimental
LicenseMIT
Sourcehttps://github.com/OpenZeppelin/uniswap-hooks
CategoriesDynamic fees
PropertiesDynamic feeVanilla 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.