Skip to content
Lattice

API3AdapterLib

Git Source

Title: API3AdapterLib

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

Library wrapping API3 dAPI reader proxies with per-feed staleness configuration, exposing the shared IPriceOracleReader read surface.

Three-layer pattern: this library holds the logic + namespaced storage; the stateless API3Adapter facet forwards to it. dAPI values are already 18-decimals (WAD), so normalization only widens int224 -> int256; reads validate sign, future timestamp, and staleness on-chain.

Functions

api3AdapterStorage

function api3AdapterStorage() internal pure returns (API3AdapterStorage storage $);

Returns

NameTypeDescription
$API3AdapterStorage

__API3Adapter_init

Registers the IAPI3Adapter ERC-165 interface.

Must be called between preInitializer / postInitializer.

function __API3Adapter_init() internal;

registerInterface

Writes true to the ERC-165 map slot for IAPI3Adapter.

function registerInterface() internal;

getFeed

function getFeed(bytes32 key) internal view returns (address proxy, uint48 maxStaleness);

Parameters

NameTypeDescription
keybytes32

Returns

NameTypeDescription
proxyaddress
maxStalenessuint48

read

Returns the validated raw dAPI value (native int224) and its update timestamp.

Validates: registration, sign (value > 0), future-timestamp, and staleness.

function read(bytes32 key) internal view returns (int224 value, uint32 timestamp);

Parameters

NameTypeDescription
keybytes32

Returns

NameTypeDescription
valueint224
timestampuint32

latestAnswer

Returns the latest dAPI value normalized to 18 decimals (WAD).

dAPI values are already 1e18-scaled, so this only widens int224 -> int256.

function latestAnswer(bytes32 key) internal view returns (int256 answerWad);

Parameters

NameTypeDescription
keybytes32

Returns

NameTypeDescription
answerWadint256

registerFeed

function registerFeed(bytes32 key, address proxy, uint48 maxStaleness) internal;

Parameters

NameTypeDescription
keybytes32
proxyaddress
maxStalenessuint48

unregisterFeed

function unregisterFeed(bytes32 key) internal;

Parameters

NameTypeDescription
keybytes32