@@ -2550,8 +2550,8 @@ def _compute_refill_requirement(
2550
2550
f"Argument 'sender_balance' must be >= 0 ({ sender_balance = } )."
2551
2551
)
2552
2552
2553
- total_minimum_shortfall = 0
2554
- total_recommended_shortfall = 0
2553
+ minimum_obligations_shortfall = 0
2554
+ recommended_obligations_shortfall = 0
2555
2555
2556
2556
for address , requirements in asset_funding_values .items ():
2557
2557
topup = requirements ["topup" ]
@@ -2568,17 +2568,23 @@ def _compute_refill_requirement(
2568
2568
)
2569
2569
2570
2570
if balance < threshold :
2571
- total_minimum_shortfall += threshold - balance
2572
- total_recommended_shortfall += topup - balance
2571
+ minimum_obligations_shortfall += threshold - balance
2572
+ recommended_obligations_shortfall += topup - balance
2573
2573
2574
- if sender_balance - total_minimum_shortfall < sender_threshold :
2575
- total_minimum_shortfall += sender_threshold
2574
+ # Compute sender's remaining balance after covering obligations
2575
+ remaining_balance_minimum = sender_balance - minimum_obligations_shortfall
2576
+ remaining_balance_recommended = (
2577
+ sender_balance - recommended_obligations_shortfall
2578
+ )
2576
2579
2577
- if sender_balance - total_recommended_shortfall < sender_threshold :
2578
- total_recommended_shortfall += sender_topup
2580
+ # Determine if the sender needs additional refill
2581
+ minimum_refill = 0
2582
+ recommended_refill = 0
2583
+ if remaining_balance_minimum < sender_threshold :
2584
+ minimum_refill = sender_threshold - remaining_balance_minimum
2579
2585
2580
- minimum_refill = max ( total_minimum_shortfall - sender_balance , 0 )
2581
- recommended_refill = max ( total_recommended_shortfall - sender_balance , 0 )
2586
+ if remaining_balance_recommended < sender_threshold :
2587
+ recommended_refill = sender_topup - remaining_balance_recommended
2582
2588
2583
2589
return {
2584
2590
"minimum_refill" : minimum_refill ,
0 commit comments