$npx -y skills add Uniswap/uniswap-ai --skill v4-hook-generatorGenerate Uniswap v4 hook contracts via OpenZeppelin MCP. Use when building custom swap logic, async swaps, hook-owned liquidity, custom curves, dynamic fees, MEV protection, limit orders, or oracle hooks.
| 1 | # v4 Hook Generator |
| 2 | |
| 3 | Generate Uniswap v4 hook contracts via the OpenZeppelin Contracts Wizard MCP tool. This skill |
| 4 | guides you through selecting the right hook type, configuring permissions and utilities, assembling |
| 5 | the canonical MCP JSON, and invoking the MCP tool to produce ready-to-compile Solidity code. |
| 6 | |
| 7 | > **Security companion**: Generated hook code touches fund-handling contracts. Always apply the |
| 8 | > `v4-security-foundations` skill immediately after generation to audit permissions, delta |
| 9 | > accounting, and access control before deploying to any network. |
| 10 | |
| 11 | ## When to Use This Skill |
| 12 | |
| 13 | Use this skill when you need to: |
| 14 | |
| 15 | - Scaffold a new Uniswap v4 hook contract from scratch |
| 16 | - Select the right base hook type for a specific use case (fees, MEV protection, oracles, etc.) |
| 17 | - Configure hook permissions, utility libraries, shares, and access control |
| 18 | - Produce the canonical MCP tool call JSON to invoke the OpenZeppelin Contracts Wizard |
| 19 | - Understand trade-offs between hook configuration options before committing to an implementation |
| 20 | |
| 21 | **Prerequisite / companion skill**: `v4-security-foundations` — run it before writing custom logic |
| 22 | and again before deployment. Hook misconfiguration can drain user funds. |
| 23 | |
| 24 | ## Hook Type Decision Table |
| 25 | |
| 26 | Choose the base hook type that matches your primary goal. If your hook has multiple goals, choose |
| 27 | the type that covers the most critical concern and layer additional logic on top. |
| 28 | |
| 29 | | Goal | Use Hook | |
| 30 | | -------------------- | -------------------------- | |
| 31 | | Custom swap logic | `BaseHook` | |
| 32 | | Async/delayed swaps | `BaseAsyncSwap` | |
| 33 | | Hook-owned liquidity | `BaseCustomAccounting` | |
| 34 | | Custom curve | `BaseCustomCurve` | |
| 35 | | Dynamic LP fees | `BaseDynamicFee` | |
| 36 | | Dynamic swap fees | `BaseOverrideFee` | |
| 37 | | Post-swap fees | `BaseDynamicAfterFee` | |
| 38 | | Fixed hook fees | `BaseHookFee` | |
| 39 | | MEV protection | `AntiSandwichHook` | |
| 40 | | JIT protection | `LiquidityPenaltyHook` | |
| 41 | | Limit orders | `LimitOrderHook` | |
| 42 | | Yield on idle | `ReHypothecationHook` | |
| 43 | | Oracle | `BaseOracleHook` | |
| 44 | | V3-compatible oracle | `OracleHookWithV3Adapters` | |
| 45 | |
| 46 | **Selection tips**: |
| 47 | |
| 48 | - `BaseHook` is the general-purpose starting point — choose a specialized type only when the |
| 49 | built-in logic provides concrete value. |
| 50 | - `BaseCustomCurve` replaces the entire AMM math; only use it if you are implementing a novel |
| 51 | pricing algorithm. |
| 52 | - `AntiSandwichHook` and `LiquidityPenaltyHook` both address MEV but target different actors |
| 53 | (traders vs. JIT LPs). Clarify which attack vector you are mitigating. |
| 54 | - `OracleHookWithV3Adapters` is appropriate when downstream integrations expect a Uniswap v3 |
| 55 | `IUniswapV3Pool`-compatible oracle interface. |
| 56 | |
| 57 | ## Minimal Decision Checklist |
| 58 | |
| 59 | Before calling the MCP tool, confirm all six decisions: |
| 60 | |
| 61 | 1. **Hook type** — chosen from the decision table above |
| 62 | 2. **Permissions to enable** — only the callbacks your logic actually uses (`beforeSwap`, `afterSwap`, etc.) |
| 63 | 3. **Utility libraries** — `currencySettler`, `safeCast`, `transientStorage` as needed |
| 64 | 4. **Shares** — `false`, `ERC20`, `ERC6909`, or `ERC1155` |
| 65 | 5. **Access control** — `ownable`, `roles`, or `managed` |
| 66 | 6. **Hook inputs** — `blockNumberOffset`, `maxAbsTickDelta` (only for hook types that use them) |
| 67 | |
| 68 | ## Permission Configuration |
| 69 | |
| 70 | All 14 permission flags with guidance on when to enable each. Start with all flags `false` and |
| 71 | enable only what your hook logic requires. Every enabled permission increases the hook's attack |
| 72 | surface and requires a specific bit to be set in the hook's deployed address (see address encoding |
| 73 | note below). |
| 74 | |
| 75 | | Permission Flag | Enable When | Risk | |
| 76 | | --------------------------------- | --------------------------------------------------------------------------------------------------------------- | -------- | |
| 77 | | `beforeInitialize` | You need to validate or restrict pool creation params | LOW | |
| 78 | | `afterInitialize` | You need to set up state after a pool is created | LOW | |
| 79 | | `beforeAddLiquidity` | You need to gate or transform LP deposits | MEDIUM | |
| 80 | | `afterAddLiquidity` | You track LP positions or |