✔️Interest Rate Model
Overview
The Bank contract allows for the use of custom Interest Rate Models (IRMs) to calculate borrow rates for different markets. This feature enables flexible and dynamic interest rate calculations tailored to specific market conditions.
InterestRateModel Interface
Custom IRMs must implement the IInterestRateModel
interface:
solidityCopyinterface IInterestRateModel {
function isIrm() external view returns (bool);
function borrowRate(MarketConfigs memory marketConfigs, Market memory market) external returns (uint256);
function borrowRateView(MarketConfigs memory marketConfigs, Market memory market) external view returns (uint256);
}
Key Functions
isIrm()
: Validates that the contract is a legitimate IRM.borrowRate()
: Calculates and returns the current borrow rate. This function may modify the contract state.borrowRateView()
: Similar toborrowRate()
, but doesn't modify the contract state.
Creating a Custom IRM
To create a custom IRM:
Implement the
IInterestRateModel
interface.Define your interest rate calculation logic in the
borrowRate()
andborrowRateView()
functions.Ensure
isIrm()
returnstrue
.
Example:
solidityCopycontract MyCustomIRM is IInterestRateModel {
using WadMath for uint128;
function isIrm() external pure returns (bool) {
return true;
}
function borrowRateView(MarketConfigs memory, Market memory market) public pure returns (uint256) {
if (market.totalSupplyAssets == 0) return 0;
uint256 utilization = market.totalBorrowAssets.divWadDown(market.totalSupplyAssets);
return utilization / 365 days;
}
function borrowRate(MarketConfigs memory marketConfigs, Market memory market) external pure returns (uint256) {
return borrowRateView(marketConfigs, market);
}
}
Registering and Using a Custom IRM
Deploy your custom IRM contract.
The DAO must register the IRM with the Bank contract using the
registerIrm()
function:solidityCopyfunction registerIrm(address irm, bool isIrm) external onlyOwner;
Once registered, you can use the IRM when creating a new market:
solidityCopyfunction createMarket(MarketConfigs memory marketConfigs) external payable returns (uint256);
Include the address of your registered IRM in the
marketConfigs.irm
field.
Important Notes
Only IRMs registered by the DAO can be used in market creation.
Ensure your IRM calculations are accurate and gas-efficient.
Test your IRM thoroughly before deployment to avoid potential issues in live markets.
The Bank contract will call the IRM's
borrowRate()
function during interest accrual, so make sure it handles all possible market states correctly.
By following these guidelines, you can create and integrate custom Interest Rate Models to suit various market strategies and conditions within the Bank ecosystem.
Last updated