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.
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
| Kind | pattern |
|---|---|
| Status | experimental |
| License | MIT |
| Source | https://github.com/CryptoGnome/v4hooks |
| Categories | Compliance |
| Properties | Vanilla swap |
| Chains | Ethereum |
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.