This project demonstrates how to build a custom Uniswap V4 hook using Hardhat.
├── contracts/
│ ├── interfaces/ # Core V4 interfaces
│ ├── BaseHook.sol # Abstract base hook contract
│ └── FeeCollectorHook.sol # Example hook implementation
├── test/ # Test files
├── scripts/ # Deployment scripts
└── hardhat.config.js # Hardhat configuration
The FeeCollectorHook
demonstrates a practical V4 hook that:
- Collects a small fee (0.1% by default) on each swap
- Allows the owner to adjust fee rates
- Tracks collected fees per token
- Emits events for fee collection
Called before a swap is executed. Use this to:
- Validate swap parameters
- Apply pre-swap logic
- Modify swap behavior
Called after a swap is completed. Use this to:
- Collect fees
- Update state based on swap results
- Emit events
- Install dependencies:
npm install
- Compile contracts:
npm run compile
- Run tests:
npm run test
- Deploy to local network:
npx hardhat node
npm run deploy