LiquidityAmounts
Authors: Aloe Labs, Inc., Modified from Uniswap
Provides functions for computing liquidity amounts from token amounts and prices
Functions
getAmountsForLiquidity
Computes the token0 and token1 value for a given amount of liquidity, the current pool prices and the prices at the tick boundaries
function getAmountsForLiquidity(
uint160 sqrtRatioX96,
uint160 sqrtRatioAX96,
uint160 sqrtRatioBX96,
uint128 liquidity
) internal pure returns (uint256 amount0, uint256 amount1);
Parameters
Name | Type | Description |
---|---|---|
sqrtRatioX96 | uint160 | A sqrt price representing the current pool prices |
sqrtRatioAX96 | uint160 | A sqrt price representing the first tick boundary |
sqrtRatioBX96 | uint160 | A sqrt price representing the second tick boundary |
liquidity | uint128 | The liquidity being valued |
Returns
Name | Type | Description |
---|---|---|
amount0 | uint256 | The amount of token0 |
amount1 | uint256 | The amount of token1 |
getValuesOfLiquidity
Computes the value of each portion of the liquidity in terms of token1
Each return value can fit in a uint192 if necessary
function getValuesOfLiquidity(
uint160 sqrtRatioX96,
uint160 sqrtRatioAX96,
uint160 sqrtRatioBX96,
uint128 liquidity
) internal pure returns (uint256 value0, uint256 value1);
Parameters
Name | Type | Description |
---|---|---|
sqrtRatioX96 | uint160 | A sqrt price representing the current pool prices |
sqrtRatioAX96 | uint160 | A sqrt price representing the lower tick boundary |
sqrtRatioBX96 | uint160 | A sqrt price representing the upper tick boundary |
liquidity | uint128 | The liquidity being valued |
Returns
Name | Type | Description |
---|---|---|
value0 | uint256 | The value of amount0 underlying liquidity , in terms of token1 |
value1 | uint256 | The amount of token1 |
getValueOfLiquidity
Computes the value of the liquidity in terms of token1
The return value can fit in a uint192 if necessary
function getValueOfLiquidity(
uint160 sqrtRatioX96,
uint160 sqrtRatioAX96,
uint160 sqrtRatioBX96,
uint128 liquidity
) internal pure returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
sqrtRatioX96 | uint160 | A sqrt price representing the current pool prices |
sqrtRatioAX96 | uint160 | A sqrt price representing the lower tick boundary |
sqrtRatioBX96 | uint160 | A sqrt price representing the upper tick boundary |
liquidity | uint128 | The liquidity being valued |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The value of the underlying liquidity , in terms of token1 |
_getAmount0ForLiquidity
Computes the amount of token0 for a given amount of liquidity and a price range
function _getAmount0ForLiquidity(
uint160 sqrtRatioAX96,
uint160 sqrtRatioBX96,
uint128 liquidity
) private pure returns (uint256 amount0);
Parameters
Name | Type | Description |
---|---|---|
sqrtRatioAX96 | uint160 | A sqrt price representing the first tick boundary |
sqrtRatioBX96 | uint160 | A sqrt price representing the second tick boundary |
liquidity | uint128 | The liquidity being valued |
Returns
Name | Type | Description |
---|---|---|
amount0 | uint256 | The amount of token0. Will fit in a uint224 if you need it to |
_getAmount1ForLiquidity
Computes the amount of token1 for a given amount of liquidity and a price range
function _getAmount1ForLiquidity(
uint160 sqrtRatioAX96,
uint160 sqrtRatioBX96,
uint128 liquidity
) private pure returns (uint256 amount1);
Parameters
Name | Type | Description |
---|---|---|
sqrtRatioAX96 | uint160 | A sqrt price representing the first tick boundary |
sqrtRatioBX96 | uint160 | A sqrt price representing the second tick boundary |
liquidity | uint128 | The liquidity being valued |
Returns
Name | Type | Description |
---|---|---|
amount1 | uint256 | The amount of token1. Will fit in a uint192 if you need it to |