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

Switchboard #9

Merged
merged 8 commits into from
Jun 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
317 changes: 296 additions & 21 deletions Cargo.lock

Large diffs are not rendered by default.

20 changes: 17 additions & 3 deletions token-lending/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type Error = Box<dyn std::error::Error>;
type CommandResult = Result<(), Error>;

const PYTH_PROGRAM_ID: &str = "gSbePebfvPy7tRqimPoVecS2UsBvYv46ynrzWocc92s";
// const SWITCHBOARD_PROGRAM_ID: &str = "DtmE9D2CSB4L5D6A15mraeEjrGMm6auWVzgaD8hK2tZM";

fn main() {
solana_logger::setup_with_default("solana=info");
Expand Down Expand Up @@ -207,6 +208,15 @@ fn main() {
.required(true)
.help("Pyth price account: https://pyth.network/developers/consumers/accounts"),
)
.arg(
Arg::with_name("switchboard_feed")
.long("switchboard-feed")
.validator(is_pubkey)
.value_name("PUBKEY")
.takes_value(true)
.required(true)
.help("Switchboard price feed account: https://switchboard.xyz/#/explorer"),
)
.arg(
Arg::with_name("optimal_utilization_rate")
.long("optimal-utilization-rate")
Expand Down Expand Up @@ -311,7 +321,7 @@ fn main() {
.get_matches();

let mut wallet_manager = None;
let config = {
let mut config = {
let cli_config = if let Some(config_file) = matches.value_of("config_file") {
solana_cli_config::Config::load(config_file).unwrap_or_default()
} else {
Expand Down Expand Up @@ -368,6 +378,7 @@ fn main() {
let ui_amount = value_of(arg_matches, "liquidity_amount").unwrap();
let pyth_product_pubkey = pubkey_of(arg_matches, "pyth_product").unwrap();
let pyth_price_pubkey = pubkey_of(arg_matches, "pyth_price").unwrap();
let switchboard_feed_pubkey = pubkey_of(arg_matches, "switchboard_feed").unwrap();
let optimal_utilization_rate =
value_of(arg_matches, "optimal_utilization_rate").unwrap();
let loan_to_value_ratio = value_of(arg_matches, "loan_to_value_ratio").unwrap();
Expand All @@ -384,7 +395,7 @@ fn main() {
let flash_loan_fee_wad = (flash_loan_fee * WAD as f64) as u64;

command_add_reserve(
&config,
&mut config,
ui_amount,
ReserveConfig {
optimal_utilization_rate,
Expand All @@ -406,6 +417,7 @@ fn main() {
lending_market_owner_keypair,
pyth_product_pubkey,
pyth_price_pubkey,
switchboard_feed_pubkey,
)
}
_ => unreachable!(),
Expand Down Expand Up @@ -471,7 +483,7 @@ fn command_create_lending_market(

#[allow(clippy::too_many_arguments)]
fn command_add_reserve(
config: &Config,
config: &mut Config,
ui_amount: f64,
reserve_config: ReserveConfig,
source_liquidity_pubkey: Pubkey,
Expand All @@ -480,6 +492,7 @@ fn command_add_reserve(
lending_market_owner_keypair: Keypair,
pyth_product_pubkey: Pubkey,
pyth_price_pubkey: Pubkey,
switchboard_feed_pubkey: Pubkey,
) -> CommandResult {
let source_liquidity_account = config.rpc_client.get_account(&source_liquidity_pubkey)?;
let source_liquidity = Token::unpack_from_slice(source_liquidity_account.data.borrow())?;
Expand Down Expand Up @@ -625,6 +638,7 @@ fn command_add_reserve(
collateral_supply_keypair.pubkey(),
pyth_product_pubkey,
pyth_price_pubkey,
switchboard_feed_pubkey,
lending_market_pubkey,
lending_market_owner_keypair.pubkey(),
user_transfer_authority_keypair.pubkey(),
Expand Down
3 changes: 2 additions & 1 deletion token-lending/program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ num-derive = "0.3"
num-traits = "0.2"
solana-program = "1.7.3"
spl-token = { path = "../../token/program", features = [ "no-entrypoint" ] }
switchboard-program = "0.1.45"
thiserror = "1.0"
uint = "0.8"
uint = "0.9.0"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just some lib for larger int arithmetic? might not need this was getting a warning or something before i think is why i changed it


[dev-dependencies]
assert_matches = "1.5.0"
Expand Down
40 changes: 24 additions & 16 deletions token-lending/program/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,16 @@ pub enum LendingInstruction {
/// 6. `[]` Pyth product account.
/// 7. `[]` Pyth price account.
/// This will be used as the reserve liquidity oracle account.
/// 8. `[writable]` Reserve collateral SPL Token mint - uninitialized.
/// 9. `[writable]` Reserve collateral token supply - uninitialized.
/// 10 `[]` Lending market account.
/// 11 `[]` Derived lending market authority.
/// 12 `[signer]` Lending market owner.
/// 13 `[signer]` User transfer authority ($authority).
/// 14 `[]` Clock sysvar.
/// 15 `[]` Rent sysvar.
/// 16 `[]` Token program id.
/// 8. `[]` Switchboard price feed account. used as a backup oracle
/// 9. `[writable]` Reserve collateral SPL Token mint - uninitialized.
/// 10`[writable]` Reserve collateral token supply - uninitialized.
/// 11 `[]` Lending market account.
/// 12 `[]` Derived lending market authority.
/// 13 `[signer]` Lending market owner.
/// 14 `[signer]` User transfer authority ($authority).
/// 15 `[]` Clock sysvar.
/// 16 `[]` Rent sysvar.
/// 17 `[]` Token program id.
InitReserve {
/// Initial amount of liquidity to deposit into the new reserve
liquidity_amount: u64,
Expand All @@ -82,8 +83,10 @@ pub enum LendingInstruction {
/// Accounts expected by this instruction:
///
/// 0. `[writable]` Reserve account.
/// 1. `[]` Reserve liquidity oracle account.
/// 1. `[]` Pyth Reserve liquidity oracle account.
/// Must be the Pyth price account specified at InitReserve.
/// 1. `[]` Switchboard Reserve liquidity oracle account.
/// Must be the Switchboard price feed account specified at InitReserve.
/// 2. `[]` Clock sysvar.
RefreshReserve,

Expand All @@ -101,10 +104,11 @@ pub enum LendingInstruction {
/// 4. `[writable]` Reserve collateral SPL Token mint.
/// 5. `[]` Lending market account.
/// 6. `[]` Derived lending market authority.
/// 7. `[]` Reserve liquidity oracle account.
/// 8. `[signer]` User transfer authority ($authority).
/// 9. `[]` Clock sysvar.
/// 10. `[]` Token program id.
/// 7. `[]` Pyth price oracle account.
/// 8. `[]` Switchboard price feed oracle account.
/// 9. `[signer]` User transfer authority ($authority).
/// 10 `[]` Clock sysvar.
/// 11 `[]` Token program id.
DepositReserveLiquidity {
/// Amount of liquidity to deposit in exchange for collateral tokens
liquidity_amount: u64,
Expand Down Expand Up @@ -638,6 +642,7 @@ pub fn init_reserve(
reserve_collateral_supply_pubkey: Pubkey,
pyth_product_pubkey: Pubkey,
pyth_price_pubkey: Pubkey,
switchboard_feed_pubkey: Pubkey,
lending_market_pubkey: Pubkey,
lending_market_owner_pubkey: Pubkey,
user_transfer_authority_pubkey: Pubkey,
Expand All @@ -657,6 +662,7 @@ pub fn init_reserve(
AccountMeta::new(reserve_collateral_supply_pubkey, false),
AccountMeta::new_readonly(pyth_product_pubkey, false),
AccountMeta::new_readonly(pyth_price_pubkey, false),
AccountMeta::new_readonly(switchboard_feed_pubkey, false),
AccountMeta::new_readonly(lending_market_pubkey, false),
AccountMeta::new_readonly(lending_market_authority_pubkey, false),
AccountMeta::new_readonly(lending_market_owner_pubkey, true),
Expand All @@ -680,11 +686,13 @@ pub fn init_reserve(
pub fn refresh_reserve(
program_id: Pubkey,
reserve_pubkey: Pubkey,
reserve_liquidity_oracle_pubkey: Pubkey,
reserve_liquidity_pyth_oracle_pubkey: Pubkey,
reserve_liquidity_switchboard_oracle_pubkey: Pubkey,
) -> Instruction {
let accounts = vec![
AccountMeta::new(reserve_pubkey, false),
AccountMeta::new_readonly(reserve_liquidity_oracle_pubkey, false),
AccountMeta::new_readonly(reserve_liquidity_pyth_oracle_pubkey, false),
AccountMeta::new_readonly(reserve_liquidity_switchboard_oracle_pubkey, false),
AccountMeta::new_readonly(sysvar::clock::id(), false),
];
Instruction {
Expand Down
2 changes: 1 addition & 1 deletion token-lending/program/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ pub mod state;
// Export current sdk types for downstream users building with a different sdk version
pub use solana_program;

solana_program::declare_id!("GdBvMRLxxx3fanubFXPxmt5sQrrTxfvkfWSDxBTztb8Z");
solana_program::declare_id!("DLendnZuSiCK4kBRtX126ogq1uRnb1TGGsjW6Tnw1vMJ");
Loading