BandAdapterLib
Title: BandAdapterLib
Authors: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80), Modified from Band Protocol (https://github.com/bandprotocol)
Library wrapping the Band Protocol standard reference oracle with per-feed staleness configuration and WAD normalization, exposing the shared IPriceOracleReader read surface.
Three-layer pattern: this library holds the logic + namespaced storage; the stateless
BandAdapter facet forwards to it. Band uses a SINGLE global StdReference contract per chain;
reads use getReferenceData(base, quote) and validate registration, sign, future timestamp, and
staleness on-chain. Band rates are already 1e18-scaled, so normalization only widens
uint256 -> int256.
Functions
bandAdapterStorage
function bandAdapterStorage() internal pure returns (BandAdapterStorage storage $);Returns
| Name | Type | Description |
|---|---|---|
| $ | BandAdapterStorage |
__BandAdapter_init
Initializes BandAdapter with the StdReference contract and registers the ERC-165 interface.
Must be called between preInitializer / postInitializer.
function __BandAdapter_init(address reference_) internal;Parameters
| Name | Type | Description |
|---|---|---|
| reference_ | address |
registerInterface
Writes true to the ERC-165 map slot for IBandAdapter.
function registerInterface() internal;stdReference
function stdReference() internal view returns (address);Returns
| Name | Type | Description |
|---|---|---|
| <none> | address |
getFeed
function getFeed(bytes32 key) internal view returns (string memory base, string memory quote, uint48 maxStaleness);Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 |
Returns
| Name | Type | Description |
|---|---|---|
| base | string | |
| quote | string | |
| maxStaleness | uint48 |
getReferenceData
Returns the validated raw Band reference data for key.
Validates: registration, sign (rate != 0), future-timestamp, and staleness. Staleness is
measured against the older of the two symbol update timestamps.
function getReferenceData(bytes32 key)
internal
view
returns (uint256 rate, uint256 lastUpdatedBase, uint256 lastUpdatedQuote);Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 |
Returns
| Name | Type | Description |
|---|---|---|
| rate | uint256 | |
| lastUpdatedBase | uint256 | |
| lastUpdatedQuote | uint256 |
latestAnswer
Returns the latest rate normalized to 18 decimals (WAD).
Band rates are already 1e18-scaled, so this only widens uint256 -> int256. A rate >= 2^255
would wrap to a negative int256, so it is rejected rather than cast.
function latestAnswer(bytes32 key) internal view returns (int256 answerWad);Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 |
Returns
| Name | Type | Description |
|---|---|---|
| answerWad | int256 |
setReference
function setReference(address reference_) internal;Parameters
| Name | Type | Description |
|---|---|---|
| reference_ | address |
registerFeed
function registerFeed(bytes32 key, string calldata base, string calldata quote, uint48 maxStaleness) internal;Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 | |
| base | string | |
| quote | string | |
| maxStaleness | uint48 |
unregisterFeed
function unregisterFeed(bytes32 key) internal;Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 |
_requireReference
function _requireReference() private view returns (address r);Returns
| Name | Type | Description |
|---|---|---|
| r | address |