Abax Documentation
  • 🧮Meet Abax!
    • Overview
    • Glossary
  • Lending
    • Collateral & Borrowing
    • Health Factor
    • Market Rules
    • Interest Rate Model
    • Liquidation
      • Liquidation Formula
    • Protocol Fee
  • Tokenomics
    • Abax Token
    • Public Contribution
    • Promotional Campaigns
  • How to Use Abax
    • How to Start Using Abax?
    • How Can I Make a Deposit?
    • How Do I Withdraw?
    • How Can I Borrow?
    • How Do I Repay Debt?
  • Governance
    • Governance System
  • Contracts
    • Lending Protocol
      • Lending Pool
        • Messages
          • Lending Pool Actions
          • Lending Pool Flash
          • Lending Pool Maintain
          • Lending Pool Manage
          • Lending Pool View
          • A Token Interface
          • V Token Interface
        • Storage
          • Types
          • Structs
        • Calculations
          • Interest Accumulation
          • Account Interest Accumulation
          • Rate Recalculation
          • Calculate Lending Power
        • Errors
    • Abax DAO
Powered by GitBook
On this page
  1. Contracts
  2. Lending Protocol
  3. Lending Pool
  4. Calculations

Rate Recalculation

PreviousAccount Interest AccumulationNextCalculate Lending Power

Last updated 10 months ago

The interest rates are calculated based on the total_deposit, total_debt, and Interest Rate Model. The Interest Rate Model is a vector of function parameters that maps reserve utilization rate into the debt rate.

Reserve utilization rate is a quotient of total_debt by total_deposit.

R(M,U)={100ā‹…M[1]ā‹…U/68U∈[0,0.68),M[1]+100(M[2]āˆ’M[1])(Uāˆ’0.68)/16U∈[0.68,0.84),M[2]+100(M[3]āˆ’M[2])(Uāˆ’0.84)/8U∈[0.84,0.92),M[3]+100(M[4]āˆ’M[3])(Uāˆ’0.92)/4U∈[0.92,0.96),M[4]+100(M[5]āˆ’M[4])(Uāˆ’0.96)/2U∈[0.96,0.98),M[5]+100(M[6]āˆ’M[5])(Uāˆ’0.98)U∈[0.98,0.99),M[6]+100(M[7]āˆ’M[6])(Uāˆ’0.99)U∈[0.99,1),M[7]ā‹…UU∈[1,āˆž).\begin{equation} { R(M,U) = \begin{cases} 100 \cdot M[1] \cdot U/68 & U \in [0, 0.68), \\ M[1] + 100(M[2]-M[1])(U - 0.68) / 16 & U \in [0.68, 0.84), \\ M[2] + 100(M[3]-M[2])(U - 0.84) / 8 & U \in [0.84, 0.92), \\ M[3] + 100(M[4]-M[3])(U - 0.92) / 4 & U \in [0.92, 0.96), \\ M[4] + 100(M[5]-M[4])(U - 0.96) / 2& U \in [0.96, 0.98), \\ M[5] + 100(M[6]-M[5])(U - 0.98) & U \in [0.98, 0.99), \\ M[6] + 100(M[7]-M[6])(U - 0.99) & U \in [0.99, 1), \\ M[7] \cdot U & U \in [1, \infty ). \\ \end{cases}} \end{equation}R(M,U)=āŽ©āŽØāŽ§ā€‹100ā‹…M[1]ā‹…U/68M[1]+100(M[2]āˆ’M[1])(Uāˆ’0.68)/16M[2]+100(M[3]āˆ’M[2])(Uāˆ’0.84)/8M[3]+100(M[4]āˆ’M[3])(Uāˆ’0.92)/4M[4]+100(M[5]āˆ’M[4])(Uāˆ’0.96)/2M[5]+100(M[6]āˆ’M[5])(Uāˆ’0.98)M[6]+100(M[7]āˆ’M[6])(Uāˆ’0.99)M[7]ā‹…U​U∈[0,0.68),U∈[0.68,0.84),U∈[0.84,0.92),U∈[0.92,0.96),U∈[0.96,0.98),U∈[0.98,0.99),U∈[0.99,1),U∈[1,āˆž).​​​

The debt_rate is given by the function R(M,U) where U is an utilization rate and M is Interest Rate Model (counting vector entries from 1). The function is a piece-wise linear function that reaches the M[1], M[2], ..., M[7] at the ends of the intervals.

**Inputs:**
- `reserve_data`: mutable reference to `ReserveData` struct
- `interest_rate_model`: array reference of u64 with length 7 
    representing interest rate model

**Pseudocode:**
1. If `reserve_data.total_debt` is 0:
    a. Set `reserve_data.current_debt_rate_e18` to 0.
    b. Set `reserve_data.current_deposit_rate_e18` to 0.
    c. Return.
2. Calculate `utilization_rate_e6` =
    10^6 * `reserve_data.total_debt` / 'reserve_data.total_deposit'.
    round in such way that the result is not lesser than the "precise result".
    
3. Calculate `reserve_data.current_debt_rate_e18` using 
    `utilization_rate_to_interest_rate_e18` function.
4. If `reserve_data.total_deposit` is not 0 then:
    a. Calculate `reserve_data.current_deposit_rate_e18` = 
        reserve_data.total_debt * reserve_data.current_debt_rate_e18 /
        reserve_data.total_deposit.
    round in such way that the result is not greater than the "precise result".
   else, set `self.current_deposit_rate_e18` to 0.