WIP: state.rs: Support Pythnet flavor prices (incl. 64 pubs) #112
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-solana
package 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.0
in pyth-sdk-solana and references to it in otherCargo.toml
'spyth-sdk-solana/src/state.rs
- Add aPriceAccountPythnet
struct near-identical toPriceAccount
. The new struct contains expanded v2 price account schema with more price components andPriceCumulative
; RenamePriceAccount
toPriceAccountSolana
, 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 asPriceAccountPythnet
andPriceAccountSolana
, 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 forPriceAccountSolana
andPriceAccountPythnet
impl 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