mToken

Git Source

Inherits: mTokenConfiguration, ReentrancyGuard

Functions

constructor

constructor();

_initializeMToken

Initialize the money market

function _initializeMToken(
    address operator_,
    address interestRateModel_,
    uint256 initialExchangeRateMantissa_,
    string memory name_,
    string memory symbol_,
    uint8 decimals_
) internal;

Parameters

NameTypeDescription
operator_addressThe address of the Operator
interestRateModel_addressThe address of the interest rate model
initialExchangeRateMantissa_uint256The initial exchange rate, scaled by 1e18
name_stringEIP-20 name of this token
symbol_stringEIP-20 symbol of this token
decimals_uint8EIP-20 decimal precision of this token

isMToken

function isMToken() external pure override returns (bool);

allowance

Returns the current allowance the spender has from the owner

function allowance(address owner, address spender) external view override returns (uint256);

Parameters

NameTypeDescription
owneraddressThe address of the token holder
spenderaddressThe address authorized to spend the tokens

Returns

NameTypeDescription
<none>uint256The current remaining number of tokens spender can spend

balanceOf

Returns the value of tokens owned by account.

function balanceOf(address owner) external view override returns (uint256);

Parameters

NameTypeDescription
owneraddress

balanceOfUnderlying

Returns the underlying asset balance of the owner

function balanceOfUnderlying(address owner) external override returns (uint256);

Parameters

NameTypeDescription
owneraddressThe address to query the balance of underlying assets for

Returns

NameTypeDescription
<none>uint256The balance of underlying assets owned by owner

getAccountSnapshot

Returns the snapshot of account details for the given account

function getAccountSnapshot(address account) external view override returns (uint256, uint256, uint256);

Parameters

NameTypeDescription
accountaddressThe address to query the account snapshot for

Returns

NameTypeDescription
<none>uint256(token balance, borrow balance, exchange rate)
<none>uint256
<none>uint256

borrowRatePerBlock

Returns the current borrow rate per block

function borrowRatePerBlock() external view override returns (uint256);

Returns

NameTypeDescription
<none>uint256The current borrow rate per block, scaled by 1e18

supplyRatePerBlock

Returns the current supply rate per block

function supplyRatePerBlock() external view override returns (uint256);

Returns

NameTypeDescription
<none>uint256The current supply rate per block, scaled by 1e18

borrowBalanceStored

Returns the stored borrow balance for account, without accruing interest

function borrowBalanceStored(address account) external view override returns (uint256);

Parameters

NameTypeDescription
accountaddressThe address to query the stored borrow balance for

Returns

NameTypeDescription
<none>uint256The stored borrow balance

getCash

Returns the total amount of available cash in the contract

function getCash() external view override returns (uint256);

Returns

NameTypeDescription
<none>uint256The total amount of cash

exchangeRateStored

Returns the stored exchange rate, without accruing interest

function exchangeRateStored() external view override returns (uint256);

Returns

NameTypeDescription
<none>uint256The stored exchange rate

transfer

Transfers amount tokens to the dst address

function transfer(address dst, uint256 amount) external override nonReentrant returns (bool);

Parameters

NameTypeDescription
dstaddressThe address of the recipient
amountuint256The number of tokens to transfer

Returns

NameTypeDescription
<none>boolWhether the transfer was successful or not

transferFrom

Transfers amount tokens from the src address to the dst address

function transferFrom(address src, address dst, uint256 amount) external override nonReentrant returns (bool);

Parameters

NameTypeDescription
srcaddressThe address from which tokens are transferred
dstaddressThe address to which tokens are transferred
amountuint256The number of tokens to transfer

Returns

NameTypeDescription
<none>boolWhether the transfer was successful or not

approve

Approves spender to spend amount tokens on behalf of the caller

function approve(address spender, uint256 amount) external override returns (bool);

Parameters

NameTypeDescription
spenderaddressThe address authorized to spend tokens
amountuint256The number of tokens to approve

Returns

NameTypeDescription
<none>boolWhether the approval was successful or not

totalBorrowsCurrent

Returns the total amount of borrows, accounting for interest

function totalBorrowsCurrent() external override nonReentrant returns (uint256);

Returns

NameTypeDescription
<none>uint256The total amount of borrows

borrowBalanceCurrent

Returns the current borrow balance for account, accounting for interest

function borrowBalanceCurrent(address account) external override nonReentrant returns (uint256);

Parameters

NameTypeDescription
accountaddressThe address to query the borrow balance for

Returns

NameTypeDescription
<none>uint256The current borrow balance

exchangeRateCurrent

Returns the current exchange rate, with interest accrued

function exchangeRateCurrent() public override nonReentrant returns (uint256);

Returns

NameTypeDescription
<none>uint256The current exchange rate

seize

Transfers collateral tokens (this market) to the liquidator.

Will fail unless called by another mToken during the process of liquidation. Its absolutely critical to use msg.sender as the borrowed mToken and not a parameter.

function seize(address liquidator, address borrower, uint256 seizeTokens) external override nonReentrant;

Parameters

NameTypeDescription
liquidatoraddressThe account receiving seized collateral
borroweraddressThe account having collateral seized
seizeTokensuint256The number of mTokens to seize

reduceReserves

Accrues interest and reduces reserves by transferring to admin

function reduceReserves(uint256 reduceAmount) external override nonReentrant;

Parameters

NameTypeDescription
reduceAmountuint256Amount of reduction to reserves

_borrowBalanceStored

Return the borrow balance of account based on stored data

function _borrowBalanceStored(address account) internal view returns (uint256);

Parameters

NameTypeDescription
accountaddressThe address whose balance should be calculated

Returns

NameTypeDescription
<none>uint256(error code, the calculated balance or 0 if error code is non-zero)

_mint

Sender supplies assets into the market and receives mTokens in exchange

Accrues interest whether or not the operation succeeds, unless reverted

function _mint(address user, address receiver, uint256 mintAmount, uint256 minAmountOut, bool doTransfer)
    internal
    nonReentrant;

Parameters

NameTypeDescription
useraddressThe user address
receiveraddress
mintAmountuint256The amount of the underlying asset to supply
minAmountOutuint256The minimum amount to be received
doTransferboolIf an actual transfer should be performed

_redeem

Sender redeems mTokens in exchange for the underlying asset

Accrues interest whether or not the operation succeeds, unless reverted

function _redeem(address user, uint256 redeemTokens, bool doTransfer)
    internal
    nonReentrant
    returns (uint256 underlyingAmount);

Parameters

NameTypeDescription
useraddressThe user address
redeemTokensuint256The number of mTokens to redeem into underlying
doTransferboolIf an actual transfer should be performed

_redeemUnderlying

Sender redeems mTokens in exchange for a specified amount of underlying asset

Accrues interest whether or not the operation succeeds, unless reverted

function _redeemUnderlying(address user, uint256 redeemAmount, bool doTransfer) internal nonReentrant;

Parameters

NameTypeDescription
useraddressThe user address
redeemAmountuint256The amount of underlying to receive from redeeming mTokens
doTransferboolIf an actual transfer should be performed

_borrow

Sender borrows assets from the protocol to their own address

function _borrow(address user, uint256 borrowAmount, bool doTransfer) internal nonReentrant;

Parameters

NameTypeDescription
useraddressThe user address
borrowAmountuint256The amount of the underlying asset to borrow
doTransferboolIf an actual transfer should be performed

_borrowWithReceiver

Sender borrows assets from the protocol to their own address

function _borrowWithReceiver(address user, address receiver, uint256 borrowAmount) internal nonReentrant;

Parameters

NameTypeDescription
useraddressThe user address
receiveraddressThe underlying receiver address
borrowAmountuint256The amount of the underlying asset to borrow

_repay

Sender repays their own borrow

function _repay(uint256 repayAmount, bool doTransfer) internal nonReentrant returns (uint256);

Parameters

NameTypeDescription
repayAmountuint256The amount to repay, or type(uint256).max for the full outstanding amount
doTransferboolIf an actual transfer should be performed

_repayBehalf

Sender repays a borrow belonging to borrower

function _repayBehalf(address borrower, uint256 repayAmount, bool doTransfer) internal nonReentrant returns (uint256);

Parameters

NameTypeDescription
borroweraddressthe account with the debt being payed off
repayAmountuint256The amount to repay, or type(uint256).max for the full outstanding amount
doTransferboolIf an actual transfer should be performed

_liquidate

The sender liquidates the borrowers collateral. The collateral seized is transferred to the liquidator.

function _liquidate(
    address liquidator,
    address borrower,
    uint256 repayAmount,
    address mTokenCollateral,
    bool doTransfer
) internal nonReentrant;

Parameters

NameTypeDescription
liquidatoraddressThe liquidator address
borroweraddressThe borrower of this mToken to be liquidated
repayAmountuint256The amount of the underlying borrowed asset to repay
mTokenCollateraladdressThe market in which to seize collateral from the borrower
doTransferboolIf an actual transfer should be performed

_seize

Transfers collateral tokens (this market) to the liquidator.

Called only during an in-kind liquidation, or by liquidateBorrow during the liquidation of another mToken. Its absolutely critical to use msg.sender as the seizer mToken and not a parameter.

function _seize(address seizerToken, address liquidator, address borrower, uint256 seizeTokens) internal;

Parameters

NameTypeDescription
seizerTokenaddressThe contract seizing the collateral (i.e. borrowed mToken)
liquidatoraddressThe account receiving seized collateral
borroweraddressThe account having collateral seized
seizeTokensuint256The number of mTokens to seize

_addReserves

Accrues interest and reduces reserves by transferring from msg.sender

function _addReserves(uint256 addAmount) internal nonReentrant;

Parameters

NameTypeDescription
addAmountuint256Amount of addition to reserves

__liquidate

The liquidator liquidates the borrowers collateral. The collateral seized is transferred to the liquidator.

function __liquidate(
    address liquidator,
    address borrower,
    uint256 repayAmount,
    address mTokenCollateral,
    bool doTransfer
) internal;

Parameters

NameTypeDescription
liquidatoraddressThe address repaying the borrow and seizing collateral
borroweraddressThe borrower of this mToken to be liquidated
repayAmountuint256The amount of the underlying borrowed asset to repay
mTokenCollateraladdressThe market in which to seize collateral from the borrower
doTransferboolIf an actual transfer should be performed

__repay

Borrows are repaid by another user (possibly the borrower).

function __repay(address payer, address borrower, uint256 repayAmount, bool doTransfer) private returns (uint256);

Parameters

NameTypeDescription
payeraddressthe account paying off the borrow
borroweraddressthe account with the debt being payed off
repayAmountuint256the amount of underlying tokens being returned, or type(uint256).max for the full outstanding amount
doTransferboolIf an actual transfer should be performed

__borrow

Users borrow assets from the protocol to their own address

function __borrow(address payable borrower, address payable receiver, uint256 borrowAmount, bool doTransfer) private;

Parameters

NameTypeDescription
borroweraddress payable
receiveraddress payable
borrowAmountuint256The amount of the underlying asset to borrow
doTransferbool

__redeem

function __redeem(address payable redeemer, uint256 redeemTokensIn, uint256 redeemAmountIn, bool doTransfer)
    private
    returns (uint256 redeemAmount);

__mint

User supplies assets into the market and receives mTokens in exchange

Assumes interest has already been accrued up to the current block

function __mint(address minter, address receiver, uint256 mintAmount, uint256 minAmountOut, bool doTransfer) private;

Parameters

NameTypeDescription
minteraddressThe address of the account which is supplying the assets
receiveraddressThe address of the account which is receiving the assets
mintAmountuint256The amount of the underlying asset to supply
minAmountOutuint256The min amount to be received
doTransferboolIf an actual transfer should be performed

_transferTokens

Transfer tokens tokens from src to dst by spender

Called by both transfer and transferFrom internally

function _transferTokens(address spender, address src, address dst, uint256 tokens) private;

Parameters

NameTypeDescription
spenderaddressThe address of the account performing the transfer
srcaddressThe address of the source account
dstaddressThe address of the destination account
tokensuint256The number of tokens to transfer