# TickMath

### Functions <a href="#functions" id="functions"></a>

#### tickSqrtPrices <a href="#ticksqrtprices" id="ticksqrtprices"></a>

Compute the lower and upper sqrtPrice of a tick.

```solidity
function tickSqrtPrices(uint256 tickSpacing, int32 _tick)
    internal
    pure
    returns (uint256 sqrtLowerPrice, uint256 sqrtUpperPrice);
```

**Parameters**

| Name          | Type      | Description                             |
| ------------- | --------- | --------------------------------------- |
| `tickSpacing` | `uint256` | The tick spacing used for calculations. |
| `_tick`       | `int32`   | The input tick value.                   |

#### subTickIndex <a href="#subtickindex" id="subtickindex"></a>

Compute the base tick value from the pool tick and the tickSpacing. Revert if base tick is beyond the max tick boundary.

```solidity
function subTickIndex(uint256 tickSpacing, int32 _tick) internal pure returns (uint32 subTick);
```

**Parameters**

| Name          | Type      | Description                             |
| ------------- | --------- | --------------------------------------- |
| `tickSpacing` | `uint256` | The tick spacing used for calculations. |
| `_tick`       | `int32`   | The input tick value.                   |

#### tickSqrtPrice <a href="#ticksqrtprice" id="ticksqrtprice"></a>

Calculate the square root price for a given tick and tick spacing.

```solidity
function tickSqrtPrice(uint256 tickSpacing, int32 _tick) internal pure returns (uint256 _result);
```

**Parameters**

| Name          | Type      | Description                             |
| ------------- | --------- | --------------------------------------- |
| `tickSpacing` | `uint256` | The tick spacing used for calculations. |
| `_tick`       | `int32`   | The input tick value.                   |

**Returns**

| Name      | Type      | Description            |
| --------- | --------- | ---------------------- |
| `_result` | `uint256` | The square root price. |

#### getTickL <a href="#gettickl" id="gettickl"></a>

Calculate liquidity of a tick.

```solidity
function getTickL(uint256 reserveA, uint256 reserveB, uint256 sqrtLowerTickPrice, uint256 sqrtUpperTickPrice)
    internal
    pure
    returns (uint256 liquidity);
```

**Parameters**

| Name                 | Type      | Description                                   |
| -------------------- | --------- | --------------------------------------------- |
| `reserveA`           | `uint256` | Tick reserve of token A.                      |
| `reserveB`           | `uint256` | Tick reserve of token B.                      |
| `sqrtLowerTickPrice` | `uint256` | The square root price of the lower tick edge. |
| `sqrtUpperTickPrice` | `uint256` | The square root price of the upper tick edge. |

#### getSqrtPrice <a href="#getsqrtprice" id="getsqrtprice"></a>

Calculate square root price of a tick. Returns left edge of the tick if the tick has no reserves.

```solidity
function getSqrtPrice(
    uint256 reserveA,
    uint256 reserveB,
    uint256 sqrtLowerTickPrice,
    uint256 sqrtUpperTickPrice,
    uint256 liquidity
) internal pure returns (uint256 sqrtPrice);
```

**Parameters**

| Name                 | Type      | Description                                   |
| -------------------- | --------- | --------------------------------------------- |
| `reserveA`           | `uint256` | Tick reserve of token A.                      |
| `reserveB`           | `uint256` | Tick reserve of token B.                      |
| `sqrtLowerTickPrice` | `uint256` | The square root price of the lower tick edge. |
| `sqrtUpperTickPrice` | `uint256` | The square root price of the upper tick edge. |
| `liquidity`          | `uint256` |                                               |

**Returns**

| Name        | Type      | Description                       |
| ----------- | --------- | --------------------------------- |
| `sqrtPrice` | `uint256` | The calculated square root price. |

#### getTickSqrtPriceAndL <a href="#getticksqrtpriceandl" id="getticksqrtpriceandl"></a>

Calculate square root price of a tick. Returns left edge of the tick if the tick has no reserves.

```solidity
function getTickSqrtPriceAndL(
    uint256 reserveA,
    uint256 reserveB,
    uint256 sqrtLowerTickPrice,
    uint256 sqrtUpperTickPrice
) internal pure returns (uint256 sqrtPrice, uint256 liquidity);
```

**Parameters**

| Name                 | Type      | Description                                   |
| -------------------- | --------- | --------------------------------------------- |
| `reserveA`           | `uint256` | Tick reserve of token A.                      |
| `reserveB`           | `uint256` | Tick reserve of token B.                      |
| `sqrtLowerTickPrice` | `uint256` | The square root price of the lower tick edge. |
| `sqrtUpperTickPrice` | `uint256` | The square root price of the upper tick edge. |

**Returns**

| Name        | Type      | Description                       |
| ----------- | --------- | --------------------------------- |
| `sqrtPrice` | `uint256` | The calculated square root price. |
| `liquidity` | `uint256` | The calculated liquidity.         |

### Errors <a href="#errors" id="errors"></a>

#### TickMaxExceeded <a href="#tickmaxexceeded" id="tickmaxexceeded"></a>

```solidity
error TickMaxExceeded(int256 tick);
```


---

# 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://docs.mav.xyz/technical-reference/maverick-v2/v2-contracts/maverick-v2-common-contracts/libraries/tickmath.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.
