Borrowing Flow
Borrowing Flow
User Borrows an Asset: A user who has supplied collateral can initiate a borrow by calling
borrow(asset, amount, interestRateMode, referralCode, onBehalfOf)
on the LendingPool. The protocol first checks the user’s borrowing power by summing the value of the user’s collateral deposits and comparing it against current and new debt using the asset’s loan-to-value (LTV) ratios and the oracle prices. TheValidationLogic.validateBorrow
ensures the new borrow won’t exceed the user’s allowed credit or push the health factor below 1. If the borrow is valid, the reserve’s state is updated: accrued interest is added to indexes (updateState()
), and the user’s chosen rate mode is handled.Stable vs Variable Rate Selection: The
interestRateMode
parameter lets the borrower choose a stable rate loan or a variable rate loan. If a stable rate is requested, the LendingPool will fetch the current stable borrow rate for the asset (which is influenced by a stable rate oracle and the reserve’s configuration). That rate is locked in for the user at borrow time (though the protocol can re-balance or update stable rates if certain conditions change drastically). If variable rate is chosen, the user’s interest will fluctuate based on the ongoing variable rate (which can change with utilization). In either case, the LendingPool mints debt tokens to represent the debt: for stable, it callsStableDebtToken.mint()
which records the user’s loan with the fixed rate; for variable, it callsVariableDebtToken.mint()
with the current variable index. The boolean return from these functions indicates if this is a new borrowing position for the user (first time borrowing this asset); if so, the user’s configuration is updated to mark that they have a debt in this reserve.Loan Funds Delivered: After updating debt records, the LendingPool adjusts the reserve’s interest rates because liquidity has been taken out (liquidity decreases, utilization increases). It calls
reserve.updateInterestRates(asset, aToken, 0, amountBorrowed)
to apply a “liquidityTaken” change. This will typically raise the borrow APRs and deposit APY for that asset given the higher utilization. Finally, ifreleaseUnderlying
is true (normal case), the LendingPool instructs the aToken contract to transfer the borrowed underlying asset to the user’s address (the borrower). The user now receives the borrowed funds in their wallet, and an eventBorrow
is emitted logging the details (asset, amount, rate mode, interest rate, etc.).During the Loan – Interest Accrual: As time passes, the borrower’s debt grows according to the interest rate. For a variable loan, the variable borrow index for that reserve will increase each second based on the variable borrow rate; the borrower’s
VariableDebtToken
balance effectively accrues interest. For a stable loan, interest accrual is tracked separately (the stable rate is added to the total debt but the token balance might remain nominally the same – the difference is accounted when repaying). The reserve’scurrentVariableBorrowRate
andcurrentStableBorrowRate
are continuously updated on any liquidity events. The LendingPool’s accounting ensures interest is accrued to the system: e.g., when any user interacts,updateState()
will calculate interest on all outstanding variable debt using a linear interest formula since last update and update the debt index. This accumulated interest is factored into the pool’s liquidity index and the debt token indexes so that neither lenders nor the protocol lose track of the accruing interest.Rewards Accrual for Borrower: Borrowers can also be incentivized with PRFI rewards. In PrimeFi, the debt tokens can be configured as reward-bearing “pools” just like aTokens. If the PrimeFi team enabled incentives for borrowing, the
ChefIncentivesController
will also track balances of stable and variable debt tokens. When the user took the loan, the corresponding debt token contract would trigger the incentive controller’s update hook (similar to aToken) to record the user’s new debt balance for rewards. This means the borrower could earn PRFI for maintaining an active loan (this is a tool to encourage borrowing activity or certain assets’ utilization). The reward calculation uses the same formula (user’s debt amount as share of that debt token’s total supply). Not all markets or modes may be rewarded equally – allocation points can differ – but the system has the flexibility to reward both sides of the market. The rationale is to bootstrap liquidity: sometimes protocols reward borrowers to encourage demand on the platform. If the borrower closes the loan, the debt tokens are burned and the incentive controller updates their reward accrual one final time.
Last updated