validateRepay, paybackAmount
Overview

validateRepay

amountSentisparams.amount, which isamountpassed intorepay

The first two require statements serves as input validation for amountSent
ensure that value is non-zero
ensure that an explicit amount was set by the user, else ensure that msg.sender is paying for himself
If
amountSentistype().max-> indicates an explicit amount was not set by usermsg.senderis notonBehalfOf: paying for someone elsewhen repaying for another party, user must be explicit in amount
cannot just whack uint256.max as a cover all
cos' what if the debt was unexpectedly large
Then we check if the asset status via getFlags:
Active
Not Paused
See link for in-depth explanation on getFlags
Lastly, we check that user has a non-zero debt in either one of the interest rate mode: stable or variable.
if both are zero, there is no debt to repay
Setting paybackAmount

Select the non-zero debt value and assign it to
paybackAmount
Here paybackAmount reflects the total debt position of the user.
If useAtokens == true && params.amount == type.max
If useAtokens == true && params.amount == type.max overwrite repay amount (
params.amount) to the user's AToken balancethis is the max that can be repaid, given AToken balances
Applicable for repayWithATokens
In the case of repay, useATokens is set to false, therefore the code within the if section is not executed.
If params.amount < paybackAmount
If params.amount < paybackAmount User has opted to repay his debt partially,
overwrite
paybackAmountto reflect user's choice of partial repayment
Here paybackAmount reflects what the user wishes to repay.
Another way to view this, is: "Is the user able to cover his total debt with the repay amount, if not, set paybackAmount to what he has offered to repay"
Last updated