Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions src/rateModels/EarnerRateModel.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { IEarnerRateModel } from "./interfaces/IEarnerRateModel.sol";

/**
* @title Earner Rate Model contract set in TTG (Two Token Governance) Registrar and accessed by MToken.
* @author M^0 Labs
* @author M0 Labs
*/
contract EarnerRateModel is IEarnerRateModel {
/* ============ Variables ============ */
Expand Down Expand Up @@ -64,14 +64,21 @@ contract EarnerRateModel is IEarnerRateModel {

/// @inheritdoc IRateModel
function rate() external view returns (uint256) {
uint256 earnerRate_ = maxRate();
uint32 minterRate_ = IMinterGateway(minterGateway).minterRate();
uint240 totalActiveOwedM_ = IMinterGateway(minterGateway).totalActiveOwedM();

// If there are no active minters or minter rate is zero, do not accrue yield to earners.
if (totalActiveOwedM_ == 0 || minterRate_ == 0) return 0;

// NOTE: if `earnerRate` <= `minterRate` and there are no deactivated minters with outstanding balance,
// it is safe to return `earnerRate` as the effective rate.
if (earnerRate_ <= minterRate_ && IMinterGateway(minterGateway).totalInactiveOwedM() == 0) return earnerRate_;

return
UIntMath.min256(
maxRate(),
getExtraSafeEarnerRate(
IMinterGateway(minterGateway).totalActiveOwedM(),
IMToken(mToken).totalEarningSupply(),
IMinterGateway(minterGateway).minterRate()
)
earnerRate_,
getExtraSafeEarnerRate(totalActiveOwedM_, IMToken(mToken).totalEarningSupply(), minterRate_)
);
}

Expand Down