RedstoneOracle
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
Name | Type | Description |
---|---|---|
redstoneFeedId | bytes32 | The ID of the price feed. |
getRedstoneFeedId
Gets the ID of the Redstone price feed.
function getRedstoneFeedId() external view returns (bytes32 feedId_);
Returns
Name | Type | Description |
---|---|---|
feedId_ | bytes32 | The feed ID. |
getRedstoneRecentPriceDelay
Gets the maximum age of a price to be considered recent.
function getRedstoneRecentPriceDelay() external view returns (uint48 delay_);
Returns
Name | Type | Description |
---|---|---|
delay_ | uint48 | The 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
Name | Type | Description |
---|---|---|
<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
Name | Type | Description |
---|---|---|
targetTimestamp | uint128 | The target timestamp to validate the price. If zero, then we accept a price as old as block.timestamp - _redstoneRecentPriceDelay . |
middlewareDecimals | uint256 | The number of decimals to format the price to. |
Returns
Name | Type | Description |
---|---|---|
formattedPrice_ | RedstonePriceInfo | The 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
Name | Type | Description |
---|---|---|
extractedTimestamp_ | uint48 | The timestamp of the price update. |