WIP: state.rs: Support Pythnet flavor prices (incl. 64 pubs)#112
Open
drozdziak1 wants to merge 2 commits intomainfrom
Open
WIP: state.rs: Support Pythnet flavor prices (incl. 64 pubs)#112drozdziak1 wants to merge 2 commits intomainfrom
drozdziak1 wants to merge 2 commits intomainfrom
Conversation
guibescos
reviewed
Dec 13, 2023
| pub comp: [PriceComp; 32], | ||
| /// Rationale (2023-12-12): Rust is currently unable to derive Default for [PriceComp; 64] | ||
| pub comp2: [PriceComp; 32], | ||
| /// Cumulative sums of aggregative price and confidence used to compute arithmetic moving |
Contributor
There was a problem hiding this comment.
I think this is wrong, there is room for 128 publishers afaik
guibescos
reviewed
Dec 14, 2023
| } | ||
|
|
||
| /// Get a `Price` account from the raw byte value of a Solana account. | ||
| pub fn load_price_account(data: &[u8]) -> Result<&PriceAccount, PythError> { |
Contributor
There was a problem hiding this comment.
Is it ok that this functions loads the account is PriceAccountSolana ? I think it's used in pyth-agent
guibescos
requested changes
Dec 14, 2023
Contributor
There was a problem hiding this comment.
Thanks! I like the macro.
I think it's weird that you implemented things like get_price_no_older_than for PriceAccountPythnet, but there's no function to load PriceAccountPythnet. pyth-agent will probably need to load PriceAccountPythnet.
Also I think there's a bug related to PriceAccountPythnet having space for 64 publishers but the real account has space for 128 publishers.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Pyth-agent relies on the
pyth-sdk-solanapackage from this repo to parse Pyth price accounts. With the recent introduction of 64-publisher v2 price account on-chain, the parsing code needs to understand the bigger publisher cap in order to do permissioned symbol filtering.Summary of changes
**/Cargo.toml- bump version to0.10.0in pyth-sdk-solana and references to it in otherCargo.toml'spyth-sdk-solana/src/state.rs- Add aPriceAccountPythnetstruct near-identical toPriceAccount. The new struct contains expanded v2 price account schema with more price components andPriceCumulative; RenamePriceAccounttoPriceAccountSolana, create a typedef:PriceAccount = PriceAccountSolana. The typedef makes this change opaque to existing code using the library without breaking anything. In case of pyth-agent, after bumping to this version, it will attempt to parse raw bytes asPriceAccountPythnetandPriceAccountSolana, in that order. This allows us to avoid stuff like marking "this primary network is pythnet-like and contains v2 prices" in agent config.Review Highlights
state.rs- I had a rare occasion to use a macro forPriceAccountSolanaandPriceAccountPythnetimpl blocks. Please help me confirm that it was the right decision. Without a macro, the code would be identical with different struct name. This feels justified as none of the existing methods touch the components array or price cumulative data that make the only difference in the v2 price struct. Some alternatives include:Remaining items