Index Synchronization with $M token
The MinterGateway
and the MToken
contract both utilize a continuous indexing mechanism to track the accrual of interest – for Minter debt in MinterGateway
and for earner balances in MToken
. It is crucial that these indices are synchronized.
Synchronization Mechanism
The MinterGateway
ensures that whenever its own interest index for Minter obligations is updated, the MToken
's earning index is also updated simultaneously. This is achieved within the MinterGateway.updateIndex()
function:
function updateIndex() public override(IContinuousIndexing, ContinuousIndexing) returns (uint128 index_) {
uint240 excessOwedM_ = excessOwedM();
if (excessOwedM_ > 0) IMToken(mToken).mint(ttgVault, excessOwedM_); // Mint excess to TTG Vault
// First, update the MinterGateway's own index and rate (for minter debt)
index_ = super.updateIndex();
// Then, explicitly trigger an update of the MToken's index and rate (for earner yield)
IMToken(mToken).updateIndex();
// Emit an event if this MinterGateway instance is also the MToken's MinterGateway
// (This is relevant if MToken directly calls this contract for its own updates)
if (address(this) == IMToken(mToken).minterGateway()) {
emit MTokenIndexUpdated(IMToken(mToken).currentIndex(), IMToken(mToken).currentRate());
}
}
This synchronized update ensures that the calculation of interest paid by Minters and yield distributed to Earners remains consistent and balanced across the protocol, reflecting the latest rates and system state.
Triggers for Index Updates
The updateIndex()
function in MinterGateway
(which in turn calls MToken.updateIndex()
) is invoked during several key operations, ensuring indices are frequently updated:
- When a Minter updates their collateral via
updateCollateral()
. - When $M tokens are minted via
mintM()
. - When $M tokens are burned via
burnM()
. - When a Minter is deactivated via
deactivateMinter()
. - When
MinterGateway.updateIndex()
is explicitly called by an external party.
This frequent synchronization is vital for the accurate accounting of debts, yields, and the overall economic stability of the M0 Protocol.