MToken

Git Source

Inherits: IMToken, ContinuousIndexing, ERC20Extended

Author: M^0 Labs

ERC20 M Token.

State Variables

minterGateway

The address of the Minter Gateway contract.

address public immutable minterGateway;

ttgRegistrar

The address of the TTG Registrar contract.

address public immutable ttgRegistrar;

totalNonEarningSupply

The total non-earning supply of M Token.

uint240 public totalNonEarningSupply;

principalOfTotalEarningSupply

The principal of the total earning supply of M Token.

uint112 public principalOfTotalEarningSupply;

_balances

The balance of M for non-earner or principal of earning M balance for earners.

mapping(address account => MBalance balance) internal _balances;

Functions

onlyMinterGateway

Modifier to check if caller is Minter Gateway.

modifier onlyMinterGateway();

constructor

Constructs the M Token contract.

constructor(address ttgRegistrar_, address minterGateway_) ContinuousIndexing() ERC20Extended("M by M^0", "M", 6);

Parameters

NameTypeDescription

ttgRegistrar_

address

The address of the TTG Registrar contract.

minterGateway_

address

The address of Minter Gateway.

mint

Mints tokens.

function mint(address account_, uint256 amount_) external onlyMinterGateway;

Parameters

NameTypeDescription

account_

address

amount_

uint256

burn

Burns tokens.

function burn(address account_, uint256 amount_) external onlyMinterGateway;

Parameters

NameTypeDescription

account_

address

amount_

uint256

startEarning

Starts earning for caller if allowed by TTG.

function startEarning() external;

stopEarning

Stops earning for caller.

function stopEarning() external;

stopEarning

Stops earning for caller.

function stopEarning(address account_) external;

rateModel

The address of TTG approved earner rate model.

function rateModel() public view returns (address rateModel_);

earnerRate

The current value of earner rate in basis points.

function earnerRate() public view returns (uint32 earnerRate_);

totalEarningSupply

The total earning supply of M Token.

function totalEarningSupply() public view returns (uint240 totalEarningSupply_);

totalSupply

Returns the amount of tokens in existence.

function totalSupply() external view returns (uint256 totalSupply_);

principalBalanceOf

The principal of an earner M token balance.

function principalBalanceOf(address account_) external view returns (uint240 balance_);

Parameters

NameTypeDescription

account_

address

Returns

NameTypeDescription

balance_

uint240

The principal balance of the account.

balanceOf

Returns the amount of tokens owned by account.

function balanceOf(address account_) external view returns (uint256 balance_);

isEarning

Checks if account is an earner.

function isEarning(address account_) external view returns (bool isEarning_);

Parameters

NameTypeDescription

account_

address

Returns

NameTypeDescription

isEarning_

bool

True if account is an earner, false otherwise.

currentIndex

The current index that would be written to storage if updateIndex is called.

function currentIndex() public view override(ContinuousIndexing, IContinuousIndexing) returns (uint128);

_addEarningAmount

Adds principal to _balances of an earning account.

function _addEarningAmount(address account_, uint112 principalAmount_) internal;

Parameters

NameTypeDescription

account_

address

The account to add principal to.

principalAmount_

uint112

The principal amount to add.

_addNonEarningAmount

Adds amount to _balances of a non-earning account.

function _addNonEarningAmount(address account_, uint240 amount_) internal;

Parameters

NameTypeDescription

account_

address

The account to add amount to.

amount_

uint240

The amount to add.

_burn

Burns amount of earning or non-earning M from account.

function _burn(address account_, uint256 amount_) internal;

Parameters

NameTypeDescription

account_

address

The account to burn from.

amount_

uint256

The present amount to burn.

_mint

Mints amount of earning or non-earning M to account.

function _mint(address recipient_, uint256 amount_) internal;

Parameters

NameTypeDescription

recipient_

address

The account to mint to.

amount_

uint256

The present amount to mint.

_startEarning

Starts earning for account.

function _startEarning(address account_) internal;

Parameters

NameTypeDescription

account_

address

The account to start earning for.

_stopEarning

Stops earning for account.

function _stopEarning(address account_) internal;

Parameters

NameTypeDescription

account_

address

The account to stop earning for.

_subtractEarningAmount

Subtracts principal from _balances of an earning account.

function _subtractEarningAmount(address account_, uint112 principalAmount_) internal;

Parameters

NameTypeDescription

account_

address

The account to subtract principal from.

principalAmount_

uint112

The principal amount to subtract.

_subtractNonEarningAmount

Subtracts amount from _balances of a non-earning account.

function _subtractNonEarningAmount(address account_, uint240 amount_) internal;

Parameters

NameTypeDescription

account_

address

The account to subtract amount from.

amount_

uint240

The amount to subtract.

_transfer

Transfer M between both earning and non-earning accounts.

function _transfer(address sender_, address recipient_, uint256 amount_) internal override;

Parameters

NameTypeDescription

sender_

address

The account to transfer from. It can be either earning or non-earning account.

recipient_

address

The account to transfer to. It can be either earning or non-earning account.

amount_

uint256

The present amount to transfer.

_transferAmountInKind

Transfer M between same earning status accounts.

function _transferAmountInKind(address sender_, address recipient_, uint240 amount_) internal;

Parameters

NameTypeDescription

sender_

address

The account to transfer from.

recipient_

address

The account to transfer to.

amount_

uint240

The amount (present or principal) to transfer.

_getPresentAmount

Returns the present amount (rounded down) given the principal amount, using the current index. All present amounts are rounded down in favor of the protocol.

function _getPresentAmount(uint112 principalAmount_) internal view returns (uint240);

Parameters

NameTypeDescription

principalAmount_

uint112

The principal amount.

Returns

NameTypeDescription

<none>

uint240

The present amount.

_getPresentAmount

Returns the present amount (rounded down) given the principal amount and an index. All present amounts are rounded down in favor of the protocol, since they are assets.

function _getPresentAmount(uint112 principalAmount_, uint128 index_) internal pure returns (uint240);

Parameters

NameTypeDescription

principalAmount_

uint112

The principal amount.

index_

uint128

An index

Returns

NameTypeDescription

<none>

uint240

The present amount.

_isApprovedEarner

Checks if earner was approved by TTG.

function _isApprovedEarner(address account_) internal view returns (bool);

Parameters

NameTypeDescription

account_

address

The account to check.

Returns

NameTypeDescription

<none>

bool

True if approved, false otherwise.

_rate

Gets the current earner rate from TTG approved rate model contract.

function _rate() internal view override returns (uint32 rate_);

Returns

NameTypeDescription

rate_

uint32

The current earner rate.

_revertIfInsufficientAmount

Reverts if the amount of a mint or burn is equal to 0.

function _revertIfInsufficientAmount(uint256 amount_) internal pure;

Parameters

NameTypeDescription

amount_

uint256

Amount to check.

_revertIfInvalidRecipient

Reverts if the recipient of a mint or transfer is address(0).

function _revertIfInvalidRecipient(address recipient_) internal pure;

Parameters

NameTypeDescription

recipient_

address

Address of the recipient to check.

Structs

MBalance

MToken balance struct.

struct MBalance {
    bool isEarning;
    uint240 rawBalance;
}

Properties

NameTypeDescription

isEarning

bool

True if the account is earning, false otherwise.

rawBalance

uint240

Balance (for a non earning account) or balance principal (for an earning account).

Copyright 2024 M^0 Foundation