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