ChainlinkOracle
Inherits: IChainlinkOracle, IOracleMiddlewareErrors
This contract is used to get the price of an asset from Chainlink. It is used by the USDN protocol to get the price of the USDN underlying asset, and by the LiquidationRewardsManager to get the price of the gas.
State Variables
PRICE_TOO_OLD
The sentinel value returned instead of the price if the data from the oracle is too old.
int256 public constant PRICE_TOO_OLD = type(int256).min;
_priceFeed
The Chainlink price feed aggregator contract.
AggregatorV3Interface internal immutable _priceFeed;
_timeElapsedLimit
Tolerated elapsed time until we consider the data too old.
uint256 internal _timeElapsedLimit;
Functions
constructor
constructor(address chainlinkPriceFeed, uint256 timeElapsedLimit);
Parameters
Name | Type | Description |
---|---|---|
chainlinkPriceFeed | address | Address of the price feed. |
timeElapsedLimit | uint256 | Tolerated elapsed time before the data is considered invalid. |
getChainlinkDecimals
Gets the number of decimals of the asset from Chainlink.
function getChainlinkDecimals() public view returns (uint256 decimals_);
Returns
Name | Type | Description |
---|---|---|
decimals_ | uint256 | The number of decimals of the asset. |
getPriceFeed
Gets the Chainlink price feed aggregator contract address.
function getPriceFeed() public view returns (AggregatorV3Interface priceFeed_);
Returns
Name | Type | Description |
---|---|---|
priceFeed_ | AggregatorV3Interface | The address of the Chainlink price feed contract. |
getChainlinkTimeElapsedLimit
Gets the duration after which the Chainlink data is considered stale or invalid.
function getChainlinkTimeElapsedLimit() external view returns (uint256 limit_);
Returns
Name | Type | Description |
---|---|---|
limit_ | uint256 | The price validity duration. |
_getChainlinkLatestPrice
Gets the latest price of the asset from Chainlink.
If the price is too old, the returned price will be equal to PRICE_TOO_OLD
.
function _getChainlinkLatestPrice() internal view virtual returns (ChainlinkPriceInfo memory price_);
Returns
Name | Type | Description |
---|---|---|
price_ | ChainlinkPriceInfo | The price of the asset. |
_getFormattedChainlinkLatestPrice
Gets the latest price of the asset from Chainlink, formatted to the specified number of decimals.
function _getFormattedChainlinkLatestPrice(uint256 middlewareDecimals)
internal
view
returns (ChainlinkPriceInfo memory formattedPrice_);
Parameters
Name | Type | Description |
---|---|---|
middlewareDecimals | uint256 | The number of decimals to format the price to. |
Returns
Name | Type | Description |
---|---|---|
formattedPrice_ | ChainlinkPriceInfo | The formatted price of the asset. |
_getFormattedChainlinkPrice
Gets the price of the asset at the specified round ID, formatted to the specified number of decimals.
function _getFormattedChainlinkPrice(uint256 middlewareDecimals, uint80 roundId)
internal
view
returns (ChainlinkPriceInfo memory formattedPrice_);
Parameters
Name | Type | Description |
---|---|---|
middlewareDecimals | uint256 | The number of decimals to format the price to. |
roundId | uint80 | The targeted round ID. |
Returns
Name | Type | Description |
---|---|---|
formattedPrice_ | ChainlinkPriceInfo | The formatted price of the asset. |
_getChainlinkPrice
Gets the price of the asset at the specified round ID.
function _getChainlinkPrice(uint80 roundId) internal view virtual returns (ChainlinkPriceInfo memory price_);
Parameters
Name | Type | Description |
---|---|---|
roundId | uint80 | The Chainlink roundId price. |
Returns
Name | Type | Description |
---|---|---|
price_ | ChainlinkPriceInfo | The price of the asset. |