Rate Recalculation
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.
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.
Last updated