pub struct PriceUpdateV2 {
pub write_authority: Pubkey,
pub verification_level: VerificationLevel,
pub price_message: PriceFeedMessage,
pub posted_slot: u64,
}Expand description
A price update account. This account is used by the Pyth Receiver program to store a verified price update from a Pyth price feed. It contains:
write_authority: The write authority for this account. This authority can close this account to reclaim rent or update the account to contain a different price update.verification_level: TheVerificationLevelof this price update. This represents how many Wormhole guardian signatures have been verified for this price update.price_message: The actual price update.posted_slot: The slot at which this price update was posted.
Fields§
§verification_level: VerificationLevel§price_message: PriceFeedMessage§posted_slot: u64Implementations§
Source§impl PriceUpdateV2
impl PriceUpdateV2
Sourcepub fn get_price_unchecked(
&self,
feed_id: &FeedId,
) -> Result<Price, GetPriceError>
pub fn get_price_unchecked( &self, feed_id: &FeedId, ) -> Result<Price, GetPriceError>
Get a Price from a PriceUpdateV2 account for a given FeedId.
§Warning
This function does not check :
- How recent the price is
- Whether the price update has been verified
It is therefore unsafe to use this function without any extra checks, as it allows for the possibility of using unverified or outdated price updates.
Sourcepub fn get_price_no_older_than_with_custom_verification_level(
&self,
clock: &Clock,
maximum_age: u64,
feed_id: &FeedId,
verification_level: VerificationLevel,
) -> Result<Price, GetPriceError>
pub fn get_price_no_older_than_with_custom_verification_level( &self, clock: &Clock, maximum_age: u64, feed_id: &FeedId, verification_level: VerificationLevel, ) -> Result<Price, GetPriceError>
Get a Price from a PriceUpdateV2 account for a given FeedId no older than maximum_age with customizable verification level.
§Warning
Lowering the verification level from Full to Partial increases the risk of using a malicious price update.
Please read the documentation for VerificationLevel for more information.
§Example
use pyth_solana_receiver_sdk::price_update::{get_feed_id_from_hex, VerificationLevel, PriceUpdateV2};
use anchor_lang::prelude::*;
const MAXIMUM_AGE : u64 = 30;
const FEED_ID: &str = "0xef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d"; // SOL/USD
#[derive(Accounts)]
#[instruction(amount_in_usd : u64)]
pub struct ReadPriceAccount<'info> {
pub price_update: Account<'info, PriceUpdateV2>,
}
pub fn read_price_account(ctx : Context<ReadPriceAccount>) -> Result<()> {
let price_update = &mut ctx.accounts.price_update;
let price = price_update.get_price_no_older_than_with_custom_verification_level(&Clock::get()?, MAXIMUM_AGE, &get_feed_id_from_hex(FEED_ID)?, VerificationLevel::Partial{num_signatures: 5})?;
Ok(())
}Sourcepub fn get_price_no_older_than(
&self,
clock: &Clock,
maximum_age: u64,
feed_id: &FeedId,
) -> Result<Price, GetPriceError>
pub fn get_price_no_older_than( &self, clock: &Clock, maximum_age: u64, feed_id: &FeedId, ) -> Result<Price, GetPriceError>
Get a Price from a PriceUpdateV2 account for a given FeedId no older than maximum_age with Full verification.
§Example
use pyth_solana_receiver_sdk::price_update::{get_feed_id_from_hex, PriceUpdateV2};
use anchor_lang::prelude::*;
const MAXIMUM_AGE : u64 = 30;
const FEED_ID: &str = "0xef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d"; // SOL/USD
#[derive(Accounts)]
#[instruction(amount_in_usd : u64)]
pub struct ReadPriceAccount<'info> {
pub price_update: Account<'info, PriceUpdateV2>,
}
pub fn read_price_account(ctx : Context<ReadPriceAccount>) -> Result<()> {
let price_update = &mut ctx.accounts.price_update;
let price = price_update.get_price_no_older_than(&Clock::get()?, MAXIMUM_AGE, &get_feed_id_from_hex(FEED_ID)?)?;
Ok(())
}Trait Implementations§
Source§impl AccountDeserialize for PriceUpdateV2
impl AccountDeserialize for PriceUpdateV2
Source§fn try_deserialize(buf: &mut &[u8]) -> Result<Self>
fn try_deserialize(buf: &mut &[u8]) -> Result<Self>
Mint account into a token
Account.Source§fn try_deserialize_unchecked(buf: &mut &[u8]) -> Result<Self>
fn try_deserialize_unchecked(buf: &mut &[u8]) -> Result<Self>
Source§impl AccountSerialize for PriceUpdateV2
impl AccountSerialize for PriceUpdateV2
Source§impl BorshDeserialize for PriceUpdateV2
impl BorshDeserialize for PriceUpdateV2
Source§impl BorshSerialize for PriceUpdateV2
impl BorshSerialize for PriceUpdateV2
Source§impl BorshSchema for PriceUpdateV2
impl BorshSchema for PriceUpdateV2
Source§fn declaration() -> Declaration
fn declaration() -> Declaration
Source§fn add_definitions_recursively(
definitions: &mut HashMap<Declaration, Definition>,
)
fn add_definitions_recursively( definitions: &mut HashMap<Declaration, Definition>, )
Source§fn add_definition(
declaration: String,
definition: Definition,
definitions: &mut HashMap<String, Definition>,
)
fn add_definition( declaration: String, definition: Definition, definitions: &mut HashMap<String, Definition>, )
fn schema_container() -> BorshSchemaContainer
Source§impl Clone for PriceUpdateV2
impl Clone for PriceUpdateV2
Source§fn clone(&self) -> PriceUpdateV2
fn clone(&self) -> PriceUpdateV2
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Discriminator for PriceUpdateV2
impl Discriminator for PriceUpdateV2
fn discriminator() -> [u8; 8]
Auto Trait Implementations§
impl Freeze for PriceUpdateV2
impl RefUnwindSafe for PriceUpdateV2
impl Send for PriceUpdateV2
impl Sync for PriceUpdateV2
impl Unpin for PriceUpdateV2
impl UnwindSafe for PriceUpdateV2
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more