@layerzerolabs/lz-evm-protocol-v2 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/artifacts/contracts/EndpointV2.sol/EndpointV2.json +2364 -0
  2. package/artifacts/contracts/EndpointV2Alt.sol/EndpointV2Alt.json +2379 -0
  3. package/artifacts/contracts/MessageLibManager.sol/MessageLibManager.json +783 -0
  4. package/artifacts/contracts/MessagingChannel.sol/MessagingChannel.json +426 -0
  5. package/artifacts/contracts/MessagingComposer.sol/MessagingComposer.json +320 -0
  6. package/artifacts/contracts/MessagingContext.sol/MessagingContext.json +42 -0
  7. package/artifacts/contracts/interfaces/ILayerZeroComposer.sol/ILayerZeroComposer.json +44 -0
  8. package/artifacts/contracts/interfaces/ILayerZeroEndpointV2.sol/ILayerZeroEndpointV2.json +1844 -0
  9. package/artifacts/contracts/interfaces/ILayerZeroReceiver.sol/ILayerZeroReceiver.json +121 -0
  10. package/artifacts/contracts/interfaces/IMessageLib.sol/IMessageLib.json +149 -0
  11. package/artifacts/contracts/interfaces/IMessageLibManager.sol/IMessageLibManager.json +629 -0
  12. package/artifacts/contracts/interfaces/IMessagingChannel.sol/IMessagingChannel.json +344 -0
  13. package/artifacts/contracts/interfaces/IMessagingComposer.sol/IMessagingComposer.json +246 -0
  14. package/artifacts/contracts/interfaces/IMessagingContext.sol/IMessagingContext.json +42 -0
  15. package/artifacts/contracts/interfaces/ISendLib.sol/ISendLib.json +364 -0
  16. package/artifacts/contracts/libs/AddressCast.sol/AddressCast.json +10 -0
  17. package/artifacts/contracts/libs/CalldataBytesLib.sol/CalldataBytesLib.json +10 -0
  18. package/artifacts/contracts/libs/Errors.sol/Errors.json +226 -0
  19. package/artifacts/contracts/libs/GUID.sol/GUID.json +10 -0
  20. package/artifacts/contracts/libs/Transfer.sol/Transfer.json +32 -0
  21. package/artifacts/contracts/messagelib/BlockedMessageLib.sol/BlockedMessageLib.json +94 -0
  22. package/artifacts/contracts/messagelib/SimpleMessageLib.sol/SimpleMessageLib.json +591 -0
  23. package/artifacts/contracts/messagelib/libs/BitMaps.sol/BitMaps.json +10 -0
  24. package/artifacts/contracts/messagelib/libs/ExecutorOptions.sol/ExecutorOptions.json +26 -0
  25. package/artifacts/contracts/messagelib/libs/PacketV1Codec.sol/PacketV1Codec.json +10 -0
  26. package/contracts/EndpointV2.sol +403 -0
  27. package/contracts/EndpointV2Alt.sol +50 -0
  28. package/contracts/MessageLibManager.sol +326 -0
  29. package/contracts/MessagingChannel.sol +161 -0
  30. package/contracts/MessagingComposer.sol +80 -0
  31. package/contracts/MessagingContext.sol +36 -0
  32. package/contracts/interfaces/ILayerZeroComposer.sol +24 -0
  33. package/contracts/interfaces/ILayerZeroEndpointV2.sol +98 -0
  34. package/contracts/interfaces/ILayerZeroReceiver.sol +20 -0
  35. package/contracts/interfaces/IMessageLib.sol +26 -0
  36. package/contracts/interfaces/IMessageLibManager.sol +68 -0
  37. package/contracts/interfaces/IMessagingChannel.sol +32 -0
  38. package/contracts/interfaces/IMessagingComposer.sol +38 -0
  39. package/contracts/interfaces/IMessagingContext.sol +9 -0
  40. package/contracts/interfaces/ISendLib.sol +36 -0
  41. package/contracts/libs/AddressCast.sol +40 -0
  42. package/contracts/libs/CalldataBytesLib.sol +58 -0
  43. package/contracts/libs/Errors.sol +42 -0
  44. package/contracts/libs/GUID.sol +19 -0
  45. package/contracts/libs/Transfer.sol +34 -0
  46. package/contracts/messagelib/BlockedMessageLib.sol +30 -0
  47. package/contracts/messagelib/SimpleMessageLib.sol +149 -0
  48. package/contracts/messagelib/libs/BitMaps.sol +26 -0
  49. package/contracts/messagelib/libs/ExecutorOptions.sol +85 -0
  50. package/contracts/messagelib/libs/PacketV1Codec.sol +108 -0
  51. package/package.json +27 -0
@@ -0,0 +1,98 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity >=0.8.0;
4
+
5
+ import { IMessageLibManager } from "./IMessageLibManager.sol";
6
+ import { IMessagingComposer } from "./IMessagingComposer.sol";
7
+ import { IMessagingChannel } from "./IMessagingChannel.sol";
8
+ import { IMessagingContext } from "./IMessagingContext.sol";
9
+
10
+ struct MessagingParams {
11
+ uint32 dstEid;
12
+ bytes32 receiver;
13
+ bytes message;
14
+ bytes options;
15
+ bool payInLzToken;
16
+ }
17
+
18
+ struct MessagingReceipt {
19
+ bytes32 guid;
20
+ uint64 nonce;
21
+ MessagingFee fee;
22
+ }
23
+
24
+ struct MessagingFee {
25
+ uint256 nativeFee;
26
+ uint256 lzTokenFee;
27
+ }
28
+
29
+ struct Origin {
30
+ uint32 srcEid;
31
+ bytes32 sender;
32
+ uint64 nonce;
33
+ }
34
+
35
+ enum ExecutionState {
36
+ NotExecutable,
37
+ Executable,
38
+ Executed
39
+ }
40
+
41
+ interface ILayerZeroEndpointV2 is IMessageLibManager, IMessagingComposer, IMessagingChannel, IMessagingContext {
42
+ event PacketSent(bytes encodedPayload, bytes options, address sendLibrary);
43
+
44
+ event PacketVerified(Origin origin, address receiver, bytes32 payloadHash);
45
+
46
+ event PacketDelivered(Origin origin, address receiver);
47
+
48
+ event LzReceiveAlert(
49
+ address indexed receiver,
50
+ address indexed executor,
51
+ Origin origin,
52
+ bytes32 guid,
53
+ uint256 gas,
54
+ uint256 value,
55
+ bytes message,
56
+ bytes extraData,
57
+ bytes reason
58
+ );
59
+
60
+ event LzTokenSet(address token);
61
+
62
+ function quote(MessagingParams calldata _params, address _sender) external view returns (MessagingFee memory);
63
+
64
+ function send(
65
+ MessagingParams calldata _params,
66
+ address _refundAddress
67
+ ) external payable returns (MessagingReceipt memory);
68
+
69
+ function verify(Origin calldata _origin, address _receiver, bytes32 _payloadHash) external;
70
+
71
+ function verifiable(
72
+ Origin calldata _origin,
73
+ address _receiver,
74
+ address _receiveLib,
75
+ bytes32 _payloadHash
76
+ ) external view returns (bool);
77
+
78
+ function executable(Origin calldata _origin, address _receiver) external view returns (ExecutionState);
79
+
80
+ function lzReceive(
81
+ Origin calldata _origin,
82
+ address _receiver,
83
+ bytes32 _guid,
84
+ bytes calldata _message,
85
+ bytes calldata _extraData
86
+ ) external payable;
87
+
88
+ // oapp can burn messages partially by calling this function with its own business logic if messages are verified in order
89
+ function clear(address _oapp, Origin calldata _origin, bytes32 _guid, bytes calldata _message) external;
90
+
91
+ function setLzToken(address _lzToken) external;
92
+
93
+ function lzToken() external view returns (address);
94
+
95
+ function nativeToken() external view returns (address);
96
+
97
+ function setDelegate(address _delegate) external;
98
+ }
@@ -0,0 +1,20 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity >=0.8.0;
4
+
5
+ import { Origin } from "./ILayerZeroEndpointV2.sol";
6
+
7
+ interface ILayerZeroReceiver {
8
+ function allowInitializePath(Origin calldata _origin) external view returns (bool);
9
+
10
+ // todo: move to OAppReceiver? it is just convention for executor. we may can change it in a new Receiver version
11
+ function nextNonce(uint32 _eid, bytes32 _sender) external view returns (uint64);
12
+
13
+ function lzReceive(
14
+ Origin calldata _origin,
15
+ bytes32 _guid,
16
+ bytes calldata _message,
17
+ address _executor,
18
+ bytes calldata _extraData
19
+ ) external payable;
20
+ }
@@ -0,0 +1,26 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity >=0.8.0;
4
+
5
+ import { IERC165 } from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
6
+
7
+ import { SetConfigParam } from "./IMessageLibManager.sol";
8
+
9
+ enum MessageLibType {
10
+ Send,
11
+ Receive,
12
+ SendAndReceive
13
+ }
14
+
15
+ interface IMessageLib is IERC165 {
16
+ function setConfig(address _oapp, SetConfigParam[] calldata _config) external;
17
+
18
+ function getConfig(uint32 _eid, address _oapp, uint32 _configType) external view returns (bytes memory config);
19
+
20
+ function isSupportedEid(uint32 _eid) external view returns (bool);
21
+
22
+ // message libs of same major version are compatible
23
+ function version() external view returns (uint64 major, uint8 minor, uint8 endpointVersion);
24
+
25
+ function messageLibType() external view returns (MessageLibType);
26
+ }
@@ -0,0 +1,68 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity >=0.8.0;
4
+
5
+ struct SetConfigParam {
6
+ uint32 eid;
7
+ uint32 configType;
8
+ bytes config;
9
+ }
10
+
11
+ interface IMessageLibManager {
12
+ struct Timeout {
13
+ address lib;
14
+ uint256 expiry;
15
+ }
16
+
17
+ event LibraryRegistered(address newLib);
18
+ event DefaultSendLibrarySet(uint32 eid, address newLib);
19
+ event DefaultReceiveLibrarySet(uint32 eid, address oldLib, address newLib);
20
+ event DefaultReceiveLibraryTimeoutSet(uint32 eid, address oldLib, uint256 expiry);
21
+ event SendLibrarySet(address sender, uint32 eid, address newLib);
22
+ event ReceiveLibrarySet(address receiver, uint32 eid, address oldLib, address newLib);
23
+ event ReceiveLibraryTimeoutSet(address receiver, uint32 eid, address oldLib, uint256 timeout);
24
+
25
+ function registerLibrary(address _lib) external;
26
+
27
+ function isRegisteredLibrary(address _lib) external view returns (bool);
28
+
29
+ function getRegisteredLibraries() external view returns (address[] memory);
30
+
31
+ function setDefaultSendLibrary(uint32 _eid, address _newLib) external;
32
+
33
+ function defaultSendLibrary(uint32 _eid) external view returns (address);
34
+
35
+ function setDefaultReceiveLibrary(uint32 _eid, address _newLib, uint256 _timeout) external;
36
+
37
+ function defaultReceiveLibrary(uint32 _eid) external view returns (address);
38
+
39
+ function setDefaultReceiveLibraryTimeout(uint32 _eid, address _lib, uint256 _expiry) external;
40
+
41
+ function defaultReceiveLibraryTimeout(uint32 _eid) external view returns (address lib, uint256 expiry);
42
+
43
+ function isSupportedEid(uint32 _eid) external view returns (bool);
44
+
45
+ /// ------------------- OApp interfaces -------------------
46
+ function setSendLibrary(address _oapp, uint32 _eid, address _newLib) external;
47
+
48
+ function getSendLibrary(address _sender, uint32 _eid) external view returns (address lib);
49
+
50
+ function isDefaultSendLibrary(address _sender, uint32 _eid) external view returns (bool);
51
+
52
+ function setReceiveLibrary(address _oapp, uint32 _eid, address _newLib, uint256 _gracePeriod) external;
53
+
54
+ function getReceiveLibrary(address _receiver, uint32 _eid) external view returns (address lib, bool isDefault);
55
+
56
+ function setReceiveLibraryTimeout(address _oapp, uint32 _eid, address _lib, uint256 _gracePeriod) external;
57
+
58
+ function receiveLibraryTimeout(address _receiver, uint32 _eid) external view returns (address lib, uint256 expiry);
59
+
60
+ function setConfig(address _oapp, address _lib, SetConfigParam[] calldata _params) external;
61
+
62
+ function getConfig(
63
+ address _oapp,
64
+ address _lib,
65
+ uint32 _eid,
66
+ uint32 _configType
67
+ ) external view returns (bytes memory config);
68
+ }
@@ -0,0 +1,32 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity >=0.8.0;
4
+
5
+ interface IMessagingChannel {
6
+ event InboundNonceSkipped(uint32 srcEid, bytes32 sender, address receiver, uint64 nonce);
7
+ event PacketNilified(uint32 srcEid, bytes32 sender, address receiver, uint64 nonce, bytes32 payloadHash);
8
+ event PacketBurnt(uint32 srcEid, bytes32 sender, address receiver, uint64 nonce, bytes32 payloadHash);
9
+
10
+ function eid() external view returns (uint32);
11
+
12
+ // this is an emergency function if a message cannot be verified for some reasons
13
+ // required to provide _nextNonce to avoid race condition
14
+ function skip(address _oapp, uint32 _srcEid, bytes32 _sender, uint64 _nonce) external;
15
+
16
+ function nilify(address _oapp, uint32 _srcEid, bytes32 _sender, uint64 _nonce, bytes32 _payloadHash) external;
17
+
18
+ function burn(address _oapp, uint32 _srcEid, bytes32 _sender, uint64 _nonce, bytes32 _payloadHash) external;
19
+
20
+ function nextGuid(address _sender, uint32 _dstEid, bytes32 _receiver) external view returns (bytes32);
21
+
22
+ function inboundNonce(address _receiver, uint32 _srcEid, bytes32 _sender) external view returns (uint64);
23
+
24
+ function outboundNonce(address _sender, uint32 _dstEid, bytes32 _receiver) external view returns (uint64);
25
+
26
+ function inboundPayloadHash(
27
+ address _receiver,
28
+ uint32 _srcEid,
29
+ bytes32 _sender,
30
+ uint64 _nonce
31
+ ) external view returns (bytes32);
32
+ }
@@ -0,0 +1,38 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity >=0.8.0;
4
+
5
+ interface IMessagingComposer {
6
+ event ComposeSent(address from, address to, bytes32 guid, uint16 index, bytes message);
7
+ event ComposeDelivered(address from, address to, bytes32 guid, uint16 index);
8
+ event LzComposeAlert(
9
+ address indexed from,
10
+ address indexed to,
11
+ address indexed executor,
12
+ bytes32 guid,
13
+ uint16 index,
14
+ uint256 gas,
15
+ uint256 value,
16
+ bytes message,
17
+ bytes extraData,
18
+ bytes reason
19
+ );
20
+
21
+ function composeQueue(
22
+ address _from,
23
+ address _to,
24
+ bytes32 _guid,
25
+ uint16 _index
26
+ ) external view returns (bytes32 messageHash);
27
+
28
+ function sendCompose(address _to, bytes32 _guid, uint16 _index, bytes calldata _message) external;
29
+
30
+ function lzCompose(
31
+ address _from,
32
+ address _to,
33
+ bytes32 _guid,
34
+ uint16 _index,
35
+ bytes calldata _message,
36
+ bytes calldata _extraData
37
+ ) external payable;
38
+ }
@@ -0,0 +1,9 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity >=0.8.0;
4
+
5
+ interface IMessagingContext {
6
+ function isSendingMessage() external view returns (bool);
7
+
8
+ function getSendContext() external view returns (uint32 dstEid, address sender);
9
+ }
@@ -0,0 +1,36 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity >=0.8.0;
4
+
5
+ import { MessagingFee } from "./ILayerZeroEndpointV2.sol";
6
+ import { IMessageLib } from "./IMessageLib.sol";
7
+
8
+ struct Packet {
9
+ uint64 nonce;
10
+ uint32 srcEid;
11
+ address sender;
12
+ uint32 dstEid;
13
+ bytes32 receiver;
14
+ bytes32 guid;
15
+ bytes message;
16
+ }
17
+
18
+ interface ISendLib is IMessageLib {
19
+ function send(
20
+ Packet calldata _packet,
21
+ bytes calldata _options,
22
+ bool _payInLzToken
23
+ ) external returns (MessagingFee memory, bytes memory encodedPacket);
24
+
25
+ function quote(
26
+ Packet calldata _packet,
27
+ bytes calldata _options,
28
+ bool _payInLzToken
29
+ ) external view returns (MessagingFee memory);
30
+
31
+ function setTreasury(address _treasury) external;
32
+
33
+ function withdrawFee(address _to, uint256 _amount) external;
34
+
35
+ function withdrawLzTokenFee(address _lzToken, address _to, uint256 _amount) external;
36
+ }
@@ -0,0 +1,40 @@
1
+ // SPDX-License-Identifier: LZBL-1.2
2
+
3
+ pragma solidity ^0.8.22;
4
+
5
+ import { Errors } from "./Errors.sol";
6
+
7
+ library AddressCast {
8
+ function toBytes32(bytes calldata _addressBytes) internal pure returns (bytes32 result) {
9
+ if (_addressBytes.length > 32) revert Errors.InvalidAddress();
10
+ result = bytes32(_addressBytes);
11
+ unchecked {
12
+ uint256 offset = 32 - _addressBytes.length;
13
+ result = result >> (offset * 8);
14
+ }
15
+ }
16
+
17
+ function toBytes32(address _address) internal pure returns (bytes32 result) {
18
+ result = bytes32(uint256(uint160(_address)));
19
+ }
20
+
21
+ function toBytes(bytes32 _addressBytes32, uint256 _size) internal pure returns (bytes memory result) {
22
+ if (_size == 0 || _size > 32) revert Errors.InvalidSizeForAddress();
23
+ result = new bytes(_size);
24
+ unchecked {
25
+ uint256 offset = 256 - _size * 8;
26
+ assembly {
27
+ mstore(add(result, 32), shl(offset, _addressBytes32))
28
+ }
29
+ }
30
+ }
31
+
32
+ function toAddress(bytes32 _addressBytes32) internal pure returns (address result) {
33
+ result = address(uint160(uint256(_addressBytes32)));
34
+ }
35
+
36
+ function toAddress(bytes calldata _addressBytes) internal pure returns (address result) {
37
+ if (_addressBytes.length != 20) revert Errors.InvalidAddress();
38
+ result = address(bytes20(_addressBytes));
39
+ }
40
+ }
@@ -0,0 +1,58 @@
1
+ // SPDX-License-Identifier: LZBL-1.2
2
+
3
+ pragma solidity ^0.8.22;
4
+
5
+ library CalldataBytesLib {
6
+ function toU8(bytes calldata _bytes, uint256 _start) internal pure returns (uint8) {
7
+ return uint8(_bytes[_start]);
8
+ }
9
+
10
+ function toU16(bytes calldata _bytes, uint256 _start) internal pure returns (uint16) {
11
+ unchecked {
12
+ uint256 end = _start + 2;
13
+ return uint16(bytes2(_bytes[_start:end]));
14
+ }
15
+ }
16
+
17
+ function toU32(bytes calldata _bytes, uint256 _start) internal pure returns (uint32) {
18
+ unchecked {
19
+ uint256 end = _start + 4;
20
+ return uint32(bytes4(_bytes[_start:end]));
21
+ }
22
+ }
23
+
24
+ function toU64(bytes calldata _bytes, uint256 _start) internal pure returns (uint64) {
25
+ unchecked {
26
+ uint256 end = _start + 8;
27
+ return uint64(bytes8(_bytes[_start:end]));
28
+ }
29
+ }
30
+
31
+ function toU128(bytes calldata _bytes, uint256 _start) internal pure returns (uint128) {
32
+ unchecked {
33
+ uint256 end = _start + 16;
34
+ return uint128(bytes16(_bytes[_start:end]));
35
+ }
36
+ }
37
+
38
+ function toU256(bytes calldata _bytes, uint256 _start) internal pure returns (uint256) {
39
+ unchecked {
40
+ uint256 end = _start + 32;
41
+ return uint256(bytes32(_bytes[_start:end]));
42
+ }
43
+ }
44
+
45
+ function toAddr(bytes calldata _bytes, uint256 _start) internal pure returns (address) {
46
+ unchecked {
47
+ uint256 end = _start + 20;
48
+ return address(bytes20(_bytes[_start:end]));
49
+ }
50
+ }
51
+
52
+ function toB32(bytes calldata _bytes, uint256 _start) internal pure returns (bytes32) {
53
+ unchecked {
54
+ uint256 end = _start + 32;
55
+ return bytes32(_bytes[_start:end]);
56
+ }
57
+ }
58
+ }
@@ -0,0 +1,42 @@
1
+ // SPDX-License-Identifier: LZBL-1.2
2
+
3
+ pragma solidity ^0.8.22;
4
+
5
+ library Errors {
6
+ error LzTokenUnavailable();
7
+ error OnlyAltToken();
8
+ error InvalidReceiveLibrary();
9
+ error InvalidNonce(uint64 nonce);
10
+ error InvalidArgument();
11
+ error InvalidExpiry();
12
+ error InvalidAmount(uint256 required, uint256 supplied);
13
+ error OnlyRegisteredOrDefaultLib();
14
+ error OnlyRegisteredLib();
15
+ error OnlyNonDefaultLib();
16
+ error Unauthorized();
17
+ error DefaultSendLibUnavailable();
18
+ error DefaultReceiveLibUnavailable();
19
+ error PathNotInitializable();
20
+ error PathNotVerifiable();
21
+ error OnlySendLib();
22
+ error OnlyReceiveLib();
23
+ error UnsupportedEid();
24
+ error UnsupportedInterface();
25
+ error AlreadyRegistered();
26
+ error SameValue();
27
+ error InvalidPayloadHash();
28
+ error PayloadHashNotFound(bytes32 expected, bytes32 actual);
29
+ error ComposeNotFound(bytes32 expected, bytes32 actual);
30
+ error ComposeExists();
31
+ error SendReentrancy();
32
+ error NotImplemented();
33
+ error InvalidAddress();
34
+ error InvalidSizeForAddress();
35
+ error InsufficientFee(
36
+ uint256 requiredNative,
37
+ uint256 suppliedNative,
38
+ uint256 requiredLzToken,
39
+ uint256 suppliedLzToken
40
+ );
41
+ error ZeroLzTokenFee();
42
+ }
@@ -0,0 +1,19 @@
1
+ // SPDX-License-Identifier: LZBL-1.2
2
+
3
+ pragma solidity ^0.8.22;
4
+
5
+ import { AddressCast } from "./AddressCast.sol";
6
+
7
+ library GUID {
8
+ using AddressCast for address;
9
+
10
+ function generate(
11
+ uint64 _nonce,
12
+ uint32 _srcEid,
13
+ address _sender,
14
+ uint32 _dstEid,
15
+ bytes32 _receiver
16
+ ) internal pure returns (bytes32) {
17
+ return keccak256(abi.encodePacked(_nonce, _srcEid, _sender.toBytes32(), _dstEid, _receiver));
18
+ }
19
+ }
@@ -0,0 +1,34 @@
1
+ // SPDX-License-Identifier: LZBL-1.2
2
+
3
+ pragma solidity ^0.8.22;
4
+
5
+ import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
6
+ import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
7
+
8
+ library Transfer {
9
+ using SafeERC20 for IERC20;
10
+
11
+ address internal constant ADDRESS_ZERO = address(0);
12
+
13
+ error TransferNativeFailed(address _to, uint256 _value);
14
+ error ToAddressIsZero();
15
+
16
+ function native(address _to, uint256 _value) internal {
17
+ if (_to == ADDRESS_ZERO) revert ToAddressIsZero();
18
+ (bool success, ) = _to.call{ value: _value }("");
19
+ if (!success) revert TransferNativeFailed(_to, _value);
20
+ }
21
+
22
+ function token(address _token, address _to, uint256 _value) internal {
23
+ if (_to == ADDRESS_ZERO) revert ToAddressIsZero();
24
+ IERC20(_token).safeTransfer(_to, _value);
25
+ }
26
+
27
+ function nativeOrToken(address _token, address _to, uint256 _value) internal {
28
+ if (_token == ADDRESS_ZERO) {
29
+ native(_to, _value);
30
+ } else {
31
+ token(_token, _to, _value);
32
+ }
33
+ }
34
+ }
@@ -0,0 +1,30 @@
1
+ // SPDX-License-Identifier: LZBL-1.2
2
+
3
+ pragma solidity 0.8.22;
4
+
5
+ import { ERC165 } from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
6
+
7
+ import { IMessageLib, MessageLibType } from "../interfaces/IMessageLib.sol";
8
+ import { Errors } from "../libs/Errors.sol";
9
+
10
+ contract BlockedMessageLib is ERC165 {
11
+ function supportsInterface(bytes4 interfaceId) public view override returns (bool) {
12
+ return interfaceId == type(IMessageLib).interfaceId || super.supportsInterface(interfaceId);
13
+ }
14
+
15
+ function version() external pure returns (uint64 major, uint8 minor, uint8 endpointVersion) {
16
+ return (type(uint64).max, type(uint8).max, 2);
17
+ }
18
+
19
+ function messageLibType() external pure returns (MessageLibType) {
20
+ return MessageLibType.SendAndReceive;
21
+ }
22
+
23
+ function isSupportedEid(uint32) external pure returns (bool) {
24
+ return true;
25
+ }
26
+
27
+ fallback() external {
28
+ revert Errors.NotImplemented();
29
+ }
30
+ }