/uniswap-hooks:v4-hook-generatorfrom uniswap-hooks
Generates Uniswap v4 hook contracts via OpenZeppelin MCP. Guides selection of hook type, permissions, and utilities for custom swap logic, MEV protection, oracles, and more.
Ships in uniswap-hooks. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Generate Uniswap v4 hook contracts via the OpenZeppelin Contracts Wizard MCP tool. This skill guides you through selecting the right hook type, configuring permissions and utilities, assembling the canonical MCP JSON, and invoking the MCP tool to produce ready-to-compile Solidity code.
Security companion: Generated hook code touches fund-handling contracts. Always apply the
v4-security-foundationsskill immediately after generation to audit permissions, delta accounting, and access control before deploying to any network.
Use this skill when you need to:
Prerequisite / companion skill: v4-security-foundations — run it before writing custom logic
and again before deployment. Hook misconfiguration can drain user funds.
Choose the base hook type that matches your primary goal. If your hook has multiple goals, choose the type that covers the most critical concern and layer additional logic on top.
| Goal | Use Hook |
|---|---|
| Custom swap logic | BaseHook |
| Async/delayed swaps | BaseAsyncSwap |
| Hook-owned liquidity | BaseCustomAccounting |
| Custom curve | BaseCustomCurve |
| Dynamic LP fees | BaseDynamicFee |
| Dynamic swap fees | BaseOverrideFee |
| Post-swap fees | BaseDynamicAfterFee |
| Fixed hook fees | BaseHookFee |
| MEV protection | AntiSandwichHook |
| JIT protection | LiquidityPenaltyHook |
| Limit orders | LimitOrderHook |
| Yield on idle | ReHypothecationHook |
| Oracle | BaseOracleHook |
| V3-compatible oracle | OracleHookWithV3Adapters |
Selection tips:
BaseHook is the general-purpose starting point — choose a specialized type only when the
built-in logic provides concrete value.BaseCustomCurve replaces the entire AMM math; only use it if you are implementing a novel
pricing algorithm.AntiSandwichHook and LiquidityPenaltyHook both address MEV but target different actors
(traders vs. JIT LPs). Clarify which attack vector you are mitigating.OracleHookWithV3Adapters is appropriate when downstream integrations expect a Uniswap v3
IUniswapV3Pool-compatible oracle interface.Before calling the MCP tool, confirm all six decisions:
beforeSwap, afterSwap, etc.)currencySettler, safeCast, transientStorage as neededfalse, ERC20, ERC6909, or ERC1155ownable, roles, or managedblockNumberOffset, maxAbsTickDelta (only for hook types that use them)All 14 permission flags with guidance on when to enable each. Start with all flags false and
enable only what your hook logic requires. Every enabled permission increases the hook's attack
surface and requires a specific bit to be set in the hook's deployed address (see address encoding
note below).
| Permission Flag | Enable When | Risk |
|---|---|---|
beforeInitialize | You need to validate or restrict pool creation params | LOW |
afterInitialize | You need to set up state after a pool is created | LOW |
beforeAddLiquidity | You need to gate or transform LP deposits | MEDIUM |
afterAddLiquidity | You track LP positions or distribute rewards | LOW |
beforeRemoveLiquidity | You need lock-up periods or fee-on-exit logic | HIGH |
afterRemoveLiquidity | You track position removals for accounting | LOW |
beforeSwap | You modify swap behavior, apply dynamic fees, or block | HIGH |
afterSwap | You observe final swap state for oracles or accounting | MEDIUM |
beforeDonate | You restrict who may donate to the pool | LOW |
afterDonate | You track donation events | LOW |
beforeSwapReturnDelta | You implement custom AMM curves or JIT liquidity (CRITICAL: NoOp attack vector — see v4-security-foundations) | CRITICAL |
afterSwapReturnDelta | You extract a hook fee from swap output | HIGH |
afterAddLiquidityReturnDelta | You adjust LP token amounts on deposit | HIGH |
afterRemoveLiquidityReturnDelta | You adjust withdrawal amounts | HIGH |
Address encoding note: Permissions are encoded as bits in the hook contract's deployed address.
The address must have the correct bits set at deployment time or the PoolManager will revert. Use
HookMiner (from v4-periphery) to mine a salt that produces an address with the correct bit
pattern. Never change permissions after deployment — the address is immutable.
Three optional utility libraries can be included in the generated hook. Include only what your hook logic uses.
| Library | Include When |
|---|---|
currencySettler | Your hook moves tokens between itself and the PoolManager (e.g., custom accounting, fee collection) |
safeCast | Your hook performs arithmetic that could overflow when casting between integer types |
transientStorage | Your hook needs to pass data between callbacks within a single transaction without persisting to storage (requires EVM Cancun or later, Solidity >= 0.8.24) |
Guidance:
currencySettler is almost always needed when beforeSwapReturnDelta,
afterSwapReturnDelta, afterAddLiquidityReturnDelta, or afterRemoveLiquidityReturnDelta
are enabled — it provides settle and take helpers that implement the correct
sync → transfer → settle sequence.transientStorage is a gas-efficient alternative to storage slots for intra-transaction state.
Use it to pass a flag or value from beforeSwap to afterSwap without paying 20k gas for a
cold SSTORE.safeCast is advisable whenever you compute amounts derived from int256/uint256 conversions,
especially for fee calculations.The shares option controls whether the generated hook issues a token representing user shares
(e.g., LP positions in hook-owned liquidity pools).
| Option | Description | Use When |
|---|---|---|
false | No share token — hook does not track ownership of deposited assets | Simple hooks that do not hold user funds |
ERC20 | Fungible share token — one token represents proportional ownership of all hook-held assets | Hook-managed liquidity pools with interchangeable shares |
ERC6909 | Multi-token (minimal) — one contract manages many token IDs with lower overhead than ERC1155 | Hook manages multiple distinct asset classes efficiently |
ERC1155 | Multi-token (standard) — full ERC1155 with metadata URI support | Hook needs broad wallet and marketplace compatibility |
Trade-offs:
false: smallest bytecode, no share accounting overhead; appropriate for fee hooks and oracles.ERC20: simplest fungible share; good DeFi composability (e.g., used as collateral).ERC6909: gas-efficient multi-token with a minimal interface; preferred for new protocol designs.ERC1155: widest ecosystem support (wallets, explorers, NFT marketplaces); higher gas cost per
transfer than ERC6909.The access option shapes the constructor and administrative interface of the generated hook.
| Option | Constructor Shape | Use When |
|---|---|---|
ownable | constructor(IPoolManager, address initialOwner) | Single owner controls all admin functions |
roles | constructor(IPoolManager, address admin) | Multiple roles with granular permissions (OpenZeppelin AccessControl) |
managed | constructor(IPoolManager, address authority) | External authority contract governs permissions (OpenZeppelin AccessManaged) |
Guidance:
ownable is the simplest — one address can perform all privileged operations. Suitable for
early-stage hooks and personal tools.roles adds ADMIN_ROLE, PAUSER_ROLE, etc. via OpenZeppelin AccessControl. Use when
different team members need different privileges (e.g., a keeper bot that can update fees but
cannot upgrade the contract).managed delegates all permission checks to a separate AccessManager contract. Use when
you need a unified governance layer across multiple contracts or want timelocked admin actions.Note: Changing the
accessoption changes the constructor signature. Update deployment scripts and initialization logic accordingly. When usingownable, ensure theinitialOwneris not the zero address — OpenZeppelin'sOwnablereverts on zero address since v5.
Some hook types accept numeric configuration inputs that tune behavior. These are passed as the
inputs object in the MCP tool call.
| Input | Type | Used By | Description |
|---|---|---|---|
blockNumberOffset | uint256 | AntiSandwichHook, LiquidityPenaltyHook | Number of blocks before sandwich/JIT detection window opens |
maxAbsTickDelta | int24 | AntiSandwichHook | Maximum tick movement allowed per block before MEV protection triggers |
For hook types that do not use these inputs, omit the inputs field or pass an empty object {}.
Passing unsupported inputs to the MCP tool will not cause an error but the values will be ignored.
The OpenZeppelin Contracts Wizard exposes a generate_hook MCP tool. The following is the
canonical JSON schema — populate each field according to your decisions from the sections above,
then pass this object as the tool's argument.
{
"hook": "BaseHook",
"name": "MyHook",
"pausable": false,
"currencySettler": true,
"safeCast": true,
"transientStorage": false,
"shares": { "options": false },
"permissions": {
"beforeInitialize": false,
"afterInitialize": false,
"beforeAddLiquidity": false,
"beforeRemoveLiquidity": false,
"afterAddLiquidity": false,
"afterRemoveLiquidity": false,
"beforeSwap": true,
"afterSwap": false,
"beforeDonate": false,
"afterDonate": false,
"beforeSwapReturnDelta": false,
"afterSwapReturnDelta": false,
"afterAddLiquidityReturnDelta": false,
"afterRemoveLiquidityReturnDelta": false
},
"inputs": {
"blockNumberOffset": 1,
"maxAbsTickDelta": 100
},
"access": "ownable",
"info": { "license": "MIT" }
}
Field notes:
hook: string — one of the 14 hook types from the decision tablename: string — the Solidity contract name (PascalCase, no spaces)pausable: boolean — wraps the hook in OpenZeppelin Pausable; adds pause()/unpause() admin functionsshares.options: false | "ERC20" | "ERC6909" | "ERC1155"access: "ownable" | "roles" | "managed"info.license: SPDX license identifier — use "MIT" for open-source hooksinputs: omit or pass {} for hook types that do not use blockNumberOffset/maxAbsTickDeltaFollow these steps in order every time you use this skill.
Ask the user (or infer from context):
currencySettler and shares.)transientStorage.)Using the decision table, identify the single best hook type. If the user's goal maps to multiple types, explain the trade-offs and ask them to confirm. Document the chosen type and the reasoning.
Work through the minimal decision checklist:
hook to the chosen type.false, enable only what the logic requires.currencySettler, safeCast, transientStorage based on utility library guidance.shares.options based on shares guidance.access based on access control guidance.inputs only if the hook type uses blockNumberOffset or maxAbsTickDelta.Construct the JSON object from Step 3 and call the OpenZeppelin Contracts Wizard MCP tool with it. The tool returns Solidity source code — it does not write files automatically.
After receiving the generated code:
getHookPermissions, enabled callbacks).access is roles or managed).Always remind the user — and invoke v4-security-foundations — before the code is deployed:
msg.sender == address(poolManager).*ReturnDelta permissions for NoOp attack exposure.v4-security-foundations.ownable adds an initialOwner parameter;
roles adds an admin parameter; managed adds an authority parameter. Update deployment
scripts and factory contracts accordingly.HookMiner from v4-periphery to mine a deployment salt that produces a
matching address.packages/contracts/src/hooks/MyHook.sol).v4-security-foundations — Run this after generation. Security audit for Uniswap v4 hooks:
permission risk matrix, NoOp attack patterns, delta accounting, access control verification,
and the full pre-deployment audit checklist. Generated hook code should never be deployed without
completing this review.viem-integration — Deploy generated hook contracts and interact with them using viem/wagmiv4-sdk-integration — Interact with deployed hooks via the Uniswap v4 SDKWhat SKILL.md sets; muted values are Claude Code's defaults
opusThree short reads, in order
uniswap-v4, hook-generator, solidity, ethereum, openzeppelin, smart-contracts
2 skills in this plugin
npx claudepluginhub uniswap/uniswap-ai --plugin uniswap-hooksOther plugins' skills for the same job