-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
JoscelynFarr
committed
Mar 29, 2024
1 parent
361c20e
commit 4da616e
Showing
5 changed files
with
87 additions
and
68 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
Copyright 2022 JOJO Exchange | ||
SPDX-License-Identifier: BUSL-1.1 | ||
*/ | ||
|
||
pragma solidity ^0.8.19; | ||
|
||
contract PythStructs { | ||
// A price with a degree of uncertainty, represented as a price +- a confidence interval. | ||
// | ||
// The confidence interval roughly corresponds to the standard error of a normal distribution. | ||
// Both the price and confidence are stored in a fixed-point numeric representation, | ||
// `x * (10^expo)`, where `expo` is the exponent. | ||
// | ||
// Please refer to the documentation at https://docs.pyth.network/documentation/pythnet-price-feeds/best-practices | ||
// for how | ||
// to how this price safely. | ||
struct Price { | ||
// Price | ||
int64 price; | ||
// Confidence interval around the price | ||
uint64 conf; | ||
// Price exponent | ||
int32 expo; | ||
// Unix timestamp describing when the price was published | ||
uint256 publishTime; | ||
} | ||
|
||
// PriceFeed represents a current aggregate price from pyth publisher feeds. | ||
struct PriceFeed { | ||
// The price ID. | ||
bytes32 id; | ||
// Latest available price | ||
Price price; | ||
// Latest available exponentially-weighted moving average price | ||
Price emaPrice; | ||
} | ||
} | ||
|
||
interface IPyth { | ||
/// @notice Returns the price and confidence interval. | ||
/// @dev Reverts if the price has not been updated within the last `getValidTimePeriod()` seconds. | ||
/// @param id The Pyth Price Feed ID of which to fetch the price and confidence interval. | ||
/// @return price - please read the documentation of PythStructs.Price to understand how to use this safely. | ||
function getPrice(bytes32 id) external view returns (PythStructs.Price memory price); | ||
|
||
/// @notice Update price feeds with given update messages. | ||
/// This method requires the caller to pay a fee in wei; the required fee can be computed by calling | ||
/// `getUpdateFee` with the length of the `updateData` array. | ||
/// Prices will be updated if they are more recent than the current stored prices. | ||
/// The call will succeed even if the update is not the most recent. | ||
/// @dev Reverts if the transferred fee is not sufficient or the updateData is invalid. | ||
/// @param updateData Array of price update data. | ||
function updatePriceFeeds(bytes[] calldata updateData) external payable; | ||
|
||
/// @notice Wrapper around updatePriceFeeds that rejects fast if a price update is not necessary. A price update is | ||
/// necessary if the current on-chain publishTime is older than the given publishTime. It relies solely on the | ||
/// given `publishTimes` for the price feeds and does not read the actual price update publish time within | ||
/// `updateData`. | ||
/// | ||
/// This method requires the caller to pay a fee in wei; the required fee can be computed by calling | ||
/// `getUpdateFee` with the length of the `updateData` array. | ||
/// | ||
/// `priceIds` and `publishTimes` are two arrays with the same size that correspond to senders known publishTime | ||
/// of each priceId when calling this method. If all of price feeds within `priceIds` have updated and have | ||
/// a newer or equal publish time than the given publish time, it will reject the transaction to save gas. | ||
/// Otherwise, it calls updatePriceFeeds method to update the prices. | ||
/// | ||
/// @dev Reverts if update is not needed or the transferred fee is not sufficient or the updateData is invalid. | ||
/// @param updateData Array of price update data. | ||
/// @param priceIds Array of price ids. | ||
/// @param publishTimes Array of publishTimes. `publishTimes[i]` corresponds to known `publishTime` of `priceIds[i]` | ||
function updatePriceFeedsIfNecessary( | ||
bytes[] calldata updateData, | ||
bytes32[] calldata priceIds, | ||
uint64[] calldata publishTimes | ||
) | ||
external | ||
payable; | ||
|
||
/// @notice Returns the required fee to update an array of price updates. | ||
/// @param updateData Array of price update data. | ||
/// @return feeAmount The required fee in Wei. | ||
function getUpdateFee(bytes[] calldata updateData) external view returns (uint256 feeAmount); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters