Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Uniswap V4 Hook Development

This project demonstrates how to build a custom Uniswap V4 hook using Hardhat.

Project Structure

├── 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

Hook Example: FeeCollectorHook

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

Key Hook Functions

beforeSwap

Called before a swap is executed. Use this to:

  • Validate swap parameters
  • Apply pre-swap logic
  • Modify swap behavior

afterSwap

Called after a swap is completed. Use this to:

  • Collect fees
  • Update state based on swap results
  • Emit events

Setup

  1. Install dependencies:
npm install
  1. Compile contracts:
npm run compile
  1. Run tests:
npm run test
  1. Deploy to local network:
npx hardhat node
npm run deploy

About

a custom Uniswap V4 hook using Hardhat.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages