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`

1

function constructor(address uniswapFactory, address weth)

Copied!

`updatePrice`

1

function updatePrice(address token) returns (bool)

Copied!

Attempts to update the price of

`token`

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

1

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

Copied!

Attempts to update the price of each token in

`tokens`

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

1

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

Copied!

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`

1

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

Copied!

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`

1

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

Copied!

Returns all price observations for

`token`

recorded between `timeFrom`

and `timeTo`

.`canUpdatePrice`

1

function canUpdatePrice(address token) returns (bool)

Copied!

Returns a boolean indicating whether the price of

`token`

can be updated.`canUpdatePrices`

1

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

Copied!

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

`tokens`

can be updated.`computeTwoWayAveragePrice`

1

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

Copied!

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`

1

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

Copied!

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`

1

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

Copied!

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`

1

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

Copied!

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`

1

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

Copied!

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`

1

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

Copied!

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`

1

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

Copied!

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`

1

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

Copied!

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`

1

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

Copied!

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`

1

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

Copied!

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`

1

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

Copied!

`_getTokenPrice`

1

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

Copied!

`_getEthPrice`

1

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

Copied!

Last modified 10mo ago

Copy link

Contents

IndexedUniswapV2Oracle

Functions:

constructor

updatePrice

updatePrices

hasPriceObservationInWindow

getPriceObservationInWindow

getPriceObservationsInRange

canUpdatePrice

canUpdatePrices

computeTwoWayAveragePrice

computeAverageTokenPrice

computeAverageEthPrice

computeTwoWayAveragePrices

computeAverageTokenPrices

computeAverageEthPrices

computeAverageEthForTokens

computeAverageTokensForEth

computeAverageEthForTokens

computeAverageTokensForEth

_getTwoWayPrice

_getTokenPrice

_getEthPrice