Borrow
The borrow flow allows the protocol to take a loan against collateral on behalf of a user.
User Requests Loan on Supplied Collateral
**********API ENDPOINT HERE**********
Params
Bytes
borrowData
The borrow data for the lender
Number
value
Ether value being sent (0 if none)
String
userAddress
The address of the user requesting loan
String
lenderName
The name of the lender
String
debtToken
The users desired debt token
Number
rateMode
The rate mode to be utilized by the lender
Backend sends request to pricing/risk engine
The backend will send required params to the backend risk engine. This will allow the Pricing engine to output a foreclosure price. These parameters are then used to execute smart contract functions.
Backend Retrieves Lender Data
Given the lender name, and the users position information (From the previous Supply calls) The backend will retrieve pertinent borrow (loan) data. The backend will then forward this information in the next section.
Backend Forwards Pricing Data to User (With Lender Data)
The backend will forward the pricing data generated to the frontend for verification by the user
APR
LTV (From Lender)
Foreclosure price
Foreclosure Penalty
Number
apr
The APR offered by the lender
Number
lenderLtv
The LTV that the lender calculates
Number
foreclosurePrice
The price in which the loan will be foreclosed
Number
foreclosurePenalty
The penalty levied against the user in the event of a foreclosure
User elects to take out loan
The user reviews the above data, then elects to take the loan.
****API ENDPOINT****
The frontend will call the API endpoint. The backend will then execute the appropriate smart contract function calls.
Backend Executes Smart Contract Calls
Step 1: Create Borrow Data
borrowData = encode(
[string, string, uint256, uint256, string],
[lenderAddress, debtToken, amount, rateMode, userAddress]
)
Step 2: Create Module Data
borrowFn = contract.encodeABI(
fn_name="borrowFromLender",
args=[borrowData, 0 ether, userAddress, lenderName]
)
Step 3: Execute borrowFromLender Function
protocol.execute("LenderModule", 0 ether, borrowFn, Enum.Operation.Call);
Add Borrow Data to Loan Token
Step 1: Create Borrow Data
borrowData = encode (
[address, uint256],
[debtToken, amount]
)
Step 2: Create Loan Data
loanData = encode(
[uint256, uint256],
[1, *CollateralBalance]
)
Step 3: Create Function Call Data
addBorrowToLoanFn = contract.encodeABI(
fn_name="addBorrowToLoan"
args=[borrowData, userAddress, uniqueId, loanData]
)
Step 2: Execute addBorrowtoLoan
protocol.execute("LoanBrokerageModule", 0 ether, addBorrowToLoanFn, EnumOperation.Call)
Last updated