Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit b862c0e

Browse files
authored
Updating toke-lending to use pyth v2 (#1959)
1 parent 6c9ca0d commit b862c0e

8 files changed

+33
-26
lines changed

token-lending/cli/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ struct Config {
4343
type Error = Box<dyn std::error::Error>;
4444
type CommandResult = Result<(), Error>;
4545

46-
const PYTH_PROGRAM_ID: &str = "5mkqGkkWSaSk2NL9p4XptwEQu4d5jFTJiurbbzdqYexF";
46+
const PYTH_PROGRAM_ID: &str = "gSbePebfvPy7tRqimPoVecS2UsBvYv46ynrzWocc92s";
4747

4848
fn main() {
4949
solana_logger::setup_with_default("solana=info");

token-lending/program/src/processor.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ fn process_init_reserve(
274274
msg!("Pyth product account provided is not a valid Pyth account");
275275
return Err(LendingError::InvalidOracleConfig.into());
276276
}
277-
if pyth_product.ver != pyth::VERSION_1 {
277+
if pyth_product.ver != pyth::VERSION_2 {
278278
msg!("Pyth product account provided has a different version than expected");
279279
return Err(LendingError::InvalidOracleConfig.into());
280280
}
@@ -497,7 +497,9 @@ fn process_deposit_reserve_liquidity(
497497
Pubkey::create_program_address(authority_signer_seeds, program_id)?;
498498
if &lending_market_authority_pubkey != lending_market_authority_info.key {
499499
msg!(
500-
"Derived lending market authority does not match the lending market authority provided"
500+
"Derived lending market authority {} does not match the lending market authority provided {}",
501+
&lending_market_authority_pubkey.to_string(),
502+
&lending_market_authority_info.key.to_string(),
501503
);
502504
return Err(LendingError::InvalidMarketAuthority.into());
503505
}

token-lending/program/src/pyth.rs

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use bytemuck::{
77
use std::mem::size_of;
88

99
pub const MAGIC: u32 = 0xa1b2c3d4;
10-
pub const VERSION_1: u32 = 1;
11-
pub const VERSION: u32 = VERSION_1;
10+
pub const VERSION_2: u32 = 2;
11+
pub const VERSION: u32 = VERSION_2;
1212
pub const MAP_TABLE_SIZE: usize = 640;
1313
pub const PROD_ACCT_SIZE: usize = 512;
1414
pub const PROD_HDR_SIZE: usize = 48;
@@ -67,29 +67,34 @@ pub struct PriceComp {
6767
pub enum PriceType {
6868
Unknown,
6969
Price,
70-
#[allow(clippy::upper_case_acronyms)]
71-
TWAP,
72-
Volatility,
7370
}
7471

7572
#[derive(Copy, Clone)]
7673
#[repr(C)]
7774
pub struct Price {
78-
pub magic: u32, // Pyth magic number.
79-
pub ver: u32, // Program version.
80-
pub atype: u32, // Account type.
81-
pub size: u32, // Price account size.
82-
pub ptype: PriceType, // Price or calculation type.
83-
pub expo: i32, // Price exponent.
84-
pub num: u32, // Number of component prices.
75+
pub magic: u32, // pyth magic number
76+
pub ver: u32, // program version
77+
pub atype: u32, // account type
78+
pub size: u32, // price account size
79+
pub ptype: PriceType, // price or calculation type
80+
pub expo: i32, // price exponent
81+
pub num: u32, // number of component prices
8582
pub unused: u32,
86-
pub curr_slot: u64, // Currently accumulating price slot.
87-
pub valid_slot: u64, // Valid slot-time of agg price.
88-
pub prod: AccKey,
89-
pub next: AccKey,
90-
pub agg_pub: AccKey,
91-
pub agg: PriceInfo,
92-
pub comp: [PriceComp; 16],
83+
pub curr_slot: u64, // currently accumulating price slot
84+
pub valid_slot: u64, // valid slot-time of agg. price
85+
pub twap: i64, // time-weighted average price
86+
pub avol: u64, // annualized price volatility
87+
pub drv0: i64, // space for future derived values
88+
pub drv1: i64, // space for future derived values
89+
pub drv2: i64, // space for future derived values
90+
pub drv3: i64, // space for future derived values
91+
pub drv4: i64, // space for future derived values
92+
pub drv5: i64, // space for future derived values
93+
pub prod: AccKey, // product account key
94+
pub next: AccKey, // next Price account in linked list
95+
pub agg_pub: AccKey, // quoter who computed last aggregate price
96+
pub agg: PriceInfo, // aggregate price info
97+
pub comp: [PriceComp; 32], // price components one per quoter
9398
}
9499

95100
#[cfg(target_endian = "little")]

token-lending/program/tests/helpers/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ pub const TEST_RESERVE_CONFIG: ReserveConfig = ReserveConfig {
5555
},
5656
};
5757

58-
pub const SOL_PYTH_PRODUCT: &str = "8yrQMUyJRnCJ72NWwMiPV9dNGw465Z8bKUvnUC8P5L6F";
59-
pub const SOL_PYTH_PRICE: &str = "BdgHsXrH1mXqhdosXavYxZgX6bGqTdj5mh2sxDhF8bJy";
58+
pub const SOL_PYTH_PRODUCT: &str = "3Mnn2fX6rQyUsyELYms1sBJyChWofzSNRoqYzvgMVz5E";
59+
pub const SOL_PYTH_PRICE: &str = "J83w4HKfqxwcq3BEMMkPFSppX3gqekLyLJBexebFVkix";
6060

61-
pub const SRM_PYTH_PRODUCT: &str = "5agdsn3jogTt8F537GW3g8BuLaBGrg9Q2gPKUNqBV6Dh";
62-
pub const SRM_PYTH_PRICE: &str = "2Mt2wcRXpCAbTRp2VjFqGa8SbJVzjJvyK4Tx7aqbRtBJ";
61+
pub const SRM_PYTH_PRODUCT: &str = "6MEwdxe4g1NeAF9u6KDG14anJpFsVEa2cvr5H6iriFZ8";
62+
pub const SRM_PYTH_PRICE: &str = "992moaMQKs32GKZ9dxi8keyM2bUmbrwBZpK4p2K6X5Vs";
6363

6464
pub const USDC_MINT: &str = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
6565

0 commit comments

Comments
 (0)