@@ -411,6 +411,23 @@ fn _refresh_reserve<'a>(
411411    } 
412412
413413    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+     } 
414431
415432    reserve. accrue_interest ( clock. slot ) ?; 
416433    reserve. last_update . update_slot ( clock. slot ) ; 
@@ -483,7 +500,6 @@ fn _deposit_reserve_liquidity<'a>(
483500        msg ! ( "Lending market token program does not match the token program provided" ) ; 
484501        return  Err ( LendingError :: InvalidTokenProgram . into ( ) ) ; 
485502    } 
486- 
487503    let  mut  reserve = Reserve :: unpack ( & reserve_info. data . borrow ( ) ) ?; 
488504    if  reserve_info. owner  != program_id { 
489505        msg ! ( "Reserve provided is not owned by the lending program" ) ; 
@@ -513,7 +529,6 @@ fn _deposit_reserve_liquidity<'a>(
513529        msg ! ( "Reserve is stale and must be refreshed in the current slot" ) ; 
514530        return  Err ( LendingError :: ReserveStale . into ( ) ) ; 
515531    } 
516- 
517532    let  authority_signer_seeds = & [ 
518533        lending_market_info. key . as_ref ( ) , 
519534        & [ lending_market. bump_seed ] , 
@@ -971,7 +986,6 @@ fn _deposit_obligation_collateral<'a>(
971986        . deposit ( collateral_amount) ?; 
972987    obligation. last_update . mark_stale ( ) ; 
973988    Obligation :: pack ( obligation,  & mut  obligation_info. data . borrow_mut ( ) ) ?; 
974- 
975989    spl_token_transfer ( TokenTransferParams  { 
976990        source :  source_collateral_info. clone ( ) , 
977991        destination :  destination_collateral_info. clone ( ) , 
@@ -980,7 +994,6 @@ fn _deposit_obligation_collateral<'a>(
980994        authority_signer_seeds :  & [ ] , 
981995        token_program :  token_program_id. clone ( ) , 
982996    } ) ?; 
983- 
984997    Ok ( ( ) ) 
985998} 
986999
@@ -1006,12 +1019,13 @@ fn process_deposit_reserve_liquidity_and_obligation_collateral(
10061019    let  destination_collateral_info = next_account_info ( account_info_iter) ?; 
10071020    let  obligation_info = next_account_info ( account_info_iter) ?; 
10081021    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) ?; 
10111024    let  user_transfer_authority_info = next_account_info ( account_info_iter) ?; 
10121025    let  clock = & Clock :: from_account_info ( next_account_info ( account_info_iter) ?) ?; 
10131026    let  token_program_id = next_account_info ( account_info_iter) ?; 
10141027
1028+     _refresh_reserve_interest ( program_id,  reserve_info,  clock) ?; 
10151029    let  collateral_amount = _deposit_reserve_liquidity ( 
10161030        program_id, 
10171031        liquidity_amount, 
@@ -1026,13 +1040,7 @@ fn process_deposit_reserve_liquidity_and_obligation_collateral(
10261040        clock, 
10271041        token_program_id, 
10281042    ) ?; 
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) ?; 
10361044    _deposit_obligation_collateral ( 
10371045        program_id, 
10381046        collateral_amount, 
@@ -1046,6 +1054,11 @@ fn process_deposit_reserve_liquidity_and_obligation_collateral(
10461054        clock, 
10471055        token_program_id, 
10481056    ) ?; 
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+ 
10491062    Ok ( ( ) ) 
10501063} 
10511064
0 commit comments