@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
@@ -0,0 +1,64 @@
1
+ const int ERRORCODE_MASK = 0x7ff;
2
+ const int CLASSLIB::ERROR::INVALID_FIELD_TYPE = "CLASSLIB::ERROR::INVALID_FIELD_TYPE"c & ERRORCODE_MASK;
3
+ const int CLASSLIB::ERROR::WRONG_ORDER_CONSTRUCTOR = "CLASSLIB::ERROR::WRONG_ORDER_CONSTRUCTOR"c & ERRORCODE_MASK;
4
+
5
+ const int MAX_U8 = 0xFF;
6
+ const int MAX_U16 = 0xFFFF;
7
+ const int MAX_U32 = 0xFFFFFFFF;
8
+ const int MAX_U64 = 0xFFFFFFFFFFFFFFFF;
9
+ const int MAX_U128 = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
10
+ const int MAX_U256 = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
11
+ const int MAX_COINS = 1329227995784915872903807060280344575; ;; 2^120 - 1
12
+
13
+ const ADDR_TYPE_NONE = 0;
14
+ const ADDR_TYPE_EXTERN = 1;
15
+ const ADDR_TYPE_STD = 2;
16
+ const ADDR_TYPE_VAR = 3;
17
+
18
+ const int TRUE = -1;
19
+ const int FALSE = 0;
20
+ const int MASTERCHAIN = -1;
21
+ const int BASECHAIN = 0;
22
+
23
+ ;; 0b011000 tag - 0, ihr_disabled - 1, bounce - 1, bounced - 0, src = adr_none$00
24
+ const int SEND_MSG_BOUNCEABLE = 0x18;
25
+ ;; 0b010000 tag - 0, ihr_disabled - 1, bounce - 0, bounced - 0, src = adr_none$00
26
+ const int SEND_MSG_NON_BOUNCEABLE = 0x10;
27
+
28
+ ;; MODIFIER
29
+ const NORMAL = 0;
30
+ const PAID_EXTERNALLY = 1;
31
+ const IGNORE_ERRORS = 2;
32
+
33
+ ;; SEND MODES
34
+ const BOUNCE_IF_FAIL = 16;
35
+ const DESTROY_IF_ZERO = 32;
36
+ const CARRY_REMAINING_GAS = 64;
37
+ const CARRY_ALL_BALANCE = 128;
38
+
39
+ ;; SENDMSG modes
40
+ const SUB_BALANCE_MSG = 64;
41
+ const SUB_BALANCE_CONTRACT = 128;
42
+ const ONLY_ESTIMATE_FEES = 1024;
43
+
44
+ ;; SEND MODES QUIETED
45
+ const QDESTROY_IF_ZERO = 34;
46
+ const QCARRY_REMAINING_GAS = 66;
47
+ const QCARRY_ALL_BALANCE = 130;
48
+
49
+ const RESERVE_EXACTLY = 0;
50
+ const RESERVE_ALL_EXCEPT = 1;
51
+ const RESERVE_AT_MOST = 2;
52
+ const EXTRN_DO_NOT_FAIL = 2;
53
+ const BALANCE_INCREASED = 4;
54
+ const BALANCE_DECREASED = 8;
55
+ const int RESERVE_BOUNCE_ON_ACTION_FAIL = 16;
56
+
57
+ ;; a lot of different constants, because arithmetic manipulation of constants is not optimized
58
+ const MAX_CELL_BITS = 1023;
59
+ const MAX_CELL_BYTES = 127;
60
+ const MAX_CELL_WHOLE_BYTE_BITS = MAX_CELL_BYTES * 8;
61
+ const MAX_CELL_BIT_INDEX = 1022;
62
+ const MAX_CELL_REFS = 4;
63
+
64
+ const int NULLADDRESS = 0;
@@ -0,0 +1,84 @@
1
+ ;;; ================================================================
2
+ ;; The base main function for LayerZero Endpoint, UltraLightNode, and OApp
3
+ ;;; ================================================================
4
+ #include "baseInterface.fc";
5
+ #include "classlib.fc";
6
+ #include "constants.fc";
7
+ #include "stdlib.fc";
8
+ #include "stringlib.fc";
9
+ #include "txnContext.fc";
10
+ #include "actions/utils.fc";
11
+ #include "abstract/contractMainAbstract.fc";
12
+ #include "handlerCore.fc";
13
+
14
+ ;;; ===============================
15
+ ;; Base main - low-level builtin context
16
+
17
+ () main(int myBalance, int msgValue, cell inMsgFull, slice inMsgBody) impure inline {
18
+ initTxnContext(myBalance, msgValue, inMsgFull, inMsgBody);
19
+
20
+ if (txnIsBounced()) {
21
+ return ();
22
+ }
23
+
24
+ authenticateIfNecessary();
25
+
26
+ ;; ignore empty messages
27
+ if (inMsgBody.slice_empty?()) {
28
+ return ();
29
+ }
30
+
31
+ int op = getOpcode();
32
+ cell $md = getMsgData();
33
+
34
+ checkPermissions(op, $md);
35
+
36
+ if (op == BaseInterface::OP::EVENT) {
37
+ throw(BaseInterface::ERROR::eventEmitted);
38
+ }
39
+
40
+ tuple actions = null();
41
+ if (op == BaseInterface::OP::INITIALIZE) {
42
+ actions = initialize($md);
43
+ } else {
44
+ assertInitialized();
45
+ actions = _executeOpcode(op, $md);
46
+ }
47
+
48
+ int outflowNanos = actions.at(ACTIONS_OUTFLOW);
49
+ ;; Storage fees are deducted from the contract balance
50
+ ;; Any amount that is explicitly deposited into this contract (getRentNanos())
51
+ ;; is reserved to prevent it from being sent downstream
52
+ int baseline = (getContractBalance() - storage_fees()) - (getMsgValue() - getDonationNanos());
53
+ ;; TODO: can we safely remove this assertion and instead rely on raw_reserve to revert?
54
+ throw_unless(37, baseline >= outflowNanos);
55
+ raw_reserve(baseline - outflowNanos, RESERVE_EXACTLY);
56
+
57
+ ;; Whether there is any value left to refund to the origin
58
+ int msgValueRemaining = true;
59
+ ;; the index of the action to be processed
60
+ int actionIndex = 1;
61
+ int numActions = actions.tlen();
62
+ while (actionIndex < numActions) {
63
+ ;; ========================================
64
+ ;; Loop management
65
+ tuple action = actions.tuple_at(actionIndex);
66
+ int actionType = action.int_at(0); ;; name is always the first index
67
+ actionIndex += 1;
68
+
69
+ ;; Applies a moving flag where if a single action returns false, then the false flag persists
70
+ msgValueRemaining = msgValueRemaining & _executeAction(actionType, action);
71
+ }
72
+
73
+ ;; If any value remains, we should refund it to the origin
74
+ if (msgValueRemaining) {
75
+ cell msg = begin_cell()
76
+ .store_uint(SEND_MSG_NON_BOUNCEABLE, 6)
77
+ .store_slice(getOriginStd())
78
+ .store_coins(0)
79
+ .store_uint(1, 107)
80
+ .store_ref(empty_cell())
81
+ .end_cell();
82
+ send_raw_message(msg, CARRY_ALL_BALANCE);
83
+ }
84
+ }
@@ -0,0 +1,155 @@
1
+ ;;; =================== DeterministicInsertionCircularQueue.fc ===================
2
+ ;; the DeterministicInsertionCircularQueue is a deterministic-gas circular buffer
3
+ ;; that stores key-value pairs along with one piece of metadata (8-bits) per entry.
4
+ #include "../utils.fc";
5
+ #include "../stdlib.fc";
6
+
7
+ const int DeterministicInsertionCircularQueue::statusBits = 8;
8
+ const int DeterministicInsertionCircularQueue::keyBits = 64;
9
+
10
+ const int DeterministicInsertionCircularQueue::invalidKey = -1;
11
+ const int DeterministicInsertionCircularQueue::invalidStatus = -1;
12
+ const int DeterministicInsertionCircularQueue::ERROR::invalidObject = "DeterministicInsertionCircularQueue::ERROR::invalidObject"c & ERRORCODE_MASK;
13
+
14
+ cell DeterministicInsertionCircularQueue::_buildLevel(int level, cell initialContents) inline {
15
+ if (level == 0) {
16
+ return begin_cell()
17
+ .store_ref(initialContents)
18
+ .store_ref(initialContents)
19
+ .store_ref(initialContents)
20
+ .store_ref(initialContents)
21
+ .end_cell();
22
+ } else {
23
+ int nextLevel = level - 1;
24
+ return begin_cell()
25
+ .store_ref(DeterministicInsertionCircularQueue::_buildLevel(nextLevel, initialContents))
26
+ .store_ref(DeterministicInsertionCircularQueue::_buildLevel(nextLevel, initialContents))
27
+ .store_ref(DeterministicInsertionCircularQueue::_buildLevel(nextLevel, initialContents))
28
+ .store_ref(DeterministicInsertionCircularQueue::_buildLevel(nextLevel, initialContents))
29
+ .end_cell();
30
+ }
31
+ }
32
+
33
+ ;; Given a well-formed commit_verification_queue
34
+ ;; get the content of the queue at a given relative nonce
35
+ ;; (actual key, entry, status, exists)
36
+ (int, cell, int, int) DeterministicInsertionCircularQueue::get(cell self, int key) inline {
37
+ int position = key % MAX_CELL_BITS;
38
+
39
+ slice commitSlice = self
40
+ .begin_parse()
41
+ .preload_ref_at(position / 256)
42
+ .begin_parse()
43
+ .preload_ref_at((position % 256) / 64)
44
+ .begin_parse()
45
+ .preload_ref_at((position % 64) / 16)
46
+ .begin_parse()
47
+ .preload_ref_at((position % 16) / 4)
48
+ .begin_parse()
49
+ .preload_ref_at(position % 4)
50
+ .begin_parse();
51
+
52
+ ;; guaranteed to always have state stored
53
+ int exists = commitSlice~load_bool();
54
+ int state = commitSlice~load_uint(DeterministicInsertionCircularQueue::statusBits);
55
+ if (exists) {
56
+ return (
57
+ commitSlice.preload_uint(DeterministicInsertionCircularQueue::keyBits),
58
+ commitSlice.preload_first_ref(),
59
+ state,
60
+ exists
61
+ );
62
+ }
63
+ return (
64
+ DeterministicInsertionCircularQueue::invalidKey,
65
+ empty_cell(),
66
+ DeterministicInsertionCircularQueue::invalidStatus,
67
+ exists
68
+ );
69
+ }
70
+
71
+ cell DeterministicInsertionCircularQueue::_setRaw(cell self, int key, cell newLeaf) inline {
72
+ int slot = key % MAX_CELL_BITS;
73
+ slice queueSlice = self.begin_parse();
74
+ int l0_idx = slot / 256;
75
+ int l1_idx = (slot % 256) / 64;
76
+ int l2_idx = (slot % 64) / 16;
77
+ int l3_idx = (slot % 16) / 4;
78
+ int leaf_idx = slot % 4;
79
+
80
+ slice l0Slice = queueSlice.preload_ref_at(l0_idx).begin_parse();
81
+ slice l1Slice = l0Slice.preload_ref_at(l1_idx).begin_parse();
82
+ slice l2Slice = l1Slice.preload_ref_at(l2_idx).begin_parse();
83
+ slice l3Slice = l2Slice.preload_ref_at(l3_idx).begin_parse();
84
+
85
+ cell new_l3 = begin_cell()
86
+ .store_slice(scutfirst(l3Slice, 0, leaf_idx))
87
+ .store_ref(newLeaf)
88
+ .store_slice(scutlast(l3Slice, 0, 3 - leaf_idx))
89
+ .end_cell();
90
+
91
+ cell new_l2 = begin_cell()
92
+ .store_slice(scutfirst(l2Slice, 0, l3_idx))
93
+ .store_ref(new_l3)
94
+ .store_slice(scutlast(l2Slice, 0, 3 - l3_idx))
95
+ .end_cell();
96
+
97
+ cell new_l1 = begin_cell()
98
+ .store_slice(scutfirst(l1Slice, 0, l2_idx))
99
+ .store_ref(new_l2)
100
+ .store_slice(scutlast(l1Slice, 0, 3 - l2_idx))
101
+ .end_cell();
102
+
103
+ cell new_l0 = begin_cell()
104
+ .store_slice(scutfirst(l0Slice, 0, l1_idx))
105
+ .store_ref(new_l1)
106
+ .store_slice(scutlast(l0Slice, 0, 3 - l1_idx))
107
+ .end_cell();
108
+
109
+ return (
110
+ begin_cell()
111
+ .store_slice(scutfirst(queueSlice, 0, l0_idx))
112
+ .store_ref(new_l0)
113
+ .store_slice(scutlast(queueSlice, 0, 3 - l0_idx))
114
+ .end_cell()
115
+ );
116
+ }
117
+
118
+ ;; self
119
+ cell DeterministicInsertionCircularQueue::set(cell self, int key, cell $obj, int newState) inline {
120
+ return DeterministicInsertionCircularQueue::_setRaw(
121
+ self,
122
+ key,
123
+ begin_cell()
124
+ .store_bool(true) ;; occupied
125
+ .store_uint(newState, DeterministicInsertionCircularQueue::statusBits)
126
+ .store_uint(key, DeterministicInsertionCircularQueue::keyBits)
127
+ .store_ref($obj)
128
+ .end_cell()
129
+ );
130
+ }
131
+
132
+ cell DeterministicInsertionCircularQueue::delete(cell self, int key) inline {
133
+ return DeterministicInsertionCircularQueue::_setRaw(
134
+ self,
135
+ key,
136
+ begin_cell()
137
+ .store_bool(false) ;; occupied
138
+ .store_uint(0, DeterministicInsertionCircularQueue::statusBits)
139
+ .store_uint(0, DeterministicInsertionCircularQueue::keyBits)
140
+ .store_ref(empty_cell())
141
+ .end_cell()
142
+ );
143
+ }
144
+
145
+ cell DeterministicInsertionCircularQueue::create() method_id {
146
+ ;; ceil(log4(MAX_CELL_BITS)) == 4
147
+ ;; build the initial contents of each leaf in the outer scope to save gas
148
+ cell initialContents = begin_cell()
149
+ .store_bool(false) ;; unoccupied
150
+ .store_uint(0, DeterministicInsertionCircularQueue::statusBits) ;; value not used until set
151
+ .store_uint(0, DeterministicInsertionCircularQueue::keyBits) ;; value not used until set
152
+ .store_ref(empty_cell()) ;; value not used until set
153
+ .end_cell();
154
+ return DeterministicInsertionCircularQueue::_buildLevel(4, initialContents);
155
+ }
@@ -0,0 +1,93 @@
1
+ ;;; ==============================================================================
2
+ ;; Pipelined Out-of-Order data structure
3
+ ;; this data structure defines a bitmap that is used to track a stream of
4
+ ;; commands that are executed out-of-order in a bounded-depth pipeline
5
+ #include "../classlib.fc";
6
+ #include "../utils.fc";
7
+
8
+ const int POOO::NAME = "POOO"u;
9
+
10
+ const int POOO::nextEmpty = 0;
11
+ const int POOO::bitmap = 1;
12
+
13
+ const int POOO::ERROR::negativeIndex = "POOO::ERROR::negativeIndex"c & ERRORCODE_MASK;
14
+
15
+ ;; Algorithm:
16
+ ;; 1. Extract the first `index` bits from the original bitmap.
17
+ ;; 2. Append a '1' bit to the extracted bits.
18
+ ;; 3. Append the remaining bits from the original bitmap after the first `index` bits to form a new bitmap.
19
+
20
+ ;; Returns:
21
+ ;; 1. The number of leading ones (`leadingOnes`).
22
+ ;; 2. A new cell that contains:
23
+ ;; - The remaining bits after the leading ones from the original bitmap.
24
+ ;; - A number of trailing zero bits equal to `leadingOnes`.
25
+
26
+ ;; Parameters:
27
+ ;; - `bitmapCell`: The original bitmap in the form of a cell.
28
+ ;; - `index`: The position up to which the first part of the bitmap is extracted.
29
+ cell POOO::set(cell $self, int absoluteIndex) impure inline method_id {
30
+ throw_if(POOO::ERROR::negativeIndex, absoluteIndex < 0);
31
+
32
+ slice bitmapSlice = $self.cl::get<cellRef>(POOO::bitmap).begin_parse();
33
+ int nextEmpty = $self.cl::get<uint64>(POOO::nextEmpty);
34
+ if (absoluteIndex < nextEmpty) {
35
+ return $self;
36
+ }
37
+ int index = absoluteIndex - nextEmpty;
38
+
39
+ (int leadingOnes, slice remainingBitmap) = ldones(
40
+ begin_cell()
41
+ .store_slice(scutfirst(bitmapSlice, index, 0))
42
+ .store_uint(1, 1)
43
+ .store_slice(scutlast(bitmapSlice, MAX_CELL_BITS - index - 1, 0))
44
+ .as_slice()
45
+ );
46
+ return $self
47
+ .cl::set(
48
+ POOO::bitmap,
49
+ begin_cell()
50
+ .store_slice(remainingBitmap)
51
+ .store_zeroes(leadingOnes)
52
+ .end_cell()
53
+ )
54
+ .cl::set(POOO::nextEmpty, nextEmpty + leadingOnes);
55
+ }
56
+
57
+ cell POOO::New() inline method_id {
58
+ return cl::declare(
59
+ POOO::NAME,
60
+ unsafeTuple([
61
+ [cl::t::uint64, 1], ;; nextEmpty
62
+ [cl::t::cellRef, begin_cell().store_zeroes(MAX_CELL_BITS).end_cell()] ;; bitmap
63
+ ])
64
+ );
65
+ }
66
+
67
+ cell POOO::NewWithBitsSets(int startingBit, int endingBit) method_id {
68
+ return cl::declare(
69
+ POOO::NAME,
70
+ unsafeTuple([
71
+ [cl::t::uint64, 1],
72
+ [cl::t::cellRef, begin_cell()
73
+ .store_zeroes(1)
74
+ .store_ones(endingBit - startingBit)
75
+ .store_zeroes(MAX_CELL_BITS - endingBit)
76
+ .end_cell()
77
+ ]
78
+ ])
79
+ );
80
+ }
81
+
82
+ int POOO::isBitSet(cell $self, int absoluteIdx) inline method_id {
83
+ int relativeIdx = absoluteIdx - $self.cl::get<uint64>(POOO::nextEmpty);
84
+ return $self
85
+ .cl::get<cellRef>(POOO::bitmap)
86
+ .begin_parse()
87
+ .preload_bits_offset(relativeIdx, 1)
88
+ .preload_uint(1) == 1;
89
+ }
90
+
91
+ int POOO::maxSettableBit(cell $self) inline method_id {
92
+ return $self.cl::get<uint64>(POOO::nextEmpty) + MAX_CELL_BIT_INDEX;
93
+ }
@@ -0,0 +1,30 @@
1
+ ;;; ==========================================
2
+ ;; This file contains the utility functions for all handler functions that follow
3
+ ;; LayerZero Labs handler convention.
4
+ ;;; ==========================================
5
+ #include "actions/utils.fc";
6
+
7
+ #include "baseInterface.fc";
8
+
9
+ #include "constants.fc";
10
+ #include "stringlib.fc";
11
+ #include "txnContext.fc";
12
+
13
+ #include "abstract/handlerAbstract.fc";
14
+
15
+ ;;; ===================REQUIRED VIRTUAL FUNCTIONS=======================
16
+ ;; todo: split into permissions and utils?
17
+
18
+ (cell, tuple) preamble() impure inline {
19
+ return (getContractStorage(), emptyActions());
20
+ }
21
+
22
+ () checkPermissions(int op, cell $md) impure inline {
23
+ if (op == BaseInterface::OP::EVENT) {
24
+ return ();
25
+ } elseif (op == BaseInterface::OP::INITIALIZE) {
26
+ assertOwner();
27
+ } else {
28
+ _checkPermissions(op, $md);
29
+ }
30
+ }