Skip to content
Lattice

IChainlinkAdapter

Git Source

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

NameTypeDescription
keybytes32The feed identifier.

Returns

NameTypeDescription
feedaddressAddress of the AggregatorV3 feed.
maxStalenessuint48Maximum 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

NameTypeDescription
keybytes32The feed identifier.

Returns

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

NameTypeDescription
keybytes32The feed identifier.

Returns

NameTypeDescription
answerint256The raw answer from the feed.
updatedAtuint256The timestamp of the last update.
decimals_uint8The 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

NameTypeDescription
keybytes32Arbitrary identifier for this feed.
feedaddressAddress of the AggregatorV3 contract.
maxStalenessuint48Maximum 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

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

NameTypeDescription
keybytes32Arbitrary identifier for this feed.
feedaddressAddress of the AggregatorV3 contract.
maxStalenessuint48Maximum age (seconds) before an answer is considered stale.

FeedUnregistered

Emitted when a price feed is removed.

event FeedUnregistered(bytes32 indexed key);

Parameters

NameTypeDescription
keybytes32The identifier of the removed feed.

Errors

ChainlinkFeedNotRegistered

The requested feed key has not been registered.

error ChainlinkFeedNotRegistered(bytes32 key);

Parameters

NameTypeDescription
keybytes32

ChainlinkStaleData

The latest round data is older than maxStaleness.

error ChainlinkStaleData(bytes32 key, uint256 updatedAt, uint256 maxStaleness);

Parameters

NameTypeDescription
keybytes32The feed identifier.
updatedAtuint256The updatedAt timestamp returned by the feed.
maxStalenessuint256The configured maximum staleness for this feed.

ChainlinkInvalidAnswer

The feed returned a non-positive answer.

error ChainlinkInvalidAnswer(bytes32 key, int256 answer);

Parameters

NameTypeDescription
keybytes32The feed identifier.
answerint256The invalid answer value.

ChainlinkRoundIncomplete

The round has not been completed (answeredInRound < roundId or updatedAt == 0).

error ChainlinkRoundIncomplete(bytes32 key);

Parameters

NameTypeDescription
keybytes32The feed identifier.

ChainlinkInvalidConfig

registerFeed was called with an invalid parameter (zero feed address or zero maxStaleness).

error ChainlinkInvalidConfig();