Skip to content

Commit d1cabeb

Browse files
Merge branch 'tests-refactoring' of github.com:curvefi/curve-stablecoin into tests-refactoring
2 parents 48e9a54 + b1d63f4 commit d1cabeb

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

contracts/Controller.vy

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,8 @@ def repay(
905905
):
906906
"""
907907
@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.
909910
@param _for The user to repay the debt for
910911
@param max_active_band Don't allow active band to be higher than this (to prevent front-running the repay)
911912
@param callbacker Address of the callback contract
@@ -927,18 +928,16 @@ def repay(
927928
callbacker, CALLBACK_REPAY, _for, xy[0], xy[1], debt, calldata
928929
)
929930

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
933933

934934
# 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:
937936
debt = 0
938937
if callbacker == empty(address):
939938
xy = extcall AMM.withdraw(_for, WAD)
940939

941-
total_borrowed = 0
940+
total_borrowed: uint256 = 0
942941
if xy[0] > 0:
943942
# Only allow full repayment when underwater for the sender to do
944943
assert approval
@@ -981,7 +980,6 @@ def repay(
981980
active_band: int256 = staticcall AMM.active_band_with_skip()
982981
assert active_band <= max_active_band
983982

984-
d_debt = total_borrowed
985983
debt = unsafe_sub(debt, d_debt)
986984
ns: int256[2] = staticcall AMM.read_user_tick_numbers(_for)
987985
size: int256 = unsafe_sub(ns[1], ns[0])

0 commit comments

Comments
 (0)