@ton-wallet/create 14.0.1 → 14.0.3

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 (123) hide show
  1. package/dist/client/TonClient.d.ts +228 -0
  2. package/dist/client/TonClient.js +441 -0
  3. package/dist/client/TonClient.spec.d.ts +1 -0
  4. package/dist/client/TonClient.spec.js +45 -0
  5. package/dist/client/TonClient4.d.ts +1130 -0
  6. package/dist/client/TonClient4.js +687 -0
  7. package/dist/client/TonClient4.spec.d.ts +1 -0
  8. package/dist/client/TonClient4.spec.js +42 -0
  9. package/dist/client/api/HttpApi.d.ts +764 -0
  10. package/dist/client/api/HttpApi.js +306 -0
  11. package/dist/client/api/TonCache.d.ts +16 -0
  12. package/dist/client/api/TonCache.js +33 -0
  13. package/dist/config/ConfigParser.d.ts +622 -0
  14. package/dist/config/ConfigParser.js +711 -0
  15. package/dist/config/ConfigParser.spec.d.ts +8 -0
  16. package/dist/config/ConfigParser.spec.js +97 -0
  17. package/dist/elector/ElectorContract.d.ts +51 -0
  18. package/dist/elector/ElectorContract.js +192 -0
  19. package/dist/elector/ElectorContract.spec.d.ts +8 -0
  20. package/dist/elector/ElectorContract.spec.js +104 -0
  21. package/dist/index.d.ts +33 -0
  22. package/dist/index.js +129 -0
  23. package/dist/jetton/JettonMaster.d.ts +21 -0
  24. package/dist/jetton/JettonMaster.js +39 -0
  25. package/dist/jetton/JettonMaster.spec.d.ts +8 -0
  26. package/dist/jetton/JettonMaster.spec.js +27 -0
  27. package/dist/jetton/JettonWallet.d.ts +14 -0
  28. package/dist/jetton/JettonWallet.js +27 -0
  29. package/dist/multisig/MultisigOrder.d.ts +17 -0
  30. package/dist/multisig/MultisigOrder.js +73 -0
  31. package/dist/multisig/MultisigOrder.spec.d.ts +1 -0
  32. package/dist/multisig/MultisigOrder.spec.js +139 -0
  33. package/dist/multisig/MultisigOrderBuilder.d.ts +13 -0
  34. package/dist/multisig/MultisigOrderBuilder.js +37 -0
  35. package/dist/multisig/MultisigWallet.d.ts +27 -0
  36. package/dist/multisig/MultisigWallet.js +134 -0
  37. package/dist/multisig/MultisigWallet.spec.d.ts +1 -0
  38. package/dist/multisig/MultisigWallet.spec.js +248 -0
  39. package/dist/utils/createTestClient.d.ts +9 -0
  40. package/dist/utils/createTestClient.js +18 -0
  41. package/dist/utils/createTestClient4.d.ts +9 -0
  42. package/dist/utils/createTestClient4.js +15 -0
  43. package/dist/utils/fees.d.ts +25 -0
  44. package/dist/utils/fees.js +105 -0
  45. package/dist/utils/fees.spec.d.ts +1 -0
  46. package/dist/utils/fees.spec.js +83 -0
  47. package/dist/utils/maybe.d.ts +8 -0
  48. package/dist/utils/maybe.js +9 -0
  49. package/dist/utils/randomTestKey.d.ts +8 -0
  50. package/dist/utils/randomTestKey.js +24 -0
  51. package/dist/utils/time.d.ts +15 -0
  52. package/dist/utils/time.js +63 -0
  53. package/dist/utils/toUrlSafe.d.ts +8 -0
  54. package/dist/utils/toUrlSafe.js +23 -0
  55. package/dist/wallets/WalletContractV1R1.d.ts +58 -0
  56. package/dist/wallets/WalletContractV1R1.js +100 -0
  57. package/dist/wallets/WalletContractV1R1.spec.d.ts +8 -0
  58. package/dist/wallets/WalletContractV1R1.spec.js +44 -0
  59. package/dist/wallets/WalletContractV1R2.d.ts +58 -0
  60. package/dist/wallets/WalletContractV1R2.js +101 -0
  61. package/dist/wallets/WalletContractV1R2.spec.d.ts +8 -0
  62. package/dist/wallets/WalletContractV1R2.spec.js +44 -0
  63. package/dist/wallets/WalletContractV1R3.d.ts +58 -0
  64. package/dist/wallets/WalletContractV1R3.js +101 -0
  65. package/dist/wallets/WalletContractV1R3.spec.d.ts +8 -0
  66. package/dist/wallets/WalletContractV1R3.spec.js +44 -0
  67. package/dist/wallets/WalletContractV2R1.d.ts +60 -0
  68. package/dist/wallets/WalletContractV2R1.js +102 -0
  69. package/dist/wallets/WalletContractV2R1.spec.d.ts +8 -0
  70. package/dist/wallets/WalletContractV2R1.spec.js +44 -0
  71. package/dist/wallets/WalletContractV2R2.d.ts +60 -0
  72. package/dist/wallets/WalletContractV2R2.js +102 -0
  73. package/dist/wallets/WalletContractV2R2.spec.d.ts +8 -0
  74. package/dist/wallets/WalletContractV2R2.spec.js +44 -0
  75. package/dist/wallets/WalletContractV3R1.d.ts +57 -0
  76. package/dist/wallets/WalletContractV3R1.js +104 -0
  77. package/dist/wallets/WalletContractV3R1.spec.d.ts +8 -0
  78. package/dist/wallets/WalletContractV3R1.spec.js +44 -0
  79. package/dist/wallets/WalletContractV3R2.d.ts +57 -0
  80. package/dist/wallets/WalletContractV3R2.js +104 -0
  81. package/dist/wallets/WalletContractV3R2.spec.d.ts +8 -0
  82. package/dist/wallets/WalletContractV3R2.spec.js +44 -0
  83. package/dist/wallets/WalletContractV3Types.d.ts +12 -0
  84. package/dist/wallets/WalletContractV3Types.js +2 -0
  85. package/dist/wallets/WalletContractV4.d.ts +65 -0
  86. package/dist/wallets/WalletContractV4.js +105 -0
  87. package/dist/wallets/WalletContractV4.spec.d.ts +8 -0
  88. package/dist/wallets/WalletContractV4.spec.js +48 -0
  89. package/dist/wallets/WalletContractV5Beta.d.ts +3 -0
  90. package/dist/wallets/WalletContractV5Beta.js +19 -0
  91. package/dist/wallets/WalletContractV5R1.d.ts +3 -0
  92. package/dist/wallets/WalletContractV5R1.js +19 -0
  93. package/dist/wallets/signing/createWalletTransfer.d.ts +48 -0
  94. package/dist/wallets/signing/createWalletTransfer.js +190 -0
  95. package/dist/wallets/signing/singer.d.ts +9 -0
  96. package/dist/wallets/signing/singer.js +21 -0
  97. package/dist/wallets/v5beta/WalletContractV5Beta.d.ts +130 -0
  98. package/dist/wallets/v5beta/WalletContractV5Beta.js +211 -0
  99. package/dist/wallets/v5beta/WalletContractV5Beta.spec.d.ts +8 -0
  100. package/dist/wallets/v5beta/WalletContractV5Beta.spec.js +298 -0
  101. package/dist/wallets/v5beta/WalletV5BetaActions.d.ts +6 -0
  102. package/dist/wallets/v5beta/WalletV5BetaActions.js +92 -0
  103. package/dist/wallets/v5beta/WalletV5BetaActions.spec.d.ts +1 -0
  104. package/dist/wallets/v5beta/WalletV5BetaActions.spec.js +166 -0
  105. package/dist/wallets/v5beta/WalletV5BetaWalletId.d.ts +13 -0
  106. package/dist/wallets/v5beta/WalletV5BetaWalletId.js +31 -0
  107. package/dist/wallets/v5beta/WalletV5BetaWalletId.spec.d.ts +1 -0
  108. package/dist/wallets/v5beta/WalletV5BetaWalletId.spec.js +68 -0
  109. package/dist/wallets/v5beta/WalletV5OutActions.d.ts +17 -0
  110. package/dist/wallets/v5beta/WalletV5OutActions.js +11 -0
  111. package/dist/wallets/v5r1/WalletContractV5R1.d.ts +125 -0
  112. package/dist/wallets/v5r1/WalletContractV5R1.js +207 -0
  113. package/dist/wallets/v5r1/WalletContractV5R1.spec.d.ts +8 -0
  114. package/dist/wallets/v5r1/WalletContractV5R1.spec.js +321 -0
  115. package/dist/wallets/v5r1/WalletV5R1Actions.d.ts +12 -0
  116. package/dist/wallets/v5r1/WalletV5R1Actions.js +128 -0
  117. package/dist/wallets/v5r1/WalletV5R1Actions.spec.d.ts +1 -0
  118. package/dist/wallets/v5r1/WalletV5R1Actions.spec.js +262 -0
  119. package/dist/wallets/v5r1/WalletV5R1WalletId.d.ts +47 -0
  120. package/dist/wallets/v5r1/WalletV5R1WalletId.js +69 -0
  121. package/dist/wallets/v5r1/WalletV5R1WalletId.spec.d.ts +1 -0
  122. package/dist/wallets/v5r1/WalletV5R1WalletId.spec.js +72 -0
  123. package/package.json +6 -3
@@ -0,0 +1,687 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Whales Corp.
4
+ * All Rights Reserved.
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ */
9
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
10
+ if (kind === "m") throw new TypeError("Private method is not writable");
11
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
12
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
13
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
14
+ };
15
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
16
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
17
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
18
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
19
+ };
20
+ var __importDefault = (this && this.__importDefault) || function (mod) {
21
+ return (mod && mod.__esModule) ? mod : { "default": mod };
22
+ };
23
+ var _TonClient4_endpoint, _TonClient4_timeout, _TonClient4_adapter, _TonClient4_axios;
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.TonClient4 = void 0;
26
+ const axios_1 = __importDefault(require("axios"));
27
+ const core_1 = require("@ton/core");
28
+ const toUrlSafe_1 = require("../utils/toUrlSafe");
29
+ const zod_1 = require("zod");
30
+ class TonClient4 {
31
+ constructor(args) {
32
+ _TonClient4_endpoint.set(this, void 0);
33
+ _TonClient4_timeout.set(this, void 0);
34
+ _TonClient4_adapter.set(this, void 0);
35
+ _TonClient4_axios.set(this, void 0);
36
+ __classPrivateFieldSet(this, _TonClient4_axios, axios_1.default.create(), "f");
37
+ __classPrivateFieldSet(this, _TonClient4_endpoint, args.endpoint, "f");
38
+ __classPrivateFieldSet(this, _TonClient4_timeout, args.timeout || 5000, "f");
39
+ __classPrivateFieldSet(this, _TonClient4_adapter, args.httpAdapter, "f");
40
+ if (args.requestInterceptor) {
41
+ __classPrivateFieldGet(this, _TonClient4_axios, "f").interceptors.request.use(args.requestInterceptor);
42
+ }
43
+ }
44
+ /**
45
+ * Get Last Block
46
+ * @returns last block info
47
+ */
48
+ async getLastBlock() {
49
+ let res = await __classPrivateFieldGet(this, _TonClient4_axios, "f").get(__classPrivateFieldGet(this, _TonClient4_endpoint, "f") + '/block/latest', { adapter: __classPrivateFieldGet(this, _TonClient4_adapter, "f"), timeout: __classPrivateFieldGet(this, _TonClient4_timeout, "f") });
50
+ let lastBlock = lastBlockCodec.safeParse(res.data);
51
+ if (!lastBlock.success) {
52
+ throw Error('Mailformed response: ' + lastBlock.error.format()._errors.join(', '));
53
+ }
54
+ return lastBlock.data;
55
+ }
56
+ /**
57
+ * Get block info
58
+ * @param seqno block sequence number
59
+ * @returns block info
60
+ */
61
+ async getBlock(seqno) {
62
+ let res = await __classPrivateFieldGet(this, _TonClient4_axios, "f").get(__classPrivateFieldGet(this, _TonClient4_endpoint, "f") + '/block/' + seqno, { adapter: __classPrivateFieldGet(this, _TonClient4_adapter, "f"), timeout: __classPrivateFieldGet(this, _TonClient4_timeout, "f") });
63
+ let block = blockCodec.safeParse(res.data);
64
+ if (!block.success) {
65
+ throw Error('Mailformed response');
66
+ }
67
+ if (!block.data.exist) {
68
+ throw Error('Block is out of scope');
69
+ }
70
+ return block.data.block;
71
+ }
72
+ /**
73
+ * Get block info by unix timestamp
74
+ * @param ts unix timestamp
75
+ * @returns block info
76
+ */
77
+ async getBlockByUtime(ts) {
78
+ let res = await __classPrivateFieldGet(this, _TonClient4_axios, "f").get(__classPrivateFieldGet(this, _TonClient4_endpoint, "f") + '/block/utime/' + ts, { adapter: __classPrivateFieldGet(this, _TonClient4_adapter, "f"), timeout: __classPrivateFieldGet(this, _TonClient4_timeout, "f") });
79
+ let block = blockCodec.safeParse(res.data);
80
+ if (!block.success) {
81
+ throw Error('Mailformed response');
82
+ }
83
+ if (!block.data.exist) {
84
+ throw Error('Block is out of scope');
85
+ }
86
+ return block.data.block;
87
+ }
88
+ /**
89
+ * Get block info by unix timestamp
90
+ * @param seqno block sequence number
91
+ * @param address account address
92
+ * @returns account info
93
+ */
94
+ async getAccount(seqno, address) {
95
+ let res = await __classPrivateFieldGet(this, _TonClient4_axios, "f").get(__classPrivateFieldGet(this, _TonClient4_endpoint, "f") + '/block/' + seqno + '/' + address.toString({ urlSafe: true }), { adapter: __classPrivateFieldGet(this, _TonClient4_adapter, "f"), timeout: __classPrivateFieldGet(this, _TonClient4_timeout, "f") });
96
+ let account = accountCodec.safeParse(res.data);
97
+ if (!account.success) {
98
+ throw Error('Mailformed response');
99
+ }
100
+ return account.data;
101
+ }
102
+ /**
103
+ * Get account lite info (without code and data)
104
+ * @param seqno block sequence number
105
+ * @param address account address
106
+ * @returns account lite info
107
+ */
108
+ async getAccountLite(seqno, address) {
109
+ let res = await __classPrivateFieldGet(this, _TonClient4_axios, "f").get(__classPrivateFieldGet(this, _TonClient4_endpoint, "f") + '/block/' + seqno + '/' + address.toString({ urlSafe: true }) + '/lite', { adapter: __classPrivateFieldGet(this, _TonClient4_adapter, "f"), timeout: __classPrivateFieldGet(this, _TonClient4_timeout, "f") });
110
+ let account = accountLiteCodec.safeParse(res.data);
111
+ if (!account.success) {
112
+ throw Error('Mailformed response');
113
+ }
114
+ return account.data;
115
+ }
116
+ /**
117
+ * Check if contract is deployed
118
+ * @param address addres to check
119
+ * @returns true if contract is in active state
120
+ */
121
+ async isContractDeployed(seqno, address) {
122
+ let account = await this.getAccountLite(seqno, address);
123
+ return account.account.state.type === 'active';
124
+ }
125
+ /**
126
+ * Check if account was updated since
127
+ * @param seqno block sequence number
128
+ * @param address account address
129
+ * @param lt account last transaction lt
130
+ * @returns account change info
131
+ */
132
+ async isAccountChanged(seqno, address, lt) {
133
+ let res = await __classPrivateFieldGet(this, _TonClient4_axios, "f").get(__classPrivateFieldGet(this, _TonClient4_endpoint, "f") + '/block/' + seqno + '/' + address.toString({ urlSafe: true }) + '/changed/' + lt.toString(10), { adapter: __classPrivateFieldGet(this, _TonClient4_adapter, "f"), timeout: __classPrivateFieldGet(this, _TonClient4_timeout, "f") });
134
+ let changed = changedCodec.safeParse(res.data);
135
+ if (!changed.success) {
136
+ throw Error('Mailformed response');
137
+ }
138
+ return changed.data;
139
+ }
140
+ /**
141
+ * Load unparsed account transactions
142
+ * @param address address
143
+ * @param lt last transaction lt
144
+ * @param hash last transaction hash
145
+ * @returns unparsed transactions
146
+ */
147
+ async getAccountTransactions(address, lt, hash) {
148
+ let res = await __classPrivateFieldGet(this, _TonClient4_axios, "f").get(__classPrivateFieldGet(this, _TonClient4_endpoint, "f") + '/account/' + address.toString({ urlSafe: true }) + '/tx/' + lt.toString(10) + '/' + (0, toUrlSafe_1.toUrlSafe)(hash.toString('base64')), { adapter: __classPrivateFieldGet(this, _TonClient4_adapter, "f"), timeout: __classPrivateFieldGet(this, _TonClient4_timeout, "f") });
149
+ let transactions = transactionsCodec.safeParse(res.data);
150
+ if (!transactions.success) {
151
+ throw Error('Mailformed response');
152
+ }
153
+ let data = transactions.data;
154
+ let tx = [];
155
+ let cells = core_1.Cell.fromBoc(Buffer.from(data.boc, 'base64'));
156
+ for (let i = 0; i < data.blocks.length; i++) {
157
+ tx.push({
158
+ block: data.blocks[i],
159
+ tx: (0, core_1.loadTransaction)(cells[i].beginParse())
160
+ });
161
+ }
162
+ return tx;
163
+ }
164
+ /**
165
+ * Load parsed account transactions
166
+ * @param address address
167
+ * @param lt last transaction lt
168
+ * @param hash last transaction hash
169
+ * @param count number of transactions to load
170
+ * @returns parsed transactions
171
+ */
172
+ async getAccountTransactionsParsed(address, lt, hash, count = 20) {
173
+ let res = await __classPrivateFieldGet(this, _TonClient4_axios, "f").get(__classPrivateFieldGet(this, _TonClient4_endpoint, "f") + '/account/' + address.toString({ urlSafe: true }) + '/tx/parsed/' + lt.toString(10) + '/' + (0, toUrlSafe_1.toUrlSafe)(hash.toString('base64')), {
174
+ adapter: __classPrivateFieldGet(this, _TonClient4_adapter, "f"),
175
+ timeout: __classPrivateFieldGet(this, _TonClient4_timeout, "f"),
176
+ params: {
177
+ count
178
+ }
179
+ });
180
+ let parsedTransactionsRes = parsedTransactionsCodec.safeParse(res.data);
181
+ if (!parsedTransactionsRes.success) {
182
+ throw Error('Mailformed response');
183
+ }
184
+ return parsedTransactionsRes.data;
185
+ }
186
+ /**
187
+ * Get network config
188
+ * @param seqno block sequence number
189
+ * @param ids optional config ids
190
+ * @returns network config
191
+ */
192
+ async getConfig(seqno, ids) {
193
+ let tail = '';
194
+ if (ids && ids.length > 0) {
195
+ tail = '/' + [...ids].sort().join(',');
196
+ }
197
+ let res = await __classPrivateFieldGet(this, _TonClient4_axios, "f").get(__classPrivateFieldGet(this, _TonClient4_endpoint, "f") + '/block/' + seqno + '/config' + tail, { adapter: __classPrivateFieldGet(this, _TonClient4_adapter, "f"), timeout: __classPrivateFieldGet(this, _TonClient4_timeout, "f") });
198
+ let config = configCodec.safeParse(res.data);
199
+ if (!config.success) {
200
+ throw Error('Mailformed response');
201
+ }
202
+ return config.data;
203
+ }
204
+ /**
205
+ * Execute run method
206
+ * @param seqno block sequence number
207
+ * @param address account address
208
+ * @param name method name
209
+ * @param args method arguments
210
+ * @returns method result
211
+ */
212
+ async runMethod(seqno, address, name, args) {
213
+ let tail = args && args.length > 0 ? '/' + (0, toUrlSafe_1.toUrlSafe)((0, core_1.serializeTuple)(args).toBoc({ idx: false, crc32: false }).toString('base64')) : '';
214
+ let url = __classPrivateFieldGet(this, _TonClient4_endpoint, "f") + '/block/' + seqno + '/' + address.toString({ urlSafe: true }) + '/run/' + encodeURIComponent(name) + tail;
215
+ let res = await __classPrivateFieldGet(this, _TonClient4_axios, "f").get(url, { adapter: __classPrivateFieldGet(this, _TonClient4_adapter, "f"), timeout: __classPrivateFieldGet(this, _TonClient4_timeout, "f") });
216
+ let runMethod = runMethodCodec.safeParse(res.data);
217
+ if (!runMethod.success) {
218
+ throw Error('Mailformed response');
219
+ }
220
+ let resultTuple = runMethod.data.resultRaw ? (0, core_1.parseTuple)(core_1.Cell.fromBoc(Buffer.from(runMethod.data.resultRaw, 'base64'))[0]) : [];
221
+ return {
222
+ exitCode: runMethod.data.exitCode,
223
+ result: resultTuple,
224
+ resultRaw: runMethod.data.resultRaw,
225
+ block: runMethod.data.block,
226
+ shardBlock: runMethod.data.shardBlock,
227
+ reader: new core_1.TupleReader(resultTuple),
228
+ };
229
+ }
230
+ /**
231
+ * Send external message
232
+ * @param message message boc
233
+ * @returns message status
234
+ */
235
+ async sendMessage(message) {
236
+ let res = await __classPrivateFieldGet(this, _TonClient4_axios, "f").post(__classPrivateFieldGet(this, _TonClient4_endpoint, "f") + '/send', { boc: message.toString('base64') }, { adapter: __classPrivateFieldGet(this, _TonClient4_adapter, "f"), timeout: __classPrivateFieldGet(this, _TonClient4_timeout, "f") });
237
+ let send = sendCodec.safeParse(res.data);
238
+ if (!send.success) {
239
+ throw Error('Mailformed response');
240
+ }
241
+ return { status: res.data.status };
242
+ }
243
+ /**
244
+ * Open smart contract
245
+ * @param contract contract
246
+ * @returns opened contract
247
+ */
248
+ open(contract) {
249
+ return (0, core_1.openContract)(contract, (args) => createProvider(this, null, args.address, args.init));
250
+ }
251
+ /**
252
+ * Open smart contract
253
+ * @param block block number
254
+ * @param contract contract
255
+ * @returns opened contract
256
+ */
257
+ openAt(block, contract) {
258
+ return (0, core_1.openContract)(contract, (args) => createProvider(this, block, args.address, args.init));
259
+ }
260
+ /**
261
+ * Create provider
262
+ * @param address address
263
+ * @param init optional init data
264
+ * @returns provider
265
+ */
266
+ provider(address, init) {
267
+ return createProvider(this, null, address, init ?? null);
268
+ }
269
+ /**
270
+ * Create provider at specified block number
271
+ * @param block block number
272
+ * @param address address
273
+ * @param init optional init data
274
+ * @returns provider
275
+ */
276
+ providerAt(block, address, init) {
277
+ return createProvider(this, block, address, init ?? null);
278
+ }
279
+ }
280
+ exports.TonClient4 = TonClient4;
281
+ _TonClient4_endpoint = new WeakMap(), _TonClient4_timeout = new WeakMap(), _TonClient4_adapter = new WeakMap(), _TonClient4_axios = new WeakMap();
282
+ function createProvider(client, block, address, init) {
283
+ return {
284
+ async getState() {
285
+ // Resolve block
286
+ let sq = block;
287
+ if (sq === null) {
288
+ let res = await client.getLastBlock();
289
+ sq = res.last.seqno;
290
+ }
291
+ // Load state
292
+ let state = await client.getAccount(sq, address);
293
+ // Convert state
294
+ let last = state.account.last ? { lt: BigInt(state.account.last.lt), hash: Buffer.from(state.account.last.hash, 'base64') } : null;
295
+ let storage;
296
+ if (state.account.state.type === 'active') {
297
+ storage = {
298
+ type: 'active',
299
+ code: state.account.state.code ? Buffer.from(state.account.state.code, 'base64') : null,
300
+ data: state.account.state.data ? Buffer.from(state.account.state.data, 'base64') : null,
301
+ };
302
+ }
303
+ else if (state.account.state.type === 'uninit') {
304
+ storage = {
305
+ type: 'uninit',
306
+ };
307
+ }
308
+ else if (state.account.state.type === 'frozen') {
309
+ storage = {
310
+ type: 'frozen',
311
+ stateHash: Buffer.from(state.account.state.stateHash, 'base64'),
312
+ };
313
+ }
314
+ else {
315
+ throw Error('Unsupported state');
316
+ }
317
+ return {
318
+ balance: BigInt(state.account.balance.coins),
319
+ last: last,
320
+ state: storage
321
+ };
322
+ },
323
+ async get(name, args) {
324
+ let sq = block;
325
+ if (sq === null) {
326
+ let res = await client.getLastBlock();
327
+ sq = res.last.seqno;
328
+ }
329
+ let method = await client.runMethod(sq, address, name, args);
330
+ if (method.exitCode !== 0 && method.exitCode !== 1) {
331
+ throw Error('Exit code: ' + method.exitCode);
332
+ }
333
+ return {
334
+ stack: new core_1.TupleReader(method.result),
335
+ };
336
+ },
337
+ async external(message) {
338
+ // Resolve last
339
+ let last = await client.getLastBlock();
340
+ // Resolve init
341
+ let neededInit = null;
342
+ if (init && (await client.getAccountLite(last.last.seqno, address)).account.state.type !== 'active') {
343
+ neededInit = init;
344
+ }
345
+ // Send with state init
346
+ const ext = (0, core_1.external)({
347
+ to: address,
348
+ init: neededInit,
349
+ body: message
350
+ });
351
+ let pkg = (0, core_1.beginCell)()
352
+ .store((0, core_1.storeMessage)(ext))
353
+ .endCell()
354
+ .toBoc();
355
+ await client.sendMessage(pkg);
356
+ },
357
+ async internal(via, message) {
358
+ // Resolve last
359
+ let last = await client.getLastBlock();
360
+ // Resolve init
361
+ let neededInit = null;
362
+ if (init && (await client.getAccountLite(last.last.seqno, address)).account.state.type !== 'active') {
363
+ neededInit = init;
364
+ }
365
+ // Resolve bounce
366
+ let bounce = true;
367
+ if (message.bounce !== null && message.bounce !== undefined) {
368
+ bounce = message.bounce;
369
+ }
370
+ // Resolve value
371
+ let value;
372
+ if (typeof message.value === 'string') {
373
+ value = (0, core_1.toNano)(message.value);
374
+ }
375
+ else {
376
+ value = message.value;
377
+ }
378
+ // Resolve body
379
+ let body = null;
380
+ if (typeof message.body === 'string') {
381
+ body = (0, core_1.comment)(message.body);
382
+ }
383
+ else if (message.body) {
384
+ body = message.body;
385
+ }
386
+ // Send internal message
387
+ await via.send({
388
+ to: address,
389
+ value,
390
+ bounce,
391
+ sendMode: message.sendMode,
392
+ init: neededInit,
393
+ body
394
+ });
395
+ },
396
+ open(contract) {
397
+ return (0, core_1.openContract)(contract, (args) => createProvider(client, block, args.address, args.init ?? null));
398
+ },
399
+ async getTransactions(address, lt, hash, limit) {
400
+ // Resolve last
401
+ const useLimit = typeof limit === 'number';
402
+ if (useLimit && limit <= 0) {
403
+ return [];
404
+ }
405
+ // Load transactions
406
+ let transactions = [];
407
+ do {
408
+ const txs = await client.getAccountTransactions(address, lt, hash);
409
+ const firstTx = txs[0].tx;
410
+ const [firstLt, firstHash] = [firstTx.lt, firstTx.hash()];
411
+ const needSkipFirst = transactions.length > 0 && firstLt === lt && firstHash.equals(hash);
412
+ if (needSkipFirst) {
413
+ txs.shift();
414
+ }
415
+ if (txs.length === 0) {
416
+ break;
417
+ }
418
+ const lastTx = txs[txs.length - 1].tx;
419
+ const [lastLt, lastHash] = [lastTx.lt, lastTx.hash()];
420
+ if (lastLt === lt && lastHash.equals(hash)) {
421
+ break;
422
+ }
423
+ transactions.push(...txs.map(tx => tx.tx));
424
+ lt = lastLt;
425
+ hash = lastHash;
426
+ } while (useLimit && transactions.length < limit);
427
+ // Apply limit
428
+ if (useLimit) {
429
+ transactions = transactions.slice(0, limit);
430
+ }
431
+ // Return transactions
432
+ return transactions;
433
+ }
434
+ };
435
+ }
436
+ //
437
+ // Codecs
438
+ //
439
+ const lastBlockCodec = zod_1.z.object({
440
+ last: zod_1.z.object({
441
+ seqno: zod_1.z.number(),
442
+ shard: zod_1.z.string(),
443
+ workchain: zod_1.z.number(),
444
+ fileHash: zod_1.z.string(),
445
+ rootHash: zod_1.z.string()
446
+ }),
447
+ init: zod_1.z.object({
448
+ fileHash: zod_1.z.string(),
449
+ rootHash: zod_1.z.string()
450
+ }),
451
+ stateRootHash: zod_1.z.string(),
452
+ now: zod_1.z.number()
453
+ });
454
+ const blockCodec = zod_1.z.union([zod_1.z.object({
455
+ exist: zod_1.z.literal(false)
456
+ }), zod_1.z.object({
457
+ exist: zod_1.z.literal(true),
458
+ block: zod_1.z.object({
459
+ shards: zod_1.z.array(zod_1.z.object({
460
+ workchain: zod_1.z.number(),
461
+ seqno: zod_1.z.number(),
462
+ shard: zod_1.z.string(),
463
+ rootHash: zod_1.z.string(),
464
+ fileHash: zod_1.z.string(),
465
+ transactions: zod_1.z.array(zod_1.z.object({
466
+ account: zod_1.z.string(),
467
+ hash: zod_1.z.string(),
468
+ lt: zod_1.z.string()
469
+ }))
470
+ }))
471
+ })
472
+ })]);
473
+ // {"lastPaid":1653099243,"duePayment":null,"used":{"bits":119,"cells":1,"publicCells":0}}
474
+ const storageStatCodec = zod_1.z.object({
475
+ lastPaid: zod_1.z.number(),
476
+ duePayment: zod_1.z.union([zod_1.z.null(), zod_1.z.string()]),
477
+ used: zod_1.z.object({
478
+ bits: zod_1.z.number(),
479
+ cells: zod_1.z.number(),
480
+ publicCells: zod_1.z.number()
481
+ })
482
+ });
483
+ const accountCodec = zod_1.z.object({
484
+ account: zod_1.z.object({
485
+ state: zod_1.z.union([
486
+ zod_1.z.object({ type: zod_1.z.literal('uninit') }),
487
+ zod_1.z.object({ type: zod_1.z.literal('active'), code: zod_1.z.union([zod_1.z.string(), zod_1.z.null()]), data: zod_1.z.union([zod_1.z.string(), zod_1.z.null()]) }),
488
+ zod_1.z.object({ type: zod_1.z.literal('frozen'), stateHash: zod_1.z.string() })
489
+ ]),
490
+ balance: zod_1.z.object({
491
+ coins: zod_1.z.string()
492
+ }),
493
+ last: zod_1.z.union([
494
+ zod_1.z.null(),
495
+ zod_1.z.object({
496
+ lt: zod_1.z.string(),
497
+ hash: zod_1.z.string()
498
+ })
499
+ ]),
500
+ storageStat: zod_1.z.union([zod_1.z.null(), storageStatCodec])
501
+ }),
502
+ block: zod_1.z.object({
503
+ workchain: zod_1.z.number(),
504
+ seqno: zod_1.z.number(),
505
+ shard: zod_1.z.string(),
506
+ rootHash: zod_1.z.string(),
507
+ fileHash: zod_1.z.string()
508
+ })
509
+ });
510
+ const accountLiteCodec = zod_1.z.object({
511
+ account: zod_1.z.object({
512
+ state: zod_1.z.union([
513
+ zod_1.z.object({ type: zod_1.z.literal('uninit') }),
514
+ zod_1.z.object({ type: zod_1.z.literal('active'), codeHash: zod_1.z.string(), dataHash: zod_1.z.string() }),
515
+ zod_1.z.object({ type: zod_1.z.literal('frozen'), stateHash: zod_1.z.string() })
516
+ ]),
517
+ balance: zod_1.z.object({
518
+ coins: zod_1.z.string()
519
+ }),
520
+ last: zod_1.z.union([
521
+ zod_1.z.null(),
522
+ zod_1.z.object({
523
+ lt: zod_1.z.string(),
524
+ hash: zod_1.z.string()
525
+ })
526
+ ]),
527
+ storageStat: zod_1.z.union([zod_1.z.null(), storageStatCodec])
528
+ })
529
+ });
530
+ const changedCodec = zod_1.z.object({
531
+ changed: zod_1.z.boolean(),
532
+ block: zod_1.z.object({
533
+ workchain: zod_1.z.number(),
534
+ seqno: zod_1.z.number(),
535
+ shard: zod_1.z.string(),
536
+ rootHash: zod_1.z.string(),
537
+ fileHash: zod_1.z.string()
538
+ })
539
+ });
540
+ const runMethodCodec = zod_1.z.object({
541
+ exitCode: zod_1.z.number(),
542
+ resultRaw: zod_1.z.union([zod_1.z.string(), zod_1.z.null()]),
543
+ block: zod_1.z.object({
544
+ workchain: zod_1.z.number(),
545
+ seqno: zod_1.z.number(),
546
+ shard: zod_1.z.string(),
547
+ rootHash: zod_1.z.string(),
548
+ fileHash: zod_1.z.string()
549
+ }),
550
+ shardBlock: zod_1.z.object({
551
+ workchain: zod_1.z.number(),
552
+ seqno: zod_1.z.number(),
553
+ shard: zod_1.z.string(),
554
+ rootHash: zod_1.z.string(),
555
+ fileHash: zod_1.z.string()
556
+ })
557
+ });
558
+ const configCodec = zod_1.z.object({
559
+ config: zod_1.z.object({
560
+ cell: zod_1.z.string(),
561
+ address: zod_1.z.string(),
562
+ globalBalance: zod_1.z.object({
563
+ coins: zod_1.z.string()
564
+ })
565
+ })
566
+ });
567
+ const sendCodec = zod_1.z.object({
568
+ status: zod_1.z.number()
569
+ });
570
+ const blocksCodec = zod_1.z.array(zod_1.z.object({
571
+ workchain: zod_1.z.number(),
572
+ seqno: zod_1.z.number(),
573
+ shard: zod_1.z.string(),
574
+ rootHash: zod_1.z.string(),
575
+ fileHash: zod_1.z.string()
576
+ }));
577
+ const transactionsCodec = zod_1.z.object({
578
+ blocks: blocksCodec,
579
+ boc: zod_1.z.string()
580
+ });
581
+ const parsedAddressExternalCodec = zod_1.z.object({
582
+ bits: zod_1.z.number(),
583
+ data: zod_1.z.string()
584
+ });
585
+ const parsedMessageInfoCodec = zod_1.z.union([
586
+ zod_1.z.object({
587
+ type: zod_1.z.literal('internal'),
588
+ value: zod_1.z.string(),
589
+ dest: zod_1.z.string(),
590
+ src: zod_1.z.string(),
591
+ bounced: zod_1.z.boolean(),
592
+ bounce: zod_1.z.boolean(),
593
+ ihrDisabled: zod_1.z.boolean(),
594
+ createdAt: zod_1.z.number(),
595
+ createdLt: zod_1.z.string(),
596
+ fwdFee: zod_1.z.string(),
597
+ ihrFee: zod_1.z.string()
598
+ }),
599
+ zod_1.z.object({
600
+ type: zod_1.z.literal('external-in'),
601
+ dest: zod_1.z.string(),
602
+ src: zod_1.z.union([parsedAddressExternalCodec, zod_1.z.null()]),
603
+ importFee: zod_1.z.string()
604
+ }),
605
+ zod_1.z.object({
606
+ type: zod_1.z.literal('external-out'),
607
+ dest: zod_1.z.union([parsedAddressExternalCodec, zod_1.z.null()])
608
+ })
609
+ ]);
610
+ const parsedStateInitCodec = zod_1.z.object({
611
+ splitDepth: zod_1.z.union([zod_1.z.number(), zod_1.z.null()]),
612
+ code: zod_1.z.union([zod_1.z.string(), zod_1.z.null()]),
613
+ data: zod_1.z.union([zod_1.z.string(), zod_1.z.null()]),
614
+ special: zod_1.z.union([zod_1.z.object({ tick: zod_1.z.boolean(), tock: zod_1.z.boolean() }), zod_1.z.null()])
615
+ });
616
+ const parsedMessageCodec = zod_1.z.object({
617
+ body: zod_1.z.string(),
618
+ info: parsedMessageInfoCodec,
619
+ init: zod_1.z.union([parsedStateInitCodec, zod_1.z.null()])
620
+ });
621
+ const accountStatusCodec = zod_1.z.union([zod_1.z.literal('uninitialized'), zod_1.z.literal('frozen'), zod_1.z.literal('active'), zod_1.z.literal('non-existing')]);
622
+ const txBodyCodec = zod_1.z.union([
623
+ zod_1.z.object({ type: zod_1.z.literal('comment'), comment: zod_1.z.string() }),
624
+ zod_1.z.object({ type: zod_1.z.literal('payload'), cell: zod_1.z.string() }),
625
+ ]);
626
+ const parsedOperationItemCodec = zod_1.z.union([
627
+ zod_1.z.object({ kind: zod_1.z.literal('ton'), amount: zod_1.z.string() }),
628
+ zod_1.z.object({ kind: zod_1.z.literal('token'), amount: zod_1.z.string() })
629
+ ]);
630
+ const supportedMessageTypeCodec = zod_1.z.union([
631
+ zod_1.z.literal('jetton::excesses'),
632
+ zod_1.z.literal('jetton::transfer'),
633
+ zod_1.z.literal('jetton::transfer_notification'),
634
+ zod_1.z.literal('deposit'),
635
+ zod_1.z.literal('deposit::ok'),
636
+ zod_1.z.literal('withdraw'),
637
+ zod_1.z.literal('withdraw::all'),
638
+ zod_1.z.literal('withdraw::delayed'),
639
+ zod_1.z.literal('withdraw::ok'),
640
+ zod_1.z.literal('airdrop')
641
+ ]);
642
+ const opCodec = zod_1.z.object({
643
+ type: supportedMessageTypeCodec,
644
+ options: zod_1.z.optional(zod_1.z.record(zod_1.z.string()))
645
+ });
646
+ const parsedOperationCodec = zod_1.z.object({
647
+ address: zod_1.z.string(),
648
+ comment: zod_1.z.optional(zod_1.z.string()),
649
+ items: zod_1.z.array(parsedOperationItemCodec),
650
+ op: zod_1.z.optional(opCodec)
651
+ });
652
+ const parsedTransactionCodec = zod_1.z.object({
653
+ address: zod_1.z.string(),
654
+ lt: zod_1.z.string(),
655
+ hash: zod_1.z.string(),
656
+ prevTransaction: zod_1.z.object({
657
+ lt: zod_1.z.string(),
658
+ hash: zod_1.z.string()
659
+ }),
660
+ time: zod_1.z.number(),
661
+ outMessagesCount: zod_1.z.number(),
662
+ oldStatus: accountStatusCodec,
663
+ newStatus: accountStatusCodec,
664
+ fees: zod_1.z.string(),
665
+ update: zod_1.z.object({
666
+ oldHash: zod_1.z.string(),
667
+ newHash: zod_1.z.string()
668
+ }),
669
+ inMessage: zod_1.z.union([parsedMessageCodec, zod_1.z.null()]),
670
+ outMessages: zod_1.z.array(parsedMessageCodec),
671
+ parsed: zod_1.z.object({
672
+ seqno: zod_1.z.union([zod_1.z.number(), zod_1.z.null()]),
673
+ body: zod_1.z.union([txBodyCodec, zod_1.z.null()]),
674
+ status: zod_1.z.union([zod_1.z.literal('success'), zod_1.z.literal('failed'), zod_1.z.literal('pending')]),
675
+ dest: zod_1.z.union([zod_1.z.string(), zod_1.z.null()]),
676
+ kind: zod_1.z.union([zod_1.z.literal('out'), zod_1.z.literal('in')]),
677
+ amount: zod_1.z.string(),
678
+ resolvedAddress: zod_1.z.string(),
679
+ bounced: zod_1.z.boolean(),
680
+ mentioned: zod_1.z.array(zod_1.z.string())
681
+ }),
682
+ operation: parsedOperationCodec
683
+ });
684
+ const parsedTransactionsCodec = zod_1.z.object({
685
+ blocks: blocksCodec,
686
+ transactions: zod_1.z.array(parsedTransactionCodec)
687
+ });
@@ -0,0 +1 @@
1
+ export {};