š¬Implementation Details
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.
Debt Tracking
In a given vault, two elements are stored:
collateralAmount
: the amount of collateral put in the vaultnormalizedDebt
: 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 interestAccumulator
which tracks the evolution of the interest rate in time.
For instance, if at the start the value of the interestAccumulator
is 1, and there's a 2% interest rate accruing to all vaults, then after a year, interestAccumulator
is 1.02.
As long as the interest rate is positive, this interestAccumulator
increases indefinitely.
When someone borrows x
of stablecoins and the value of the interestAccumulator
is :
At any given time, if the value of the interestAccumulator
is , the value of the debt of this vault is:
If and , then the debt of this vault which borrowed x
stablecoins increased to .
Interest Rate Computing
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.
Last updated