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

Interest Accumulation

Interest accumulation on a reserve updates the indexes that tracks the accumulated interest. This operation mutates the Reserve Indexes based on the rates inside Reserve Data and the time that have passed since the last Reserve Indexes mutation.

**'Internal' Inputs:**
- `reserve_indexes`: mutable reference to `ReserveIndexes
- `reserve_data`: reference to `ReserveData` struct
**'External' Inputs:**
- `timestamp`: actual block timestamp

**Pseudocode:**

1. Calculate `delta_timestamp`- time that passed since last accumulation
    as the difference between `timestamp` and `self.update_timestamp`.
    
2. If `delta_timestamp` is 0 then accumulation was already performed in this block,
    return.
    
3. If `reserve_data.current_deposit_rate_e18` is not 0 
    and `reserve_data.total_deposit` is not 0 then:
        update the reserve_indexes.deposit_index_e18 by multiplying it by
        ( 1 + reserve_data.current_deposit_rate_e18 * delta_timestamp / 10^18)
        round in such way that the result is not greater than the "precise result".
        
4. If `reserve_data.current_debt_rate_e18` is not 0
    and `reserve_data.total_debt` is not 0 then:
        update the reserve_indexes.debt_index_e18 by multiplying it by
        ( 1 + reserve_data.current_debt_rate_e18 * delta_timestamp / 10^18)
        round in such way that the result is not smaller than the "precise result".
        
5. Update `reserve_indexes.update_timestamp` to the value of `timestamp`.
PreviousCalculationsNextAccount Interest Accumulation

Last updated 1 year ago