Indexed Finance

Searchâ€¦

Introduction

Day-To-Day Operations

Index Pool Protocol

Index Pool Smart Contracts

Yield Aggregator Protocol

Yield Aggregator Smart Contracts

@indexed-finance/uniswap-v2-oracle

`IndexedUniswapV2Oracle`

Functions:

`constructor`

function constructor(address uniswapFactory, address weth)

`updatePrice`

function updatePrice(address token) returns (bool)

Attempts to update the price of

`token`

and returns a boolean indicating whether it was updated.`updatePrices`

function updatePrices(address[] tokens) returns (bool[] pricesUpdated)

Attempts to update the price of each token in

`tokens`

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

function hasPriceObservationInWindow(address token, uint256 priceKey) returns (bool)

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`

function getPriceObservationInWindow(address token, uint256 priceKey) returns (struct PriceLibrary.PriceObservation observation)

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`

function getPriceObservationsInRange(address token, uint256 timeFrom, uint256 timeTo) returns (struct PriceLibrary.PriceObservation[] prices)

Returns all price observations for

`token`

recorded between `timeFrom`

and `timeTo`

.`canUpdatePrice`

function canUpdatePrice(address token) returns (bool)

Returns a boolean indicating whether the price of

`token`

can be updated.`canUpdatePrices`

function canUpdatePrices(address[] tokens) returns (bool[] canUpdateArr)

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

`tokens`

can be updated.`computeTwoWayAveragePrice`

function computeTwoWayAveragePrice(address token, uint256 minTimeElapsed, uint256 maxTimeElapsed) returns (struct PriceLibrary.TwoWayAveragePrice)

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.`maxTimeElapsed`

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

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

function computeAverageTokenPrice(address token, uint256 minTimeElapsed, uint256 maxTimeElapsed) returns (struct FixedPoint.uq112x112 priceAverage)

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.`maxTimeElapsed`

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

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

function computeAverageEthPrice(address token, uint256 minTimeElapsed, uint256 maxTimeElapsed) returns (struct FixedPoint.uq112x112 priceAverage)

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.`maxTimeElapsed`

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

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

function computeTwoWayAveragePrices(address[] tokens, uint256 minTimeElapsed, uint256 maxTimeElapsed) returns (struct PriceLibrary.TwoWayAveragePrice[] prices)

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.`maxTimeElapsed`

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

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

function computeAverageTokenPrices(address[] tokens, uint256 minTimeElapsed, uint256 maxTimeElapsed) returns (struct FixedPoint.uq112x112[] averagePrices)

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.`maxTimeElapsed`

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

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

function computeAverageEthPrices(address[] tokens, uint256 minTimeElapsed, uint256 maxTimeElapsed) returns (struct FixedPoint.uq112x112[] averagePrices)

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.`maxTimeElapsed`

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

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

function computeAverageEthForTokens(address token, uint256 tokenAmount, uint256 minTimeElapsed, uint256 maxTimeElapsed) returns (uint144)

Compute the average value of **Note:** **Note:**

`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`

. `maxTimeElapsed`

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

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

function computeAverageTokensForEth(address token, uint256 wethAmount, uint256 minTimeElapsed, uint256 maxTimeElapsed) returns (uint144)

Compute the average value of **Note:** **Note:**

`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`

. `maxTimeElapsed`

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

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

function computeAverageEthForTokens(address[] tokens, uint256[] tokenAmounts, uint256 minTimeElapsed, uint256 maxTimeElapsed) returns (uint144[] averageValuesInWETH)

Compute the average value of each amount of tokens in **Note:** **Note:**

`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`

. `maxTimeElapsed`

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

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

function computeAverageTokensForEth(address[] tokens, uint256[] wethAmounts, uint256 minTimeElapsed, uint256 maxTimeElapsed) returns (uint144[] averageValuesInWETH)

Compute the average value of each amount of ether in **Note:** **Note:**

`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`

. `maxTimeElapsed`

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

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

function _getTwoWayPrice(address token, uint256 minTimeElapsed, uint256 maxTimeElapsed) returns (struct PriceLibrary.TwoWayAveragePrice)

`_getTokenPrice`

function _getTokenPrice(address token, uint256 minTimeElapsed, uint256 maxTimeElapsed) returns (struct FixedPoint.uq112x112)

`_getEthPrice`

function _getEthPrice(address token, uint256 minTimeElapsed, uint256 maxTimeElapsed) returns (struct FixedPoint.uq112x112)

Last modified 1yr ago

Copy link

On this page

IndexedUniswapV2Oracle

Functions:

constructor

updatePrice

updatePrices

hasPriceObservationInWindow

getPriceObservationInWindow

getPriceObservationsInRange

canUpdatePrice

canUpdatePrices

computeTwoWayAveragePrice

computeAverageTokenPrice

computeAverageEthPrice

computeTwoWayAveragePrices

computeAverageTokenPrices

computeAverageEthPrices

computeAverageEthForTokens

computeAverageTokensForEth

computeAverageEthForTokens

computeAverageTokensForEth

_getTwoWayPrice

_getTokenPrice

_getEthPrice