Skip to content

Commit

Permalink
sliding down borrow limit and 1 percent close factor
Browse files Browse the repository at this point in the history
  • Loading branch information
nope-finance committed Jun 21, 2022
1 parent 46cdf9a commit 40f0a03
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
43 changes: 40 additions & 3 deletions token-lending/program/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ use solana_program::{
};
use spl_token::solana_program::instruction::AccountMeta;
use spl_token::state::{Account, Mint};
use std::{convert::TryInto, result::Result};
use std::{
cmp::{max, min},
convert::TryInto,
result::Result,
};
use switchboard_program::{
get_aggregator, get_aggregator_result, AggregatorState, RoundResult, SwitchboardAccountType,
};
Expand Down Expand Up @@ -897,8 +901,41 @@ fn process_refresh_obligation(program_id: &Pubkey, accounts: &[AccountInfo]) ->

obligation.deposited_value = deposited_value;
obligation.borrowed_value = borrowed_value;
obligation.allowed_borrow_value = allowed_borrow_value;
obligation.unhealthy_borrow_value = unhealthy_borrow_value;

let start_slot = 138307846u64;
let end_slot = 138307846u64;
let current_slot_in_range = min(max(start_slot, clock.slot), end_slot);
let numerator = end_slot
.checked_sub(current_slot_in_range)
.ok_or(LendingError::MathOverflow)?;
let denominator = end_slot
.checked_sub(start_slot)
.ok_or(LendingError::MathOverflow)?;

let start_global_unhealthy_borrow_value = Decimal::from(110000000u64);
let end_global_unhealthy_borrow_value = Decimal::from(50000000u64);

// let mut global_unhealthy_borrow_value = end_global_unhealthy_borrow_value;
// if unhealthy_borrow_value > end_global_unhealthy_borrow_value {
// global_unhealthy_borrow_value = end_global_unhealthy_borrow_value
// .try_add(
// start_global_unhealthy_borrow_value
// .try_sub(end_global_unhealthy_borrow_value)?
// .try_mul(numerator)?
// .try_div(denominator)?
// )?;
// }
let global_unhealthy_borrow_value = end_global_unhealthy_borrow_value.try_add(
start_global_unhealthy_borrow_value
.try_sub(end_global_unhealthy_borrow_value)?
.try_mul(numerator)?
.try_div(denominator)?,
)?;
let global_allowed_borrow_value =
global_unhealthy_borrow_value.try_sub(Decimal::from(5000000u64))?;

obligation.allowed_borrow_value = min(allowed_borrow_value, global_allowed_borrow_value);
obligation.unhealthy_borrow_value = min(unhealthy_borrow_value, global_unhealthy_borrow_value);

obligation.last_update.update_slot(clock.slot);
Obligation::pack(obligation, &mut obligation_info.data.borrow_mut())?;
Expand Down
2 changes: 1 addition & 1 deletion token-lending/program/src/state/reserve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use std::{
};

/// Percentage of an obligation that can be repaid during each liquidation call
pub const LIQUIDATION_CLOSE_FACTOR: u8 = 20;
pub const LIQUIDATION_CLOSE_FACTOR: u8 = 1;

/// Obligation borrow amount that is small enough to close out
pub const LIQUIDATION_CLOSE_AMOUNT: u64 = 2;
Expand Down

0 comments on commit 40f0a03

Please sign in to comment.