@@ -411,6 +411,23 @@ fn _refresh_reserve<'a>(
411
411
}
412
412
413
413
reserve. liquidity . market_price = get_price ( switchboard_feed_info, pyth_price_info, clock) ?;
414
+ Reserve :: pack ( reserve, & mut reserve_info. data . borrow_mut ( ) ) ?;
415
+
416
+ _refresh_reserve_interest ( program_id, reserve_info, clock)
417
+ }
418
+
419
+ /// Lite version of refresh_reserve that should be used when the oracle price doesn't need to be updated
420
+ /// BE CAREFUL WHEN USING THIS
421
+ fn _refresh_reserve_interest < ' a > (
422
+ program_id : & Pubkey ,
423
+ reserve_info : & AccountInfo < ' a > ,
424
+ clock : & Clock ,
425
+ ) -> ProgramResult {
426
+ let mut reserve = Reserve :: unpack ( & reserve_info. data . borrow ( ) ) ?;
427
+ if reserve_info. owner != program_id {
428
+ msg ! ( "Reserve provided is not owned by the lending program" ) ;
429
+ return Err ( LendingError :: InvalidAccountOwner . into ( ) ) ;
430
+ }
414
431
415
432
reserve. accrue_interest ( clock. slot ) ?;
416
433
reserve. last_update . update_slot ( clock. slot ) ;
@@ -483,7 +500,6 @@ fn _deposit_reserve_liquidity<'a>(
483
500
msg ! ( "Lending market token program does not match the token program provided" ) ;
484
501
return Err ( LendingError :: InvalidTokenProgram . into ( ) ) ;
485
502
}
486
-
487
503
let mut reserve = Reserve :: unpack ( & reserve_info. data . borrow ( ) ) ?;
488
504
if reserve_info. owner != program_id {
489
505
msg ! ( "Reserve provided is not owned by the lending program" ) ;
@@ -513,7 +529,6 @@ fn _deposit_reserve_liquidity<'a>(
513
529
msg ! ( "Reserve is stale and must be refreshed in the current slot" ) ;
514
530
return Err ( LendingError :: ReserveStale . into ( ) ) ;
515
531
}
516
-
517
532
let authority_signer_seeds = & [
518
533
lending_market_info. key . as_ref ( ) ,
519
534
& [ lending_market. bump_seed ] ,
@@ -971,7 +986,6 @@ fn _deposit_obligation_collateral<'a>(
971
986
. deposit ( collateral_amount) ?;
972
987
obligation. last_update . mark_stale ( ) ;
973
988
Obligation :: pack ( obligation, & mut obligation_info. data . borrow_mut ( ) ) ?;
974
-
975
989
spl_token_transfer ( TokenTransferParams {
976
990
source : source_collateral_info. clone ( ) ,
977
991
destination : destination_collateral_info. clone ( ) ,
@@ -980,7 +994,6 @@ fn _deposit_obligation_collateral<'a>(
980
994
authority_signer_seeds : & [ ] ,
981
995
token_program : token_program_id. clone ( ) ,
982
996
} ) ?;
983
-
984
997
Ok ( ( ) )
985
998
}
986
999
@@ -1006,12 +1019,13 @@ fn process_deposit_reserve_liquidity_and_obligation_collateral(
1006
1019
let destination_collateral_info = next_account_info ( account_info_iter) ?;
1007
1020
let obligation_info = next_account_info ( account_info_iter) ?;
1008
1021
let obligation_owner_info = next_account_info ( account_info_iter) ?;
1009
- let pyth_price_info = next_account_info ( account_info_iter) ?;
1010
- let switchboard_feed_info = next_account_info ( account_info_iter) ?;
1022
+ let _pyth_price_info = next_account_info ( account_info_iter) ?;
1023
+ let _switchboard_feed_info = next_account_info ( account_info_iter) ?;
1011
1024
let user_transfer_authority_info = next_account_info ( account_info_iter) ?;
1012
1025
let clock = & Clock :: from_account_info ( next_account_info ( account_info_iter) ?) ?;
1013
1026
let token_program_id = next_account_info ( account_info_iter) ?;
1014
1027
1028
+ _refresh_reserve_interest ( program_id, reserve_info, clock) ?;
1015
1029
let collateral_amount = _deposit_reserve_liquidity (
1016
1030
program_id,
1017
1031
liquidity_amount,
@@ -1026,13 +1040,7 @@ fn process_deposit_reserve_liquidity_and_obligation_collateral(
1026
1040
clock,
1027
1041
token_program_id,
1028
1042
) ?;
1029
- _refresh_reserve (
1030
- program_id,
1031
- reserve_info,
1032
- pyth_price_info,
1033
- switchboard_feed_info,
1034
- clock,
1035
- ) ?;
1043
+ _refresh_reserve_interest ( program_id, reserve_info, clock) ?;
1036
1044
_deposit_obligation_collateral (
1037
1045
program_id,
1038
1046
collateral_amount,
@@ -1046,6 +1054,11 @@ fn process_deposit_reserve_liquidity_and_obligation_collateral(
1046
1054
clock,
1047
1055
token_program_id,
1048
1056
) ?;
1057
+ // mark the reserve as stale to make sure no weird bugs happen
1058
+ let mut reserve = Reserve :: unpack ( & reserve_info. data . borrow ( ) ) ?;
1059
+ reserve. last_update . mark_stale ( ) ;
1060
+ Reserve :: pack ( reserve, & mut reserve_info. data . borrow_mut ( ) ) ?;
1061
+
1049
1062
Ok ( ( ) )
1050
1063
}
1051
1064
0 commit comments