Skip to content
Lattice

ChainlinkAdapter

Git Source

Inherits: IChainlinkAdapter

Title: ChainlinkAdapter

Authors: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80), Modified from Chainlink (https://github.com/smartcontractkit/chainlink-evm/blob/develop/contracts/src/v0.8/shared/interfaces/AggregatorV3Interface.sol)

Diamond facet that exposes Chainlink AggregatorV3 price feeds with per-feed staleness configuration and WAD-normalised answers.

Stateless delegator — all logic and storage live in ChainlinkAdapterLib. Consumers inherit this contract and add AccessControl + an initializer.

Notes:

  • lattice-version: 0.1.0
  • lattice-source: Chainlink

Functions

getFeed

Returns the registered feed address and staleness threshold for a key.

function getFeed(bytes32 key) external view virtual override 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 virtual override 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
        virtual
        override
        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 virtual override;

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 virtual override;

Parameters

NameTypeDescription
keybytes32The feed identifier to remove.

exportSelectors

ERC-8153 selector export: this facet's cuttable selectors, tightly packed (4 bytes each).

Excludes exportSelectors() itself (0x0ef22643) - it is never cut into a diamond. Order matches forge inspect ChainlinkAdapter methodIdentifiers (alphabetical by signature); kept in exact parity by ExportSelectorsParityTest. Chunks: getFeed(bytes32) 0x280aebcf latestAnswer(bytes32) 0x084d4783 latestAnswerRaw(bytes32) 0xad0ddbee registerFeed(bytes32,address,uint48) 0x915d3063 unregisterFeed(bytes32) 0x2a589908

function exportSelectors() external pure virtual returns (bytes memory selectors);

Returns

NameTypeDescription
selectorsbytes