Index / JitVault
pattern · MIT · last updated 2026-08-27
JitVault
JIT lock blocks LP ops during swap; optional output skim accrues to vault balances.
First-party teaching hook inspired by Uniswap DualPoolHook. beforeSwap sets jitActive; beforeAddLiquidity and beforeRemoveLiquidity revert while active. afterSwap clears the lock and optionally skims skimBps of swap output into per-pool vault0/vault1 balances held by the hook. No ERC4626 or bucket deployment — study the lifecycle gate only. Experimental. Forge tests in test/JitVault.t.sol. Listing is not an audit.
Permission bits
These bits must match the deployed address. Confirm on-chain before you route.
beforeAddLiquiditybeforeRemoveLiquiditybeforeSwapafterSwapafterSwapReturnDelta
Solidity
Excerpt from contracts/JitVault.sol. Copy the full file to implement this. Not an audit.
// SPDX-License-Identifier: MIT
function _beforeSwap(...) internal override returns (bytes4, BeforeSwapDelta, uint24) {
jitActive[key.toId()] = true;
return (this.beforeSwap.selector, BeforeSwapDeltaLibrary.ZERO_DELTA, 0);
}
function _afterSwap(...) internal override returns (bytes4, int128) {
jitActive[id] = false;
// skim skimBps of output into vault0/vault1
}Spec
| Kind | pattern |
|---|---|
| Status | experimental |
| License | MIT |
| Source | https://github.com/CryptoGnome/v4hooks |
| Categories | LP managementMEV protection |
| Properties | Vanilla swap |
| Chains | Ethereum |
FAQ
Can I paste this into production? The snippet is an excerpt. Use the full file at the source URL, match flags to the address, and treat this page as a map, not a guarantee.
How do I build this safely? Start with secure v4 hooks and the OpenZeppelin hooks guide.