Skip to content

Commit

Permalink
Release 1.6.2 (#16)
Browse files Browse the repository at this point in the history
* release changes

* .

* .
  • Loading branch information
y2kappa authored Aug 8, 2024
1 parent 9a0a1d4 commit 349df28
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 21 deletions.
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion programs/klend/src/handlers/handler_init_obligation.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anchor_lang::{prelude::*, Accounts};
use anchor_spl::token::Mint;
use anchor_spl::token_interface::Mint;

use crate::{
state::{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub fn process(ctx: Context<InitObligationFarmsForReserve>, mode: u8) -> Result<
let obligation = &ctx.accounts.obligation.to_account_info().key;

require!(
reserve.config.status() == ReserveStatus::Active,
reserve.config.status() != ReserveStatus::Obsolete,
LendingError::ReserveObsolete
);

Expand Down
6 changes: 5 additions & 1 deletion programs/klend/src/handlers/handler_update_reserve_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ pub fn process(
);
msg!("WARNING! Skipping validation of the config");
} else {
lending_operations::utils::validate_reserve_config(&reserve.config, &market)?;
lending_operations::utils::validate_reserve_config(
&reserve.config,
&market,
ctx.accounts.reserve.key(),
)?;
}

Ok(())
Expand Down
36 changes: 25 additions & 11 deletions programs/klend/src/lending_market/lending_operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1616,12 +1616,19 @@ where
let absolute_referral_rate =
Fraction::from_bits(borrow_reserve.liquidity.absolute_referral_rate_sf);

if absolute_referral_rate == Fraction::ZERO {
return Ok(());
}

let fixed_rate = approximate_compounded_interest(
Fraction::from_bps(borrow_reserve.config.host_fixed_interest_rate_bps),
slots_elapsed,
);
let net_new_debt = borrowed_amount_f - previous_borrowed_amount_f;
let net_new_fixed_debt = previous_borrowed_amount_f * fixed_rate - previous_borrowed_amount_f;
if net_new_fixed_debt > net_new_debt {
return Err(LendingError::CannotCalculateReferralAmountDueToSlotsMismatch.into());
}
let net_new_variable_debt_f = net_new_debt - net_new_fixed_debt;

let referrer_fee_f = net_new_variable_debt_f * absolute_referral_rate;
Expand Down Expand Up @@ -2932,7 +2939,11 @@ pub mod utils {
Ok(())
}

pub fn validate_reserve_config(config: &ReserveConfig, market: &LendingMarket) -> Result<()> {
pub fn validate_reserve_config(
config: &ReserveConfig,
market: &LendingMarket,
reserve_address: Pubkey,
) -> Result<()> {
if config.loan_to_value_pct >= 100 {
msg!("Loan to value ratio must be in range [0, 100)");
return err!(LendingError::InvalidConfig);
Expand Down Expand Up @@ -3008,21 +3019,24 @@ pub mod utils {
return err!(LendingError::InvalidConfig);
}

if elevation_group.liquidation_threshold_pct < config.liquidation_threshold_pct {
msg!("Invalid liquidation threshold, elevation id liquidation threshold must be greater than the config's");
return err!(LendingError::InvalidConfig);
}

if elevation_group.ltv_pct < config.loan_to_value_pct {
msg!("Invalid ltv ratio, cannot be bigger than the ltv ratio");
return err!(LendingError::InvalidConfig);
}

if elevation_group.debt_reserve == Pubkey::default() {
msg!("Invalid elevation group debt reserve");
return err!(LendingError::InvalidConfig);
}

if elevation_group.debt_reserve != reserve_address {
if elevation_group.liquidation_threshold_pct < config.liquidation_threshold_pct
{
msg!("Invalid liquidation threshold, elevation id liquidation threshold must be greater than the config's");
return err!(LendingError::InvalidConfig);
}

if elevation_group.ltv_pct < config.loan_to_value_pct {
msg!("Invalid ltv ratio, cannot be bigger than the ltv ratio");
return err!(LendingError::InvalidConfig);
}
}

if elevation_group.max_reserves_as_collateral == 0 {
msg!("Invalid elevation group max collateral reserves");
return err!(LendingError::InvalidConfig);
Expand Down
2 changes: 2 additions & 0 deletions programs/klend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,8 @@ pub enum LendingError {
UnsupportedTokenExtension,
#[msg("Can't have an spl token mint with a t22 account")]
InvalidTokenAccount,
#[msg("Cannot calculate referral amount due to slots mismatch")]
CannotCalculateReferralAmountDueToSlotsMismatch,
}

pub type LendingResult<T = ()> = std::result::Result<T, LendingError>;

0 comments on commit 349df28

Please sign in to comment.