简介
自动化构建 Uniswap V4 Hook 完整开发套件,涵盖合约生成、Foundry 测试、CREATE2 地址挖矿与部署脚本,加速 DeFi 协议定制化开发。
原始描述
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、把文件清单和校验值给你看,你确认之后才解压安装。不会一步装完、也不改系统其它位置。
或者手动安装
包是「根级 SKILL.md + 作者附带的文件」,解压到上面的 <slug>/ 目录即可;
目录名不用换,也不要把包直接解压到 skills 根目录。
技能申请的权限由作者决定:装之前先看清单里有没有脚本、它会读写什么。
中文使用说明 来自收录源
技能概述
build-hook 是一款面向 DeFi 开发者的专业级技能,专注于 Uniswap V4 Hook 的全生命周期构建。该技能通过智能委托 hook-builder 代理,将复杂的 Hook 开发流程抽象为标准化、自动化的代码生成服务。
核心功能
智能需求解析:自动识别用户意图,将自然语言描述(如"限价单 Hook"、"动态费率 Hook")映射为具体的 V4 回调组合(beforeSwap、afterSwap、beforeAddLiquidity 等)。
完整代码生成:
- Solidity 合约:基于
BaseHook扩展,包含完整的 NatSpec 文档、重入保护和访问控制 - Foundry 测试套件:单元测试、集成测试、边界情况与 Gas 快照全覆盖
- CREATE2 地址挖矿:自动计算满足 Hook Flags 编码要求的部署地址
- 部署脚本:包含多链配置与合约验证步骤
技术规范:生成代码采用 Solidity ^0.8.26,依赖 @uniswap/v4-core 与 @uniswap/v4-periphery 官方库,确保与 V4 生态兼容。
显著优势
- 降低技术门槛:开发者无需深入理解 V4 Hook 的位掩码计算与 CREATE2 地址编码规则
- 生产级质量:内置安全最佳实践,包括重入锁、权限校验和 Gas 优化
- 全链路覆盖:从需求到部署脚本的一站式交付,减少手动配置错误
- 灵活定制:支持 gas 预算、安全等级、目标链等多维度约束配置
局限性与风险
技术局限:
- 依赖 Foundry 工具链,需预先安装
- 复杂 Hook 逻辑(如 TWAMM 的复杂时间加权算法)可能需要人工调优
- CREATE2 地址挖矿存在超时风险,极端 flag 组合可能导致长时间计算
安全风险:
- 生成代码虽遵循标准模式,但仍需专业审计,尤其是涉及资金托管的 Hook
- Hook Flags 配置错误可能导致 PoolManager 拒绝注册
- 动态 fee Hook 等高级功能需充分测试经济模型
适用人群:
- 具备 Solidity 基础的 DeFi 协议开发者
- 需要快速验证 Hook 概念的初创团队
- 学习 V4 架构的进阶开发者
使用建议
建议在测试网充分验证后再部署主网,关键业务场景务必配合专业安全审计。该技能生成的代码为高质量起点,但非最终生产代码。
技能正文
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
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
-
Extract parameters from the user's request: identify the hook behavior, any explicitly mentioned callbacks, constraints, and target chain.
-
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
-
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
| 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) |
-
Extract parameters from the user's request: identify the hook behavior, any explicitly mentioned callbacks, constraints, and target chain.
-
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
-
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
hook-builder agent -- it does not call MCP tools directly.@uniswap/v4-core and @uniswap/v4-periphery.| 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 |
正文来自原始发布页, 版权归作者所有,许可未标注。 权利人认为有不妥,可申请下架。