A Uniswap V4 hook implementation providing advanced liquidity protection mechanisms, featuring impermanent loss protection and enhanced fee distribution. Built with Foundry for Ethereum development.
Core Protection Mechanisms:
- Impermanent Loss Protection with reserve pool
- Dynamic Fee Distribution:
- 80% to Liquidity Providers
- 15% to IL Protection Reserve
- 5% to Governance Token Holders
- Liquidity Provider Rewards System
- Position Management Utilities
Advanced Functionality:
- Chainlink Price Feed Integration
- Flexible Hook Permissions:
- Before/After Add/Remove Liquidity
- Before/After Swap
- Delta Return capabilities
- CREATE2 Deployment Support
- LiquidityProtectionHook.sol
Main hook contract inheriting from Uniswap v4's BaseHook - BTBHook.sol
Core implementation for position tracking and fee management - MockPriceFeed.sol
Test implementation of Chainlink's AggregatorV3Interface - HookDeployer.sol
CREATE2 utility for deterministic deployments
- Price Oracle: Chainlink with fallback mechanisms
- Fee Distribution: Atomic operations with reentrancy protection
- Access Control: Owner-restricted critical functions
- Foundry
- Solidity ^0.8.26
- Node.js (for deployment scripts)
# Clone repository
git clone https://github.com/btb-finance/BTBLiquidityProtection.git
cd BTBLiquidityProtection
# Install dependencies
forge install
# Build project
forge build
# Run all tests
forge test --ffi
# Run specific test with verbosity
forge test --match-test test_HookRegistration -vvv
# Deploy to network
forge script script/Deploy.s.sol:Deploy --rpc-url $RPC_URL --private-key $PRIVATE_KEY
# Verify contract
forge verify-contract $CONTRACT_ADDRESS src/hooks/LiquidityProtectionHook.sol:LiquidityProtectionHook
// Set price feed for pool
hook.setPriceFeed(poolKey, PRICE_FEED_ADDRESS);
// Update voter shares
hook.updateVoterShares(voterAddress, newShares);
// Claim IL protection
hook.claimILProtection(poolKey, positionId);
- Price Reliability: Chainlink feeds with fallback mechanisms
- Access Controls: Owner-restricted critical functions
- Fee Safety: Atomic distribution operations
- Reentrancy Protection: Secure modifiers on all hook functions
- Fork the repository
- Create feature branch:
git checkout -b feature/new-feature
- Commit changes:
git commit -m 'Add new feature'
- Push to branch:
git push origin feature/new-feature
- Open Pull Request
MIT - See LICENSE for details
- Uniswap v4 Team for hook architecture
- Chainlink for oracle infrastructure
- OpenZeppelin for security patterns
- Paradigm for Foundry toolkit