# LiquidityAmounts

Provides functions for computing liquidity amounts from token amounts and prices

### Functions[​](https://docs.uniswap.org/contracts/v3/reference/periphery/libraries/LiquidityAmounts#functions) <a href="#functions" id="functions"></a>

#### getLiquidityForAmount0[​](https://docs.uniswap.org/contracts/v3/reference/periphery/libraries/LiquidityAmounts#getliquidityforamount0) <a href="#getliquidityforamount0" id="getliquidityforamount0"></a>

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

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:**[**​**](https://docs.uniswap.org/contracts/v3/reference/periphery/libraries/LiquidityAmounts#parameters)

| Name            | Type    | Description                                        |
| --------------- | ------- | -------------------------------------------------- |
| `sqrtRatioAX96` | uint160 | A sqrt price representing the first tick boundary  |
| `sqrtRatioBX96` | uint160 | A sqrt price representing the second tick boundary |
| `amount0`       | uint256 | The amount0 being sent in                          |

**Return Values:**[**​**](https://docs.uniswap.org/contracts/v3/reference/periphery/libraries/LiquidityAmounts#return-values)

| Name        | Type    | Description                      |
| ----------- | ------- | -------------------------------- |
| `liquidity` | uint128 | The amount of returned liquidity |

#### getLiquidityForAmount1[​](https://docs.uniswap.org/contracts/v3/reference/periphery/libraries/LiquidityAmounts#getliquidityforamount1) <a href="#getliquidityforamount1" id="getliquidityforamount1"></a>

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

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

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

**Parameters:**[**​**](https://docs.uniswap.org/contracts/v3/reference/periphery/libraries/LiquidityAmounts#parameters-1)

| Name            | Type    | Description                                        |
| --------------- | ------- | -------------------------------------------------- |
| `sqrtRatioAX96` | uint160 | A sqrt price representing the first tick boundary  |
| `sqrtRatioBX96` | uint160 | A sqrt price representing the second tick boundary |
| `amount1`       | uint256 | The amount1 being sent in                          |

**Return Values:**[**​**](https://docs.uniswap.org/contracts/v3/reference/periphery/libraries/LiquidityAmounts#return-values-1)

| Name        | Type    | Description                      |
| ----------- | ------- | -------------------------------- |
| `liquidity` | uint128 | The amount of returned liquidity |

#### getLiquidityForAmounts[​](https://docs.uniswap.org/contracts/v3/reference/periphery/libraries/LiquidityAmounts#getliquidityforamounts) <a href="#getliquidityforamounts" id="getliquidityforamounts"></a>

```solidity
  function getLiquidityForAmounts(
    uint160 sqrtRatioX96,
    uint160 sqrtRatioAX96,
    uint160 sqrtRatioBX96,
    uint256 amount0,
    uint256 amount1
  ) internal returns (uint128 liquidity)
```

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:**[**​**](https://docs.uniswap.org/contracts/v3/reference/periphery/libraries/LiquidityAmounts#parameters-2)

| 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 |
| `amount0`       | uint256 | The amount of token0 being sent in                 |
| `amount1`       | uint256 | The amount of token1 being sent in                 |

**Return Values:**[**​**](https://docs.uniswap.org/contracts/v3/reference/periphery/libraries/LiquidityAmounts#return-values-2)

| Name        | Type    | Description                              |
| ----------- | ------- | ---------------------------------------- |
| `liquidity` | uint128 | The maximum amount of liquidity received |

#### getAmount0ForLiquidity[​](https://docs.uniswap.org/contracts/v3/reference/periphery/libraries/LiquidityAmounts#getamount0forliquidity) <a href="#getamount0forliquidity" id="getamount0forliquidity"></a>

```solidity
  function getAmount0ForLiquidity(
    uint160 sqrtRatioAX96,
    uint160 sqrtRatioBX96,
    uint128 liquidity
  ) internal returns (uint256 amount0)
```

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

**Parameters:**[**​**](https://docs.uniswap.org/contracts/v3/reference/periphery/libraries/LiquidityAmounts#parameters-3)

| 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                         |

**Return Values:**[**​**](https://docs.uniswap.org/contracts/v3/reference/periphery/libraries/LiquidityAmounts#return-values-3)

| Name      | Type    | Description          |
| --------- | ------- | -------------------- |
| `amount0` | uint256 | The amount of token0 |

#### getAmount1ForLiquidity[​](https://docs.uniswap.org/contracts/v3/reference/periphery/libraries/LiquidityAmounts#getamount1forliquidity) <a href="#getamount1forliquidity" id="getamount1forliquidity"></a>

```solidity
  function getAmount1ForLiquidity(
    uint160 sqrtRatioAX96,
    uint160 sqrtRatioBX96,
    uint128 liquidity
  ) internal returns (uint256 amount1)
```

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

**Parameters:**[**​**](https://docs.uniswap.org/contracts/v3/reference/periphery/libraries/LiquidityAmounts#parameters-4)

| 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                         |

**Return Values:**[**​**](https://docs.uniswap.org/contracts/v3/reference/periphery/libraries/LiquidityAmounts#return-values-4)

| Name      | Type    | Description          |
| --------- | ------- | -------------------- |
| `amount1` | uint256 | The amount of token1 |

#### getAmountsForLiquidity[​](https://docs.uniswap.org/contracts/v3/reference/periphery/libraries/LiquidityAmounts#getamountsforliquidity) <a href="#getamountsforliquidity" id="getamountsforliquidity"></a>

```solidity
  function getAmountsForLiquidity(
    uint160 sqrtRatioX96,
    uint160 sqrtRatioAX96,
    uint160 sqrtRatioBX96,
    uint128 liquidity
  ) internal returns (uint256 amount0, uint256 amount1)
```

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

**Parameters:**[**​**](https://docs.uniswap.org/contracts/v3/reference/periphery/libraries/LiquidityAmounts#parameters-5)

| 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                         |

**Return Values:**[**​**](https://docs.uniswap.org/contracts/v3/reference/periphery/libraries/LiquidityAmounts#return-values-5)

| Name      | Type    | Description          |
| --------- | ------- | -------------------- |
| `amount0` | uint256 | The amount of token0 |
| `amount1` | uint256 | The amount of token1 |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://bonsaiswap.gitbook.io/bonsaiswap-docs/developers/technical-reference/periphery/libraries/liquidityamounts.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
