ImErc20Host

Git Source

Title: ImErc20Host

Author: Merge Layers Inc.

Interface for host-side mERC20 cross-chain operations

Functions

mintOrBorrowMigration

Mints mTokens during migration without requiring underlying transfer

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

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

extractForRebalancing

Extract amount to be used for rebalancing operation

function extractForRebalancing(uint256 amount) external;

Parameters

NameTypeDescription
amountuint256The amount to rebalance

updateAllowedCallerStatus

Set caller status for msg.sender

function updateAllowedCallerStatus(address caller, bool status) external;

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;

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;

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;

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;

Parameters

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

getProofData

Returns the proof data journal

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

Parameters

NameTypeDescription
useraddressThe user address for the proof
dstIduint32The destination chain identifier

Returns

NameTypeDescription
dataRootuint256The proof data root
journalHashuint256The proof journal hash

Events

AllowedCallerUpdated

Emitted when a user updates allowed callers

event AllowedCallerUpdated(address indexed sender, address indexed caller, bool status);

Parameters

NameTypeDescription
senderaddressThe caller updating permission
calleraddressThe address whose status is updated
statusboolWhether the caller is allowed

mErc20Host_ChainStatusUpdated

Emitted when a chain id whitelist status is updated

event mErc20Host_ChainStatusUpdated(uint32 indexed chainId, bool status);

Parameters

NameTypeDescription
chainIduint32The chain identifier
statusboolWhether the chain is whitelisted

mErc20Host_LiquidateExternal

Emitted when a liquidate operation is executed

event mErc20Host_LiquidateExternal(
    address indexed msgSender,
    address indexed srcSender,
    address userToLiquidate,
    address receiver,
    address indexed collateral,
    uint32 srcChainId,
    uint256 amount
);

Parameters

NameTypeDescription
msgSenderaddressThe caller on host chain
srcSenderaddressThe caller on source chain
userToLiquidateaddressThe user being liquidated
receiveraddressThe receiver of seized collateral
collateraladdressThe collateral market
srcChainIduint32Source chain identifier
amountuint256The repay amount

mErc20Host_MintExternal

Emitted when a mint operation is executed

event mErc20Host_MintExternal(
    address indexed msgSender, address indexed srcSender, address indexed receiver, uint32 chainId, uint256 amount
);

Parameters

NameTypeDescription
msgSenderaddressThe caller on host chain
srcSenderaddressThe caller on source chain
receiveraddressThe receiver of minted tokens
chainIduint32Source chain identifier
amountuint256The mint amount

mErc20Host_BorrowExternal

Emitted when a borrow operation is executed

event mErc20Host_BorrowExternal(
    address indexed msgSender, address indexed srcSender, uint32 indexed chainId, uint256 amount
);

Parameters

NameTypeDescription
msgSenderaddressThe caller on host chain
srcSenderaddressThe caller on source chain
chainIduint32Source chain identifier
amountuint256The borrow amount

mErc20Host_RepayExternal

Emitted when a repay operation is executed

event mErc20Host_RepayExternal(
    address indexed msgSender, address indexed srcSender, address indexed position, uint32 chainId, uint256 amount
);

Parameters

NameTypeDescription
msgSenderaddressThe caller on host chain
srcSenderaddressThe caller on source chain
positionaddressThe position being repaid
chainIduint32Source chain identifier
amountuint256The repay amount

mErc20Host_WithdrawExternal

Emitted when a withdrawal is executed

event mErc20Host_WithdrawExternal(
    address indexed msgSender, address indexed srcSender, uint32 indexed chainId, uint256 amount
);

Parameters

NameTypeDescription
msgSenderaddressThe caller on host chain
srcSenderaddressThe caller on source chain
chainIduint32Source chain identifier
amountuint256The withdrawal amount

mErc20Host_BorrowOnExtensionChain

Emitted when a borrow operation is triggered for an extension chain

event mErc20Host_BorrowOnExtensionChain(address indexed sender, uint32 dstChainId, uint256 amount);

Parameters

NameTypeDescription
senderaddressThe caller initiating the borrow
dstChainIduint32Destination chain identifier
amountuint256The borrow amount

mErc20Host_WithdrawOnExtensionChain

Emitted when a withdraw operation is triggered for an extension chain

event mErc20Host_WithdrawOnExtensionChain(address indexed sender, uint32 dstChainId, uint256 amount);

Parameters

NameTypeDescription
senderaddressThe caller initiating the withdrawal
dstChainIduint32Destination chain identifier
amountuint256The withdrawal amount

mErc20Host_GasFeeUpdated

Emitted when gas fees are updated for a dst chain

event mErc20Host_GasFeeUpdated(uint32 indexed dstChainId, uint256 amount);

Parameters

NameTypeDescription
dstChainIduint32Destination chain identifier
amountuint256The gas fee amount

mErc20Host_MintMigration

Emitted when migration mint is performed

event mErc20Host_MintMigration(address indexed receiver, uint256 amount);

Parameters

NameTypeDescription
receiveraddressReceiver of the migrated tokens
amountuint256Amount minted

mErc20Host_BorrowMigration

Emitted when migration borrow is performed

event mErc20Host_BorrowMigration(address indexed borrower, uint256 amount);

Parameters

NameTypeDescription
borroweraddressBorrower receiving funds
amountuint256Amount borrowed

mErc20Host_MigratorUpdated

Emitted when migrator address is updated

event mErc20Host_MigratorUpdated(address indexed migrator);

Parameters

NameTypeDescription
migratoraddressThe new migrator address

mErc20Host_GasHelperUpdated

Emitted when gas helper address is updated

event mErc20Host_GasHelperUpdated(address indexed helper);

Parameters

NameTypeDescription
helperaddressThe new gas helper address

Errors

mErc20Host_ProofGenerationInputNotValid

Thrown when the chain id is not LINEA

error mErc20Host_ProofGenerationInputNotValid();

mErc20Host_DstChainNotValid

Thrown when the dst chain id is not current chain

error mErc20Host_DstChainNotValid();

mErc20Host_ChainNotValid

Thrown when the chain id is not LINEA

error mErc20Host_ChainNotValid();

mErc20Host_AddressNotValid

Thrown when the address is not valid

error mErc20Host_AddressNotValid();

mErc20Host_AmountTooBig

Thrown when the amount provided is bigger than the available amount`

error mErc20Host_AmountTooBig();

mErc20Host_AmountNotValid

Thrown when the amount specified is invalid (e.g., zero)

error mErc20Host_AmountNotValid();

mErc20Host_JournalNotValid

Thrown when the journal data provided is invalid or corrupted

error mErc20Host_JournalNotValid();

mErc20Host_CallerNotAllowed

Thrown when caller is not allowed

error mErc20Host_CallerNotAllowed();

mErc20Host_NotRebalancer

Thrown when caller is not rebalancer

error mErc20Host_NotRebalancer();

mErc20Host_LengthMismatch

Thrown when length of array is not valid

error mErc20Host_LengthMismatch();

mErc20Host_NotEnoughGasFee

Thrown when not enough gas fee was received

error mErc20Host_NotEnoughGasFee();

mErc20Host_L1InclusionRequired

Thrown when L1 inclusion is required

error mErc20Host_L1InclusionRequired();

mErc20Host_ActionNotAvailable

Thrown when extension action is not valid

error mErc20Host_ActionNotAvailable();