Skip to content

Uniswap Hooks

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

Installation

bash
/plugin install uniswap-hooks

Skills

SkillDescriptionInvocation
v4 Security FoundationsSecurity-first guide for V4 hook development/v4-security-foundations

Hook Callbacks

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

CallbackWhen CalledUse Case
beforeInitializeBefore pool creationValidate pool parameters
afterInitializeAfter pool creationSet up hook state
beforeAddLiquidityBefore LP depositCustom fee logic
afterAddLiquidityAfter LP depositUpdate rewards
beforeRemoveLiquidityBefore LP withdrawalLock periods
afterRemoveLiquidityAfter LP withdrawalDistribute rewards
beforeSwapBefore swap executionPrice oracles, routing
afterSwapAfter swap executionMEV protection, analytics
beforeDonateBefore donationAccess control
afterDonateAfter donationTrack 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.

solidity
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

Released under the MIT License.