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

Pull oracle support for pyth, switchboard #187

Merged
merged 31 commits into from
Jul 10, 2024
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
c27c1d8
upgrade
0xripleys Jun 7, 2024
6a30199
add receiver sdk dependency
0xripleys Jun 7, 2024
a6703de
impementing pyth pull oracle
nope-finance Jun 14, 2024
119cfed
rustfmt
nope-finance Jun 14, 2024
c678941
clippy
nope-finance Jun 14, 2024
17cde76
added some account state
nope-finance Jun 24, 2024
c4c40a2
test example
0xripleys Jun 25, 2024
6f24450
test doesn't break for stupid reasons
0xripleys Jun 25, 2024
01213ff
fix tests
nope-finance Jul 3, 2024
748eda2
making get price function more generic
nope-finance Jul 3, 2024
b4e2872
feat: switchboard on-demand, init deps
mgild Jun 20, 2024
1cb1d1e
add body for parsing switchboard feeds
mgild Jun 20, 2024
b4109da
add body for parsing switchboard feeds
mgild Jun 20, 2024
4859319
update to sdk 0.1.12
mgild Jul 3, 2024
0330d2f
fixing up sb on demand
nope-finance Jul 3, 2024
d630929
Merge branch 'mgild-add_sb_on_demand_shit' into add_pythnet_shit
nope-finance Jul 3, 2024
97aa9f8
adding range check for switchboard
nope-finance Jul 3, 2024
b7c4fc0
pull oracle tests
0xripleys Jul 3, 2024
6e46900
switchboard test failing
0xripleys Jul 4, 2024
89cedae
fixing tests
0xripleys Jul 5, 2024
78b44b8
fmt
0xripleys Jul 5, 2024
ca8e365
update solana version
0xripleys Jul 5, 2024
949c00f
rust version
0xripleys Jul 5, 2024
e0cb002
fixing other warnings
0xripleys Jul 5, 2024
7468a62
create oracle crate
0xripleys Jul 5, 2024
cf78a99
minor cleanup
0xripleys Jul 5, 2024
be326fb
forgot to add fixtures
0xripleys Jul 5, 2024
a7ec4fa
clip
0xripleys Jul 5, 2024
1056f96
oops
0xripleys Jul 5, 2024
eed4f01
remove oracle ids from sdk
0xripleys Jul 5, 2024
e3634f5
fmt
0xripleys Jul 8, 2024
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
Prev Previous commit
Next Next commit
minor cleanup
  • Loading branch information
0xripleys committed Jul 5, 2024
commit cf78a993b00c65dc8e215945073d802b9a21887f
16 changes: 16 additions & 0 deletions token-lending/oracles/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
pub mod pyth;
pub mod switchboard;

use crate::pyth::get_pyth_price_unchecked;
use crate::pyth::get_pyth_pull_price;
use crate::pyth::get_pyth_pull_price_unchecked;
use crate::switchboard::get_switchboard_price;
use crate::switchboard::get_switchboard_price_on_demand;
use crate::switchboard::get_switchboard_price_v2;
use solana_program::{
account_info::AccountInfo, msg, program_error::ProgramError, sysvar::clock::Clock,
};
@@ -59,6 +63,18 @@ pub fn get_single_price(
}
}

pub fn get_single_price_unchecked(
oracle_account_info: &AccountInfo,
clock: &Clock,
) -> Result<Decimal, ProgramError> {
match get_oracle_type(oracle_account_info)? {
OracleType::Pyth => get_pyth_price_unchecked(oracle_account_info),
OracleType::PythPull => get_pyth_pull_price_unchecked(oracle_account_info),
OracleType::Switchboard => get_switchboard_price_v2(oracle_account_info, clock, false),
OracleType::SbOnDemand => get_switchboard_price_on_demand(oracle_account_info, clock, true),
}
}

/// Mainnet program id for Switchboard v2.
pub mod switchboard_v2_mainnet {
solana_program::declare_id!("SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f");
31 changes: 6 additions & 25 deletions token-lending/program/src/processor.rs
Original file line number Diff line number Diff line change
@@ -15,18 +15,11 @@ use crate::{
};
use bytemuck::bytes_of;
use oracles::get_single_price;
use oracles::get_single_price_unchecked;
use oracles::pyth::validate_pyth_keys;
use oracles::switchboard::get_switchboard_price_on_demand;
use oracles::switchboard::get_switchboard_price_v2;
use oracles::switchboard::validate_sb_on_demand_keys;
use oracles::switchboard::validate_switchboard_keys;
use oracles::{
get_oracle_type,
pyth::{
get_pyth_price_unchecked, get_pyth_pull_price_unchecked, validate_pyth_price_account_info,
},
OracleType,
};
use oracles::{get_oracle_type, pyth::validate_pyth_price_account_info, OracleType};
use solana_program::{
account_info::{next_account_info, AccountInfo},
entrypoint::ProgramResult,
@@ -578,22 +571,10 @@ fn _refresh_reserve<'a>(
return Err(LendingError::InvalidAccountInput.into());
}

match get_oracle_type(extra_oracle_account_info)? {
OracleType::Pyth => Some(get_pyth_price_unchecked(extra_oracle_account_info)?),
OracleType::PythPull => {
Some(get_pyth_pull_price_unchecked(extra_oracle_account_info)?)
}
OracleType::Switchboard => Some(get_switchboard_price_v2(
extra_oracle_account_info,
clock,
false,
)?),
OracleType::SbOnDemand => Some(get_switchboard_price_on_demand(
extra_oracle_account_info,
clock,
true,
)?),
}
Some(get_single_price_unchecked(
extra_oracle_account_info,
clock,
)?)
}
None => {
msg!("Reserve extra oracle account info missing");
Loading
Oops, something went wrong.