Design Hook:Uniswap V4 架构与规划 - Openclaw Skills

作者:互联网

2026-03-29

AI教程

什么是 Design Hook (Uniswap V4)?

此技能通过利用 hook-builder 子代理,赋予开发者构建复杂的 Uniswap V4 hook 架构的能力。它不直接进入实现阶段,而是提供一份结构化的设计文档,概述回调要求、位掩码标志和状态管理模式。对于需要在进入开发阶段之前验证复杂交易逻辑或动态费用结构可行性的 DeFi 开发者来说,它是 Openclaw Skills 生态系统中不可或缺的一部分。

通过分析特定的 hook 行为和外部集成,该技能可以识别潜在的安全隐患并估算 Gas 开销。这确保了最终的智能合约既高效又健壮。无论您是在构建限价单、预言机还是自定义流动性管理工具,Openclaw Skills 库中的这个工具都能简化开发前的规划流程。

下载入口:https://github.com/openclaw/skills/tree/main/skills/wpank/design-hook

安装与下载

1. ClawHub CLI

从源直接安装技能的最快方式。

npx clawhub@latest install design-hook

2. 手动安装

将技能文件夹复制到以下位置之一

全局模式 ~/.openclaw/skills/ 工作区 /skills/

优先级:工作区 > 本地 > 内置

3. 提示词安装

将此提示词复制到 OpenClaw 即可自动安装。

请帮我使用 Clawhub 安装 design-hook。如果尚未安装 Clawhub,请先安装(npm i -g clawhub)。

Design Hook (Uniswap V4) 应用场景

  • 为动态费用 hook 或自定义预言机规划回调逻辑。
  • 为 TWAMM 等复杂的 V4 功能确定所需的位掩码和 hook 标志。
  • 在编写 Solidity 之前评估 hook 设计的 Gas 影响和可行性。
  • 审查外部协议集成的安全注意事项和状态管理策略。
Design Hook (Uniswap V4) 工作原理
  1. 用户提供所需的 hook 行为、约束和必要的集成。
  2. 系统在专门的仅限设计模式下触发 hook-builder 子代理。
  3. 代理分析 Uniswap V4 规范以映射所需的回调并验证标志组合。
  4. 它生成一份全面的设计文档,涵盖状态变量、Gas 估算和安全缓解措施。
  5. 生成的架构计划作为未来使用 Openclaw Skills 开发的蓝图呈现给用户。

Design Hook (Uniswap V4) 配置指南

要在您的环境中启用此功能,请确保已安装框架并配置了 hook-builder 子代理。此技能是更广泛的 Openclaw Skills 套件的一部分。

# 初始化 design-hook 环境
openclaw install design-hook

Design Hook (Uniswap V4) 数据架构与分类体系

设计文档遵循结构化模式,以确保使用 Openclaw Skills 的开发者清晰明了。

字段 描述
所需回调 V4 回调列表(例如 beforeSwap、afterDonate)及其用途。
Hook 标志与位掩码 部署所需的技术标志和十六进制位掩码。
状态管理 存储变量、数据结构和访问模式的定义。
Gas 估算 每个活跃回调的近似 Gas 成本。
安全性 识别到的风险(如预言机操纵)及建议的缓解措施。
name: design-hook
description: >-
  Design a Uniswap V4 hook architecture without code generation. Use when user
  wants to plan a hook, understand which callbacks to use, or review an
  architecture before building. Returns a design document, not code.
allowed-tools: >-
  Read, Glob, Grep,
  Task(subagent_type:hook-builder),
  mcp__uniswap__get_supported_chains
model: opus

Design Hook

Overview

Designs a Uniswap V4 hook architecture without generating code. Delegates to the hook-builder agent in design-only mode to produce a comprehensive design document covering: which callbacks are needed, hook flag requirements, state management approach, gas estimates, security considerations, and architecture decisions. Use this to plan before building, or to evaluate feasibility.

When to Use

Activate when the user asks:

  • "Design a hook for..."
  • "What callbacks do I need for..."
  • "Hook architecture for..."
  • "Plan a V4 hook"
  • "Is it possible to build a hook that..."
  • "What would a dynamic fee hook look like?"
  • "Help me think through a hook design"
  • "Which flags do I need for a TWAMM?"

Parameters

Parameter Required Default Description
behavior Yes -- Hook behavior description (e.g., "limit orders", "dynamic fees", "oracle pricing")
constraints No -- Gas budget, security requirements, or specific design constraints
integrations No -- External systems the hook needs to interact with (oracles, governance, staking)

Workflow

  1. Extract parameters from the user's request: identify the hook behavior, constraints, and any external integrations.

  2. Delegate to hook-builder in design-only mode: Invoke Task(subagent_type:hook-builder) with explicit instruction to produce a design document only -- no code generation, no file writes. The hook-builder will:

    • Analyze the requirements and determine which V4 callbacks are needed
    • Map callbacks to hook flags and validate the combination
    • Design the state management approach (what storage, what data structures)
    • Estimate gas overhead per callback
    • Identify security considerations specific to this hook design
    • Evaluate feasibility and flag any concerns
  3. Present the design document to the user covering:

    • Callbacks needed and why each is required
    • Hook flags and bitmask
    • State management design (storage variables, data structures, access patterns)
    • Gas estimates and performance implications
    • Security considerations and mitigations
    • Architecture decisions with rationale
    • Comparison with alternative approaches if applicable

Output Format

Present a structured design document:

V4 Hook Design: Dynamic Fee Hook

  Callbacks Required:
    - beforeSwap: Read volatility oracle, calculate dynamic fee
    - beforeInitialize: Set initial fee parameters and oracle address

  Hook Flags: BEFORE_SWAP_FLAG | BEFORE_INITIALIZE_FLAG
  Bitmask: 0x2080

  State Management:
    - volatilityOracle: IVolatilityOracle (immutable, set in constructor)
    - baseFee: uint24 (configurable by owner)
    - maxFee: uint24 (cap to prevent excessive fees)
    - feeMultiplier: uint24 (scales with volatility)

  Gas Estimates:
    beforeSwap: ~30,000 gas (oracle read + fee calculation)
    beforeInitialize: ~25,000 gas (one-time setup)

  Security Considerations:
    - Oracle manipulation: Use TWAP, not spot price
    - Fee cap: Enforce maxFee to protect traders
    - Owner control: Fee parameters updatable by owner only

  Architecture Decisions:
    - Using beforeSwap (not afterSwap) to set fee before execution
    - External oracle for volatility data rather than on-chain calculation
    - Fee bounded between baseFee and maxFee for predictability

  Alternative Approaches:
    - On-chain volatility calculation (higher gas, no oracle dependency)
    - Fixed fee tiers with governance voting (simpler, less responsive)

Important Notes

  • This skill produces a design document only -- no code is generated and no files are written.
  • The design document provides enough detail to proceed with build-hook when the user is ready.
  • If the hook design is infeasible (e.g., requires callbacks that V4 doesn't support), this will be clearly communicated.
  • Gas estimates are approximations based on typical implementations -- actual gas depends on implementation details.

Error Handling

Error User-Facing Message Suggested Action
VAGUE_REQUIREMENTS "Need more detail about the desired hook behavior." Describe specific behavior (e.g., "limit orders that execute at tick boundaries")
UNSUPPORTED_CALLBACK "V4 does not support the requested callback." Review available V4 callbacks and adjust requirements
INFEASIBLE_DESIGN "This hook design is not feasible with current V4 capabilities." Simplify requirements or consider alternative approaches