This repository contains example implementations of Uniswap v4 hooks demonstrating advanced DeFi functionality. It includes two main hooks: Take Profits Hook and Points Hook.
A smart contract that enables limit order-like functionality for taking profits at specified price points in Uniswap v4 pools.
A rewards system that distributes points to users who provide liquidity or trade in specific pools, with additional referral mechanics.
- Place limit orders at specific price points (ticks)
- Automatic order execution when price crosses specified ticks
- ERC1155-based position management
- Support for both trading directions (token0 → token1 and token1 → token0)
- Multiple orders at different price points
- Partial order execution and cancellation
-
Order Placement
- Validates tick spacing
- Transfers input tokens
- Mints ERC1155 claim tokens
- Updates pending orders
-
Order Execution
- Monitors price changes via afterSwap
- Executes matching orders
- Updates claimable balances
- Handles token settlements
-
Position Management
- Unique position IDs per pool/tick/direction
- Claim token accounting
- Order cancellation logic
- Rewards for liquidity provision and trading
- Referral system with bonus points
- Native ETH pool integration
- Automatic point distribution
- ERC20-based points token
-
Reward Distribution
- Tracks user referrals
- Calculates points based on activity
- Handles referral bonuses
-
Activity Monitoring
- afterSwap hook for trade rewards
- afterAddLiquidity for LP rewards
- ETH amount tracking
- Order placement and cancellation
- Single and multiple order execution
- Direction-specific order execution
- Edge cases and token accounting
- Basic point distribution
- Referral system
- Liquidity provision rewards
- Swap rewards
- Access control via onlyByPoolManager
- Safe token transfer handling
- Proper accounting and state management
- Input validation
- Reentrancy protection
- Uniswap v4 Core & Periphery
- OpenZeppelin Contracts
- Solmate
- Forge Standard Library