ChainLinkDataConsumer
Introduction
The ChainLinkDataConsumer
contract is a utility component within the protocol, designed to provide real-time, reliable token price data using Chainlink’s decentralized oracle network. Its primary purpose is to normalize and convert the yield generated from different staking tokens (e.g., stETH, wBTC, cbETH) into a common base currency, such as USD. This normalization is crucial for accurately aggregating yield across various DepositPools and ensuring fair distribution of MOR rewards, regardless of the asset type contributed by users.
The contract supports the composition of multiple Chainlink feeds into a single price path (e.g., cbETH/ETH/USD
), which allows for flexible and accurate multi-hop price resolution. These paths are referenced via unique string identifiers and stored as a hash in the contract’s mapping structure. Though the contract does not calculate MOR rewards directly, it provides the foundational price data necessary for consistent yield evaluation.
Key Responsibilities
Composable price path resolution: supports multi-step Chainlink feed composition using stored feed sequences.
Accurate yield normalization: normalizes yield values to a unified base unit (18 decimals, typically USD), enabling consistent reward calculations.
Dynamic feed configuration: allows the owner to register or update Chainlink data feeds by providing token path identifiers and feed arrays.
Chainlink oracle integration: queries live Chainlink aggregators and computes composite price outputs with correct decimal adjustment and error handling.
Storage
dataFeeds
The Chainlink data feed addresses. dataFeeds[<pathId>]
mapping(bytes32 => address[]) public dataFeeds;
Write functions for the contract owner
updateDataFeeds
Updates the list of Chainlink price feed contracts for specified paths. Only callable by the contract owner.
function updateDataFeeds(
string[] calldata paths_,
address[][] calldata feeds_
) external onlyOwner
paths_
Array of unique feed path strings (e.g., ["ETH/USD"])
feeds_
Array of feed address chains, each corresponding to a path. Can include multiple hops (e.g., [ETH/USD, USD/DAI])
Read functions
getPathId
Returns a bytes32
hash of a feed path string. Used to access stored feeds in the mapping.
function getPathId(string memory path_) public pure returns (bytes32)
path_
The string representing the feed path.
decimals
Returns the standard number of decimals used for price normalization. Returns 18
as standard
function decimals() public pure returns (uint8)
getChainLinkDataFeedLatestAnswer
Fetches the latest value from the Chainlink feeds assigned to a specific path ID. Handles multi-hop price feeds (e.g., ETH → USD → EUR).
function getChainLinkDataFeedLatestAnswer(
bytes32 pathId_
) external view returns (uint256)
pathId_
The hashed identifier of a feed path.
supportsInterface
Used for interface detection (ERC165). Returns true if the contract supports a specific interfaceId_
. Supports IChainLinkDataConsumer
, IERC165
.
function supportsInterface(bytes4 interfaceId_) external pure returns (bool)
version
Returns the current version of the contract.
function version() external pure returns (uint256)
Last updated
Was this helpful?