@@ -28,7 +28,11 @@ use solana_program::{
28
28
} ;
29
29
use spl_token:: solana_program:: instruction:: AccountMeta ;
30
30
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
+ } ;
32
36
use switchboard_program:: {
33
37
get_aggregator, get_aggregator_result, AggregatorState , RoundResult , SwitchboardAccountType ,
34
38
} ;
@@ -897,8 +901,35 @@ fn process_refresh_obligation(program_id: &Pubkey, accounts: &[AccountInfo]) ->
897
901
898
902
obligation. deposited_value = deposited_value;
899
903
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) ;
902
933
903
934
obligation. last_update . update_slot ( clock. slot ) ;
904
935
Obligation :: pack ( obligation, & mut obligation_info. data . borrow_mut ( ) ) ?;
0 commit comments