APY
Annual Percentage Yield

Borrow APY

[IRM(utilization_rate) / slots_per_year + 1] ^ slots_per_year
1
let slot_interest_rate = current_borrow_rate.try_div(SLOTS_PER_YEAR)?;
2
let compounded_interest_rate = Rate::one()
3
.try_add(slot_interest_rate)?
4
.try_pow(slots_elapsed)?;
5
self.cumulative_borrow_rate_wads = self
6
.cumulative_borrow_rate_wads
7
.try_mul(compounded_interest_rate)?;
8
self.borrowed_amount_wads = self
9
.borrowed_amount_wads
10
.try_mul(compounded_interest_rate)?;
11
Ok(())
Copied!
Supply APY
(borrow_apy - platform_profit) / (total_borrow / total_supply)
IRM
1
// Calculate the current borrow rate
2
pub fn current_borrow_rate(&self) -> Result<Rate, ProgramError> {
3
let utilization_rate = self.liquidity.utilization_rate()?;
4
let optimal_utilization_rate = Rate::from_percent(self.config.optimal_utilization_rate);
5
let low_utilization = utilization_rate < optimal_utilization_rate;
6
if low_utilization || self.config.optimal_utilization_rate == 100 {
7
let normalized_rate = utilization_rate.try_div(optimal_utilization_rate)?
8
let min_rate = Rate::from_percent(self.config.min_borrow_rate);
9
let rate_range = Rate::from_percent(
10
self.config
11
.optimal_borrow_rate
12
.checked_sub(self.config.min_borrow_rate)
13
.ok_or(LendingError::MathOverflow)?,
14
);
15
Ok(normalized_rate.try_mul(rate_range)?.try_add(min_rate)?)
16
} else {
17
let normalized_rate = utilization_rate
18
.try_sub(optimal_utilization_rate)?
19
.try_div(Rate::from_percent(
20
100u8
21
.checked_sub(self.config.optimal_utilization_rate)
22
.ok_or(LendingError::MathOverflow)?,
23
))?;
24
let min_rate = Rate::from_percent(self.config.optimal_borrow_rate);
25
let rate_range = Rate::from_percent(
26
self.config
27
.max_borrow_rate
28
.checked_sub(self.config.optimal_borrow_rate)
29
.ok_or(LendingError::MathOverflow)?,
30
);
31
32
Ok(normalized_rate.try_mul(rate_range)?.try_add(min_rate)?)
33
}
34
}
Copied!
Last modified 4mo ago
Copy link