General

This document is better viewed on the docs page.

Ready-to-use hooks built on top of the base and fee abstract contracts

Hooks

LiquidityPenaltyHook

import "uniswap-hooks/src/general/LiquidityPenaltyHook.sol";

Just-in-Time (JIT) liquidity provisioning resistant hook.

This hook disincentivizes JIT attacks by penalizing LP fee collection during _afterRemoveLiquidity, and disabling it during _afterAddLiquidity if liquidity was recently added to the position. The penalty is donated to the pool’s liquidity providers in range at the time of removal.

See _calculateLiquidityPenalty for penalty calculation.

If a long term liquidity provider adds liquidity continuously, a pause of blockNumberOffset before removing will be needed if feesAccrued collection is intended, in order to avoid getting penalized by the JIT protection mechanism.
Altrough this hook achieves it’s objective of protecting long term LP’s in most scenarios, low liquidity pools and long-tail assets may still be vulnerable depending on the configured blockNumberOffset. Larger values of such are recommended in those cases in order to decrease the profitability of the attack.
In low liquidity pools, this hook may be vulnerable to multi-account strategies: attackers may bypass JIT protection by using a secondary account to add minimal liquidity at a target tick with no other liquidity, then moving the price there after a JIT attack. This allows penalty fees to be redirected to the attacker’s secondary account. While technically feasible, this attack is rarely profitable in practice, due to the cost associated with moving the price to the target tick.
This is experimental software and is provided on an "as is" and "as available" basis. We do not give any warranties and will not be liable for any losses incurred through any use of this code base.

Available since v0.1.1

constructor(contract IPoolManager _poolManager, uint48 _blockNumberOffset) public

Sets the PoolManager address and the {getBlockNumberOffset}.

_afterAddLiquidity(address sender, struct PoolKey key, struct ModifyLiquidityParams params, BalanceDelta, BalanceDelta feeDelta, bytes) → bytes4, BalanceDelta internal

Tracks lastAddedLiquidityBlock and withholds feeDelta if liquidity was recently added within the blockNumberOffset period.

See _afterRemoveLiquidity for claiming the withheld fees back.

_afterRemoveLiquidity(address sender, struct PoolKey key, struct ModifyLiquidityParams params, BalanceDelta, BalanceDelta feeDelta, bytes) → bytes4, BalanceDelta internal

Penalizes the collection of any existing LP feesDelta and withheldFees after liquidity removal if liquidity was recently added to the position.

The penalty is applied on both withheldFees and feeDelta equally. Therefore, regardless of how many times liquidity was added to the position within the blockNumberOffset period, all accrued fees are penalized as if the liquidity was added only once during that period. This ensures that splitting liquidity additions within the blockNumberOffset period does not reduce or increase the penalty.
The penalty is donated to the pool’s liquidity providers in range at the time of liquidity removal, which may be different from the liquidity providers in range at the time of liquidity addition.

_getBlockNumber() → uint48 internal

Returns the current block number.

_updateLastAddedLiquidityBlock(PoolId poolId, bytes32 positionKey) internal

Updates the lastAddedLiquidityBlock for a liquidity position.

_takeFeesToHook(struct PoolKey key, bytes32 positionKey, BalanceDelta feeDelta) internal

Takes feeDelta from a liquidity position as withheldFees into this hook.

_settleFeesFromHook(struct PoolKey key, bytes32 positionKey) → BalanceDelta withheldFees internal

Returns withheldFees from this hook to the liquidity provider.

_calculateLiquidityPenalty(BalanceDelta feeDelta, uint48 lastAddedLiquidityBlock) → BalanceDelta liquidityPenalty internal

Calculates the penalty to be applied to JIT liquidity provisioning.

The penalty is calculated as a linear function of the block number difference between the lastAddedLiquidityBlock and the currentBlockNumber.

The used formula is:

liquidityPenalty = feeDelta * ( 1 - (currentBlockNumber - lastAddedLiquidityBlock) / blockNumberOffset)

As a result, the penalty is 100% at the same block where liquidity was last added and zero after the blockNumberOffset block time window.

Won’t overflow if currentBlockNumber - lastAddedLiquidityBlock < blockNumberOffset is verified prior to calling this function.

getLastAddedLiquidityBlock(PoolId poolId, bytes32 positionKey) → uint48 public

Tracks the lastAddedLiquidityBlock for a liquidity position.

lastAddedLiquidityBlock is the block number when liquidity was last added to the position.

getWithheldFees(PoolId poolId, bytes32 positionKey) → BalanceDelta public

Returns the withheldFees for a liquidity position.

withheldFees are UniswapV4’s feesAccrued retained by this hook during liquidity addition if liquidity has been recently added within the blockNumberOffset block time window, with the purpose of disabling fee collection during JIT liquidity provisioning attacks. See _afterRemoveLiquidity for claiming the fees back.

getHookPermissions() → struct Hooks.Permissions permissions public

Set the hooks permissions, specifically afterAddLiquidity, afterAddLiquidityReturnDelta, afterRemoveLiquidity and afterRemoveLiquidityReturnDelta.

MIN_BLOCK_NUMBER_OFFSET() → uint48 public

The minimum value for the blockNumberOffset.

blockNumberOffset() → uint48 public

The minimum time window (in blocks) that must pass after adding liquidity before it can be removed without any penalty. During this period, JIT attacks are deterred through fee withholding and penalties. Higher values provide stronger JIT protection but may discourage legitimate LPs.

BlockNumberOffsetTooLow() error

The hook was attempted to be constructed with a blockNumberOffset lower than MIN_BLOCK_NUMBER_OFFSET.

NoLiquidityToReceiveDonation() error

A penalty was attempted to be applied and donated to LP’s in range, but there aren’t any.

AntiSandwichHook

import "uniswap-hooks/src/general/AntiSandwichHook.sol";

This hook implements the sandwich-resistant AMM design introduced here. Specifically, this hook guarantees that no swaps get filled at a price better than the price at the beginning of the slot window (i.e. one block).

Within a slot window, swaps impact the pool asymmetrically for buys and sells. When a buy order is executed, the offer on the pool increases in accordance with the xy=k curve. However, the bid price remains constant, instead increasing the amount of liquidity on the bid. Subsequent sells eat into this liquidity, while decreasing the offer price according to xy=k.

In order to use this hook, the inheriting contract must implement the {_handleCollectedFees} function to determine how to handle the collected fees from the anti-sandwich mechanism.

The Anti-sandwich mechanism only protects swaps in the zeroForOne swap direction. Swaps in the !zeroForOne direction are not protected by this hook design.
Since this hook makes MEV not profitable, there’s not as much arbitrage in the pool, making prices at beginning of the block not necessarily close to market price.
In _beforeSwap, the hook iterates over all ticks between last tick and current tick. Developers must be aware that for large price changes in pools with small tick spacing, the for loop will iterate over a large number of ticks, which could lead to MemoryOOG error.
This is experimental software and is provided on an "as is" and "as available" basis. We do not give any warranties and will not be liable for any losses incurred through any use of this code base.

Available since v1.1.0

constructor(contract IPoolManager _poolManager) internal

_beforeSwap(address sender, struct PoolKey key, struct SwapParams params, bytes hookData) → bytes4, BeforeSwapDelta, uint24 internal

Handles the before swap hook.

For the first swap in a block, it saves the current pool state as a checkpoint.

For subsequent swaps in the same block, it calculates a target output based on the beginning-of-block state, and sets the inherited _targetOutput and _applyTargetOutput variables to enforce price limits in {_afterSwap}.

_getBlockNumber() → uint48 internal

Returns the current block number.

_getTargetUnspecified(address, struct PoolKey key, struct SwapParams params, bytes) → uint256 targetUnspecifiedAmount, bool applyTarget internal

Calculates the unspecified amount based on the pool state at the beginning of the block. This prevents sandwich attacks by ensuring trades can’t get better prices than what was available at the start of the block. Note that the calculated unspecified amount could either be input or output, depending if it’s an exactInput or outputOutput swap. In cases of zeroForOne == true, the target unspecified amount is not applicable, and the max uint256 value is returned as a flag only.

The anti-sandwich mechanism works such as:

  • For currency0 to currency1 swaps (zeroForOne = true): The pool behaves normally with xy=k curve.

  • For currency1 to currency0 swaps (zeroForOne = false): The price is fixed at the beginning-of-block price, which prevents attackers from manipulating the price within a block.

getHookPermissions() → struct Hooks.Permissions permissions public

Set the hook permissions, specifically beforeSwap, afterSwap, and afterSwapReturnDelta.

LimitOrderHook

import "uniswap-hooks/src/general/LimitOrderHook.sol";

Limit Order Mechanism hook.

Allows users to place limit orders at specific ticks outside of the current price range, which will be filled if the pool’s price crosses the order’s tick.

Note that given the way UniswapV4 pools works, when liquidity is added out of the current range, a single currency will be provided, instead of both currencies as in in-range liquidity additions.

Orders can be cancelled at any time until they are filled and their liquidity is removed from the pool. Once completely filled, the resulting liquidity can be withdrawn from the pool.

When cancelling or adding more liquidity into an existing order, it’s possible that fees have been accrued. In those cases, the accrued fees are added to the order info, benefitting the remaining limit order placers.
This is experimental software and is provided on an "as is" and "as available" basis. We do not give any warranties and will not be liable for any losses incurred through any use of this code base.

Available since v1.1.0

constructor(contract IPoolManager _poolManager) public

Set the PoolManager address.

_afterInitialize(address, struct PoolKey key, uint160, int24 tick) → bytes4 internal

Hooks into the afterInitialize hook to set the last tick lower for the pool.

_afterSwap(address, struct PoolKey key, struct SwapParams params, BalanceDelta, bytes) → bytes4, int128 internal

Hooks into the afterSwap hook to get the ticks crossed by the swap and fill the orders that are crossed, filling them.

placeOrder(struct PoolKey key, int24 tick, bool zeroForOne, uint128 liquidity) public

Places a limit order by adding liquidity out of range at a specific tick. The order will be filled when the pool price crosses the specified tick. Takes a PoolKey key, target tick, direction zeroForOne indicating whether to buy currency0 or currency1, and amount of liquidity to place. The interaction with the poolManager is done via the unlock function, which will trigger the unlockCallback function.

cancelOrder(struct PoolKey key, int24 tickLower, bool zeroForOne, address to) public

Cancels a limit order by removing liquidity from the pool. Takes a PoolKey key, tickLower of the order, direction zeroForOne indicating whether it was buying currency0 or currency1, and recipient address to for the removed liquidity. Note that partial cancellation is not supported - the entire liquidity added by the msg.sender will be removed. Note also that cancelling an order will cancel the order placed by the msg.sender, not orders placed by other users in the same tick range. The interaction with the poolManager is done via the unlock function, which will trigger the unlockCallback function.

withdraw(OrderIdLibrary.OrderId orderId, address to) → uint256 amount0, uint256 amount1 public

Withdraws liquidity from a filled order, sending it to address to. Takes an OrderId orderId of the filled order to withdraw from. Returns the withdrawn amounts as (amount0, amount1). Can only be called after the order is filled - use cancelOrder to remove liquidity from unfilled orders. The interaction with the poolManager is done via the unlock function, which will trigger the unlockCallback function.

unlockCallback(bytes rawData) → bytes returnData public

Handles callbacks from the PoolManager for order operations. Takes encoded rawData containing the callback type and operation-specific data. Returns encoded data containing fees accrued for cancel operations, or empty bytes otherwise. Only callable by the PoolManager.

_handlePlaceCallback(struct LimitOrderHook.PlaceCallbackData placeData) → uint256 amount0Fee, uint256 amount1Fee internal

Internal handler for place order callbacks. Takes placeData containing the order details and adds the specified liquidity to the pool out of range. Reverts if the order would be placed in range or on the wrong side of the range.

_handleCancelCallback(struct LimitOrderHook.CancelCallbackData cancelData) → uint256 amount0Fee, uint256 amount1Fee internal

Internal handler for cancel order callbacks. Takes cancelData containing the cancellation details and removes liquidity from the pool. Returns accrued fees (amount0Fee, amount1Fee) which are allocated to remaining limit order placers, or to the cancelling user if they’re removing all liquidity.

_handleWithdrawCallback(struct LimitOrderHook.WithdrawCallbackData withdrawData) internal

Internal handler for withdraw callbacks. Takes withdrawData containing withdrawal amounts and recipient, burns the specified currency amounts from the hook, and transfers them to the recipient address.

_fillOrder(struct PoolKey key, int24 tickLower, bool zeroForOne) internal

Internal handler for filling limit orders when price crosses a tick. Takes a PoolKey key, target tickLower, and direction zeroForOne. Removes liquidity from filled orders, mints the received currencies to the hook, and updates order state to track filled amounts.

_getCrossedTicks(PoolId poolId, int24 tickSpacing) → int24 tickLower, int24 lower, int24 upper internal

Internal helper that calculates the range of ticks crossed during a price change. Takes a PoolId poolId and tickSpacing, returns the current tickLower and the range of ticks crossed (lower, upper) that need to be checked for limit orders.

getTickLowerLast(PoolId poolId) → int24 public

Returns the last recorded lower tick for a given pool. Takes a PoolId poolId and returns the stored tickLowerLast value.

getOrderId(struct PoolKey key, int24 tickLower, bool zeroForOne) → OrderIdLibrary.OrderId public

Retrieves the order id for a given pool position. Takes a PoolKey key, target tickLower, and direction zeroForOne indicating whether it’s buying currency0 or currency1. Returns the {OrderId} associated with this position, or the default order id if no order exists.

_getTickLower(int24 tick, int24 tickSpacing) → int24 internal

Get the tick lower. Takes a tick and tickSpacing and returns the nearest valid tick boundary at or below the input tick, accounting for negative tick handling.

getOrderLiquidity(OrderIdLibrary.OrderId orderId, address owner) → uint256 external

Get the liquidity of an order for a given order id and owner. Takes an {OrderId} orderId and owner address and returns the amount of liquidity the owner has contributed to the order.

_getTick(PoolId poolId) → int24 tick internal

Get the current tick for a given pool. Takes a PoolId poolId and returns the tick calculated from the pool’s current sqrt price.

getOrderInfo(OrderIdLibrary.OrderId orderId) → bool filled, Currency currency0, Currency currency1, uint256 currency0Total, uint256 currency1Total, uint128 liquidityTotal external

Get the order info for a given order id. Takes an {OrderId} orderId and returns the order info.

getHookPermissions() → struct Hooks.Permissions permissions public

Get the hook permissions for this contract. Returns a Hooks.Permissions struct configured to enable afterInitialize and afterSwap hooks while disabling all other hooks.

Place(address indexed owner, OrderIdLibrary.OrderId indexed orderId, struct PoolKey key, int24 tickLower, bool zeroForOne, uint128 liquidity) event

Emitted when an owner places a limit order with the given orderId, in the pool identified by key, at the given tickLower, zeroForOne indicating the direction of the order, and liquidity the amount of liquidity added.

Fill(OrderIdLibrary.OrderId indexed orderId, struct PoolKey key, int24 tickLower, bool zeroForOne) event

Emitted when a limit order with the given orderId is filled in the pool identified by key, at the given tickLower, zeroForOne indicating the direction of the order.

Cancel(address indexed owner, OrderIdLibrary.OrderId indexed orderId, struct PoolKey key, int24 tickLower, bool zeroForOne, uint128 liquidity) event

Emitted when an owner cancels a limit order with the given orderId, in the pool identified by key, at the given tickLower, zeroForOne indicating the direction of the order, and liquidity the amount of liquidity removed.

Withdraw(address indexed owner, OrderIdLibrary.OrderId indexed orderId, uint128 liquidity) event

Emitted when an owner withdraws their liquidity from a limit order with the given orderId, in the pool identified by key, at the given tickLower, zeroForOne indicating the direction of the order.

ZeroLiquidity() error

Zero liquidity was attempted to be added or removed.

InRange() error

Limit order was placed in range.

CrossedRange() error

Limit order placed on the wrong side of the range.

Filled() error

Limit order was already filled.

NotFilled() error

Limit order is not filled.

bytes ZERO_BYTES internal constant

The zero bytes.

OrderIdLibrary.OrderId ORDER_ID_DEFAULT internal constant

The default order id, used to indicate that an order is not yet initialized.

ReHypothecationHook

import "uniswap-hooks/src/general/ReHypothecationHook.sol";

A Uniswap V4 hook that enables rehypothecation of liquidity positions.

This hook allows users to deposit assets into yield-generating sources (e.g., ERC-4626 vaults) while providing liquidity to Uniswap pools Just-in-Time (JIT) during swaps. Assets earn yield when idle and are temporarily injected as pool liquidity only when needed for swap execution, then immediately withdrawn back to yield sources.

Conceptually, the hook acts as an intermediary that manages: - the user-facing ERC20 share token (representing rehypothecated positions), and - the underlying relationship between yield sources and pool liquidity.

Key features: - Users can deposit assets into yield sources via the hook and receive ERC20 shares that represent their rehypothecated liquidity position. - The hook dynamically manages pool liquidity based on available yield source assets, performing JIT provisioning during swaps. - After swaps, assets are deposited back into yield sources to continue earning yield. - Supports both ERC20 tokens and native ETH by default.

By default, the hook liquidity position is placed in the entire curve range. Override the getTickLower and getTickUpper functions to customize the position.
By default, both canonical and rehypothecated liquidity modifications are allowed. Override beforeAddLiquidity and beforeRemoveLiquidity to disable canonical liquidity modifications if desired.
This hook relies on the PoolManager singleton token reserves for flash accounting during swaps. During afterSwap, the hook takes tokens from the PoolManager to settle deltas before users transfer their swap tokens. The PoolManager may lack sufficient reserves for illiquid tokens, preventing swaps until the PoolManager accumulates enough tokens for these small flash loans. This can be mitigated by maintaining some permanent pool liquidity alongside rehypothecated liquidity.
This is experimental software and is provided on an "as is" and "as available" basis. We do not give any warranties and will not be liable for any losses incurred through any use of this code base. Available since v1.1.0
Functions
ReentrancyGuardTransient
  • {xref-ReentrancyGuardTransient-_reentrancyGuardEntered--}[_reentrancyGuardEntered()]

ERC20
  • {xref-ERC20-name--}[name()]

  • {xref-ERC20-symbol--}[symbol()]

  • {xref-ERC20-decimals--}[decimals()]

  • {xref-ERC20-totalSupply--}[totalSupply()]

  • {xref-ERC20-balanceOf-address-}[balanceOf(account)]

  • {xref-ERC20-transfer-address-uint256-}[transfer(to, value)]

  • {xref-ERC20-allowance-address-address-}[allowance(owner, spender)]

  • {xref-ERC20-approve-address-uint256-}[approve(spender, value)]

  • {xref-ERC20-transferFrom-address-address-uint256-}[transferFrom(from, to, value)]

  • {xref-ERC20-_transfer-address-address-uint256-}[_transfer(from, to, value)]

  • {xref-ERC20-_update-address-address-uint256-}[_update(from, to, value)]

  • {xref-ERC20-_mint-address-uint256-}[_mint(account, value)]

  • {xref-ERC20-_burn-address-uint256-}[_burn(account, value)]

  • {xref-ERC20-_approve-address-address-uint256-}[_approve(owner, spender, value)]

  • {xref-ERC20-_approve-address-address-uint256-bool-}[_approve(owner, spender, value, emitEvent)]

  • {xref-ERC20-_spendAllowance-address-address-uint256-}[_spendAllowance(owner, spender, value)]

Events
IERC20
  • {xref-IERC20-Transfer-address-address-uint256-}[Transfer(from, to, value)]

  • {xref-IERC20-Approval-address-address-uint256-}[Approval(owner, spender, value)]

Errors
ReentrancyGuardTransient
  • {xref-ReentrancyGuardTransient-ReentrancyGuardReentrantCall--}[ReentrancyGuardReentrantCall()]

IERC20Errors
  • {xref-IERC20Errors-ERC20InsufficientBalance-address-uint256-uint256-}[ERC20InsufficientBalance(sender, balance, needed)]

  • {xref-IERC20Errors-ERC20InvalidSender-address-}[ERC20InvalidSender(sender)]

  • {xref-IERC20Errors-ERC20InvalidReceiver-address-}[ERC20InvalidReceiver(receiver)]

  • {xref-IERC20Errors-ERC20InsufficientAllowance-address-uint256-uint256-}[ERC20InsufficientAllowance(spender, allowance, needed)]

  • {xref-IERC20Errors-ERC20InvalidApprover-address-}[ERC20InvalidApprover(approver)]

  • {xref-IERC20Errors-ERC20InvalidSpender-address-}[ERC20InvalidSpender(spender)]

constructor(contract IPoolManager _poolManager) internal

Sets the PoolManager address.

getPoolKey() → struct PoolKey poolKey public

Returns the poolKey for the hook pool.

_beforeInitialize(address, struct PoolKey key, uint160) → bytes4 internal

Initialize the hook’s poolKey. The stored key by the hook is unique and should not be modified so that it can safely be used across the hook’s lifecycle.

Native ETH is supported by default, which can be disabled by overriding _beforeInitialize with:
function _beforeInitialize(address, PoolKey calldata key, uint160) internal override returns (bytes4) {
    if (key.currency0.isAddressZero()) revert UnsupportedCurrency();
    return super._beforeInitialize(key);
}

addReHypothecatedLiquidity(uint256 shares) → BalanceDelta delta public

Adds rehypothecated liquidity to yield sources and mints shares to the caller.

Liquidity is added in the ratio determined by the hook’s existing balances in yield sources. Assets are deposited into yield sources where they earn returns when idle and can be dynamically used as pool liquidity during swaps.

Returns a balance delta representing the assets deposited into the hook.

Requirements: - Pool must be initialized - Sender must have sufficient token balances - Sender must have approved the hook to spend the required tokens

removeReHypothecatedLiquidity(uint256 shares) → BalanceDelta delta public

Removes rehypothecated liquidity from yield sources and burns caller’s shares.

Liquidity is withdrawn in the ratio determined by the hook’s existing balances in yield sources. Assets are withdrawn from yield sources where they were generating yield, allowing users to exit their rehypothecated position and reclaim their underlying tokens.

Returns a balance delta representing the assets withdrawn from the hook.

Requirements: - Pool must be initialized - Sender must have sufficient shares for the desired liquidity withdrawal

_beforeSwap(address, struct PoolKey, struct SwapParams, bytes) → bytes4, BeforeSwapDelta, uint24 internal

Hook executed before a swap operation to provide liquidity from rehypothecated assets.

Gets the amount of liquidity to be provided from yield sources and temporarily adds it to the pool, in a Just-in-Time provision of liquidity.

Note that at this point there are no actual transfers of tokens happening to the pool, instead, thanks to the Flash Accounting model, this addition creates a currencyDelta to the hook, which must be settled during the _afterSwap function before locking the poolManager again.

_afterSwap(address, struct PoolKey key, struct SwapParams, BalanceDelta, bytes) → bytes4, int128 internal

Hook executed after a swap operation to remove temporary liquidity and rebalance assets.

Removes the liquidity that was temporarily added in _beforeSwap, and resolves the hook’s deltas in each currency in order to neutralize any pending debits or credits.

_resolveHookDelta(Currency currency) internal

Takes or settles any pending currencyDelta amount with the poolManager, neutralizing the Flash Accounting deltas before locking the poolManager again.

previewAmountsForShares(uint256 shares) → uint256 amount0, uint256 amount1 public

Preview the amounts of currency0 and currency1 required/obtained for a given amount of shares.

_convertSharesToAmounts(uint256 shares) → uint256 amount0, uint256 amount1 internal

Calculates the amounts of currency0 and currency1 required for adding a specific amount of shares.

If the hook has not emitted shares yet, the initial deposit ratio is determined by the current pool price. Otherwise, it is determined by ratio of the hook balances in the yield sources.

_shareToAmount(uint256 shares, Currency currency) → uint256 amount internal

Converts a given shares amount to the corresponding currency amount.

_getLiquidityToUse() → uint256 internal

Returns the liquidity to be provided just-in-time for incoming swaps.

By default, returns the maximum liquidity that can be provided with the current balances of the hook in the yield sources.

Since liquidity is provided and withdrawn transiently during flash accounting, it can be virtually inflated for performing "leveraged liquidity" strategies, which would give better pricing to swappers at the cost of the profitability of LP’s and increased risks.

_getHookPositionLiquidity() → uint128 liquidity internal

Retrieves the current liquidity of the hook owned liquidity position in the _poolKey pool.

Given that just-in-time liquidity provisioning is performed, this function will only return values larger than zero between beforeSwap and afterSwap, where the liquidity is actually inside the pool. It will return zero in any other point in the hook lifecycle. For determining the hook balances in any other point, use _getAmountInYieldSource.

getTickLower() → int24 public

Returns the lower tick boundary for the hook’s liquidity position.

Can be overridden to customize the tick boundary.

getTickUpper() → int24 public

Returns the upper tick boundary for the hook’s liquidity position.

Can be overridden to customize the tick boundary.

_modifyLiquidity(int256 liquidityDelta) → BalanceDelta delta internal

Modifies the hook’s liquidity position in the pool.

Positive liquidityDelta adds liquidity, while negative removes it.

_transferFromSenderToHook(Currency currency, uint256 amount, address sender) internal

_transferFromHookToSender(Currency currency, uint256 amount, address sender) internal

Transfers the amount of currency from the hook to the sender.

getCurrencyYieldSource(Currency currency) → address yieldSource public

Returns the yieldSource address for a given currency.

Note: Must be implemented and adapted for the desired type of yield sources, such as ERC-4626 Vaults, or any custom DeFi protocol interface, optionally handling native currency.

_depositToYieldSource(Currency currency, uint256 amount) internal

Deposits a specified amount of currency into its corresponding yield source.

Note: Must be implemented and adapted for the desired type of yield sources, such as ERC-4626 Vaults, or any custom DeFi protocol interface, optionally handling native currency.

_withdrawFromYieldSource(Currency currency, uint256 amount) internal

Withdraws a specified amount of currency from its corresponding yield source.

Note: Must be implemented and adapted for the desired type of yield sources, such as ERC-4626 Vaults, or any custom DeFi protocol interface, optionally handling native currency.

_getAmountInYieldSource(Currency currency) → uint256 amount internal

Gets the amount of currency deposited in its corresponding yield source.

Note: Must be implemented and adapted for the desired type of yield sources, such as ERC-4626 Vaults, or any custom DeFi protocol interface, optionally handling native currency.

getHookPermissions() → struct Hooks.Permissions permissions public

receive() external

Allows the hook to receive native ETH from the yield sources.

ReHypothecatedLiquidityAdded(address indexed sender, struct PoolKey indexed poolKey, uint256 shares, uint256 amount0, uint256 amount1) event

Emitted when a sender adds rehypothecated shares to the poolKey pool, transferring amount0 of currency0 and amount1 of currency1 to the hook.

ReHypothecatedLiquidityRemoved(address indexed sender, struct PoolKey indexed poolKey, uint256 shares, uint256 amount0, uint256 amount1) event

Emitted when a sender removes rehypothecated liquidity from the poolKey pool, receiving amount0 of currency0 and amount1 of currency1 from the hook.

AlreadyInitialized() error

Error thrown when trying to initialize a pool that has already been initialized.

NotInitialized() error

Error thrown when attempting to interact with a pool that has not been initialized.

ZeroShares() error

Error thrown when attempting to add or remove liquidity with zero shares.

InvalidMsgValue() error

Error thrown when the message value doesn’t match the expected amount for native ETH deposits.

RefundFailed() error

Error thrown when the refund fails.