Function: redeemCollateral(uint256 _debtAmount, address _firstRedemptionHint, address _upperPartialRedemptionHint, address _lowerPartialRedemptionHint, uint256 _partialRedemptionHintNICR, uint256 _maxIterations, uint256 _maxFeePercentage)
This is the function used to redeem the corresponding amount of collateral from as manytTroves as are needed to fill the redemption request.
Inputs
_debtAmountControl: Fully controlled.
Constraints: Balance of caller should be greater than
_debtAmount.Impact: The debt amount to be sent to the system.
_firstRedemptionHintControl: Fully controlled.
Constraints: No constraints.
Impact: Hints at the position of the first trove that will be redeemed from.
_upperPartialRedemptionHintControl: Fully controlled.
Constraints: No constraints.
Impact: Hints at the
prevIdneighbor of the last redeemed trove upon reinsertion, if it is partially redeemed.
_lowerPartialRedemptionHintControl: Fully controlled.
Constraints: No constraints.
Impact: Hints at the
nextIdneighbor of the last redeemed trove upon reinsertion, if it is partially redeemed.
_partialRedemptionHintNICRControl: Fully controlled.
Constraints: No constraints.
Impact: Ensures that the transaction will not run out of gas if neither
_lowerPartialRedemptionHintnor_upperPartialRedemptionHintare valid anymore.
_maxIterationsControl: Fully controlled.
Constraints: No constraints.
Impact: The number of troves redeemed from is capped by
_maxIterations.
_maxFeePercentageControl: Fully controlled.
Constraints:
_maxFeePercentage >= redemptionFeeFloor && _maxFeePercentage <= maxRedemptionFee.Impact: The borrower has to provide a
_maxFeePercentagethat they are willing to accept in case of a fee slippage.
Branches and code coverage (including function calls)
Intended branches
If the provided redemption hint is valid, set current borrower to the given first redemption hint.
If the provided redemption hint is invalid, find the first trove with ICR >= MCR.
If
_maxIterationsis set to a nonzero value, the loop is capped to the provided value.If
_maxIterationsis set to 0, the value should be ignored.The amount to be redeemed should be capped by the entire debt of the trove minus the liquidation reserve.
If the remaining debt is equal to
DEBT_GAS_COMPENSATION, close the trove.If partial redemption was cancelled (out-of-date hint or new net debt < minimum), do not redeem from the last trove and break out of the loop.
Collateral fee should be zero when sunsetting; otherwise, check if the user accepts the fee.
If the trove length becomes zero after redemptions, reset the state of the system.
Negative behavior
Revert if
_maxFeePercentageis not in acceptable range.Revert if collateral drawn is zero.
Function call analysis
debtToken.balanceOf(msg.sender)What is controllable?
msg.sender.If return value controllable, how is it used and how can it go wrong? Return value is the balance of caller's
debtToken.What happens if it reverts, reenters, or does other unusual control flow? No reentrancy scenarios.