LayerzeroImplementation
Inherits: IAmbImplementation, ILayerZeroUserApplicationConfig, ILayerZeroReceiver
Author: Zeropoint Labs
allows state registries to use Layerzero for crosschain communication
State Variables
RECEIVER_OFFSET
uint256 private constant RECEIVER_OFFSET = 1;
superRegistry
ISuperRegistry public immutable superRegistry;
lzEndpoint
ILayerZeroEndpoint public lzEndpoint;
isValid
prevents layerzero relayer from replaying payload
mapping(uint16 => mapping(uint64 => bool)) public isValid;
ambChainId
mapping(uint64 => uint16) public ambChainId;
superChainId
mapping(uint16 => uint64) public superChainId;
trustedRemoteLookup
mapping(uint16 => bytes) public trustedRemoteLookup;
failedMessages
mapping(uint16 => mapping(bytes => mapping(uint64 => bytes32))) public failedMessages;
Functions
onlyProtocolAdmin
modifier onlyProtocolAdmin();
constructor
constructor(ISuperRegistry superRegistry_);
Parameters
Name | Type | Description |
---|---|---|
superRegistry_ | ISuperRegistry | is the super registry address |
dispatchPayload
allows state registry to send message via implementation.
function dispatchPayload(
address srcSender_,
uint64 dstChainId_,
bytes memory message_,
bytes memory extraData_
)
external
payable
override;
Parameters
Name | Type | Description |
---|---|---|
srcSender_ | address | is the caller (used for gas refunds) |
dstChainId_ | uint64 | is the identifier of the destination chain |
message_ | bytes | is the cross-chain message to be sent |
extraData_ | bytes | is message amb specific override information |
setChainId
allows protocol admin to add new chain ids in future
function setChainId(uint64 superChainId_, uint16 ambChainId_) external onlyProtocolAdmin;
Parameters
Name | Type | Description |
---|---|---|
superChainId_ | uint64 | is the identifier of the chain within superform protocol |
ambChainId_ | uint16 | is the identifier of the chain given by the AMB NOTE: cannot be defined in an interface as types vary for each message bridge (amb) |
_nonblockingLzReceive
reset old mappings
function _nonblockingLzReceive(uint16 _srcChainId, bytes memory, bytes memory _payload) internal;
lzReceive
decodes payload received NOTE: experimental split of registry contracts
function lzReceive(
uint16 srcChainId_,
bytes memory srcAddress_,
uint64 nonce_,
bytes memory payload_
)
public
override;
nonblockingLzReceive
function nonblockingLzReceive(uint16 srcChainId_, bytes memory srcAddress_, bytes memory payload_) public;
retryMessage
function retryMessage(
uint16 srcChainId_,
bytes memory srcAddress_,
uint64 nonce_,
bytes memory payload_
)
public
payable;
_lzSend
function _lzSend(
uint16 dstChainId_,
bytes memory payload_,
address payable refundAddress_,
address zroPaymentAddress_,
bytes memory adapterParams_,
uint256 msgValue_
)
internal;
_blockingLzReceive
function _blockingLzReceive(
uint16 srcChainId_,
bytes memory srcAddress_,
uint64 nonce_,
bytes memory payload_
)
internal;
setLzEndpoint
allows protocol admin to configure layerzero endpoint
function setLzEndpoint(address endpoint_) external onlyProtocolAdmin;
Parameters
Name | Type | Description |
---|---|---|
endpoint_ | address | is the layerzero endpoint on the deployed network |
getConfig
function getConfig(
uint16 version_,
uint16 chainId_,
address,
uint256 configType_
)
external
view
returns (bytes memory);
setConfig
allows protocol admin to configure UA on layerzero
function setConfig(
uint16 version_,
uint16 chainId_,
uint256 configType_,
bytes calldata config_
)
external
override
onlyProtocolAdmin;
setSendVersion
function setSendVersion(uint16 version_) external override onlyProtocolAdmin;
setReceiveVersion
function setReceiveVersion(uint16 version_) external override onlyProtocolAdmin;
forceResumeReceive
function forceResumeReceive(uint16 srcChainId_, bytes calldata srcAddress_) external override onlyProtocolAdmin;
setTrustedRemote
function setTrustedRemote(uint16 srcChainId_, bytes calldata srcAddress_) external onlyProtocolAdmin;
isTrustedRemote
function isTrustedRemote(uint16 srcChainId_, bytes calldata srcAddress_) external view returns (bool);
estimateFees
not all AMBs will have on-chain estimation for which this function will return 0
returns the gas fees estimation in native tokens
function estimateFees(
uint64 dstChainId_,
bytes memory message_,
bytes memory extraData_
)
external
view
override
returns (uint256 fees);
Parameters
Name | Type | Description |
---|---|---|
dstChainId_ | uint64 | is the identifier of the destination chain |
message_ | bytes | is the cross-chain message |
extraData_ | bytes | is any amb-specific information |
Returns
Name | Type | Description |
---|---|---|
fees | uint256 | is the native_tokens to be sent along the transaction |
Events
EndpointUpdated
event EndpointUpdated(address oldEndpoint_, address newEndpoint_);
MessageFailed
event MessageFailed(uint16 srcChainId_, bytes srcAddress_, uint64 nonce_, bytes payload_);
SetTrustedRemote
event SetTrustedRemote(uint16 srcChainId_, bytes srcAddress_);