@layerzerolabs/protocol-v2-messagelib-evm-contracts 1.2.95

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 (88) hide show
  1. package/README.md +15 -0
  2. package/contracts/Executor.sol +339 -0
  3. package/contracts/ExecutorFeeLib.sol +241 -0
  4. package/contracts/MessageLibBase.sol +21 -0
  5. package/contracts/PriceFeed.sol +304 -0
  6. package/contracts/ReceiveLibBaseE2.sol +28 -0
  7. package/contracts/SendLibBase.sol +258 -0
  8. package/contracts/SendLibBaseE2.sol +140 -0
  9. package/contracts/SimpleReadExecutor.sol +110 -0
  10. package/contracts/Treasury.sol +74 -0
  11. package/contracts/Worker.sol +167 -0
  12. package/contracts/decompressor/DVNDecoder.sol +52 -0
  13. package/contracts/decompressor/DVNDecompressor.sol +70 -0
  14. package/contracts/decompressor/DecompressorExtension.sol +204 -0
  15. package/contracts/decompressor/ExecutorDecoder.sol +147 -0
  16. package/contracts/decompressor/ExecutorDecompressor.sol +58 -0
  17. package/contracts/interfaces/IExecutor.sol +47 -0
  18. package/contracts/interfaces/IExecutorFeeLib.sol +56 -0
  19. package/contracts/interfaces/ILayerZeroExecutor.sol +29 -0
  20. package/contracts/interfaces/ILayerZeroPriceFeed.sol +61 -0
  21. package/contracts/interfaces/ILayerZeroReadExecutor.sol +15 -0
  22. package/contracts/interfaces/ILayerZeroTreasury.sol +19 -0
  23. package/contracts/interfaces/IWorker.sol +29 -0
  24. package/contracts/libs/ExecutorOptions.sol +104 -0
  25. package/contracts/libs/SafeCall.sol +123 -0
  26. package/contracts/lowlat/EssenceDVNWrapper.sol +77 -0
  27. package/contracts/lowlat/MultiCall.sol +42 -0
  28. package/contracts/mocks/DVNMock.sol +28 -0
  29. package/contracts/mocks/ExecutorMock.sol +95 -0
  30. package/contracts/uln/LzExecutor.sol +129 -0
  31. package/contracts/uln/ReceiveUlnBase.sol +125 -0
  32. package/contracts/uln/SendUlnBase.sol +129 -0
  33. package/contracts/uln/UlnBase.sol +195 -0
  34. package/contracts/uln/dvn/DVN.sol +393 -0
  35. package/contracts/uln/dvn/DVNFeeLib.sol +288 -0
  36. package/contracts/uln/dvn/DeadDVN.sol +30 -0
  37. package/contracts/uln/dvn/MultiSig.sol +135 -0
  38. package/contracts/uln/dvn/SimpleReadDVN.sol +112 -0
  39. package/contracts/uln/dvn/adapters/CCIP/CCIPDVNAdapter.sol +151 -0
  40. package/contracts/uln/dvn/adapters/CCIP/CCIPDVNAdapterFeeLib.sol +71 -0
  41. package/contracts/uln/dvn/adapters/DVNAdapterBase.sol +114 -0
  42. package/contracts/uln/dvn/adapters/arbitrum/ArbitrumDVNAdapterL1.sol +126 -0
  43. package/contracts/uln/dvn/adapters/arbitrum/ArbitrumDVNAdapterL2.sol +50 -0
  44. package/contracts/uln/dvn/adapters/avalanche/NOTES.md +4 -0
  45. package/contracts/uln/dvn/adapters/axelar/AxelarDVNAdapter.sol +152 -0
  46. package/contracts/uln/dvn/adapters/axelar/AxelarDVNAdapterFeeLib.sol +127 -0
  47. package/contracts/uln/dvn/adapters/libs/DVNAdapterMessageCodec.sol +41 -0
  48. package/contracts/uln/dvn/adapters/optimism/OptimismDVNAdapterL1.sol +86 -0
  49. package/contracts/uln/dvn/adapters/optimism/OptimismDVNAdapterL2.sol +58 -0
  50. package/contracts/uln/interfaces/IDVN.sol +26 -0
  51. package/contracts/uln/interfaces/IDVNFeeLib.sol +56 -0
  52. package/contracts/uln/interfaces/ILayerZeroDVN.sol +34 -0
  53. package/contracts/uln/interfaces/ILayerZeroReadDVN.sol +27 -0
  54. package/contracts/uln/interfaces/IReceiveUlnE2.sol +13 -0
  55. package/contracts/uln/interfaces/adapters/IAxelarDVNAdapter.sol +50 -0
  56. package/contracts/uln/interfaces/adapters/IAxelarDVNAdapterFeeLib.sol +49 -0
  57. package/contracts/uln/interfaces/adapters/ICCIPDVNAdapter.sol +34 -0
  58. package/contracts/uln/interfaces/adapters/ICCIPDVNAdapterFeeLib.sol +46 -0
  59. package/contracts/uln/libs/DVNOptions.sol +181 -0
  60. package/contracts/uln/libs/ReadCmdCodecV1.sol +136 -0
  61. package/contracts/uln/libs/SupportedCmdTypes.sol +29 -0
  62. package/contracts/uln/libs/UlnOptions.sol +176 -0
  63. package/contracts/uln/readlib/ReadLib1002.sol +518 -0
  64. package/contracts/uln/readlib/ReadLib1002View.sol +98 -0
  65. package/contracts/uln/readlib/ReadLibBase.sol +187 -0
  66. package/contracts/uln/uln301/AddressSizeConfig.sol +22 -0
  67. package/contracts/uln/uln301/ReceiveLibBaseE1.sol +103 -0
  68. package/contracts/uln/uln301/ReceiveUln301.sol +83 -0
  69. package/contracts/uln/uln301/ReceiveUln301View.sol +89 -0
  70. package/contracts/uln/uln301/SendLibBaseE1.sol +194 -0
  71. package/contracts/uln/uln301/SendUln301.sol +99 -0
  72. package/contracts/uln/uln301/TreasuryFeeHandler.sol +41 -0
  73. package/contracts/uln/uln301/interfaces/IMessageLibE1.sol +22 -0
  74. package/contracts/uln/uln301/interfaces/INonceContract.sol +7 -0
  75. package/contracts/uln/uln301/interfaces/ITreasuryFeeHandler.sol +13 -0
  76. package/contracts/uln/uln301/interfaces/IUltraLightNode301.sol +7 -0
  77. package/contracts/uln/uln301/mocks/NonceContractMock.sol +23 -0
  78. package/contracts/uln/uln302/ReceiveUln302.sol +85 -0
  79. package/contracts/uln/uln302/ReceiveUln302View.sol +89 -0
  80. package/contracts/uln/uln302/SendUln302.sol +86 -0
  81. package/contracts/upgradeable/WorkerUpgradeable.sol +186 -0
  82. package/contracts/upgradeable/proxy/ProxyAdmin.sol +96 -0
  83. package/contracts/upgradeable/proxy/TransparentUpgradeableProxy.sol +131 -0
  84. package/dist/index.d.ts +7 -0
  85. package/dist/index.d.ts.map +1 -0
  86. package/dist/index.js +6 -0
  87. package/dist/index.js.map +1 -0
  88. package/package.json +70 -0
@@ -0,0 +1,204 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity ^0.8.0;
4
+
5
+ /**
6
+ * @title DecompressorExtension
7
+ * @dev A contract that implements a decompression algorithm to be used in conjunction with compressed data.
8
+ * You should implement in your contract a function that makes use of the internal methods `_setData`, `_setDataArray` for data addition to the dictionary.
9
+ * NOTE: It is important to implement a delay when using the `_setData` and `_setDataArray` methods in your transactions. This delay helps to guard against the possibility of frontrunning, which can occur when the state of the dictionary changes during the execution of a transaction.
10
+ * @notice This extension could result in a much higher gas consumption than expected and could potentially lead to significant memory expansion costs. Be sure to properly estimate these aspects to avoid unforeseen expenses.
11
+ */
12
+ abstract contract DecompressorExtension {
13
+ /**
14
+ * @dev Emitted when an offset is used incorrectly, either because it is too small, or because its sum with a dict data's length exceeds a certain limit.
15
+ * @param value The incorrect value used as an offset or as the sum of the offset and a dict data's length.
16
+ */
17
+ error IncorrectDictAccess(uint256 value);
18
+
19
+ uint256 public constant MAX_DICT_LEN = 1_048_576; // 2 ** 20
20
+ uint256 public constant RESERVE_DICT_LEN = 2; // 0: msg.sender; 1: address(this)
21
+
22
+ /**
23
+ * @dev The dictionary mapping storage slots to their associated compressed data.
24
+ */
25
+ bytes32[MAX_DICT_LEN] private _dict;
26
+
27
+ /**
28
+ * @dev Ensures the provided value is correctly used as an offset. This includes checks for the offset being too small or its sum with an dict data's length exceeding a certain limit. Value less `RESERVE_DICT_LEN` are reserved.
29
+ * @param value The value used as an offset or as the sum of the offset and an array's length.
30
+ */
31
+ modifier validDictAccess(uint256 value) {
32
+ if (value < RESERVE_DICT_LEN || value >= MAX_DICT_LEN) revert IncorrectDictAccess(value);
33
+ _;
34
+ }
35
+
36
+ /**
37
+ * @dev Returns the data stored in the dictionary in the specified range.
38
+ * @param begin The starting index of the data range to return. First 2 positions are reserved, so it should be greater than 1.
39
+ * @param end The ending index of the data range to return.
40
+ * @return res An array of bytes32 values containing the data in the specified range.
41
+ */
42
+ function getData(
43
+ uint256 begin,
44
+ uint256 end
45
+ ) external view validDictAccess(begin) validDictAccess(end) returns (bytes32[] memory res) {
46
+ unchecked {
47
+ if (begin < end) {
48
+ res = new bytes32[](end - begin);
49
+ for (uint256 i = begin; i < end; i++) {
50
+ res[i - begin] = _dict[i];
51
+ }
52
+ }
53
+ }
54
+ }
55
+
56
+ /**
57
+ * @dev Sets the data at the specified dictionary offset.
58
+ * @param offset The dictionary offset to set the data at. First 2 positions are reserved, so it should be greater than 1.
59
+ * @param data The data to be stored at the specified offset.
60
+ */
61
+ function _setData(uint256 offset, bytes32 data) internal validDictAccess(offset) {
62
+ unchecked {
63
+ _dict[offset] = data;
64
+ }
65
+ }
66
+
67
+ /**
68
+ * @dev Sets an array of data starting at the specified dictionary offset.
69
+ * @param offset The starting dictionary offset to set the data at. First 2 positions are reserved, so it should be greater than 1.
70
+ * @param dataArray The array of data to be stored starting at the specified offset.
71
+ */
72
+ function _setDataArray(
73
+ uint256 offset,
74
+ bytes32[] calldata dataArray
75
+ ) internal validDictAccess(offset) validDictAccess(offset + dataArray.length) {
76
+ unchecked {
77
+ for (uint256 i = 0; i < dataArray.length; i++) {
78
+ _dict[offset + i] = dataArray[i];
79
+ }
80
+ }
81
+ }
82
+
83
+ /**
84
+ * @dev Decompresses the compressed data (N bytes) passed to the function using the _delegatecall function.
85
+ */
86
+ function decompress() external payable {
87
+ _delegatecall(decompressed());
88
+ }
89
+
90
+ /**
91
+ * @dev Calculates and returns the decompressed data from the compressed calldata.
92
+ * @return raw The decompressed raw data.
93
+ */
94
+ function decompressed() public view returns (bytes memory raw) {
95
+ return _decompressed(msg.data[4:]);
96
+ }
97
+
98
+ /**
99
+ * @dev Calculates and returns the decompressed raw data from the compressed data passed as an argument.
100
+ * @param cd The compressed data to be decompressed.
101
+ * @return raw The decompressed raw data.
102
+ */
103
+ function _decompressed(bytes calldata cd) internal view returns (bytes memory raw) {
104
+ assembly ("memory-safe") {
105
+ // solhint-disable-line no-inline-assembly
106
+ raw := mload(0x40)
107
+ let outptr := add(raw, 0x20)
108
+ let end := add(cd.offset, cd.length)
109
+ for {
110
+ let inptr := cd.offset
111
+ } lt(inptr, end) {
112
+
113
+ } {
114
+ // solhint-disable-line no-empty-blocks
115
+ let data := calldataload(inptr)
116
+
117
+ let key
118
+
119
+ // 00XXXXXX - insert X+1 zero bytes
120
+ // 01PXXXXX - copy X+1 bytes calldata (P means padding to 32 bytes or not)
121
+ // 10BBXXXX XXXXXXXX - use 12 bits as key for [32,20,4,31][B] bytes from storage X
122
+ // 11BBXXXX XXXXXXXX XXXXXXXX - use 20 bits as [32,20,4,31][B] bytes from storage X
123
+ switch shr(254, data)
124
+ case 0 {
125
+ let size := add(byte(0, data), 1)
126
+ calldatacopy(outptr, calldatasize(), size)
127
+ inptr := add(inptr, 1)
128
+ outptr := add(outptr, size)
129
+ continue
130
+ }
131
+ case 1 {
132
+ let size := add(and(0x1F, byte(0, data)), 1)
133
+ if and(data, 0x2000000000000000000000000000000000000000000000000000000000000000) {
134
+ mstore(outptr, 0)
135
+ outptr := add(outptr, sub(32, size))
136
+ }
137
+ calldatacopy(outptr, add(inptr, 1), size)
138
+ inptr := add(inptr, add(1, size))
139
+ outptr := add(outptr, size)
140
+ continue
141
+ }
142
+ case 2 {
143
+ key := shr(244, shl(4, data))
144
+ inptr := add(inptr, 2)
145
+ // fallthrough
146
+ }
147
+ case 3 {
148
+ key := shr(236, shl(4, data))
149
+ inptr := add(inptr, 3)
150
+ // fallthrough
151
+ }
152
+
153
+ // TODO: check sload argument
154
+ let value
155
+ switch key
156
+ case 0 {
157
+ value := caller()
158
+ }
159
+ case 1 {
160
+ value := address()
161
+ }
162
+ default {
163
+ value := sload(add(_dict.slot, key))
164
+ }
165
+
166
+ switch shr(254, shl(2, data))
167
+ case 0 {
168
+ mstore(outptr, value)
169
+ outptr := add(outptr, 32)
170
+ }
171
+ case 1 {
172
+ mstore(outptr, shl(96, value))
173
+ outptr := add(outptr, 20)
174
+ }
175
+ case 2 {
176
+ mstore(outptr, shl(224, value))
177
+ outptr := add(outptr, 4)
178
+ }
179
+ default {
180
+ mstore(outptr, shl(8, value))
181
+ outptr := add(outptr, 31)
182
+ }
183
+ }
184
+ mstore(raw, sub(sub(outptr, raw), 0x20))
185
+ mstore(0x40, outptr)
186
+ }
187
+ }
188
+
189
+ /**
190
+ * @dev Executes a delegate call to the raw data calculated by the _decompressed function.
191
+ * @param raw The raw data to execute the delegate call with.
192
+ */
193
+ function _delegatecall(bytes memory raw) internal {
194
+ assembly ("memory-safe") {
195
+ // solhint-disable-line no-inline-assembly
196
+ let success := delegatecall(gas(), address(), add(raw, 0x20), mload(raw), 0, 0)
197
+ returndatacopy(0, 0, returndatasize())
198
+ if success {
199
+ return(0, returndatasize())
200
+ }
201
+ revert(0, returndatasize())
202
+ }
203
+ }
204
+ }
@@ -0,0 +1,147 @@
1
+ // SPDX-License-Identifier: BUSL-1.1
2
+ pragma solidity ^0.8.0;
3
+
4
+ import { Origin } from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol";
5
+ import { IExecutor } from "../interfaces/IExecutor.sol";
6
+
7
+ library ExecutorDecoder {
8
+ uint8 internal constant NATIVE_DROP_GAS_LIMIT_OFFSET = 0; // uint32
9
+ uint8 internal constant SRC_EID_OFFSET = 4; // uint32
10
+ uint8 internal constant SENDER_OFFSET = 8; // bytes32
11
+ uint8 internal constant NONCE_OFFSET = 40; // uint64
12
+ uint8 internal constant RECEIVER_OFFSET = 48; // address
13
+
14
+ uint8 internal constant NATIVEDROP_DST_EID_OFFSET = 68; // uint32
15
+ uint8 internal constant DST_EID_SIZE = 4; // uint32
16
+ function nativeDrop(
17
+ bytes calldata _encoded
18
+ )
19
+ internal
20
+ pure
21
+ returns (
22
+ Origin memory origin,
23
+ uint32 dstEid,
24
+ address receiver,
25
+ IExecutor.NativeDropParams[] memory nativeDropParams,
26
+ uint256 nativeDropGasLimit
27
+ )
28
+ {
29
+ nativeDropGasLimit = uint256(uint32(bytes4(_encoded[NATIVE_DROP_GAS_LIMIT_OFFSET:SRC_EID_OFFSET])));
30
+ origin.srcEid = uint32(bytes4(_encoded[SRC_EID_OFFSET:SENDER_OFFSET]));
31
+ origin.sender = bytes32(_encoded[SENDER_OFFSET:NONCE_OFFSET]);
32
+ origin.nonce = uint64(bytes8(_encoded[NONCE_OFFSET:RECEIVER_OFFSET]));
33
+ receiver = address(bytes20(_encoded[RECEIVER_OFFSET:NATIVEDROP_DST_EID_OFFSET]));
34
+
35
+ uint8 nativeDropOffset = NATIVEDROP_DST_EID_OFFSET + DST_EID_SIZE;
36
+ dstEid = uint32(bytes4(_encoded[NATIVEDROP_DST_EID_OFFSET:nativeDropOffset]));
37
+
38
+ nativeDropParams = _nativeDrop(_encoded[nativeDropOffset:]);
39
+ }
40
+
41
+ uint8 internal constant EXECUTE301_GAS_LIMIT_OFFSET = 0; // uint64
42
+ uint8 internal constant EXECUTE301_PACKET_OFFSET = 8; // uint64
43
+ function execute301(bytes calldata encoded) internal pure returns (bytes memory packet, uint256 gasLimit) {
44
+ gasLimit = uint256(uint64(bytes8(encoded[EXECUTE301_GAS_LIMIT_OFFSET:EXECUTE301_PACKET_OFFSET])));
45
+ packet = encoded[EXECUTE301_PACKET_OFFSET:];
46
+ }
47
+
48
+ uint8 internal constant NATIVEDROP_AND_EXECUTE301_GAS_LIMIT_OFFSET = 48; // uint64
49
+ uint8 internal constant NATIVEDROP_AND_EXECUTE301_PACKET_LENGTH_OFFSET = 56; // uint64
50
+ uint8 internal constant NATIVEDROP_AND_EXECUTE301_PACKET_OFFSET = 64; // uint64
51
+ function nativeDropAndExecute301(
52
+ bytes calldata _encoded
53
+ )
54
+ internal
55
+ pure
56
+ returns (
57
+ Origin memory origin,
58
+ IExecutor.NativeDropParams[] memory nativeDropParams,
59
+ uint256 nativeDropGasLimit,
60
+ bytes memory packet,
61
+ uint256 gasLimit
62
+ )
63
+ {
64
+ nativeDropGasLimit = uint256(uint32(bytes4(_encoded[NATIVE_DROP_GAS_LIMIT_OFFSET:SRC_EID_OFFSET])));
65
+ origin.srcEid = uint32(bytes4(_encoded[SRC_EID_OFFSET:SENDER_OFFSET]));
66
+ origin.sender = bytes32(_encoded[SENDER_OFFSET:NONCE_OFFSET]);
67
+ origin.nonce = uint64(bytes8(_encoded[NONCE_OFFSET:NATIVEDROP_AND_EXECUTE301_GAS_LIMIT_OFFSET]));
68
+
69
+ gasLimit = uint256(
70
+ uint64(
71
+ bytes8(
72
+ _encoded[NATIVEDROP_AND_EXECUTE301_GAS_LIMIT_OFFSET:NATIVEDROP_AND_EXECUTE301_PACKET_LENGTH_OFFSET]
73
+ )
74
+ )
75
+ );
76
+
77
+ uint64 packetLength = uint64(
78
+ bytes8(_encoded[NATIVEDROP_AND_EXECUTE301_PACKET_LENGTH_OFFSET:NATIVEDROP_AND_EXECUTE301_PACKET_OFFSET])
79
+ );
80
+
81
+ uint256 cursor = NATIVEDROP_AND_EXECUTE301_PACKET_OFFSET;
82
+
83
+ packet = _encoded[cursor:cursor + packetLength];
84
+ cursor += packetLength;
85
+
86
+ nativeDropParams = _nativeDrop(_encoded[cursor:]);
87
+ }
88
+
89
+ uint8 internal constant EXECUTE302_GUID_OFFSET = 68; // bytes32
90
+ uint8 internal constant EXECUTE302_GAS_LIMIT_OFFSET = 100; // uint64
91
+ uint8 internal constant EXECUTE302_MESSAGE_LENGTH_OFFSET = 108; // uint64
92
+ uint8 internal constant EXECUTE302_MESSAGE_OFFSET = 116; // uint64
93
+ uint8 internal constant EXTRA_DATA_LENGTH_SIZE = 8; // uint64
94
+ function nativeDropAndExecute302(
95
+ bytes calldata _encoded
96
+ )
97
+ internal
98
+ pure
99
+ returns (
100
+ IExecutor.NativeDropParams[] memory nativeDropParams,
101
+ uint256 nativeDropGasLimit,
102
+ IExecutor.ExecutionParams memory executionParams
103
+ )
104
+ {
105
+ nativeDropGasLimit = uint256(uint32(bytes4(_encoded[NATIVE_DROP_GAS_LIMIT_OFFSET:SRC_EID_OFFSET])));
106
+ executionParams.origin.srcEid = uint32(bytes4(_encoded[SRC_EID_OFFSET:SENDER_OFFSET]));
107
+ executionParams.origin.sender = bytes32(_encoded[SENDER_OFFSET:NONCE_OFFSET]);
108
+ executionParams.origin.nonce = uint64(bytes8(_encoded[NONCE_OFFSET:RECEIVER_OFFSET]));
109
+ executionParams.receiver = address(bytes20(_encoded[RECEIVER_OFFSET:EXECUTE302_GUID_OFFSET]));
110
+ executionParams.guid = bytes32(_encoded[EXECUTE302_GUID_OFFSET:EXECUTE302_GAS_LIMIT_OFFSET]);
111
+ executionParams.gasLimit = uint256(
112
+ uint64(bytes8(_encoded[EXECUTE302_GAS_LIMIT_OFFSET:EXECUTE302_MESSAGE_LENGTH_OFFSET]))
113
+ );
114
+
115
+ uint64 messageLength = uint64(bytes8(_encoded[EXECUTE302_MESSAGE_LENGTH_OFFSET:EXECUTE302_MESSAGE_OFFSET]));
116
+ uint256 cursor = EXECUTE302_MESSAGE_OFFSET;
117
+
118
+ executionParams.message = _encoded[cursor:cursor + messageLength];
119
+ cursor += messageLength;
120
+
121
+ uint64 extraDataLength = uint64(bytes8(_encoded[cursor:cursor + EXTRA_DATA_LENGTH_SIZE]));
122
+ cursor += EXTRA_DATA_LENGTH_SIZE;
123
+
124
+ executionParams.extraData = _encoded[cursor:cursor + extraDataLength];
125
+ cursor += extraDataLength;
126
+
127
+ nativeDropParams = _nativeDrop(_encoded[cursor:]);
128
+ }
129
+
130
+ uint8 internal constant NATIVE_DROP_RECEIVER_SIZE = 20; // address
131
+ uint8 internal constant NATIVE_DROP_AMOUNT_SIZE = 9; // uint72
132
+ uint8 internal constant NATIVE_DROP_PARAM_SIZE = 29; // 20 + 9
133
+ function _nativeDrop(
134
+ bytes calldata _encoded
135
+ ) internal pure returns (IExecutor.NativeDropParams[] memory nativeDropParams) {
136
+ uint256 cursor = 0;
137
+ uint256 nativeDropParamsLength = _encoded.length / NATIVE_DROP_PARAM_SIZE;
138
+
139
+ nativeDropParams = new IExecutor.NativeDropParams[](nativeDropParamsLength);
140
+ for (uint256 i = 0; i < nativeDropParamsLength; i++) {
141
+ nativeDropParams[i].receiver = address(bytes20(_encoded[cursor:cursor + NATIVE_DROP_RECEIVER_SIZE]));
142
+ cursor += NATIVE_DROP_RECEIVER_SIZE;
143
+ nativeDropParams[i].amount = uint256(uint72(bytes9(_encoded[cursor:cursor + NATIVE_DROP_AMOUNT_SIZE])));
144
+ cursor += NATIVE_DROP_AMOUNT_SIZE;
145
+ }
146
+ }
147
+ }
@@ -0,0 +1,58 @@
1
+ // SPDX-License-Identifier: BUSL-1.1
2
+
3
+ pragma solidity 0.8.22;
4
+
5
+ import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
6
+ import { Origin } from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol";
7
+
8
+ import { Executor } from "../Executor.sol";
9
+ import { ExecutorDecoder } from "./ExecutorDecoder.sol";
10
+ import { DecompressorExtension } from "./DecompressorExtension.sol";
11
+
12
+ contract ExecutorDecompressor is Ownable, DecompressorExtension {
13
+ Executor public immutable executor;
14
+
15
+ constructor(Executor _executor) {
16
+ executor = _executor;
17
+ }
18
+
19
+ function nativeDrop(bytes calldata _encoded) external onlyOwner {
20
+ (
21
+ Origin memory origin,
22
+ uint32 dstEid,
23
+ address oapp,
24
+ Executor.NativeDropParams[] memory nativeDropParams,
25
+ uint256 nativeDropGasLimit
26
+ ) = ExecutorDecoder.nativeDrop(_encoded);
27
+
28
+ executor.nativeDrop(origin, dstEid, oapp, nativeDropParams, nativeDropGasLimit);
29
+ }
30
+
31
+ function execute301(bytes calldata _encoded) external onlyOwner {
32
+ (bytes memory packet, uint256 gasLimit) = ExecutorDecoder.execute301(_encoded);
33
+
34
+ executor.execute301(packet, gasLimit);
35
+ }
36
+
37
+ function nativeDropAndExecute301(bytes calldata _encoded) external onlyOwner {
38
+ (
39
+ Origin memory origin,
40
+ Executor.NativeDropParams[] memory nativeDropParams,
41
+ uint256 nativeDropGasLimit,
42
+ bytes memory packet,
43
+ uint256 gasLimit
44
+ ) = ExecutorDecoder.nativeDropAndExecute301(_encoded);
45
+
46
+ executor.nativeDropAndExecute301(origin, nativeDropParams, nativeDropGasLimit, packet, gasLimit);
47
+ }
48
+
49
+ function nativeDropAndExecute302(bytes calldata _encoded) external onlyOwner {
50
+ (
51
+ Executor.NativeDropParams[] memory nativeDropParams,
52
+ uint256 nativeDropGasLimit,
53
+ Executor.ExecutionParams memory executionParams
54
+ ) = ExecutorDecoder.nativeDropAndExecute302(_encoded);
55
+
56
+ executor.nativeDropAndExecute302(nativeDropParams, nativeDropGasLimit, executionParams);
57
+ }
58
+ }
@@ -0,0 +1,47 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity >=0.8.0;
4
+
5
+ import { Origin } from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol";
6
+
7
+ import { IWorker } from "./IWorker.sol";
8
+ import { ILayerZeroExecutor } from "./ILayerZeroExecutor.sol";
9
+ import { ILayerZeroReadExecutor } from "./ILayerZeroReadExecutor.sol";
10
+
11
+ interface IExecutor is IWorker, ILayerZeroExecutor, ILayerZeroReadExecutor {
12
+ struct DstConfigParam {
13
+ uint32 dstEid;
14
+ uint64 lzReceiveBaseGas;
15
+ uint64 lzComposeBaseGas;
16
+ uint16 multiplierBps;
17
+ uint128 floorMarginUSD;
18
+ uint128 nativeCap;
19
+ }
20
+
21
+ struct DstConfig {
22
+ uint64 lzReceiveBaseGas;
23
+ uint16 multiplierBps;
24
+ uint128 floorMarginUSD; // uses priceFeed PRICE_RATIO_DENOMINATOR
25
+ uint128 nativeCap;
26
+ uint64 lzComposeBaseGas;
27
+ }
28
+
29
+ struct ExecutionParams {
30
+ address receiver;
31
+ Origin origin;
32
+ bytes32 guid;
33
+ bytes message;
34
+ bytes extraData;
35
+ uint256 gasLimit;
36
+ }
37
+
38
+ struct NativeDropParams {
39
+ address receiver;
40
+ uint256 amount;
41
+ }
42
+
43
+ event DstConfigSet(DstConfigParam[] params);
44
+ event NativeDropApplied(Origin origin, uint32 dstEid, address oapp, NativeDropParams[] params, bool[] success);
45
+
46
+ function dstConfig(uint32 _dstEid) external view returns (uint64, uint16, uint128, uint128, uint64);
47
+ }
@@ -0,0 +1,56 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity >=0.8.0;
4
+
5
+ import { IExecutor } from "./IExecutor.sol";
6
+
7
+ interface IExecutorFeeLib {
8
+ struct FeeParams {
9
+ address priceFeed;
10
+ uint32 dstEid;
11
+ address sender;
12
+ uint256 calldataSize;
13
+ uint16 defaultMultiplierBps;
14
+ }
15
+
16
+ struct FeeParamsForRead {
17
+ address priceFeed;
18
+ address sender;
19
+ uint16 defaultMultiplierBps;
20
+ }
21
+
22
+ error Executor_NoOptions();
23
+ error Executor_NativeAmountExceedsCap(uint256 amount, uint256 cap);
24
+ error Executor_UnsupportedOptionType(uint8 optionType);
25
+ error Executor_InvalidExecutorOptions(uint256 cursor);
26
+ error Executor_ZeroLzReceiveGasProvided();
27
+ error Executor_ZeroLzComposeGasProvided();
28
+ error Executor_ZeroCalldataSizeProvided();
29
+ error Executor_EidNotSupported(uint32 eid);
30
+
31
+ function getFeeOnSend(
32
+ FeeParams calldata _params,
33
+ IExecutor.DstConfig calldata _dstConfig,
34
+ bytes calldata _options
35
+ ) external returns (uint256 fee);
36
+
37
+ function getFee(
38
+ FeeParams calldata _params,
39
+ IExecutor.DstConfig calldata _dstConfig,
40
+ bytes calldata _options
41
+ ) external view returns (uint256 fee);
42
+
43
+ function getFeeOnSend(
44
+ FeeParamsForRead calldata _params,
45
+ IExecutor.DstConfig calldata _dstConfig,
46
+ bytes calldata _options
47
+ ) external returns (uint256 fee);
48
+
49
+ function getFee(
50
+ FeeParamsForRead calldata _params,
51
+ IExecutor.DstConfig calldata _dstConfig,
52
+ bytes calldata _options
53
+ ) external view returns (uint256 fee);
54
+
55
+ function version() external view returns (uint64 major, uint8 minor);
56
+ }
@@ -0,0 +1,29 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity >=0.8.0;
4
+
5
+ interface ILayerZeroExecutor {
6
+ // @notice query price and assign jobs at the same time
7
+ // @param _dstEid - the destination endpoint identifier
8
+ // @param _sender - the source sending contract address. executors may apply price discrimination to senders
9
+ // @param _calldataSize - dynamic data size of message + caller params
10
+ // @param _options - optional parameters for extra service plugins, e.g. sending dust tokens at the destination chain
11
+ function assignJob(
12
+ uint32 _dstEid,
13
+ address _sender,
14
+ uint256 _calldataSize,
15
+ bytes calldata _options
16
+ ) external returns (uint256 price);
17
+
18
+ // @notice query the executor price for relaying the payload and its proof to the destination chain
19
+ // @param _dstEid - the destination endpoint identifier
20
+ // @param _sender - the source sending contract address. executors may apply price discrimination to senders
21
+ // @param _calldataSize - dynamic data size of message + caller params
22
+ // @param _options - optional parameters for extra service plugins, e.g. sending dust tokens at the destination chain
23
+ function getFee(
24
+ uint32 _dstEid,
25
+ address _sender,
26
+ uint256 _calldataSize,
27
+ bytes calldata _options
28
+ ) external view returns (uint256 price);
29
+ }
@@ -0,0 +1,61 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity >=0.8.0;
4
+
5
+ interface ILayerZeroPriceFeed {
6
+ /**
7
+ * @dev
8
+ * priceRatio: (USD price of 1 unit of remote native token in unit of local native token) * PRICE_RATIO_DENOMINATOR
9
+ */
10
+
11
+ struct Price {
12
+ uint128 priceRatio; // float value * 10 ^ 20, decimal awared. for aptos to evm, the basis would be (10^18 / 10^8) * 10 ^20 = 10 ^ 30.
13
+ uint64 gasPriceInUnit; // for evm, it is in wei, for aptos, it is in octas.
14
+ uint32 gasPerByte;
15
+ }
16
+
17
+ struct UpdatePrice {
18
+ uint32 eid;
19
+ Price price;
20
+ }
21
+
22
+ /**
23
+ * @dev
24
+ * ArbGasInfo.go:GetPricesInArbGas
25
+ *
26
+ */
27
+ struct ArbitrumPriceExt {
28
+ uint64 gasPerL2Tx; // L2 overhead
29
+ uint32 gasPerL1CallDataByte;
30
+ }
31
+
32
+ struct UpdatePriceExt {
33
+ uint32 eid;
34
+ Price price;
35
+ ArbitrumPriceExt extend;
36
+ }
37
+
38
+ error LZ_PriceFeed_OnlyPriceUpdater();
39
+ error LZ_PriceFeed_InsufficientFee(uint256 provided, uint256 required);
40
+ error LZ_PriceFeed_NotAnOPStack(uint32 l2Eid);
41
+
42
+ function nativeTokenPriceUSD() external view returns (uint128);
43
+
44
+ function getFee(uint32 _dstEid, uint256 _callDataSize, uint256 _gas) external view returns (uint256);
45
+
46
+ function getPrice(uint32 _dstEid) external view returns (Price memory);
47
+
48
+ function getPriceRatioDenominator() external view returns (uint128);
49
+
50
+ function estimateFeeByEid(
51
+ uint32 _dstEid,
52
+ uint256 _callDataSize,
53
+ uint256 _gas
54
+ ) external view returns (uint256 fee, uint128 priceRatio, uint128 priceRatioDenominator, uint128 nativePriceUSD);
55
+
56
+ function estimateFeeOnSend(
57
+ uint32 _dstEid,
58
+ uint256 _callDataSize,
59
+ uint256 _gas
60
+ ) external payable returns (uint256 fee, uint128 priceRatio, uint128 priceRatioDenominator, uint128 nativePriceUSD);
61
+ }
@@ -0,0 +1,15 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity >=0.8.0;
4
+
5
+ interface ILayerZeroReadExecutor {
6
+ // @notice query price and assign jobs at the same time
7
+ // @param _sender - the source sending contract address. executors may apply price discrimination to senders
8
+ // @param _options - optional parameters for extra service plugins, e.g. sending dust tokens at the destination chain
9
+ function assignJob(address _sender, bytes calldata _options) external returns (uint256 fee);
10
+
11
+ // @notice query the executor price for executing the payload on this chain
12
+ // @param _sender - the source sending contract address. executors may apply price discrimination to senders
13
+ // @param _options - optional parameters for extra service plugins, e.g. sending dust tokens
14
+ function getFee(address _sender, bytes calldata _options) external view returns (uint256 fee);
15
+ }
@@ -0,0 +1,19 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity >=0.8.0;
4
+
5
+ interface ILayerZeroTreasury {
6
+ function getFee(
7
+ address _sender,
8
+ uint32 _dstEid,
9
+ uint256 _totalNativeFee,
10
+ bool _payInLzToken
11
+ ) external view returns (uint256 fee);
12
+
13
+ function payFee(
14
+ address _sender,
15
+ uint32 _dstEid,
16
+ uint256 _totalNativeFee,
17
+ bool _payInLzToken
18
+ ) external payable returns (uint256 fee);
19
+ }
@@ -0,0 +1,29 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity >=0.8.0;
4
+
5
+ interface IWorker {
6
+ event SetWorkerLib(address workerLib);
7
+ event SetPriceFeed(address priceFeed);
8
+ event SetDefaultMultiplierBps(uint16 multiplierBps);
9
+ event SetSupportedOptionTypes(uint32 dstEid, uint8[] optionTypes);
10
+ event Withdraw(address lib, address to, uint256 amount);
11
+
12
+ error Worker_NotAllowed();
13
+ error Worker_OnlyMessageLib();
14
+ error Worker_RoleRenouncingDisabled();
15
+
16
+ function setPriceFeed(address _priceFeed) external;
17
+
18
+ function priceFeed() external view returns (address);
19
+
20
+ function setDefaultMultiplierBps(uint16 _multiplierBps) external;
21
+
22
+ function defaultMultiplierBps() external view returns (uint16);
23
+
24
+ function withdrawFee(address _lib, address _to, uint256 _amount) external;
25
+
26
+ function setSupportedOptionTypes(uint32 _eid, uint8[] calldata _optionTypes) external;
27
+
28
+ function getSupportedOptionTypes(uint32 _eid) external view returns (uint8[] memory);
29
+ }