Larix
  • Who is Larix
  • Community
  • Roadmap
  • Product Update
  • Monthly Report
    • Larix Monthly Report [Oct]2021
    • Larix Monthly Report [Nov]2021
    • Larix Monthly Report [Dec]2021
    • Larix Monthly Report [Jan ]2022
    • Larix Monthly Report [Feb] 2022
    • Larix Monthly Report [Mar] 2022
    • Larix Monthly Report [April] 2022
    • Larix Monthly Report [May] 2022
  • FAQ
    • General FAQ
    • Raydium LPs FAQ
    • Error Explanation
    • Trouble shooting
    • Liquidation
  • PROTOCOL
    • Mainnet
      • Main Pool
        • Addresses
      • Lending Launchpad
        • Bonfida Pool
        • xSOL Pool
        • LARIX Pool
        • Step Pool
        • Stepn Pool
    • Devnet
  • Larix Guide
    • Step 1: Get Wallet
    • Step 2: Connect Wallet
    • Step 3: Deposit
    • Step 4: Borrow
    • Step 5: Repay
    • Step 6: Withdraw
    • Step 7: Claim rewards
  • Interest Rate Model
  • Mathematics
    • APY
    • Mining
    • Price Feed
    • Obligation Health
  • Function
  • Design and Principle of the Liquidation
  • Access Controls
  • Security
    • Bug Bounty Reward
    • Audit
    • Oracles
  • Tokenomics
    • LARIX
    • Buy LARIX
      • b30LARIX
    • Larix Distribution
    • LARIX Token Distribution Rate Model
  • Risk
    • Risk Framework
    • Asset Risk
    • Liquidity Risk
    • External Audits & Analysis
  • API
    • Instruction
    • Function
    • Query
      • Logo
      • State
      • Reserve
      • Mining
      • Obligation
      • SDK
Powered by GitBook
On this page

Was this helpful?

  1. Mathematics

APY

Annual Percentage Yield

Borrow APY

[IRM(utilization_rate) / slots_per_year + 1] ^ slots_per_year

let slot_interest_rate = current_borrow_rate.try_div(SLOTS_PER_YEAR)?;
let compounded_interest_rate = Rate::one()
     .try_add(slot_interest_rate)?
     .try_pow(slots_elapsed)?;
 self.cumulative_borrow_rate_wads = self
     .cumulative_borrow_rate_wads
     .try_mul(compounded_interest_rate)?;
self.borrowed_amount_wads = self
     .borrowed_amount_wads
     .try_mul(compounded_interest_rate)?;
      Ok(())

Supply APY

(borrow_apy - platform_profit) / (total_borrow / total_supply)

IRM

// Calculate the current borrow rate

    pub fn current_borrow_rate(&self) -> Result<Rate, ProgramError> {

        let utilization_rate = self.liquidity.utilization_rate()?;

        let optimal_utilization_rate = Rate::from_percent(self.config.optimal_utilization_rate);        
        let low_utilization = utilization_rate < optimal_utilization_rate;
        if low_utilization || self.config.optimal_utilization_rate == 100 {
            let normalized_rate = utilization_rate.try_div(optimal_utilization_rate)?
            let min_rate = Rate::from_percent(self.config.min_borrow_rate);
            let rate_range = Rate::from_percent(
                self.config

                    .optimal_borrow_rate

                    .checked_sub(self.config.min_borrow_rate)

                    .ok_or(LendingError::MathOverflow)?,

            );

            Ok(normalized_rate.try_mul(rate_range)?.try_add(min_rate)?)

        } else {

            let normalized_rate = utilization_rate

                .try_sub(optimal_utilization_rate)?

                .try_div(Rate::from_percent(

                    100u8

                        .checked_sub(self.config.optimal_utilization_rate)

                        .ok_or(LendingError::MathOverflow)?,
                ))?;

            let min_rate = Rate::from_percent(self.config.optimal_borrow_rate);

            let rate_range = Rate::from_percent(

                self.config

                    .max_borrow_rate

                    .checked_sub(self.config.optimal_borrow_rate)

                    .ok_or(LendingError::MathOverflow)?,
            );
  
            Ok(normalized_rate.try_mul(rate_range)?.try_add(min_rate)?)
  
         }
  
     }
PreviousMathematicsNextMining

Last updated 3 years ago

Was this helpful?