pyth-min

Crates.iopyth-min
lib.rspyth-min
version0.1.2
sourcesrc
created_at2024-06-11 20:27:59.11472
updated_at2024-11-15 19:04:26.827424
descriptionMinimal sdk for interacting with Pyth pull oracles on Solana
homepage
repositoryhttps://github.com/mithraiclabs/pyth-min
max_upload_size
id1268885
size32,500
Jon Gurary (jgur-psyops)

documentation

README

An absolutely bare-minimum sdk, using zero dependencies, for consuming PythV2 prices generated by the Pyth Solana Receiver.

USAGE

Take a Pyth Price Feed Account as an UncheckedAccount. Here is example of this type of account on mainnet: https://solana.fm/address/7UVimffxr9ow1uXYxsr4LHAcV58mLzhmwaeKvJ1pjLiE

#[derive(Accounts)]
pub struct Some_Instruction<'info> {
    /// CHECK: You may also want to validate `owner = PYTH_PID`
    pub price_acc: UncheckedAccount<'info>,
}

Then simply borrow the data, minus the 8-byte Anchor discrminator:

let data = &ctx.accounts.price_acc.try_borrow_data()?[..][8..];
let price_v2 = PriceUpdateV2::get_price_update_v2_from_bytes(data);

let price = price_v2.get_price_no_older_than(
    &Clock::get()?.unix_timestamp,
    MAXIMUM_AGE, // in seconds
    None, // Pass the feed ID in bytes if you want to validate it
)?;

Or if you absolutely do not care about any verification whatsoever:

price_v2.get_price_unchecked(None)

We suggest you validate the discriminator (see DISCRIMINATOR_AS_HEX) unless you are absolutely sure this is the correct account!

Commit count: 13

cargo fmt