validateRepay, paybackAmount
Last updated
Last updated
amountSent
is params.amount
, which is amount
passed into repay
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 amountSent
is type().max
-> indicates an explicit amount was not set by user
msg.sender
is not onBehalfOf
: paying for someone else
when 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
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
overwrite repay amount (params.amount
) to the user's AToken balance
this 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
User has opted to repay his debt partially,
overwrite paybackAmount
to 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"