mTokenGateway

Git Source

Inherits: OwnableUpgradeable, ImTokenGateway, ImTokenOperationTypes, HypernativeFirewallProtected

Title: mTokenGateway

Author: Merge Layers Inc.

Gateway contract for mToken operations

State Variables

LINEA_CHAIN_ID

Linea chain ID

uint32 private constant LINEA_CHAIN_ID = 59144

rolesOperator

Roles

IRoles public rolesOperator

blacklistOperator

Blacklist operator

IBlacklister public blacklistOperator

verifier

The ZkVerifier contract

IZkVerifier public verifier

paused

Mapping of operation types to pause status

mapping(OperationType operationType => bool paused) public paused

underlying

Returns the address of the underlying token

address public underlying

accAmountIn

Mapping of accumulated amounts in

mapping(address account => uint256 amount) public accAmountIn

accAmountOut

Mapping of accumulated amounts out

mapping(address account => uint256 amount) public accAmountOut

allowedCallers

Mapping of allowed callers

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

userWhitelisted

Mapping of whitelisted users

mapping(address user => bool whitelisted) public userWhitelisted

whitelistEnabled

Whether whitelist is enabled

bool public whitelistEnabled

gasFee

Gas fee required for supplyOnHost

uint256 public gasFee

__gap

uint256[50] private __gap

Functions

notPaused

Modifier to restrict access to only allowed users

modifier notPaused(OperationType _type) ;

Parameters

NameTypeDescription
_typeOperationTypeThe operation type

onlyAllowedUser

Modifier to restrict access to only allowed users

modifier onlyAllowedUser(address user) ;

Parameters

NameTypeDescription
useraddressThe user address

ifNotBlacklisted

Modifier to restrict access to only not blacklisted users

modifier ifNotBlacklisted(address user) ;

Parameters

NameTypeDescription
useraddressThe user address

liquidateChecks

Modifier to check liquidate conditions

modifier liquidateChecks() ;

constructor

Disables initializers on implementation

Note: oz-upgrades-unsafe-allow: constructor

constructor() ;

initialize

Initializes the gateway

function initialize(
    address payable _owner,
    address _underlying,
    address _roles,
    address _blacklister,
    address zkVerifier_
) external initializer;

Parameters

NameTypeDescription
_owneraddress payableOwner address
_underlyingaddressUnderlying token
_rolesaddressRoles contract
_blacklisteraddressBlacklister contract
zkVerifier_addressZK verifier

initFirewall

Initializes the firewall configuration

function initFirewall(address _firewall) external onlyOwner;

Parameters

NameTypeDescription
_firewalladdressFirewall address to set

setBlacklister

Sets the blacklister contract

function setBlacklister(address _blacklister) external onlyOwner;

Parameters

NameTypeDescription
_blacklisteraddressAddress of the blacklister

setWhitelistedUser

Sets user whitelist status

function setWhitelistedUser(address user, bool state) external onlyOwner;

Parameters

NameTypeDescription
useraddressThe user address
stateboolThe new state

enableWhitelist

Enable user whitelist

function enableWhitelist() external onlyOwner;

disableWhitelist

Disable user whitelist

function disableWhitelist() external onlyOwner;

setPaused

function setPaused(OperationType _type, bool state) external override;

extractForRebalancing

Extract amount to be used for rebalancing operation

function extractForRebalancing(uint256 amount) external notPaused(OperationType.Rebalancing);

Parameters

NameTypeDescription
amountuint256The amount to rebalance

setGasFee

Sets the gas fee

function setGasFee(uint256 amount) external onlyOwner;

Parameters

NameTypeDescription
amountuint256the new gas fee

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 onlyOwner;

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

supplyOnHost

Supply underlying to the contract

function supplyOnHost(uint256 amount, address receiver, bytes4 lineaSelector)
    external
    payable
    override
    notPaused(OperationType.AmountIn)
    onlyAllowedUser(msg.sender)
    ifNotBlacklisted(msg.sender)
    ifNotBlacklisted(receiver)
    onlyFirewallApproved;

Parameters

NameTypeDescription
amountuint256The supplied amount
receiveraddressThe receiver address
lineaSelectorbytes4The method selector to be called on Linea by our relayer. If empty, user has to submit it

liquidate

Liquidate a user

function liquidate(address userToLiquidate, uint256 liquidateAmount, address collateral, address receiver)
    external
    payable
    override
    liquidateChecks
    ifNotBlacklisted(receiver);

Parameters

NameTypeDescription
userToLiquidateaddressThe user to liquidate
liquidateAmountuint256The amount to liquidate
collateraladdressThe collateral address
receiveraddressThe receiver address

outHere

Extract tokens

function outHere(bytes calldata journalData, bytes calldata seal, uint256[] calldata amounts, address receiver)
    external
    notPaused(OperationType.AmountOutHere)
    ifNotBlacklisted(msg.sender)
    ifNotBlacklisted(receiver)
    onlyFirewallApproved;

Parameters

NameTypeDescription
journalDatabytesThe supplied journal
sealbytesThe seal address
amountsuint256[]The amounts to withdraw for each journal
receiveraddressThe receiver address

isPaused

function isPaused(OperationType _type) external view returns (bool);

getProofData

Returns the proof data journal

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

Parameters

NameTypeDescription
useraddressUser address
<none>uint32

Returns

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

firewallRegister

Registers an account in the firewall

function firewallRegister(address _account) public override(HypernativeFirewallProtected);

Parameters

NameTypeDescription
_accountaddressAccount to register

_takeIn

Handles inbound transfers and accounting

function _takeIn(address asset, uint256 amount, address receiver) private;

Parameters

NameTypeDescription
assetaddressAsset address
amountuint256Amount to transfer
receiveraddressReceiver address

_outHere

Processes an outgoing transfer based on journal data

function _outHere(bytes memory journalData, uint256 amount, address receiver) private;

Parameters

NameTypeDescription
journalDatabytesEncoded journal payload
amountuint256Amount to transfer
receiveraddressReceiver address override

_verifyProof

Verifies proof data and inclusion constraints

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

Parameters

NameTypeDescription
journalDatabytesEncoded journals
sealbytesProof seal data

_checkSender

Validates sender permissions for proof forwarding

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

Parameters

NameTypeDescription
msgSenderaddressCaller address
srcSenderaddressSource sender encoded in journal

_getSequencerRole

Returns sequencer role identifier

function _getSequencerRole() private view returns (bytes32);

Returns

NameTypeDescription
<none>bytes32Role id

_getBatchProofForwarderRole

Returns batch proof forwarder role identifier

function _getBatchProofForwarderRole() private view returns (bytes32);

Returns

NameTypeDescription
<none>bytes32Role id

_getProofForwarderRole

Returns proof forwarder role identifier

function _getProofForwarderRole() private view returns (bytes32);

Returns

NameTypeDescription
<none>bytes32Role id

_isAllowedFor

Checks if sender has a specific role

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

Parameters

NameTypeDescription
_senderaddressSender address
rolebytes32Role to check

Returns

NameTypeDescription
<none>boolTrue if allowed