LayerzeroV2Implementation

Introduction

This contract is used to allow Superform to send messages via LayerZeroV2.

Core Concepts

LayerzeroV2Implementation builds upon AMBImplementation to formalize certain methods specific to LayerzeroV2. The biggest differences towards LayerzeroV1 is the unordered message delivery, which offers the highest possible message throughput, only limited by the chain itself. You can read more on this here.

Trusted Remotes

Trusted remotes establish a secure connection between the LayerzeroV2Implementation on source chain and the LayerzeroV2Implementation on destination chain. They are configured by the LayerzeroV2Implementation contract on the LZendpoint which validates it upon sending and receiving payloads. You can read more on Trusted Remotes here.

Receiving payloads

LayerzeroV2 attempts to call lzReceive function on Superform's LayerzeroV2Implementation contract after the successfully validation of a message at the bridge end. Upon delivery, certain mandatory input validations are made by the lzReceive function.

lzReceive

Receives a payload from the LayerzeroV2 endpoint and forwards it to the appropriate state registry by decoding the payload header. The lzReceive function can only be called by the LayerZero endpoint and each nonce_ can only be used once.

function lzReceive(
        Origin calldata origin_,
        bytes32 guid_,
        bytes calldata message_,
        address executor_,
        bytes calldata extraData_
) public;
namedescription

origin_

A struct containing information about where the packet came from.

guid_

A global unique identifier for tracking the packet.

message_

The cross-chain message send by the srcAddress_ from srcChainId_

executor_

Parameter is ignored

extraData_

Parameter is ignored

Retrying Payloads

As mentioned in the AMB Implementations section, messages can be retried by calling retryPayload with a bytes hash of relevant data. In the case of LayerzeroV2, the data is the following:

(Origin memory origin, address receiver, bytes32 guid, bytes memory message, bytes memory extraData)Configuration Setters

There are multiple bridge related configurations to be made on the LayerzeroV2Implementation contract. These configuration functions are gate kept and can only be called by addresses with PROTOCOL_ADMIN_ROLE

setChainId

Each messaging bridge uses their own chain identifiers, different than the blockchain's native chain identifier (a uint256 value). Hence a mapping is introduced to map the chain id of the bridge to Superform protocol's internal chain ids.

function setChainId(uint64 superChainId_, uint16 ambChainId_) external
namedescription

superChainId_

internal chain id used by the Superform protocol. block.chainid casted to uint64

ambChainId_

uint16 chain id allocated to each chain by LayerzeroV2

setLzEndpoint

This setter function updates / sets the LayerzeroV2 endpoint contract. The LayerzeroV2 endpoint is where cross-chain messages are sent/received by LayerzeroV2Implementation

function setLzEndpoint(address endpoint_) external
namedescription

endpoint_

the address of the LayerzeroV2's endpoint contract

setPeer

function setPeer(
   uint32 eid_,
   bytes32 peer_
) external override onlyProtocolAdmin
namedescription

eid_

The endpoint ID

peer_

The address of the peer to be associated with the corresponding endpoint

setDelegate

function setDelegate(
   address delegate_
) external override onlyProtocolAdmin
namedescription

delegate_

The layerzerov2 delegate

Last updated