IChainlinkAdapter
Title: IChainlinkAdapter
Author: Modified from Chainlink (https://github.com/smartcontractkit/chainlink-evm/blob/develop/contracts/src/v0.8/shared/interfaces/AggregatorV3Interface.sol)
Interface for the ChainlinkAdapter Diamond facet.
Price feeds are identified by an arbitrary bytes32 key chosen by the
administrator. All answers returned by latestAnswer are normalised to
18 decimal places (WAD).
The adapter checks staleness, round completeness and non-positive answers only. It does NOT check
an L2 sequencer-uptime feed and does NOT bound the answer to a sane range, so on an L2 it can return
a pre-outage answer or one read right after a restart. Integrators that need either check read
through the opt-in IOracleGuard (OracleGuard facet) instead of calling latestAnswer directly.
Functions
getFeed
Returns the registered feed address and staleness threshold for a key.
function getFeed(bytes32 key) external view returns (address feed, uint48 maxStaleness);Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 | The feed identifier. |
Returns
| Name | Type | Description |
|---|---|---|
| feed | address | Address of the AggregatorV3 feed. |
| maxStaleness | uint48 | Maximum age in seconds before data is considered stale. |
latestAnswer
Returns the latest price normalised to 18 decimal places.
function latestAnswer(bytes32 key) external view returns (int256 answerWad);Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 | The feed identifier. |
Returns
| Name | Type | Description |
|---|---|---|
| answerWad | int256 | The latest price scaled to 1e18. |
latestAnswerRaw
Returns the raw latest price, its update timestamp, and the feed's decimals.
function latestAnswerRaw(bytes32 key) external view returns (int256 answer, uint256 updatedAt, uint8 decimals_);Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 | The feed identifier. |
Returns
| Name | Type | Description |
|---|---|---|
| answer | int256 | The raw answer from the feed. |
| updatedAt | uint256 | The timestamp of the last update. |
| decimals_ | uint8 | The number of decimals used by the feed. |
registerFeed
Registers a Chainlink price feed under the given key.
Caller must hold DEFAULT_ADMIN_ROLE. The feed's decimals() is
read and cached at registration time.
function registerFeed(bytes32 key, address feed, uint48 maxStaleness) external;Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 | Arbitrary identifier for this feed. |
| feed | address | Address of the AggregatorV3 contract. |
| maxStaleness | uint48 | Maximum age (seconds) an answer may be before it is considered stale. Must be non-zero. |
unregisterFeed
Removes a registered price feed.
Caller must hold DEFAULT_ADMIN_ROLE.
function unregisterFeed(bytes32 key) external;Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 | The feed identifier to remove. |
Events
FeedRegistered
Emitted when a price feed is registered or updated.
event FeedRegistered(bytes32 indexed key, address feed, uint48 maxStaleness);Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 | Arbitrary identifier for this feed. |
| feed | address | Address of the AggregatorV3 contract. |
| maxStaleness | uint48 | Maximum age (seconds) before an answer is considered stale. |
FeedUnregistered
Emitted when a price feed is removed.
event FeedUnregistered(bytes32 indexed key);Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 | The identifier of the removed feed. |
Errors
ChainlinkFeedNotRegistered
The requested feed key has not been registered.
error ChainlinkFeedNotRegistered(bytes32 key);Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 |
ChainlinkStaleData
The latest round data is older than maxStaleness.
error ChainlinkStaleData(bytes32 key, uint256 updatedAt, uint256 maxStaleness);Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 | The feed identifier. |
| updatedAt | uint256 | The updatedAt timestamp returned by the feed. |
| maxStaleness | uint256 | The configured maximum staleness for this feed. |
ChainlinkInvalidAnswer
The feed returned a non-positive answer.
error ChainlinkInvalidAnswer(bytes32 key, int256 answer);Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 | The feed identifier. |
| answer | int256 | The invalid answer value. |
ChainlinkRoundIncomplete
The round has not been completed (answeredInRound < roundId or updatedAt == 0).
error ChainlinkRoundIncomplete(bytes32 key);Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 | The feed identifier. |
ChainlinkInvalidConfig
registerFeed was called with an invalid parameter (zero feed address
or zero maxStaleness).
error ChainlinkInvalidConfig();