Borrows
Last updated
Last updated
The information provided by Aloe Labs, Inc. (āwe,ā āusā or āourā) on docs.aloe.capital (the āSiteā) is for general informational purposes only. All information on the Site is provided in good faith, however we make no representation or warranty of any kind, express or implied, regarding the accuracy, adequacy, validity, reliability, availability or completeness of any information on the Site.
Under no circumstance shall we have any liability to you for any loss or damage of any kind incurred as a result of the use of the site or reliance on any information provided on the site. Your use of the site and your reliance on any information on the site is solely at your own risk.
In Aloe II, the Lender
is responsible for tracking borrows. This means two things:
recording the amount each address has borrowed
accounting for the growth of these borrows as interest accrues
The interest compounds continuously, so borrow growth should be modeled with the exponential function:
Since there are no borrows at deployment time, and different users request borrows at different times, is purely hypothetical. When a user takes on some amount of , we must update the hypothetical value:
So when a user calls borrow
, we add to borrows-at-deployment-time, and when a user calls repay
, we do the opposite: subtract from borrows-at-deployment-time. This addition and subtraction applies both to the user's borrows
, and to the pool's total borrowBase
.
We'd be done if r
were constant, but it's notļ¼the interest rate changes with time, as a function of utilization. Instead of an elegant exponential, we get a piecewise function:
borrowIndex *= e ** (currentRate * secondsSinceLastUpdate)
In practice we do change-of-base and implement (1 + yieldPerSecond) ** T
, but the concept is the same.
*In the code, we subtract one from borrows[user]
because the first unit is used for whitelisting; it's not real debt.
The interest rate is a function of utilization, defined in RateModel
. The default RateModel
is a rational function.
The product of this chain of exponentials is the borrowIndex
. For precision, it starts at (instead of 1) and it gets updated in the first call to the pool in a given block. Subsequent calls in the same block do nothing because block.timestamp
is the same. The update looks like:
As for the coefficient, , we scale that up by and call it borrowBase
. Individual users have their own personal borrowBase
s stored in the borrows
mapping (we use the expression for from earlier, but scale up by and divide by borrowIndex
instead of the plain exponential).
Value | Expression |
---|---|
The supply rate (earned by lenders) is always less than the borrow rate (paid by borrowers). Given utilization and reserve factor , they are related like so:
Total Borrows
borrowBase * borrowIndex / (2**32 * 10**12)
User's Borrows*
borrows[user] * borrowIndex / (2**32 * 10**12)