@tonappchain/sdk 0.7.1 → 0.7.2-alpha-2

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 (74) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +198 -198
  3. package/dist/artifacts/dev/ton/internal/build/CrossChainLayer.compiled.json +1 -1
  4. package/dist/artifacts/dev/ton/internal/build/Executor.compiled.json +1 -1
  5. package/dist/artifacts/dev/ton/internal/build/JettonMinter.compiled.json +1 -1
  6. package/dist/artifacts/dev/ton/internal/build/JettonProxy.compiled.json +1 -1
  7. package/dist/artifacts/dev/ton/internal/build/JettonWallet.compiled.json +1 -1
  8. package/dist/artifacts/dev/ton/internal/build/NFTItem.compiled.json +1 -1
  9. package/dist/artifacts/dev/ton/internal/build/NFTProxy.compiled.json +1 -1
  10. package/dist/artifacts/dev/ton/internal/wrappers/CrossChainLayer.d.ts +13 -1
  11. package/dist/artifacts/dev/ton/internal/wrappers/CrossChainLayer.js +45 -7
  12. package/dist/artifacts/dev/ton/internal/wrappers/JettonMinter.d.ts +2 -2
  13. package/dist/artifacts/dev/ton/internal/wrappers/JettonMinter.js +2 -2
  14. package/dist/artifacts/testnet/ton/internal/build/CrossChainLayer.compiled.json +1 -1
  15. package/dist/artifacts/testnet/ton/internal/build/Executor.compiled.json +1 -1
  16. package/dist/artifacts/testnet/ton/internal/build/JettonMinter.compiled.json +1 -1
  17. package/dist/artifacts/testnet/ton/internal/build/JettonProxy.compiled.json +1 -1
  18. package/dist/artifacts/testnet/ton/internal/build/JettonWallet.compiled.json +1 -1
  19. package/dist/artifacts/testnet/ton/internal/build/NFTItem.compiled.json +1 -1
  20. package/dist/artifacts/testnet/ton/internal/build/NFTProxy.compiled.json +1 -1
  21. package/dist/artifacts/testnet/ton/internal/wrappers/CrossChainLayer.d.ts +13 -1
  22. package/dist/artifacts/testnet/ton/internal/wrappers/CrossChainLayer.js +45 -7
  23. package/dist/artifacts/testnet/ton/internal/wrappers/JettonMinter.d.ts +2 -2
  24. package/dist/artifacts/testnet/ton/internal/wrappers/JettonMinter.js +2 -2
  25. package/dist/src/adapters/contractOpener.d.ts +4 -0
  26. package/dist/src/adapters/contractOpener.js +162 -1
  27. package/dist/src/adapters/retryableContractOpener.d.ts +5 -1
  28. package/dist/src/adapters/retryableContractOpener.js +38 -7
  29. package/dist/src/assets/AssetFactory.js +8 -2
  30. package/dist/src/assets/FT.d.ts +1 -1
  31. package/dist/src/assets/FT.js +1 -1
  32. package/dist/src/assets/NFT.d.ts +1 -1
  33. package/dist/src/assets/NFT.js +1 -1
  34. package/dist/src/assets/TON.d.ts +3 -2
  35. package/dist/src/assets/TON.js +2 -1
  36. package/dist/src/errors/instances.d.ts +2 -0
  37. package/dist/src/errors/instances.js +3 -1
  38. package/dist/src/index.d.ts +1 -1
  39. package/dist/src/index.js +2 -4
  40. package/dist/src/interfaces/Asset.d.ts +4 -9
  41. package/dist/src/interfaces/ContractOpener.d.ts +5 -1
  42. package/dist/src/interfaces/ISimulator.d.ts +15 -1
  43. package/dist/src/interfaces/ITONTransactionManager.d.ts +20 -1
  44. package/dist/src/interfaces/ITacSDK.d.ts +10 -1
  45. package/dist/src/interfaces/ITxFinalizer.d.ts +5 -0
  46. package/dist/src/interfaces/ITxFinalizer.js +2 -0
  47. package/dist/src/interfaces/WalletInstanse.d.ts +4 -8
  48. package/dist/src/sdk/Consts.d.ts +50 -1
  49. package/dist/src/sdk/Consts.js +52 -2
  50. package/dist/src/sdk/Simulator.d.ts +11 -2
  51. package/dist/src/sdk/Simulator.js +190 -0
  52. package/dist/src/sdk/StartTracking.d.ts +5 -3
  53. package/dist/src/sdk/StartTracking.js +60 -40
  54. package/dist/src/sdk/TONTransactionManager.d.ts +8 -5
  55. package/dist/src/sdk/TONTransactionManager.js +50 -7
  56. package/dist/src/sdk/TacSdk.d.ts +2 -1
  57. package/dist/src/sdk/TacSdk.js +7 -1
  58. package/dist/src/sdk/TxFinalizer.d.ts +15 -4
  59. package/dist/src/sdk/TxFinalizer.js +102 -23
  60. package/dist/src/sdk/Utils.d.ts +10 -1
  61. package/dist/src/sdk/Utils.js +48 -0
  62. package/dist/src/sender/BatchSender.js +19 -0
  63. package/dist/src/sender/MockSender.d.ts +2 -0
  64. package/dist/src/sender/MockSender.js +13 -0
  65. package/dist/src/sender/RawSender.js +34 -1
  66. package/dist/src/sender/SenderFactory.js +1 -1
  67. package/dist/src/sender/TonConnectSender.js +2 -0
  68. package/dist/src/sender/index.d.ts +1 -0
  69. package/dist/src/sender/index.js +1 -0
  70. package/dist/src/structs/InternalStruct.d.ts +45 -1
  71. package/dist/src/structs/Struct.d.ts +29 -2
  72. package/dist/src/wrappers/HighloadWalletV3.d.ts +5 -3
  73. package/dist/src/wrappers/HighloadWalletV3.js +14 -3
  74. package/package.json +116 -118
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAdjacentTransactionsHelper = getAdjacentTransactionsHelper;
3
4
  exports.liteClientOpener = liteClientOpener;
4
5
  exports.sandboxOpener = sandboxOpener;
5
6
  exports.orbsOpener = orbsOpener;
6
7
  exports.orbsOpener4 = orbsOpener4;
8
+ exports.tonClientOpener = tonClientOpener;
7
9
  const ton_access_1 = require("@orbs-network/ton-access");
8
10
  const ton_1 = require("@ton/ton");
9
11
  const ton_lite_client_1 = require("@tonappchain/ton-lite-client");
@@ -42,6 +44,74 @@ async function getHttpV4EndpointWithRetry(network, maxRetries = 5, delay = 1000)
42
44
  }
43
45
  throw lastError || new Error('Failed to get HTTP V4 endpoint after retries');
44
46
  }
47
+ async function findTransactionByHash(addr, targetHashB64, getTransactions, opts) {
48
+ const timeoutMs = opts?.timeoutMs ?? 60000; // 60 seconds default
49
+ const retryDelayMs = opts?.retryDelayMs ?? 2000; // 2 seconds between retries
50
+ const deadline = Date.now() + timeoutMs;
51
+ const limit = opts?.limit ?? 10;
52
+ while (Date.now() < deadline) {
53
+ const batch = await getTransactions(addr, {
54
+ limit,
55
+ archival: opts?.archival ?? true,
56
+ });
57
+ // Check each transaction in the current batch
58
+ for (const tx of batch) {
59
+ // 1. check tx itself
60
+ if (tx.hash().toString('base64') === targetHashB64) {
61
+ return tx;
62
+ }
63
+ // 2. check incoming message(external-in)
64
+ if (tx.inMessage && tx.inMessage.info.type === 'external-in') {
65
+ const hash = (0, Utils_1.getNormalizedExtMessageHash)(tx.inMessage);
66
+ if (hash === targetHashB64) {
67
+ return tx;
68
+ }
69
+ }
70
+ // 3. check incoming message(internal)
71
+ if (tx.inMessage && tx.inMessage.info.type === 'internal') {
72
+ const messageCell = (0, ton_1.beginCell)().store((0, ton_1.storeMessage)(tx.inMessage)).endCell();
73
+ const hash = messageCell.hash();
74
+ if (hash.toString('base64') === targetHashB64) {
75
+ return tx;
76
+ }
77
+ }
78
+ }
79
+ if (Date.now() < deadline) {
80
+ await (0, Utils_1.sleep)(retryDelayMs);
81
+ }
82
+ }
83
+ return null;
84
+ }
85
+ async function getAdjacentTransactionsHelper(addr, hashB64, getTransactions, opts) {
86
+ // 1. Find the root transaction
87
+ const rootTx = await findTransactionByHash(addr, hashB64, getTransactions, opts);
88
+ if (!rootTx)
89
+ return [];
90
+ const adjacent = [];
91
+ // 2. Follow every outgoing message
92
+ for (const msg of rootTx.outMessages.values()) {
93
+ const dst = msg.info.dest;
94
+ if (!dst || dst instanceof ton_1.ExternalAddress)
95
+ continue;
96
+ const msgHashB64 = (0, ton_1.beginCell)().store((0, ton_1.storeMessage)(msg)).endCell().hash().toString('base64');
97
+ const tx = await findTransactionByHash(dst, msgHashB64, getTransactions, opts);
98
+ if (tx)
99
+ adjacent.push(tx);
100
+ }
101
+ // 3. Optional: follow the incoming message (if it exists and is internal)
102
+ if (rootTx.inMessage?.info.type === 'internal') {
103
+ const src = rootTx.inMessage.info.src;
104
+ if (src instanceof ton_1.Address) {
105
+ // The incoming message belongs to the sender's out-message list,
106
+ // so we look for the same message hash on the sender side.
107
+ const msgHashB64 = (0, ton_1.beginCell)().store((0, ton_1.storeMessage)(rootTx.inMessage)).endCell().hash().toString('base64');
108
+ const tx = await findTransactionByHash(src, msgHashB64, getTransactions, opts);
109
+ if (tx)
110
+ adjacent.push(tx);
111
+ }
112
+ }
113
+ return adjacent;
114
+ }
45
115
  function intToIP(int) {
46
116
  const part1 = int & 255;
47
117
  const part2 = (int >> 8) & 255;
@@ -72,6 +142,14 @@ async function liteClientOpener(options) {
72
142
  const closeConnections = () => {
73
143
  engine.close();
74
144
  };
145
+ const getTransactions = async (address, opts) => {
146
+ const txsBuffered = await client
147
+ .getAccountTransactions(address, opts.lt ?? '', opts.hash ? Buffer.from(opts.hash, 'base64') : Buffer.alloc(0), opts.limit)
148
+ .then((r) => r.transactions);
149
+ const cell = ton_1.Cell.fromBoc(txsBuffered);
150
+ const transactions = cell.map((c) => (0, ton_1.loadTransaction)(c.beginParse()));
151
+ return transactions;
152
+ };
75
153
  return {
76
154
  getContractState: async (addr) => {
77
155
  const block = await client.getMasterchainInfo();
@@ -86,6 +164,21 @@ async function liteClientOpener(options) {
86
164
  },
87
165
  open: (contract) => client.open(contract),
88
166
  closeConnections,
167
+ getTransactionByHash: async (addr, hash, opts) => {
168
+ const tx = await findTransactionByHash(addr, hash, getTransactions, opts);
169
+ return tx;
170
+ },
171
+ getAdjacentTransactions: async (addr, hash, opts) => getAdjacentTransactionsHelper(addr, hash, getTransactions, opts),
172
+ getAddressInformation: async (addr) => {
173
+ const block = await client.getMasterchainInfo();
174
+ const state = await client.getAccountState(addr, block.last);
175
+ return {
176
+ lastTransaction: {
177
+ lt: state.lastTx?.lt.toString() ?? '',
178
+ hash: Buffer.from(state.lastTx?.hash.toString(16) ?? '', 'hex').toString('base64'),
179
+ },
180
+ };
181
+ },
89
182
  };
90
183
  }
91
184
  function sandboxOpener(blockchain) {
@@ -99,15 +192,47 @@ function sandboxOpener(blockchain) {
99
192
  state: state.state.type === 'uninit' ? 'uninitialized' : state.state.type,
100
193
  };
101
194
  },
195
+ getTransactionByHash: () => {
196
+ throw new Error('Not implemented.');
197
+ },
198
+ getAdjacentTransactions() {
199
+ throw new Error('Not implemented.');
200
+ },
201
+ getAddressInformation: async () => {
202
+ throw new Error('Not implemented.');
203
+ },
102
204
  };
103
205
  }
104
206
  async function orbsOpener(network) {
105
207
  const endpoint = await getHttpEndpointWithRetry(network);
106
- return new ton_1.TonClient({ endpoint });
208
+ const client = new ton_1.TonClient({ endpoint });
209
+ return {
210
+ open: client.open,
211
+ getContractState: client.getContractState,
212
+ getTransactionByHash: async (addr, hash, opts) => {
213
+ const tx = await findTransactionByHash(addr, hash, client.getTransactions, opts);
214
+ return tx;
215
+ },
216
+ getAdjacentTransactions: async (addr, hash, opts) => getAdjacentTransactionsHelper(addr, hash, client.getTransactions, opts),
217
+ getAddressInformation: async (addr) => {
218
+ const state = await client.getContractState(addr);
219
+ return {
220
+ lastTransaction: {
221
+ lt: state.lastTransaction?.lt ?? '',
222
+ hash: state.lastTransaction?.hash ?? '',
223
+ },
224
+ };
225
+ },
226
+ };
107
227
  }
108
228
  async function orbsOpener4(network, timeout = 10000) {
109
229
  const endpoint = await getHttpV4EndpointWithRetry(network);
110
230
  const client4 = new ton_1.TonClient4({ endpoint, timeout });
231
+ const getTransactions = async (address, opts) => {
232
+ return client4
233
+ .getAccountTransactions(address, opts.lt ? BigInt(opts.lt) : 0n, opts.hash ? Buffer.from(opts.hash, 'base64') : Buffer.alloc(0))
234
+ .then((res) => res.map((t) => t.tx));
235
+ };
111
236
  return {
112
237
  open: (contract) => client4.open(contract),
113
238
  getContractState: async (address) => {
@@ -122,5 +247,41 @@ async function orbsOpener4(network, timeout = 10000) {
122
247
  state: state.account.state.type === 'uninit' ? 'uninitialized' : state.account.state.type,
123
248
  };
124
249
  },
250
+ getTransactionByHash: async (addr, hash, opts) => {
251
+ const tx = await findTransactionByHash(addr, hash, getTransactions, opts);
252
+ return tx;
253
+ },
254
+ getAdjacentTransactions: async (addr, hash, opts) => getAdjacentTransactionsHelper(addr, hash, getTransactions, opts),
255
+ getAddressInformation: async (addr) => {
256
+ const latestBlock = await client4.getLastBlock();
257
+ const latestBlockNumber = latestBlock.last.seqno;
258
+ const state = await client4.getAccount(latestBlockNumber, addr);
259
+ return {
260
+ lastTransaction: {
261
+ lt: state.account.last?.lt ?? '',
262
+ hash: state.account.last?.hash ?? '',
263
+ },
264
+ };
265
+ },
266
+ };
267
+ }
268
+ function tonClientOpener(client) {
269
+ return {
270
+ open: client.open.bind(client),
271
+ getContractState: client.getContractState.bind(client),
272
+ getTransactionByHash: async (addr, hash, opts) => {
273
+ const tx = await findTransactionByHash(addr, hash, client.getTransactions.bind(client), opts);
274
+ return tx;
275
+ },
276
+ getAdjacentTransactions: async (addr, hash, opts) => getAdjacentTransactionsHelper(addr, hash, client.getTransactions.bind(client), opts),
277
+ getAddressInformation: async (addr) => {
278
+ const state = await client.getContractState(addr);
279
+ return {
280
+ lastTransaction: {
281
+ lt: state.lastTransaction?.lt ?? '',
282
+ hash: state.lastTransaction?.hash ?? '',
283
+ },
284
+ };
285
+ },
125
286
  };
126
287
  }
@@ -1,6 +1,7 @@
1
1
  import { SandboxContract } from '@ton/sandbox';
2
- import { Address, Contract, OpenedContract } from '@ton/ton';
2
+ import { Address, Contract, OpenedContract, Transaction } from '@ton/ton';
3
3
  import { ContractOpener } from '../interfaces';
4
+ import { AddressInformation, GetTransactionsOptions } from '../structs/InternalStruct';
4
5
  import { ContractState, Network } from '../structs/Struct';
5
6
  export interface OpenerConfig {
6
7
  /** Underlying opener implementation to use for this slot. */
@@ -13,8 +14,11 @@ export interface OpenerConfig {
13
14
  export declare class RetryableContractOpener implements ContractOpener {
14
15
  private readonly openerConfigs;
15
16
  constructor(openerConfigs: OpenerConfig[]);
17
+ getTransactionByHash(address: Address, hash: string, opts: GetTransactionsOptions): Promise<Transaction | null>;
18
+ getAdjacentTransactions(address: Address, hash: string): Promise<Transaction[]>;
16
19
  open<T extends Contract>(src: T): OpenedContract<T> | SandboxContract<T>;
17
20
  getContractState(address: Address): Promise<ContractState>;
21
+ getAddressInformation(address: Address): Promise<AddressInformation>;
18
22
  closeConnections(): void;
19
23
  private executeWithFallback;
20
24
  private tryWithRetries;
@@ -14,6 +14,20 @@ class RetryableContractOpener {
14
14
  }
15
15
  this.openerConfigs = openerConfigs;
16
16
  }
17
+ async getTransactionByHash(address, hash, opts) {
18
+ const result = await this.executeWithFallback((config) => config.opener.getTransactionByHash(address, hash, opts));
19
+ if (result.success && result.data) {
20
+ return result.data;
21
+ }
22
+ throw result.lastError || (0, instances_1.allContractOpenerFailedError)('Failed to get transaction by hash');
23
+ }
24
+ async getAdjacentTransactions(address, hash) {
25
+ const result = await this.executeWithFallback((config) => config.opener.getAdjacentTransactions(address, hash));
26
+ if (result.success && result.data) {
27
+ return result.data;
28
+ }
29
+ throw result.lastError || (0, instances_1.allContractOpenerFailedError)('Failed to get account transactions');
30
+ }
17
31
  open(src) {
18
32
  const firstConfig = this.openerConfigs[0];
19
33
  const contract = firstConfig.opener.open(src);
@@ -26,6 +40,13 @@ class RetryableContractOpener {
26
40
  }
27
41
  throw result.lastError || (0, instances_1.allContractOpenerFailedError)('Failed to get contract state');
28
42
  }
43
+ async getAddressInformation(address) {
44
+ const result = await this.executeWithFallback((config) => config.opener.getAddressInformation(address));
45
+ if (result.success && result.data) {
46
+ return result.data;
47
+ }
48
+ throw result.lastError || (0, instances_1.allContractOpenerFailedError)('Failed to get address information');
49
+ }
29
50
  closeConnections() {
30
51
  for (const config of this.openerConfigs) {
31
52
  config.opener.closeConnections?.();
@@ -87,14 +108,24 @@ class RetryableContractOpener {
87
108
  exports.RetryableContractOpener = RetryableContractOpener;
88
109
  async function createDefaultRetryableOpener(tonRpcEndpoint, networkType, maxRetries = 5, retryDelay = 1000) {
89
110
  const openers = [];
90
- const tonClient = new ton_1.TonClient({
91
- endpoint: new URL('api/v2/jsonRPC', tonRpcEndpoint).toString(),
92
- });
93
- openers.push({ opener: tonClient, retries: maxRetries, retryDelay });
111
+ const tonClient = new ton_1.TonClient({ endpoint: new URL('api/v2/jsonRPC', tonRpcEndpoint).toString() });
112
+ const opener = (0, contractOpener_1.tonClientOpener)(tonClient);
113
+ openers.push({ opener, retries: maxRetries, retryDelay });
94
114
  if (networkType !== Struct_1.Network.DEV) {
95
- const opener4 = await (0, contractOpener_1.orbsOpener4)(networkType);
96
- const opener = await (0, contractOpener_1.orbsOpener)(networkType);
97
- openers.push({ opener: opener4, retries: maxRetries, retryDelay }, { opener: opener, retries: maxRetries, retryDelay });
115
+ try {
116
+ const opener4 = await (0, contractOpener_1.orbsOpener4)(networkType);
117
+ openers.push({ opener: opener4, retries: maxRetries, retryDelay });
118
+ }
119
+ catch {
120
+ // skip opener in case of failure
121
+ }
122
+ try {
123
+ const opener = await (0, contractOpener_1.orbsOpener)(networkType);
124
+ openers.push({ opener: opener, retries: maxRetries, retryDelay });
125
+ }
126
+ catch {
127
+ // skip opener in case of failure
128
+ }
98
129
  }
99
130
  return new RetryableContractOpener(openers);
100
131
  }
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AssetFactory = void 0;
4
4
  const errors_1 = require("../errors");
5
+ const Consts_1 = require("../sdk/Consts");
5
6
  const Struct_1 = require("../structs/Struct");
6
7
  const AssetCache_1 = require("./AssetCache");
7
8
  const FT_1 = require("./FT");
@@ -9,7 +10,9 @@ const NFT_1 = require("./NFT");
9
10
  const TON_1 = require("./TON");
10
11
  class AssetFactory {
11
12
  static async from(configuration, token) {
12
- if (token.address === '' || token.address === configuration.nativeTONAddress) {
13
+ if (token.address === '' ||
14
+ token.address === configuration.nativeTONAddress ||
15
+ token.address === Consts_1.TON_BURN_ADDRESS) {
13
16
  if (token.tokenType !== Struct_1.AssetType.FT)
14
17
  throw (0, errors_1.unknownTokenTypeError)(token.address, 'detected TON, but token type is not FT');
15
18
  return TON_1.TON.create(configuration);
@@ -26,7 +29,10 @@ class AssetFactory {
26
29
  }
27
30
  static async createFTAsset(configuration, address) {
28
31
  const ton = TON_1.TON.create(configuration);
29
- if (address === configuration.nativeTONAddress || address === '' || address === (await ton.getEVMAddress())) {
32
+ if (address === configuration.nativeTONAddress ||
33
+ address === '' ||
34
+ address === (await ton.getEVMAddress()) ||
35
+ address === Consts_1.TON_BURN_ADDRESS) {
30
36
  return ton;
31
37
  }
32
38
  return FT_1.FT.fromAddress(configuration, address);
@@ -39,7 +39,7 @@ export declare class FT implements Asset {
39
39
  crossChainTonAmount?: bigint;
40
40
  forwardFeeTonAmount?: bigint;
41
41
  feeParams?: FeeParams;
42
- }): Promise<Cell>;
42
+ }): Cell;
43
43
  get opType(): AssetOpType.JETTON_BURN | AssetOpType.JETTON_TRANSFER;
44
44
  getWallet(userAddress: string): Promise<OpenedContract<JettonWallet> | SandboxContract<JettonWallet>>;
45
45
  getUserWalletAddress(userAddress: string): Promise<string>;
@@ -197,7 +197,7 @@ class FT {
197
197
  async getTVMAddress() {
198
198
  return this._tvmAddress.toString({ bounceable: true });
199
199
  }
200
- async generatePayload(params) {
200
+ generatePayload(params) {
201
201
  const { excessReceiver, evmData, crossChainTonAmount = 0n, forwardFeeTonAmount = 0n, feeParams } = params;
202
202
  const feeData = (0, Utils_1.generateFeeData)(feeParams);
203
203
  let payload;
@@ -59,7 +59,7 @@ export declare class NFT implements Asset {
59
59
  crossChainTonAmount?: bigint;
60
60
  forwardFeeTonAmount?: bigint;
61
61
  feeParams?: FeeParams;
62
- }): Promise<Cell>;
62
+ }): Cell;
63
63
  isOwnedBy(userAddress: string): Promise<boolean>;
64
64
  checkCanBeTransferredBy(userAddress: string): Promise<void>;
65
65
  getBalanceOf(userAddress: string): Promise<bigint>;
@@ -188,7 +188,7 @@ class NFT {
188
188
  async getTVMAddress() {
189
189
  return this.address.toString();
190
190
  }
191
- async generatePayload(params) {
191
+ generatePayload(params) {
192
192
  const { excessReceiver, evmData, crossChainTonAmount = 0n, forwardFeeTonAmount = 0n, feeParams } = params;
193
193
  const opType = this.origin === Struct_1.Origin.TAC ? InternalStruct_1.AssetOpType.NFT_BURN : InternalStruct_1.AssetOpType.NFT_TRANSFER;
194
194
  const feeData = (0, Utils_1.generateFeeData)(feeParams);
@@ -2,13 +2,14 @@ import { Cell } from '@ton/ton';
2
2
  import { Asset, IConfiguration } from '../interfaces';
3
3
  import type { SenderAbstraction } from '../sender';
4
4
  import type { ShardTransaction } from '../structs/InternalStruct';
5
- import { AssetType, FeeParams } from '../structs/Struct';
5
+ import { AssetType, FeeParams, Origin } from '../structs/Struct';
6
6
  export declare class TON implements Asset {
7
7
  readonly address: string;
8
8
  readonly type: AssetType;
9
9
  private evmAddress;
10
10
  private _rawAmount;
11
11
  private _config;
12
+ readonly origin: Origin;
12
13
  constructor(config: IConfiguration);
13
14
  static create(config: IConfiguration): TON;
14
15
  get rawAmount(): bigint;
@@ -25,7 +26,7 @@ export declare class TON implements Asset {
25
26
  crossChainTonAmount?: bigint;
26
27
  forwardFeeTonAmount?: bigint;
27
28
  feeParams?: FeeParams;
28
- }): Promise<Cell>;
29
+ }): Cell;
29
30
  getUserBalance(userAddress: string): Promise<bigint>;
30
31
  static checkBalance(sender: SenderAbstraction, config: IConfiguration, transactions: ShardTransaction[]): Promise<void>;
31
32
  checkCanBeTransferredBy(userAddress: string): Promise<void>;
@@ -9,6 +9,7 @@ const Struct_1 = require("../structs/Struct");
9
9
  class TON {
10
10
  constructor(config) {
11
11
  this.type = Struct_1.AssetType.FT;
12
+ this.origin = Struct_1.Origin.TON;
12
13
  this.address = '';
13
14
  this._config = config;
14
15
  this._rawAmount = 0n;
@@ -60,7 +61,7 @@ class TON {
60
61
  async getTVMAddress() {
61
62
  return '';
62
63
  }
63
- async generatePayload(params) {
64
+ generatePayload(params) {
64
65
  const { excessReceiver, evmData, feeParams } = params;
65
66
  const queryId = (0, Utils_1.generateRandomNumberByTimestamp)().randomNumber;
66
67
  const feeData = (0, Utils_1.generateFeeData)(feeParams);
@@ -1,3 +1,4 @@
1
+ import { Origin } from '../structs/Struct';
1
2
  import { AddressError, BitError, ContractError, EVMCallError, FetchError, FormatError, InsufficientBalanceError, KeyError, MetadataError, NoValidGroupFoundError, PrepareMessageGroupError, SettingError, TokenError, WalletError } from './errors';
2
3
  export declare const emptyContractError: ContractError;
3
4
  export declare const operationFetchError: (msg: string, inner?: unknown) => FetchError;
@@ -32,3 +33,4 @@ export declare const missingJettonDataError: MetadataError;
32
33
  export declare const zeroRawAmountError: (assetAddress: string) => TokenError;
33
34
  export declare const sendCrossChainTransactionFailedError: (msg: string) => WalletError;
34
35
  export declare const convertCurrencyNegativeOrZeroValueError: FormatError;
36
+ export declare const unknownAssetOriginError: (origin: Origin) => TokenError;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.convertCurrencyNegativeOrZeroValueError = exports.sendCrossChainTransactionFailedError = exports.zeroRawAmountError = exports.missingJettonDataError = exports.missingDecimals = exports.missingGasLimitError = exports.missingTvmExecutorFeeError = exports.missingFeeParamsError = exports.getTONFeeInfoFetchError = exports.simulationFetchError = exports.convertCurrencyFetchError = exports.indexRequiredError = exports.unknownTokenTypeError = exports.insufficientBalanceError = exports.allContractOpenerFailedError = exports.allEndpointsFailedError = exports.noValidGroupFoundError = exports.prepareMessageGroupError = exports.invalidAssetType = exports.emptyArrayError = exports.profilingFetchError = exports.invalidMethodNameError = exports.emptySettingError = exports.prefixError = exports.notMultiplyOf8Error = exports.unsupportedFormatError = exports.unsupportedKeyError = exports.unknownWalletError = exports.evmAddressError = exports.tvmAddressError = exports.statusFetchError = exports.operationFetchError = exports.emptyContractError = void 0;
3
+ exports.unknownAssetOriginError = exports.convertCurrencyNegativeOrZeroValueError = exports.sendCrossChainTransactionFailedError = exports.zeroRawAmountError = exports.missingJettonDataError = exports.missingDecimals = exports.missingGasLimitError = exports.missingTvmExecutorFeeError = exports.missingFeeParamsError = exports.getTONFeeInfoFetchError = exports.simulationFetchError = exports.convertCurrencyFetchError = exports.indexRequiredError = exports.unknownTokenTypeError = exports.insufficientBalanceError = exports.allContractOpenerFailedError = exports.allEndpointsFailedError = exports.noValidGroupFoundError = exports.prepareMessageGroupError = exports.invalidAssetType = exports.emptyArrayError = exports.profilingFetchError = exports.invalidMethodNameError = exports.emptySettingError = exports.prefixError = exports.notMultiplyOf8Error = exports.unsupportedFormatError = exports.unsupportedKeyError = exports.unknownWalletError = exports.evmAddressError = exports.tvmAddressError = exports.statusFetchError = exports.operationFetchError = exports.emptyContractError = void 0;
4
4
  const errors_1 = require("./errors");
5
5
  exports.emptyContractError = new errors_1.ContractError('unexpected empty contract code of given jetton.', 100);
6
6
  const operationFetchError = (msg, inner) => new errors_1.FetchError(`failed to fetch OperationId: ${msg}`, 101, inner);
@@ -56,3 +56,5 @@ exports.zeroRawAmountError = zeroRawAmountError;
56
56
  const sendCrossChainTransactionFailedError = (msg) => new errors_1.WalletError(`failed to send cross chain transaction: ${msg}`, 131);
57
57
  exports.sendCrossChainTransactionFailedError = sendCrossChainTransactionFailedError;
58
58
  exports.convertCurrencyNegativeOrZeroValueError = new errors_1.FormatError('Value cannot be negative or zero for currency conversion', 132);
59
+ const unknownAssetOriginError = (origin) => new errors_1.TokenError(`Unknown asset origin: ${origin}`, 133);
60
+ exports.unknownAssetOriginError = unknownAssetOriginError;
@@ -10,7 +10,7 @@ export { LiteSequencerClient } from './sdk/LiteSequencerClient';
10
10
  export { ConsoleLogger, NoopLogger } from './sdk/Logger';
11
11
  export { OperationTracker } from './sdk/OperationTracker';
12
12
  export { Simulator } from './sdk/Simulator';
13
- export { startTracking, startTrackingMultiple } from './sdk/StartTracking';
13
+ export * from './sdk/StartTracking';
14
14
  export { TacSdk } from './sdk/TacSdk';
15
15
  export { TACTransactionManager } from './sdk/TACTransactionManager';
16
16
  export { TONTransactionManager } from './sdk/TONTransactionManager';
package/dist/src/index.js CHANGED
@@ -36,7 +36,7 @@ var __importStar = (this && this.__importStar) || (function () {
36
36
  };
37
37
  })();
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.TONTransactionManager = exports.TACTransactionManager = exports.TacSdk = exports.startTrackingMultiple = exports.startTracking = exports.Simulator = exports.OperationTracker = exports.NoopLogger = exports.ConsoleLogger = exports.LiteSequencerClient = exports.Configuration = exports.AxiosHttpClient = exports.AgnosticStructs = exports.AgnosticProxySDK = void 0;
39
+ exports.TONTransactionManager = exports.TACTransactionManager = exports.TacSdk = exports.Simulator = exports.OperationTracker = exports.NoopLogger = exports.ConsoleLogger = exports.LiteSequencerClient = exports.Configuration = exports.AxiosHttpClient = exports.AgnosticStructs = exports.AgnosticProxySDK = void 0;
40
40
  __exportStar(require("./adapters"), exports);
41
41
  var AgnosticSdk_1 = require("./agnosticSdk/AgnosticSdk");
42
42
  Object.defineProperty(exports, "AgnosticProxySDK", { enumerable: true, get: function () { return AgnosticSdk_1.AgnosticProxySDK; } });
@@ -57,9 +57,7 @@ var OperationTracker_1 = require("./sdk/OperationTracker");
57
57
  Object.defineProperty(exports, "OperationTracker", { enumerable: true, get: function () { return OperationTracker_1.OperationTracker; } });
58
58
  var Simulator_1 = require("./sdk/Simulator");
59
59
  Object.defineProperty(exports, "Simulator", { enumerable: true, get: function () { return Simulator_1.Simulator; } });
60
- var StartTracking_1 = require("./sdk/StartTracking");
61
- Object.defineProperty(exports, "startTracking", { enumerable: true, get: function () { return StartTracking_1.startTracking; } });
62
- Object.defineProperty(exports, "startTrackingMultiple", { enumerable: true, get: function () { return StartTracking_1.startTrackingMultiple; } });
60
+ __exportStar(require("./sdk/StartTracking"), exports);
63
61
  var TacSdk_1 = require("./sdk/TacSdk");
64
62
  Object.defineProperty(exports, "TacSdk", { enumerable: true, get: function () { return TacSdk_1.TacSdk; } });
65
63
  var TACTransactionManager_1 = require("./sdk/TACTransactionManager");
@@ -1,10 +1,11 @@
1
1
  import type { Cell } from '@ton/ton';
2
- import { AssetType, FeeParams } from '../structs/Struct';
2
+ import { AssetType, GeneratePayloadParams, Origin } from '../structs/Struct';
3
3
  export interface Asset {
4
4
  address: string;
5
5
  type: AssetType;
6
6
  rawAmount: bigint;
7
7
  clone: Asset;
8
+ origin: Origin;
8
9
  /**
9
10
  * Returns a new asset instance with the specified transfer amount in human-readable units.
10
11
  * Does not mutate the current asset instance.
@@ -53,15 +54,9 @@ export interface Asset {
53
54
  * @param params.crossChainTonAmount Optional TON amount to transfer cross-chain with the message.
54
55
  * @param params.forwardFeeTonAmount Optional TON amount used to cover forwarding fees on TON.
55
56
  * @param params.feeParams Optional fee parameters to fine-tune execution costs.
56
- * @returns Promise that resolves to a Cell containing the encoded payload.
57
+ * @returns Cell containing the encoded payload.
57
58
  */
58
- generatePayload(params: {
59
- excessReceiver: string;
60
- evmData: Cell;
61
- crossChainTonAmount?: bigint;
62
- forwardFeeTonAmount?: bigint;
63
- feeParams?: FeeParams;
64
- }): Promise<Cell>;
59
+ generatePayload(params: GeneratePayloadParams): Cell;
65
60
  /**
66
61
  * Validates whether the specified user is allowed to transfer this asset.
67
62
  * Implementations should throw if the transfer is not permitted (e.g., frozen asset, missing wallet, insufficient permissions).
@@ -1,5 +1,6 @@
1
1
  import { SandboxContract } from '@ton/sandbox';
2
- import type { Address, Contract, OpenedContract } from '@ton/ton';
2
+ import type { Address, Contract, OpenedContract, Transaction } from '@ton/ton';
3
+ import { AddressInformation, GetTransactionsOptions } from '../structs/InternalStruct';
3
4
  import { ContractState } from '../structs/Struct';
4
5
  export interface ContractOpener {
5
6
  /**
@@ -18,4 +19,7 @@ export interface ContractOpener {
18
19
  * Closes any underlying connections if supported by the implementation.
19
20
  */
20
21
  closeConnections?: () => unknown;
22
+ getTransactionByHash(address: Address, hash: string, opts?: GetTransactionsOptions): Promise<Transaction | null>;
23
+ getAdjacentTransactions(address: Address, hash: string, opts?: GetTransactionsOptions): Promise<Transaction[]>;
24
+ getAddressInformation(address: Address): Promise<AddressInformation>;
21
25
  }
@@ -1,5 +1,6 @@
1
1
  import type { SenderAbstraction } from '../sender';
2
- import { CrosschainTx, ExecutionFeeEstimationResult } from '../structs/Struct';
2
+ import { CrosschainTx, ExecutionFeeEstimationResult, GeneratePayloadParams } from '../structs/Struct';
3
+ import { Asset } from './Asset';
3
4
  export interface ISimulator {
4
5
  /**
5
6
  * Simulates a list of cross-chain transactions for a given sender.
@@ -15,4 +16,17 @@ export interface ISimulator {
15
16
  * @returns Promise with fee estimation and execution info.
16
17
  */
17
18
  getSimulationInfo(sender: SenderAbstraction, tx: CrosschainTx): Promise<ExecutionFeeEstimationResult>;
19
+ /**
20
+ * Estimates the total TON network fees required for a cross-chain transaction.
21
+ * @param assets Assets to be included in the transaction.
22
+ * @returns The total estimated fee in nanotons (1 TON = 10^9 nanotons) for processing all provided assets.
23
+ */
24
+ estimateTONFees(assets: Asset[], params: GeneratePayloadParams): bigint;
25
+ /**
26
+ * Estimates the TON network fee required for a single asset.
27
+ * @param asset Asset to be included in the transaction.
28
+ * @param params Payload parameters.
29
+ * @returns The total estimated fee in nanotons (1 TON = 10^9 nanotons) for processing the provided asset.
30
+ */
31
+ estimateTONFee(asset: Asset, params: GeneratePayloadParams): bigint;
18
32
  }
@@ -1,5 +1,6 @@
1
1
  import type { SenderAbstraction } from '../sender';
2
- import { BatchCrossChainTx, CrossChainTransactionsOptions, CrosschainTx, EvmProxyMsg, TransactionLinkerWithOperationId } from '../structs/Struct';
2
+ import { BatchCrossChainTx, CrossChainPayloadResult, CrossChainTransactionOptions, CrossChainTransactionsOptions, CrosschainTx, EvmProxyMsg, FeeParams, TransactionLinkerWithOperationId } from '../structs/Struct';
3
+ import { Asset } from './Asset';
3
4
  export interface ITONTransactionManager {
4
5
  /**
5
6
  * Sends a single cross-chain transaction.
@@ -17,4 +18,22 @@ export interface ITONTransactionManager {
17
18
  * @returns Array of transaction linkers, one per submitted transaction.
18
19
  */
19
20
  sendCrossChainTransactions(sender: SenderAbstraction, txs: BatchCrossChainTx[], options?: CrossChainTransactionsOptions): Promise<TransactionLinkerWithOperationId[]>;
21
+ /**
22
+ * Builds the fee parameters for a cross-chain transaction.
23
+ * @param options Transaction configuration options.
24
+ * @param evmProxyMsg Encoded EVM proxy message.
25
+ * @param sender Sender abstraction for TVM message sending.
26
+ * @param tx Cross-chain transaction to bridge.
27
+ * @returns Promise with the fee parameters.
28
+ */
29
+ buildFeeParams(options: CrossChainTransactionOptions, evmProxyMsg: EvmProxyMsg, sender: SenderAbstraction, tx: CrosschainTx): Promise<FeeParams>;
30
+ /**
31
+ * Prepares the transaction payloads required for a cross-chain operation without sending them.
32
+ * @param evmProxyMsg Encoded EVM proxy message.
33
+ * @param senderAddress TVM address of the transaction sender (wallet address).
34
+ * @param assets Assets to be included in the transaction.
35
+ * @param options Optional transaction configuration including error handling and executor settings.
36
+ * @returns Promise with the prepared transaction payloads.
37
+ */
38
+ prepareCrossChainTransactionPayload(evmProxyMsg: EvmProxyMsg, senderAddress: string, assets: Asset[], options?: CrossChainTransactionOptions): Promise<CrossChainPayloadResult[]>;
20
39
  }
@@ -2,7 +2,7 @@ import { Wallet } from 'ethers';
2
2
  import { JettonMinterData, NFTItemData } from '../../artifacts/tonTypes';
3
3
  import { FT, NFT } from '../assets';
4
4
  import type { SenderAbstraction } from '../sender';
5
- import { AssetFromFTArg, AssetFromNFTCollectionArg, AssetFromNFTItemArg, AssetLike, BatchCrossChainTxWithAssetLike, CrossChainTransactionOptions, CrossChainTransactionsOptions, CrosschainTx, EVMAddress, EvmProxyMsg, ExecutionFeeEstimationResult, NFTAddressType, SuggestedTVMExecutorFee, TACSimulationParams, TACSimulationResult, TransactionLinkerWithOperationId, TVMAddress, UserWalletBalanceExtended, WaitOptions } from '../structs/Struct';
5
+ import { AssetFromFTArg, AssetFromNFTCollectionArg, AssetFromNFTItemArg, AssetLike, BatchCrossChainTxWithAssetLike, CrossChainPayloadResult, CrossChainTransactionOptions, CrossChainTransactionsOptions, CrosschainTx, EVMAddress, EvmProxyMsg, ExecutionFeeEstimationResult, NFTAddressType, SuggestedTVMExecutorFee, TACSimulationParams, TACSimulationResult, TransactionLinkerWithOperationId, TVMAddress, UserWalletBalanceExtended, WaitOptions } from '../structs/Struct';
6
6
  import { Asset } from './Asset';
7
7
  import { IConfiguration } from './IConfiguration';
8
8
  import { IOperationTracker } from './IOperationTracker';
@@ -182,4 +182,13 @@ export interface ITacSDK {
182
182
  * Returns the operation tracker instance used for querying operation statuses and utilities.
183
183
  */
184
184
  getOperationTracker(): IOperationTracker;
185
+ /**
186
+ * Prepares the transaction payloads required for a cross-chain operation without sending them.
187
+ * @param evmProxyMsg Encoded EVM proxy message.
188
+ * @param senderAddress TVM address of the transaction sender (wallet address).
189
+ * @param assets Assets to be included in the transaction.
190
+ * @param options Optional transaction configuration including error handling and executor settings.
191
+ * @returns Promise with the prepared transaction payloads.
192
+ */
193
+ prepareCrossChainTransactionPayload(evmProxyMsg: EvmProxyMsg, senderAddress: string, assets?: AssetLike[], options?: CrossChainTransactionOptions): Promise<CrossChainPayloadResult[]>;
185
194
  }
@@ -0,0 +1,5 @@
1
+ export interface ITxFinalizer {
2
+ trackTransactionTree(address: string, hash: string, params: {
3
+ maxDepth?: number;
4
+ }): Promise<void>;
5
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,20 +1,16 @@
1
- import type { Contract, ContractProvider, MessageRelaxed, SendMode } from '@ton/ton';
1
+ import type { Cell, Contract, ContractProvider, MessageRelaxed, SendMode } from '@ton/ton';
2
2
  export interface WalletInstanse extends Contract {
3
3
  /**
4
4
  * Returns current wallet seqno, used for nonce/ordering.
5
5
  * @param provider Contract provider to query the wallet.
6
6
  */
7
7
  getSeqno(provider: ContractProvider): Promise<number>;
8
- /**
9
- * Sends a transfer with specified messages and send mode.
10
- * @param provider Contract provider used to send the transfer.
11
- * @param args Transfer arguments including seqno, secretKey, messages and sendMode.
12
- */
13
- sendTransfer(provider: ContractProvider, args: {
8
+ send(provider: ContractProvider, msg: Cell): Promise<string | void>;
9
+ createTransfer(args: {
14
10
  seqno: number;
15
11
  secretKey: Buffer;
16
12
  messages: MessageRelaxed[];
17
13
  sendMode: SendMode;
18
14
  timeout?: number;
19
- }): Promise<void>;
15
+ }): Cell;
20
16
  }