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

Uniswap V4 Hook 零代码架构师

design-hook · vv0.1.0
开发 安全 S+ 级 作者 wpank 公开目录收录
1.3k 下载 383 安装 4.2k 收藏 33k 浏览

简介

社区开发者打造的纯文档型设计工具,专注 Uniswap V4 Hook 架构规划,输出回调选择、Gas 估算与安全考量的专业设计文档。

原始描述

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.

通过你的 Agent 添加

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

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

或者手动安装

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

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

中文使用说明 来自收录源

核心用法

design-hook 是一款专注于 Uniswap V4 Hook 架构规划的专业设计工具。它采用纯设计模式(design-only mode),通过调用 hook-builder 子代理,在不生成任何代码的前提下,为用户提供全面的架构设计方案。

用户只需描述目标行为(如动态手续费、限价单、预言机定价等)、约束条件(Gas 预算、安全要求)以及外部集成需求,该工具即可输出包含回调函数选择、Hook 标志位计算、状态管理设计、Gas 开销估算及安全考量的完整设计文档。

显著优点

架构先行方法论:强制设计先于编码,帮助开发者在投入开发成本前识别技术可行性与潜在风险,特别适合复杂 DeFi 协议的规划阶段。

专业深度分析:针对 Uniswap V4 的特定机制(如 beforeSwap、afterSwap 等回调点),提供标志位组合验证、存储布局优化建议,以及基于典型实现的 Gas 估算(如 beforeSwap 约 30,000 Gas)。

安全内建考量:设计文档强制包含安全分析模块,涵盖预言机操控防护(建议使用 TWAP 而非现货价格)、手续费上限保护、权限控制等关键安全模式。

错误预防机制:内置 VAGUE_REQUIREMENTS、UNSUPPORTED_CALLBACK 等错误处理,当需求模糊或回调不支持时及时反馈,避免无效工作。

潜在缺点与局限性

无代码输出:严格遵守"不生成代码"原则,用户获得设计文档后,仍需使用 build-hook 或其他工具进行实际编码,存在设计到实现的认知鸿沟。

Gas 估算偏差:文档明确提示 Gas 估算基于典型实现,实际开销高度依赖具体编码细节,不能作为链上部署的最终依据。

来源可信度限制:维护者为个人开发者(GitHub: wpank),缺乏企业级背书,设计方法论虽合理但未经过大规模社区审计验证。

子代理依赖性:实际分析工作委托给 hook-builder 子代理,其输出质量直接影响设计文档的准确性,存在代理能力边界风险。

适合的目标群体

Solidity 开发者:计划开发 Uniswap V4 Hook 但不确定技术路线的工程师,可通过该工具验证架构可行性。

DeFi 协议设计师:需要评估创新机制(如动态费用、TWAMM)在 V4 框架下的实现复杂度与成本效益的产品经理。

安全审计员:在代码审计前使用该工具生成设计规格文档,作为审计基准与实现对比的参考。

教育学习者:希望深入理解 Uniswap V4 Hook 架构设计范式与最佳实践的区块链开发者。

使用风险

设计实现偏差:设计文档与最终代码实现可能存在差异,特别是 Solidity 存储布局优化、回调函数重入防护等细节,需资深开发者审核转换过程。

依赖项风险:依赖 hook-builder 子代理的专业能力,若代理对最新 V4 合约规范理解滞后,可能导致设计建议过时。

权限误用风险:虽当前权限申请合理(Read/Glob/Grep/限定子代理),但用户应警惕未来版本变更中可能引入的高危权限。

T3 来源风险:作为个人维护项目,长期更新维护存在不确定性,关键设计决策应交叉验证官方 Uniswap 文档。

技能正文


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

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

标签

development-engineeringblockchaindefismart-contractsarchitecturedesign

同类 Skill