OracleMiddlewareWithRedstone
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
Name | Type | Description |
---|---|---|
pythContract | address | Address of the Pyth contract. |
pythFeedId | bytes32 | The Pyth price feed ID for the asset. |
redstoneFeedId | bytes32 | The Redstone price feed ID for the asset. |
chainlinkPriceFeed | address | Address of the Chainlink price feed. |
chainlinkTimeElapsedLimit | uint256 | The 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
Name | Type | Description |
---|---|---|
penaltyBps_ | uint16 | The 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
Name | Type | Description |
---|---|---|
data | bytes | |
actionTimestamp | uint128 | The timestamp of the action corresponding to the price. If zero, then we must accept all prices younger than _pythRecentPriceDelay or _redstoneRecentPriceDelay. |
dir | PriceAdjustment | |
targetLimit | uint128 |
_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
Name | Type | Description |
---|---|---|
redstonePrice | RedstonePriceInfo | The formatted Redstone price object. |
dir | PriceAdjustment | The direction to apply the penalty. |
Returns
Name | Type | Description |
---|---|---|
price_ | PriceInfo | The adjusted price according to the penalty. |
setRedstoneRecentPriceDelay
Sets the Redstone recent price delay.
function setRedstoneRecentPriceDelay(uint48 newDelay) external onlyRole(ADMIN_ROLE);
Parameters
Name | Type | Description |
---|---|---|
newDelay | uint48 | The 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
Name | Type | Description |
---|---|---|
newPenaltyBps | uint16 | The new penalty. |