IOracleRegistry
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
| Name | Type | Description |
|---|---|---|
_token | address | Token address to query |
Returns
| Name | Type | Description |
|---|---|---|
oracle_ | address | Address 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
| Name | Type | Description |
|---|---|---|
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
| Name | Type | Description |
|---|---|---|
timestamp_ | uint256 | Timestamp 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
| Name | Type | Description |
|---|---|---|
timestamp_ | uint256 | Timestamp 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
| Name | Type | Description |
|---|---|---|
_token | address | Token address |
Returns
| Name | Type | Description |
|---|---|---|
price_ | uint256 | Latest 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
| Name | Type | Description |
|---|---|---|
_token | address | Token address |
_index | uint256 | Index (0 = latest) |
Returns
| Name | Type | Description |
|---|---|---|
price_ | uint256 | Historical 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
| Name | Type | Description |
|---|---|---|
_token | address | Token address |
_index | uint256 | Index (0 = latest) |
Returns
| Name | Type | Description |
|---|---|---|
price_ | uint256 | Historical 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
| Name | Type | Description |
|---|---|---|
_index | uint256 | Index (0 = latest) |
Returns
| Name | Type | Description |
|---|---|---|
price_ | uint256 | Vault 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
| Name | Type | Description |
|---|---|---|
_index | uint256 | Index (0 = latest) |
Returns
| Name | Type | Description |
|---|---|---|
price_ | uint256 | Vault 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
| Name | Type | Description |
|---|---|---|
_token | address | Token address |
_index | uint256 | Index of cut-off update (0 = latest) |
Returns
| Name | Type | Description |
|---|---|---|
price_ | uint256 | The 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
| Name | Type | Description |
|---|---|---|
_index | uint256 | Index of cut-off update (0 = latest) |
Returns
| Name | Type | Description |
|---|---|---|
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
| Name | Type | Description |
|---|---|---|
_index | uint256 | Index of cut-off update (0 = latest) |
Returns
| Name | Type | Description |
|---|---|---|
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
| Name | Type | Description |
|---|---|---|
_index | uint256 | Index of cut-off update (0 = latest) |
Returns
| Name | Type | Description |
|---|---|---|
price_ | uint256 | Vault 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
| Name | Type | Description |
|---|---|---|
_index | uint256 | Index of cut-off update (0 = latest) |
Returns
| Name | Type | Description |
|---|---|---|
price_ | uint256 | Vault 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
| Name | Type | Description |
|---|---|---|
token | address | The token address associated with the oracle |
oracle | address | The 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
| Name | Type | Description |
|---|---|---|
token | address | The 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
| Name | Type | Description |
|---|---|---|
token | address | The token address whose oracle is updated |
oracle | address | The 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
| Name | Type | Description |
|---|---|---|
token | address | The token address |
price | uint256 | The new price |
updatedAt | uint256 | Timestamp when the price is updated |
isCutOffPrice | bool | Whether this price is a cut-off price |