Skip to content

Commit

Permalink
pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
nope-finance committed Jun 30, 2021
1 parent f5b5873 commit 677c9c4
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions token-lending/program/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,6 @@ fn process_init_reserve(
return Err(LendingError::InvalidOracleConfig.into());
}

// let market_price = get_pyth_price(pyth_price_info, clock)?;
let market_price = get_price(switchboard_feed_info, pyth_price_info, clock)?;

let authority_signer_seeds = &[
Expand Down Expand Up @@ -431,7 +430,6 @@ fn process_refresh_reserve(program_id: &Pubkey, accounts: &[AccountInfo]) -> Pro
return Err(LendingError::InvalidOracleConfig.into());
}

// reserve.liquidity.market_price = get_pyth_price(pyth_price_info, clock)?;
reserve.liquidity.market_price = get_price(switchboard_feed_info, pyth_price_info, clock)?;

reserve.accrue_interest(clock.slot)?;
Expand Down Expand Up @@ -1852,12 +1850,10 @@ fn get_price(
clock: &Clock,
) -> Result<Decimal, ProgramError> {
let pyth_price = get_pyth_price(pyth_price_account_info, clock).unwrap_or_default();
if pyth_price != Decimal::from(0u64) {
if pyth_price != Decimal::zero() {
return Ok(pyth_price);
}
let switchboard_price = get_switchboard_price(switchboard_feed_info, clock)?;

Ok(switchboard_price)
get_switchboard_price(switchboard_feed_info, clock)
}

fn get_pyth_price(pyth_price_info: &AccountInfo, clock: &Clock) -> Result<Decimal, ProgramError> {
Expand Down Expand Up @@ -1942,13 +1938,12 @@ fn get_switchboard_price(
let price_float = round_result.result.unwrap_or(0.0);

// we just do this so we can parse coins with low usd value
// it might be better to just extract the mantissa and exponent from the float directly
let price_quotient = 10u64.pow(9);

let price = ((price_quotient as f64) * price_float).round() as u128;

let decimal_price = Decimal::from(price).try_div(price_quotient)?;

Ok(decimal_price)
Decimal::from(price).try_div(price_quotient)
}

/// Issue a spl_token `InitializeAccount` instruction.
Expand Down

0 comments on commit 677c9c4

Please sign in to comment.