LzApp

Inherits: Auth, ILayerZeroReceiver, ILayerZeroUserApplicationConfig

SPDX-License-Identifier: SSPL-1.-0

State Variables

DEFAULT_PAYLOAD_SIZE_LIMIT

uint256 public constant DEFAULT_PAYLOAD_SIZE_LIMIT = 10_000;

lzEndpoint

ILayerZeroEndpoint public immutable lzEndpoint;

trustedRemoteLookup

mapping(uint16 => bytes) public trustedRemoteLookup;

minDstGasLookup

mapping(uint16 => mapping(uint16 => uint256)) public minDstGasLookup;

payloadSizeLimitLookup

mapping(uint16 => uint256) public payloadSizeLimitLookup;

precrime

address public precrime;

Functions

constructor

constructor(address authority, address _endpoint) Auth(authority);

lzReceive

function lzReceive(uint16 _srcChainId, bytes calldata _srcAddress, uint64 _nonce, bytes calldata _payload) public virtual override;

_blockingLzReceive

This function is used to receive a payload from a different chain.

This function is used to receive a payload from a different chain. It is triggered when a payload is sent from a different chain. The payload is stored in the _payload parameter. The _srcChainId parameter is used to identify the chain the payload is coming from. The _srcAddress parameter is used to identify the address the payload is coming from. The _nonce parameter is used to identify the payload.

function _blockingLzReceive(uint16 _srcChainId, bytes memory _srcAddress, uint64 _nonce, bytes memory _payload) internal virtual;

_lzSend

function _lzSend(
    uint16 _dstChainId,
    bytes memory _payload,
    address payable _refundAddress,
    address _zroPaymentAddress,
    bytes memory _adapterParams,
    uint256 _nativeFee
)
    internal
    virtual;

_checkGasLimit

function _checkGasLimit(uint16 _dstChainId, uint16 _type, bytes memory _adapterParams, uint256 _extraGas) internal view virtual;

_getGasLimit

This function is used to get the gas limit from the adapter parameters.

The function requires the adapter parameters to be at least 34 bytes long. If the adapter parameters are shorter than 34 bytes, the function will revert with an InvalidAdapterParams error. The gas limit is then loaded from the memory address of the adapter parameters plus 34 bytes.

function _getGasLimit(bytes memory _adapterParams) internal pure virtual returns (uint256 gasLimit);

_checkPayloadSize

function _checkPayloadSize(uint16 _dstChainId, uint256 _payloadSize) internal view virtual;

getConfig

getConfig() is a function that retrieves the configuration data from the lzEndpoint.

getConfig() takes in four parameters: _version, _chainId, address, and _configType. It returns a bytes memory.

function getConfig(uint16 _version, uint16 _chainId, address, uint256 _configType) external view returns (bytes memory);

setConfig

This function is used to set the configuration of the contract.

This function is only accessible to the admin of the contract. It takes in four parameters: _version, _chainId, _configType, and _config. The _version and _chainId parameters are used to identify the version and chainId of the contract. The _configType parameter is used to specify the type of configuration being set. The _config parameter is used to pass in the configuration data. The lzEndpoint.setConfig() function is then called to set the configuration.

function setConfig(uint16 _version, uint16 _chainId, uint256 _configType, bytes calldata _config) external override onlyAdmin;

setSendVersion

This function allows an admin to set the send version of the lzEndpoint.

This function is only available to admins and will override any existing send version.

function setSendVersion(uint16 _version) external override onlyAdmin;

Parameters

NameTypeDescription
_versionuint16The version of the lzEndpoint to be set.

setReceiveVersion

This function sets the receive version of the lzEndpoint.

This function is only available to the admin and is used to set the receive version of the lzEndpoint.

function setReceiveVersion(uint16 _version) external override onlyAdmin;

Parameters

NameTypeDescription
_versionuint16The version to set the lzEndpoint to.

forceResumeReceive

function forceResumeReceive(uint16 _srcChainId, bytes calldata _srcAddress) external override onlyAdmin;

setTrustedRemote

This function allows an admin to set a trusted remote chain.

This function sets a trusted remote chain by taking in a chain ID and a path. It then stores the path in the trustedRemoteLookup mapping and emits an event.

function setTrustedRemote(uint16 _remoteChainId, bytes calldata _path) external onlyAdmin;

setTrustedRemoteAddress

function setTrustedRemoteAddress(uint16 _remoteChainId, bytes calldata _remoteAddress) external onlyAdmin;

getTrustedRemoteAddress

getTrustedRemoteAddress() retrieves the trusted remote address for a given chain ID.

The function reverts if no trusted path is found for the given chain ID. The last 20 bytes of the path should be address(this).

function getTrustedRemoteAddress(uint16 _remoteChainId) external view returns (bytes memory);

setPrecrime

This function allows an admin to set the address of the Precrime contract.

This function sets the address of the Precrime contract and emits an event.

function setPrecrime(address _precrime) external onlyAdmin;

setMinDstGas

Sets the minimum gas for a packet type on a destination chain.

function setMinDstGas(uint16 _dstChainId, uint16 _packetType, uint256 _minGas) external onlyAdmin;

Parameters

NameTypeDescription
_dstChainIduint16The ID of the destination chain.
_packetTypeuint16The type of packet.
_minGasuint256The minimum gas for the packet type.

setPayloadSizeLimit

This function sets the payload size limit for a given destination chain.

This function is only callable by the admin and sets the payload size limit for a given destination chain.

function setPayloadSizeLimit(uint16 _dstChainId, uint256 _size) external onlyAdmin;

isTrustedRemote

function isTrustedRemote(uint16 _srcChainId, bytes calldata _srcAddress) external view returns (bool);

Events

SetPrecrime

event SetPrecrime(address precrime);

SetTrustedRemote

event SetTrustedRemote(uint16 _remoteChainId, bytes _path);

SetTrustedRemoteAddress

event SetTrustedRemoteAddress(uint16 _remoteChainId, bytes _remoteAddress);

SetMinDstGas

event SetMinDstGas(uint16 _dstChainId, uint16 _type, uint256 _minDstGas);

Errors

NoTrustedPath

error NoTrustedPath();

InvalidEndpointCaller

error InvalidEndpointCaller();

DestinationChainNotTrusted

error DestinationChainNotTrusted();

MinGasLimitNotSet

error MinGasLimitNotSet();

GasLimitTooLow

error GasLimitTooLow();

InvalidAdapterParams

error InvalidAdapterParams();

PayloadSizeTooLarge

error PayloadSizeTooLarge();

InvalidMinGas

error InvalidMinGas();

InvalidSourceSendingContract

error InvalidSourceSendingContract();