mErc20Host

Git Source

Inherits: mErc20Upgradable, ImErc20Host, ImTokenOperationTypes

State Variables

FLASH_MINT_CALLBACK_SUCCESS

bytes4 private constant FLASH_MINT_CALLBACK_SUCCESS = bytes4(keccak256("onFlashMint(address,uint256,bytes)"));

migrator

address public migrator;

accAmountInPerChain

mapping(uint32 => mapping(address => uint256)) public accAmountInPerChain;

accAmountOutPerChain

mapping(uint32 => mapping(address => uint256)) public accAmountOutPerChain;

allowedCallers

mapping(address => mapping(address => bool)) public allowedCallers;

allowedChains

mapping(uint32 => bool) public allowedChains;

gasFees

mapping(uint32 => uint256) public gasFees;

verifier

IZkVerifier public verifier;

Functions

onlyMigrator

modifier onlyMigrator();

initialize

Initializes the new money market

function initialize(
    address underlying_,
    address operator_,
    address interestRateModel_,
    uint256 initialExchangeRateMantissa_,
    string memory name_,
    string memory symbol_,
    uint8 decimals_,
    address payable admin_,
    address zkVerifier_,
    address roles_
) external initializer;

Parameters

NameTypeDescription
underlying_addressThe address of the underlying asset
operator_addressThe address of the Operator
interestRateModel_addressThe address of the interest rate model
initialExchangeRateMantissa_uint256The initial exchange rate, scaled by 1e18
name_stringERC-20 name of this token
symbol_stringERC-20 symbol of this token
decimals_uint8ERC-20 decimal precision of this token
admin_address payableAddress of the administrator of this token
zkVerifier_addressThe IZkVerifier address
roles_address

isCallerAllowed

Returns if a caller is allowed for sender

function isCallerAllowed(address sender, address caller) external view returns (bool);

getProofData

Returns the proof data journal

function getProofData(address user, uint32 dstId) external view returns (uint256, uint256);

updateAllowedChain

Updates an allowed chain status

function updateAllowedChain(uint32 _chainId, bool _status) external;

Parameters

NameTypeDescription
_chainIduint32the chain id
_statusboolthe new status

extractForRebalancing

Extract amount to be used for rebalancing operation

function extractForRebalancing(uint256 amount) external;

Parameters

NameTypeDescription
amountuint256The amount to rebalance

setMigrator

Sets the migrator address

function setMigrator(address _migrator) external onlyAdmin;

Parameters

NameTypeDescription
_migratoraddressThe new migrator address

setGasFee

Sets the gas fee

function setGasFee(uint32 dstChainId, uint256 amount) external onlyAdmin;

Parameters

NameTypeDescription
dstChainIduint32the destination chain id
amountuint256the gas fee amount

withdrawGasFees

Withdraw gas received so far

function withdrawGasFees(address payable receiver) external;

Parameters

NameTypeDescription
receiveraddress payablethe receiver address

updateZkVerifier

Updates IZkVerifier address

function updateZkVerifier(address _zkVerifier) external onlyAdmin;

Parameters

NameTypeDescription
_zkVerifieraddressthe verifier address

updateAllowedCallerStatus

Set caller status for msg.sender

function updateAllowedCallerStatus(address caller, bool status) external override;

Parameters

NameTypeDescription
calleraddressThe caller address
statusboolThe status to set for caller

liquidateExternal

Mints tokens after external verification

function liquidateExternal(
    bytes calldata journalData,
    bytes calldata seal,
    address[] calldata userToLiquidate,
    uint256[] calldata liquidateAmount,
    address[] calldata collateral,
    address receiver
) external override;

Parameters

NameTypeDescription
journalDatabytesThe journal data for minting (array of encoded journals)
sealbytesThe Zk proof seal
userToLiquidateaddress[]Array of positions to liquidate
liquidateAmountuint256[]Array of amounts to liquidate
collateraladdress[]Array of collaterals to seize
receiveraddressThe collateral receiver

mintExternal

Mints tokens after external verification

function mintExternal(
    bytes calldata journalData,
    bytes calldata seal,
    uint256[] calldata mintAmount,
    uint256[] calldata minAmountsOut,
    address receiver
) external override;

Parameters

NameTypeDescription
journalDatabytesThe journal data for minting (array of encoded journals)
sealbytesThe Zk proof seal
mintAmountuint256[]Array of amounts to mint
minAmountsOutuint256[]Array of min amounts accepted
receiveraddressThe tokens receiver

repayExternal

Repays tokens after external verification

function repayExternal(
    bytes calldata journalData,
    bytes calldata seal,
    uint256[] calldata repayAmount,
    address receiver
) external override;

Parameters

NameTypeDescription
journalDatabytesThe journal data for repayment (array of encoded journals)
sealbytesThe Zk proof seal
repayAmountuint256[]Array of amounts to repay
receiveraddressThe position to repay for

withdrawOnExtension

Initiates a withdraw operation

amount represents the number of mTokens to redeem

function withdrawOnExtension(uint256 amount, uint32 dstChainId) external payable override;

Parameters

NameTypeDescription
amountuint256The amount to withdraw
dstChainIduint32The destination chain to recieve funds

borrowOnExtension

Initiates a withdraw operation

function borrowOnExtension(uint256 amount, uint32 dstChainId) external payable override;

Parameters

NameTypeDescription
amountuint256The amount to withdraw
dstChainIduint32The destination chain to recieve funds

mintMigration

Mints mTokens during migration without requiring underlying transfer

function mintMigration(uint256 amount, uint256 minAmount, address receiver) external onlyMigrator;

Parameters

NameTypeDescription
amountuint256The amount of underlying to be accounted for
minAmountuint256The min amount of underlying to be accounted for
receiveraddressThe address that will receive the mTokens

borrowMigration

Borrows from market for a specific borrower and not msg.sender

function borrowMigration(uint256 amount, address borrower, address receiver) external onlyMigrator;

Parameters

NameTypeDescription
amountuint256The amount of underlying to be accounted for
borroweraddressThe address that borrow is executed for
receiveraddress

_computeTotalOutflowAmount

function _computeTotalOutflowAmount(uint256[] calldata amounts) private pure returns (uint256);

_checkOutflow

function _checkOutflow(uint256 amount) private;

_isAllowedFor

function _isAllowedFor(address _sender, bytes32 role) private view returns (bool);

_getProofForwarderRole

function _getProofForwarderRole() private view returns (bytes32);

_getBatchProofForwarderRole

function _getBatchProofForwarderRole() private view returns (bytes32);

_getSequencerRole

function _getSequencerRole() private view returns (bytes32);

_verifyProof

function _verifyProof(bytes calldata journalData, bytes calldata seal) private view;

_checkSender

function _checkSender(address msgSender, address srcSender) private view;

_liquidateExternal

function _liquidateExternal(
    bytes memory singleJournal,
    address userToLiquidate,
    uint256 liquidateAmount,
    address collateral,
    address receiver
) internal;

_mintExternal

function _mintExternal(bytes memory singleJournal, uint256 mintAmount, uint256 minAmountOut, address receiver)
    internal;

_repayExternal

function _repayExternal(bytes memory singleJournal, uint256 repayAmount, address receiver) internal;