Build Hook
Overview
Builds a complete Uniswap V4 hook by delegating to the hook-builder agent. Handles the full development lifecycle: understanding requirements, determining hook flags, generating Solidity contracts, generating Foundry tests, mining a CREATE2 address with correct flag bits, and producing deployment scripts. Returns production-ready code artifacts written directly to the project.
When to Use
Activate when the user asks:
- "Build a V4 hook"
- "Create a limit order hook"
- "Build a dynamic fee hook"
- "Create a TWAMM hook"
- "Custom hook for V4"
- "Hook that charges higher fees during volatility"
- "Build a hook that distributes LP fees to stakers"
- "Create a hook with oracle integration"
Parameters
| Parameter |
Required |
Default |
Description |
| behavior |
Yes |
-- |
Hook behavior description (e.g., "limit orders", "dynamic fees", "TWAMM", "oracle-based pricing") |
| callbacks |
No |
Auto-detect |
Specific V4 callbacks if the user knows them (e.g., "beforeSwap, afterSwap") |
| constraints |
No |
-- |
Gas budget, security requirements, or specific design constraints |
| chain |
No |
ethereum |
Target chain for deployment (affects PoolManager address) |
Workflow
Extract parameters from the user's request: identify the hook behavior, any explicitly mentioned callbacks, constraints, and target chain.
Delegate to hook-builder: Invoke Task(subagent_type:hook-builder) with the full context. The hook-builder agent will:
- Understand the requirements and determine which callbacks are needed
- Map callbacks to hook flags and validate the flag combination
- Generate a Solidity contract extending BaseHook with proper NatSpec
- Generate comprehensive Foundry tests (unit, integration, edge cases, gas snapshots)
- Mine a CREATE2 salt that produces an address encoding the required flags
- Produce a deployment script with verification steps
Present results to the user with a summary covering:
- Files written (contract path, test path, deployment script path)
- Hook architecture explanation (what it does, how state flows)
- Callbacks implemented and their flag bitmask
- Gas estimates per callback (from Foundry test output)
- Next steps for the developer (run tests, deploy to testnet, mainnet considerations)
Output Format
Present a summary followed by the generated files:
V4 Hook Built: LimitOrderHook
Contract: src/hooks/LimitOrderHook.sol (187 lines)
Tests: test/hooks/LimitOrderHook.t.sol (12 tests)
Deployment: script/DeployLimitOrderHook.s.sol
Callbacks: beforeSwap, afterSwap
Flags: 0x00C0
CREATE2: Salt mined, address verified
Gas Estimates:
beforeSwap: ~45,000 gas
afterSwap: ~32,000 gas
Total overhead per swap: ~77,000 gas
Architecture:
Orders are placed at specific ticks and stored in an on-chain order book.
During beforeSwap, the hook checks for matching orders at the target tick.
Matched orders are filled atomically within the same transaction.
Next Steps:
1. Run tests: forge test --match-contract LimitOrderHookTest
2. Deploy to testnet: forge script script/DeployLimitOrderHook.s.sol --rpc-url sepolia
3. Verify on Etherscan: forge verify-contract <address> LimitOrderHook
Important Notes
- This skill delegates entirely to the
hook-builder agent -- it does not call MCP tools directly.
- The hook-builder generates production-quality Solidity code with reentrancy protection and access control.
- CREATE2 address mining ensures the deployed address encodes the correct hook flags in its leading bytes (required by V4 PoolManager).
- Foundry must be installed for test generation and compilation. If not found, the skill will provide installation instructions.
- Generated code uses Solidity ^0.8.26 and imports from
@uniswap/v4-core and @uniswap/v4-periphery.
Error Handling
| Error |
User-Facing Message |
Suggested Action |
INVALID_CALLBACK_COMBINATION |
"The requested behavior requires conflicting callbacks." |
Simplify hook behavior or split into multiple hooks |
CREATE2_MINING_TIMEOUT |
"Could not mine a valid CREATE2 address within time limit." |
Increase mining time limit or reduce required flags |
FORGE_NOT_INSTALLED |
"Foundry (forge) is required but not installed." |
Install: curl -L https://foundry.paradigm.xyz | bash && foundryup |
VAGUE_REQUIREMENTS |
"Need more detail about the desired hook behavior." |
Describe specific behavior (e.g., "limit orders that execute at tick boundaries") |
COMPILATION_ERROR |
"Generated contract has compilation errors." |
Review error output and adjust requirements |
1---2name: build-hook3description: Builds a complete Uniswap V4 hook by delegating to a hook-builder agent, generating Solidity contracts, Foundry tests, CREATE2 address mining, and deployment scripts.4---56# Build Hook78## Overview910Builds a complete Uniswap V4 hook by delegating to the `hook-builder` agent. Handles the full development lifecycle: understanding requirements, determining hook flags, generating Solidity contracts, generating Foundry tests, mining a CREATE2 address with correct flag bits, and producing deployment scripts. Returns production-ready code artifacts written directly to the project.1112## When to Use1314Activate when the user asks:1516- "Build a V4 hook"17- "Create a limit order hook"18- "Build a dynamic fee hook"19- "Create a TWAMM hook"20- "Custom hook for V4"21- "Hook that charges higher fees during volatility"22- "Build a hook that distributes LP fees to stakers"23- "Create a hook with oracle integration"2425## Parameters2627| Parameter | Required | Default | Description |28| --- | --- | --- | --- |29| behavior | Yes | -- | Hook behavior description (e.g., "limit orders", "dynamic fees", "TWAMM", "oracle-based pricing") |30| callbacks | No | Auto-detect | Specific V4 callbacks if the user knows them (e.g., "beforeSwap, afterSwap") |31| constraints | No | -- | Gas budget, security requirements, or specific design constraints |32| chain | No | ethereum | Target chain for deployment (affects PoolManager address) |3334## Workflow35361. **Extract parameters** from the user's request: identify the hook behavior, any explicitly mentioned callbacks, constraints, and target chain.37382. **Delegate to hook-builder**: Invoke `Task(subagent_type:hook-builder)` with the full context. The hook-builder agent will:39 - Understand the requirements and determine which callbacks are needed40 - Map callbacks to hook flags and validate the flag combination41 - Generate a Solidity contract extending BaseHook with proper NatSpec42 - Generate comprehensive Foundry tests (unit, integration, edge cases, gas snapshots)43 - Mine a CREATE2 salt that produces an address encoding the required flags44 - Produce a deployment script with verification steps45463. **Present results** to the user with a summary covering:47 - Files written (contract path, test path, deployment script path)48 - Hook architecture explanation (what it does, how state flows)49 - Callbacks implemented and their flag bitmask50 - Gas estimates per callback (from Foundry test output)51 - Next steps for the developer (run tests, deploy to testnet, mainnet considerations)5253## Output Format5455Present a summary followed by the generated files:5657```text58V4 Hook Built: LimitOrderHook5960 Contract: src/hooks/LimitOrderHook.sol (187 lines)61 Tests: test/hooks/LimitOrderHook.t.sol (12 tests)62 Deployment: script/DeployLimitOrderHook.s.sol6364 Callbacks: beforeSwap, afterSwap65 Flags: 0x00C066 CREATE2: Salt mined, address verified6768 Gas Estimates:69 beforeSwap: ~45,000 gas70 afterSwap: ~32,000 gas71 Total overhead per swap: ~77,000 gas7273 Architecture:74 Orders are placed at specific ticks and stored in an on-chain order book.75 During beforeSwap, the hook checks for matching orders at the target tick.76 Matched orders are filled atomically within the same transaction.7778 Next Steps:79 1. Run tests: forge test --match-contract LimitOrderHookTest80 2. Deploy to testnet: forge script script/DeployLimitOrderHook.s.sol --rpc-url sepolia81 3. Verify on Etherscan: forge verify-contract <address> LimitOrderHook82```8384## Important Notes8586- This skill delegates entirely to the `hook-builder` agent -- it does not call MCP tools directly.87- The hook-builder generates production-quality Solidity code with reentrancy protection and access control.88- CREATE2 address mining ensures the deployed address encodes the correct hook flags in its leading bytes (required by V4 PoolManager).89- Foundry must be installed for test generation and compilation. If not found, the skill will provide installation instructions.90- Generated code uses Solidity ^0.8.26 and imports from `@uniswap/v4-core` and `@uniswap/v4-periphery`.9192## Error Handling9394| Error | User-Facing Message | Suggested Action |95| --- | --- | --- |96| `INVALID_CALLBACK_COMBINATION` | "The requested behavior requires conflicting callbacks." | Simplify hook behavior or split into multiple hooks |97| `CREATE2_MINING_TIMEOUT` | "Could not mine a valid CREATE2 address within time limit." | Increase mining time limit or reduce required flags |98| `FORGE_NOT_INSTALLED` | "Foundry (forge) is required but not installed." | Install: `curl -L https://foundry.paradigm.xyz \| bash && foundryup` |99| `VAGUE_REQUIREMENTS` | "Need more detail about the desired hook behavior." | Describe specific behavior (e.g., "limit orders that execute at tick boundaries") |100| `COMPILATION_ERROR` | "Generated contract has compilation errors." | Review error output and adjust requirements |