pyth-min 0.1.2

Minimal sdk for interacting with Pyth pull oracles on Solana
Documentation
  • Coverage
  • 44.83%
    26 out of 58 items documented2 out of 16 items with examples
  • Size
  • Source code size: 32.17 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.83 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • mithraiclabs/pyth-min
    0 1 1
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • jgur-psyops

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!