Build
Architecture
protocol
contracts
evm
GatewayEVM.sol
Contract.gatewayevm

Git Source (opens in a new tab)

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

The GatewayEVM contract is the endpoint to call smart contracts on external chains.

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

custody

The address of the custody contract.

address public custody;

tssAddress

The address of the TSS (Threshold Signature Scheme) contract.

address public tssAddress;

zetaConnector

The address of the ZetaConnector contract.

address public zetaConnector;

zetaToken

The address of the Zeta token contract.

address public zetaToken;

TSS_ROLE

New role identifier for tss role.

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

ASSET_HANDLER_ROLE

New role identifier for asset handler role.

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

PAUSER_ROLE

New role identifier for pauser role.

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

MAX_PAYLOAD_SIZE

Max size of payload + revertOptions revert message.

uint256 public constant MAX_PAYLOAD_SIZE = 1024;

constructor

constructor();

initialize

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

Using admin to authorize upgrades and pause, and tss for tss role.

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

_authorizeUpgrade

Authorizes the upgrade of the contract, sender must be owner.

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

Parameters

NameTypeDescription
newImplementationaddressAddress of the new implementation.

updateTSSAddress

Update tss address

function updateTSSAddress(address newTSSAddress) external onlyRole(DEFAULT_ADMIN_ROLE);

Parameters

NameTypeDescription
newTSSAddressaddressnew tss address

pause

Pause contract.

function pause() external onlyRole(PAUSER_ROLE);

unpause

Unpause contract.

function unpause() external onlyRole(PAUSER_ROLE);

executeRevert

Transfers msg.value to destination contract and executes it's onRevert function.

This function can only be called by the TSS address and it is payable.

function executeRevert(
    address destination,
    bytes calldata data,
    RevertContext calldata revertContext
)
    public
    payable
    onlyRole(TSS_ROLE)
    whenNotPaused
    nonReentrant;

Parameters

NameTypeDescription
destinationaddressAddress to call.
databytesCalldata to pass to the call.
revertContextRevertContext

execute

Executes an authenticated call to a destination address without ERC20 tokens.

This function can only be called by the TSS address and it is payable.

function execute(
    MessageContext calldata messageContext,
    address destination,
    bytes calldata data
)
    external
    payable
    onlyRole(TSS_ROLE)
    whenNotPaused
    nonReentrant
    returns (bytes memory);

Parameters

NameTypeDescription
messageContextMessageContextMessage context containing sender.
destinationaddressAddress to call.
databytesCalldata to pass to the call.

Returns

NameTypeDescription
<none>bytesThe result of the call.

execute

Executes an arbitrary call to a destination address without ERC20 tokens.

This function can only be called by the TSS address and it is payable.

function execute(
    address destination,
    bytes calldata data
)
    external
    payable
    onlyRole(TSS_ROLE)
    whenNotPaused
    returns (bytes memory);

Parameters

NameTypeDescription
destinationaddressAddress to call.
databytesCalldata to pass to the call.

Returns

NameTypeDescription
<none>bytesThe result of the call.

executeWithERC20

Executes a call to a destination contract using ERC20 tokens.

This function can only be called by the custody or connector address. It uses the ERC20 allowance system, resetting gateway allowance at the end.

function executeWithERC20(
    address token,
    address to,
    uint256 amount,
    bytes calldata data
)
    public
    onlyRole(ASSET_HANDLER_ROLE)
    whenNotPaused
    nonReentrant;

Parameters

NameTypeDescription
tokenaddressAddress of the ERC20 token.
toaddressAddress of the contract to call.
amountuint256Amount of tokens to transfer.
databytesCalldata to pass to the call.

revertWithERC20

Directly transfers ERC20 tokens and calls onRevert.

This function can only be called by the custody or connector address.

function revertWithERC20(
    address token,
    address to,
    uint256 amount,
    bytes calldata data,
    RevertContext calldata revertContext
)
    external
    onlyRole(ASSET_HANDLER_ROLE)
    whenNotPaused
    nonReentrant;

Parameters

NameTypeDescription
tokenaddressAddress of the ERC20 token.
toaddressAddress of the contract to call.
amountuint256Amount of tokens to transfer.
databytesCalldata to pass to the call.
revertContextRevertContextRevert context to pass to onRevert.

deposit

Deposits ETH to the TSS address.

function deposit(address receiver, RevertOptions calldata revertOptions) external payable whenNotPaused nonReentrant;

Parameters

NameTypeDescription
receiveraddressAddress of the receiver.
revertOptionsRevertOptionsRevert options.

deposit

Deposits ERC20 tokens to the custody or connector contract.

function deposit(
    address receiver,
    uint256 amount,
    address asset,
    RevertOptions calldata revertOptions
)
    external
    whenNotPaused
    nonReentrant;

Parameters

NameTypeDescription
receiveraddressAddress of the receiver.
amountuint256Amount of tokens to deposit.
assetaddressAddress of the ERC20 token.
revertOptionsRevertOptionsRevert options.

depositAndCall

Deposits ETH to the TSS address and calls an omnichain smart contract.

function depositAndCall(
    address receiver,
    bytes calldata payload,
    RevertOptions calldata revertOptions
)
    external
    payable
    whenNotPaused
    nonReentrant;

Parameters

NameTypeDescription
receiveraddressAddress of the receiver.
payloadbytesCalldata to pass to the call.
revertOptionsRevertOptionsRevert options.

depositAndCall

Deposits ERC20 tokens to the custody or connector contract and calls an omnichain smart contract.

function depositAndCall(
    address receiver,
    uint256 amount,
    address asset,
    bytes calldata payload,
    RevertOptions calldata revertOptions
)
    external
    whenNotPaused
    nonReentrant;

Parameters

NameTypeDescription
receiveraddressAddress of the receiver.
amountuint256Amount of tokens to deposit.
assetaddressAddress of the ERC20 token.
payloadbytesCalldata to pass to the call.
revertOptionsRevertOptionsRevert options.

call

Calls an omnichain smart contract without asset transfer.

function call(
    address receiver,
    bytes calldata payload,
    RevertOptions calldata revertOptions
)
    external
    whenNotPaused
    nonReentrant;

Parameters

NameTypeDescription
receiveraddressAddress of the receiver.
payloadbytesCalldata to pass to the call.
revertOptionsRevertOptionsRevert options.

setCustody

Sets the custody contract address.

function setCustody(address custody_) external onlyRole(DEFAULT_ADMIN_ROLE);

Parameters

NameTypeDescription
custody_addressAddress of the custody contract.

setConnector

Sets the connector contract address.

function setConnector(address zetaConnector_) external onlyRole(DEFAULT_ADMIN_ROLE);

Parameters

NameTypeDescription
zetaConnector_addressAddress of the connector contract.

_resetApproval

Resets the approval of a token for a specified address. This is used to ensure that the approval is set to zero before setting it to a new value.

function _resetApproval(address token, address to) private returns (bool);

Parameters

NameTypeDescription
tokenaddressAddress of the ERC20 token.
toaddressAddress to reset the approval for.

Returns

NameTypeDescription
<none>boolTrue if the approval reset was successful, false otherwise.

_transferFromToAssetHandler

Transfers tokens from the sender to the asset handler. This function handles the transfer of tokens to either the connector or custody contract based on the asset type.

function _transferFromToAssetHandler(address from, address token, uint256 amount) private;

Parameters

NameTypeDescription
fromaddressAddress of the sender.
tokenaddressAddress of the ERC20 token.
amountuint256Amount of tokens to transfer.

_transferToAssetHandler

Transfers tokens to the asset handler. This function handles the transfer of tokens to either the connector or custody contract based on the asset type.

function _transferToAssetHandler(address token, uint256 amount) private;

Parameters

NameTypeDescription
tokenaddressAddress of the ERC20 token.
amountuint256Amount of tokens to transfer.

_executeArbitraryCall

Private function to execute an arbitrary call to a destination address.

function _executeArbitraryCall(address destination, bytes calldata data) private returns (bytes memory);

Parameters

NameTypeDescription
destinationaddressAddress to call.
databytesCalldata to pass to the call.

Returns

NameTypeDescription
<none>bytesThe result of the call.

_executeAuthenticatedCall

Private function to execute an authenticated call to a destination address.

function _executeAuthenticatedCall(
    MessageContext calldata messageContext,
    address destination,
    bytes calldata data
)
    private
    returns (bytes memory);

Parameters

NameTypeDescription
messageContextMessageContextMessage context containing sender and arbitrary call flag.
destinationaddressAddress to call.
databytesCalldata to pass to the call.

Returns

NameTypeDescription
<none>bytesThe result of the call.

_revertIfOnCallOrOnRevert

function _revertIfOnCallOrOnRevert(bytes calldata data) private pure;