RedstoneOracle

Git Source

Inherits: IRedstoneOracle, PrimaryProdDataServiceConsumerBase, IOracleMiddlewareErrors

This contract is used to get the price of the asset that corresponds to the stored feed ID.

Is implemented by the OracleMiddlewareWithRedstone contract.

State Variables

REDSTONE_HEARTBEAT

Gets the interval between two Redstone price updates.

uint48 public constant REDSTONE_HEARTBEAT = 10 seconds;

REDSTONE_DECIMALS

Gets the number of decimals for prices contained in Redstone price updates.

uint8 public constant REDSTONE_DECIMALS = 8;

_redstoneFeedId

The ID of the Redstone price feed.

bytes32 internal immutable _redstoneFeedId;

_redstoneRecentPriceDelay

The maximum age of a price to be considered recent.

uint48 internal _redstoneRecentPriceDelay = 45 seconds;

Functions

constructor

constructor(bytes32 redstoneFeedId);

Parameters

NameTypeDescription
redstoneFeedIdbytes32The ID of the price feed.

getRedstoneFeedId

Gets the ID of the Redstone price feed.

function getRedstoneFeedId() external view returns (bytes32 feedId_);

Returns

NameTypeDescription
feedId_bytes32The feed ID.

getRedstoneRecentPriceDelay

Gets the maximum age of a price to be considered recent.

function getRedstoneRecentPriceDelay() external view returns (uint48 delay_);

Returns

NameTypeDescription
delay_uint48The age in seconds.

validateTimestamp

Used by the Redstone contract internally, we override it to allow all timestamps.

function validateTimestamp(uint256) public pure override(IRedstoneOracle, RedstoneConsumerBase);

Parameters

NameTypeDescription
<none>uint256

_getFormattedRedstonePrice

Gets the price of the asset from Redstone, formatted to the specified number of decimals.

Redstone automatically retrieves data from the end of the calldata, no need to pass the pointer.

function _getFormattedRedstonePrice(uint128 targetTimestamp, uint256 middlewareDecimals)
    internal
    view
    returns (RedstonePriceInfo memory formattedPrice_);

Parameters

NameTypeDescription
targetTimestampuint128The target timestamp to validate the price. If zero, then we accept a price as old as block.timestamp - _redstoneRecentPriceDelay.
middlewareDecimalsuint256The number of decimals to format the price to.

Returns

NameTypeDescription
formattedPrice_RedstonePriceInfoThe price from Redstone, normalized to middlewareDecimals.

_extractPriceUpdateTimestamp

Extract the timestamp from the price update.

extractedTimestamp_ is a timestamp in seconds.

function _extractPriceUpdateTimestamp() internal pure returns (uint48 extractedTimestamp_);

Returns

NameTypeDescription
extractedTimestamp_uint48The timestamp of the price update.