-
Notifications
You must be signed in to change notification settings - Fork 222
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
feat(pyth-solana-receiver): add post_twap_update
instruction & types
#2172
feat(pyth-solana-receiver): add post_twap_update
instruction & types
#2172
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
2 Skipped Deployments
|
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.
very nice!
let (price, conf, down_slots_ratio) = calculate_twap(&start_msg, &end_msg)?; | ||
|
||
twap_update_account.write_authority = write_authority.key(); | ||
twap_update_account.verification_level = start_vaa_components.verification_level; |
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.
here maybe you would want to make it the minimum of start_vaa_components.verification_level
and end_vaa_components.verification_level
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.
ah yep good point, will update
twap_update_account.write_authority = write_authority.key(); | ||
twap_update_account.verification_level = start_vaa_components.verification_level; | ||
|
||
twap_update_account.twap.feed_id = start_msg.feed_id; |
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 think you forgot to check that start and end are for the same id?
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.
yea true, will update
Purpose
Allows users to post verified TWAP prices on chain using the Pyth Solana Receiver Contract.
Implementation details
The
post_twap_update
instruction takes in start & end VAA accounts and start & endMerklePriceUpdate
calldata.twap = (cumul_price_t1 - cumul_price_t0)/(pub_slot_t1 - pub_slot_t0)
.The calculated TWAP is stored in a
TwapUpdate
account as follows:TwapUpdate
andTwapPrice
types live in thesolana_receiver_sdk
Rust SDK to facilitate easy deserialization for users consuming the update account, similar to thePriceUpdateV2
type.Misc
lib.rs
to extract out common functionality acrosspost_update
andpost_twap_update
, such as collecting the update fee and verifying VAAs.Testing
post_twap_update
. Verification/malformed inputs are already being tested in the other tests.lib.rs
sincecalculate_twap
is private and can't be accessed by thetests
crates. This also tests for invalid inputs, e.g. start slot > end slot.Up next