@@ -785,6 +785,7 @@ fn process_redeem_reserve_collateral(
785785 let clock = & Clock :: get ( ) ?;
786786 let token_program_id = next_account_info ( account_info_iter) ?;
787787
788+ _refresh_reserve_interest ( program_id, reserve_info, clock) ?;
788789 _redeem_reserve_collateral (
789790 program_id,
790791 collateral_amount,
@@ -1467,6 +1468,8 @@ fn _withdraw_obligation_collateral<'a>(
14671468 }
14681469
14691470 let withdraw_reserve = Box :: new ( Reserve :: unpack ( & withdraw_reserve_info. data . borrow ( ) ) ?) ;
1471+ let mut obligation = Obligation :: unpack ( & obligation_info. data . borrow ( ) ) ?;
1472+
14701473 if withdraw_reserve_info. owner != program_id {
14711474 msg ! ( "Withdraw reserve provided is not owned by the lending program" ) ;
14721475 return Err ( LendingError :: InvalidAccountOwner . into ( ) ) ;
@@ -1483,12 +1486,11 @@ fn _withdraw_obligation_collateral<'a>(
14831486 msg ! ( "Withdraw reserve collateral supply cannot be used as the destination collateral provided" ) ;
14841487 return Err ( LendingError :: InvalidAccountInput . into ( ) ) ;
14851488 }
1486- if withdraw_reserve. last_update . is_stale ( clock. slot ) ? {
1489+ if withdraw_reserve. last_update . is_stale ( clock. slot ) ? && !obligation . borrows . is_empty ( ) {
14871490 msg ! ( "Withdraw reserve is stale and must be refreshed in the current slot" ) ;
14881491 return Err ( LendingError :: ReserveStale . into ( ) ) ;
14891492 }
14901493
1491- let mut obligation = Obligation :: unpack ( & obligation_info. data . borrow ( ) ) ?;
14921494 if obligation_info. owner != program_id {
14931495 msg ! ( "Obligation provided is not owned by the lending program" ) ;
14941496 return Err ( LendingError :: InvalidAccountOwner . into ( ) ) ;
@@ -1505,7 +1507,7 @@ fn _withdraw_obligation_collateral<'a>(
15051507 msg ! ( "Obligation owner provided must be a signer" ) ;
15061508 return Err ( LendingError :: InvalidSigner . into ( ) ) ;
15071509 }
1508- if obligation. last_update . is_stale ( clock. slot ) ? {
1510+ if obligation. last_update . is_stale ( clock. slot ) ? && !obligation . borrows . is_empty ( ) {
15091511 msg ! ( "Obligation is stale and must be refreshed in the current slot" ) ;
15101512 return Err ( LendingError :: ObligationStale . into ( ) ) ;
15111513 }
@@ -2348,6 +2350,10 @@ fn process_withdraw_obligation_collateral_and_redeem_reserve_liquidity(
23482350 & accounts[ 12 ..] ,
23492351 ) ?;
23502352
2353+ // Needed in the case where the obligation has no borrows => user doesn't refresh anything
2354+ // if the obligation has borrows, then withdraw_obligation_collateral ensures that the
2355+ // obligation (and as a result, the reserves) were refreshed
2356+ _refresh_reserve_interest ( program_id, reserve_info, clock) ?;
23512357 _redeem_reserve_collateral (
23522358 program_id,
23532359 liquidity_amount,
0 commit comments