V4HOOKSCUT SHEET DIRECTORY

Index / TWAMM

pattern · UNLICENSED · last updated 2026-08-27

TWAMM

Execute large orders over time by settling virtual TWAMM flow before each swap and LP change.

Uniswap’s example TWAMM hook runs executeTWAMMOrders in beforeInitialize, beforeAddLiquidity, and beforeSwap so long-lived orders accrue between blocks and settle against the pool instead of dumping in one swap. Permissions must enable those three callbacks. The rest of the file (order storage, expiration) lives in the linked Solidity — copy the full contract from v4-periphery example-contracts, do not ship this excerpt. The example is UNLICENSED research code, not production. Confirm bytecode on hooklist if you route size. 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

beforeInitializebeforeAddLiquiditybeforeSwap

Solidity

Excerpt from contracts/hooks/examples/TWAMM.sol. Copy the full file to implement this. Not an audit.

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

function beforeAddLiquidity(address, PoolKey calldata key, IPoolManager.ModifyLiquidityParams calldata, bytes calldata)
    external
    override
    onlyByManager
    returns (bytes4)
{
    executeTWAMMOrders(key);
    return BaseHook.beforeAddLiquidity.selector;
}

function beforeSwap(address, PoolKey calldata key, IPoolManager.SwapParams calldata, bytes calldata)
    external
    override
    onlyByManager
    returns (bytes4, BeforeSwapDelta, uint24)
{
    executeTWAMMOrders(key);
    return (BaseHook.beforeSwap.selector, BeforeSwapDeltaLibrary.ZERO_DELTA, 0);
}

Spec

Kindpattern
Statusexperimental
LicenseUNLICENSED
Sourcehttps://github.com/Uniswap/v4-periphery
CategoriesTWAMM
PropertiesVanilla swapCustom swap data
ChainsEthereum
Docshttps://blog.uniswap.org/v4-twamm-hook

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.