uniswap/uniswap-ai/v4-hook-generator

Claude Code and agent skill by uniswap/uniswap-ai

Trust tier 2
  • community
LLM review pending
Source check pending

Checking that the SKILL.md file is still in the repository.

Generate 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.

Install

npx vskill@latest install uniswap/uniswap-ai/v4-hook-generator

SKILL.md

v4 Hook Generator

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-foundations skill immediately after generation to audit permissions, delta
accounting, and access control before deploying to any network.

When to Use This Skill

Use this skill when you need to:

  • Scaffold a new Uniswap v4 hook contract from scratch
  • Select the right base hook type for a specific use case (fees, MEV protection, oracles, etc.)
  • Configure hook permissions, utility libraries, shares, and access control
  • Produce the canonical MCP tool call JSON to invoke the OpenZeppelin Contracts Wizard
  • Understand trade-offs between hook configuration options before committing to an implementation

Prerequisite / companion skill: v4-security-foundations — run it before writing custom logic and again before deployment. Hook misconfiguration can drain user funds.

Hook Type Decision Table

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.

GoalUse Hook
Custom swap logicBaseHook
Async/delayed swapsBaseAsyncSwap
Hook-owned liquidityBaseCustomAccounting
Custom curveBaseCustomCurve
Dynamic LP feesBaseDynamicFee
Dynamic swap feesBaseOverrideFee
Post-swap feesBaseDynamicAfterFee
Fixed hook feesBaseHookFee
MEV protectionAntiSandwichHook
JIT protectionLiquidityPenaltyHook
Limit ordersLimitOrderHook
Yield on idleReHypothecationHook
OracleBaseOracleHook
V3-compatible oracleOracleHookWithV3Adapters

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.

Minimal Decision Checklist

Before calling the MCP tool, confirm all six decisions:

  1. Hook type — chosen from the decision table above
  2. Permissions to enable — only the callbacks your logic actually uses (beforeSwap, afterSwap, etc.)
  3. Utility libraries — currencySettler, safeCast, transientStorage as needed
  4. Shares — false, ERC20, ERC6909, or ERC1155
  5. Access control — ownable, roles, or managed
  6. Hook inputs — blockNumberOffset, maxAbsTickDelta (only for hook types that use them)

Permission Configuration

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 FlagEnable WhenRisk
beforeInitializeYou need to validate or restrict pool creation paramsLOW
afterInitializeYou need to set up state after a pool is createdLOW
beforeAddLiquidityYou need to gate or transform LP depositsMEDIUM
afterAddLiquidityYou track LP positions or distribute rewardsLOW
beforeRemoveLiquidityYou need lock-up periods or fee-on-exit logicHIGH
afterRemoveLiquidityYou track position removals for accountingLOW
beforeSwapYou modify swap behavior, apply dynamic fees, or blockHIGH
afterSwapYou observe final swap state for oracles or accountingMEDIUM
beforeDonateYou restrict who may donate to the poolLOW
afterDonateYou track donation eventsLOW
beforeSwapReturnDeltaYou implement custom AMM curves or JIT liquidity (CRITICAL: NoOp attack vector — see v4-security-foundations)CRITICAL
afterSwapReturnDeltaYou extract a hook fee from swap outputHIGH
afterAddLiquidityReturnDeltaYou adjust LP token amounts on depositHIGH
afterRemoveLiquidityReturnDeltaYou adjust withdrawal amountsHIGH

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.

Utility Library Selection

Three optional utility libraries can be included in the generated hook. Include only what your hook logic uses.

LibraryInclude When
currencySettlerYour hook moves tokens between itself and the PoolManager (e.g., custom accounting, fee collection)
safeCastYour hook performs arithmetic that could overflow when casting between integer types
transientStorageYour 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.

Shares Configuration

The shares option controls whether the generated hook issues a token representing user shares (e.g., LP positions in hook-owned liquidity pools).

OptionDescriptionUse When
falseNo share token — hook does not track ownership of deposited assetsSimple hooks that do not hold user funds
ERC20Fungible share token — one token represents proportional ownership of all hook-held assetsHook-managed liquidity pools with interchangeable shares
ERC6909Multi-token (minimal) — one contract manages many token IDs with lower overhead than ERC1155Hook manages multiple distinct asset classes efficiently
ERC1155Multi-token (standard) — full ERC1155 with metadata URI supportHook 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.

Access Control Options

The access option shapes the constructor and administrative interface of the generated hook.

OptionConstructor ShapeUse When
ownableconstructor(IPoolManager, address initialOwner)Single owner controls all admin functions
rolesconstructor(IPoolManager, address admin)Multiple roles with granular permissions (OpenZeppelin AccessControl)
managedconstructor(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 access option changes the constructor signature. Update deployment
scripts and initialization logic accordingly. When using ownable, ensure the initialOwner
is not the zero address — OpenZeppelin's Ownable reverts on zero address since v5.

Hook Inputs Reference

Some hook types accept numeric configuration inputs that tune behavior. These are passed as the inputs object in the MCP tool call.

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 93 of 100Pattern checks on the skill's files.
  • Model reviewNot runA model review is scheduled for the next rescan.

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
232
Repository forks
37
7-day trend score
27

Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 21 Sep 2026, a month ago.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/uniswap/uniswap-ai/v4-hook-generator/badge)](https://verified-skill.com/skills/uniswap/uniswap-ai/v4-hook-generator)

Something wrong with this skill or its page? Tell us.