Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow passing just pyth to save bytes #105

Merged
merged 4 commits into from
Sep 29, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions token-lending/program/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,12 @@ fn process_refresh_reserve(program_id: &Pubkey, accounts: &[AccountInfo]) -> Pro
let account_info_iter = &mut accounts.iter().peekable();
0xripleys marked this conversation as resolved.
Show resolved Hide resolved
let reserve_info = next_account_info(account_info_iter)?;
let pyth_price_info = next_account_info(account_info_iter)?;
let switchboard_feed_info = next_account_info(account_info_iter)?;
// set switchboard to a placeholder account info
let mut switchboard_feed_info = pyth_price_info;
// if the next account info exists and is not the clock set it to be switchboard
if account_info_iter.peek().map(|a| a.key) != Some(&clock::ID) {
0xripleys marked this conversation as resolved.
Show resolved Hide resolved
switchboard_feed_info = next_account_info(account_info_iter)?;
}
let clock = &Clock::get()?;
if account_info_iter.peek().map(|a| a.key) == Some(&clock::ID) {
next_account_info(account_info_iter)?;
Expand Down Expand Up @@ -2572,7 +2577,13 @@ fn get_price(
if pyth_price != Decimal::zero() {
return Ok(pyth_price);
}
get_switchboard_price(switchboard_feed_info, clock)

// if switchboard was not passed in don't try to grab the price
if switchboard_feed_info.key != pyth_price_account_info.key {
return get_switchboard_price(switchboard_feed_info, clock);
}

Err(LendingError::InvalidOracleConfig.into())
}

fn get_pyth_price(pyth_price_info: &AccountInfo, clock: &Clock) -> Result<Decimal, ProgramError> {
Expand Down