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 02b699e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
37 changes: 34 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,35 @@ 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;


// Wednesday, June 22, 2022 12:00:00 AM GMT
let start_timestamp = 1655856000u64;
// Wednesday, June 29, 2022 12:00:00 AM GMT
let end_timestamp = 1656435600u64;
let current_timestamp = clock.unix_timestamp as u64;
let current_timestamp_in_range = min(max(start_timestamp, current_timestamp), end_timestamp);
let numerator = end_timestamp
.checked_sub(current_timestamp_in_range)
.ok_or(LendingError::MathOverflow)?;
let denominator = end_timestamp
.checked_sub(start_timestamp)
.ok_or(LendingError::MathOverflow)?;

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

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 02b699e

Please sign in to comment.