Skip to content
Lattice

BandAdapterLib

Git Source

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

NameTypeDescription
$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

NameTypeDescription
reference_address

registerInterface

Writes true to the ERC-165 map slot for IBandAdapter.

function registerInterface() internal;

stdReference

function stdReference() internal view returns (address);

Returns

NameTypeDescription
<none>address

getFeed

function getFeed(bytes32 key) internal view returns (string memory base, string memory quote, uint48 maxStaleness);

Parameters

NameTypeDescription
keybytes32

Returns

NameTypeDescription
basestring
quotestring
maxStalenessuint48

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

NameTypeDescription
keybytes32

Returns

NameTypeDescription
rateuint256
lastUpdatedBaseuint256
lastUpdatedQuoteuint256

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

NameTypeDescription
keybytes32

Returns

NameTypeDescription
answerWadint256

setReference

function setReference(address reference_) internal;

Parameters

NameTypeDescription
reference_address

registerFeed

function registerFeed(bytes32 key, string calldata base, string calldata quote, uint48 maxStaleness) internal;

Parameters

NameTypeDescription
keybytes32
basestring
quotestring
maxStalenessuint48

unregisterFeed

function unregisterFeed(bytes32 key) internal;

Parameters

NameTypeDescription
keybytes32

_requireReference

function _requireReference() private view returns (address r);

Returns

NameTypeDescription
raddress