3.0 KiB

title, order
title order
Uniswap Hooks 3

Uniswap Hooks

AI-powered, security-first assistance for creating Uniswap v4 hooks.

Installation

/plugin install uniswap-hooks

Skills

Skill Description Invocation
v4 Security Foundations Security-first guide for V4 hook development /v4-security-foundations
v4 Hook Generator Generate V4 hook contracts via OpenZeppelin Contracts MCP /v4-hook-generator

Hook Callbacks

Hooks are smart contracts that intercept and modify pool actions at specific points:

Callback When Called Use Case
beforeInitialize Before pool creation Validate pool parameters
afterInitialize After pool creation Set up hook state
beforeAddLiquidity Before LP deposit Custom fee logic
afterAddLiquidity After LP deposit Update rewards
beforeRemoveLiquidity Before LP withdrawal Lock periods
afterRemoveLiquidity After LP withdrawal Distribute rewards
beforeSwap Before swap execution Price oracles, routing
afterSwap After swap execution MEV protection, analytics
beforeDonate Before donation Access control
afterDonate After donation Track donations

Hook Flags

Hooks declare which callbacks they implement via a permissions struct. The hook address must encode which callbacks are enabled in its last 14 bits. Use the hook miner to find valid addresses during deployment.

function getHookPermissions() public pure override returns (Hooks.Permissions memory) {
    return Hooks.Permissions({
        beforeInitialize: false,
        afterInitialize: true,
        beforeSwap: true,
        afterSwap: true,
        // ... remaining flags
    });
}

Development Guidelines

  • Address requirements: v4 hooks must have specific address patterns where the last 14 bits encode enabled callbacks
  • State management: Use transient storage for temporary data; consider gas costs for persistent state
  • Security: Validate all inputs, guard against reentrancy, consider MEV implications
  • Testing: Test edge cases with extreme tick ranges