V4 Hook Generator 标志

V4 Hook Generator

组织
Uniswap
v4-hook-generator

通过 OpenZeppelin MCP 生成 Uniswap v4 hook 合约。用于构建自定义兑换逻辑、异步兑换、由 hook 管理的流动性、自定义曲线、动态手续费、MEV 保护、限价订单或预言机 hook。

Add to TypingMind

概览

发布者Uniswap
代码仓库uniswap-ai
技能名称v4-hook-generator
星标数
234
复刻数
40
附带文件
仅含指令
许可协议MIT
链接
  • Markdown 格式的指令

    模型按需加载 SKILL.md 文件,因此只有在请求确实与该技能匹配时才会消耗 Token。

  • 兼容任何大语言模型

    AI 技能采用纯 Markdown,而非特定提供商的代码,因此可搭配 GPT、Claude、Gemini、Grok 或本地模型使用。

  • 指令自成一体

    模型所需的一切都包含在指令中,无需同步额外文件。

  • 开源

    由 Uniswap 发布于 GitHub。请在安装前查看技能的源文件。

安装

在 TypingMind 中安装 V4 Hook Generator AI 技能,即可搭配任意大语言模型使用;也可以将其放入其他支持读取 SKILL.md 的智能体中。

1

安装到 TypingMind

TypingMind 可直接从 GitHub 文件夹安装技能:读取 SKILL.md,打包资源文件,并将结果保存在本地。

  1. 打开应用,前往“插件 → 技能”。
  2. 选择“从 GitHub 安装”。
  3. 粘贴下方的技能文件夹 URL 并确认。
    https://github.com/Uniswap/uniswap-ai/tree/main/packages/plugins/uniswap-hooks/skills/v4-hook-generator
  4. 请在每个需要使用该技能的聊天中启用它。
依次选择“插件 → 技能 → 添加技能 → 从 GitHub URL 导入”,然后粘贴文件夹 URL 并点击“继续”。
2

安装到其他智能体

任何支持 Agent Skills 格式的智能体都可以使用此技能,只需将文件夹复制到该智能体的技能目录中。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/Uniswap/uniswap-ai.git /tmp/uniswap-ai
mkdir -p .claude/skills
cp -r /tmp/uniswap-ai/packages/plugins/uniswap-hooks/skills/v4-hook-generator .claude/skills/v4-hook-generator
复制后,请重启 Claude Code,以加载新技能。

在 TypingMind 中使用此技能

在任意 TypingMind 聊天中启用 V4 Hook Generator,后续即可交由模型处理。技能的名称和描述会放在系统提示词中,一旦请求匹配,模型就会自动加载完整指令,无需您手动调用,且在实际使用前不会消耗 Token。

一旦请求与技能匹配,模型就会自动加载 V4 Hook Generator。

兼容任何 AI 模型

AI 技能是纯 Markdown 指令,而非特定提供商的代码,因此 V4 Hook Generator 不局限于最初适配的模型。只需在 TypingMind 中安装一次,即可搭配 GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 或您自行运行的本地模型使用,全程使用您自己的 API 密钥。

  • 仅在需要时加载

    系统提示词中仅包含技能名称和描述。首次遇到匹配的请求时才会加载完整指令,因此技能未使用时,这些指令不会消耗 Token。

  • 在聊天中切换模型

    技能是指令而非代码,因此切换模型不会导致技能失效,新模型会读取同一个 SKILL.md。

技能指令

这是模型会加载的 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.

InputTypeUsed ByDescription
blockNumberOffsetuint256AntiSandwichHook, LiquidityPenaltyHookNumber of blocks before sandwich/JIT detection window opens
maxAbsTickDeltaint24AntiSandwichHookMaximum 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.

MCP Tool Call (Canonical)

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.

json
{
  "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 table
  • name: string — the Solidity contract name (PascalCase, no spaces)
  • pausable: boolean — wraps the hook in OpenZeppelin Pausable; adds pause()/unpause() admin functions
  • shares.options: false | "ERC20" | "ERC6909" | "ERC1155"
  • access: "ownable" | "roles" | "managed"
  • info.license: SPDX license identifier — use "MIT" for open-source hooks
  • inputs: omit or pass {} for hook types that do not use blockNumberOffset/maxAbsTickDelta

Workflow: Gather → Configure → Generate → Secure

Follow these steps in order every time you use this skill.

Step 1: Gather Requirements

Ask the user (or infer from context):

  1. What is the hook's primary goal? (Map to the decision table.)
  2. Which lifecycle events does the hook need to intercept? (Map to permissions.)
  3. Does the hook hold or move user funds? (Determines currencySettler and shares.)
  4. Who administers the hook? (Single owner, role-based team, or external governance?)
  5. Does the hook need to pass state between callbacks within a single transaction?
  6. Is this for a chain with EVM Cancun support? (Required for transientStorage.)

Step 2: Select Hook Type

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.

Step 3: Configure All Six Decisions

Work through the minimal decision checklist:

  1. Set hook to the chosen type.
  2. Set each permission flag — default false, enable only what the logic requires.
  3. Set currencySettler, safeCast, transientStorage based on utility library guidance.
  4. Set shares.options based on shares guidance.
  5. Set access based on access control guidance.
  6. Set inputs only if the hook type uses blockNumberOffset or maxAbsTickDelta.

Step 4: Assemble and Call the MCP Tool

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:

  1. Display the code to the user.
  2. Explain the key generated sections (constructor, getHookPermissions, enabled callbacks).
  3. Note any manual steps required (HookMiner for address mining, deployment script updates for constructor args if access is roles or managed).

Step 5: Apply Security Foundations

Always remind the user — and invoke v4-security-foundations — before the code is deployed:

  • Verify all enabled callbacks check msg.sender == address(poolManager).
  • Review any enabled *ReturnDelta permissions for NoOp attack exposure.
  • Confirm delta accounting sums to zero for every execution path.
  • Run the full pre-deployment audit checklist from v4-security-foundations.

Important Notes

  • Access control changes constructor shape: Choosing ownable adds an initialOwner parameter; roles adds an admin parameter; managed adds an authority parameter. Update deployment scripts and factory contracts accordingly.
  • Permissions encode in the hook address: Each enabled permission flag corresponds to a specific bit in the lower bytes of the hook's deployed address. The PoolManager validates these bits on every callback. Use HookMiner from v4-periphery to mine a deployment salt that produces a matching address.
  • MCP returns code only — it does not write files: The generated Solidity is returned as a string. You must write it to disk yourself (e.g., packages/contracts/src/hooks/MyHook.sol).

Related Skills

  • 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/wagmi
  • v4-sdk-integration — Interact with deployed hooks via the Uniswap v4 SDK

常见问题

V4 Hook Generator AI 技能有什么作用?

通过 OpenZeppelin MCP 生成 Uniswap v4 hook 合约。用于构建自定义兑换逻辑、异步兑换、由 hook 管理的流动性、自定义曲线、动态手续费、MEV 保护、限价订单或预言机 hook。

为什么在 TypingMind 中使用 V4 Hook Generator?

因为您只需安装一次,就能搭配任何模型使用。V4 Hook Generator 采用纯 Markdown 格式,而非特定提供商专用的代码,因此同一技能可用于 GPT-5、Claude、Gemini、Grok 或本地模型。您甚至可以在聊天中途切换模型,而不会影响技能的正常使用。TypingMind 使用您自己的 API 密钥,因此您直接向提供商付费,而不是按席位订阅;您的技能和聊天记录也都保留在您自己的存储空间中。

如何在 TypingMind 中安装 V4 Hook Generator?

在 TypingMind 中打开“插件 → 技能 → 从 GitHub 安装”,然后粘贴 https://github.com/Uniswap/uniswap-ai/tree/main/packages/plugins/uniswap-hooks/skills/v4-hook-generator。TypingMind 会读取其中的 SKILL.md,并将其安装为技能,供您在各个聊天中按需启用。

哪些 AI 模型可以使用 V4 Hook Generator?

您在 TypingMind 中连接的任何模型都可以。AI 技能采用纯 Markdown 指令,而非特定提供商专用的代码,因此 GPT、Claude、Gemini、Grok 和本地模型都能在请求匹配时加载此技能。

V4 Hook Generator 可以搭配多少个 AI 模型使用?

数量不限。只要模型支持技能,您就可以将它与 V4 Hook Generator 搭配使用。GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 等模型都可以通过您自己的 API 密钥接入 TypingMind。

V4 Hook Generator AI 技能免费吗?

是的。Uniswap 已在 GitHub 上根据 MIT 许可证发布了该技能。您只需向自己的 AI 提供商支付所用 Token 的费用。

什么是 AI 技能?

AI 技能是一组可复用的指令,用于教会 AI 模型完成某项特定任务。它遵循开放的 Agent Skills 格式:包含名称和描述的 SKILL.md 文件,以及模型可能需要的脚本、模板或参考文件。模型仅在您的请求与技能匹配时才会读取这些指令,因此已安装的技能在使用前不会产生任何费用。

AI 技能与插件或 MCP 服务器有何不同?

插件或 MCP 服务器为模型提供可调用的新工具,也就是在某处运行并返回结果的代码。AI 技能则为模型提供知识和流程:如何处理任务、遵循哪些步骤,以及怎样的输出才算优质。技能采用纯 Markdown 格式,因此不需要服务器、API 密钥或运行时环境,并且适用于任何模型。

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇