Skip to content
Lattice

API3Adapter

Git Source

Inherits: IAPI3Adapter

Title: API3Adapter

Authors: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80), Modified from API3 (https://github.com/api3dao/contracts)

Diamond facet that reads API3 dAPIs through their reader proxies with per-feed staleness configuration and WAD-normalized answers.

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

Notes:

  • lattice-version: 0.1.0
  • lattice-source: API3

Functions

getFeed

Returns a feed's configuration.

function getFeed(bytes32 key) external view virtual override returns (address proxy, uint48 maxStaleness);

Parameters

NameTypeDescription
keybytes32The feed identifier.

Returns

NameTypeDescription
proxyaddressThe dAPI reader proxy address.
maxStalenessuint48Maximum age (seconds) before a value is stale.

latestAnswer

Returns the latest price for key, normalized to 18 decimals (WAD). Selector matches IPriceOracleReader.latestAnswer. Reverts on stale / future / non-positive value.

function latestAnswer(bytes32 key) external view virtual override returns (int256 answerWad);

Parameters

NameTypeDescription
keybytes32The feed identifier.

Returns

NameTypeDescription
answerWadint256The latest price scaled to 1e18.

read

Returns the validated raw dAPI value and its update timestamp, in API3's native types.

Provider-native reader (mirrors IApi3Proxy.read); keeps this adapter's ERC-165 id distinct from other read adapters that share the latestAnswer selector.

function read(bytes32 key) external view virtual override returns (int224 value, uint32 timestamp);

Parameters

NameTypeDescription
keybytes32The feed identifier.

Returns

NameTypeDescription
valueint224The dAPI value (already 18 decimals).
timestampuint32The off-chain update timestamp.

registerFeed

Registers a dAPI feed under key. Caller must hold DEFAULT_ADMIN_ROLE.

function registerFeed(bytes32 key, address proxy, uint48 maxStaleness) external virtual override;

Parameters

NameTypeDescription
keybytes32The arbitrary feed identifier.
proxyaddressThe dAPI reader proxy address (non-zero).
maxStalenessuint48Maximum age (seconds); must be non-zero.

unregisterFeed

Removes a registered 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 API3Adapter methodIdentifiers (alphabetical by signature); kept in exact parity by ExportSelectorsParityTest. Chunks: getFeed(bytes32) 0x280aebcf latestAnswer(bytes32) 0x084d4783 read(bytes32) 0x61da1439 registerFeed(bytes32,address,uint48) 0x915d3063 unregisterFeed(bytes32) 0x2a589908

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

Returns

NameTypeDescription
selectorsbytes