Comment on page
Implementation details for developers
The Borrowing module has been coded with some implementation choices which should be known to developers to understand some on-chain data.
In a given vault, two elements are stored:
collateralAmount: the amount of collateral put in the vault
normalizedDebt: a normalized value of the debt
In fact, when someone borrows stablecoins with the Angle Protocol, it's not this amount that is stored but this amount normalized by a quantity called the
interestAccumulatorwhich tracks the evolution of the interest rate in time.
For instance, if at the start the value of the
interestAccumulatoris 1, and there's a 2% interest rate accruing to all vaults, then after a year,
As long as the interest rate is positive, this
When someone borrows
xof stablecoins and the value of the
At any given time, if the value of the
, the value of the debt of this vault is:
, then the debt of this vault which borrowed
xstablecoins increased to
There is nothing obvious with power computation in Solidity and it can rapidly lead to overflows. As such compounding interest rates (like in the formula above) is not that easy.
While Maker uses its own library for interest rates, the solution adopted in Angle Borrowing Module, like Aave in their V2 and V3 is to rely on a third order binomial approximation which works assuming a small interest rate.
This approximation shows up to be quite accurate even for big time frames (like 10 years). It however slightly undercharges borrowers with the advantage of a great gas cost reduction. Interest rates could be set by the protocol with this in mind.