# IMaverickV2PoolLens

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

#### getAddLiquidityParams <a href="#getaddliquidityparams" id="getaddliquidityparams"></a>

Converts add parameter slippage specification into add parameters. The return values are given in both raw format and as packed values that can be used in the LiquidityManager contract.

```solidity
function getAddLiquidityParams(AddParamsViewInputs memory params)
    external
    view
    returns (
        bytes memory packedSqrtPriceBreaks,
        bytes[] memory packedArgs,
        uint88[] memory sqrtPriceBreaks,
        IMaverickV2Pool.AddLiquidityParams[] memory addParams,
        IMaverickV2PoolLens.TickDeltas[] memory tickDeltas
    );
```

#### getAddLiquidityParamsForBoostedPosition <a href="#getaddliquidityparamsforboostedposition" id="getaddliquidityparamsforboostedposition"></a>

Converts add parameter slippage specification for a boosted position into add parameters. The return values are given in both raw format and as packed values that can be used in the LiquidityManager contract.

```solidity
function getAddLiquidityParamsForBoostedPosition(
    IMaverickV2BoostedPosition boostedPosition,
    AddParamsSpecification memory addSpec
)
    external
    view
    returns (
        bytes memory packedSqrtPriceBreaks,
        bytes[] memory packedArgs,
        uint88[] memory sqrtPriceBreaks,
        IMaverickV2Pool.AddLiquidityParams[] memory addParams,
        IMaverickV2PoolLens.TickDeltas[] memory tickDeltas
    );
```

#### getCreateBoostedPositionParams <a href="#getcreateboostedpositionparams" id="getcreateboostedpositionparams"></a>

Converts add parameter slippage specification and boosted position specification into add parameters. The return values are given in both raw format and as packed values that can be used in the LiquidityManager contract.

```solidity
function getCreateBoostedPositionParams(
    BoostedPositionSpecification memory bpSpec,
    AddParamsSpecification memory addSpec
)
    external
    view
    returns (
        bytes memory packedSqrtPriceBreaks,
        bytes[] memory packedArgs,
        uint88[] memory sqrtPriceBreaks,
        IMaverickV2Pool.AddLiquidityParams[] memory addParams,
        IMaverickV2PoolLens.TickDeltas[] memory tickDeltas
    );
```

#### getCreatePoolAtPriceAndAddLiquidityParams <a href="#getcreatepoolatpriceandaddliquidityparams" id="getcreatepoolatpriceandaddliquidityparams"></a>

Converts add parameter slippage specification and new pool specification into CreateAndAddParamsInputs parameters that can be used in the LiquidityManager contract.

```solidity
function getCreatePoolAtPriceAndAddLiquidityParams(
    CreateAndAddParamsViewInputs memory params,
    IMaverickV2Factory factory
) external view returns (CreateAndAddParamsInputs memory output);
```

#### getTicksAroundActive <a href="#getticksaroundactive" id="getticksaroundactive"></a>

View function that provides information about pool ticks within a tick radius from the activeTick.

```solidity
function getTicksAroundActive(IMaverickV2Pool pool, int32 tickRadius)
    external
    view
    returns (int32[] memory ticks, IMaverickV2Pool.TickState[] memory tickStates);
```

#### getTicks <a href="#getticks" id="getticks"></a>

View function that provides information about pool ticks within a range.

```solidity
function getTicks(IMaverickV2Pool pool, int32 tickStart, int32 tickEnd)
    external
    view
    returns (int32[] memory ticks, IMaverickV2Pool.TickState[] memory tickStates);
```

#### getFullPoolState <a href="#getfullpoolstate" id="getfullpoolstate"></a>

View function that provides pool state information.

```solidity
function getFullPoolState(IMaverickV2Pool pool, uint32 binStart, uint32 binEnd)
    external
    view
    returns (PoolState memory poolState);
```

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

View function that provides price and liquidity of a given tick.

```solidity
function getTickSqrtPriceAndL(IMaverickV2Pool pool, int32 tick)
    external
    view
    returns (uint256 sqrtPrice, uint256 liquidity);
```

#### getPoolSqrtPrice <a href="#getpoolsqrtprice" id="getpoolsqrtprice"></a>

Pool sqrt price.

```solidity
function getPoolSqrtPrice(IMaverickV2Pool pool) external view returns (uint256 sqrtPrice);
```

#### getPoolPrice <a href="#getpoolprice" id="getpoolprice"></a>

Pool price.

```solidity
function getPoolPrice(IMaverickV2Pool pool) external view returns (uint256 price);
```

#### tokenScales <a href="#tokenscales" id="tokenscales"></a>

Token scale of two tokens in a pool.

```solidity
function tokenScales(IMaverickV2Pool pool) external view returns (uint256 tokenAScale, uint256 tokenBScale);
```

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

#### LensTargetPriceOutOfBounds <a href="#lenstargetpriceoutofbounds" id="lenstargetpriceoutofbounds"></a>

```solidity
error LensTargetPriceOutOfBounds(uint256 targetSqrtPrice, uint256 sqrtLowerTickPrice, uint256 sqrtUpperTickPrice);
```

#### LensTooLittleLiquidity <a href="#lenstoolittleliquidity" id="lenstoolittleliquidity"></a>

```solidity
error LensTooLittleLiquidity(uint256 relativeLiquidityAmount, uint256 deltaA, uint256 deltaB);
```

#### LensTargetingTokenWithNoDelta <a href="#lenstargetingtokenwithnodelta" id="lenstargetingtokenwithnodelta"></a>

```solidity
error LensTargetingTokenWithNoDelta(bool targetIsA, uint256 deltaA, uint256 deltaB);
```

### Structs <a href="#structs" id="structs"></a>

#### AddParamsViewInputs <a href="#addparamsviewinputs" id="addparamsviewinputs"></a>

Add liquidity slippage parameters for a distribution of liquidity.

```solidity
struct AddParamsViewInputs {
    IMaverickV2Pool pool;
    uint8 kind;
    int32[] ticks;
    uint128[] relativeLiquidityAmounts;
    AddParamsSpecification addSpec;
}
```

**Properties**

| Name                       | Type                     | Description                                                                                                                                                                                                                                             |
| -------------------------- | ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `pool`                     | `IMaverickV2Pool`        | Pool where liquidity is being added.                                                                                                                                                                                                                    |
| `kind`                     | `uint8`                  | Bin kind; all bins must have the same kind in a given call to addLiquidity.                                                                                                                                                                             |
| `ticks`                    | `int32[]`                | Array of tick values to add liquidity to.                                                                                                                                                                                                               |
| `relativeLiquidityAmounts` | `uint128[]`              | Relative liquidity amounts for the specified ticks. Liquidity in this case is not bin LP balance, it is the bin liquidity as defined by liquidity = deltaA / (sqrt(upper) - sqrt(lower)) or deltaB = liquidity / sqrt(lower) - liquidity / sqrt(upper). |
| `addSpec`                  | `AddParamsSpecification` | Slippage specification.                                                                                                                                                                                                                                 |

#### AddParamsSpecification <a href="#addparamsspecification" id="addparamsspecification"></a>

Multi-price add param specification.

```solidity
struct AddParamsSpecification {
    uint256 slippageFactorD18;
    uint256 numberOfPriceBreaksPerSide;
    uint256 targetAmount;
    bool targetIsA;
}
```

**Properties**

| Name                         | Type      | Description                                                                                                      |
| ---------------------------- | --------- | ---------------------------------------------------------------------------------------------------------------- |
| `slippageFactorD18`          | `uint256` | Max slippage allowed as a percent in D18 scale. e.g. 1% slippage is 0.01e18                                      |
| `numberOfPriceBreaksPerSide` | `uint256` | Number of price break values on either side of current price.                                                    |
| `targetAmount`               | `uint256` | Target token contribution amount in tokenA if targetIsA is true, otherwise this is the target amount for tokenB. |
| `targetIsA`                  | `bool`    | Indicates if the target amount is for tokenA or tokenB                                                           |

#### CreateBoostedPositionInputs <a href="#createboostedpositioninputs" id="createboostedpositioninputs"></a>

Boosted position creation specification and add parameters.

```solidity
struct CreateBoostedPositionInputs {
    BoostedPositionSpecification bpSpec;
    bytes packedSqrtPriceBreaks;
    bytes[] packedArgs;
}
```

**Properties**

| Name                    | Type                           | Description                                                                                                                                                                                                                                         |
| ----------------------- | ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `bpSpec`                | `BoostedPositionSpecification` | Boosted position kind/binId/ratio information.                                                                                                                                                                                                      |
| `packedSqrtPriceBreaks` | `bytes`                        | Array of sqrt price breaks packed into bytes. These breaks act as a lookup table for the packedArgs array to indicate to the Liquidity manager what add liquidity parameters from packedArgs to use depending on the price of the pool at add time. |
| `packedArgs`            | `bytes[]`                      | Array of bytes arguments. Each array element is a packed version of addLiquidity paramters.                                                                                                                                                         |

#### CreateAndAddParamsViewInputs <a href="#createandaddparamsviewinputs" id="createandaddparamsviewinputs"></a>

Specification for deriving create pool parameters. Creating a pool in the liquidity manager has several steps:

* Deploy pool
* Donate a small amount of initial liquidity in the activeTick
* Execute a small swap to set the pool price to the desired value
* Add liquidity In order to execute these steps, the caller must specify the parameters of each step. The PoolLens has helper function to derive the values used by the LiquidityManager, but this struct is the input to that helper function and represents the core intent of the pool creator.

```solidity
struct CreateAndAddParamsViewInputs {
    uint64 feeAIn;
    uint64 feeBIn;
    uint16 tickSpacing;
    uint32 lookback;
    IERC20 tokenA;
    IERC20 tokenB;
    int32 activeTick;
    uint8 kinds;
    uint256 initialTargetB;
    uint256 sqrtPrice;
    uint8 kind;
    int32[] ticks;
    uint128[] relativeLiquidityAmounts;
    uint256 targetAmount;
    bool targetIsA;
}
```

**Properties**

| Name                       | Type        | Description                                                                                                                                                                                                                                             |
| -------------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `feeAIn`                   | `uint64`    |                                                                                                                                                                                                                                                         |
| `feeBIn`                   | `uint64`    |                                                                                                                                                                                                                                                         |
| `tickSpacing`              | `uint16`    | Tick spacing of pool where 1.0001^tickSpacing is the bin width.                                                                                                                                                                                         |
| `lookback`                 | `uint32`    | Pool lookback in second in D2 scale.                                                                                                                                                                                                                    |
| `tokenA`                   | `IERC20`    | Address of tokenA.                                                                                                                                                                                                                                      |
| `tokenB`                   | `IERC20`    | Address of tokenB.                                                                                                                                                                                                                                      |
| `activeTick`               | `int32`     | Tick position that contains the active bins.                                                                                                                                                                                                            |
| `kinds`                    | `uint8`     | 1-15 number to represent the active kinds 0b0001 = static; 0b0010 = right; 0b0100 = left; 0b1000 = both. e.g. a pool with all 4 modes will have kinds = b1111 = 15                                                                                      |
| `initialTargetB`           | `uint256`   | Amount of B to be donated to the pool after pool create. This amount needs to be big enough to meet the minimum bin liquidity.                                                                                                                          |
| `sqrtPrice`                | `uint256`   | Target sqrt price of the pool.                                                                                                                                                                                                                          |
| `kind`                     | `uint8`     | Bin kind; all bins must have the same kind in a given call to addLiquidity.                                                                                                                                                                             |
| `ticks`                    | `int32[]`   | Array of tick values to add liquidity to.                                                                                                                                                                                                               |
| `relativeLiquidityAmounts` | `uint128[]` | Relative liquidity amounts for the specified ticks. Liquidity in this case is not bin LP balance, it is the bin liquidity as defined by liquidity = deltaA / (sqrt(upper) - sqrt(lower)) or deltaB = liquidity / sqrt(lower) - liquidity / sqrt(upper). |
| `targetAmount`             | `uint256`   | Target token contribution amount in tokenA if targetIsA is true, otherwise this is the target amount for tokenB.                                                                                                                                        |
| `targetIsA`                | `bool`      | Indicates if the target amount is for tokenA or tokenB                                                                                                                                                                                                  |

#### Output <a href="#output" id="output"></a>

```solidity
struct Output {
    uint256 deltaAOut;
    uint256 deltaBOut;
    uint256[] deltaAs;
    uint256[] deltaBs;
    uint128[] deltaLpBalances;
}
```

#### Reserves <a href="#reserves" id="reserves"></a>

```solidity
struct Reserves {
    uint256 amountA;
    uint256 amountB;
}
```

#### BinPositionKinds <a href="#binpositionkinds" id="binpositionkinds"></a>

```solidity
struct BinPositionKinds {
    uint128[4] values;
}
```

#### PoolState <a href="#poolstate" id="poolstate"></a>

```solidity
struct PoolState {
    IMaverickV2Pool.TickState[] tickStateMapping;
    IMaverickV2Pool.BinState[] binStateMapping;
    BinPositionKinds[] binIdByTickKindMapping;
    IMaverickV2Pool.State state;
    Reserves protocolFees;
}
```

#### BoostedPositionSpecification <a href="#boostedpositionspecification" id="boostedpositionspecification"></a>

```solidity
struct BoostedPositionSpecification {
    IMaverickV2Pool pool;
    uint32[] binIds;
    uint128[] ratios;
    uint8 kind;
}
```

#### CreateAndAddParamsInputs <a href="#createandaddparamsinputs" id="createandaddparamsinputs"></a>

```solidity
struct CreateAndAddParamsInputs {
    uint64 feeAIn;
    uint64 feeBIn;
    uint16 tickSpacing;
    uint32 lookback;
    IERC20 tokenA;
    IERC20 tokenB;
    int32 activeTick;
    uint8 kinds;
    IMaverickV2Pool pool;
    IMaverickV2Pool.AddLiquidityParams donateParams;
    uint256 swapAmount;
    IMaverickV2Pool.AddLiquidityParams addParams;
    bytes[] packedAddParams;
    uint256 deltaAOut;
    uint256 deltaBOut;
}
```

#### TickDeltas <a href="#tickdeltas" id="tickdeltas"></a>

```solidity
struct TickDeltas {
    uint256 deltaAOut;
    uint256 deltaBOut;
    uint256[] deltaAs;
    uint256[] deltaBs;
}
```

<br>


---

# 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-supplemental-contracts/interfaces/imaverickv2poollens.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.
