The MToken contract is an abstract contract that defines the core functionalities for a tokenized lending market. It provides a standard interface for ERC-20 compatible tokens with additional functionalities to support borrowing, lending, and interest accrual. This contract is intended to be inherited by specific token implementations.
The MToken contract depends on the following interfaces and libraries:
- ComptrollerInterface.sol: Interface for the Comptroller contract that controls market operations.
- MTokenInterfaces.sol: Interface for the MToken contract.
- ErrorReporter.sol: Error reporting library for handling errors.
- Exponential.sol: Library for handling fixed-point arithmetic.
- EIP20Interface.sol: Interface for ERC-20 tokens.
- IRModels/InterestRateModel.sol: Interface for the interest rate model.
- transfer: Transfers a specified amount of tokens to a target address.
- transferFrom: Transfers tokens from a source address to a target address on behalf of an approved spender.
- approve: Approves a spender to spend a specific amount of tokens on behalf of the owner.
- allowance: Returns the amount of tokens the spender is allowed to spend on behalf of the owner.
- balanceOf: Returns the balance of tokens for a specific account.
- balanceOfUnderlying: Returns the balance of underlying assets (tokens) for a specific account.
- getAccountSnapshot: Returns various account metrics, including token balance, borrow balance, and exchange rate.
- borrowRatePerTimestamp: Returns the current borrow interest rate per block timestamp.
- supplyRatePerTimestamp: Returns the current supply interest rate per block timestamp.
- totalBorrowsCurrent: Returns the total amount of outstanding borrows after accruing interest.
- borrowBalanceCurrent: Returns the current borrow balance of a specific account after accruing interest.
- borrowBalanceStored: Returns the stored borrow balance of a specific account without accruing interest.
- exchangeRateCurrent: Returns the current exchange rate between the token and underlying assets after accruing interest.
- exchangeRateStored: Returns the stored exchange rate between the token and underlying assets without accruing interest.
- accrueInterest: Accrues interest for the market, updating total borrows, total reserves, and borrow index.
- initialize: Initializes the market with initial parameters. This function can only be called by the contract's admin.
- _setPendingAdmin: External function to set the pending admin of the contract.
- _acceptAdmin: External function to accept the admin role after being nominated as the pending admin.
- _setComptroller: External function to set the Comptroller contract address.
- _setReserveFactor: External function to set the reserve factor for the market.
- _reduceReserves: External function to reduce reserves by a specified amount.
- _setInterestRateModel: External function to set the interest rate model for the market.
- _setProtocolSeizeShare: External function to set the share of seized funds distributed to the protocol.