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)?)
}
}
Last modified 7mo ago
Copy link