LogoLogo
  • āš’ļøIntroduction
  • Overview
    • šŸ“–Public Repositories
    • ā›“ļøSmart Contracts Addresses
      • ā›“ļøMainnet
      • 🟣Polygon
      • šŸ”“Optimism
      • šŸ”µArbitrum
      • šŸ•øļøOther Sidechains and L2s
  • Developer Guides
    • šŸ’±Using Transmuter
    • šŸ’øIntegrating Savings Contracts
    • ⚔Flash Loans
    • šŸ¶Liquidations in the Borrowing Module
    • 🌻Auto-Leverage and Capital-Efficiency in the Borrowing Module
  • Tools
    • šŸ”ŒAPI - Accessing Angle Data
  • Governance and Cross-Module Contracts
    • āš–ļøAgToken - Stablecoin Contracts
    • šŸ›£ļøRouter - Combining Protocol Interactions
    • šŸ’«FlashAngle - Instant AgToken liquidity
    • šŸ’—CoreBorrow - Access Control Manager
    • šŸ—³ļøANGLE and veANGLE - Governance Token
  • Borrowing Module Contracts
    • šŸ”œArchitecture Overview
    • šŸ“€Smart Contracts Docs
      • šŸ¦VaultManager - Borrowing AgTokens
      • šŸ‘®Treasury - Stablecoin Accounting
      • šŸ”±Oracles - Getting Price Feeds
      • šŸ—”ļøSettlement - Closing VaultManager contracts
      • šŸ’±Swapper - Helper for Liquidations and Auto-Leverage
    • šŸ”¬Implementation Details
Powered by GitBook
On this page
  • Debt Tracking
  • Interest Rate Computing

Was this helpful?

  1. Borrowing Module Contracts

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 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 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 IRt1IR_{t_1}IRt1​​:

normalizedDebt=xIRt1\texttt{normalizedDebt} = \frac{x}{IR_{t_1}}normalizedDebt=IRt1​​x​

At any given time, if the value of the interestAccumulator is IRt2IR_{t_2}IRt2​​, the value of the debt of this vault is:

debt=normalizedDebtƗIRt2=xƗIRt2IRt1\texttt{debt} = \texttt{normalizedDebt} \times IR_{t_2} = \frac{x\times IR_{t_2}}{IR_{t_1}}debt=normalizedDebtƗIRt2​​=IRt1​​xƗIRt2​​​

If IRt1=1IR_{t_1} = 1IRt1​​=1 and IRt2=1.02IR_{t_2} = 1.02IRt2​​=1.02, then the debt of this vault which borrowed x stablecoins increased to 1.02Ɨx1.02 \times x1.02Ɨx.

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.

(1+r)Ī”tā‰ˆ1+Ī”tr+12Ī”t(Ī”tāˆ’1)r2+16Ī”t(Ī”tāˆ’1)(Ī”tāˆ’2)r3(1+r)^{\Delta_t} \approx 1 + \Delta_tr+\frac{1}{2} \Delta_t(\Delta_t - 1)r^2+\frac{1}{6} \Delta_t(\Delta_t - 1)(\Delta_t - 2)r^3(1+r)Ī”tā€‹ā‰ˆ1+Ī”t​r+21​Δt​(Ī”tā€‹āˆ’1)r2+61​Δt​(Ī”tā€‹āˆ’1)(Ī”tā€‹āˆ’2)r3

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.

PreviousSwapper - Helper for Liquidations and Auto-Leverage

Last updated 3 years ago

Was this helpful?

šŸ”¬