validateRepay, paybackAmount

Overview

validateRepay

  • amountSent is params.amount, which is amount passed into repay

The first two require statements serves as input validation for amountSent

  1. ensure that value is non-zero

  2. ensure that an explicit amount was set by the user, else ensure that msg.sender is paying for himself

  1. If amountSent is type().max -> indicates an explicit amount was not set by user

  2. msg.sender is not onBehalfOf: paying for someone else

  3. 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

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

  • 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.

Last updated

Was this helpful?