@@ -907,7 +907,8 @@ def repay(
907
907
):
908
908
"""
909
909
@notice Repay debt (partially or fully)
910
- @param _d_debt The amount of debt to repay from user's wallet. If higher than the current debt - will do full repayment
910
+ @param _d_debt The amount of debt to repay from user's wallet.
911
+ If it ' s max_value (uint256 ) or just higher than the current debt - will do full repayment.
911
912
@param _for The user to repay the debt for
912
913
@param max_active_band Don't allow active band to be higher than this (to prevent front-running the repay)
913
914
@param callbacker Address of the callback contract
@@ -929,18 +930,16 @@ def repay(
929
930
callbacker, CALLBACK_REPAY, _for, xy[0 ], xy[1 ], debt, calldata
930
931
)
931
932
932
- total_borrowed: uint256 = _d_debt + xy[0] + cb.borrowed
933
- assert total_borrowed > 0 # dev: no coins to repay
934
- d_debt: uint256 = 0
933
+ d_debt: uint256 = min (min (_d_debt, debt) + xy[0 ] + cb.borrowed, debt)
934
+ assert d_debt > 0 # dev: no coins to repay
935
935
936
936
# If we have more borrowed tokens than the debt - full repayment and closing the position
937
- if total_borrowed >= debt:
938
- d_debt = debt
937
+ if d_debt >= debt:
939
938
debt = 0
940
939
if callbacker == empty (address ):
941
940
xy = extcall AMM.withdraw (_for, WAD)
942
941
943
- total_borrowed = 0
942
+ total_borrowed: uint256 = 0
944
943
if xy[0 ] > 0 :
945
944
# Only allow full repayment when underwater for the sender to do
946
945
assert approval
@@ -983,7 +982,6 @@ def repay(
983
982
active_band: int256 = staticcall AMM.active_band_with_skip ()
984
983
assert active_band <= max_active_band
985
984
986
- d_debt = total_borrowed
987
985
debt = unsafe_sub (debt, d_debt)
988
986
ns: int256 [2 ] = staticcall AMM.read_user_tick_numbers (_for)
989
987
size: int256 = unsafe_sub (ns[1 ], ns[0 ])
0 commit comments