Module 0xd5044d9f4b80910ef7b8910a68d2ac257d14319fb9315ddce1ca5190878bc8ea::default_reserve_interest_rate_strategy

@title Default Reserve Interest Rate Strategy Module @author Aave @notice Default interest rate strategy used by the Aave protocol

use 0x1::event;
use 0x1::signer;
use 0x1::smart_table;
use 0xa888dd108ea636a234c973b8b72b9cadf0c7ae94d6f355c64dde9fdc275724ee::error_config;
use 0xd63343bff7977cb364b17dcdcdeb64e77b7bc9b4ec252f481ace51b6de3bbd96::math_utils;
use 0xd63343bff7977cb364b17dcdcdeb64e77b7bc9b4ec252f481ace51b6de3bbd96::wad_ray_math;

Struct RateDataUpdate

@notice Emitted when new interest rate data is set in a reserve @param reserve Address of the reserve that has new interest rate data set @param optimal_usage_ratio The optimal usage ratio, in bps @param base_variable_borrow_rate The base variable borrow rate, in bps @param variable_rate_slope1 The slope of the variable interest curve, before hitting the optimal ratio, in bps @param variable_rate_slope2 The slope of the variable interest curve, after hitting the optimal ratio, in bps

#[event]
struct RateDataUpdate has drop, store

Struct InterestRateData

@notice Holds the interest rate data for a given reserve @dev Since values are in bps, they are multiplied by 1e23 in order to become rays with 27 decimals. This in turn means that the maximum supported interest rate is 4294967295 (2**32-1) bps or 42949672.95%. @param optimal_usage_ratio The optimal usage ratio, in bps @param base_variable_borrow_rate The base variable borrow rate, in bps @param variable_rate_slope1 The slope of the variable interest curve, before hitting the optimal ratio, in bps @param variable_rate_slope2 The slope of the variable interest curve, after hitting the optimal ratio, in bps

struct InterestRateData has copy, drop, store

Struct InterestRateDataRay

@notice The interest rate data, where all values are in ray (fixed-point 27 decimal numbers) for a given reserve, used in in-memory calculations. @param optimal_usage_ratio The optimal usage ratio @param base_variable_borrow_rate The base variable borrow rate @param variable_rate_slope1 The slope of the variable interest curve, before hitting the optimal ratio @param variable_rate_slope2 The slope of the variable interest curve, after hitting the optimal ratio

struct InterestRateDataRay has drop

Resource ReserveInterestRateStrategyMap

@notice Map of reserves address and their interest rate data (reserve_address => InterestRateData)

struct ReserveInterestRateStrategyMap has key

Struct CalcInterestRatesLocalVars

@notice Local variables for calculating interest rates

struct CalcInterestRatesLocalVars has drop

Constants

@notice The maximum value achievable for variable borrow rate, in bps

const MAX_BORROW_RATE: u256 = 100000;

@notice The maximum optimal point, in bps

const MAX_OPTIMAL_POINT: u256 = 9900;

@notice The minimum optimal point, in bps

const MIN_OPTIMAL_POINT: u256 = 100;

Function get_reserve_interest_rate_strategy

@notice Returns the full InterestRateData object for the given reserve, in ray @param reserve The reserve to get the data of @return The InterestRateDataRay object for the given reserve

#[view]
public fun get_reserve_interest_rate_strategy(reserve: address): default_reserve_interest_rate_strategy::InterestRateDataRay

Function get_reserve_interest_rate_strategy_bps

@notice Returns the full InterestRateDataRay object for the given reserve, in bps @param reserve The reserve to get the data of @return The InterestRateData object for the given reserve

#[view]
public fun get_reserve_interest_rate_strategy_bps(reserve: address): default_reserve_interest_rate_strategy::InterestRateData

Function get_optimal_usage_ratio

@notice Returns the optimal usage rate for the given reserve in ray @param reserve The reserve to get the optimal usage rate of @return The optimal usage rate is the level of borrow / collateral at which the borrow rate

#[view]
public fun get_optimal_usage_ratio(reserve: address): u256

Function get_variable_rate_slope1

@notice Returns the variable rate slope below optimal usage ratio in ray @dev It's the variable rate when usage ratio > 0 and <= OPTIMAL_USAGE_RATIO @param reserve The reserve to get the variable rate slope 1 of @return The variable rate slope

#[view]
public fun get_variable_rate_slope1(reserve: address): u256

Function get_variable_rate_slope2

@notice Returns the variable rate slope above optimal usage ratio in ray @dev It's the variable rate when usage ratio > OPTIMAL_USAGE_RATIO @param reserve The reserve to get the variable rate slope 2 of @return The variable rate slope

#[view]
public fun get_variable_rate_slope2(reserve: address): u256

Function get_base_variable_borrow_rate

@notice Returns the base variable borrow rate, in ray @param reserve The reserve to get the base variable borrow rate of @return The base variable borrow rate

#[view]
public fun get_base_variable_borrow_rate(reserve: address): u256

Function get_max_variable_borrow_rate

@notice Returns the maximum variable borrow rate, in ray @param reserve The reserve to get the maximum variable borrow rate of @return The maximum variable borrow rate

#[view]
public fun get_max_variable_borrow_rate(reserve: address): u256

Function calculate_interest_rates

@notice Calculates the interest rates depending on the reserve's state and configurations @param unbacked The amount of unbacked liquidity @param liquidity_added The amount of liquidity added @param liquidity_taken The amount of liquidity taken @param total_debt The total debt of the reserve @param reserve_factor The reserve factor @param reserve The address of the reserve @param virtual_underlying_balance The virtual underlying balance of the reserve @return current_liquidity_rate The liquidity rate expressed in rays @return current_variable_borrow_rate The variable borrow rate expressed in rays

#[view]
public fun calculate_interest_rates(unbacked: u256, liquidity_added: u256, liquidity_taken: u256, total_debt: u256, reserve_factor: u256, reserve: address, virtual_underlying_balance: u256): (u256, u256)

Function init_interest_rate_strategy

@notice Initializes the interest rate strategy @dev Only callable by the pool_configurator module @param account The signer account of the caller

public(friend) fun init_interest_rate_strategy(account: &signer)

Function set_reserve_interest_rate_strategy

@notice Sets interest rate data for an Aave rate strategy @dev Only callable by the pool_configurator and pool_token_logic module @param reserve The address of the underlying asset of the reserve @param optimal_usage_ratio The optimal usage ratio, in bps @param base_variable_borrow_rate The base variable borrow rate, in bps @param variable_rate_slope1 The slope of the variable interest curve, before hitting the optimal ratio, in bps @param variable_rate_slope2 The slope of the variable interest curve, after hitting the optimal ratio, in bps

public(friend) fun set_reserve_interest_rate_strategy(reserve: address, optimal_usage_ratio: u256, base_variable_borrow_rate: u256, variable_rate_slope1: u256, variable_rate_slope2: u256)