-
Notifications
You must be signed in to change notification settings - Fork 220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parse Benchmark Prices - Aptos Contract Implementation #1727
base: main
Are you sure you want to change the base?
Conversation
@hhdgknsn is attempting to deploy a commit to the pyth-web Team on Vercel. A member of the Team first needs to authorize it. |
|
||
public fun parse_price_feed_updates( | ||
update_data: vector<vector<u8>>, | ||
price_ids: vector<vector<u8>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the new version of pythnet, the user can construct the message with only the price_ids they require. So there is no need to accept this argument and we can remove the checks of price_ids all together
while(i < vector::length(price_infos)) { | ||
let price_info = vector::borrow(price_infos, i); | ||
let price_feed = price_info::get_price_feed(price_info); | ||
let price: price::Price = price_feed::get_price(price_feed); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to define the type
fee: Coin<AptosCoin> | ||
): vector<price_feed::PriceFeed> { | ||
// validate and deposit the update fee | ||
let update_fee = get_update_fee(&update_data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will run all the verification again. You can assert the fees were enough at the end of the function using the length of the price_feeds. Same as what we have done on update_price_feeds
|
||
#[test(aptos_framework = @aptos_framework)] | ||
#[expected_failure(abort_code = 393224, location = pyth::pyth)] | ||
fun test_parse_price_feed_updates_invalid_publish_times(aptos_framework: &signer) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should have a separate test where publish times are valid but outside the price times
|
||
|
||
#[test(aptos_framework = @aptos_framework)] | ||
fun test_parse_price_feed_updates_success(aptos_framework: &signer) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add assertions for the transfer of fees
5ff334c
to
ba26645
Compare
Summary of Changes 1. Removed price_ids Parameter: The I have also ensured that all relevant test cases reflect these changes to verify the correctness and reliability of the new functionality. Happy to adjust anything further as required. Many thanks. |
max_publish_time: u64 | ||
): vector<price_feed::PriceFeed> { | ||
let parsed_price_feeds = vector::empty<price_feed::PriceFeed>(); | ||
let parsed_price_ids = vector::empty<vector<u8>>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this vector is useless
let max_publish_time: u64 = 1663680750; | ||
|
||
let test_price_feeds: vector<pyth::price_feed::PriceFeed> = pyth::parse_price_feed_updates(update_data, min_publish_time, max_publish_time, coins); | ||
assert!(vector::length(&test_price_feeds) == 0, 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the test reaches this line since the previous line will fail. We can probably remove it for clarity. the same goes for the next few testcases where we expect failure
A summary of the changes I've made:
|
Description:
This pull request introduces new functionality to the Pyth Aptos contract to parse and validate benchmark prices, similar to the parsePriceFeedUpdates method on the EVM chain. The new methods allow the contract to verify and consume benchmark price data from off-chain API endpoints, ensuring they meet specific publish time boundaries and include all requested price IDs.
Added Functions Overview:
parse_and_validate_price_feeds
:parse_price_feed_updates_single_vaa
:parse_price_feed_updates
:This new pull request replaces the initial one I have closed, reflecting significant changes in the functionality and logic of the benchmark price parsing methods. The updated implementation now includes enhanced logic for processing price updates, integrated fee validation and handling, and the addition of working tests to ensure reliability and correctness of the new features. These improvements address issues from the previous implementation and provide a more robust solution for the Pyth Aptos contract.
Additionally, the assertion statement -
assert!(is_coin_initialized<CoinType>(), error::invalid_argument(ECOIN_INFO_NOT_PUBLISHED));
(inside theis_account_registered
function in the coin.move file (aptos-move/framework/aptos-framework/sources)) was causing some of the original contract method tests to fail, including my own added tests. After commenting out this line temporarily, all tests are functioning correctly.Please review the latest commit and let me know if any further amendments are needed.
Thanks!