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

V4 Hook架构设计与规划工具

Design Uniswap Hook · v0.1.0
开发 安全 A 级 作者 wpank 公开目录收录
1.1k 下载 0 安装 3.9k 收藏 11 浏览

简介

专业设计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-uniswap-hook/
Codex CLI~/.codex/skills/design-uniswap-hook/
DeepSeek Harness~/.agents/skills/design-uniswap-hook/

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

中文使用说明 来自收录源

核心功能

design-hook 是一个专注于Uniswap V4 Hook架构设计的规划型技能,其核心定位是**"设计先行、代码后置"**。与直接生成代码的工具不同,它通过调用 hook-builder 子代理,在纯设计模式下输出一份完整的设计文档,涵盖开发Hook所需的全部架构决策。

设计文档核心内容

模块 输出内容
回调选择 分析业务需求,确定必需的V4回调(如 beforeSwap、afterInitialize 等)
Hook标志位 计算所需的Hook Flags组合及对应的十六进制掩码(如 0x2080)
状态管理 设计存储变量、数据结构和访问模式,包括可变/不可变状态划分
Gas估算 按回调提供粗略Gas开销(如 beforeSwap ~30,000 gas)
安全考量 识别特定于该设计的攻击向量(预言机操纵、重入等)及缓解措施
架构决策 记录关键设计选择及其理由,支持追溯与评审
替代方案 对比其他可行路径,说明当前选择的优劣

典型使用场景

  • 开发前规划:明确技术可行性,避免编码后返工
  • 方案评审:团队内部分享设计,收集反馈
  • 学习参考:理解特定Hook类型(如TWAMM、动态费用、限价单)的实现原理
  • 可行性评估:判断想法是否在V4技术约束内可实现

显著优点

  1. 零代码风险:设计阶段不生成文件,避免污染工作区
  2. 专业化分工:由 hook-builder 子代理专注处理复杂的V4回调矩阵
  3. 决策可追溯:强制记录架构决策理由,提升代码可维护性
  4. 安全前置:在设计阶段识别风险,而非事后修补

潜在局限

  • 无代码产出:需要配合 build-hook 技能才能进入实现阶段
  • Gas估算非精确值:基于典型实现的经验值,实际消耗依赖具体编码
  • 依赖子代理质量:设计深度受限于 hook-builder 的知识覆盖
  • 无法自动验证:设计正确性需人工或后续代码审查确认

适合人群

  • V4 Hook开发者(初级到高级)
  • DeFi协议架构师评估Hook集成的技术方案
  • 安全审计师快速理解陌生Hook的设计意图
  • 研究人员探索V4 Hook的设计空间

常规风险

风险类型 说明
设计错误 错误的回调选择或标志位计算导致Hook无法正常触发
Gas低估 复杂状态操作可能导致实际Gas远超估算,影响用户体验
预言机依赖 涉及外部数据的Hook需额外评估操纵风险与可用性
权限模型缺陷 设计中未妥善处理的权限控制可能引入中心化风险

技能正文


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

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

标签

uniswap-v4hook-designdefi-architectureprotocol-planninggas-optimization

同类 Skill