Crates.io | pyth-min |
lib.rs | pyth-min |
version | 0.1.2 |
source | src |
created_at | 2024-06-11 20:27:59.11472 |
updated_at | 2024-11-15 19:04:26.827424 |
description | Minimal sdk for interacting with Pyth pull oracles on Solana |
homepage | |
repository | https://github.com/mithraiclabs/pyth-min |
max_upload_size | |
id | 1268885 |
size | 32,500 |
An absolutely bare-minimum sdk, using zero dependencies, for consuming PythV2 prices generated by the Pyth Solana Receiver.
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!