微算力 · API 导航与自营网关
API 接入 EN
未登录登录
🪝

V4 Hook 智能合约生成器

build-hook · vv0.1.0
入口已确认,内容待校验 文件树里有 SKILL.md,但正文还没采回,frontmatter 未核对。
开发 安全 A 级 作者 wpank 公开目录收录
728 下载 179 安装 3k 收藏 11.5k 浏览

简介

基于 Uniswap V4 官方架构,自动化生成 Solidity 合约、Foundry 测试及 CREATE2 部署脚本,降低自定义 Hook 开发门槛。

原始描述

Build a Uniswap V4 hook. Use when user wants to create a custom V4 hook contract. Generates Solidity code, Foundry tests, mines CREATE2 address for hook flags, and produces deployment scripts. Handles the full hook development lifecycle.

通过你的 Agent 添加

安装目录:build-hook/(目录名取自 SKILL.md 的 frontmatter name,不是 URL 里的 slug)。

点「快速安装」复制一段指令贴给你的 Agent:它会先下载到 /tmp、把文件清单和校验值给你看,你确认之后才解压安装。不会一步装完、也不改系统其它位置。

或者手动安装

Claude Code~/.claude/skills/build-hook/
Codex CLI~/.codex/skills/build-hook/
DeepSeek Harness~/.agents/skills/build-hook/

包是「根级 SKILL.md + 作者附带的文件」,解压到上面的 <slug>/ 目录即可; 目录名不用换,也不要把包直接解压到 skills 根目录。 技能申请的权限由作者决定:装之前先看清单里有没有脚本、它会读写什么。

中文使用说明 来自收录源

核心用法

build-hook 是一个专为 Uniswap V4 开发者设计的 Agent Skill,用于构建自定义 Hook 合约。用户只需描述期望的 Hook 行为(如“动态手续费钩子”、“限价单钩子”、“TWAMM 钩子”),该技能即可自动完成从需求分析到生产级代码输出的完整开发生命周期。

具体工作流包括:理解需求并确定所需回调类型、将回调映射到 V4 Hook 标志位、生成继承 BaseHook 的 Solidity 合约、生成基于 Foundry 的综合测试套件(含单元测试、集成测试、边缘案例和 Gas 快照)、挖掘符合标志位的 CREATE2 地址盐值、生成包含验证步骤的部署脚本。所有产物直接写入项目目录,开箱即用。

显著优点

  1. 全生命周期覆盖:从需求理解、代码生成、测试、地址挖掘到部署脚本,一站式解决 V4 Hook 开发的所有环节,大幅降低开发门槛。
  2. 生成代码质量高:合约继承 BaseHook,自带重入保护和访问控制;测试覆盖全面,包含 Gas 快照;CREATE2 地址挖掘确保前端字节编码正确的 Hook 标志位(V4 PoolManager 的硬性要求)。
  3. 声明式交互体验:用户无需关心技术细节,用自然语言描述 Hook 行为即可。由子代理 hook-builder 承担所有工程实现负担。
  4. 纯声明式设计,安全透明:该 Skill 本身为纯 Markdown 文件,无可执行代码嵌入,功能与声明完全一致,无隐藏行为。

潜在缺点或局限性

  1. 生成质量依赖子代理:核心功能完全委托给 hook-builder 子代理,生成的合约和测试质量直接取决于该代理的实现水平。若子代理未及时适配 V4 最新版本或存在逻辑偏差,输出可能不理想。
  2. 灵活性有限:适用于标准 V4 Hook 模式(限价单、动态手续费、TWAMM 等),若用户需求超出子代理预设模板范围,生成结果可能需要大量手动修改。
  3. 环境依赖性强:强依赖 Foundry 工具链,若环境中未安装,需额外手动安装 foundryup。
  4. CREATE2 挖掘性能限制:地址挖掘存在超时风险(CREATE2_MINING_TIMEOUT),所需标志位越多,挖掘耗时越长。

适合的目标群体

  • Uniswap V4 初学者:想快速上手 V4 Hook 开发但缺乏参考模板的开发者。
  • Solidity 合约开发者:需要快速原型化 Hook 想法,节省样板代码编写时间。
  • DeFi 项目团队:在项目早期需要快速验证 Hook 可行性,再在生成代码基础上深度定制。
  • 审计前的预研团队:利用生成的测试套件和 Gas 快照,在正式审计前进行初步安全与经济可行性评估。

使用风险提示

  1. 供应链风险:该 Skill 声明了 Bash(npm:*) 通配符权限,理论上可安装任意 npm 包。虽然 Hook 开发确实依赖 npm 安装,但权限范围偏宽,建议在实际使用中注意审查安装的包来源。
  2. 子代理透明度有限:核心代码生成逻辑封装在 hook-builder 子代理中,本 Skill 无法直接审计其内部行为。使用者应确保该子代理同样经过安全审查。
  3. T3 来源可信度:该 Skill 来自个人开发者 wpank 的社区项目,仓库信誉和长期维护状态无法完全验证。用于生产环境前,建议充分审查生成代码并自行测试。
  4. 许可证未声明:缺少明确的许可证信息,在商业使用场景下可能带来法律不确定性。

技能正文


name: build-hook description: >- Build a Uniswap V4 hook. Use when user wants to create a custom V4 hook contract. Generates Solidity code, Foundry tests, mines CREATE2 address for hook flags, and produces deployment scripts. Handles the full hook development lifecycle. allowed-tools: >- Read, Write, Edit, Glob, Grep, Bash(forge:), Bash(npm:), Bash(git:*), Task(subagent_type:hook-builder), mcp__uniswap__get_supported_chains model: opus

Build Hook

Overview

Builds a complete Uniswap V4 hook by delegating to the hook-builder agent. Handles the full development lifecycle: understanding requirements, determining hook flags, generating Solidity contracts, generating Foundry tests, mining a CREATE2 address with correct flag bits, and producing deployment scripts. Returns production-ready code artifacts written directly to the project.

When to Use

Activate when the user asks:

  • "Build a V4 hook"
  • "Create a limit order hook"
  • "Build a dynamic fee hook"
  • "Create a TWAMM hook"
  • "Custom hook for V4"
  • "Hook that charges higher fees during volatility"
  • "Build a hook that distributes LP fees to stakers"
  • "Create a hook with oracle integration"

Parameters

Parameter Required Default Description
behavior Yes -- Hook behavior description (e.g., "limit orders", "dynamic fees", "TWAMM", "oracle-based pricing")
callbacks No Auto-detect Specific V4 callbacks if the user knows them (e.g., "beforeSwap, afterSwap")
constraints No -- Gas budget, security requirements, or specific design constraints
chain No ethereum Target chain for deployment (affects PoolManager address)

Workflow

  1. Extract parameters from the user's request: identify the hook behavior, any explicitly mentioned callbacks, constraints, and target chain.

  2. Delegate to hook-builder: Invoke Task(subagent_type:hook-builder) with the full context. The hook-builder agent will:

    • Understand the requirements and determine which callbacks are needed
    • Map callbacks to hook flags and validate the flag combination
    • Generate a Solidity contract extending BaseHook with proper NatSpec
    • Generate comprehensive Foundry tests (unit, integration, edge cases, gas snapshots)
    • Mine a CREATE2 salt that produces an address encoding the required flags
    • Produce a deployment script with verification steps
  3. Present results to the user with a summary covering:

    • Files written (contract path, test path, deployment script path)
    • Hook architecture explanation (what it does, how state flows)
    • Callbacks implemented and their flag bitmask
    • Gas estimates per callback (from Foundry test output)
    • Next steps for the developer (run tests, deploy to testnet, mainnet considerations)

Output Format

Present a summary followed by the generated files:

V4 Hook Built: LimitOrderHook

  Contract:   src/hooks/LimitOrderHook.sol (187 lines)
  Tests:      test/hooks/LimitOrderHook.t.sol (12 tests)
  Deployment: script/DeployLimitOrderHook.s.sol

  Callbacks: beforeSwap, afterSwap
  Flags:     0x00C0
  CREATE2:   Salt mined, address verified

  Gas Estimates:
    beforeSwap: ~45,000 gas
    afterSwap:  ~32,000 gas
    Total overhead per swap: ~77,000 gas

  Architecture:
    Orders are placed at specific ticks and stored in an on-chain order book.
    During beforeSwap, the hook checks for matching orders at the target tick.
    Matched orders are filled atomically within the same transaction.

  Next Steps:
    1. Run tests: forge test --match-contract LimitOrderHookTest
    2. Deploy to testnet: forge script script/DeployLimitOrderHook.s.sol --rpc-url sepolia
    3. Verify on Etherscan: forge verify-contract <address> LimitOrderHook

Important Notes

  • This skill delegates entirely to the hook-builder agent -- it does not call MCP tools directly.
  • The hook-builder generates production-quality Solidity code with reentrancy protection and access control.
  • CREATE2 address mining ensures the deployed address encodes the correct hook flags in its leading bytes (required by V4 PoolManager).
  • Foundry must be installed for test generation and compilation. If not found, the skill will provide installation instructions.
  • Generated code uses Solidity ^0.8.26 and imports from @uniswap/v4-core and @uniswap/v4-periphery.

Error Handling

Error User-Facing Message Suggested Action
INVALID_CALLBACK_COMBINATION "The requested behavior requires conflicting callbacks." Simplify hook behavior or split into multiple hooks
CREATE2_MINING_TIMEOUT "Could not mine a valid CREATE2 address within time limit." Increase mining time limit or reduce required flags
FORGE_NOT_INSTALLED "Foundry (forge) is required but not installed." Install: curl -L https://foundry.paradigm.xyz | bash && foundryup
VAGUE_REQUIREMENTS "Need more detail about the desired hook behavior." Describe specific behavior (e.g., "limit orders that execute at tick boundaries")
COMPILATION_ERROR "Generated contract has compilation errors." Review error output and adjust requirements

正文来自原始发布页, 版权归作者所有,许可未标注。 权利人认为有不妥,可申请下架。

标签

development-engineeringbackenddefiblockchainsmart-contract

同类 Skill