IAPI3Adapter
Title: IAPI3Adapter
Authors: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80), Modified from API3 (https://github.com/api3dao/contracts)
Interface for the API3Adapter Diamond facet — reads API3 dAPIs through their per-feed reader proxy and exposes WAD-normalized answers.
dAPIs are read via IApi3Proxy.read() -> (int224 value, uint32 timestamp); value is already
18-decimals (WAD), so normalization only widens int224 -> int256 (no rescaling). Feeds are keyed
by an arbitrary bytes32 mapped to a dAPI proxy address. 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 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 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 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 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;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;Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 | The feed identifier to remove. |
Events
FeedRegistered
Emitted when a feed is registered or updated.
event FeedRegistered(bytes32 indexed key, address indexed proxy, uint48 maxStaleness);Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 | The arbitrary feed identifier. |
| proxy | address | The dAPI reader proxy address. |
| maxStaleness | uint48 | Maximum age (seconds) before a value is stale. |
FeedUnregistered
Emitted when a feed is removed.
event FeedUnregistered(bytes32 indexed key);Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 | The removed feed identifier. |
Errors
API3FeedNotRegistered
The requested feed key has not been registered.
error API3FeedNotRegistered(bytes32 key);Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 |
API3StaleData
The value is older than the feed's maxStaleness (or has a future timestamp).
error API3StaleData(bytes32 key, uint256 timestamp, uint256 maxStaleness);Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 | |
| timestamp | uint256 | |
| maxStaleness | uint256 |
API3InvalidAnswer
The proxy returned a non-positive value.
error API3InvalidAnswer(bytes32 key, int256 value);Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 | |
| value | int256 |
API3InvalidConfig
registerFeed was called with a zero proxy address or zero maxStaleness.
error API3InvalidConfig();