ChainlinkOracle

Git Source

Inherits: IOracleOperator

Title: ChainlinkOracle

Author: Merge Layers Inc.

Oracle contract using Chainlink price feeds

State Variables

DECIMALS

Number of decimals for price

uint8 public constant DECIMALS = 18

priceFeeds

Mapping of symbols to price feeds

mapping(string symbol => IAggregatorV3 feed) public priceFeeds

baseUnits

Mapping of symbols to base units

mapping(string symbol => uint256 units) public baseUnits

Functions

constructor

Constructor

constructor(string[] memory symbols_, IAggregatorV3[] memory feeds_, uint256[] memory baseUnits_) ;

Parameters

NameTypeDescription
symbols_string[]Array of symbols
feeds_IAggregatorV3[]Array of price feeds
baseUnits_uint256[]Array of base units

getPrice

Get the price of a mToken asset

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

Parameters

NameTypeDescription
mTokenaddressThe mToken to get the price of

Returns

NameTypeDescription
<none>uint256price The underlying asset price mantissa (scaled by 1e18). Zero means unavailable.

getUnderlyingPrice

Get the underlying price of a mToken asset

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

Parameters

NameTypeDescription
mTokenaddressThe mToken to get the underlying price of

Returns

NameTypeDescription
<none>uint256price The underlying asset price mantissa (scaled by 1e18). Zero means unavailable.

_getLatestPrice

Get the latest price for a symbol

function _getLatestPrice(string memory symbol) internal view returns (uint256, uint256);

Parameters

NameTypeDescription
symbolstringThe symbol to get price for

Returns

NameTypeDescription
<none>uint256answer The price
<none>uint256updatedAt The timestamp when the price was last updated

Errors

ChainlinkOracle_NoPriceFeed

Error thrown when no price feed is found

error ChainlinkOracle_NoPriceFeed();

ChainlinkOracle_ZeroPrice

Error thrown when price is zero

error ChainlinkOracle_ZeroPrice();