Hook Contracts Developer Guide
Hook Contracts
Few Protocol provides specialized Uniswap V4 Hook contracts that enable seamless integration between Few Wrapped Tokens and Uniswap V4 pools. These hooks automatically handle token wrapping/unwrapping during trading operations.
Overview
Hook contracts act as middleware between Uniswap V4 pools and Few Protocol's wrapped tokens, providing:
Automatic Token Wrapping: Converts underlying tokens to Few Wrapped Tokens during liquidity provision
Seamless Trading: Users can trade with underlying tokens while the pool operates with wrapped tokens
Gas Optimization: Reduces transaction costs by batching operations
Enhanced Liquidity: Enables deeper liquidity pools with wrapped token benefits
Available Hook Contracts
FewTokenHook
Purpose: Universal hook for ERC20 tokens (USDC, DAI, CBBTC, etc.)
Features:
Supports all standard ERC20 tokens except USDT
1:1 wrapping/unwrapping ratio
Automatic approval management
Compatible with most modern tokens
Use Cases:
USDC β fwUSDC pools
DAI β fwDAI pools
CBBTC β fwCBBTC pools
Any standard ERC20 β Few Wrapped Token pools
FewETHHook
Purpose: Specialized hook for ETH/WETH integration
Features:
Native ETH support
WETH compatibility
Optimized for Ethereum's native currency
Gas-efficient ETH handling
Use Cases:
ETH β fwETH pools
WETH β fwETH pools
Native Ethereum trading pairs
FewUSDTHook
Purpose: Specialized hook for USDT integration
Features:
SafeERC20 compatibility for USDT's non-standard approve function
Handles USDT's unique implementation quirks
Secure approval management
Use Cases:
USDT β fwUSDT pools
Legacy token compatibility
How Hook Contracts Work
1. Pool Initialization
When a Uniswap V4 pool is created with a Hook contract:
Pool: Token A / Few Wrapped Token B (with Hook)
2. Liquidity Provision
Users provide liquidity with underlying tokens:
User provides: Token A + Token B
Hook converts: Token A β Few Wrapped Token A, Token B β Few Wrapped Token B
Pool receives: Few Wrapped Token A + Few Wrapped Token B
3. Trading Operations
Users trade with underlying tokens seamlessly:
User swaps: Token A β Token B
Hook converts: Token A β Few Wrapped Token A (input conversion)
Pool executes: Few Wrapped Token A β Few Wrapped Token B
Hook converts: Few Wrapped Token B β Token B (output conversion)
User receives: Token B
4. Liquidity Removal
Users withdraw underlying tokens:
Pool returns: Few Wrapped Token A + Few Wrapped Token B
Hook converts: Few Wrapped Token A β Token A, Few Wrapped Token B β Token B
User receives: Token A + Token B
Integration Benefits
For Traders
Familiar Interface: Trade with standard tokens (USDC, ETH, etc.)
Enhanced Features: Access Few Protocol benefits transparently
Lower Costs: Optimized gas usage through hook automation
Better Rates: Deeper liquidity from wrapped token pools
For Liquidity Providers
Dual Benefits: Earn trading fees + Few Protocol rewards
Risk Management: Maintain exposure to underlying assets
Simplified Operations: Automatic wrapping/unwrapping
Capital Efficiency: Single-sided liquidity provision support
For Developers
Easy Integration: Standard Uniswap V4 interface
Flexible Architecture: Support for various token types
Extensible Design: Custom hooks for specific needs
Battle-tested Code: Audited and production-ready
Contract Addresses
Technical Specifications
Hook Flags
All Few Protocol hooks implement the following Uniswap V4 flags:
BEFORE_SWAP_FLAG
: Pre-swap token conversionBEFORE_ADD_LIQUIDITY_FLAG
: Pre-liquidity token wrappingBEFORE_SWAP_RETURNS_DELTA_FLAG
: Delta handling for conversionsBEFORE_INITIALIZE_FLAG
: Pool initialization setup
Security Features
Address Validation: Ensures correct token pairing
Overflow Protection: SafeMath operations throughout
Reentrancy Guards: Protection against reentrancy attacks
Access Controls: Proper permission management
Gas Optimization
Batch Operations: Multiple actions in single transaction
Efficient Storage: Optimized state variable usage
Minimal External Calls: Reduced cross-contract interactions
Assembly Optimizations: Critical path optimizations
Integration Guide
For Pool Creators
Choose the Right Hook: Select based on your token type
Deploy Pool: Use Uniswap V4 PoolManager with hook address
Initialize: Set initial price and liquidity
Test: Verify wrapping/unwrapping functionality
For Frontend Developers
Standard Interface: Use normal Uniswap V4 SDK calls
Token Display: Show underlying tokens to users
Transaction Handling: Let hooks manage conversions automatically
Error Handling: Implement proper error catching
Example Integration
// Create pool with FewTokenHook
IPoolManager.PoolKey memory key = IPoolManager.PoolKey({
currency0: Currency.wrap(USDC_ADDRESS),
currency1: Currency.wrap(FW_USDC_ADDRESS),
fee: 3000,
tickSpacing: 60,
hooks: IHooks(FEW_TOKEN_HOOK_ADDRESS)
});
poolManager.initialize(key, SQRT_RATIO_1_1, ZERO_BYTES);
Security: Never send tokens directly to hook contract addresses. Always interact through Uniswap V4 PoolManager.
Last updated