@layerzerolabs/layerzero-v2-ton 3.0.19-ton.0 → 3.0.19-ton.1
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.
- package/CHANGELOG.md +6 -0
- package/build/AllStorages.compiled.json +1 -1
- package/build/AllStorages.test.compiled.json +1 -1
- package/build/BaseContract.test.compiled.json +1 -1
- package/build/Channel.compiled.json +1 -1
- package/build/Channel.permissions.test.compiled.json +1 -1
- package/build/ChannelBurn.test.compiled.json +1 -1
- package/build/ChannelCommitPacket.test.compiled.json +1 -1
- package/build/ChannelConfig.test.compiled.json +1 -1
- package/build/ChannelInitialize.test.compiled.json +1 -1
- package/build/ChannelMsglibIntegration.test.compiled.json +1 -1
- package/build/ChannelMsglibSendCallback.test.compiled.json +1 -1
- package/build/ChannelNilify.test.compiled.json +1 -1
- package/build/ChannelReceive.test.compiled.json +1 -1
- package/build/ChannelReceiveCallback.test.compiled.json +1 -1
- package/build/ChannelReceiveView.test.compiled.json +1 -1
- package/build/ChannelSend.test.compiled.json +1 -1
- package/build/Classlib.test.compiled.json +1 -1
- package/build/ComputeDataSizeGas.test.compiled.json +1 -1
- package/build/Connection.compiled.json +1 -1
- package/build/Controller.assertions.test.compiled.json +1 -1
- package/build/Controller.compiled.json +1 -1
- package/build/Controller.permissions.test.compiled.json +1 -1
- package/build/Controller.test.compiled.json +1 -1
- package/build/Counter.compiled.json +1 -1
- package/build/Counter.permissions.test.compiled.json +1 -1
- package/build/Counter.setters.test.compiled.json +1 -1
- package/build/Counter.test.compiled.json +1 -1
- package/build/Dvn.compiled.json +1 -1
- package/build/Dvn.test.compiled.json +1 -1
- package/build/DvnFeeLib.compiled.json +1 -1
- package/build/DvnPermissions.test.compiled.json +1 -1
- package/build/Endpoint.compiled.json +1 -1
- package/build/Endpoint.permissions.test.compiled.json +1 -1
- package/build/Endpoint.test.compiled.json +1 -1
- package/build/EndpointSetEpConfigDefaults.test.compiled.json +1 -1
- package/build/Executor.compiled.json +1 -1
- package/build/Executor.test.compiled.json +1 -1
- package/build/ExecutorFeeLib.compiled.json +1 -1
- package/build/ExecutorPermissions.test.compiled.json +1 -1
- package/build/LzClasses.test.compiled.json +1 -1
- package/build/LzUtil.test.compiled.json +1 -1
- package/build/MsgData.test.compiled.json +1 -1
- package/build/MsglibPacketCodec.test.compiled.json +1 -1
- package/build/PipelinedOutOfOrder.test.compiled.json +1 -1
- package/build/PriceFeedCache.compiled.json +1 -1
- package/build/PriceFeedCache.permissions.test.compiled.json +1 -1
- package/build/PriceFeedCache.test.compiled.json +1 -1
- package/build/Proxy.compiled.json +1 -1
- package/build/Proxy.permissions.test.compiled.json +1 -1
- package/build/Proxy.test.compiled.json +1 -1
- package/build/SmlConnection.compiled.json +1 -1
- package/build/SmlConnection.permissions.test.compiled.json +1 -1
- package/build/SmlConnection.test.compiled.json +1 -1
- package/build/SmlManager.compiled.json +1 -1
- package/build/SmlManager.permissions.test.compiled.json +1 -1
- package/build/SmlManager.test.compiled.json +1 -1
- package/build/Uln.compiled.json +1 -1
- package/build/Uln.test.compiled.json +1 -1
- package/build/UlnConnection.compiled.json +1 -1
- package/build/UlnConnection.test.compiled.json +1 -1
- package/build/UlnConnectionPermissions.test.compiled.json +1 -1
- package/build/UlnManagement.test.compiled.json +1 -1
- package/build/UlnManager.compiled.json +1 -1
- package/build/UlnManager.test.compiled.json +1 -1
- package/build/UlnManagerPermissions.test.compiled.json +1 -1
- package/build/UlnManagerUtil.test.compiled.json +1 -1
- package/build/UlnPermissions.test.compiled.json +1 -1
- package/build/UlnReceiveConfig.test.compiled.json +1 -1
- package/build/UlnSend.test.compiled.json +1 -1
- package/build/UlnSendConfig.test.compiled.json +1 -1
- package/build/UlnSendWithDvnFeeLib.test.compiled.json +1 -1
- package/build/UlnSendWithExecFeeLib.test.compiled.json +1 -1
- package/build/UlnSendWorkerFactory.test.compiled.json +1 -1
- package/build/UlnUtil.test.compiled.json +1 -1
- package/build/WorkerCore.test.compiled.json +1 -1
- package/build/badFeeLib1.test.compiled.json +1 -1
- package/build/badFeeLib10.test.compiled.json +1 -1
- package/build/badFeeLib11.test.compiled.json +1 -1
- package/build/badFeeLib12.test.compiled.json +1 -1
- package/build/badFeeLib2.test.compiled.json +1 -1
- package/build/badFeeLib3.test.compiled.json +1 -1
- package/build/badFeeLib4.test.compiled.json +1 -1
- package/build/badFeeLib5.test.compiled.json +1 -1
- package/build/badFeeLib6.test.compiled.json +1 -1
- package/build/badFeeLib7.test.compiled.json +1 -1
- package/build/badFeeLib8.test.compiled.json +1 -1
- package/build/badFeeLib9.test.compiled.json +1 -1
- package/package.json +5 -5
- package/src/classes/msgdata/LzReceiveStatus.fc +0 -1
- package/src/funC++/actions/call.fc +1 -0
- package/src/funC++/actions/deploy.fc +0 -1
- package/src/funC++/actions/destroy.fc +0 -1
- package/src/funC++/actions/dispatch.fc +0 -1
- package/src/funC++/actions/event.fc +0 -1
- package/src/funC++/actions/payment.fc +0 -1
- package/src/funC++/actions/sendJettons.fc +0 -1
- package/src/funC++/actions/utils.fc +0 -2
- package/src/funC++/baseInterface.fc +0 -2
- package/src/funC++/classlib.fc +0 -36
- package/src/funC++/contractMain.fc +2 -8
- package/src/funC++/dataStructures/DeterministicInsertionCircularQueue.fc +0 -1
- package/src/funC++/dataStructures/PipelinedOutOfOrder.fc +0 -1
- package/src/funC++/handlerCore.fc +2 -6
- package/src/funC++/stringlib.fc +0 -2
- package/src/funC++/testutils.fc +0 -1
- package/src/funC++/txnContext.fc +1 -1
- package/src/funC++/utils.fc +35 -0
- package/src/protocol/channel/callbackOpcodes.fc +10 -0
- package/src/protocol/channel/handler.fc +1032 -0
- package/src/protocol/channel/interface.fc +60 -0
- package/src/protocol/channel/main.fc +39 -0
- package/src/protocol/channel/storage.fc +55 -0
- package/src/protocol/controller/handler.fc +347 -0
- package/src/protocol/controller/interface.fc +25 -0
- package/src/protocol/controller/main.fc +29 -0
- package/src/protocol/controller/storage.fc +31 -0
- package/src/protocol/core/abstract/protocolHandler.fc +110 -0
- package/src/protocol/core/abstract/protocolMain.fc +30 -0
- package/src/protocol/core/baseStorage.fc +1 -2
- package/src/protocol/endpoint/handler.fc +426 -0
- package/src/protocol/endpoint/interface.fc +20 -0
- package/src/protocol/endpoint/main.fc +23 -0
- package/src/protocol/interfaces.fc +4 -0
- package/src/protocol/msglibs/BytesDecoder.fc +135 -0
- package/src/protocol/msglibs/BytesEncoder.fc +150 -0
- package/src/protocol/msglibs/interface.fc +16 -0
- package/src/protocol/msglibs/simpleMsglib/smlConnection/handler.fc +125 -0
- package/src/protocol/msglibs/simpleMsglib/smlConnection/interface.fc +3 -0
- package/src/protocol/msglibs/simpleMsglib/smlConnection/main.fc +19 -0
- package/src/protocol/msglibs/simpleMsglib/smlConnection/storage.fc +20 -0
- package/src/protocol/msglibs/simpleMsglib/smlManager/handler.fc +281 -0
- package/src/protocol/msglibs/simpleMsglib/smlManager/interface.fc +14 -0
- package/src/protocol/msglibs/simpleMsglib/smlManager/main.fc +24 -0
- package/src/protocol/msglibs/simpleMsglib/smlManager/storage.fc +38 -0
- package/src/protocol/msglibs/ultralightnode/callbackOpcodes.fc +1 -0
- package/src/protocol/msglibs/ultralightnode/feeLibInterface.fc +10 -0
- package/src/protocol/msglibs/ultralightnode/feeLibUtils.fc +51 -0
- package/src/protocol/msglibs/ultralightnode/msgdata/Attestation.fc +49 -0
- package/src/protocol/msglibs/ultralightnode/msgdata/DvnFeesPaidEvent.fc +26 -0
- package/src/protocol/msglibs/ultralightnode/msgdata/ExecutorFeePaidEvent.fc +23 -0
- package/src/protocol/msglibs/ultralightnode/msgdata/InitUln.fc +18 -0
- package/src/protocol/msglibs/ultralightnode/msgdata/InitUlnConnection.fc +62 -0
- package/src/protocol/msglibs/ultralightnode/msgdata/InitUlnManager.fc +18 -0
- package/src/protocol/msglibs/ultralightnode/msgdata/RentRefill.fc +18 -0
- package/src/protocol/msglibs/ultralightnode/msgdata/SetAdminWorkerAddresses.fc +18 -0
- package/src/protocol/msglibs/ultralightnode/msgdata/TreasuryFeeBps.fc +16 -0
- package/src/protocol/msglibs/ultralightnode/msgdata/UlnEvents.fc +26 -0
- package/src/protocol/msglibs/ultralightnode/msgdata/UlnReceiveConfig.fc +249 -0
- package/src/protocol/msglibs/ultralightnode/msgdata/UlnSend.fc +27 -0
- package/src/protocol/msglibs/ultralightnode/msgdata/UlnSendConfig.fc +170 -0
- package/src/protocol/msglibs/ultralightnode/msgdata/UlnVerification.fc +21 -0
- package/src/protocol/msglibs/ultralightnode/msgdata/UlnWorkerFeelibBytecode.fc +16 -0
- package/src/protocol/msglibs/ultralightnode/msgdata/UlnWorkerFeelibEvents.fc +58 -0
- package/src/protocol/msglibs/ultralightnode/msgdata/UlnWorkerFeelibInfo.fc +56 -0
- package/src/protocol/msglibs/ultralightnode/msgdata/VerificationStatus.fc +18 -0
- package/src/protocol/msglibs/ultralightnode/uln/handler.fc +803 -0
- package/src/protocol/msglibs/ultralightnode/uln/interface.fc +63 -0
- package/src/protocol/msglibs/ultralightnode/uln/main.fc +37 -0
- package/src/protocol/msglibs/ultralightnode/uln/storage.fc +43 -0
- package/src/protocol/msglibs/ultralightnode/ulnConnection/handler.fc +600 -0
- package/src/protocol/msglibs/ultralightnode/ulnConnection/interface.fc +36 -0
- package/src/protocol/msglibs/ultralightnode/ulnConnection/main.fc +32 -0
- package/src/protocol/msglibs/ultralightnode/ulnConnection/storage.fc +49 -0
- package/src/protocol/msglibs/ultralightnode/ulnConnection/utils.fc +141 -0
- package/src/protocol/msglibs/ultralightnode/ulnManager/handler.fc +495 -0
- package/src/protocol/msglibs/ultralightnode/ulnManager/interface.fc +59 -0
- package/src/protocol/msglibs/ultralightnode/ulnManager/main.fc +40 -0
- package/src/protocol/msglibs/ultralightnode/ulnManager/storage.fc +44 -0
- package/src/protocol/msglibs/ultralightnode/workerFeeLibs/common.fc +27 -0
- package/src/protocol/msglibs/ultralightnode/workerFeeLibs/dvnFeeLib/handler.fc +80 -0
- package/src/protocol/msglibs/ultralightnode/workerFeeLibs/dvnFeeLib/main.fc +4 -0
- package/src/protocol/msglibs/ultralightnode/workerFeeLibs/dvnFeeLib/storage.fc +26 -0
- package/src/protocol/msglibs/ultralightnode/workerFeeLibs/executorFeeLib/handler.fc +123 -0
- package/src/protocol/msglibs/ultralightnode/workerFeeLibs/executorFeeLib/main.fc +4 -0
- package/src/protocol/msglibs/ultralightnode/workerFeeLibs/executorFeeLib/storage.fc +29 -0
- package/src/protocol/msglibs/ultralightnode/workerFeeLibs/main.fc +3 -0
- package/src/protocol/msglibs/ultralightnode/workerFeeLibs/priceFeedFeeLib/main.fc +1 -0
- package/src/protocol/msglibs/ultralightnode/workerFeeLibs/priceFeedFeeLib/storage.fc +39 -0
- package/src/protocol/msglibs/ultralightnode/workerFeeLibs/ulnSendWorkerV1.fc +363 -0
- package/src/workers/core/abstract/workerHandler.fc +150 -0
- package/src/workers/core/interface.fc +25 -0
- package/src/workers/core/workerCoreStorage.fc +44 -0
- package/src/workers/dvn/handler.fc +332 -0
- package/src/workers/dvn/interface.fc +25 -0
- package/src/workers/dvn/main.fc +36 -0
- package/src/workers/dvn/storage.fc +27 -0
- package/src/workers/executor/handler.fc +110 -0
- package/src/workers/executor/interface.fc +19 -0
- package/src/workers/executor/main.fc +26 -0
- package/src/workers/executor/storage.fc +19 -0
- package/src/workers/msgdata/ExecuteParams.fc +29 -0
- package/src/workers/msgdata/NativeDrop.fc +16 -0
- package/src/workers/msgdata/ProxyMessage.fc +20 -0
- package/src/workers/msgdata/SetDict.fc +20 -0
- package/src/workers/msgdata/SetQuorum.fc +20 -0
- package/src/workers/msgdata/SignedRequest.fc +18 -0
- package/src/workers/priceFeedCache/handler.fc +114 -0
- package/src/workers/priceFeedCache/interface.fc +4 -0
- package/src/workers/priceFeedCache/main.fc +25 -0
- package/src/workers/priceFeedCache/storage.fc +21 -0
- package/src/workers/proxy/handler.fc +81 -0
- package/src/workers/proxy/interface.fc +11 -0
- package/src/workers/proxy/main.fc +17 -0
- package/src/workers/proxy/storage.fc +21 -0
- package/tests/testMain.fc +0 -1
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
#include "../../classes/lz/Packet.fc";
|
|
2
|
+
|
|
3
|
+
const int BytesDecoder::ERROR::invalidOptionSize = 1121;
|
|
4
|
+
const int BytesDecoder::ERROR::malformedOptions = 1122;
|
|
5
|
+
const int BytesDecoder::ERROR::malformedArray = 1123;
|
|
6
|
+
|
|
7
|
+
;; n_bytes should be <= 32
|
|
8
|
+
(slice, int) BytesDecoder::loadBytes(slice decoder, int nBytes) inline method_id {
|
|
9
|
+
int sliceBits = decoder.slice_bits();
|
|
10
|
+
if ((decoder.slice_refs() > 1) | (sliceBits % 8 != 0)) {
|
|
11
|
+
throw(BytesDecoder::ERROR::malformedOptions);
|
|
12
|
+
}
|
|
13
|
+
int sliceBytes = sliceBits / 8;
|
|
14
|
+
if (sliceBytes >= nBytes) {
|
|
15
|
+
return decoder.load_uint(nBytes * 8);
|
|
16
|
+
} else {
|
|
17
|
+
(decoder, int valueHeader) = decoder.load_uint(sliceBits);
|
|
18
|
+
int remainingBytes = nBytes - sliceBytes;
|
|
19
|
+
(slice next_data, int valueTail) = BytesDecoder::loadBytes(
|
|
20
|
+
decoder.preload_first_ref().begin_parse(),
|
|
21
|
+
remainingBytes
|
|
22
|
+
);
|
|
23
|
+
slice fullData = begin_cell()
|
|
24
|
+
.store_uint(valueHeader, sliceBits)
|
|
25
|
+
.store_uint(valueTail, remainingBytes * 8)
|
|
26
|
+
.as_slice();
|
|
27
|
+
return (next_data, fullData.preload_uint(nBytes * 8));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
;; byte- and cell- align the data
|
|
32
|
+
cell BytesDecoder::compactRemainder(slice data) impure inline {
|
|
33
|
+
int moduloBits = data.slice_bits(); ;; "misaligned" portion
|
|
34
|
+
throw_unless(
|
|
35
|
+
BytesDecoder::ERROR::malformedArray,
|
|
36
|
+
(data.slice_refs() <= 1) & ((moduloBits % 8) == 0)
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
if (moduloBits == 0) {
|
|
40
|
+
return empty_cell();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (data.slice_refs() == 0) {
|
|
44
|
+
return begin_cell().store_slice(data).end_cell();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
tuple retData = empty_tuple();
|
|
48
|
+
|
|
49
|
+
while (data.slice_refs() > 0) {
|
|
50
|
+
slice nextData = data.preload_first_ref().begin_parse();
|
|
51
|
+
int sliceBits = nextData.slice_bits();
|
|
52
|
+
int remainingBits = ((sliceBits + moduloBits) <= 1016) ? sliceBits : (1016 - moduloBits);
|
|
53
|
+
if (nextData.slice_refs() > 0) {
|
|
54
|
+
throw_if(BytesDecoder::ERROR::malformedArray, nextData.slice_bits() != 1016);
|
|
55
|
+
}
|
|
56
|
+
throw_unless(
|
|
57
|
+
BytesDecoder::ERROR::malformedArray,
|
|
58
|
+
(nextData.slice_refs() <= 1) & (sliceBits > 0) & (sliceBits % 8 == 0)
|
|
59
|
+
);
|
|
60
|
+
retData~tpush(
|
|
61
|
+
begin_cell()
|
|
62
|
+
.store_slice(data.scutlast(moduloBits, 0))
|
|
63
|
+
.store_slice(nextData.scutfirst(remainingBits, 0))
|
|
64
|
+
);
|
|
65
|
+
if ((nextData.slice_refs() == 0) & ((sliceBits - remainingBits) > 0)) {
|
|
66
|
+
retData~tpush(
|
|
67
|
+
begin_cell().store_slice(nextData.sskipfirst(remainingBits, 0))
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
data = nextData;
|
|
71
|
+
}
|
|
72
|
+
int idx = retData.tlen() - 1;
|
|
73
|
+
builder ret = retData.at(idx);
|
|
74
|
+
while (idx > 0) {
|
|
75
|
+
idx -= 1;
|
|
76
|
+
ret = retData.at(idx).store_ref(ret.end_cell());
|
|
77
|
+
}
|
|
78
|
+
return ret.end_cell();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
;; returns (optionType, option, optionsTail)
|
|
82
|
+
(int, cell, cell) BytesDecoder::nextOption(cell options) inline {
|
|
83
|
+
slice parsingOptions = options.begin_parse();
|
|
84
|
+
(parsingOptions, int executorId) = BytesDecoder::loadBytes(parsingOptions, 1);
|
|
85
|
+
(parsingOptions, int optionSizeInBytes) = BytesDecoder::loadBytes(parsingOptions, 2);
|
|
86
|
+
(parsingOptions, int optionType) = BytesDecoder::loadBytes(parsingOptions, 1);
|
|
87
|
+
(parsingOptions, int option) = BytesDecoder::loadBytes(parsingOptions, optionSizeInBytes);
|
|
88
|
+
return (
|
|
89
|
+
optionType,
|
|
90
|
+
begin_cell().store_uint(option, optionSizeInBytes * 8).end_cell(),
|
|
91
|
+
begin_cell().store_slice(parsingOptions).end_cell() ;; should retain the ref
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
;; (gas, value)
|
|
96
|
+
(int, int) BytesDecoder::decode<LzReceiveOption>(cell option) inline {
|
|
97
|
+
slice optionSlice = option.begin_parse();
|
|
98
|
+
int optionSizeInBytes = optionSlice.slice_bits() / 8;
|
|
99
|
+
if ((optionSizeInBytes != 16) & (optionSizeInBytes != 32)) {
|
|
100
|
+
throw(BytesDecoder::ERROR::invalidOptionSize);
|
|
101
|
+
}
|
|
102
|
+
if (optionSizeInBytes == 256 / 8) {
|
|
103
|
+
return (optionSlice~load_uint128(), optionSlice~load_uint128());
|
|
104
|
+
}
|
|
105
|
+
return (optionSlice~load_uint128(), 0);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
;; (amount, receiver)
|
|
109
|
+
(int, int) BytesDecoder::decode<NativeDropOption>(cell option) inline {
|
|
110
|
+
slice parsingOption = option.begin_parse();
|
|
111
|
+
int optionBytes = parsingOption.slice_bits() * 8;
|
|
112
|
+
throw_unless(BytesDecoder::ERROR::invalidOptionSize, optionBytes == (32 + 16));
|
|
113
|
+
return (
|
|
114
|
+
parsingOption~load_uint128(), ;; amount
|
|
115
|
+
parsingOption~load_uint256() ;; receiver
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
;; returns lz::Packet
|
|
120
|
+
cell BytesDecoder::decode<PacketV1>(cell encodedPacket) inline method_id {
|
|
121
|
+
slice parsingPacket = encodedPacket.begin_parse();
|
|
122
|
+
(parsingPacket, int packetVersion) = BytesDecoder::loadBytes(parsingPacket, 1);
|
|
123
|
+
(parsingPacket, int nonce) = BytesDecoder::loadBytes(parsingPacket, 8);
|
|
124
|
+
(parsingPacket, int srcEid) = BytesDecoder::loadBytes(parsingPacket, 4);
|
|
125
|
+
(parsingPacket, int srcOApp) = BytesDecoder::loadBytes(parsingPacket, 32);
|
|
126
|
+
(parsingPacket, int dstEid) = BytesDecoder::loadBytes(parsingPacket, 4);
|
|
127
|
+
(parsingPacket, int dstOApp) = BytesDecoder::loadBytes(parsingPacket, 32);
|
|
128
|
+
(parsingPacket, int guid) = BytesDecoder::loadBytes(parsingPacket, 32);
|
|
129
|
+
|
|
130
|
+
return lz::Packet::New(
|
|
131
|
+
lz::Path::New(srcEid, srcOApp, dstEid, dstOApp),
|
|
132
|
+
BytesDecoder::compactRemainder(parsingPacket),
|
|
133
|
+
nonce
|
|
134
|
+
).cl::set(lz::Packet::guid, guid);
|
|
135
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
#include "../../classes/lz/Path.fc";
|
|
2
|
+
#include "../../classes/lz/Packet.fc";
|
|
3
|
+
|
|
4
|
+
const int BytesEncoder::ERROR::malformed_subtree = 1217;
|
|
5
|
+
const int BytesEncoder::ERROR::malformed_data = 1218;
|
|
6
|
+
;; these are calculated relative to their position in the BytesEncoder::build<PacketV1> function
|
|
7
|
+
const int PacketV1::nonceOffsetBytes = 1;
|
|
8
|
+
const int PacketV1::nonceBytes = 8;
|
|
9
|
+
const int PacketV1::guidOffsetBytes = 81;
|
|
10
|
+
const int PacketV1::guidBytes = 32;
|
|
11
|
+
|
|
12
|
+
;; keeps a stack of builders on a tuple
|
|
13
|
+
tuple BytesEncoder::New() inline {
|
|
14
|
+
return unsafeTuple([begin_cell()]);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
;; appends a slice to the bytes encoder
|
|
18
|
+
tuple BytesEncoder::feed(tuple self, slice data) impure inline {
|
|
19
|
+
while (~ data.is_null()) {
|
|
20
|
+
;; verifies it is a linked list and only has one reference
|
|
21
|
+
throw_if(BytesEncoder::ERROR::malformed_subtree,data.slice_refs() > 1);
|
|
22
|
+
|
|
23
|
+
;; grabs the last builder on the tuple stack
|
|
24
|
+
int curBuilderIdx = self.tlen() - 1;
|
|
25
|
+
builder curBuilder = self.at(curBuilderIdx);
|
|
26
|
+
|
|
27
|
+
;; calculates the size in bytes of the current builder and the data
|
|
28
|
+
int curBuilderBytes = curBuilder.builder_bits() / 8;
|
|
29
|
+
int dataWidthBytes = data.slice_bits() / 8;
|
|
30
|
+
int fillsCurrentBuilder = (curBuilderBytes + dataWidthBytes) == 127;
|
|
31
|
+
|
|
32
|
+
;; if there is a partail byte at the end the check below makes it throw if it is
|
|
33
|
+
throw_if(BytesEncoder::ERROR::malformed_data, (data.slice_bits() % 8) != 0);
|
|
34
|
+
|
|
35
|
+
;; if the current builder + the size of data are greater
|
|
36
|
+
;; than 127 bytes, we need to break it up into multiple builders
|
|
37
|
+
if ((curBuilderBytes + dataWidthBytes) > 127) {
|
|
38
|
+
;; calculate the first X bytes to add to the current builder to fill it
|
|
39
|
+
int partialDataWidth = 127 - curBuilderBytes;
|
|
40
|
+
|
|
41
|
+
;; the remaining bytes length inside data after we move the reference to
|
|
42
|
+
;; where the partialDataWidth left off
|
|
43
|
+
dataWidthBytes = dataWidthBytes - partialDataWidth;
|
|
44
|
+
|
|
45
|
+
;; store the leading X bytes and saves to the tuple stack
|
|
46
|
+
self = self.tset(
|
|
47
|
+
curBuilderIdx,
|
|
48
|
+
curBuilder
|
|
49
|
+
.store_slice(data.preload_bits(partialDataWidth * 8))
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
;; moves the pointer
|
|
53
|
+
data = data.skip_bits(partialDataWidth * 8);
|
|
54
|
+
curBuilderIdx += 1;
|
|
55
|
+
|
|
56
|
+
;; adds a new builder to the tuple stack
|
|
57
|
+
curBuilder = begin_cell();
|
|
58
|
+
self~tpush(curBuilder);
|
|
59
|
+
}
|
|
60
|
+
;; If we entered the previous if statement, we have a fresh builder and less than
|
|
61
|
+
;; 127 bytes remaining at this slice in the data linked list. This will take the remaining
|
|
62
|
+
;; data inside the data slice and store in the builder.
|
|
63
|
+
;; If we didn't enter the previous if statement it will append the remaining bytes
|
|
64
|
+
;; of the data slice to the builder.
|
|
65
|
+
;; THhen updates the tuple stack with the updated writes
|
|
66
|
+
self = self.tset(curBuilderIdx, curBuilder.store_slice(data.sdskipfirst(0)));
|
|
67
|
+
|
|
68
|
+
;; if data linked list has more data extend the data stack and move the pointer of
|
|
69
|
+
;; data to the next item in the list.
|
|
70
|
+
ifnot (data.slice_refs_empty?()) {
|
|
71
|
+
|
|
72
|
+
;; if the current builder is full add a new builer on the tuple stack
|
|
73
|
+
if (fillsCurrentBuilder) {
|
|
74
|
+
self = self.tpush(begin_cell());
|
|
75
|
+
}
|
|
76
|
+
;; move the pointer
|
|
77
|
+
data = data.preload_first_ref().begin_parse();
|
|
78
|
+
} else {
|
|
79
|
+
;; cue to end the while loop, the data has been stored in the bytes encoded tuple stack
|
|
80
|
+
data = null();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return self;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
;; builds from the bottom up (of the stack) since data is built from the leaf node of a tree
|
|
88
|
+
cell BytesEncoder::serialize(tuple self) impure inline {
|
|
89
|
+
int idx = self.tlen() - 1;
|
|
90
|
+
;; if we're at the head
|
|
91
|
+
if (idx == 0) {
|
|
92
|
+
return self.at(idx).end_cell();
|
|
93
|
+
}
|
|
94
|
+
;; if second to last
|
|
95
|
+
if (idx == 1) {
|
|
96
|
+
return self.at(0).store_ref(self.at(1).end_cell()).end_cell();
|
|
97
|
+
}
|
|
98
|
+
builder last = self.at(idx);
|
|
99
|
+
builder secondLast = self.at(idx - 1);
|
|
100
|
+
while (idx > 1) {
|
|
101
|
+
idx -= 1;
|
|
102
|
+
last = secondLast.store_ref(last.end_cell());
|
|
103
|
+
secondLast = self.at(idx);
|
|
104
|
+
}
|
|
105
|
+
return secondLast.store_ref(last.end_cell()).end_cell();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
tuple BytesEncoder::feed<uint8>(tuple self, int data) inline {
|
|
109
|
+
return self.BytesEncoder::feed(begin_cell().store_uint8(data).as_slice());
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
tuple BytesEncoder::feed<uint16>(tuple self, int data) inline {
|
|
113
|
+
return self.BytesEncoder::feed(begin_cell().store_uint16(data).as_slice());
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
tuple BytesEncoder::feed<uint32>(tuple self, int data) inline {
|
|
117
|
+
return self.BytesEncoder::feed(begin_cell().store_uint32(data).as_slice());
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
tuple BytesEncoder::feed<uint64>(tuple self, int data) inline {
|
|
121
|
+
return self.BytesEncoder::feed(begin_cell().store_uint64(data).as_slice());
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
tuple BytesEncoder::feed<coins>(tuple self, int data) inline {
|
|
125
|
+
return self.BytesEncoder::feed(begin_cell().store_uint128(data).as_slice());
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
tuple BytesEncoder::feed<uint256>(tuple self, int data) inline {
|
|
129
|
+
return self.BytesEncoder::feed(begin_cell().store_uint256(data).as_slice());
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
tuple BytesEncoder::feed<cellRef>(tuple self, cell data) inline {
|
|
133
|
+
return self.BytesEncoder::feed(data.begin_parse());
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
tuple BytesEncoder::build<PacketV1>(cell $packet) inline {
|
|
137
|
+
cell $path = $packet.cl::get<objRef>(lz::Packet::path);
|
|
138
|
+
return unsafeTuple([
|
|
139
|
+
begin_cell() ;; 113 bytes of the 127
|
|
140
|
+
.store_uint8(1) ;; packetVersion uint8
|
|
141
|
+
.store_uint64($packet.cl::get<uint64>(lz::Packet::nonce)) ;; nonce uint64
|
|
142
|
+
.store_uint32($path.cl::get<uint32>(lz::Path::srcEid)) ;; srcEid uint32
|
|
143
|
+
.store_uint256($path.cl::get<uint256>(lz::Path::srcOApp)) ;; sender bytes32
|
|
144
|
+
.store_uint32($path.cl::get<uint32>(lz::Path::dstEid)) ;; dstEid uint32
|
|
145
|
+
.store_uint256($path.cl::get<uint256>(lz::Path::dstOApp)) ;; receiver bytes32
|
|
146
|
+
.store_uint256($packet.cl::get<uint256>(lz::Packet::guid)) ;; guid bytes32
|
|
147
|
+
]).BytesEncoder::feed<cellRef>(
|
|
148
|
+
$packet.cl::get<cellRef>(lz::Packet::message) ;; message []bytes
|
|
149
|
+
);
|
|
150
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
;; All msglibs must have the path in their storage as field 1
|
|
2
|
+
const int MsglibConnection::PathFieldIdx = 1;
|
|
3
|
+
|
|
4
|
+
;; All msglibs are required to have a connection and a manager
|
|
5
|
+
const int MsglibManager::OP::GET_MSGLIB_INFO = "MsglibManager::OP::GET_MSGLIB_INFO"c;
|
|
6
|
+
|
|
7
|
+
const int MsglibManager::OP::DEPLOY_CONNECTION = "MsglibManager::OP::DEPLOY_CONNECTION"c;
|
|
8
|
+
|
|
9
|
+
const int Msglib::OP::RETURN_QUOTE = "Msglib::OP::RETURN_QUOTE"c;
|
|
10
|
+
|
|
11
|
+
const int MsglibConnection::OP::MSGLIB_CONNECTION_QUOTE = "MsglibConnection::OP::MSGLIB_CONNECTION_QUOTE"c;
|
|
12
|
+
const int MsglibConnection::OP::MSGLIB_CONNECTION_SEND = "MsglibConnection::OP::MSGLIB_CONNECTION_SEND"c;
|
|
13
|
+
const int MsglibConnection::OP::MSGLIB_CONNECTION_COMMIT_PACKET_CALLBACK = "MsglibConnection::OP::MSGLIB_CONNECTION_COMMIT_PACKET_CALLBACK"c;
|
|
14
|
+
const int MsglibConnection::OP::MSGLIB_CONNECTION_SYNC_CHANNEL_STATE = "MsglibConnection::OP::MSGLIB_CONNECTION_SYNC_CHANNEL_STATE"c;
|
|
15
|
+
|
|
16
|
+
const int Msglib::ERROR::onlyChannel = 288;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
#include "../../../core/abstract/protocolHandler.fc";
|
|
2
|
+
|
|
3
|
+
#include "../../../../classes/msgdata/ExtendedMd.fc";
|
|
4
|
+
#include "../../../../classes/msgdata/InitSmlConnection.fc";
|
|
5
|
+
#include "../../../../classes/msgdata/MdAddress.fc";
|
|
6
|
+
#include "../../../../classes/msgdata/MdObj.fc";
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
#include "../../../endpoint/interface.fc";
|
|
10
|
+
#include "../../interface.fc";
|
|
11
|
+
#include "../smlManager/interface.fc";
|
|
12
|
+
#include "interface.fc";
|
|
13
|
+
#include "../../../../funC++/classlib.fc";
|
|
14
|
+
|
|
15
|
+
;;; ================HELPER FUNCTIONS========================
|
|
16
|
+
|
|
17
|
+
int getChannelAddress() impure inline {
|
|
18
|
+
return getContractStorage().cl::get<address>(SmlConnection::channelAddress);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
() assertChannel() impure inline {
|
|
22
|
+
throw_unless(
|
|
23
|
+
Msglib::ERROR::onlyChannel,
|
|
24
|
+
getCaller() == getChannelAddress()
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
;;; ================INTERFACE FUNCTIONS=====================
|
|
29
|
+
|
|
30
|
+
(cell, tuple) _initialize(cell $initSmlConnection) impure inline {
|
|
31
|
+
(cell $storage, tuple actions) = preamble();
|
|
32
|
+
int channelAddress = $initSmlConnection
|
|
33
|
+
.cl::get<address>(md::InitSmlConnection::channelAddress);
|
|
34
|
+
return (
|
|
35
|
+
$storage.cl::set(SmlConnection::channelAddress, channelAddress),
|
|
36
|
+
actions
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
int _getEventSink() inline {
|
|
41
|
+
return getContractAddress();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
;;; ================PERMISSION FUNCTIONS=====================
|
|
45
|
+
|
|
46
|
+
() _checkPermissions(int op, cell $md) impure inline method_id {
|
|
47
|
+
if (op == MsglibConnection::OP::MSGLIB_CONNECTION_SEND) {
|
|
48
|
+
return assertChannel();
|
|
49
|
+
} elseif (op == MsglibConnection::OP::MSGLIB_CONNECTION_COMMIT_PACKET_CALLBACK) {
|
|
50
|
+
return assertChannel();
|
|
51
|
+
} elseif (op == SmlConnection::OP::SML_CONNECTION_COMMIT_PACKET) {
|
|
52
|
+
return assertOwner();
|
|
53
|
+
} elseif (op == MsglibConnection::OP::MSGLIB_CONNECTION_SYNC_CHANNEL_STATE) {
|
|
54
|
+
return assertChannel();
|
|
55
|
+
} else {
|
|
56
|
+
;; we must put a check for all opcodes to make sure we don't
|
|
57
|
+
;; mistakenly miss an opp code's permissions
|
|
58
|
+
throw(BaseInterface::ERROR::invalidOpcode);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
;;; =================HANDLERS================================
|
|
63
|
+
|
|
64
|
+
;; @in channel/handler.fc/send
|
|
65
|
+
;; @in_md LzSend
|
|
66
|
+
;; @out smlManager/handler.fc/msglibSend
|
|
67
|
+
;; @out_md ExtendedMd(LzSend, initialStorage, channelAddress)
|
|
68
|
+
tuple msglibConnectionSend(cell $lzSend) impure inline method_id {
|
|
69
|
+
(cell $storage, tuple actions) = preamble();
|
|
70
|
+
|
|
71
|
+
actions~pushAction<call>(
|
|
72
|
+
getOwner(), ;; smlManager
|
|
73
|
+
SmlManager::OP::SML_MANAGER_SEND,
|
|
74
|
+
md::ExtendedMd::New(
|
|
75
|
+
$lzSend,
|
|
76
|
+
getInitialStorage(),
|
|
77
|
+
$storage.cl::get<address>(SmlConnection::channelAddress)
|
|
78
|
+
)
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
return actions;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
;; @in smlManager/handler.fc/smlManagerCommitPacket
|
|
85
|
+
;; @in_md msglibCommitPacket
|
|
86
|
+
;; @out endpoint/handler.fc/commitPacket
|
|
87
|
+
;; @out_md MdObj { packet, initialStorage }
|
|
88
|
+
tuple smlConnectionCommitPacket(cell $mdAddress) impure inline method_id {
|
|
89
|
+
(_, tuple actions) = preamble();
|
|
90
|
+
|
|
91
|
+
actions~pushAction<call>(
|
|
92
|
+
$mdAddress.cl::get<address>(md::MdAddress::address),
|
|
93
|
+
Endpoint::OP::ENDPOINT_COMMIT_PACKET,
|
|
94
|
+
$mdAddress.cl::get<objRef>(md::MdAddress::md)
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
return actions;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
;; @in channel/handler.fc/commitPacket
|
|
101
|
+
;; @in_md msglibCommitPacketCallback
|
|
102
|
+
;; @out smlManager/handler.fc/smlManagerCommitPacketCallback
|
|
103
|
+
tuple msglibConnectionCommitPacketCallback(cell $mdObj) impure inline method_id {
|
|
104
|
+
(_, tuple actions) = preamble();
|
|
105
|
+
|
|
106
|
+
actions~pushAction<call>(
|
|
107
|
+
getOwner(),
|
|
108
|
+
SmlManager::OP::SML_MANAGER_COMMIT_PACKET_CALLBACK,
|
|
109
|
+
$mdObj
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
return actions;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
tuple syncChannelState(cell $mdObj) impure inline method_id {
|
|
116
|
+
(_, tuple actions) = preamble();
|
|
117
|
+
|
|
118
|
+
actions~pushAction<call>(
|
|
119
|
+
getChannelAddress(),
|
|
120
|
+
MsglibConnection::OP::MSGLIB_CONNECTION_SYNC_CHANNEL_STATE,
|
|
121
|
+
$mdObj
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
return actions;
|
|
125
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#include "../../../core/abstract/protocolMain.fc";
|
|
2
|
+
#include "../../interface.fc";
|
|
3
|
+
|
|
4
|
+
#include "handler.fc";
|
|
5
|
+
#include "interface.fc";
|
|
6
|
+
|
|
7
|
+
tuple _executeOpcode(int op, cell $md) impure inline {
|
|
8
|
+
if (op == MsglibConnection::OP::MSGLIB_CONNECTION_SEND) {
|
|
9
|
+
return msglibConnectionSend($md);
|
|
10
|
+
} elseif (op == SmlConnection::OP::SML_CONNECTION_COMMIT_PACKET) {
|
|
11
|
+
return smlConnectionCommitPacket($md);
|
|
12
|
+
} elseif (op == MsglibConnection::OP::MSGLIB_CONNECTION_COMMIT_PACKET_CALLBACK) {
|
|
13
|
+
return msglibConnectionCommitPacketCallback($md);
|
|
14
|
+
} elseif (op == MsglibConnection::OP::MSGLIB_CONNECTION_SYNC_CHANNEL_STATE) {
|
|
15
|
+
return syncChannelState($md);
|
|
16
|
+
}
|
|
17
|
+
throw(BaseInterface::ERROR::invalidOpcode);
|
|
18
|
+
return empty_tuple();
|
|
19
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#include "../../../core/baseStorage.fc";
|
|
2
|
+
#include "../../../../funC++/classlib.fc";
|
|
3
|
+
|
|
4
|
+
const int SmlConnection::NAME = "smlConn"u;
|
|
5
|
+
|
|
6
|
+
const int SmlConnection::baseStorage = 0;
|
|
7
|
+
const int SmlConnection::path = 1;
|
|
8
|
+
const int SmlConnection::channelAddress = 2;
|
|
9
|
+
|
|
10
|
+
;; @owner LayerZero admin EOA
|
|
11
|
+
cell SmlConnection::New(int owner, cell $path) method_id {
|
|
12
|
+
return cl::declare(
|
|
13
|
+
SmlConnection::NAME,
|
|
14
|
+
unsafeTuple([
|
|
15
|
+
[cl::t::objRef, BaseStorage::New(owner)], ;; SmlConnection::baseStorage
|
|
16
|
+
[cl::t::objRef, $path], ;; SmlConnection::path
|
|
17
|
+
[cl::t::address, NULLADDRESS] ;; SmlConnection::channelAddress
|
|
18
|
+
])
|
|
19
|
+
);
|
|
20
|
+
}
|