@layerzerolabs/layerzero-v2-ton 3.0.12-ton.0

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 (251) hide show
  1. package/CHANGELOG.md +67 -0
  2. package/README.md +15 -0
  3. package/build/AllStorages.boc +0 -0
  4. package/build/AllStorages.compiled.json +1 -0
  5. package/build/AllStorages.fif +4164 -0
  6. package/build/AllStorages.test.boc +0 -0
  7. package/build/AllStorages.test.compiled.json +1 -0
  8. package/build/AllStorages.test.fif +1831 -0
  9. package/build/BaseContract.test.boc +0 -0
  10. package/build/BaseContract.test.compiled.json +1 -0
  11. package/build/BaseContract.test.fif +3553 -0
  12. package/build/Channel.boc +0 -0
  13. package/build/Channel.compiled.json +1 -0
  14. package/build/Channel.fif +5001 -0
  15. package/build/Channel.permissions.test.boc +0 -0
  16. package/build/Channel.permissions.test.compiled.json +1 -0
  17. package/build/Channel.permissions.test.fif +7569 -0
  18. package/build/ChannelBurn.test.boc +0 -0
  19. package/build/ChannelBurn.test.compiled.json +1 -0
  20. package/build/ChannelBurn.test.fif +7454 -0
  21. package/build/ChannelCommitPacket.test.boc +0 -0
  22. package/build/ChannelCommitPacket.test.compiled.json +1 -0
  23. package/build/ChannelCommitPacket.test.fif +7981 -0
  24. package/build/ChannelConfig.test.boc +0 -0
  25. package/build/ChannelConfig.test.compiled.json +1 -0
  26. package/build/ChannelConfig.test.fif +7442 -0
  27. package/build/ChannelInitialize.test.boc +0 -0
  28. package/build/ChannelInitialize.test.compiled.json +1 -0
  29. package/build/ChannelInitialize.test.fif +7289 -0
  30. package/build/ChannelMsglibIntegration.test.boc +0 -0
  31. package/build/ChannelMsglibIntegration.test.compiled.json +1 -0
  32. package/build/ChannelMsglibIntegration.test.fif +7404 -0
  33. package/build/ChannelMsglibSendCallback.test.boc +0 -0
  34. package/build/ChannelMsglibSendCallback.test.compiled.json +1 -0
  35. package/build/ChannelMsglibSendCallback.test.fif +7711 -0
  36. package/build/ChannelNilify.test.boc +0 -0
  37. package/build/ChannelNilify.test.compiled.json +1 -0
  38. package/build/ChannelNilify.test.fif +7672 -0
  39. package/build/ChannelReceive.test.boc +0 -0
  40. package/build/ChannelReceive.test.compiled.json +1 -0
  41. package/build/ChannelReceive.test.fif +7702 -0
  42. package/build/ChannelReceiveCallback.test.boc +0 -0
  43. package/build/ChannelReceiveCallback.test.compiled.json +1 -0
  44. package/build/ChannelReceiveCallback.test.fif +7549 -0
  45. package/build/ChannelReceiveView.test.boc +0 -0
  46. package/build/ChannelReceiveView.test.compiled.json +1 -0
  47. package/build/ChannelReceiveView.test.fif +7352 -0
  48. package/build/ChannelSend.test.boc +0 -0
  49. package/build/ChannelSend.test.compiled.json +1 -0
  50. package/build/ChannelSend.test.fif +7658 -0
  51. package/build/Classlib.test.boc +0 -0
  52. package/build/Classlib.test.compiled.json +1 -0
  53. package/build/Classlib.test.fif +4728 -0
  54. package/build/Connection.boc +0 -0
  55. package/build/Connection.compiled.json +1 -0
  56. package/build/Connection.fif +3503 -0
  57. package/build/Connection.test.boc +0 -0
  58. package/build/Connection.test.compiled.json +1 -0
  59. package/build/Connection.test.fif +6575 -0
  60. package/build/Controller.assertions.test.boc +0 -0
  61. package/build/Controller.assertions.test.compiled.json +1 -0
  62. package/build/Controller.assertions.test.fif +6130 -0
  63. package/build/Controller.boc +0 -0
  64. package/build/Controller.compiled.json +1 -0
  65. package/build/Controller.fif +3195 -0
  66. package/build/Controller.permissions.test.boc +0 -0
  67. package/build/Controller.permissions.test.compiled.json +1 -0
  68. package/build/Controller.permissions.test.fif +6237 -0
  69. package/build/Controller.test.boc +0 -0
  70. package/build/Controller.test.compiled.json +1 -0
  71. package/build/Controller.test.fif +6400 -0
  72. package/build/Counter.boc +0 -0
  73. package/build/Counter.compiled.json +1 -0
  74. package/build/Counter.fif +4809 -0
  75. package/build/Counter.permissions.test.boc +0 -0
  76. package/build/Counter.permissions.test.compiled.json +1 -0
  77. package/build/Counter.permissions.test.fif +7106 -0
  78. package/build/Counter.setters.test.boc +0 -0
  79. package/build/Counter.setters.test.compiled.json +1 -0
  80. package/build/Counter.setters.test.fif +7083 -0
  81. package/build/Counter.test.boc +0 -0
  82. package/build/Counter.test.compiled.json +1 -0
  83. package/build/Counter.test.fif +7540 -0
  84. package/build/Dvn.boc +0 -0
  85. package/build/Dvn.compiled.json +1 -0
  86. package/build/Dvn.fif +2923 -0
  87. package/build/Dvn.test.boc +0 -0
  88. package/build/Dvn.test.compiled.json +1 -0
  89. package/build/Dvn.test.fif +5753 -0
  90. package/build/Endpoint.boc +0 -0
  91. package/build/Endpoint.compiled.json +1 -0
  92. package/build/Endpoint.fif +3694 -0
  93. package/build/Endpoint.permissions.test.boc +0 -0
  94. package/build/Endpoint.permissions.test.compiled.json +1 -0
  95. package/build/Endpoint.permissions.test.fif +6211 -0
  96. package/build/Endpoint.test.boc +0 -0
  97. package/build/Endpoint.test.compiled.json +1 -0
  98. package/build/Endpoint.test.fif +6899 -0
  99. package/build/EndpointSetEpConfigDefaults.test.boc +0 -0
  100. package/build/EndpointSetEpConfigDefaults.test.compiled.json +1 -0
  101. package/build/EndpointSetEpConfigDefaults.test.fif +6529 -0
  102. package/build/Executor.boc +0 -0
  103. package/build/Executor.compiled.json +1 -0
  104. package/build/Executor.fif +2731 -0
  105. package/build/Executor.test.boc +0 -0
  106. package/build/Executor.test.compiled.json +1 -0
  107. package/build/Executor.test.fif +5822 -0
  108. package/build/LzClasses.test.boc +0 -0
  109. package/build/LzClasses.test.compiled.json +1 -0
  110. package/build/LzClasses.test.fif +4457 -0
  111. package/build/LzUtil.test.boc +0 -0
  112. package/build/LzUtil.test.compiled.json +1 -0
  113. package/build/LzUtil.test.fif +1831 -0
  114. package/build/MsgData.test.boc +0 -0
  115. package/build/MsgData.test.compiled.json +1 -0
  116. package/build/MsgData.test.fif +4318 -0
  117. package/build/MsglibPacketCodec.test.boc +0 -0
  118. package/build/MsglibPacketCodec.test.compiled.json +1 -0
  119. package/build/MsglibPacketCodec.test.fif +4851 -0
  120. package/build/MultiSig.boc +0 -0
  121. package/build/MultiSig.compiled.json +1 -0
  122. package/build/MultiSig.fif +727 -0
  123. package/build/MultiSigOrder.boc +0 -0
  124. package/build/MultiSigOrder.compiled.json +1 -0
  125. package/build/MultiSigOrder.fif +650 -0
  126. package/build/PipelinedOutOfOrder.test.boc +0 -0
  127. package/build/PipelinedOutOfOrder.test.compiled.json +1 -0
  128. package/build/PipelinedOutOfOrder.test.fif +2188 -0
  129. package/build/SmlConnection.boc +0 -0
  130. package/build/SmlConnection.compiled.json +1 -0
  131. package/build/SmlConnection.fif +2517 -0
  132. package/build/SmlConnection.permissions.test.boc +0 -0
  133. package/build/SmlConnection.permissions.test.compiled.json +1 -0
  134. package/build/SmlConnection.permissions.test.fif +5497 -0
  135. package/build/SmlConnection.test.boc +0 -0
  136. package/build/SmlConnection.test.compiled.json +1 -0
  137. package/build/SmlConnection.test.fif +5494 -0
  138. package/build/SmlManager.boc +0 -0
  139. package/build/SmlManager.compiled.json +1 -0
  140. package/build/SmlManager.fif +3904 -0
  141. package/build/SmlManager.permissions.test.boc +0 -0
  142. package/build/SmlManager.permissions.test.compiled.json +1 -0
  143. package/build/SmlManager.permissions.test.fif +6018 -0
  144. package/build/SmlManager.test.boc +0 -0
  145. package/build/SmlManager.test.compiled.json +1 -0
  146. package/build/SmlManager.test.fif +6047 -0
  147. package/build/Uln.boc +0 -0
  148. package/build/Uln.compiled.json +1 -0
  149. package/build/Uln.fif +4841 -0
  150. package/build/Uln.test.boc +0 -0
  151. package/build/Uln.test.compiled.json +1 -0
  152. package/build/Uln.test.fif +7077 -0
  153. package/build/UlnManager.boc +0 -0
  154. package/build/UlnManager.compiled.json +1 -0
  155. package/build/UlnManager.fif +3851 -0
  156. package/build/UlnManager.test.boc +0 -0
  157. package/build/UlnManager.test.compiled.json +1 -0
  158. package/build/UlnManager.test.fif +6571 -0
  159. package/build/UlnReceiveConfig.test.boc +0 -0
  160. package/build/UlnReceiveConfig.test.compiled.json +1 -0
  161. package/build/UlnReceiveConfig.test.fif +4413 -0
  162. package/build/UlnSend.test.boc +0 -0
  163. package/build/UlnSend.test.compiled.json +1 -0
  164. package/build/UlnSend.test.fif +6576 -0
  165. package/build/UlnSendConfig.test.boc +0 -0
  166. package/build/UlnSendConfig.test.compiled.json +1 -0
  167. package/build/UlnSendConfig.test.fif +4431 -0
  168. package/build/UlnSendWorkerFactory.test.boc +0 -0
  169. package/build/UlnSendWorkerFactory.test.compiled.json +1 -0
  170. package/build/UlnSendWorkerFactory.test.fif +6683 -0
  171. package/build/UlnUtil.test.boc +0 -0
  172. package/build/UlnUtil.test.compiled.json +1 -0
  173. package/build/UlnUtil.test.fif +5873 -0
  174. package/build/WorkerCore.test.boc +0 -0
  175. package/build/WorkerCore.test.compiled.json +1 -0
  176. package/build/WorkerCore.test.fif +5630 -0
  177. package/build/ZroMinter.boc +0 -0
  178. package/build/ZroMinter.compiled.json +1 -0
  179. package/build/ZroMinter.fif +2300 -0
  180. package/build/ZroWallet.boc +0 -0
  181. package/build/ZroWallet.compiled.json +1 -0
  182. package/build/ZroWallet.fif +2471 -0
  183. package/package.json +64 -0
  184. package/src/classes/lz/Attestation.fc +23 -0
  185. package/src/classes/lz/Config.fc +23 -0
  186. package/src/classes/lz/EpConfig.fc +91 -0
  187. package/src/classes/lz/MsglibInfo.fc +31 -0
  188. package/src/classes/lz/Packet.fc +202 -0
  189. package/src/classes/lz/Path.fc +56 -0
  190. package/src/classes/lz/ReceiveEpConfig.fc +24 -0
  191. package/src/classes/lz/SendEpConfig.fc +18 -0
  192. package/src/classes/lz/SmlJobAssigned.fc +20 -0
  193. package/src/classes/lz/Worker.fc +32 -0
  194. package/src/classes/msgdata/AddMsglib.fc +18 -0
  195. package/src/classes/msgdata/Amount.fc +16 -0
  196. package/src/classes/msgdata/Bool.fc +16 -0
  197. package/src/classes/msgdata/ChannelNonceInfo.fc +18 -0
  198. package/src/classes/msgdata/ClaimUnaccountedPoolFunds.fc +0 -0
  199. package/src/classes/msgdata/CoinsAmount.fc +16 -0
  200. package/src/classes/msgdata/CounterIncrement.fc +24 -0
  201. package/src/classes/msgdata/Deploy.fc +20 -0
  202. package/src/classes/msgdata/ExtendedMd.fc +20 -0
  203. package/src/classes/msgdata/GetMsglibCallback.fc +18 -0
  204. package/src/classes/msgdata/InitEndpoint.fc +16 -0
  205. package/src/classes/msgdata/InitSmlConnection.fc +16 -0
  206. package/src/classes/msgdata/InitUlnConnection.fc +18 -0
  207. package/src/classes/msgdata/LzReceiveStatus.fc +58 -0
  208. package/src/classes/msgdata/LzSend.fc +58 -0
  209. package/src/classes/msgdata/MdAddress.fc +18 -0
  210. package/src/classes/msgdata/MdEid.fc +18 -0
  211. package/src/classes/msgdata/MdObj.fc +18 -0
  212. package/src/classes/msgdata/MessagingReceipt.fc +22 -0
  213. package/src/classes/msgdata/MsglibSendCallback.fc +113 -0
  214. package/src/classes/msgdata/Nonce.fc +16 -0
  215. package/src/classes/msgdata/OptionsExtended.fc +20 -0
  216. package/src/classes/msgdata/OptionsV1.fc +27 -0
  217. package/src/classes/msgdata/OptionsV2.fc +34 -0
  218. package/src/classes/msgdata/PacketId.fc +18 -0
  219. package/src/classes/msgdata/PacketSent.fc +39 -0
  220. package/src/classes/msgdata/SetAddress.fc +16 -0
  221. package/src/classes/msgdata/SetEpConfig.fc +33 -0
  222. package/src/classes/msgdata/SetPeer.fc +18 -0
  223. package/src/classes/msgdata/SetSmlManagerConfig.fc +18 -0
  224. package/src/funC++/abstract/contractMainAbstract.fc +3 -0
  225. package/src/funC++/abstract/handlerAbstract.fc +12 -0
  226. package/src/funC++/actions/call.fc +51 -0
  227. package/src/funC++/actions/deploy.fc +118 -0
  228. package/src/funC++/actions/destroy.fc +28 -0
  229. package/src/funC++/actions/dispatch.fc +57 -0
  230. package/src/funC++/actions/event.fc +69 -0
  231. package/src/funC++/actions/payment.fc +52 -0
  232. package/src/funC++/actions/sendJettons.fc +76 -0
  233. package/src/funC++/actions/utils.fc +49 -0
  234. package/src/funC++/baseInterface.fc +16 -0
  235. package/src/funC++/classlib.fc +819 -0
  236. package/src/funC++/constants.fc +64 -0
  237. package/src/funC++/contractMain.fc +84 -0
  238. package/src/funC++/dataStructures/DeterministicInsertionCircularQueue.fc +155 -0
  239. package/src/funC++/dataStructures/PipelinedOutOfOrder.fc +93 -0
  240. package/src/funC++/handlerCore.fc +30 -0
  241. package/src/funC++/stdlib.fc +625 -0
  242. package/src/funC++/stringlib.fc +75 -0
  243. package/src/funC++/txnContext.fc +126 -0
  244. package/src/funC++/utils.fc +119 -0
  245. package/src/jettons/zro/minter.fc +120 -0
  246. package/src/jettons/zro/op-codes.fc +10 -0
  247. package/src/jettons/zro/params.fc +18 -0
  248. package/src/jettons/zro/utils.fc +33 -0
  249. package/src/jettons/zro/wallet.fc +261 -0
  250. package/tests/baseContractTest.fc +192 -0
  251. package/tests/testMain.fc +135 -0
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@layerzerolabs/layerzero-v2-ton",
3
+ "version": "3.0.12-ton.0",
4
+ "exports": {
5
+ ".": {
6
+ "types": "./dist/index.d.ts",
7
+ "import": "./dist/index.mjs",
8
+ "require": "./dist/index.cjs"
9
+ },
10
+ "./package.json": "./package.json"
11
+ },
12
+ "main": "./dist/index.cjs",
13
+ "types": "./dist/index.d.ts",
14
+ "files": [
15
+ "build/",
16
+ "src/classes/*/*.fc",
17
+ "src/funC++/actions/*.fc",
18
+ "src/funC++/abstract/*.fc",
19
+ "src/funC++/dataStructures/*.fc",
20
+ "src/funC++/*.fc",
21
+ "src/funC++/actions/sendJettons.fc",
22
+ "src/protocol/",
23
+ "src/jettons/zro/*.fc",
24
+ "tests/testMain.fc",
25
+ "tests/baseContractTest.fc"
26
+ ],
27
+ "scripts": {
28
+ "build": "$npm_execpath clean-prebuild && $npm_execpath build-all && $npm_execpath compile",
29
+ "build-all": "$npm_execpath blueprint build --all",
30
+ "build-single": "$npm_execpath blueprint build",
31
+ "clean": "$npm_execpath clean-prebuild && rimraf .turbo",
32
+ "clean-prebuild": "rimraf build",
33
+ "compile": "GIT_ROOT=$(git rev-parse --show-toplevel) docker compose run --rm compiler && yarn generate-artifacts",
34
+ "crc16xmodem": "$npm_execpath ts-node scripts/crc16xmodem.ts",
35
+ "generate-artifacts": "$npm_execpath ts-node scripts/generateArtifacts.ts",
36
+ "start": "$npm_execpath blueprint run",
37
+ "test": "$npm_execpath jest --verbose",
38
+ "test-local": "$npm_execpath compile && $npm_execpath test"
39
+ },
40
+ "dependencies": {
41
+ "crc-32": "^1.2.2"
42
+ },
43
+ "devDependencies": {
44
+ "@jest/globals": "^29.7.0",
45
+ "@ston-fi/funcbox": "^0.1.1",
46
+ "@ton/blueprint": "0.25.0-beta.1",
47
+ "@ton/core": "^0.59.0",
48
+ "@ton/crypto": "^3.3.0",
49
+ "@ton/sandbox": "^0.22.0",
50
+ "@ton/test-utils": "^0.4.2",
51
+ "@ton/ton": "^15.1.0",
52
+ "@types/jest": "^29.5.10",
53
+ "@types/node": "^20.10.5",
54
+ "jest": "^29.7.0",
55
+ "prettier": "^3.2.4",
56
+ "rimraf": "^5.0.5",
57
+ "ts-jest": "^29.1.1",
58
+ "ts-node": "^10.9.1",
59
+ "typescript": "~5.2.2"
60
+ },
61
+ "publishConfig": {
62
+ "access": "restricted"
63
+ }
64
+ }
@@ -0,0 +1,23 @@
1
+ #include "../../funC++/classlib.fc";
2
+
3
+ ;; required storage name
4
+ const int lz::Attestation::NAME = "Attest"u;
5
+
6
+ ;; field names
7
+ const int lz::Attestation::hash = 0; ;; hash
8
+ const int lz::Attestation::confirmations = 1; ;; uint64
9
+
10
+ cell lz::Attestation::New(int hash, int confirmations) inline method_id {
11
+ return cl::declare(
12
+ lz::Attestation::NAME,
13
+ unsafeTuple([
14
+ [cl::t::uint256, hash], ;; lz::Attestation::hash
15
+ [cl::t::uint64, confirmations] ;; lz::Attestation::confirmations
16
+ ])
17
+ );
18
+ }
19
+
20
+ int lz::Attestation::isValid(cell self, int hash, int confirmations) inline method_id {
21
+ return (self.cl::get<uint256>(lz::Attestation::hash) == hash) &
22
+ (self.cl::get<uint64>(lz::Attestation::confirmations) <= confirmations);
23
+ }
@@ -0,0 +1,23 @@
1
+ #include "../../funC++/classlib.fc";
2
+
3
+ ;; required storage name
4
+ const int lz::Config::NAME = "Config"u;
5
+
6
+ ;; field names
7
+ const int lz::Config::path = 0;
8
+ const int lz::Config::forwardingAddress = 1;
9
+ const int lz::Config::opCode = 2;
10
+ ;; provide an arbitrary config md that can be forwarded anywhere in the lz protocol that a config is accepted
11
+ const int lz::Config::config = 3;
12
+
13
+ cell lz::Config::New(cell $path, int forwardingAddress, int opCode, cell $config) inline method_id {
14
+ return cl::declare(
15
+ lz::Config::NAME,
16
+ unsafeTuple([
17
+ [cl::t::objRef, $path], ;; lz::Config::path
18
+ [cl::t::address, forwardingAddress], ;; lz::Config::forwardingAddress
19
+ [cl::t::uint32, opCode], ;; lz::Config::opCode
20
+ [cl::t::objRef, $config] ;; lz::Config::config
21
+ ])
22
+ );
23
+ }
@@ -0,0 +1,91 @@
1
+ #include "../../funC++/classlib.fc";
2
+
3
+ ;; ERRORS
4
+ const int lz::EpConfig::ERROR::sameMsglib = "sameMsglib"c & ERRORCODE_MASK;
5
+ const int lz::EpConfig::ERROR::invalidTimeoutExpiry = "invalidTimeoutExpiry"c & ERRORCODE_MASK;
6
+ const int lz::EpConfig::ERROR::invalidTimeoutReceiveMsglib = "invalidTimeoutReceiveMsglib"c & ERRORCODE_MASK;
7
+ const int lz::EpConfig::VALID = 42069 & ERRORCODE_MASK;
8
+
9
+ ;; required storage name
10
+ const int lz::EpConfig::NAME = "EpConfig"u;
11
+
12
+ ;; field names
13
+ const int lz::EpConfig::useDefaults = 0;
14
+ const int lz::EpConfig::sendMsglib = 1;
15
+ const int lz::EpConfig::sendMsglibConnection = 2;
16
+ const int lz::EpConfig::receiveMsglib = 3;
17
+ const int lz::EpConfig::receiveMsglibConnection = 4;
18
+ const int lz::EpConfig::timeoutReceiveMsglib = 5;
19
+ const int lz::EpConfig::timeoutReceiveMsglibConnection = 6;
20
+ const int lz::EpConfig::timeoutReceiveMsglibExpiry = 7;
21
+
22
+ cell lz::EpConfig::NewWithConnection(
23
+ int useDefaults,
24
+ int sendMsglib,
25
+ int sendMsglibConnection,
26
+ int receiveMsglib,
27
+ int receiveMsglibConnection,
28
+ int timeoutReceiveMsglib,
29
+ int timeoutReceiveMsglibConnection,
30
+ int timeoutReceiveMsglibExpiry
31
+ ) inline method_id {
32
+ return cl::declare(
33
+ lz::EpConfig::NAME,
34
+ unsafeTuple([
35
+ [cl::t::bool, useDefaults], ;; lz::EpConfig::useDefaults,
36
+ [cl::t::address, sendMsglib], ;; lz::EpConfig::sendMsglib,
37
+ [cl::t::address, sendMsglibConnection], ;; lz::EpConfig::sendMsglibConnection,
38
+ [cl::t::address, receiveMsglib], ;; lz::EpConfig::receiveMsglib,
39
+ [cl::t::address, receiveMsglibConnection], ;; lz::EpConfig::receiveMsglibConnection,
40
+ [cl::t::address, timeoutReceiveMsglib], ;; lz::EpConfig::timeoutReceiveMsglib,
41
+ [cl::t::address, timeoutReceiveMsglibConnection], ;; lz::EpConfig::timeoutReceiveMsglibConnection,
42
+ [cl::t::uint64, timeoutReceiveMsglibExpiry] ;; lz::EpConfig::timeoutReceiveMsglibExpiry
43
+ ])
44
+ );
45
+ }
46
+
47
+ cell lz::EpConfig::New(
48
+ int useDefaults,
49
+ int sendMsglib,
50
+ int receiveMsglib,
51
+ int timeoutReceiveMsglib,
52
+ int timeoutReceiveMsglibExpiry
53
+ ) inline method_id {
54
+ return lz::EpConfig::NewWithConnection(
55
+ useDefaults,
56
+ sendMsglib,
57
+ NULLADDRESS,
58
+ receiveMsglib,
59
+ NULLADDRESS,
60
+ timeoutReceiveMsglib,
61
+ NULLADDRESS,
62
+ timeoutReceiveMsglibExpiry
63
+ );
64
+ }
65
+
66
+ cell lz::EpConfig::NewWithDefaults() inline method_id {
67
+ return lz::EpConfig::New(true, NULLADDRESS, NULLADDRESS, NULLADDRESS, 0);
68
+ }
69
+
70
+ cell lz::EpConfig::NewFrom(int sendMsglib, int receiveMsglib) inline method_id {
71
+ return lz::EpConfig::New(true, sendMsglib, receiveMsglib, NULLADDRESS, 0);
72
+ }
73
+
74
+ int lz::EpConfig::isValid(cell $epConfig) inline method_id {
75
+ int receiveMsglib = $epConfig.cl::get<address>(lz::EpConfig::receiveMsglib);
76
+ int timeoutReceiveMsglib = $epConfig.cl::get<address>(lz::EpConfig::timeoutReceiveMsglib);
77
+ int timeoutReceiveMsglibExpiry = $epConfig.cl::get<uint64>(lz::EpConfig::timeoutReceiveMsglibExpiry);
78
+
79
+ if ((timeoutReceiveMsglib == NULLADDRESS) & (timeoutReceiveMsglibExpiry != 0)) {
80
+ ;; If the timeout receive msglib is null, the expiry must be 0
81
+ return lz::EpConfig::ERROR::invalidTimeoutReceiveMsglib;
82
+ } elseif ((timeoutReceiveMsglib != NULLADDRESS) & (timeoutReceiveMsglibExpiry <= now())) {
83
+ ;; if the timeout receive msglib is not null, the expiry must be in the future
84
+ return lz::EpConfig::ERROR::invalidTimeoutExpiry;
85
+ } elseif ((receiveMsglib != NULLADDRESS) & (receiveMsglib == timeoutReceiveMsglib)) {
86
+ ;; the receive msglib and timeout receive msglib must be different
87
+ return lz::EpConfig::ERROR::sameMsglib;
88
+ }
89
+
90
+ return lz::EpConfig::VALID;
91
+ }
@@ -0,0 +1,31 @@
1
+ #include "../../funC++/classlib.fc";
2
+ #include "../../protocol/msglibs/interface.fc";
3
+
4
+ ;; required storage name
5
+ const int lz::MsglibInfo::NAME = "MsglibInfo"u;
6
+
7
+ ;; field names
8
+ const int lz::MsglibInfo::msglibAddress = 0;
9
+ ;; connectionCode + connectionInitStorage are used to programmatically derive the connection address
10
+ const int lz::MsglibInfo::msglibConnectionCode = 1;
11
+ const int lz::MsglibInfo::msglibConnectionInitStorage = 2;
12
+
13
+ cell lz::MsglibInfo::New(int msglibAddress, cell msglibConnectionCode, cell msglibConnectionInitStorage) inline method_id {
14
+ return cl::declare(
15
+ lz::MsglibInfo::NAME,
16
+ unsafeTuple([
17
+ [cl::t::address, msglibAddress], ;; lz::MsglibInfo::msglibAddress
18
+ [cl::t::cellRef, msglibConnectionCode], ;; lz::MsglibInfo::msglibConnectionBytecode
19
+ [cl::t::objRef, msglibConnectionInitStorage] ;; lz::MsglibInfo::msglibConnectionInitStorage
20
+ ])
21
+ );
22
+ }
23
+
24
+ int lz::MsglibInfo::getMsglibConnectionAddress(cell $msglibInfo, cell $path) inline method_id {
25
+ return computeContractAddress(
26
+ $msglibInfo
27
+ .cl::get<objRef>(lz::MsglibInfo::msglibConnectionInitStorage)
28
+ .cl::set(MsglibConnection::PathFieldIdx, $path),
29
+ $msglibInfo.cl::get<cellRef>(lz::MsglibInfo::msglibConnectionCode)
30
+ );
31
+ }
@@ -0,0 +1,202 @@
1
+ #include "../../funC++/classlib.fc";
2
+ #include "../../funC++/constants.fc";
3
+
4
+ #include "Path.fc";
5
+
6
+ ;; required storage name
7
+ const int lz::Packet::NAME = "Packet"u;
8
+
9
+ ;; field names
10
+ const int lz::Packet::path = 0;
11
+ const int lz::Packet::message = 1;
12
+ const int lz::Packet::nonce = 2;
13
+ const int lz::Packet::guid = 3;
14
+
15
+ const int lz::Packet::ERROR::INVALID_MESSAGE = "invalid_message"c & ERRORCODE_MASK;
16
+ const int lz::Packet::ERROR::INVALID_NONCE = "invalid_nonce"c & ERRORCODE_MASK;
17
+ const int lz::Packet::ERROR::INVALID_PACKET_FIELD = "invalid_packet_field"c & ERRORCODE_MASK;
18
+
19
+ const int lz::Packet::MAX_RECEIVE_MESSAGE_CELLS = 32;
20
+ const int lz::Packet::MAX_SEND_MESSAGE_CELLS = 255;
21
+
22
+ cell lz::Packet::New(cell $path, cell message, int nonce) inline method_id {
23
+ return cl::declare(
24
+ lz::Packet::NAME,
25
+ unsafeTuple([
26
+ [cl::t::objRef, $path], ;; lz::Packet::path
27
+ [cl::t::cellRef, message], ;; lz::Packet::message
28
+ [cl::t::uint64, nonce], ;; lz::Packet::nonce
29
+ [cl::t::uint256, 0] ;; lz::Packet::guid
30
+ ])
31
+ );
32
+ }
33
+
34
+ cell lz::Packet::nonceless(cell $path, cell message) inline method_id {
35
+ return lz::Packet::New($path, message, 0);
36
+ }
37
+
38
+ () lz::Packet::_assertValidLinkedList(cell head, int maxLen) impure inline {
39
+ slice messageSlice = head.begin_parse();
40
+ repeat (maxLen) {
41
+ (int sliceBits, int sliceRefs) = messageSlice.slice_bits_refs();
42
+ if (sliceRefs == 0) {
43
+ throw_if(lz::Packet::ERROR::INVALID_MESSAGE, sliceBits % 8 != 0);
44
+ return ();
45
+ } else {
46
+ throw_if(
47
+ lz::Packet::ERROR::INVALID_MESSAGE,
48
+ (sliceRefs != 1) | (sliceBits != MAX_CELL_WHOLE_BYTE_BITS)
49
+ );
50
+ }
51
+ messageSlice = messageSlice.preload_first_ref().begin_parse();
52
+ }
53
+ throw(lz::Packet::ERROR::INVALID_MESSAGE);
54
+ }
55
+
56
+ () lz::Packet::assertValidSendMessage(cell $self) impure inline {
57
+ lz::Packet::_assertValidLinkedList(
58
+ $self.cl::get<cellRef>(lz::Packet::message),
59
+ lz::Packet::MAX_SEND_MESSAGE_CELLS
60
+ );
61
+ }
62
+
63
+ () lz::Packet::assertValidReceiveMessage(cell $self) impure inline {
64
+ lz::Packet::_assertValidLinkedList(
65
+ $self.cl::get<cellRef>(lz::Packet::message),
66
+ lz::Packet::MAX_RECEIVE_MESSAGE_CELLS
67
+ );
68
+ }
69
+
70
+ int lz::Packet::calculateGuid(cell $path, int nonce) inline method_id {
71
+ return keccak256Builder(
72
+ begin_cell()
73
+ .store_uint64(nonce)
74
+ .store_uint32($path.cl::get<uint32>(lz::Path::srcEid))
75
+ .store_uint256($path.cl::get<address>(lz::Path::srcOApp))
76
+ .store_uint32($path.cl::get<uint32>(lz::Path::dstEid))
77
+ .store_uint256($path.cl::get<address>(lz::Path::dstOApp))
78
+ );
79
+ }
80
+
81
+ ;; NOTE: this assumes that the placement of the first field is before the second field
82
+ cell lz::Packet::replaceTwoFieldsAtOffsets(
83
+ cell encodedPacket,
84
+ int replacementValue1,
85
+ int replacementOffsetBytes1,
86
+ int field1Bytes,
87
+ int replacementValue2,
88
+ int replacementOffsetBytes2,
89
+ int field2Bytes
90
+ ) impure inline method_id {
91
+ int field1PosBits = (replacementOffsetBytes1 % MAX_CELL_BYTES) * 8;
92
+ int cell1Idx = replacementOffsetBytes1 / MAX_CELL_BYTES;
93
+ int field2PosBits = (replacementOffsetBytes2 % MAX_CELL_BYTES) * 8;
94
+ int cell2Idx = replacementOffsetBytes2 / MAX_CELL_BYTES;
95
+ slice itr = encodedPacket.begin_parse();
96
+ int field1Bits = field1Bytes * 8;
97
+ int field2Bits = field2Bytes * 8;
98
+ int field1EndPosBits = field1PosBits + field1Bits;
99
+ int field2EndPosBits = field2PosBits + field2Bits;
100
+
101
+ throw_if(
102
+ lz::Packet::ERROR::INVALID_PACKET_FIELD,
103
+ (max(field1Bytes, field2Bytes) > MAX_CELL_BYTES)
104
+ | (max(field1EndPosBits, field2EndPosBits) > MAX_CELL_WHOLE_BYTE_BITS)
105
+ );
106
+
107
+ ;; short-circuit the common case to save gas
108
+ if (cell2Idx == 0) {
109
+ return begin_cell()
110
+ .store_slice(scutfirst(itr, field1PosBits, 0))
111
+ .store_uint(replacementValue1, field1Bits)
112
+ .store_slice(subslice(
113
+ itr,
114
+ field1EndPosBits,
115
+ 0,
116
+ field2PosBits - field1EndPosBits,
117
+ 0
118
+ ))
119
+ .store_uint(replacementValue2, field2Bits)
120
+ .store_slice(scutlast(
121
+ itr,
122
+ itr.slice_bits() - field2EndPosBits,
123
+ itr.slice_refs()
124
+ ))
125
+ .end_cell();
126
+ }
127
+
128
+ tuple encodedPacketBuilders = empty_tuple();
129
+
130
+ int idx = 0;
131
+
132
+ do {
133
+ if ((idx == cell1Idx) & (cell1Idx == cell2Idx)) {
134
+ slice beforeFirstField = scutfirst(itr, field1PosBits, 0);
135
+
136
+ slice betweenFields = subslice(
137
+ itr,
138
+ (field1PosBits + field1Bits),
139
+ 0,
140
+ (field2PosBits - field1PosBits - field1Bits),
141
+ 0
142
+ );
143
+
144
+ slice afterSecondField = scutlast(
145
+ itr,
146
+ itr.slice_bits() - (field2Bits + field2PosBits),
147
+ itr.slice_refs()
148
+ );
149
+
150
+ encodedPacketBuilders~tpush(
151
+ begin_cell()
152
+ .store_slice(beforeFirstField)
153
+ .store_uint(replacementValue1, field1Bits)
154
+ .store_slice(betweenFields)
155
+ .store_uint(replacementValue2, field2Bits)
156
+ .store_slice(afterSecondField)
157
+ );
158
+ } elseif (idx == cell1Idx) {
159
+ encodedPacketBuilders~tpush(
160
+ begin_cell()
161
+ .store_slice(scutfirst(itr, field1PosBits, 0))
162
+ .store_uint(replacementValue1, field1Bits)
163
+ .store_slice(
164
+ scutlast(
165
+ itr,
166
+ itr.slice_bits() - (field1Bits + field1PosBits),
167
+ itr.slice_refs()
168
+ )
169
+ )
170
+ );
171
+ } elseif (idx == cell2Idx) {
172
+ encodedPacketBuilders~tpush(
173
+ begin_cell()
174
+ .store_slice(scutfirst(itr, field2PosBits, 0))
175
+ .store_uint(replacementValue2, field2Bits)
176
+ .store_slice(
177
+ scutlast(
178
+ itr,
179
+ itr.slice_bits() - (field2Bits + field2PosBits),
180
+ itr.slice_refs()
181
+ )
182
+ )
183
+ );
184
+ } else {
185
+ encodedPacketBuilders~tpush(begin_cell().store_slice(itr));
186
+ }
187
+
188
+ if (itr.slice_refs() > 0) {
189
+ itr = itr.preload_first_ref().begin_parse();
190
+ }
191
+ idx += 1;
192
+ } until (idx >= cell2Idx);
193
+
194
+ cell curCell = encodedPacketBuilders.at(cell2Idx).end_cell();
195
+
196
+ while (cell2Idx > 0) {
197
+ cell2Idx -= 1;
198
+ curCell = encodedPacketBuilders.at(cell2Idx).store_ref(curCell).end_cell();
199
+ }
200
+
201
+ return curCell;
202
+ }
@@ -0,0 +1,56 @@
1
+ #include "../../funC++/classlib.fc";
2
+
3
+ ;; required storage name
4
+ const int lz::Path::NAME = "path"u;
5
+
6
+ ;; field names
7
+ const int lz::Path::srcEid = 0;
8
+ const int lz::Path::srcOApp = 1;
9
+ const int lz::Path::dstEid = 2;
10
+ const int lz::Path::dstOApp = 3;
11
+
12
+ ;; In all blockchains with atomic cross-contract call, we can use src/dst/srcOApp/dstOApp
13
+ ;; because the send channel doesn't exist (it's just a nonce).
14
+ ;; In TON, we need both send/receive channels, so we use srcOApp/dstOApp to provide
15
+ ;; a context-free way to refer to the two ends of the channel.
16
+ ;; The direction is inferred by the context of the contract (send vs receive).
17
+ ;; The srcOApp is the 256-bit hashpart of a standard address.
18
+ cell lz::Path::New(int srcEid, int srcOApp, int dstEid, int dstOApp) inline method_id {
19
+ return cl::declare(
20
+ lz::Path::NAME,
21
+ unsafeTuple([
22
+ [cl::t::uint32, srcEid], ;; lz::Path::srcEid
23
+ [cl::t::uint256, srcOApp], ;; lz::Path::srcOApp
24
+ [cl::t::uint32, dstEid], ;; lz::Path::dstEid
25
+ [cl::t::uint256, dstOApp] ;; lz::Path::dstOApp
26
+ ])
27
+ );
28
+ }
29
+
30
+ cell lz::Path::endpointPath(int srcEid, int dstEid) inline {
31
+ return lz::Path::New(srcEid, NULLADDRESS, dstEid, NULLADDRESS);
32
+ }
33
+
34
+ cell lz::Path::reverse(cell $path) inline {
35
+ int srcEid = $path.cl::get<uint32>(lz::Path::srcEid);
36
+ int srcOapp = $path.cl::get<address>(lz::Path::srcOApp);
37
+ int dstEid = $path.cl::get<uint32>(lz::Path::dstEid);
38
+ int dstOapp = $path.cl::get<address>(lz::Path::dstOApp);
39
+ return lz::Path::New(dstEid, dstOapp, srcEid, srcOapp);
40
+
41
+ }
42
+
43
+ const int lz::Path::_srcEidOffset = _HEADER_WIDTH;
44
+ const int lz::Path::_srcOAppOffset = lz::Path::_srcEidOffset + 32;
45
+ const int lz::Path::_dstEidOffset = lz::Path::_srcOAppOffset + 256;
46
+ ;; low-level optimized version
47
+ ;; original: 12k gas
48
+ ;; optimized: 1k gas
49
+ cell lz::Path::optimizedReverse(cell $path) inline {
50
+ slice pathSlice = $path.begin_parse();
51
+ return begin_cell()
52
+ .store_slice(pathSlice.scutfirst(_HEADER_WIDTH, 0))
53
+ .store_slice(pathSlice.preload_bits_offset(lz::Path::_dstEidOffset, 288)) ;; 32 + 256
54
+ .store_slice(pathSlice.preload_bits_offset(lz::Path::_srcEidOffset, 288)) ;; eid + address
55
+ .end_cell();
56
+ }
@@ -0,0 +1,24 @@
1
+ #include "../../funC++/classlib.fc";
2
+
3
+ ;; required storage name
4
+ const int lz::ReceiveEpConfig::NAME = "RcvMsglib"u;
5
+
6
+ ;; field names
7
+ const int lz::ReceiveEpConfig::receiveMsglibConnectionAddress = 0;
8
+ const int lz::ReceiveEpConfig::timeoutReceiveMsglibConnectionAddress = 1;
9
+ const int lz::ReceiveEpConfig::expiry = 2;
10
+
11
+ cell lz::ReceiveEpConfig::New(
12
+ int receiveMsglibConnectionAddress,
13
+ int timeoutReceiveMsglibConnectionAddress,
14
+ int expiry
15
+ ) inline method_id {
16
+ return cl::declare(
17
+ lz::ReceiveEpConfig::NAME,
18
+ unsafeTuple([
19
+ [cl::t::address, receiveMsglibConnectionAddress], ;; lz::ReceiveEpConfig::receiveMsglibConnectionAddress
20
+ [cl::t::address, timeoutReceiveMsglibConnectionAddress], ;; lz::ReceiveEpConfig::timeoutReceiveMsglibConnectionAddress
21
+ [cl::t::uint64, expiry] ;; lz::ReceiveEpConfig::expiry
22
+ ])
23
+ );
24
+ }
@@ -0,0 +1,18 @@
1
+ #include "../../funC++/classlib.fc";
2
+
3
+ ;; required storage name
4
+ const int lz::SendEpConfig::NAME = "SendEpCfg"u;
5
+
6
+ ;; field names
7
+ const int lz::SendEpConfig::sendMsglibAddress = 0;
8
+ const int lz::SendEpConfig::sendMsglibConnectionAddress = 1;
9
+
10
+ cell lz::SendEpConfig::New(int sendMsglibAddress, int sendMsglibConnectionAddress) inline method_id {
11
+ return cl::declare(
12
+ lz::SendEpConfig::NAME,
13
+ unsafeTuple([
14
+ [cl::t::address, sendMsglibAddress], ;; lz::SendEpConfig::sendMsglibAddress
15
+ [cl::t::address, sendMsglibConnectionAddress] ;; lz::SendEpConfig::sendMsglibConnectionAddress
16
+ ])
17
+ );
18
+ }
@@ -0,0 +1,20 @@
1
+ #include "../../funC++/classlib.fc";
2
+
3
+ ;; required storage name
4
+ const int lz::SmlJobAssigned::NAME = "SmlJobAssg"u;
5
+
6
+ ;; field names
7
+ const int lz::SmlJobAssigned::executorAddress = 0;
8
+ const int lz::SmlJobAssigned::fee = 1;
9
+
10
+ const int lz::SmlJobAssigned::SmlExecutorAddress = 0xdeadbeef;
11
+
12
+ cell lz::SmlJobAssigned::New(int fee) inline method_id {
13
+ return cl::declare(
14
+ lz::SmlJobAssigned::NAME,
15
+ unsafeTuple([
16
+ [cl::t::address, lz::SmlJobAssigned::SmlExecutorAddress], ;; lz::SmlJobAssigned::executorAddress
17
+ [cl::t::coins, fee] ;; lz::SmlJobAssigned::fee
18
+ ])
19
+ );
20
+ }
@@ -0,0 +1,32 @@
1
+ #include "../../funC++/classlib.fc";
2
+
3
+ ;; required storage name
4
+ const int lz::Worker::NAME = "Worker"u;
5
+
6
+ ;; field names
7
+ const int lz::Worker::owner = 0; ;; key
8
+ ;; allowlist of workers who are allowed to view my storage
9
+ const int lz::Worker::viewAllowlist = 1;
10
+ ;; list of workers whose storage I depend on
11
+ const int lz::Worker::viewDependencies = 2;
12
+ const int lz::Worker::bytecodeLibrary = 3; ;; library cell
13
+ const int lz::Worker::storage = 4;
14
+
15
+ ;; In all blockchains with atomic cross-contract call, we can use src/dst/sender/receiver
16
+ ;; because the send channel doesn't exist (it's just a nonce).
17
+ ;; In TON, we need both send/receive channels, so we use local/remote to provide
18
+ ;; a context-free way to refer to the two ends of the channel.
19
+ ;; The direction is inferred by the context of the contract (send vs receive).
20
+ ;; The srcOApp is the 256-bit hashpart of a standard address.
21
+ cell lz::Worker::New(int owner, int pricefeedAddress, cell bytecode, cell $storage) inline method_id {
22
+ return cl::declare(
23
+ lz::Worker::NAME,
24
+ unsafeTuple([
25
+ [cl::t::address, owner], ;; lz::Worker::owner
26
+ [cl::t::dict256, cl::dict256::New()], ;; lz::Worker::viewAllowlist
27
+ [cl::t::dict256, cl::dict256::New()], ;; lz::Worker::viewDependencies
28
+ [cl::t::cellRef, bytecode], ;; lz::Worker::bytecodeLibrary
29
+ [cl::t::objRef, $storage] ;; lz::Worker::storage
30
+ ])
31
+ );
32
+ }
@@ -0,0 +1,18 @@
1
+ #include "../../funC++/classlib.fc";
2
+
3
+ ;; required storage name
4
+ const int md::AddMsglib::NAME = "addMsgLib"u;
5
+
6
+ ;; field names
7
+ const int md::AddMsglib::msglibManagerAddress = 0;
8
+ const int md::AddMsglib::dstEid = 1; ;; dstEid is not used by SML, only ULN
9
+
10
+ cell md::AddMsglib::New(int msglibManagerAddress, int dstEid) inline method_id {
11
+ return cl::declare(
12
+ md::AddMsglib::NAME,
13
+ unsafeTuple([
14
+ [cl::t::address, msglibManagerAddress], ;; md::AddMsglib::msglibManagerAddress
15
+ [cl::t::uint32, dstEid] ;; md::AddMsglib::dstEid
16
+ ])
17
+ );
18
+ }
@@ -0,0 +1,16 @@
1
+ #include "../../funC++/classlib.fc";
2
+
3
+ ;; required storage name
4
+ const int md::Amount::NAME = "Amount"u;
5
+
6
+ ;; field names
7
+ const int md::Amount::amount = 0;
8
+
9
+ cell md::Amount::New(int amount) inline method_id {
10
+ return cl::declare(
11
+ md::Amount::NAME,
12
+ unsafeTuple([
13
+ [cl::t::coins, amount] ;; md::Amount::amount
14
+ ])
15
+ );
16
+ }
@@ -0,0 +1,16 @@
1
+ #include "../../funC++/classlib.fc";
2
+
3
+ ;; required storage name
4
+ const int md::Bool::NAME = "Bool"u;
5
+
6
+ ;; field names
7
+ const int md::Bool::bool = 0;
8
+
9
+ cell md::Bool::New(int boolean) inline method_id {
10
+ return cl::declare(
11
+ md::Bool::NAME,
12
+ unsafeTuple([
13
+ [cl::t::bool, boolean] ;; md::Bool::success
14
+ ])
15
+ );
16
+ }
@@ -0,0 +1,18 @@
1
+ #include "../../funC++/classlib.fc";
2
+
3
+ ;; required storage name
4
+ const int md::ChannelNonceInfo::NAME = "cNonceInfo"u;
5
+
6
+ ;; field names
7
+ const int md::ChannelNonceInfo::firstUncommittedNonce = 0;
8
+ const int md::ChannelNonceInfo::firstUnexecutedNonce = 1;
9
+
10
+ cell md::ChannelNonceInfo::New(int firstUncommittedNonce, int firstUnexecutedNonce) inline method_id {
11
+ return cl::declare(
12
+ md::ChannelNonceInfo::NAME,
13
+ unsafeTuple([
14
+ [cl::t::uint64, firstUncommittedNonce], ;; md::ChannelNonceInfo::firstUncommittedNonce
15
+ [cl::t::uint64, firstUnexecutedNonce] ;; md::ChannelNonceInfo::firstUnexecutedNonce
16
+ ])
17
+ );
18
+ }