mErc20Host

Git Source

Inherits: mErc20Upgradable, ImErc20Host, ImTokenOperationTypes

State Variables

migrator

address public migrator;

acc

mapping(uint32 => Accumulated) internal acc;

allowedCallers

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

allowedChains

mapping(uint32 => bool) public allowedChains;

verifier

IZkVerifier public verifier;

gasHelper

IGasFeesHelper public gasHelper;

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

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

setGasHelper

Sets the gas fees helper address

function setGasHelper(address _helper) external onlyAdmin;

Parameters

NameTypeDescription
_helperaddressThe new helper address

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

performExtensionCall

Initiates a withdraw operation

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

Parameters

NameTypeDescription
actionTypeuint256The actionType param (1 - withdraw, 2 - borrow)
amountuint256The amount to withdraw
dstChainIduint32The destination chain to recieve funds

mintOrBorrowMigration

Mints mTokens during migration without requiring underlying transfer

function mintOrBorrowMigration(bool mint, uint256 amount, address receiver, address borrower, uint256 minAmount)
    external
    onlyMigrator;

Parameters

NameTypeDescription
mintboolMint or borrow
amountuint256The amount of underlying to be accounted for
receiveraddressThe address that will receive the mTokens or the underlying in case of borrowing
borroweraddressThe address that borrow is executed for
minAmountuint256The min amount of underlying to be accounted for

_onlyAdminOrRole

function _onlyAdminOrRole(bytes32 _role) internal view;

_decodeJournals

function _decodeJournals(bytes calldata data) internal pure returns (bytes[] memory);

_checkOutflow

function _checkOutflow(uint256 amount) internal;

_checkProofCall

function _checkProofCall(uint32 dstChainId, uint32 chainId, address market, address sender) internal view;

_checkSender

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

_getGasFees

function _getGasFees(uint32 dstChain) internal view returns (uint256);

_isAllowedFor

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

_getChainsManagerRole

function _getChainsManagerRole() internal view returns (bytes32);

_getProofForwarderRole

function _getProofForwarderRole() internal view returns (bytes32);

_getBatchProofForwarderRole

function _getBatchProofForwarderRole() internal view returns (bytes32);

_getSequencerRole

function _getSequencerRole() internal view returns (bytes32);

_verifyProof

function _verifyProof(bytes calldata journalData, bytes calldata seal) internal 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;

Structs

Accumulated

struct Accumulated {
    mapping(address => uint256) inPerChain;
    mapping(address => uint256) outPerChain;
}