Github: https://github.com/impetus82/il-aware-limit-order-hook Slides: Project Link: https://il-aware-hook.vercel.app Demo Video: https://youtu.be/eikjiI5kq8I
On-chain limit orders are idle capital: your tokens sit locked in the order earning nothing while they wait to fill - and the moment the order fills, you've effectively sold into a moving market and eaten impermanent loss versus simply holding. I wanted a limit order that does the opposite: it puts the capital to work earning yield while it waits, and uses that yield to compensate the user for the IL they incur on the fill - entirely on-chain, with no trusted oracle.
It fuses two things that are normally separate - execution (limit orders) and capital efficiency (yield + IL protection) - into one Uniswap V4 hook. Impermanent loss is computed on-chain from the pool's own sqrtPriceX96 via a Taylor approximation (the pool is the oracle), and the rebate is provably bounded at min(yield, IL), so the system is always solvent. Orders are minted as ERC-721 NFTs, making a resting or filled order a composable, tradeable asset. As a default primitive, every limit order on Uniswap could become yield-bearing and IL-aware by default.
The hardest part was computing impermanent loss on-chain without an oracle - deriving it from sqrtPriceX96 with a Taylor approximation that stays gas-cheap and accurate. On top of that: keeping the hook solvent and DoS-resistant with graceful execution that never reverts the whole swap and degrades safely when a vault redeem or slippage check fails; O(1) tick-bucket bookkeeping so order discovery doesn't blow up gas; and using V4 flash accounting for exact settlement with no custom token accounting. Covering the edge cases - lossy vault redeem, partial fills, slippage - to 53 passing tests took real effort.