Interest rate

The loan interest rate is an Annual Percentage Rate (APR) paid by the borrower for the period of the loan.

The getInterestRates function sets the interest rate for borrowing money, making it cheaper when there's a lot of money available and more expensive when funds are running low.

Interest rates are calculated for the borrowed amount (loanAmount). Where taking a loan of 1,000 ADA will have a lower interest rate than taking a loan of 100,000 ADA (if taken from the same pool).

The loan interest rate is fixed for every loan and does not change for as long as the loan exists.

getInterestRates()


Parameters

  • loanAmount: The amount to be loaned.

  • lentOut: The total amount already loaned out by the system.

  • balance: The total amount of funds in the system.


Constants

Constants are protocol-set values to ensure a fluent lending/borrowing experience.

  • optimalUtilizationBN: Optimal rate at which the system should be loaning out funds.

  • baseInterestRateBN: The minimum interest rate to be charged.

  • rslope1BN and rslope2BN: Rates at which interest increases.

const optimalUtilizationRate = 45%
const baseInterestRate = 3%
const rslope1BN = 7.5%
const rslope2BN = 300%

Utilization Rate

  • Formula: (loanAmount + lentOut) / (balance + lentOut)

  • Purpose: It measures how much of the available balance is being loaned out.


Interest Rate Calculation

  1. If Utilization Rate ≤ Optimal Utilization Rate

    • Formula: baseInterestRateBN + (utilizationRateBN * rslope1BN)

  2. If Utilization Rate > Optimal Utilization Rate

    • Formula: A more complicated formula involving both rslope1BN and rslope2BN is used to calculate the interest rate.


export function getInterestRates(
  interestParams: InterestParams,
  loanAmount: bigint,
  lentOut: bigint,
  balance: bigint,
): bigint {

  const optimalUtilizationBN = new BigNumber(Number(interestParams.optimalUtilization))
  const baseInterestRateBN = new BigNumber(Number(BigInt(interestParams.baseInterestRate) * 1000000n))
  const rslope1BN = new BigNumber(Number(interestParams.rslope1))
  const rslope2BN = new BigNumber(Number(interestParams.rslope2))
  const oneMillionBN = new BigNumber(1000000)
  const loanAmountBN = new BigNumber(Number(loanAmount))
  const lentOutBN = new BigNumber(Number(lentOut))
  const balanceBN = new BigNumber(Number(balance))

  const utilizationRateBN = new BigNumber(
    lentOutBN.plus(loanAmountBN).multipliedBy(oneMillionBN).dividedBy(balanceBN.plus(lentOutBN)),
  )

  if (utilizationRateBN.lte(optimalUtilizationBN)) {
    const utilizationCharge = utilizationRateBN.multipliedBy(rslope1BN)

    const interestRate = BigInt(Math.floor(baseInterestRateBN.plus(utilizationCharge).dividedBy(1000000).toNumber()))

    return interestRate
  } else {
    const lowCharge = rslope1BN.multipliedBy(optimalUtilizationBN)
    const highCharge = utilizationRateBN.minus(optimalUtilizationBN).multipliedBy(rslope2BN)

    return BigInt(Math.floor(Number(baseInterestRateBN.plus(lowCharge).plus(highCharge).dividedBy(1000000).toNumber())))
  }
}

Last updated