A Uniswap V4 hook designed to protect liquidity providers from impermanent loss by providing compensation in BTB tokens.
The BTB Liquidity Protection Hook is a sophisticated smart contract that integrates with Uniswap V4 pools to provide protection against impermanent loss for liquidity providers. When LPs experience a loss upon removing their liquidity, they receive compensation in BTB tokens based on the USD value of their loss.
- Tracks initial USD value of liquidity provided
- Calculates losses when liquidity is removed
- Automatically compensates LPs with BTB tokens for their losses
- Supports multiple positions per user
- Owner-controlled BTB token address and price settings
- Voter share system for potential governance decisions
- Impermanent Loss (IL) reserve for future enhancements
- Owner can update BTB token address and price
- Owner can manage voter shares
- Emergency functions to recover tokens or ETH
- IL reserve funding mechanism
- BTB tokens are used as the compensation currency
- Token price is maintained in USD (18 decimal precision)
- Example: If 1 BTB = $1, then
btbTokenPrice = 1e18
- Records initial USD value when liquidity is added
- Compares final value when liquidity is removed
- Calculates loss and provides appropriate compensation
beforeAddLiquidity: Pass-through callbackafterAddLiquidity: Records initial investment valuebeforeRemoveLiquidity: Pass-through callbackafterRemoveLiquidity: Calculates loss and provides compensationbeforeSwap&afterSwap: Pass-through callbacks
- Add liquidity to a Uniswap V4 pool using this hook
- Your initial investment value is automatically recorded
- When removing liquidity:
- If value has decreased: Receive BTB tokens as compensation
- If value has increased or stayed same: No compensation needed
- Set BTB token address:
hook.setBTBToken(address _btbToken)- Update BTB token price:
hook.setBTBTokenPrice(uint256 newPrice)- Manage voter shares:
hook.updateVoterShares(address voter, uint256 shares)- Fund IL reserve:
hook.fundILReserve(uint256 amount)- All admin functions are protected by OpenZeppelin's
Ownable - Zero-address checks for critical parameters
- Balance checks before token transfers
- ETH receiving capability for future enhancements
VoterSharesUpdated: Emitted when voter shares are modifiedILReserveFunded: Emitted when IL reserve receives fundingILCompensationPaid: Emitted when compensation is paid to an LPBTBTokenUpdated: Emitted when BTB token address is updatedBTBTokenPriceUpdated: Emitted when BTB token price is updated
- OpenZeppelin Contracts v5.2.0
- Uniswap V4 Core
- Uniswap V4 Periphery
- Foundry
- Node.js
- Git
git clone https://github.com/your-repo/BTBLiquidityProtection
cd BTBLiquidityProtection
forge installforge testMIT