Skip to main content
Helpful?

IPoolManager

Git Source | Generated with forge doc

Inherits: IProtocolFees, IERC6909Claims, IExtsload, IExttload

Interface for the PoolManager

Functions

unlock

All interactions on the contract that account deltas require unlocking. A caller that calls unlock must implement IUnlockCallback(msg.sender).unlockCallback(data), where they interact with the remaining functions on this contract.

The only functions callable without an unlocking are initialize and updateDynamicLPFee

function unlock(bytes calldata data) external returns (bytes memory);

Parameters

NameTypeDescription
databytesAny data to pass to the callback, via IUnlockCallback(msg.sender).unlockCallback(data)

Returns

NameTypeDescription
<none>bytesThe data returned by the call to IUnlockCallback(msg.sender).unlockCallback(data)

initialize

Initialize the state for a given pool ID

A swap fee totaling MAX_SWAP_FEE (100%) makes exact output swaps impossible since the input is entirely consumed by the fee

function initialize(PoolKey memory key, uint160 sqrtPriceX96, bytes calldata hookData) external returns (int24 tick);

Parameters

NameTypeDescription
keyPoolKeyThe pool key for the pool to initialize
sqrtPriceX96uint160The initial square root price
hookDatabytesThe data to pass through to the initialize hooks

Returns

NameTypeDescription
tickint24The initial tick of the pool

modifyLiquidity

Modify the liquidity for the given pool

Poke by calling with a zero liquidityDelta

function modifyLiquidity(PoolKey memory key, ModifyLiquidityParams memory params, bytes calldata hookData)
external
returns (BalanceDelta callerDelta, BalanceDelta feesAccrued);

Parameters

NameTypeDescription
keyPoolKeyThe pool to modify liquidity in
paramsModifyLiquidityParamsThe parameters for modifying the liquidity
hookDatabytesThe data to pass through to the add/removeLiquidity hooks

Returns

NameTypeDescription
callerDeltaBalanceDeltaThe balance delta of the caller of modifyLiquidity. This is the total of both principal, fee deltas, and hook deltas if applicable
feesAccruedBalanceDeltaThe balance delta of the fees generated in the liquidity range. Returned for informational purposes

swap

Swap against the given pool

Swapping on low liquidity pools may cause unexpected swap amounts when liquidity available is less than amountSpecified. Additionally note that if interacting with hooks that have the BEFORE_SWAP_RETURNS_DELTA_FLAG or AFTER_SWAP_RETURNS_DELTA_FLAG the hook may alter the swap input/output. Integrators should perform checks on the returned swapDelta.

function swap(PoolKey memory key, SwapParams memory params, bytes calldata hookData)
external
returns (BalanceDelta swapDelta);

Parameters

NameTypeDescription
keyPoolKeyThe pool to swap in
paramsSwapParamsThe parameters for swapping
hookDatabytesThe data to pass through to the swap hooks

Returns

NameTypeDescription
swapDeltaBalanceDeltaThe balance delta of the address swapping

Donate the given currency amounts to the in-range liquidity providers of a pool

Calls to donate can be frontrun adding just-in-time liquidity, with the aim of receiving a portion donated funds. Donors should keep this in mind when designing donation mechanisms.

This function donates to in-range LPs at slot0.tick. In certain edge-cases of the swap algorithm, the sqrtPrice of a pool can be at the lower boundary of tick n, but the slot0.tick of the pool is already n - 1. In this case a call to donate would donate to tick n - 1 (slot0.tick) not tick n (getTickAtSqrtPrice(slot0.sqrtPriceX96)). Read the comments in Pool.swap() for more information about this.

function donate(PoolKey memory key, uint256 amount0, uint256 amount1, bytes calldata hookData)
external
returns (BalanceDelta);

Parameters

NameTypeDescription
keyPoolKeyThe key of the pool to donate to
amount0uint256The amount of currency0 to donate
amount1uint256The amount of currency1 to donate
hookDatabytesThe data to pass through to the donate hooks

Returns

NameTypeDescription
<none>BalanceDeltaBalanceDelta The delta of the caller after the donate

sync

Writes the current ERC20 balance of the specified currency to transient storage This is used to checkpoint balances for the manager and derive deltas for the caller.

This MUST be called before any ERC20 tokens are sent into the contract, but can be skipped for native tokens because the amount to settle is determined by the sent value. However, if an ERC20 token has been synced and not settled, and the caller instead wants to settle native funds, this function can be called with the native currency to then be able to settle the native currency

function sync(Currency currency) external;

take

Called by the user to net out some value owed to the user

Can also be used as a mechanism for free flash loans

function take(Currency currency, address to, uint256 amount) external;

Parameters

NameTypeDescription
currencyCurrencyThe currency to withdraw from the pool manager
toaddressThe address to withdraw to
amountuint256The amount of currency to withdraw

settle

Called by the user to pay what is owed

function settle() external payable returns (uint256 paid);

Returns

NameTypeDescription
paiduint256The amount of currency settled

settleFor

Called by the user to pay on behalf of another address

function settleFor(address recipient) external payable returns (uint256 paid);

Parameters

NameTypeDescription
recipientaddressThe address to credit for the payment

Returns

NameTypeDescription
paiduint256The amount of currency settled

clear

WARNING - Any currency that is cleared, will be non-retrievable, and locked in the contract permanently. A call to clear will zero out a positive balance WITHOUT a corresponding transfer.

This could be used to clear a balance that is considered dust. Additionally, the amount must be the exact positive balance. This is to enforce that the caller is aware of the amount being cleared.

function clear(Currency currency, uint256 amount) external;

mint

Called by the user to move value into ERC6909 balance

The id is converted to a uint160 to correspond to a currency address If the upper 12 bytes are not 0, they will be 0-ed out

function mint(address to, uint256 id, uint256 amount) external;

Parameters

NameTypeDescription
toaddressThe address to mint the tokens to
iduint256The currency address to mint to ERC6909s, as a uint256
amountuint256The amount of currency to mint

burn

Called by the user to move value from ERC6909 balance

The id is converted to a uint160 to correspond to a currency address If the upper 12 bytes are not 0, they will be 0-ed out

function burn(address from, uint256 id, uint256 amount) external;

Parameters

NameTypeDescription
fromaddressThe address to burn the tokens from
iduint256The currency address to burn from ERC6909s, as a uint256
amountuint256The amount of currency to burn

updateDynamicLPFee

Updates the pools lp fees for the a pool that has enabled dynamic lp fees.

A swap fee totaling MAX_SWAP_FEE (100%) makes exact output swaps impossible since the input is entirely consumed by the fee

function updateDynamicLPFee(PoolKey memory key, uint24 newDynamicLPFee) external;

Parameters

NameTypeDescription
keyPoolKeyThe key of the pool to update dynamic LP fees for
newDynamicLPFeeuint24The new dynamic pool LP fee

Events

Initialize

Emitted when a new pool is initialized

event Initialize(
PoolId indexed id,
Currency indexed currency0,
Currency indexed currency1,
uint24 fee,
int24 tickSpacing,
IHooks hooks,
uint160 sqrtPriceX96,
int24 tick
);

Parameters

NameTypeDescription
idPoolIdThe abi encoded hash of the pool key struct for the new pool
currency0CurrencyThe first currency of the pool by address sort order
currency1CurrencyThe second currency of the pool by address sort order
feeuint24The fee collected upon every swap in the pool, denominated in hundredths of a bip
tickSpacingint24The minimum number of ticks between initialized ticks
hooksIHooksThe hooks contract address for the pool, or address(0) if none
sqrtPriceX96uint160The price of the pool on initialization
tickint24The initial tick of the pool corresponding to the intialized price

ModifyLiquidity

Emitted when a liquidity position is modified

event ModifyLiquidity(
PoolId indexed id, address indexed sender, int24 tickLower, int24 tickUpper, int256 liquidityDelta, bytes32 salt
);

Parameters

NameTypeDescription
idPoolIdThe abi encoded hash of the pool key struct for the pool that was modified
senderaddressThe address that modified the pool
tickLowerint24The lower tick of the position
tickUpperint24The upper tick of the position
liquidityDeltaint256The amount of liquidity that was added or removed
saltbytes32The extra data to make positions unique

Swap

Emitted for swaps between currency0 and currency1

event Swap(
PoolId indexed id,
address indexed sender,
int128 amount0,
int128 amount1,
uint160 sqrtPriceX96,
uint128 liquidity,
int24 tick,
uint24 fee
);

Parameters

NameTypeDescription
idPoolIdThe abi encoded hash of the pool key struct for the pool that was modified
senderaddressThe address that initiated the swap call, and that received the callback
amount0int128The delta of the currency0 balance of the pool
amount1int128The delta of the currency1 balance of the pool
sqrtPriceX96uint160The sqrt(price) of the pool after the swap, as a Q64.96
liquidityuint128The liquidity of the pool after the swap
tickint24The log base 1.0001 of the price of the pool after the swap
feeuint24The swap fee in hundredths of a bip

Emitted for donations

event Donate(PoolId indexed id, address indexed sender, uint256 amount0, uint256 amount1);

Parameters

NameTypeDescription
idPoolIdThe abi encoded hash of the pool key struct for the pool that was donated to
senderaddressThe address that initiated the donate call
amount0uint256The amount donated in currency0
amount1uint256The amount donated in currency1

Errors

CurrencyNotSettled

Thrown when a currency is not netted out after the contract is unlocked

error CurrencyNotSettled();

PoolNotInitialized

Thrown when trying to interact with a non-initialized pool

error PoolNotInitialized();

AlreadyUnlocked

Thrown when unlock is called, but the contract is already unlocked

error AlreadyUnlocked();

ManagerLocked

Thrown when a function is called that requires the contract to be unlocked, but it is not

error ManagerLocked();

TickSpacingTooLarge

Pools are limited to type(int16).max tickSpacing in #initialize, to prevent overflow

error TickSpacingTooLarge(int24 tickSpacing);

TickSpacingTooSmall

Pools must have a positive non-zero tickSpacing passed to #initialize

error TickSpacingTooSmall(int24 tickSpacing);

CurrenciesOutOfOrderOrEqual

PoolKey must have currencies where address(currency0) < address(currency1)

error CurrenciesOutOfOrderOrEqual(address currency0, address currency1);

UnauthorizedDynamicLPFeeUpdate

Thrown when a call to updateDynamicLPFee is made by an address that is not the hook, or on a pool that does not have a dynamic swap fee.

error UnauthorizedDynamicLPFeeUpdate();

SwapAmountCannotBeZero

Thrown when trying to swap amount of 0

error SwapAmountCannotBeZero();

NonzeroNativeValue

Thrown when native currency is passed to a non native settlement

error NonzeroNativeValue();

MustClearExactPositiveDelta

Thrown when clear is called with an amount that is not exactly equal to the open currency delta.

error MustClearExactPositiveDelta();

Structs

ModifyLiquidityParams

struct ModifyLiquidityParams {
int24 tickLower;
int24 tickUpper;
int256 liquidityDelta;
bytes32 salt;
}

SwapParams

struct SwapParams {
bool zeroForOne;
int256 amountSpecified;
uint160 sqrtPriceLimitX96;
}
Helpful?