OracleMiddlewareWithDataStreams
Inherits: CommonOracleMiddleware, ChainlinkDataStreamsOracle, IOracleMiddlewareWithDataStreams
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.
Functions
constructor
constructor(
address pythContract,
bytes32 pythFeedId,
address chainlinkPriceFeed,
uint256 chainlinkTimeElapsedLimit,
address chainlinkProxyVerifierAddress,
bytes32 chainlinkStreamId
)
CommonOracleMiddleware(pythContract, pythFeedId, chainlinkPriceFeed, chainlinkTimeElapsedLimit)
ChainlinkDataStreamsOracle(chainlinkProxyVerifierAddress, chainlinkStreamId);
Parameters
Name | Type | Description |
---|---|---|
pythContract | address | Address of the Pyth contract. |
pythFeedId | bytes32 | The Pyth price feed ID for the asset. |
chainlinkPriceFeed | address | The address of the Chainlink price feed. |
chainlinkTimeElapsedLimit | uint256 | The duration after which a Chainlink price is considered stale. |
chainlinkProxyVerifierAddress | address | The address of the Chainlink proxy verifier contract. |
chainlinkStreamId | bytes32 | The supported Chainlink data stream ID. |
validationCost
Returns the cost of one price validation for the given action (in native token).
function validationCost(bytes calldata data, Types.ProtocolAction)
public
view
override(CommonOracleMiddleware, IBaseOracleMiddleware)
returns (uint256 result_);
Parameters
Name | Type | Description |
---|---|---|
data | bytes | Price data for which to get the fee. |
<none> | Types.ProtocolAction |
Returns
Name | Type | Description |
---|---|---|
result_ | uint256 | cost_ The cost of one price validation (in native token). |
setDataStreamsRecentPriceDelay
Sets the amount of time after which we do not consider a price as recent for Chainlink.
function setDataStreamsRecentPriceDelay(uint64 newDelay) external onlyRole(ADMIN_ROLE);
Parameters
Name | Type | Description |
---|---|---|
newDelay | uint64 | The maximum age of a price to be considered recent. |
_getLowLatencyPrice
Gets the price from the low-latency oracle.
function _getLowLatencyPrice(bytes calldata payload, uint128 actionTimestamp, PriceAdjustment dir, uint128 targetLimit)
internal
virtual
override
returns (PriceInfo memory price_);
Parameters
Name | Type | Description |
---|---|---|
payload | bytes | |
actionTimestamp | uint128 | The timestamp of the action corresponding to the price. If zero, then we must accept all prices younger than the recent price delay. |
dir | PriceAdjustment | The direction for the low latency price adjustment. |
targetLimit | uint128 | The most recent timestamp a price can have (can be zero if actionTimestamp is zero). |
Returns
Name | Type | Description |
---|---|---|
price_ | PriceInfo | The price from the low-latency oracle, adjusted according to the price adjustment direction. |
_getInitiateActionPrice
Gets the price for an initiate
action of the protocol.
If the data parameter is not empty, validate the price with the low latency oracle. Else, get the on-chain
price from ChainlinkOracle and compare its timestamp with the latest seen Pyth price (cached). If Pyth is more
recent, we return it. Otherwise, we return the Chainlink price. For the latter, we don't have a price adjustment,
so both neutralPrice
and price
are equal.
function _getInitiateActionPrice(bytes calldata data, PriceAdjustment dir)
internal
override
returns (PriceInfo memory price_);
Parameters
Name | Type | Description |
---|---|---|
data | bytes | The low latency data. |
dir | PriceAdjustment | The direction to adjust the price (when using a low latency price). |
Returns
Name | Type | Description |
---|---|---|
price_ | PriceInfo | The price to use for the user action. |
_getLiquidationPrice
Gets the price from the low-latency oracle.
function _getLiquidationPrice(bytes calldata data) internal virtual override returns (PriceInfo memory price_);
Parameters
Name | Type | Description |
---|---|---|
data | bytes | The signed price update data. |
Returns
Name | Type | Description |
---|---|---|
price_ | PriceInfo | The low-latency oracle price. |
_convertPythPrice
Converts a formatted Pyth price into a PriceInfo.
function _convertPythPrice(FormattedPythPrice memory pythPrice) internal pure returns (PriceInfo memory price_);
Parameters
Name | Type | Description |
---|---|---|
pythPrice | FormattedPythPrice | The formatted Pyth price containing the price and publish time. |
Returns
Name | Type | Description |
---|---|---|
price_ | PriceInfo | The PriceInfo with the price, neutral price, and timestamp set from the Pyth price data. |
_adjustDataStreamPrice
Applies the ask, bid or price according to the dir
direction.
function _adjustDataStreamPrice(FormattedDataStreamsPrice memory formattedPrice, PriceAdjustment dir)
internal
pure
returns (PriceInfo memory price_);
Parameters
Name | Type | Description |
---|---|---|
formattedPrice | FormattedDataStreamsPrice | The Chainlink data streams formatted price. |
dir | PriceAdjustment | The direction to adjust the price. |
Returns
Name | Type | Description |
---|---|---|
price_ | PriceInfo | The adjusted price according to the direction. |