# @indexed-finance/uniswap-v2-oracle

`IndexedUniswapV2Oracle`

`IndexedUniswapV2Oracle`

## Functions:

`constructor`

`constructor`

`updatePrice`

`updatePrice`

Attempts to update the price of `token`

and returns a boolean indicating whether it was updated.

**Note:** The price can be updated if there is no observation for the current hour and at least 30 minutes have passed since the last observation.

`updatePrices`

`updatePrices`

Attempts to update the price of each token in `tokens`

and returns a boolean array indicating which tokens had their prices updated.

**Note:** The price can be updated if there is no observation for the current hour and at least 30 minutes have passed since the last observation.

`hasPriceObservationInWindow`

`hasPriceObservationInWindow`

Returns a boolean indicating whether a price was recorded for `token`

at `priceKey`

.

#### Parameters:

`token`

: Token to check if the oracle has a price for`priceKey`

: Index of the hour to check

`getPriceObservationInWindow`

`getPriceObservationInWindow`

Returns the price observation for `token`

recorded in `priceKey`

. Reverts if no prices have been recorded for that key.

#### Parameters:

`token`

: Token to retrieve a price for`priceKey`

: Index of the hour to query

`getPriceObservationsInRange`

`getPriceObservationsInRange`

Returns all price observations for `token`

recorded between `timeFrom`

and `timeTo`

.

`canUpdatePrice`

`canUpdatePrice`

Returns a boolean indicating whether the price of `token`

can be updated.

**Note:** The price can be updated if there is no observation for the current hour and at least 30 minutes have passed since the last observation.

`canUpdatePrices`

`canUpdatePrices`

Returns a boolean array indicating whether the price of each token in `tokens`

can be updated.

**Note:** The price can be updated if there is no observation for the current hour and at least 30 minutes have passed since the last observation.

`computeTwoWayAveragePrice`

`computeTwoWayAveragePrice`

Returns the TwoWayAveragePrice struct representing the average price of weth in terms of `token`

and the average price of `token`

in terms of weth.

Computes the time-weighted average price of weth in terms of `token`

and the price of `token`

in terms of weth by getting the current prices from Uniswap and searching for a historical price which is between `minTimeElapsed`

and `maxTimeElapsed`

seconds old.

**Note:** `maxTimeElapsed`

is only accurate to the nearest hour (rounded down) unless it is less than one hour.

**Note:** `minTimeElapsed`

is only accurate to the nearest hour (rounded up) unless it is less than one hour.

`computeAverageTokenPrice`

`computeAverageTokenPrice`

Returns the UQ112x112 struct representing the average price of `token`

in terms of weth.

Computes the time-weighted average price of `token`

in terms of weth by getting the current price from Uniswap and searching for a historical price which is between `minTimeElapsed`

and `maxTimeElapsed`

seconds old.

**Note:** `maxTimeElapsed`

is only accurate to the nearest hour (rounded down) unless it is less than one hour.

**Note:** `minTimeElapsed`

is only accurate to the nearest hour (rounded up) unless it is less than one hour.

`computeAverageEthPrice`

`computeAverageEthPrice`

Returns the UQ112x112 struct representing the average price of weth in terms of `token`

.

Computes the time-weighted average price of weth in terms of `token`

by getting the current price from Uniswap and searching for a historical price which is between `minTimeElapsed`

and `maxTimeElapsed`

seconds old.

**Note:** `maxTimeElapsed`

is only accurate to the nearest hour (rounded down) unless it is less than one hour.

**Note:** `minTimeElapsed`

is only accurate to the nearest hour (rounded up) unless it is less than one hour.

`computeTwoWayAveragePrices`

`computeTwoWayAveragePrices`

Returns the TwoWayAveragePrice structs representing the average price of weth in terms of each token in `tokens`

and the average price of each token in terms of weth.

Computes the time-weighted average price of weth in terms of each token and the price of each token in terms of weth by getting the current prices from Uniswap and searching for a historical price which is between `minTimeElapsed`

and `maxTimeElapsed`

seconds old.

**Note:** `maxTimeElapsed`

is only accurate to the nearest hour (rounded down) unless it is less than one hour.

**Note:** `minTimeElapsed`

is only accurate to the nearest hour (rounded up) unless it is less than one hour.

`computeAverageTokenPrices`

`computeAverageTokenPrices`

Returns the UQ112x112 structs representing the average price of each token in `tokens`

in terms of weth.

Computes the time-weighted average price of each token in terms of weth by getting the current price from Uniswap and searching for a historical price which is between `minTimeElapsed`

and `maxTimeElapsed`

seconds old.

**Note:** `maxTimeElapsed`

is only accurate to the nearest hour (rounded down) unless it is less than one hour.

**Note:** `minTimeElapsed`

is only accurate to the nearest hour (rounded up) unless it is less than one hour.

`computeAverageEthPrices`

`computeAverageEthPrices`

Returns the UQ112x112 structs representing the average price of weth in terms of each token in `tokens`

.

Computes the time-weighted average price of weth in terms of each token by getting the current price from Uniswap and searching for a historical price which is between `minTimeElapsed`

and `maxTimeElapsed`

seconds old.

**Note:** `maxTimeElapsed`

is only accurate to the nearest hour (rounded down) unless it is less than one hour. **Note:** `minTimeElapsed`

is only accurate to the nearest hour (rounded up) unless it is less than one hour.

`computeAverageEthForTokens`

`computeAverageEthForTokens`

Compute the average value of `tokenAmount`

ether in terms of weth. Computes the time-weighted average price of `token`

in terms of weth by getting the current price from Uniswap and searching for a historical price which is between `minTimeElapsed`

and `maxTimeElapsed`

seconds old, then multiplies by `wethAmount`

. **Note:** `maxTimeElapsed`

is only accurate to the nearest hour (rounded down) unless it is less than one hour. **Note:** `minTimeElapsed`

is only accurate to the nearest hour (rounded up) unless it is less than one hour.

`computeAverageTokensForEth`

`computeAverageTokensForEth`

Compute the average value of `wethAmount`

ether in terms of `token`

. Computes the time-weighted average price of weth in terms of the token by getting the current price from Uniswap and searching for a historical price which is between `minTimeElapsed`

and `maxTimeElapsed`

seconds old, then multiplies by `wethAmount`

. **Note:** `maxTimeElapsed`

is only accurate to the nearest hour (rounded down) unless it is less than one hour. **Note:** `minTimeElapsed`

is only accurate to the nearest hour (rounded up) unless it is less than one hour.

`computeAverageEthForTokens`

`computeAverageEthForTokens`

Compute the average value of each amount of tokens in `tokenAmounts`

in terms of the corresponding token in `tokens`

. Computes the time-weighted average price of each token in terms of weth by getting the current price from Uniswap and searching for a historical price which is between `minTimeElapsed`

and `maxTimeElapsed`

seconds old, then multiplies by the corresponding amount in `tokenAmounts`

. **Note:** `maxTimeElapsed`

is only accurate to the nearest hour (rounded down) unless it is less than one hour. **Note:** `minTimeElapsed`

is only accurate to the nearest hour (rounded up) unless it is less than one hour.

`computeAverageTokensForEth`

`computeAverageTokensForEth`

Compute the average value of each amount of ether in `wethAmounts`

in terms of the corresponding token in `tokens`

. Computes the time-weighted average price of weth in terms of each token by getting the current price from Uniswap and searching for a historical price which is between `minTimeElapsed`

and `maxTimeElapsed`

seconds old, then multiplies by the corresponding amount in `wethAmounts`

. **Note:** `maxTimeElapsed`

is only accurate to the nearest hour (rounded down) unless it is less than one hour. **Note:** `minTimeElapsed`

is only accurate to the nearest hour (rounded up) unless it is less than one hour.

`_getTwoWayPrice`

`_getTwoWayPrice`

`_getTokenPrice`

`_getTokenPrice`

`_getEthPrice`

`_getEthPrice`

Last updated