Build
Architecture
protocol
contracts
zevm
GatewayZEVM.sol
Contract.gatewayzevm

Git Source (opens in a new tab)

Inherits: IGatewayZEVM, Initializable, AccessControlUpgradeable, UUPSUpgradeable, ReentrancyGuardUpgradeable, PausableUpgradeable

The GatewayZEVM contract is the endpoint to call smart contracts on omnichain.

The contract doesn't hold any funds and should never have active allowances.

PROTOCOL_ADDRESS

The constant address of the protocol

address public constant PROTOCOL_ADDRESS = 0x735b14BB79463307AAcBED86DAf3322B1e6226aB;

zetaToken

The address of the Zeta token.

address public zetaToken;

PAUSER_ROLE

New role identifier for pauser role.

bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");

MAX_MESSAGE_SIZE

Max size of message + revertOptions revert message.

uint256 public constant MAX_MESSAGE_SIZE = 1024;

onlyProtocol

Only protocol address allowed modifier.

modifier onlyProtocol();

constructor

constructor();

initialize

Initialize with address of zeta token and admin account set as DEFAULT_ADMIN_ROLE.

Using admin to authorize upgrades and pause.

function initialize(address zetaToken_, address admin_) public initializer;

_authorizeUpgrade

Authorizes the upgrade of the contract.

function _authorizeUpgrade(address newImplementation) internal override onlyRole(DEFAULT_ADMIN_ROLE);

Parameters

NameTypeDescription
newImplementationaddressThe address of the new implementation.

receive

Receive function to receive ZETA from WETH9.withdraw().

receive() external payable whenNotPaused;

pause

Pause contract.

function pause() external onlyRole(PAUSER_ROLE);

unpause

Unpause contract.

function unpause() external onlyRole(PAUSER_ROLE);

_withdrawZRC20

Private function to withdraw ZRC20 tokens.

function _withdrawZRC20(uint256 amount, address zrc20) private returns (uint256);

Parameters

NameTypeDescription
amountuint256The amount of tokens to withdraw.
zrc20addressThe address of the ZRC20 token.

Returns

NameTypeDescription
<none>uint256The gas fee for the withdrawal.

_withdrawZRC20WithGasLimit

Private function to withdraw ZRC20 tokens with gas limit.

function _withdrawZRC20WithGasLimit(uint256 amount, address zrc20, uint256 gasLimit) private returns (uint256);

Parameters

NameTypeDescription
amountuint256The amount of tokens to withdraw.
zrc20addressThe address of the ZRC20 token.
gasLimituint256Gas limit.

Returns

NameTypeDescription
<none>uint256The gas fee for the withdrawal.

_transferZETA

Private function to transfer ZETA tokens.

function _transferZETA(uint256 amount, address to) private;

Parameters

NameTypeDescription
amountuint256The amount of tokens to transfer.
toaddressThe address to transfer the tokens to.

withdraw

Withdraw ZRC20 tokens to an external chain.

function withdraw(
    bytes memory receiver,
    uint256 amount,
    address zrc20,
    RevertOptions calldata revertOptions
)
    external
    nonReentrant
    whenNotPaused;

Parameters

NameTypeDescription
receiverbytesThe receiver address on the external chain.
amountuint256The amount of tokens to withdraw.
zrc20addressThe address of the ZRC20 token.
revertOptionsRevertOptionsRevert options.

withdrawAndCall

Withdraw ZRC20 tokens and call a smart contract on an external chain.

function withdrawAndCall(
    bytes memory receiver,
    uint256 amount,
    address zrc20,
    bytes calldata message,
    uint256 gasLimit,
    RevertOptions calldata revertOptions
)
    external
    nonReentrant
    whenNotPaused;

Parameters

NameTypeDescription
receiverbytesThe receiver address on the external chain.
amountuint256The amount of tokens to withdraw.
zrc20addressThe address of the ZRC20 token.
messagebytesThe calldata to pass to the contract call.
gasLimituint256Gas limit.
revertOptionsRevertOptionsRevert options.

withdrawAndCall

Withdraw ZRC20 tokens and call a smart contract on an external chain.

function withdrawAndCall(
    bytes memory receiver,
    uint256 amount,
    address zrc20,
    bytes calldata message,
    CallOptions calldata callOptions,
    RevertOptions calldata revertOptions
)
    external
    nonReentrant
    whenNotPaused;

Parameters

NameTypeDescription
receiverbytesThe receiver address on the external chain.
amountuint256The amount of tokens to withdraw.
zrc20addressThe address of the ZRC20 token.
messagebytesThe calldata to pass to the contract call.
callOptionsCallOptionsCall options including gas limit and arbirtrary call flag.
revertOptionsRevertOptionsRevert options.

withdraw

Withdraw ZETA tokens to an external chain.

function withdraw(
    bytes memory receiver,
    uint256 amount,
    uint256 chainId,
    RevertOptions calldata revertOptions
)
    external
    nonReentrant
    whenNotPaused;

Parameters

NameTypeDescription
receiverbytesThe receiver address on the external chain.
amountuint256The amount of tokens to withdraw.
chainIduint256
revertOptionsRevertOptionsRevert options.

withdrawAndCall

Withdraw ZETA tokens and call a smart contract on an external chain.

function withdrawAndCall(
    bytes memory receiver,
    uint256 amount,
    uint256 chainId,
    bytes calldata message,
    RevertOptions calldata revertOptions
)
    external
    nonReentrant
    whenNotPaused;

Parameters

NameTypeDescription
receiverbytesThe receiver address on the external chain.
amountuint256The amount of tokens to withdraw.
chainIduint256Chain id of the external chain.
messagebytesThe calldata to pass to the contract call.
revertOptionsRevertOptionsRevert options.

withdrawAndCall

Withdraw ZETA tokens and call a smart contract on an external chain.

function withdrawAndCall(
    bytes memory receiver,
    uint256 amount,
    uint256 chainId,
    bytes calldata message,
    CallOptions calldata callOptions,
    RevertOptions calldata revertOptions
)
    external
    nonReentrant
    whenNotPaused;

Parameters

NameTypeDescription
receiverbytesThe receiver address on the external chain.
amountuint256The amount of tokens to withdraw.
chainIduint256Chain id of the external chain.
messagebytesThe calldata to pass to the contract call.
callOptionsCallOptionsCall options including gas limit and arbirtrary call flag.
revertOptionsRevertOptionsRevert options.

call

Call a smart contract on an external chain without asset transfer.

function call(
    bytes memory receiver,
    address zrc20,
    bytes calldata message,
    CallOptions calldata callOptions,
    RevertOptions calldata revertOptions
)
    external
    nonReentrant
    whenNotPaused;

Parameters

NameTypeDescription
receiverbytesThe receiver address on the external chain.
zrc20addressAddress of zrc20 to pay fees.
messagebytesThe calldata to pass to the contract call.
callOptionsCallOptionsCall options including gas limit and arbirtrary call flag.
revertOptionsRevertOptionsRevert options.

call

Call a smart contract on an external chain without asset transfer.

function call(
    bytes memory receiver,
    address zrc20,
    bytes calldata message,
    uint256 gasLimit,
    RevertOptions calldata revertOptions
)
    external
    nonReentrant
    whenNotPaused;

Parameters

NameTypeDescription
receiverbytesThe receiver address on the external chain.
zrc20addressAddress of zrc20 to pay fees.
messagebytesThe calldata to pass to the contract call.
gasLimituint256Gas limit.
revertOptionsRevertOptionsRevert options.

_call

function _call(
    bytes memory receiver,
    address zrc20,
    bytes calldata message,
    CallOptions memory callOptions,
    RevertOptions memory revertOptions
)
    private;

deposit

Deposit foreign coins into ZRC20.

function deposit(address zrc20, uint256 amount, address target) external onlyProtocol whenNotPaused;

Parameters

NameTypeDescription
zrc20addressThe address of the ZRC20 token.
amountuint256The amount of tokens to deposit.
targetaddressThe target address to receive the deposited tokens.

execute

Execute a user-specified contract on ZEVM.

function execute(
    MessageContext calldata context,
    address zrc20,
    uint256 amount,
    address target,
    bytes calldata message
)
    external
    onlyProtocol
    whenNotPaused;

Parameters

NameTypeDescription
contextMessageContextThe context of the cross-chain call.
zrc20addressThe address of the ZRC20 token.
amountuint256The amount of tokens to transfer.
targetaddressThe target contract to call.
messagebytesThe calldata to pass to the contract call.

depositAndCall

Deposit foreign coins into ZRC20 and call a user-specified contract on ZEVM.

function depositAndCall(
    MessageContext calldata context,
    address zrc20,
    uint256 amount,
    address target,
    bytes calldata message
)
    external
    onlyProtocol
    whenNotPaused;

Parameters

NameTypeDescription
contextMessageContextThe context of the cross-chain call.
zrc20addressThe address of the ZRC20 token.
amountuint256The amount of tokens to transfer.
targetaddressThe target contract to call.
messagebytesThe calldata to pass to the contract call.

depositAndCall

Deposit ZETA and call a user-specified contract on ZEVM.

function depositAndCall(
    MessageContext calldata context,
    uint256 amount,
    address target,
    bytes calldata message
)
    external
    onlyProtocol
    whenNotPaused;

Parameters

NameTypeDescription
contextMessageContextThe context of the cross-chain call.
amountuint256The amount of tokens to transfer.
targetaddressThe target contract to call.
messagebytesThe calldata to pass to the contract call.

executeRevert

Revert a user-specified contract on ZEVM.

function executeRevert(address target, RevertContext calldata revertContext) external onlyProtocol whenNotPaused;

Parameters

NameTypeDescription
targetaddressThe target contract to call.
revertContextRevertContextRevert context to pass to onRevert.

depositAndRevert

Deposit foreign coins into ZRC20 and revert a user-specified contract on ZEVM.

function depositAndRevert(
    address zrc20,
    uint256 amount,
    address target,
    RevertContext calldata revertContext
)
    external
    onlyProtocol
    whenNotPaused;

Parameters

NameTypeDescription
zrc20addressThe address of the ZRC20 token.
amountuint256The amount of tokens to revert.
targetaddressThe target contract to call.
revertContextRevertContextRevert context to pass to onRevert.

ZeroAddress

Error indicating a zero address was provided.

error ZeroAddress();