Skip to main content

LiquidityAmounts

Git Source - Generated with forge doc

Provides functions for computing liquidity amounts from token amounts and prices

Functions

getLiquidityForAmount0

Computes the amount of liquidity received for a given amount of token0 and price range

Calculates amount0 (sqrt(upper) sqrt(lower)) / (sqrt(upper) - sqrt(lower))

function getLiquidityForAmount0(uint160 sqrtPriceAX96, uint160 sqrtPriceBX96, uint256 amount0)
internal
pure
returns (uint128 liquidity);

Parameters

NameTypeDescription
sqrtPriceAX96uint160A sqrt price representing the first tick boundary
sqrtPriceBX96uint160A sqrt price representing the second tick boundary
amount0uint256The amount0 being sent in

Returns

NameTypeDescription
liquidityuint128The amount of returned liquidity

getLiquidityForAmount1

Computes the amount of liquidity received for a given amount of token1 and price range

Calculates amount1 / (sqrt(upper) - sqrt(lower)).

function getLiquidityForAmount1(uint160 sqrtPriceAX96, uint160 sqrtPriceBX96, uint256 amount1)
internal
pure
returns (uint128 liquidity);

Parameters

NameTypeDescription
sqrtPriceAX96uint160A sqrt price representing the first tick boundary
sqrtPriceBX96uint160A sqrt price representing the second tick boundary
amount1uint256The amount1 being sent in

Returns

NameTypeDescription
liquidityuint128The amount of returned liquidity

getLiquidityForAmounts

Computes the maximum amount of liquidity received for a given amount of token0, token1, the current pool prices and the prices at the tick boundaries

function getLiquidityForAmounts(
uint160 sqrtPriceX96,
uint160 sqrtPriceAX96,
uint160 sqrtPriceBX96,
uint256 amount0,
uint256 amount1
) internal pure returns (uint128 liquidity);

Parameters

NameTypeDescription
sqrtPriceX96uint160A sqrt price representing the current pool prices
sqrtPriceAX96uint160A sqrt price representing the first tick boundary
sqrtPriceBX96uint160A sqrt price representing the second tick boundary
amount0uint256The amount of token0 being sent in
amount1uint256The amount of token1 being sent in

Returns

NameTypeDescription
liquidityuint128The maximum amount of liquidity received