@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,75 @@
1
+ #include "constants.fc";
2
+ #include "stdlib.fc";
3
+ #include "utils.fc";
4
+
5
+ ;;; ===============================STRING MANIPULATION FUNCTIONS===========================
6
+ ;; note that these functions are NOT optimized and should NOT be used in production code
7
+
8
+ const int ASCII_ZERO = 48;
9
+ const int ASCII_MASK = 0x1313131313131313131313131313131313131313131313131313131313131313;
10
+ const int ASCII_A = 65;
11
+
12
+ slice str::asciiUint256ToStr(int asciiUint256) {
13
+ int leading_zeroes = _SDCNTLEAD0(begin_cell().store_uint256(asciiUint256).end_cell().begin_parse());
14
+ int trailing_bits = 256 - leading_zeroes;
15
+ int mask = POW2(trailing_bits) - 1;
16
+ return begin_cell().store_uint256(asciiUint256 | (ASCII_MASK & (~ mask))).end_cell().begin_parse();
17
+ }
18
+
19
+ (slice, ()) ~str::concat(slice self, slice other) {
20
+ if(self.slice_bits() + other.slice_bits() > 127 * MAX_U8) {
21
+ throwError("Cannot concatenate: string too long");
22
+ }
23
+ return (begin_cell().store_slice(self).store_slice(other).end_cell().begin_parse(), ());
24
+ }
25
+
26
+ slice str::concat(slice self, slice other) {
27
+ self~str::concat(other);
28
+ return self;
29
+ }
30
+
31
+ (slice, ()) ~str::concatInt(slice self, int val) {
32
+ slice intSlice = empty_slice();
33
+ if (val < 0) {
34
+ self~str::concat("-");
35
+ val = -1 * val;
36
+ }
37
+ if (val == 0) {
38
+ intSlice~str::concat(begin_cell().store_uint8(ASCII_ZERO).end_cell().begin_parse());
39
+ }
40
+ while (val > 0) {
41
+ intSlice = begin_cell().store_uint8(ASCII_ZERO + val % 10).end_cell().begin_parse().str::concat(intSlice);
42
+ val /= 10;
43
+ }
44
+ return (self.str::concat(intSlice), ());
45
+ }
46
+
47
+ slice str::concatInt(slice self, int val) {
48
+ self~str::concatInt(val);
49
+ return self;
50
+ }
51
+
52
+ (slice, ()) ~str::concatHex(slice self, int val) {
53
+ slice hexSlice = empty_slice();
54
+ if (val == 0) {
55
+ hexSlice~str::concat(begin_cell().store_uint8(ASCII_ZERO).end_cell().begin_parse());
56
+ }
57
+ while (val > 0) {
58
+ if (val % 16 <= 9) {
59
+ hexSlice = begin_cell().store_uint8(ASCII_ZERO + val % 16).end_cell().begin_parse().str::concat(hexSlice);
60
+ } else {
61
+ hexSlice = begin_cell().store_uint8(ASCII_A + val % 16 - 10).end_cell().begin_parse().str::concat(hexSlice);
62
+ }
63
+ val = (val >> 4); ;; val /= 16
64
+ }
65
+ return (self.str::concat(hexSlice), ());
66
+ }
67
+
68
+ slice str::concatHex(slice self, int val) {
69
+ self~str::concatHex(val);
70
+ return self;
71
+ }
72
+
73
+ () str::console::log<int>(slice string, int val) impure {
74
+ ~strdump(string.str::concat(": ").str::concatInt(val));
75
+ }
@@ -0,0 +1,126 @@
1
+ #include "classlib.fc";
2
+
3
+ global tuple txnContext;
4
+
5
+ const _IS_BOUNCED = 0;
6
+ const _CALLER = 1;
7
+ const _FWD_FEE = 2;
8
+ const _OPCODE = 3;
9
+ const _QUERY_ID = 4;
10
+ const _BALANCE = 5;
11
+ const _MSG_VALUE = 6;
12
+ const _BODY = 7;
13
+ const _RAW_MSG = 8;
14
+ const _ORIGIN = 9;
15
+ const _DONATION_NANOS = 10;
16
+ const _MD = 11;
17
+ const _VALUE_OUTFLOW = 12;
18
+
19
+ int getMsgValue() inline {
20
+ return txnContext.int_at(_MSG_VALUE);
21
+ }
22
+
23
+ int getOpcode() inline {
24
+ return txnContext.int_at(_OPCODE);
25
+ }
26
+
27
+ int txnIsBounced() inline {
28
+ return txnContext.int_at(_IS_BOUNCED);
29
+ }
30
+
31
+ int getContractBalance() inline {
32
+ return txnContext.int_at(_BALANCE);
33
+ }
34
+
35
+ int getInitialContractBalance() inline {
36
+ return getContractBalance() - getMsgValue();
37
+ }
38
+
39
+ int getCaller() inline {
40
+ return txnContext.int_at(_CALLER);
41
+ }
42
+
43
+ int getOrigin() inline {
44
+ return txnContext.int_at(_ORIGIN);
45
+ }
46
+
47
+ slice getOriginStd() inline {
48
+ return hashpartToBasechainAddressStd(getOrigin());
49
+ }
50
+
51
+ int getDonationNanos() inline {
52
+ return txnContext.int_at(_DONATION_NANOS);
53
+ }
54
+
55
+ () setDonationNanos(int nanos) impure inline {
56
+ txnContext~tset(_DONATION_NANOS, nanos);
57
+ }
58
+
59
+ cell getMsgData() inline {
60
+ return txnContext.cell_at(_MD);
61
+ }
62
+
63
+ () setOrigin(int newOrigin) impure inline {
64
+ txnContext~tset(_ORIGIN, newOrigin);
65
+ }
66
+
67
+ ;; returns if slice empty
68
+ ;; if empty body, sets opcode=-1 & query_id=-1, so it cannot be faked
69
+ () initTxnContext(int myBalance, int msgValue, cell inMsgValue, slice inMsgBody) impure inline {
70
+ slice cs = inMsgValue.begin_parse();
71
+ int flags = cs~load_uint(4);
72
+
73
+ int _is_bounced = false;
74
+ if flags & 1 {
75
+ _is_bounced = true;
76
+ inMsgBody~skip_bits(32); ;; 0xFFFFFFFF
77
+ }
78
+
79
+ int opcode = -1;
80
+ int query_id = -1;
81
+ int donationNanos = 0;
82
+ cell md = null();
83
+
84
+ slice _sender_address = cs~load_msg_addr();
85
+ cs~load_msg_addr();
86
+ cs~load_coins();
87
+ cs~skip_bits(1);
88
+ cs~load_coins();
89
+ int senderAddress = basechainAddressStdToHashpart(_sender_address);
90
+
91
+ ;; by default, the origin is the sender address
92
+ int origin = senderAddress;
93
+
94
+ ;; the inMsgBody parsing is technically compatible with the reference jetton implementation
95
+ ;; where donationNanos == the amount of tokens received
96
+ ;; and and the origin will contain garbage data
97
+ ifnot (inMsgBody.slice_empty?()) {
98
+ opcode = inMsgBody~load_uint(32);
99
+ query_id = inMsgBody~load_uint(64);
100
+ donationNanos = inMsgBody~load_coins();
101
+ ;; if the origin is explicitly overriden in the body, use that
102
+ if (inMsgBody.slice_bits() >= 267) {
103
+ origin = inMsgBody.preload_bits_offset(11, 256).preload_uint(256);
104
+ }
105
+ ifnot (inMsgBody.slice_refs_empty?()) {
106
+ md = inMsgBody.preload_ref();
107
+ }
108
+ }
109
+
110
+ txnContext = castToTuple([
111
+ _is_bounced,
112
+ senderAddress,
113
+ muldiv(cs~load_coins(), 3, 2),
114
+ opcode,
115
+ query_id,
116
+ myBalance,
117
+ msgValue,
118
+ inMsgBody, ;; could be an empty slice
119
+ inMsgValue,
120
+ origin,
121
+ donationNanos,
122
+ md
123
+ ]);
124
+ }
125
+
126
+ (builder) beginTonMessage(int _opcode) asm "txnContext GETGLOB 4 INDEX SWAP NEWC 32 STU 64 STU";
@@ -0,0 +1,119 @@
1
+ #include "constants.fc";
2
+ #include "stdlib.fc";
3
+
4
+ forall X -> tuple unsafeTuple(X x) asm "NOP";
5
+ (slice) as_slice(builder b) asm "ENDC CTOS";
6
+ (slice, int) load_uint8(slice s) asm "8 LDU SWAP";
7
+ (builder) store_uint8(builder b, int t) inline asm(t b) "8 STU";
8
+ (slice, int) load_uint16(slice s) asm "16 LDU SWAP";
9
+ (builder) store_uint16(builder b, int t) inline asm(t b) "16 STU";
10
+ (slice, int) load_uint32(slice s) asm "32 LDU SWAP";
11
+ (builder) store_uint32(builder b, int t) inline asm(t b) "32 STU";
12
+ (slice, int) load_uint64(slice s) asm "64 LDU SWAP";
13
+ (builder) store_uint64(builder b, int t) inline asm(t b) "64 STU";
14
+ (slice, int) load_uint128(slice s) asm "128 LDU SWAP";
15
+ (builder) store_uint128(builder b, int t) inline asm(t b) "128 STU";
16
+ (slice, int) load_uint256(slice s) asm "256 LDU SWAP";
17
+ (builder) store_uint256(builder b, int t) inline asm(t b) "256 STU";
18
+ forall X -> int is_null(X x) asm "ISNULL";
19
+ forall X -> int is_int(X x) asm "<{ TRY:<{ 0 PUSHINT ADD DROP -1 PUSHINT }>CATCH<{ 2DROP 0 PUSHINT }> }>CONT 1 1 CALLXARGS";
20
+ forall X -> int is_cell(X x) asm "<{ TRY:<{ CTOS DROP -1 PUSHINT }>CATCH<{ 2DROP 0 PUSHINT }> }>CONT 1 1 CALLXARGS";
21
+ forall X -> int is_slice(X x) asm "<{ TRY:<{ SBITS DROP -1 PUSHINT }>CATCH<{ 2DROP 0 PUSHINT }> }>CONT 1 1 CALLXARGS";
22
+ forall X -> int is_tuple(X x) asm "ISTUPLE";
23
+ forall X -> cell cast_to_cell(X x) asm "NOP";
24
+ forall X -> slice cast_to_slice(X x) asm "NOP";
25
+ forall X -> int cast_to_int(X x) asm "NOP";
26
+ forall X -> tuple cast_to_tuple(X x) asm "NOP";
27
+ (cell) my_code() asm "MYCODE";
28
+ (tuple) get_values() asm "INCOMINGVALUE";
29
+ int storage_fees() asm "STORAGEFEES";
30
+ (int, slice) ldones(slice s) asm "LDONES";
31
+
32
+ (int) get_gas_consumed() asm "GASCONSUMED";
33
+
34
+ builder store_zeroes(builder b, int x) asm "STZEROES";
35
+ builder store_ones(builder b, int x) asm "STONES";
36
+ cell preload_first_ref(slice s) asm "0 PLDREFIDX";
37
+ slice preload_bits_offset(slice s, int offset, int len) asm "SDSUBSTR";
38
+ (slice, int) load_bool(slice s) asm(-> 1 0) "1 LDI";
39
+ (builder) store_bool(builder b, int v) asm(v b) "1 STI";
40
+ cell empty_cell() asm "<b b> PUSHREF";
41
+ forall X -> tuple tset(tuple t, int k, X x) asm(t x k) "SETINDEXVAR";
42
+ forall X -> (tuple, ()) ~tset(tuple t, int k, X x) asm(t x k) "SETINDEXVAR";
43
+ forall X -> (tuple, X) tpop(tuple t) asm "TPOP";
44
+ int tlen(tuple t) asm "TLEN";
45
+ int keccak256Builder(builder b) asm "1 PUSHINT HASHEXT_KECCAK256";
46
+
47
+ int cell_is_empty(cell c) inline {
48
+ return c.cell_hash() == 68134197439415885698044414435951397869210496020759160419881882418413283430343;
49
+ }
50
+
51
+ int get_compute_fee(int workchain, int gas_used) asm(gas_used workchain) "GETGASFEE";
52
+ int get_storage_fee(int workchain, int seconds, int bits, int cells) asm(cells bits seconds workchain) "GETSTORAGEFEE";
53
+ int get_forward_fee(int workchain, int bits, int cells) asm(cells bits workchain) "GETFORWARDFEE";
54
+
55
+ int ilog4(int x) asm(x) "UBITSIZE 4 PUSHINT DIV";
56
+ cell preload_ref_at(slice s, int idx) inline asm "PLDREFVAR";
57
+ slice scutfirst(slice s, int bits, int refs) inline asm "SCUTFIRST";
58
+ slice scutlast(slice s, int bits, int refs) inline asm "SCUTLAST";
59
+ slice subslice(slice s, int start_bits, int start_refs, int bits, int refs) inline asm "SUBSLICE";
60
+ slice sskipfirst(slice s, int bits, int refs) inline asm "SSKIPFIRST";
61
+ slice sdskipfirst(slice s, int bits) inline asm "SDSKIPFIRST";
62
+ forall X -> builder cast_to_builder(X x) inline asm "NOP";
63
+ int abs(int x) inline asm "ABS";
64
+
65
+ () throwError(slice reason) impure inline {
66
+ ~strdump(reason);
67
+ throw(reason.slice_hash() & ERRORCODE_MASK);
68
+ }
69
+
70
+ () throwErrorUnless(int condition, slice reason) inline {
71
+ ifnot (condition) {
72
+ throwError(reason);
73
+ }
74
+ }
75
+ int _SDCNTLEAD0(slice x) asm "SDCNTLEAD0";
76
+ int POW2(int y) asm "POW2";
77
+
78
+ ;; numCells, num_bits
79
+ (int, int) getContractStateSize(cell code, cell init_storage) inline {
80
+ cell stateInit = begin_cell()
81
+ .store_uint(6, 5)
82
+ .store_ref(code)
83
+ .store_ref(init_storage)
84
+ .end_cell();
85
+ (int cellsCount, int bitsCount, _) = stateInit.compute_data_size(MAX_U16);
86
+ return (cellsCount, bitsCount);
87
+ }
88
+
89
+ int calculateStorageFees(int cellsCount, int bitsCount, int timeDelta) inline {
90
+ return get_storage_fee(BASECHAIN, timeDelta, bitsCount, cellsCount);
91
+ }
92
+
93
+ forall X -> tuple castToTuple(X x) asm "NOP";
94
+
95
+ slice empty_slice() asm "<b b> <s PUSHSLICE";
96
+
97
+ int treeShapeEqual(cell lhs, cell rhs) inline {
98
+ slice lhsSlice = lhs.begin_parse();
99
+ slice rhsSlice = rhs.begin_parse();
100
+ (int lhsBits, int lhsRefs) = lhsSlice.slice_bits_refs();
101
+ (int rhsBits, int rhsRefs) = rhsSlice.slice_bits_refs();
102
+ if ((lhsBits != rhsBits) | (lhsRefs != rhsRefs)) {
103
+ return false;
104
+ }
105
+ if (lhsRefs == 0) {
106
+ return true;
107
+ }
108
+ int subtreeShapeEqual = true;
109
+ int refIdx = 0;
110
+ while (refIdx < lhsRefs) {
111
+ subtreeShapeEqual &= treeShapeEqual(
112
+ lhsSlice.preload_ref_at(refIdx),
113
+ rhsSlice.preload_ref_at(refIdx)
114
+ );
115
+ }
116
+ return subtreeShapeEqual;
117
+ }
118
+
119
+ int _globvarIsNull(int idx) impure asm "GETGLOBVAR ISNULL";
@@ -0,0 +1,120 @@
1
+ #include "../../../node_modules/@ston-fi/funcbox/autoload.fc";
2
+ #include "utils.fc";
3
+ #include "op-codes.fc";
4
+ #include "../../../node_modules/@ston-fi/funcbox/contracts/stdlib.fc";
5
+ ;; It is recommended to use https://github.com/ton-blockchain/token-contract/blob/main/ft/jetton-minter-discoverable.fc
6
+ ;; instead of this contract, see https://github.com/ton-blockchain/TEPs/blob/master/text/0089-jetton-wallet-discovery.md
7
+
8
+ ;; Jettons minter smart contract
9
+
10
+ ;; storage scheme
11
+ ;; storage#_ total_supply:Coins admin_address:MsgAddress content:^Cell jetton_wallet_code:^Cell = Storage;
12
+
13
+ (int, slice, cell, cell) load_data() inline {
14
+ slice ds = get_data().begin_parse();
15
+ return (
16
+ ds~load_coins(), ;; total_supply
17
+ ds~load_msg_addr(), ;; admin_address
18
+ ds~load_ref(), ;; content
19
+ ds~load_ref() ;; jetton_wallet_code
20
+ );
21
+ }
22
+
23
+ () save_data(int total_supply, slice admin_address, cell content, cell jetton_wallet_code) impure inline {
24
+ set_data(begin_cell()
25
+ .store_coins(total_supply)
26
+ .store_slice(admin_address)
27
+ .store_ref(content)
28
+ .store_ref(jetton_wallet_code)
29
+ .end_cell()
30
+ );
31
+ }
32
+
33
+ () mint_tokens(slice to_address, cell jetton_wallet_code, int amount, cell master_msg) impure {
34
+ cell state_init = calculate_jetton_wallet_state_init(to_address, my_address(), jetton_wallet_code);
35
+ slice to_wallet_address = calculate_jetton_wallet_address(state_init);
36
+ var msg = begin_cell()
37
+ .store_uint(0x18, 6)
38
+ .store_slice(to_wallet_address)
39
+ .store_coins(amount)
40
+ .store_uint(4 + 2 + 1, 1 + 4 + 4 + 64 + 32 + 1 + 1 + 1)
41
+ .store_ref(state_init)
42
+ .store_ref(master_msg);
43
+ send_raw_message(msg.end_cell(), 64); ;; pay transfer fees separately, revert on errors
44
+ }
45
+
46
+ () recv_internal(int msg_value, cell in_msg_full, slice in_msg_body) impure {
47
+ if (in_msg_body.slice_empty?()) { ;; ignore empty messages
48
+ return ();
49
+ }
50
+
51
+ slice cs = in_msg_full.begin_parse();
52
+ int flags = cs~load_uint(4);
53
+
54
+ if (flags & 1) { ;; ignore all bounced messages
55
+ return ();
56
+ }
57
+ slice sender_address = cs~load_msg_addr();
58
+ int op = in_msg_body~load_uint(32);
59
+ int query_id = in_msg_body~load_uint(64);
60
+ (int total_supply, slice admin_address, cell content, cell jetton_wallet_code) = load_data();
61
+ if (op == op::mint()) {
62
+ throw_unless(73, equal_slices(sender_address, admin_address));
63
+
64
+ slice to_address = in_msg_body~load_msg_addr();
65
+ int amount = in_msg_body~load_coins();
66
+ cell master_msg = in_msg_body~load_ref();
67
+ slice master_msg_cs = master_msg.begin_parse();
68
+ master_msg_cs~skip_bits(32 + 64); ;; op + query_id
69
+ int jetton_amount = master_msg_cs~load_coins();
70
+ mint_tokens(to_address, jetton_wallet_code, amount, master_msg);
71
+ save_data(total_supply + jetton_amount, to_address, content, jetton_wallet_code);
72
+ return ();
73
+ }
74
+
75
+ if (op == op::burn_notification()) {
76
+ int jetton_amount = in_msg_body~load_coins();
77
+ slice from_address = in_msg_body~load_msg_addr();
78
+ throw_unless(74,
79
+ equal_slices(calculate_user_jetton_wallet_address(from_address, my_address(), jetton_wallet_code), sender_address)
80
+ );
81
+ save_data(total_supply - jetton_amount, admin_address, content, jetton_wallet_code);
82
+ slice response_address = in_msg_body~load_msg_addr();
83
+ if (response_address.preload_uint(2) != 0) {
84
+ var msg = begin_cell()
85
+ .store_uint(0x10, 6) ;; nobounce - int_msg_info$0 ihr_disabled:Bool bounce:Bool bounced:Bool src:MsgAddress -> 011000
86
+ .store_slice(response_address)
87
+ .store_coins(0)
88
+ .store_uint(0, 1 + 4 + 4 + 64 + 32 + 1 + 1)
89
+ .store_uint(op::excesses, 32)
90
+ .store_uint(query_id, 64);
91
+ send_raw_message(msg.end_cell(), 2 + 64);
92
+ }
93
+ return ();
94
+ }
95
+
96
+ if (op == 3) { ;; change admin
97
+ throw_unless(73, equal_slices(sender_address, admin_address));
98
+ slice new_admin_address = in_msg_body~load_msg_addr();
99
+ save_data(total_supply, new_admin_address, content, jetton_wallet_code);
100
+ return ();
101
+ }
102
+
103
+ if (op == 4) { ;; change content, delete this for immutable tokens
104
+ throw_unless(73, equal_slices(sender_address, admin_address));
105
+ save_data(total_supply, admin_address, in_msg_body~load_ref(), jetton_wallet_code);
106
+ return ();
107
+ }
108
+
109
+ throw(0xffff);
110
+ }
111
+
112
+ (int, int, slice, cell, cell) get_jetton_data() method_id {
113
+ (int total_supply, slice admin_address, cell content, cell jetton_wallet_code) = load_data();
114
+ return (total_supply, -1, admin_address, content, jetton_wallet_code);
115
+ }
116
+
117
+ slice get_wallet_address(slice owner_address) method_id {
118
+ (int total_supply, slice admin_address, cell content, cell jetton_wallet_code) = load_data();
119
+ return calculate_user_jetton_wallet_address(owner_address, my_address(), jetton_wallet_code);
120
+ }
@@ -0,0 +1,10 @@
1
+ int op::transfer() asm "0xf8a7ea5 PUSHINT";
2
+ int op::transfer_notification() asm "0x7362d09c PUSHINT";
3
+ int op::internal_transfer() asm "0x178d4519 PUSHINT";
4
+ ;; this is "copied" because it's already imported in funcbox
5
+ int op::excesses_copy() asm "0xd53276db PUSHINT";
6
+ int op::burn() asm "0x595f07bc PUSHINT";
7
+ int op::burn_notification() asm "0x7bdd97de PUSHINT";
8
+
9
+ ;; Minter
10
+ int op::mint() asm "0x642b7d07 PUSHINT";
@@ -0,0 +1,18 @@
1
+ #include "../../../node_modules/@ston-fi/funcbox/autoload.fc";
2
+
3
+ int workchain() asm "0 PUSHINT";
4
+
5
+ ;; () force_chain(slice addr) impure {
6
+ ;; (int wc, _) = parse_std_addr(addr);
7
+ ;; throw_unless(333, wc == workchain());
8
+ ;; }
9
+
10
+ (int) get_workchain(slice address) inline {
11
+ (int wc, _) = parse_std_addr(address);
12
+ return wc;
13
+ }
14
+
15
+ () force_chain(int workchain, slice address, int error_code) impure inline {
16
+ (int wc) = get_workchain(address);
17
+ throw_unless(error_code, wc == workchain);
18
+ }
@@ -0,0 +1,33 @@
1
+ #include "../../../node_modules/@ston-fi/funcbox/autoload.fc";
2
+ #include "params.fc";
3
+
4
+ cell pack_jetton_wallet_data(int balance, slice owner_address, slice jetton_master_address, cell jetton_wallet_code) inline {
5
+ return begin_cell()
6
+ .store_coins(balance)
7
+ .store_slice(owner_address)
8
+ .store_slice(jetton_master_address)
9
+ .store_ref(jetton_wallet_code)
10
+ .end_cell();
11
+ }
12
+
13
+ cell calculate_jetton_wallet_state_init(slice owner_address, slice jetton_master_address, cell jetton_wallet_code) inline {
14
+ return begin_cell()
15
+ .store_uint(0, 2)
16
+ .store_dict(jetton_wallet_code)
17
+ .store_dict(pack_jetton_wallet_data(0, owner_address, jetton_master_address, jetton_wallet_code))
18
+ .store_uint(0, 1)
19
+ .end_cell();
20
+ }
21
+
22
+ slice calculate_jetton_wallet_address(cell state_init) inline {
23
+ return begin_cell().store_uint(4, 3)
24
+ .store_int(workchain(), 8)
25
+ .store_uint(cell_hash(state_init), 256)
26
+ .end_cell()
27
+ .begin_parse();
28
+ }
29
+
30
+ slice calculate_user_jetton_wallet_address(slice owner_address, slice jetton_master_address, cell jetton_wallet_code) inline {
31
+ return calculate_jetton_wallet_address(calculate_jetton_wallet_state_init(owner_address, jetton_master_address, jetton_wallet_code));
32
+ }
33
+