# WeightedOracleLibrary

Provides functions to integrate with different tier oracles of the same V3 pair

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

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

```solidity
  function consult(
    address pool,
    uint32 period
  ) internal view returns (struct WeightedOracleLibrary.PeriodObservation observation)
```

Fetches a time-weighted observation for a given Uniswap V3 pool

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

| Name     | Type    | Description                                                                      |
| -------- | ------- | -------------------------------------------------------------------------------- |
| `pool`   | address | Address of the pool that we want to observe                                      |
| `period` | uint32  | Number of seconds in the past to start calculating the time-weighted observation |

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

| Name          | Type    | Description                                                                                   |
| ------------- | ------- | --------------------------------------------------------------------------------------------- |
| `observation` | address | An observation that has been time-weighted from (block.timestamp - period) to block.timestamp |

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

```solidity
  function getArithmeticMeanTickWeightedByLiquidity(
    struct WeightedOracleLibrary.PeriodObservation[] observations
  ) internal pure returns (int24 arithmeticMeanWeightedTick)
```

Given some time-weighted observations, calculates the arithmetic mean tick, weighted by liquidity

In most scenarios, each entry of `observations` should share the same `period` and underlying `pool` tokens. If `period` differs across observations, the result becomes difficult to interpret and is likely biased/manipulable. If the underlying `pool` tokens differ across observations, extreme care must be taken to ensure that both prices and liquidity values are comparable. Even if prices are commensurate (e.g. two different USD-stable assets against ETH), liquidity values may not be, as decimals can differ between tokens.

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

| Name           | Type                                              | Description                          |
| -------------- | ------------------------------------------------- | ------------------------------------ |
| `observations` | struct WeightedOracleLibrary.PeriodObservation\[] | A list of time-weighted observations |

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

| Name                         | Type                                              | Description                                                                                      |
| ---------------------------- | ------------------------------------------------- | ------------------------------------------------------------------------------------------------ |
| `arithmeticMeanWeightedTick` | struct WeightedOracleLibrary.PeriodObservation\[] | The arithmetic mean tick, weighted by the observations' time-weighted harmonic average liquidity |


---

# 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/weightedoraclelibrary.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.
