Skip to content

Commit

Permalink
review/bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
nope-finance committed Jun 30, 2021
1 parent 023f727 commit 654b34c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
6 changes: 3 additions & 3 deletions token-lending/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,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 @@ -395,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 Down Expand Up @@ -483,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 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");
22 changes: 16 additions & 6 deletions token-lending/program/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,11 @@ fn process_init_reserve(
assert_rent_exempt(rent, reserve_info)?;
let mut reserve = assert_uninitialized::<Reserve>(reserve_info)?;
if reserve_info.owner != program_id {
msg!("Reserve provided is not owned by the lending program");
msg!(
"Reserve provided is not owned by the lending program {} != {}",
&reserve_info.owner.to_string(),
&program_id.to_string(),
);
return Err(LendingError::InvalidAccountOwner.into());
}

Expand All @@ -255,7 +259,10 @@ fn process_init_reserve(

let lending_market = LendingMarket::unpack(&lending_market_info.data.borrow())?;
if lending_market_info.owner != program_id {
msg!("Lending market provided is not owned by the lending program");
msg!("Lending market provided is not owned by the lending program {} != {}",
&lending_market_info.owner.to_string(),
&program_id.to_string(),
);
return Err(LendingError::InvalidAccountOwner.into());
}
if &lending_market.token_program_id != token_program_id.key {
Expand Down Expand Up @@ -1868,7 +1875,11 @@ fn process_flash_loan(

fn assert_rent_exempt(rent: &Rent, account_info: &AccountInfo) -> ProgramResult {
if !rent.is_exempt(account_info.lamports(), account_info.data_len()) {
msg!(&rent.minimum_balance(account_info.data_len()).to_string());
msg!(
"Rent exempt balance insufficient got {} expected {}",
&account_info.lamports().to_string(),
&rent.minimum_balance(account_info.data_len()).to_string(),
);
Err(LendingError::NotRentExempt.into())
} else {
Ok(())
Expand Down Expand Up @@ -2000,7 +2011,7 @@ fn get_switchboard_price(
switchboard_feed_info: &AccountInfo,
clock: &Clock,
) -> Result<Decimal, ProgramError> {
const STALE_AFTER_SLOTS_ELAPSED: u64 = 30;
const STALE_AFTER_SLOTS_ELAPSED: u64 = 100;

let account_buf = switchboard_feed_info.try_borrow_data()?;
if account_buf[0] != SwitchboardAccountType::TYPE_AGGREGATOR as u8 {
Expand Down Expand Up @@ -2029,8 +2040,7 @@ fn get_switchboard_price(
// 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 price = ((price_quotient as f64) * price_float) as u128;

Decimal::from(price).try_div(price_quotient)
}
Expand Down

0 comments on commit 654b34c

Please sign in to comment.