Repay Loan

This flow describes the backend flow for processing a user requested repayment of an active loan.

Frontend Requests a Loan Repayment

****API ENDPOINT***

The backend will need to get the lender market address from the provided lender name

Params

Type
Name
Description

Number

loanId

The loan ID that is to be repaid

String

lenderName

The name of the lender being targeted

String

tokenAddress

The debt token being repaid

Number

rateMode

The rate mode used to take the loan out

Number

amount

The amount being repaid

Backend Processes Repayment

Step 1: Create Repayment Data

repaymentData = encode(
    [uint256, address, address, uint256, uint256],
    [loanId, marketAddress, tokenAddress, rateMode, amount]
 )
repayData = contract.encodeABI(
    fn_name="repayLender", 
    args=[supplyBytesData, value, userAddress, lender]
)

Step 2: Execute repayLender Function

protocol.execute("LenderModule", 0 ether, repayData, Enum.Operation.Cal)

Backend Processes Loan Update

Step 1: Create Loan Update Data

loanUpdateData = encode(
    [uint256, uint256],
    [1, collateralBalance]
)

Step 2: Create UpdateLoan Fn Bytes

updateFn = contract.encodeABI(
    fn_name="updateLoan",
    args=[loanUpdateInfo, userAddress, uniqueId]
)

Step 3: Execute updateLoanInfo

protocol.execute("LoanBrokerageModule", 0 ether, updateFn, Enum.Operation.Call)

Last updated