DIAAdapterLib
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
| Name | Type | Description |
|---|---|---|
| $ | 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
| Name | Type | Description |
|---|---|---|
| key | bytes32 |
Returns
| Name | Type | Description |
|---|---|---|
| oracle | address | |
| diaKey | string | |
| maxStaleness | uint48 |
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
| Name | Type | Description |
|---|---|---|
| key | bytes32 |
Returns
| Name | Type | Description |
|---|---|---|
| value | uint128 | |
| timestamp | uint128 |
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
| Name | Type | Description |
|---|---|---|
| key | bytes32 |
Returns
| Name | Type | Description |
|---|---|---|
| answerWad | int256 |
registerFeed
function registerFeed(bytes32 key, address oracle, string calldata diaKey, uint48 maxStaleness) internal;Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 | |
| oracle | address | |
| diaKey | string | |
| maxStaleness | uint48 |
unregisterFeed
function unregisterFeed(bytes32 key) internal;Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 |