@@ -785,6 +785,7 @@ fn process_redeem_reserve_collateral(
785
785
let clock = & Clock :: get ( ) ?;
786
786
let token_program_id = next_account_info ( account_info_iter) ?;
787
787
788
+ _refresh_reserve_interest ( program_id, reserve_info, clock) ?;
788
789
_redeem_reserve_collateral (
789
790
program_id,
790
791
collateral_amount,
@@ -1467,6 +1468,8 @@ fn _withdraw_obligation_collateral<'a>(
1467
1468
}
1468
1469
1469
1470
let withdraw_reserve = Box :: new ( Reserve :: unpack ( & withdraw_reserve_info. data . borrow ( ) ) ?) ;
1471
+ let mut obligation = Obligation :: unpack ( & obligation_info. data . borrow ( ) ) ?;
1472
+
1470
1473
if withdraw_reserve_info. owner != program_id {
1471
1474
msg ! ( "Withdraw reserve provided is not owned by the lending program" ) ;
1472
1475
return Err ( LendingError :: InvalidAccountOwner . into ( ) ) ;
@@ -1483,12 +1486,11 @@ fn _withdraw_obligation_collateral<'a>(
1483
1486
msg ! ( "Withdraw reserve collateral supply cannot be used as the destination collateral provided" ) ;
1484
1487
return Err ( LendingError :: InvalidAccountInput . into ( ) ) ;
1485
1488
}
1486
- if withdraw_reserve. last_update . is_stale ( clock. slot ) ? {
1489
+ if withdraw_reserve. last_update . is_stale ( clock. slot ) ? && !obligation . borrows . is_empty ( ) {
1487
1490
msg ! ( "Withdraw reserve is stale and must be refreshed in the current slot" ) ;
1488
1491
return Err ( LendingError :: ReserveStale . into ( ) ) ;
1489
1492
}
1490
1493
1491
- let mut obligation = Obligation :: unpack ( & obligation_info. data . borrow ( ) ) ?;
1492
1494
if obligation_info. owner != program_id {
1493
1495
msg ! ( "Obligation provided is not owned by the lending program" ) ;
1494
1496
return Err ( LendingError :: InvalidAccountOwner . into ( ) ) ;
@@ -1505,7 +1507,7 @@ fn _withdraw_obligation_collateral<'a>(
1505
1507
msg ! ( "Obligation owner provided must be a signer" ) ;
1506
1508
return Err ( LendingError :: InvalidSigner . into ( ) ) ;
1507
1509
}
1508
- if obligation. last_update . is_stale ( clock. slot ) ? {
1510
+ if obligation. last_update . is_stale ( clock. slot ) ? && !obligation . borrows . is_empty ( ) {
1509
1511
msg ! ( "Obligation is stale and must be refreshed in the current slot" ) ;
1510
1512
return Err ( LendingError :: ObligationStale . into ( ) ) ;
1511
1513
}
@@ -2348,6 +2350,10 @@ fn process_withdraw_obligation_collateral_and_redeem_reserve_liquidity(
2348
2350
& accounts[ 12 ..] ,
2349
2351
) ?;
2350
2352
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) ?;
2351
2357
_redeem_reserve_collateral (
2352
2358
program_id,
2353
2359
liquidity_amount,
0 commit comments