Fix oracle price decimal usage
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
This commit is contained in:
parent
242d39295a
commit
47bccfeec8
|
@ -9,7 +9,7 @@ use crate::checked_math as cm;
|
|||
use crate::error::MangoError;
|
||||
use crate::util::LoadZeroCopy;
|
||||
|
||||
pub const QUOTE_DECIMALS: u32 = 6;
|
||||
pub const QUOTE_DECIMALS: i32 = 6;
|
||||
|
||||
#[derive(PartialEq)]
|
||||
pub enum OracleType {
|
||||
|
@ -47,13 +47,17 @@ pub fn oracle_price(acc_info: &AccountInfo, base_token_decimals: u8) -> Result<I
|
|||
OracleType::Pyth => {
|
||||
let price_struct = pyth_sdk_solana::load_price(data).unwrap();
|
||||
let price = I80F48::from_num(price_struct.price);
|
||||
let decimals = (price_struct.expo as u32)
|
||||
let decimals = (price_struct.expo as i32)
|
||||
.checked_add(QUOTE_DECIMALS)
|
||||
.unwrap()
|
||||
.checked_sub(base_token_decimals as u32)
|
||||
.checked_sub(base_token_decimals as i32)
|
||||
.unwrap();
|
||||
let decimal_adj = I80F48::from_num(10_u32.pow(decimals));
|
||||
cm!(price * decimal_adj)
|
||||
let decimal_adj = I80F48::from_num(10_u32.pow(decimals.abs() as u32));
|
||||
if decimals < 0 {
|
||||
cm!(price / decimal_adj)
|
||||
} else {
|
||||
cm!(price * decimal_adj)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue