Skip to content
Lattice

DIAAdapterLib

Git Source

Title: DIAAdapterLib

Authors: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80), Modified from DIA (https://github.com/diadata-org)

Library wrapping DIA OracleV2 price feeds with per-feed staleness configuration, exposing the shared IPriceOracleReader read surface.

Three-layer pattern: this library holds the logic + namespaced storage; the stateless DIAAdapter facet forwards to it. DIA values have 8 decimals and are normalized to 18 decimals (WAD) by multiplying by 1e10; reads validate zero value, future timestamp, and staleness on-chain.

Functions

diaAdapterStorage

function diaAdapterStorage() internal pure returns (DIAAdapterStorage storage $);

Returns

NameTypeDescription
$DIAAdapterStorage

__DIAAdapter_init

Registers the IDIAAdapter ERC-165 interface.

Must be called between preInitializer / postInitializer.

function __DIAAdapter_init() internal;

registerInterface

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

function registerInterface() internal;

getFeed

function getFeed(bytes32 key) internal view returns (address oracle, string memory diaKey, uint48 maxStaleness);

Parameters

NameTypeDescription
keybytes32

Returns

NameTypeDescription
oracleaddress
diaKeystring
maxStalenessuint48

getValue

Returns the validated raw DIA value (native uint128) and its update timestamp.

Validates: registration, zero-value, future-timestamp, and staleness.

function getValue(bytes32 key) internal view returns (uint128 value, uint128 timestamp);

Parameters

NameTypeDescription
keybytes32

Returns

NameTypeDescription
valueuint128
timestampuint128

latestAnswer

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

DIA values have 8 decimals; multiplying by 1e10 scales them to WAD.

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

Parameters

NameTypeDescription
keybytes32

Returns

NameTypeDescription
answerWadint256

registerFeed

function registerFeed(bytes32 key, address oracle, string calldata diaKey, uint48 maxStaleness) internal;

Parameters

NameTypeDescription
keybytes32
oracleaddress
diaKeystring
maxStalenessuint48

unregisterFeed

function unregisterFeed(bytes32 key) internal;

Parameters

NameTypeDescription
keybytes32