API3AdapterLib
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
| Name | Type | Description |
|---|---|---|
| $ | 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
| Name | Type | Description |
|---|---|---|
| key | bytes32 |
Returns
| Name | Type | Description |
|---|---|---|
| proxy | address | |
| maxStaleness | uint48 |
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
| Name | Type | Description |
|---|---|---|
| key | bytes32 |
Returns
| Name | Type | Description |
|---|---|---|
| value | int224 | |
| timestamp | uint32 |
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
| Name | Type | Description |
|---|---|---|
| key | bytes32 |
Returns
| Name | Type | Description |
|---|---|---|
| answerWad | int256 |
registerFeed
function registerFeed(bytes32 key, address proxy, uint48 maxStaleness) internal;Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 | |
| proxy | address | |
| maxStaleness | uint48 |
unregisterFeed
function unregisterFeed(bytes32 key) internal;Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 |