Skip to content

Commit 02b699e

Browse files
committed
sliding down borrow limit and 1 percent close factor
1 parent 46cdf9a commit 02b699e

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

token-lending/program/src/processor.rs

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ use solana_program::{
2828
};
2929
use spl_token::solana_program::instruction::AccountMeta;
3030
use spl_token::state::{Account, Mint};
31-
use std::{convert::TryInto, result::Result};
31+
use std::{
32+
cmp::{max, min},
33+
convert::TryInto,
34+
result::Result,
35+
};
3236
use switchboard_program::{
3337
get_aggregator, get_aggregator_result, AggregatorState, RoundResult, SwitchboardAccountType,
3438
};
@@ -897,8 +901,35 @@ fn process_refresh_obligation(program_id: &Pubkey, accounts: &[AccountInfo]) ->
897901

898902
obligation.deposited_value = deposited_value;
899903
obligation.borrowed_value = borrowed_value;
900-
obligation.allowed_borrow_value = allowed_borrow_value;
901-
obligation.unhealthy_borrow_value = unhealthy_borrow_value;
904+
905+
906+
// Wednesday, June 22, 2022 12:00:00 AM GMT
907+
let start_timestamp = 1655856000u64;
908+
// Wednesday, June 29, 2022 12:00:00 AM GMT
909+
let end_timestamp = 1656435600u64;
910+
let current_timestamp = clock.unix_timestamp as u64;
911+
let current_timestamp_in_range = min(max(start_timestamp, current_timestamp), end_timestamp);
912+
let numerator = end_timestamp
913+
.checked_sub(current_timestamp_in_range)
914+
.ok_or(LendingError::MathOverflow)?;
915+
let denominator = end_timestamp
916+
.checked_sub(start_timestamp)
917+
.ok_or(LendingError::MathOverflow)?;
918+
919+
let start_global_unhealthy_borrow_value = Decimal::from(120000000u64);
920+
let end_global_unhealthy_borrow_value = Decimal::from(50000000u64);
921+
922+
let global_unhealthy_borrow_value = end_global_unhealthy_borrow_value.try_add(
923+
start_global_unhealthy_borrow_value
924+
.try_sub(end_global_unhealthy_borrow_value)?
925+
.try_mul(numerator)?
926+
.try_div(denominator)?,
927+
)?;
928+
let global_allowed_borrow_value =
929+
global_unhealthy_borrow_value.try_sub(Decimal::from(5000000u64))?;
930+
931+
obligation.allowed_borrow_value = min(allowed_borrow_value, global_allowed_borrow_value);
932+
obligation.unhealthy_borrow_value = min(unhealthy_borrow_value, global_unhealthy_borrow_value);
902933

903934
obligation.last_update.update_slot(clock.slot);
904935
Obligation::pack(obligation, &mut obligation_info.data.borrow_mut())?;

token-lending/program/src/state/reserve.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use std::{
1818
};
1919

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

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

0 commit comments

Comments
 (0)