Skip to content
Lattice

IDIAAdapter

Git Source

Title: IDIAAdapter

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

Interface for the DIAAdapter Diamond facet — reads DIA OracleV2 price feeds through their string-keyed getValue API and exposes WAD-normalized answers.

DIA values are read via IDIAOracleV2.getValue(string) -> (uint128 value, uint128 timestamp); value has 8 decimals and is normalized to 18 decimals (WAD) by multiplying by 1e10. Feeds are keyed by an arbitrary bytes32 mapped to an oracle address + DIA key string. latestAnswer(bytes32)->int256 is declared with the same selector as IPriceOracleReader, so consumers can read this adapter through that provider-agnostic interface. (Declared directly, not by inheriting IPriceOracleReader, because Solidity excludes inherited functions from type(I).interfaceId, which would shift the ERC-165 id.) The native getValue(bytes32) reader keeps this adapter's ERC-165 id distinct from other adapters that share the latestAnswer selector.

The adapter does NOT check an L2 sequencer-uptime feed and does NOT bound the answer to a sane range. Integrators that need either check read through the opt-in IOracleGuard (OracleGuard facet) instead of calling latestAnswer directly.

Functions

getFeed

Returns a feed's configuration.

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

Parameters

NameTypeDescription
keybytes32The feed identifier.

Returns

NameTypeDescription
oracleaddressThe DIA OracleV2 contract address.
diaKeystringThe DIA price key string.
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 / zero value.

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

Parameters

NameTypeDescription
keybytes32The feed identifier.

Returns

NameTypeDescription
answerWadint256The latest price scaled to 1e18.

getValue

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

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

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

Parameters

NameTypeDescription
keybytes32The feed identifier.

Returns

NameTypeDescription
valueuint128The DIA value (8 decimals).
timestampuint128The off-chain update timestamp.

registerFeed

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

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

Parameters

NameTypeDescription
keybytes32The arbitrary feed identifier.
oracleaddressThe DIA OracleV2 contract address (non-zero).
diaKeystringThe DIA price key string (non-empty).
maxStalenessuint48Maximum age (seconds); must be non-zero.

unregisterFeed

Removes a registered feed. Caller must hold DEFAULT_ADMIN_ROLE.

function unregisterFeed(bytes32 key) external;

Parameters

NameTypeDescription
keybytes32The feed identifier to remove.

Events

FeedRegistered

Emitted when a feed is registered or updated.

event FeedRegistered(bytes32 indexed key, address indexed oracle, string diaKey, uint48 maxStaleness);

Parameters

NameTypeDescription
keybytes32The arbitrary feed identifier.
oracleaddressThe DIA OracleV2 contract address.
diaKeystringThe DIA price key string (e.g. "ETH/USD").
maxStalenessuint48Maximum age (seconds) before a value is stale.

FeedUnregistered

Emitted when a feed is removed.

event FeedUnregistered(bytes32 indexed key);

Parameters

NameTypeDescription
keybytes32The removed feed identifier.

Errors

DIAFeedNotRegistered

The requested feed key has not been registered.

error DIAFeedNotRegistered(bytes32 key);

Parameters

NameTypeDescription
keybytes32

DIAStaleData

The value is older than the feed's maxStaleness (or has a future timestamp).

error DIAStaleData(bytes32 key, uint256 timestamp, uint256 maxStaleness);

Parameters

NameTypeDescription
keybytes32
timestampuint256
maxStalenessuint256

DIAInvalidAnswer

The oracle returned a zero value.

error DIAInvalidAnswer(bytes32 key, uint128 value);

Parameters

NameTypeDescription
keybytes32
valueuint128

DIAInvalidConfig

registerFeed was called with a zero oracle address, empty key string, or zero maxStaleness.

error DIAInvalidConfig();