Skip to content
Lattice

IBandAdapter

Git Source

Title: IBandAdapter

Authors: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80), Modified from Band Protocol (https://github.com/bandprotocol)

Interface for the BandAdapter Diamond facet — reads Band Protocol reference data through the single global StdReference contract with per-feed staleness configuration and WAD-normalized answers.

Band uses ONE global StdReference contract per chain; feeds are keyed by an arbitrary bytes32 mapped to a (base, quote) symbol pair. rate is already 18-decimals (WAD), so normalization only widens uint256 -> int256 (no rescaling); reads validate registration, sign, future timestamp, and staleness on-chain. 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

stdReference

Returns the StdReference contract address.

function stdReference() external view returns (address);

Returns

NameTypeDescription
<none>address

getFeed

Returns a feed's configuration.

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

Parameters

NameTypeDescription
keybytes32The feed identifier.

Returns

NameTypeDescription
basestringThe base symbol (e.g. "ETH").
quotestringThe quote symbol (e.g. "USD").
maxStalenessuint48Maximum age (seconds) before a value is stale.

latestAnswer

Returns the latest rate for key, normalized to 18 decimals (WAD). Selector matches IPriceOracleReader.latestAnswer. Reverts on stale / future / zero rate.

function latestAnswer(bytes32 key) external view returns (int256 answerWad);

Parameters

NameTypeDescription
keybytes32The feed identifier.

Returns

NameTypeDescription
answerWadint256The latest rate scaled to 1e18.

getReferenceData

Returns the validated raw Band reference data for key, in Band's native types.

Provider-native reader (mirrors IStdReference.getReferenceData); keeps this adapter's ERC-165 id distinct from other read adapters that share the latestAnswer selector.

function getReferenceData(bytes32 key)
        external
        view
        returns (uint256 rate, uint256 lastUpdatedBase, uint256 lastUpdatedQuote);

Parameters

NameTypeDescription
keybytes32The feed identifier.

Returns

NameTypeDescription
rateuint256The base/quote exchange rate (already 18 decimals).
lastUpdatedBaseuint256The unix timestamp the base symbol was last updated.
lastUpdatedQuoteuint256The unix timestamp the quote symbol was last updated.

setReference

Sets the StdReference contract. Caller must hold DEFAULT_ADMIN_ROLE.

function setReference(address reference_) external;

Parameters

NameTypeDescription
reference_addressThe StdReference contract (non-zero).

registerFeed

Registers a Band feed under key. Caller must hold DEFAULT_ADMIN_ROLE.

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

Parameters

NameTypeDescription
keybytes32The arbitrary feed identifier.
basestringThe base symbol (non-empty, e.g. "ETH").
quotestringThe quote symbol (non-empty, e.g. "USD").
maxStalenessuint48Maximum age (seconds); must be non-zero.

unregisterFeed

Removes a registered feed. Caller must hold DEFAULT_ADMIN_ROLE.

function unregisterFeed(bytes32 key) external;

Parameters

NameTypeDescription
keybytes32The feed identifier to remove.

Events

FeedRegistered

Emitted when a feed is registered or updated.

event FeedRegistered(bytes32 indexed key, string base, string quote, uint48 maxStaleness);

Parameters

NameTypeDescription
keybytes32The arbitrary feed identifier.
basestringThe base symbol (e.g. "ETH").
quotestringThe quote symbol (e.g. "USD").
maxStalenessuint48Maximum age (seconds) before a value is stale.

FeedUnregistered

Emitted when a feed is removed.

event FeedUnregistered(bytes32 indexed key);

Parameters

NameTypeDescription
keybytes32The removed feed identifier.

ReferenceSet

Emitted when the StdReference contract address is set.

event ReferenceSet(address indexed stdReference);

Parameters

NameTypeDescription
stdReferenceaddressThe StdReference contract.

Errors

BandFeedNotRegistered

The requested feed key has not been registered.

error BandFeedNotRegistered(bytes32 key);

Parameters

NameTypeDescription
keybytes32

BandStaleData

The rate is older than the feed's maxStaleness (or has a future timestamp).

error BandStaleData(bytes32 key, uint256 lastUpdated, uint256 maxStaleness);

Parameters

NameTypeDescription
keybytes32
lastUpdateduint256
maxStalenessuint256

BandInvalidAnswer

The reference returned a zero rate.

error BandInvalidAnswer(bytes32 key, uint256 rate);

Parameters

NameTypeDescription
keybytes32
rateuint256

BandInvalidConfig

registerFeed was called with an empty base/quote symbol or zero maxStaleness.

error BandInvalidConfig();

BandReferenceNotSet

The StdReference contract address has not been set.

error BandReferenceNotSet();

BandReferenceIsZero

Setting the StdReference contract to the zero address.

error BandReferenceIsZero();