API3Adapter
Inherits: IAPI3Adapter
Title: API3Adapter
Authors: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80), Modified from API3 (https://github.com/api3dao/contracts)
Diamond facet that reads API3 dAPIs through their reader proxies with per-feed staleness configuration and WAD-normalized answers.
Stateless delegator — all logic and storage live in API3AdapterLib. Consumers inherit this contract and add AccessControl + an initializer.
Notes:
- lattice-version: 0.1.0
- lattice-source: API3
Functions
getFeed
Returns a feed's configuration.
function getFeed(bytes32 key) external view virtual override returns (address proxy, uint48 maxStaleness);Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 | The feed identifier. |
Returns
| Name | Type | Description |
|---|---|---|
| proxy | address | The dAPI reader proxy address. |
| maxStaleness | uint48 | Maximum 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 / non-positive value.
function latestAnswer(bytes32 key) external view virtual override returns (int256 answerWad);Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 | The feed identifier. |
Returns
| Name | Type | Description |
|---|---|---|
| answerWad | int256 | The latest price scaled to 1e18. |
read
Returns the validated raw dAPI value and its update timestamp, in API3's native types.
Provider-native reader (mirrors IApi3Proxy.read); keeps this adapter's ERC-165 id distinct
from other read adapters that share the latestAnswer selector.
function read(bytes32 key) external view virtual override returns (int224 value, uint32 timestamp);Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 | The feed identifier. |
Returns
| Name | Type | Description |
|---|---|---|
| value | int224 | The dAPI value (already 18 decimals). |
| timestamp | uint32 | The off-chain update timestamp. |
registerFeed
Registers a dAPI feed under key. Caller must hold DEFAULT_ADMIN_ROLE.
function registerFeed(bytes32 key, address proxy, uint48 maxStaleness) external virtual override;Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 | The arbitrary feed identifier. |
| proxy | address | The dAPI reader proxy address (non-zero). |
| maxStaleness | uint48 | Maximum age (seconds); must be non-zero. |
unregisterFeed
Removes a registered feed. Caller must hold DEFAULT_ADMIN_ROLE.
function unregisterFeed(bytes32 key) external virtual override;Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 | The feed identifier to remove. |
exportSelectors
ERC-8153 selector export: this facet's cuttable selectors, tightly packed (4 bytes each).
Excludes exportSelectors() itself (0x0ef22643) - it is never cut into a diamond. Order matches
forge inspect API3Adapter methodIdentifiers (alphabetical by signature); kept in exact parity by
ExportSelectorsParityTest. Chunks:
getFeed(bytes32) 0x280aebcf
latestAnswer(bytes32) 0x084d4783
read(bytes32) 0x61da1439
registerFeed(bytes32,address,uint48) 0x915d3063
unregisterFeed(bytes32) 0x2a589908
function exportSelectors() external pure virtual returns (bytes memory selectors);Returns
| Name | Type | Description |
|---|---|---|
| selectors | bytes |