V4HOOKSCUT SHEET DIRECTORY

Index / AllowlistSwap

pattern · MIT · last updated 2026-08-27

AllowlistSwap

Gate-controlled per-pool swap allowlist; beforeSwap reverts for unlisted traders.

First-party teaching hook inspired by Uniswap Permissioned Pools. An immutable gate address sets allowed[poolId][trader]. beforeSwap resolves the trader from hookData (abi.encode address) or the swap sender and reverts Unauthorized if not listed. No permissions-adapter stack — minimal allowlist gate only. Experimental. Forge tests in test/AllowlistSwap.t.sol. 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

beforeSwap

Solidity

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

// SPDX-License-Identifier: MIT
function _beforeSwap(address sender, PoolKey calldata key, SwapParams calldata, bytes calldata hookData)
    internal view override returns (bytes4, BeforeSwapDelta, uint24)
{
    address trader = traderOf(sender, hookData);
    if (!allowed[key.toId()][trader]) revert Unauthorized();
    return (this.beforeSwap.selector, BeforeSwapDeltaLibrary.ZERO_DELTA, 0);
}

Spec

Kindpattern
Statusexperimental
LicenseMIT
Sourcehttps://github.com/CryptoGnome/v4hooks
CategoriesCompliance
PropertiesVanilla swap
ChainsEthereum

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.