MixedPriceOracleV3
Inherits: IOracleOperator
Title: MixedPriceOracleV3
Author: Merge Layers Inc.
Mixed price oracle contract
State Variables
STALENESS_PERIOD
Staleness period
uint256 public immutable STALENESS_PERIOD
ROLES
Roles contract
IRoles public immutable ROLES
configs
Mapping of symbols to price configs
mapping(string symbol => IDefaultAdapter.PriceConfig config) public configs
stalenessPerSymbol
Mapping of symbols to staleness periods
mapping(string symbol => uint256 staleness) public stalenessPerSymbol
Functions
onlyRole
Modifier to check if the caller has specific role
modifier onlyRole(bytes32 role) ;
Parameters
| Name | Type | Description |
|---|---|---|
role | bytes32 | Role identifier to check |
constructor
Initializes the oracle with symbols, configs, roles, and default staleness
constructor(
string[] memory symbols_,
IDefaultAdapter.PriceConfig[] memory configs_,
address roles_,
uint256 stalenessPeriod_
) ;
Parameters
| Name | Type | Description |
|---|---|---|
symbols_ | string[] | Array of token symbols |
configs_ | IDefaultAdapter.PriceConfig[] | Array of price configs for symbols |
roles_ | address | Roles contract address |
stalenessPeriod_ | uint256 | Default staleness period |
setStaleness
Sets a custom staleness period for a symbol
function setStaleness(string calldata symbol, uint256 val) external onlyRole(ROLES.GUARDIAN_ORACLE());
Parameters
| Name | Type | Description |
|---|---|---|
symbol | string | Symbol to update |
val | uint256 | New staleness value |
setConfig
Sets a price configuration for a symbol
function setConfig(string calldata symbol, IDefaultAdapter.PriceConfig calldata config)
external
onlyRole(ROLES.GUARDIAN_ORACLE());
Parameters
| Name | Type | Description |
|---|---|---|
symbol | string | Symbol to configure |
config | IDefaultAdapter.PriceConfig | Price configuration |
getUnderlyingPrice
Returns underlying price for an mToken
function getUnderlyingPrice(address mToken) external view override returns (uint256);
Parameters
| Name | Type | Description |
|---|---|---|
mToken | address | Address of the mToken |
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | Price denominated in USD with 18 decimals adjusted for underlying decimals |
getPrice
Returns price for an mToken
function getPrice(address mToken) public view returns (uint256);
Parameters
| Name | Type | Description |
|---|---|---|
mToken | address | Address of the mToken |
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | Price denominated in USD with 18 decimals |
_getPriceUSD
Returns the USD price for a symbol
function _getPriceUSD(string memory symbol) internal view returns (uint256);
Parameters
| Name | Type | Description |
|---|---|---|
symbol | string | Token symbol |
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | price Price denominated in USD with 18 decimals |
_getLatestPrice
Fetches the latest price from configured feeds
function _getLatestPrice(string memory symbol, IDefaultAdapter.PriceConfig memory config)
internal
view
returns (uint256, uint256);
Parameters
| Name | Type | Description |
|---|---|---|
symbol | string | Token symbol |
config | IDefaultAdapter.PriceConfig | Price configuration for the symbol |
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | price Latest price from feed |
<none> | uint256 | decimals Decimals returned by the feed |
_getStaleness
Returns staleness for a symbol or default if not set
function _getStaleness(string memory symbol) internal view returns (uint256);
Parameters
| Name | Type | Description |
|---|---|---|
symbol | string | Token symbol |
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | Staleness period in seconds |
_onlyRole
Ensures caller has specific role
function _onlyRole(bytes32 role) internal view;
Parameters
| Name | Type | Description |
|---|---|---|
role | bytes32 | Role identifier to check |
Events
ConfigSet
Emitted when a configuration is set for a symbol
event ConfigSet(string symbol, IDefaultAdapter.PriceConfig config);
Parameters
| Name | Type | Description |
|---|---|---|
symbol | string | Symbol being configured |
config | IDefaultAdapter.PriceConfig | Price configuration applied |
StalenessUpdated
Emitted when staleness is updated for a symbol
event StalenessUpdated(string symbol, uint256 val);
Parameters
| Name | Type | Description |
|---|---|---|
symbol | string | Symbol being updated |
val | uint256 | New staleness value |
Errors
MixedPriceOracle_Unauthorized
Error thrown when caller lacks required role
error MixedPriceOracle_Unauthorized();
MixedPriceOracle_StalePrice
Error thrown when price is stale
error MixedPriceOracle_StalePrice();
MixedPriceOracle_InvalidPrice
Error thrown when price returned is invalid
error MixedPriceOracle_InvalidPrice();
MixedPriceOracle_InvalidRound
Error thrown when price round is invalid
error MixedPriceOracle_InvalidRound();
MixedPriceOracle_InvalidConfig
Error thrown when configuration is invalid
error MixedPriceOracle_InvalidConfig();
MixedPriceOracle_AddressNotValid
Error thrown when roles contract address is invalid
error MixedPriceOracle_AddressNotValid();