IOracleRegistry

Git Source

Author: luoyhang003

Interface for Oracle Registry contract to manage token oracles and price updates

Handles addition, removal, and updates of token oracles. Stores historical prices and cut-off prices. Includes role-based access control: PRICE_UPDATE_ROLE for price updates, ORACLE_MANAGE_ROLE for oracle management.

Functions

getOracle

Returns the oracle feed address for a given token

Returns zero address if token is not registered

function getOracle(address _token) external view returns (address oracle_);

Parameters

NameTypeDescription
_tokenaddressToken address to query

Returns

NameTypeDescription
oracle_addressAddress of the oracle feed

getTokens

Returns all registered token addresses

Useful for iterating over all tokens to fetch historical prices

function getTokens() external view returns (address[] memory tokens_);

Returns

NameTypeDescription
tokens_address[]Array of token addresses

latestPricesUpdatedAt

Returns the timestamp of the latest common price update

Reverts if no updates exist

function latestPricesUpdatedAt() external view returns (uint256 timestamp_);

Returns

NameTypeDescription
timestamp_uint256Timestamp of latest update

latestCutOffPriceUpdatedAt

Returns the timestamp of the latest cut-off price update

Reverts if no cut-off updates exist

function latestCutOffPriceUpdatedAt() external view returns (uint256 timestamp_);

Returns

NameTypeDescription
timestamp_uint256Timestamp of latest cut-off update

peek

Returns the latest price of a token from its oracle

Performs deviation check to prevent extreme values

function peek(address _token) external view returns (uint256 price_);

Parameters

NameTypeDescription
_tokenaddressToken address

Returns

NameTypeDescription
price_uint256Latest price from oracle

peekAt

Returns historical price for a token at a given index

Checks price validity (time not expired)

function peekAt(address _token, uint256 _index) external view returns (uint256 price_);

Parameters

NameTypeDescription
_tokenaddressToken address
_indexuint256Index (0 = latest)

Returns

NameTypeDescription
price_uint256Historical price

onlyPeekAt

Returns historical price without validity check

Useful for auditing or internal calculations

function onlyPeekAt(address _token, uint256 _index) external view returns (uint256 price_);

Parameters

NameTypeDescription
_tokenaddressToken address
_indexuint256Index (0 = latest)

Returns

NameTypeDescription
price_uint256Historical price

getVaultTokenPrice

Returns the historical price of the vault token at a given index

Checks price validity

function getVaultTokenPrice(uint256 _index) external view returns (uint256 price_);

Parameters

NameTypeDescription
_indexuint256Index (0 = latest)

Returns

NameTypeDescription
price_uint256Vault token price

onlyGetVaultTokenPrice

Returns the historical price of the vault token without validity check

Useful for internal calculations

function onlyGetVaultTokenPrice(uint256 _index) external view returns (uint256 price_);

Parameters

NameTypeDescription
_indexuint256Index (0 = latest)

Returns

NameTypeDescription
price_uint256Vault token price

getCutOffPrice

Returns token price at a cut-off update

Reverts if price is expired or index out of bounds

function getCutOffPrice(address _token, uint256 _index) external view returns (uint256 price_);

Parameters

NameTypeDescription
_tokenaddressToken address
_indexuint256Index of cut-off update (0 = latest)

Returns

NameTypeDescription
price_uint256The cut-off price for the token

getCutOffPrices

Returns token addresses and prices at a cut-off update

Reverts if price is expired or index out of bounds

function getCutOffPrices(uint256 _index) external view returns (address[] memory tokens_, uint256[] memory prices_);

Parameters

NameTypeDescription
_indexuint256Index of cut-off update (0 = latest)

Returns

NameTypeDescription
tokens_address[]Array of token addresses
prices_uint256[]Array of prices for each token

onlyGetCutOffPrices

Same as getCutOffPrices but does not check validity

Useful for internal auditing or calculation

function onlyGetCutOffPrices(uint256 _index)
    external
    view
    returns (address[] memory tokens_, uint256[] memory prices_);

Parameters

NameTypeDescription
_indexuint256Index of cut-off update (0 = latest)

Returns

NameTypeDescription
tokens_address[]Array of token addresses
prices_uint256[]Array of prices for each token

getVaultTokenCutOffPrice

Returns the vault token cut-off price at a given index

Checks validity

function getVaultTokenCutOffPrice(uint256 _index) external view returns (uint256 price_);

Parameters

NameTypeDescription
_indexuint256Index of cut-off update (0 = latest)

Returns

NameTypeDescription
price_uint256Vault token price

onlyGetVaultTokenCutOffPrice

Returns the vault token cut-off price without validity check

Useful for internal calculations

function onlyGetVaultTokenCutOffPrice(uint256 _index) external view returns (uint256 price_);

Parameters

NameTypeDescription
_indexuint256Index of cut-off update (0 = latest)

Returns

NameTypeDescription
price_uint256Vault token price

Events

OracleAdded

Emitted when a new token oracle is added

Only callable via OracleRegistry contract functions that manage oracles

event OracleAdded(address indexed token, address indexed oracle);

Parameters

NameTypeDescription
tokenaddressThe token address associated with the oracle
oracleaddressThe oracle address providing price feeds

OracleRemoved

Emitted when a token oracle is removed

Only callable via OracleRegistry contract functions that manage oracles

event OracleRemoved(address indexed token);

Parameters

NameTypeDescription
tokenaddressThe token address whose oracle is removed

OracleUpdated

Emitted when a token oracle is updated

Only callable via OracleRegistry contract functions that manage oracles

event OracleUpdated(address indexed token, address indexed oracle);

Parameters

NameTypeDescription
tokenaddressThe token address whose oracle is updated
oracleaddressThe new oracle address

PriceUpdated

Emitted when a token price is updated

Only callable by addresses with PRICE_UPDATE_ROLE

event PriceUpdated(address indexed token, uint256 price, uint256 updatedAt, bool isCutOffPrice);

Parameters

NameTypeDescription
tokenaddressThe token address
priceuint256The new price
updatedAtuint256Timestamp when the price is updated
isCutOffPriceboolWhether this price is a cut-off price