Skip to content
Lattice

IRedStoneAdapter

Git Source

Title: IRedStoneAdapter

Authors: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80), Modified from RedStone (https://github.com/redstone-finance/redstone-oracles-monorepo)

Interface for the RedStoneAdapter Diamond facet — reads RedStone Push price feeds from their on-chain PriceFeedsAdapter with per-feed staleness configuration and WAD-normalized answers.

This adapter targets the RedStone Push model: signed values are relayed on-chain and read via IRedstonePriceFeedsAdapter.getValueForDataFeed (8 decimals) with the batch update time from getTimestampsFromLatestUpdate. (The RedStone Core/pull model, which extracts signed data from calldata via the RedStone SDK, is a separate follow-up.) Feeds are keyed by an arbitrary bytes32 mapped to a (PriceFeedsAdapter, dataFeedId) pair. 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 adapter, bytes32 dataFeedId, uint48 maxStaleness);

Parameters

NameTypeDescription
keybytes32The feed identifier.

Returns

NameTypeDescription
adapteraddressThe RedStone PriceFeedsAdapter contract.
dataFeedIdbytes32The RedStone data-feed id.
maxStalenessuint48Maximum 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 / zero / overflowing value.

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

Parameters

NameTypeDescription
keybytes32The feed identifier.

Returns

NameTypeDescription
answerWadint256The latest price scaled to 1e18.

getValueForDataFeed

Returns the validated raw RedStone value (8 decimals) and the batch update timestamp.

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

function getValueForDataFeed(bytes32 key) external view returns (uint256 value, uint256 timestamp);

Parameters

NameTypeDescription
keybytes32The feed identifier.

Returns

NameTypeDescription
valueuint256The RedStone value (8 decimals).
timestampuint256The on-chain batch update timestamp (seconds).

registerFeed

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

function registerFeed(bytes32 key, address adapter, bytes32 dataFeedId, uint48 maxStaleness) external;

Parameters

NameTypeDescription
keybytes32The arbitrary feed identifier.
adapteraddressThe RedStone PriceFeedsAdapter contract (non-zero).
dataFeedIdbytes32The RedStone data-feed id.
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, address indexed adapter, bytes32 indexed dataFeedId, uint48 maxStaleness);

Parameters

NameTypeDescription
keybytes32The arbitrary feed identifier.
adapteraddressThe RedStone PriceFeedsAdapter contract.
dataFeedIdbytes32The RedStone data-feed id.
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.

Errors

RedStoneFeedNotRegistered

The requested feed key has not been registered.

error RedStoneFeedNotRegistered(bytes32 key);

Parameters

NameTypeDescription
keybytes32

RedStoneStaleData

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

error RedStoneStaleData(bytes32 key, uint256 timestamp, uint256 maxStaleness);

Parameters

NameTypeDescription
keybytes32
timestampuint256
maxStalenessuint256

RedStoneInvalidAnswer

The adapter returned a zero value, or one too large to normalize without overflow.

error RedStoneInvalidAnswer(bytes32 key, uint256 value);

Parameters

NameTypeDescription
keybytes32
valueuint256

RedStoneInvalidConfig

registerFeed was called with a zero adapter address or zero maxStaleness.

error RedStoneInvalidConfig();