LiquidityAmounts
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))
Parameters:
Name | Type | Description |
---|---|---|
| uint160 | A sqrt price representing the first tick boundary |
| uint160 | A sqrt price representing the second tick boundary |
| uint256 | The amount0 being sent in |
Return Values:
Name | Type | Description |
---|---|---|
| uint128 | The 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)).
Parameters:
Name | Type | Description |
---|---|---|
| uint160 | A sqrt price representing the first tick boundary |
| uint160 | A sqrt price representing the second tick boundary |
| uint256 | The amount1 being sent in |
Return Values:
Name | Type | Description |
---|---|---|
| uint128 | The 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
Parameters:
Name | Type | Description |
---|---|---|
| uint160 | A sqrt price representing the current pool prices |
| uint160 | A sqrt price representing the first tick boundary |
| uint160 | A sqrt price representing the second tick boundary |
| uint256 | The amount of token0 being sent in |
| uint256 | The amount of token1 being sent in |
Return Values:
Name | Type | Description |
---|---|---|
| uint128 | The maximum amount of liquidity received |
getAmount0ForLiquidity
Computes the amount of token0 for a given amount of liquidity and a price range
Parameters:
Name | Type | Description |
---|---|---|
| uint160 | A sqrt price representing the first tick boundary |
| uint160 | A sqrt price representing the second tick boundary |
| uint128 | The liquidity being valued |
Return Values:
Name | Type | Description |
---|---|---|
| uint256 | The amount of token0 |
getAmount1ForLiquidity
Computes the amount of token1 for a given amount of liquidity and a price range
Parameters:
Name | Type | Description |
---|---|---|
| uint160 | A sqrt price representing the first tick boundary |
| uint160 | A sqrt price representing the second tick boundary |
| uint128 | The liquidity being valued |
Return Values:
Name | Type | Description |
---|---|---|
| uint256 | The amount of token1 |
getAmountsForLiquidity
Computes the token0 and token1 value for a given amount of liquidity, the current pool prices and the prices at the tick boundaries
Parameters:
Name | Type | Description |
---|---|---|
| uint160 | A sqrt price representing the current pool prices |
| uint160 | A sqrt price representing the first tick boundary |
| uint160 | A sqrt price representing the second tick boundary |
| uint128 | The liquidity being valued |
Return Values:
Name | Type | Description |
---|---|---|
| uint256 | The amount of token0 |
| uint256 | The amount of token1 |
Last updated