LiquidityAmounts

Functions for converting between token amounts and liquidity.

Source: contracts/periphery/libraries/LiquidityAmounts.sol

Functions

getLiquidityForAmount0

function getLiquidityForAmount0(
    uint160 sqrtRatioAX96,
    uint160 sqrtRatioBX96,
    uint256 amount0
) internal pure returns (uint128 liquidity)

Computes liquidity for a given amount of token0.

getLiquidityForAmount1

function getLiquidityForAmount1(
    uint160 sqrtRatioAX96,
    uint160 sqrtRatioBX96,
    uint256 amount1
) internal pure returns (uint128 liquidity)

Computes liquidity for a given amount of token1.

getLiquidityForAmounts

Computes the maximum liquidity for given token amounts based on current price.

Parameters:

  • sqrtRatioX96 - Current pool price

  • sqrtRatioAX96 - Lower bound sqrt price

  • sqrtRatioBX96 - Upper bound sqrt price

  • amount0 - Desired token0 amount

  • amount1 - Desired token1 amount

getAmount0ForLiquidity

Computes token0 amount for a given liquidity.

getAmount1ForLiquidity

Computes token1 amount for a given liquidity.

getAmountsForLiquidity

Computes token amounts for given liquidity based on current price.

JavaScript Implementation

Usage Example

Last updated