Skip to content

Commit fdaec0e

Browse files
authored
Merge pull request #9 from solendprotocol/switchboard
Switchboard
2 parents 7ba5e0d + 668b30e commit fdaec0e

16 files changed

+530
-94
lines changed

Cargo.lock

Lines changed: 296 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

token-lending/cli/src/main.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type Error = Box<dyn std::error::Error>;
4444
type CommandResult = Result<(), Error>;
4545

4646
const PYTH_PROGRAM_ID: &str = "gSbePebfvPy7tRqimPoVecS2UsBvYv46ynrzWocc92s";
47+
// const SWITCHBOARD_PROGRAM_ID: &str = "DtmE9D2CSB4L5D6A15mraeEjrGMm6auWVzgaD8hK2tZM";
4748

4849
fn main() {
4950
solana_logger::setup_with_default("solana=info");
@@ -207,6 +208,15 @@ fn main() {
207208
.required(true)
208209
.help("Pyth price account: https://pyth.network/developers/consumers/accounts"),
209210
)
211+
.arg(
212+
Arg::with_name("switchboard_feed")
213+
.long("switchboard-feed")
214+
.validator(is_pubkey)
215+
.value_name("PUBKEY")
216+
.takes_value(true)
217+
.required(true)
218+
.help("Switchboard price feed account: https://switchboard.xyz/#/explorer"),
219+
)
210220
.arg(
211221
Arg::with_name("optimal_utilization_rate")
212222
.long("optimal-utilization-rate")
@@ -311,7 +321,7 @@ fn main() {
311321
.get_matches();
312322

313323
let mut wallet_manager = None;
314-
let config = {
324+
let mut config = {
315325
let cli_config = if let Some(config_file) = matches.value_of("config_file") {
316326
solana_cli_config::Config::load(config_file).unwrap_or_default()
317327
} else {
@@ -368,6 +378,7 @@ fn main() {
368378
let ui_amount = value_of(arg_matches, "liquidity_amount").unwrap();
369379
let pyth_product_pubkey = pubkey_of(arg_matches, "pyth_product").unwrap();
370380
let pyth_price_pubkey = pubkey_of(arg_matches, "pyth_price").unwrap();
381+
let switchboard_feed_pubkey = pubkey_of(arg_matches, "switchboard_feed").unwrap();
371382
let optimal_utilization_rate =
372383
value_of(arg_matches, "optimal_utilization_rate").unwrap();
373384
let loan_to_value_ratio = value_of(arg_matches, "loan_to_value_ratio").unwrap();
@@ -384,7 +395,7 @@ fn main() {
384395
let flash_loan_fee_wad = (flash_loan_fee * WAD as f64) as u64;
385396

386397
command_add_reserve(
387-
&config,
398+
&mut config,
388399
ui_amount,
389400
ReserveConfig {
390401
optimal_utilization_rate,
@@ -406,6 +417,7 @@ fn main() {
406417
lending_market_owner_keypair,
407418
pyth_product_pubkey,
408419
pyth_price_pubkey,
420+
switchboard_feed_pubkey,
409421
)
410422
}
411423
_ => unreachable!(),
@@ -471,7 +483,7 @@ fn command_create_lending_market(
471483

472484
#[allow(clippy::too_many_arguments)]
473485
fn command_add_reserve(
474-
config: &Config,
486+
config: &mut Config,
475487
ui_amount: f64,
476488
reserve_config: ReserveConfig,
477489
source_liquidity_pubkey: Pubkey,
@@ -480,6 +492,7 @@ fn command_add_reserve(
480492
lending_market_owner_keypair: Keypair,
481493
pyth_product_pubkey: Pubkey,
482494
pyth_price_pubkey: Pubkey,
495+
switchboard_feed_pubkey: Pubkey,
483496
) -> CommandResult {
484497
let source_liquidity_account = config.rpc_client.get_account(&source_liquidity_pubkey)?;
485498
let source_liquidity = Token::unpack_from_slice(source_liquidity_account.data.borrow())?;
@@ -625,6 +638,7 @@ fn command_add_reserve(
625638
collateral_supply_keypair.pubkey(),
626639
pyth_product_pubkey,
627640
pyth_price_pubkey,
641+
switchboard_feed_pubkey,
628642
lending_market_pubkey,
629643
lending_market_owner_keypair.pubkey(),
630644
user_transfer_authority_keypair.pubkey(),

token-lending/program/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ num-derive = "0.3"
1818
num-traits = "0.2"
1919
solana-program = "1.7.3"
2020
spl-token = { path = "../../token/program", features = [ "no-entrypoint" ] }
21+
switchboard-program = "0.1.45"
2122
thiserror = "1.0"
22-
uint = "0.8"
23+
uint = "0.9.0"
2324

2425
[dev-dependencies]
2526
assert_matches = "1.5.0"

token-lending/program/src/instruction.rs

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,16 @@ pub enum LendingInstruction {
6060
/// 6. `[]` Pyth product account.
6161
/// 7. `[]` Pyth price account.
6262
/// This will be used as the reserve liquidity oracle account.
63-
/// 8. `[writable]` Reserve collateral SPL Token mint - uninitialized.
64-
/// 9. `[writable]` Reserve collateral token supply - uninitialized.
65-
/// 10 `[]` Lending market account.
66-
/// 11 `[]` Derived lending market authority.
67-
/// 12 `[signer]` Lending market owner.
68-
/// 13 `[signer]` User transfer authority ($authority).
69-
/// 14 `[]` Clock sysvar.
70-
/// 15 `[]` Rent sysvar.
71-
/// 16 `[]` Token program id.
63+
/// 8. `[]` Switchboard price feed account. used as a backup oracle
64+
/// 9. `[writable]` Reserve collateral SPL Token mint - uninitialized.
65+
/// 10`[writable]` Reserve collateral token supply - uninitialized.
66+
/// 11 `[]` Lending market account.
67+
/// 12 `[]` Derived lending market authority.
68+
/// 13 `[signer]` Lending market owner.
69+
/// 14 `[signer]` User transfer authority ($authority).
70+
/// 15 `[]` Clock sysvar.
71+
/// 16 `[]` Rent sysvar.
72+
/// 17 `[]` Token program id.
7273
InitReserve {
7374
/// Initial amount of liquidity to deposit into the new reserve
7475
liquidity_amount: u64,
@@ -82,8 +83,10 @@ pub enum LendingInstruction {
8283
/// Accounts expected by this instruction:
8384
///
8485
/// 0. `[writable]` Reserve account.
85-
/// 1. `[]` Reserve liquidity oracle account.
86+
/// 1. `[]` Pyth Reserve liquidity oracle account.
8687
/// Must be the Pyth price account specified at InitReserve.
88+
/// 1. `[]` Switchboard Reserve liquidity oracle account.
89+
/// Must be the Switchboard price feed account specified at InitReserve.
8790
/// 2. `[]` Clock sysvar.
8891
RefreshReserve,
8992

@@ -101,10 +104,11 @@ pub enum LendingInstruction {
101104
/// 4. `[writable]` Reserve collateral SPL Token mint.
102105
/// 5. `[]` Lending market account.
103106
/// 6. `[]` Derived lending market authority.
104-
/// 7. `[]` Reserve liquidity oracle account.
105-
/// 8. `[signer]` User transfer authority ($authority).
106-
/// 9. `[]` Clock sysvar.
107-
/// 10. `[]` Token program id.
107+
/// 7. `[]` Pyth price oracle account.
108+
/// 8. `[]` Switchboard price feed oracle account.
109+
/// 9. `[signer]` User transfer authority ($authority).
110+
/// 10 `[]` Clock sysvar.
111+
/// 11 `[]` Token program id.
108112
DepositReserveLiquidity {
109113
/// Amount of liquidity to deposit in exchange for collateral tokens
110114
liquidity_amount: u64,
@@ -638,6 +642,7 @@ pub fn init_reserve(
638642
reserve_collateral_supply_pubkey: Pubkey,
639643
pyth_product_pubkey: Pubkey,
640644
pyth_price_pubkey: Pubkey,
645+
switchboard_feed_pubkey: Pubkey,
641646
lending_market_pubkey: Pubkey,
642647
lending_market_owner_pubkey: Pubkey,
643648
user_transfer_authority_pubkey: Pubkey,
@@ -657,6 +662,7 @@ pub fn init_reserve(
657662
AccountMeta::new(reserve_collateral_supply_pubkey, false),
658663
AccountMeta::new_readonly(pyth_product_pubkey, false),
659664
AccountMeta::new_readonly(pyth_price_pubkey, false),
665+
AccountMeta::new_readonly(switchboard_feed_pubkey, false),
660666
AccountMeta::new_readonly(lending_market_pubkey, false),
661667
AccountMeta::new_readonly(lending_market_authority_pubkey, false),
662668
AccountMeta::new_readonly(lending_market_owner_pubkey, true),
@@ -680,11 +686,13 @@ pub fn init_reserve(
680686
pub fn refresh_reserve(
681687
program_id: Pubkey,
682688
reserve_pubkey: Pubkey,
683-
reserve_liquidity_oracle_pubkey: Pubkey,
689+
reserve_liquidity_pyth_oracle_pubkey: Pubkey,
690+
reserve_liquidity_switchboard_oracle_pubkey: Pubkey,
684691
) -> Instruction {
685692
let accounts = vec![
686693
AccountMeta::new(reserve_pubkey, false),
687-
AccountMeta::new_readonly(reserve_liquidity_oracle_pubkey, false),
694+
AccountMeta::new_readonly(reserve_liquidity_pyth_oracle_pubkey, false),
695+
AccountMeta::new_readonly(reserve_liquidity_switchboard_oracle_pubkey, false),
688696
AccountMeta::new_readonly(sysvar::clock::id(), false),
689697
];
690698
Instruction {

token-lending/program/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ pub mod state;
1313
// Export current sdk types for downstream users building with a different sdk version
1414
pub use solana_program;
1515

16-
solana_program::declare_id!("GdBvMRLxxx3fanubFXPxmt5sQrrTxfvkfWSDxBTztb8Z");
16+
solana_program::declare_id!("DLendnZuSiCK4kBRtX126ogq1uRnb1TGGsjW6Tnw1vMJ");

0 commit comments

Comments
 (0)