# LiquidityPoolUtils

*Library to abstract liquidity pool operations such as fetching observations, calculating TWAP, etc. Currently supports Uniswap V3 and Algebra V1.9 liquidity pools*

## getLiquidityPoolInfo

```solidity
function getLiquidityPoolInfo(struct IPriceAggregator.LiquidityPoolInput _input) internal view returns (struct IPriceAggregator.LiquidityPoolInfo)
```

*Returns a `LiquidityPoolInfo` struct for LiquidityPoolInput `_input`*

### Parameters

| Name    | Type                                                                                                                                    | Description                                          |
| ------- | --------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------- |
| \_input | [IPriceAggregator.LiquidityPoolInput](/developer/technical-reference/contracts/interfaces/types/ipriceaggregator.md#liquiditypoolinput) | LiquidityPoolInput struct with pool address and type |

## getTimeWeightedAveragePrice

```solidity
function getTimeWeightedAveragePrice(struct IPriceAggregator.LiquidityPoolInfo _poolInfo, uint32 _twapInterval, uint256 _precisionDelta) internal view returns (uint256)
```

*Calculates the time-weighted average price of a liquidity pool over a given interval*

### Parameters

| Name             | Type                                                                                                                                  | Description                   |
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------- |
| \_poolInfo       | [IPriceAggregator.LiquidityPoolInfo](/developer/technical-reference/contracts/interfaces/types/ipriceaggregator.md#liquiditypoolinfo) | Liquidity pool info           |
| \_twapInterval   | uint32                                                                                                                                | TWAP interval in seconds      |
| \_precisionDelta | uint256                                                                                                                               | precision delta of collateral |

## \_getPoolTickCumulatives

```solidity
function _getPoolTickCumulatives(struct IPriceAggregator.LiquidityPoolInfo _poolInfo, uint32 _twapInterval) internal view returns (int56[])
```

*Fetches tickCumulatives data from the pool. Calls the appropriate oracle function based on the pool type*

### Parameters

| Name           | Type                                                                                                                                  | Description         |
| -------------- | ------------------------------------------------------------------------------------------------------------------------------------- | ------------------- |
| \_poolInfo     | [IPriceAggregator.LiquidityPoolInfo](/developer/technical-reference/contracts/interfaces/types/ipriceaggregator.md#liquiditypoolinfo) | Liquidity pool info |
| \_twapInterval | uint32                                                                                                                                | TWAP interval       |

## \_tickCumulativesToTokenPrice

```solidity
function _tickCumulativesToTokenPrice(int56[] _tickCumulatives, uint32 _twapInterval, uint256 _precisionDelta, bool _isGnsToken0InLp) internal pure returns (uint256)
```

*Returns TWAP price (1e10 precision) from tickCumulatives data*

### Parameters

| Name              | Type     | Description                                                                                                                         |
| ----------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| \_tickCumulatives | int56\[] | array of tickCumulatives                                                                                                            |
| \_twapInterval    | uint32   | TWAP interval                                                                                                                       |
| \_precisionDelta  | uint256  | precision delta of collateral                                                                                                       |
| \_isGnsToken0InLp | bool     | true if GNS is token0 in LP Inspired from <https://github.com/Uniswap/v3-periphery/blob/main/contracts/libraries/OracleLibrary.sol> |


---

# 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.gains.trade/developer/technical-reference/contracts/libraries/liquiditypoolutils.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.
