OracleMiddlewareWithRedstone

Git Source

Inherits: IOracleMiddlewareWithRedstone, OracleMiddlewareWithPyth, RedstoneOracle

This contract is used to get the price of an asset from different oracles. It is used by the USDN protocol to get the price of the USDN underlying asset.

This contract allows users to use the Redstone oracle and exists in case the Pyth infrastructure fails and we need a temporary solution. Redstone and Pyth are used concurrently, which could introduce arbitrage opportunities.

State Variables

_penaltyBps

The penalty for using a non-Pyth price with low latency oracle (in basis points).

uint16 internal _penaltyBps = 25;

Functions

constructor

constructor(
    address pythContract,
    bytes32 pythFeedId,
    bytes32 redstoneFeedId,
    address chainlinkPriceFeed,
    uint256 chainlinkTimeElapsedLimit
)
    OracleMiddlewareWithPyth(pythContract, pythFeedId, chainlinkPriceFeed, chainlinkTimeElapsedLimit)
    RedstoneOracle(redstoneFeedId);

Parameters

NameTypeDescription
pythContractaddressAddress of the Pyth contract.
pythFeedIdbytes32The Pyth price feed ID for the asset.
redstoneFeedIdbytes32The Redstone price feed ID for the asset.
chainlinkPriceFeedaddressAddress of the Chainlink price feed.
chainlinkTimeElapsedLimituint256The duration after which a Chainlink price is considered stale.

getPenaltyBps

Gets the penalty for using a non-Pyth price with low latency oracle (in basis points)

function getPenaltyBps() external view returns (uint16 penaltyBps_);

Returns

NameTypeDescription
penaltyBps_uint16The penalty (in basis points).

_getLowLatencyPrice

Gets the price from the low-latency oracle (Pyth or Redstone).

function _getLowLatencyPrice(bytes calldata data, uint128 actionTimestamp, PriceAdjustment dir, uint128 targetLimit)
    internal
    override
    returns (PriceInfo memory price_);

Parameters

NameTypeDescription
databytes
actionTimestampuint128The timestamp of the action corresponding to the price. If zero, then we must accept all prices younger than _pythRecentPriceDelay or _redstoneRecentPriceDelay.
dirPriceAdjustment
targetLimituint128

_adjustRedstonePrice

Applies the confidence interval in the dir direction, applying the penalty _penaltyBps

function _adjustRedstonePrice(RedstonePriceInfo memory redstonePrice, PriceAdjustment dir)
    internal
    view
    returns (PriceInfo memory price_);

Parameters

NameTypeDescription
redstonePriceRedstonePriceInfoThe formatted Redstone price object.
dirPriceAdjustmentThe direction to apply the penalty.

Returns

NameTypeDescription
price_PriceInfoThe adjusted price according to the penalty.

setRedstoneRecentPriceDelay

Sets the Redstone recent price delay.

function setRedstoneRecentPriceDelay(uint48 newDelay) external onlyRole(ADMIN_ROLE);

Parameters

NameTypeDescription
newDelayuint48The maximum age of a price to be considered recent.

setPenaltyBps

Sets the penalty (in basis points).

function setPenaltyBps(uint16 newPenaltyBps) external onlyRole(ADMIN_ROLE);

Parameters

NameTypeDescription
newPenaltyBpsuint16The new penalty.