1pub use self::error::PythError;
6
7mod error;
8pub mod state;
9
10use solana_program::account_info::{
11 Account,
12 AccountInfo,
13 IntoAccountInfo,
14};
15use solana_program::pubkey::Pubkey;
16
17use state::{
18 load_price_account,
19 GenericPriceAccount,
20 SolanaPriceAccount,
21};
22
23pub use pyth_sdk::{
24 Price,
25 PriceFeed,
26 PriceIdentifier,
27 ProductIdentifier,
28};
29
30pub const VALID_SLOT_PERIOD: u64 = 25;
32
33#[deprecated(note = "solana-specific, use SolanaPriceAccount::account_info_to_feed instead.")]
35pub fn load_price_feed_from_account_info(
36 price_account_info: &AccountInfo,
37) -> Result<PriceFeed, PythError> {
38 SolanaPriceAccount::account_info_to_feed(price_account_info)
39}
40
41#[deprecated(note = "solana-specific, use SolanaPriceAccount::account_to_feed instead.")]
45pub fn load_price_feed_from_account(
46 price_key: &Pubkey,
47 price_account: &mut impl Account,
48) -> Result<PriceFeed, PythError> {
49 SolanaPriceAccount::account_to_feed(price_key, price_account)
50}
51
52impl<const N: usize, T: 'static> GenericPriceAccount<N, T>
53where
54 T: Default,
55 T: Copy,
56{
57 pub fn account_info_to_feed(price_account_info: &AccountInfo) -> Result<PriceFeed, PythError> {
58 load_price_account::<N, T>(
59 *price_account_info
60 .try_borrow_data()
61 .map_err(|_| PythError::InvalidAccountData)?,
62 )
63 .map(|acc| acc.to_price_feed(price_account_info.key))
64 }
65
66 pub fn account_to_feed(
67 price_key: &Pubkey,
68 price_account: &mut impl Account,
69 ) -> Result<PriceFeed, PythError> {
70 let price_account_info = (price_key, price_account).into_account_info();
71 Self::account_info_to_feed(&price_account_info)
72 }
73}