MixedPriceOracleV3

Git Source

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

NameTypeDescription
rolebytes32Role 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

NameTypeDescription
symbols_string[]Array of token symbols
configs_IDefaultAdapter.PriceConfig[]Array of price configs for symbols
roles_addressRoles contract address
stalenessPeriod_uint256Default staleness period

setStaleness

Sets a custom staleness period for a symbol

function setStaleness(string calldata symbol, uint256 val) external onlyRole(ROLES.GUARDIAN_ORACLE());

Parameters

NameTypeDescription
symbolstringSymbol to update
valuint256New 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

NameTypeDescription
symbolstringSymbol to configure
configIDefaultAdapter.PriceConfigPrice configuration

getUnderlyingPrice

Returns underlying price for an mToken

function getUnderlyingPrice(address mToken) external view override returns (uint256);

Parameters

NameTypeDescription
mTokenaddressAddress of the mToken

Returns

NameTypeDescription
<none>uint256Price 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

NameTypeDescription
mTokenaddressAddress of the mToken

Returns

NameTypeDescription
<none>uint256Price denominated in USD with 18 decimals

_getPriceUSD

Returns the USD price for a symbol

function _getPriceUSD(string memory symbol) internal view returns (uint256);

Parameters

NameTypeDescription
symbolstringToken symbol

Returns

NameTypeDescription
<none>uint256price 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

NameTypeDescription
symbolstringToken symbol
configIDefaultAdapter.PriceConfigPrice configuration for the symbol

Returns

NameTypeDescription
<none>uint256price Latest price from feed
<none>uint256decimals 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

NameTypeDescription
symbolstringToken symbol

Returns

NameTypeDescription
<none>uint256Staleness period in seconds

_onlyRole

Ensures caller has specific role

function _onlyRole(bytes32 role) internal view;

Parameters

NameTypeDescription
rolebytes32Role identifier to check

Events

ConfigSet

Emitted when a configuration is set for a symbol

event ConfigSet(string symbol, IDefaultAdapter.PriceConfig config);

Parameters

NameTypeDescription
symbolstringSymbol being configured
configIDefaultAdapter.PriceConfigPrice configuration applied

StalenessUpdated

Emitted when staleness is updated for a symbol

event StalenessUpdated(string symbol, uint256 val);

Parameters

NameTypeDescription
symbolstringSymbol being updated
valuint256New 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();