mErc20Host

Git Source

Inherits: mErc20Upgradable, ImErc20Host, ImTokenOperationTypes

Title: mErc20Host

Author: Merge Layers Inc.

Host contract for mErc20 tokens

State Variables

acc

Mapping of chain IDs to accumulated amounts

mapping(uint32 chainId => Accumulated accumulated) internal acc

allowedCallers

Mapping of allowed callers

mapping(address caller => mapping(address target => bool allowed)) public allowedCallers

allowedChains

Mapping of allowed chains

mapping(uint32 chainId => bool allowed) public allowedChains

verifier

The ZkVerifier contract

IZkVerifier public verifier

gasHelper

The gas fees helper contract

IGasFeesHelper public gasHelper

migrator

Migrator address

address public migrator

__gap

uint256[50] private __gap

Functions

onlyMigrator

Modifier to restrict access to migrator only

modifier onlyMigrator() ;

initialize

Initializes the new money market

function initialize(
    address underlying_,
    address operator_,
    address interestRateModel_,
    uint256 initialExchangeRateMantissa_,
    // note: these have to remain as 'memory' to avoid stack-depth issues
    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_addressThe IRoles address

updateAllowedChain

Updates an allowed chain status

function updateAllowedChain(uint32 _chainId, bool status_) external;

Parameters

NameTypeDescription
_chainIduint32the chain id
status_boolthe 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 isMint, uint256 amount, address receiver, address borrower, uint256 minAmount)
    external
    onlyMigrator;

Parameters

NameTypeDescription
isMintbool
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

getProofData

Returns the proof data journal

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

Parameters

NameTypeDescription
useraddressThe user address for the proof
dstIduint32The destination chain identifier

Returns

NameTypeDescription
<none>uint256dataRoot The proof data root
<none>uint256journalHash The proof journal hash

_liquidateExternal

Processes a single liquidateExternal call from decoded journal

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

Parameters

NameTypeDescription
singleJournalbytesEncoded journal entry
userToLiquidateaddressAccount to be liquidated
liquidateAmountuint256Amount to liquidate
collateraladdressCollateral address to seize
receiveraddressReceiver of seized collateral

_mintExternal

Processes a single mintExternal call from decoded journal

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

Parameters

NameTypeDescription
singleJournalbytesEncoded journal entry
mintAmountuint256Amount to mint
minAmountOutuint256Minimum amount out allowed
receiveraddressReceiver address

_repayExternal

Processes a single repayExternal call from decoded journal

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

Parameters

NameTypeDescription
singleJournalbytesEncoded journal entry
repayAmountuint256Amount to repay
receiveraddressReceiver address

_checkOutflow

Validates outflow limits via defender

function _checkOutflow(uint256 amount) internal;

Parameters

NameTypeDescription
amountuint256Amount to check

_onlyAdminOrRole

Ensures caller is admin or has specific role

function _onlyAdminOrRole(bytes32 _role) internal view;

Parameters

NameTypeDescription
_rolebytes32Role identifier to check

_checkJournalData

Performs basic proof call checks

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

Parameters

NameTypeDescription
dstChainIduint32Destination chain id
chainIduint32Source chain id
marketaddressMarket address encoded in proof
senderaddressSender extracted from proof

_isAllowedFor

Checks if sender has specified role

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

Parameters

NameTypeDescription
_senderaddressAddress to check
rolebytes32Role identifier

Returns

NameTypeDescription
<none>boolTrue if allowed

_getChainsManagerRole

Retrieves chains manager role id

function _getChainsManagerRole() internal view returns (bytes32);

Returns

NameTypeDescription
<none>bytes32Role identifier

_getProofForwarderRole

Retrieves proof forwarder role id

function _getProofForwarderRole() internal view returns (bytes32);

Returns

NameTypeDescription
<none>bytes32Role identifier

_getBatchProofForwarderRole

Retrieves batch proof forwarder role id

function _getBatchProofForwarderRole() internal view returns (bytes32);

Returns

NameTypeDescription
<none>bytes32Role identifier

_getSequencerRole

Retrieves sequencer role id

function _getSequencerRole() internal view returns (bytes32);

Returns

NameTypeDescription
<none>bytes32Role identifier

_verifyProof

Verifies proof data and checks inclusion constraints

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

Parameters

NameTypeDescription
journalDatabytesEncoded journal data
sealbytesZk proof seal

_decodeJournals

Decodes encoded journals data

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

Parameters

NameTypeDescription
databytesEncoded journal data

Returns

NameTypeDescription
<none>bytes[]Decoded journals array

Structs

Accumulated

Struct for accumulated amounts per chain

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