@tonappchain/sdk 0.7.0-rc14 → 0.7.0-rc15

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 (54) hide show
  1. package/README.md +7 -7
  2. package/dist/adapters/retryableContractOpener.js +1 -1
  3. package/dist/assets/AssetFactory.js +1 -1
  4. package/dist/assets/FT.d.ts +8 -12
  5. package/dist/assets/FT.js +69 -36
  6. package/dist/assets/NFT.d.ts +4 -2
  7. package/dist/assets/NFT.js +14 -2
  8. package/dist/assets/TON.d.ts +4 -10
  9. package/dist/assets/TON.js +17 -15
  10. package/dist/errors/index.d.ts +1 -1
  11. package/dist/errors/index.js +7 -2
  12. package/dist/errors/instances.d.ts +8 -1
  13. package/dist/errors/instances.js +22 -16
  14. package/dist/index.d.ts +2 -1
  15. package/dist/index.js +5 -3
  16. package/dist/interfaces/Asset.d.ts +22 -17
  17. package/dist/interfaces/ILiteSequencerClient.d.ts +14 -1
  18. package/dist/interfaces/IOperationTracker.d.ts +16 -1
  19. package/dist/interfaces/ISimulator.d.ts +7 -36
  20. package/dist/interfaces/ITACTransactionManager.d.ts +15 -0
  21. package/dist/interfaces/ITONTransactionManager.d.ts +21 -0
  22. package/dist/interfaces/ITONTransactionManager.js +2 -0
  23. package/dist/interfaces/ITacSDK.d.ts +51 -13
  24. package/dist/interfaces/index.d.ts +2 -1
  25. package/dist/interfaces/index.js +2 -1
  26. package/dist/sdk/Configuration.d.ts +1 -0
  27. package/dist/sdk/Configuration.js +52 -4
  28. package/dist/sdk/Consts.d.ts +1 -0
  29. package/dist/sdk/Consts.js +5 -4
  30. package/dist/sdk/LiteSequencerClient.d.ts +5 -3
  31. package/dist/sdk/LiteSequencerClient.js +27 -4
  32. package/dist/sdk/OperationTracker.d.ts +3 -1
  33. package/dist/sdk/OperationTracker.js +51 -11
  34. package/dist/sdk/Simulator.d.ts +6 -12
  35. package/dist/sdk/Simulator.js +30 -124
  36. package/dist/sdk/TACTransactionManager.d.ts +10 -0
  37. package/dist/sdk/TACTransactionManager.js +92 -0
  38. package/dist/sdk/TONTransactionManager.d.ts +17 -0
  39. package/dist/sdk/TONTransactionManager.js +209 -0
  40. package/dist/sdk/TacSdk.d.ts +16 -10
  41. package/dist/sdk/TacSdk.js +52 -19
  42. package/dist/sdk/TxFinalizer.d.ts +3 -2
  43. package/dist/sdk/TxFinalizer.js +8 -8
  44. package/dist/sdk/Utils.d.ts +8 -4
  45. package/dist/sdk/Utils.js +80 -12
  46. package/dist/sdk/Validator.d.ts +2 -2
  47. package/dist/sdk/Validator.js +1 -1
  48. package/dist/structs/InternalStruct.d.ts +6 -2
  49. package/dist/structs/Struct.d.ts +70 -16
  50. package/package.json +4 -3
  51. package/dist/interfaces/ITransactionManager.d.ts +0 -35
  52. package/dist/sdk/TransactionManager.d.ts +0 -22
  53. package/dist/sdk/TransactionManager.js +0 -272
  54. /package/dist/interfaces/{ITransactionManager.js → ITACTransactionManager.js} +0 -0
@@ -34,6 +34,7 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.TacSdk = void 0;
37
+ const agnostic_sdk_1 = require("@tonappchain/agnostic-sdk");
37
38
  const assets_1 = require("../assets");
38
39
  const Struct_1 = require("../structs/Struct");
39
40
  const Configuration_1 = require("./Configuration");
@@ -41,12 +42,16 @@ const Consts_1 = require("./Consts");
41
42
  const Logger_1 = require("./Logger");
42
43
  const OperationTracker_1 = require("./OperationTracker");
43
44
  const Simulator_1 = require("./Simulator");
44
- const TransactionManager_1 = require("./TransactionManager");
45
+ const TACTransactionManager_1 = require("./TACTransactionManager");
46
+ const TONTransactionManager_1 = require("./TONTransactionManager");
47
+ const Utils_1 = require("./Utils");
45
48
  class TacSdk {
46
- constructor(config, simulator, transactionManager) {
49
+ constructor(config, simulator, tonTransactionManager, tacTransactionManager, operationTracker) {
47
50
  this.config = config;
48
51
  this.simulator = simulator;
49
- this.transactionManager = transactionManager;
52
+ this.tonTransactionManager = tonTransactionManager;
53
+ this.tacTransactionManager = tacTransactionManager;
54
+ this.operationTracker = operationTracker;
50
55
  }
51
56
  static async create(sdkParams, logger = new Logger_1.NoopLogger()) {
52
57
  const network = sdkParams.network;
@@ -54,10 +59,11 @@ class TacSdk {
54
59
  const { testnet, mainnet } = await Promise.resolve().then(() => __importStar(require('@tonappchain/artifacts')));
55
60
  const artifacts = network === Struct_1.Network.TESTNET ? testnet : mainnet;
56
61
  const config = await Configuration_1.Configuration.create(network, artifacts, sdkParams.TONParams, sdkParams.TACParams, sdkParams.customLiteSequencerEndpoints, delay);
57
- const simulator = new Simulator_1.Simulator(config, logger);
58
62
  const operationTracker = new OperationTracker_1.OperationTracker(network, config.liteSequencerEndpoints);
59
- const transactionManager = new TransactionManager_1.TransactionManager(config, simulator, operationTracker, logger);
60
- return new TacSdk(config, simulator, transactionManager);
63
+ const simulator = new Simulator_1.Simulator(config, operationTracker, logger);
64
+ const tonTransactionManager = new TONTransactionManager_1.TONTransactionManager(config, simulator, operationTracker, logger);
65
+ const tacTransactionManager = new TACTransactionManager_1.TACTransactionManager(config, operationTracker, logger);
66
+ return new TacSdk(config, simulator, tonTransactionManager, tacTransactionManager, operationTracker);
61
67
  }
62
68
  closeConnections() {
63
69
  return this.config.closeConnections();
@@ -65,6 +71,13 @@ class TacSdk {
65
71
  get nativeTONAddress() {
66
72
  return this.config.nativeTONAddress;
67
73
  }
74
+ getAgnosticProxySDK(agnosticProxyAddress, smartAccountFactoryAddress) {
75
+ return new agnostic_sdk_1.AgnosticProxySDK(smartAccountFactoryAddress ?? this.config.artifacts.TAC_SMART_ACCOUNT_FACTORY_ADDRESS, this.config.TACParams.provider, agnosticProxyAddress ?? this.config.artifacts.AGNOSTIC_PROXY_ADDRESS);
76
+ }
77
+ async getSmartAccountAddressForTvmWallet(tvmWallet, applicationAddress) {
78
+ const bouncedAddress = (0, Utils_1.getBouncedAddress)(tvmWallet);
79
+ return await this.config.TACParams.smartAccountFactory.getSmartAccountForApplication(bouncedAddress, applicationAddress);
80
+ }
68
81
  async nativeTACAddress() {
69
82
  return this.config.nativeTACAddress();
70
83
  }
@@ -74,29 +87,45 @@ class TacSdk {
74
87
  get getTrustedTONExecutors() {
75
88
  return this.config.getTrustedTONExecutors;
76
89
  }
77
- async getTransactionSimulationInfo(evmProxyMsg, sender, assets) {
78
- return this.simulator.getTransactionSimulationInfo(evmProxyMsg, sender, assets);
90
+ async getSimulationInfo(evmProxyMsg, sender, assets, options) {
91
+ const normalizedAssets = await (0, Utils_1.normalizeAssets)(this.config, assets);
92
+ const tx = { evmProxyMsg, assets: normalizedAssets, options };
93
+ return this.simulator.getSimulationInfo(sender, tx);
79
94
  }
80
95
  async getTVMExecutorFeeInfo(assets, feeSymbol, tvmValidExecutors) {
81
- return this.simulator.getTVMExecutorFeeInfo(assets, feeSymbol, tvmValidExecutors);
96
+ const normalized = await (0, Utils_1.normalizeAssets)(this.config, assets);
97
+ const params = {
98
+ tonAssets: (0, Utils_1.mapAssetsToTonAssets)(normalized),
99
+ feeSymbol: feeSymbol,
100
+ tvmValidExecutors: tvmValidExecutors ?? [],
101
+ };
102
+ return this.operationTracker.getTVMExecutorFee(params);
82
103
  }
83
- async sendCrossChainTransaction(evmProxyMsg, sender, assets, options, waitOptions) {
84
- return this.transactionManager.sendCrossChainTransaction(evmProxyMsg, sender, assets, options, waitOptions);
104
+ async sendCrossChainTransaction(evmProxyMsg, sender, assets = [], options, waitOptions) {
105
+ const normalizedAssets = await (0, Utils_1.normalizeAssets)(this.config, assets);
106
+ const tx = { evmProxyMsg, assets: normalizedAssets, options };
107
+ return this.tonTransactionManager.sendCrossChainTransaction(evmProxyMsg, sender, tx, waitOptions);
85
108
  }
86
109
  async sendCrossChainTransactions(sender, txs, waitOptions) {
87
- return this.transactionManager.sendCrossChainTransactions(sender, txs, waitOptions);
110
+ const normalizedTxs = await Promise.all(txs.map(async (tx) => ({
111
+ evmProxyMsg: tx.evmProxyMsg,
112
+ options: tx.options,
113
+ assets: await (0, Utils_1.normalizeAssets)(this.config, tx.assets),
114
+ })));
115
+ return this.tonTransactionManager.sendCrossChainTransactions(sender, normalizedTxs, waitOptions);
88
116
  }
89
117
  async bridgeTokensToTON(signer, value, tonTarget, assets, tvmExecutorFee, tvmValidExecutors) {
90
- return this.transactionManager.bridgeTokensToTON(signer, value, tonTarget, assets, tvmExecutorFee, tvmValidExecutors);
118
+ const normalizedAssets = await (0, Utils_1.normalizeAssets)(this.config, assets);
119
+ return this.tacTransactionManager.bridgeTokensToTON(signer, value, tonTarget, normalizedAssets, tvmExecutorFee, tvmValidExecutors);
91
120
  }
92
121
  async isContractDeployedOnTVM(address) {
93
122
  return this.config.isContractDeployedOnTVM(address);
94
123
  }
95
124
  async simulateTACMessage(req) {
96
- return this.simulator.simulateTACMessage(req);
125
+ return this.operationTracker.simulateTACMessage(req);
97
126
  }
98
127
  async simulateTransactions(sender, txs) {
99
- return this.simulator.simulateTransactions(sender, txs);
128
+ return this.simulator.getSimulationsInfo(sender, txs);
100
129
  }
101
130
  async getAsset(args) {
102
131
  return await assets_1.AssetFactory.from(this.config, args);
@@ -147,10 +176,11 @@ class TacSdk {
147
176
  }
148
177
  // Address conversion methods
149
178
  async getEVMTokenAddress(tvmTokenAddress) {
150
- if (tvmTokenAddress === this.nativeTONAddress || tvmTokenAddress === '') {
151
- return assets_1.TON.create(this.config).getEVMAddress();
152
- }
153
- return assets_1.FT.getEVMAddress(this.config, tvmTokenAddress);
179
+ const asset = await assets_1.AssetFactory.from(this.config, {
180
+ address: tvmTokenAddress,
181
+ tokenType: Struct_1.AssetType.FT,
182
+ });
183
+ return asset.getEVMAddress();
154
184
  }
155
185
  async getTVMTokenAddress(evmTokenAddress) {
156
186
  return assets_1.FT.getTVMAddress(this.config, evmTokenAddress);
@@ -168,5 +198,8 @@ class TacSdk {
168
198
  return nftCollection.getEVMAddress();
169
199
  }
170
200
  }
201
+ getOperationTracker() {
202
+ return this.operationTracker;
203
+ }
171
204
  }
172
205
  exports.TacSdk = TacSdk;
@@ -1,9 +1,10 @@
1
- import { ILogger } from '../interfaces';
1
+ import { IHttpClient, ILogger } from '../interfaces';
2
2
  import { TxFinalizerConfig } from '../structs/InternalStruct';
3
3
  export declare class TonTxFinalizer {
4
4
  private logger;
5
5
  private apiConfig;
6
- constructor(apiConfig: TxFinalizerConfig, logger?: ILogger);
6
+ private readonly httpClient;
7
+ constructor(apiConfig: TxFinalizerConfig, logger?: ILogger, httpClient?: IHttpClient);
7
8
  private logHashFormats;
8
9
  private fetchAdjacentTransactions;
9
10
  trackTransactionTree(hash: string, maxDepth?: number): Promise<void>;
@@ -1,10 +1,7 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.TonTxFinalizer = void 0;
7
- const axios_1 = __importDefault(require("axios"));
4
+ const AxiosHttpClient_1 = require("./AxiosHttpClient");
8
5
  const Logger_1 = require("./Logger");
9
6
  const Utils_1 = require("./Utils");
10
7
  const IGNORE_OPCODE = [
@@ -12,9 +9,10 @@ const IGNORE_OPCODE = [
12
9
  '0x7362d09c', // Jetton Notify
13
10
  ];
14
11
  class TonTxFinalizer {
15
- constructor(apiConfig, logger = new Logger_1.NoopLogger()) {
12
+ constructor(apiConfig, logger = new Logger_1.NoopLogger(), httpClient = new AxiosHttpClient_1.AxiosHttpClient()) {
16
13
  this.apiConfig = apiConfig;
17
14
  this.logger = logger;
15
+ this.httpClient = httpClient;
18
16
  }
19
17
  logHashFormats(hash) {
20
18
  let hex, base64;
@@ -34,10 +32,9 @@ class TonTxFinalizer {
34
32
  // Fetches adjacent transactions from toncenter
35
33
  async fetchAdjacentTransactions(hash, retries = 5, delay = 1000) {
36
34
  for (let i = retries; i >= 0; i--) {
37
- await (0, Utils_1.sleep)(delay);
38
35
  try {
39
36
  const url = this.apiConfig.urlBuilder(hash);
40
- const response = await axios_1.default.get(url, {
37
+ const response = await this.httpClient.get(url, {
41
38
  headers: {
42
39
  [this.apiConfig.authorization.header]: this.apiConfig.authorization.value,
43
40
  },
@@ -57,6 +54,7 @@ class TonTxFinalizer {
57
54
  console.warn(`Failed to fetch adjacent transactions for ${hash}:`, logMessage);
58
55
  }
59
56
  }
57
+ await (0, Utils_1.sleep)(delay);
60
58
  }
61
59
  return [];
62
60
  }
@@ -91,7 +89,9 @@ class TonTxFinalizer {
91
89
  `action.result_code = ${action.resultCode}`);
92
90
  }
93
91
  if (currentDepth + 1 < maxDepth) {
94
- queue.push({ hash: tx.hash, depth: currentDepth + 1 });
92
+ if (tx.outMsgs.length > 0) {
93
+ queue.push({ hash: tx.hash, depth: currentDepth + 1 });
94
+ }
95
95
  }
96
96
  }
97
97
  else {
@@ -1,9 +1,9 @@
1
1
  import { Address, Cell } from '@ton/ton';
2
2
  import { AbiCoder } from 'ethers';
3
- import { FT, NFT, TON } from '../assets';
4
- import { Asset } from '../interfaces';
3
+ import type { FT, NFT, TON } from '../assets';
4
+ import { Asset, IConfiguration } from '../interfaces';
5
5
  import { RandomNumberByTimestamp } from '../structs/InternalStruct';
6
- import { EvmProxyMsg, FeeParams, TransactionLinker, ValidExecutors, WaitOptions } from '../structs/Struct';
6
+ import { AssetLike, EvmProxyMsg, FeeParams, TONAsset, TransactionLinker, ValidExecutors, WaitOptions } from '../structs/Struct';
7
7
  export declare const sleep: (ms: number) => Promise<unknown>;
8
8
  export declare function generateRandomNumber(interval: number): number;
9
9
  export declare function generateRandomNumberByTimestamp(): RandomNumberByTimestamp;
@@ -17,11 +17,15 @@ export declare const calculateRawAmount: (amount: number, decimals: number) => b
17
17
  export declare const calculateAmount: (rawAmount: bigint, decimals: number) => number;
18
18
  export declare const toCamelCaseTransformer: (data: string) => any;
19
19
  export declare const generateFeeData: (feeParams?: FeeParams) => Cell | undefined;
20
- export declare function waitUntilSuccess<T, A extends unknown[]>(options: WaitOptions<T> | undefined, operation: (...args: A) => Promise<T>, ...args: A): Promise<T>;
20
+ export declare function waitUntilSuccess<T, TContext = unknown, A extends unknown[] = unknown[]>(options: WaitOptions<T, TContext> | undefined, operation: (...args: A) => Promise<T>, operationDescription?: string, ...args: A): Promise<T>;
21
21
  export declare function formatObjectForLogging(obj: unknown): string;
22
+ export declare function getBouncedAddress(tvmAddress: string): string;
22
23
  export declare function aggregateTokens(assets?: Asset[]): Promise<{
23
24
  jettons: FT[];
24
25
  nfts: NFT[];
25
26
  ton?: TON;
26
27
  }>;
27
28
  export declare function sha256toBigInt(ContractName: string): bigint;
29
+ export declare function mapAssetsToTonAssets(assets: Asset[]): TONAsset[];
30
+ export declare function normalizeAsset(config: IConfiguration, input: AssetLike): Promise<Asset>;
31
+ export declare function normalizeAssets(config: IConfiguration, assets?: AssetLike[]): Promise<Asset[]>;
package/dist/sdk/Utils.js CHANGED
@@ -10,11 +10,16 @@ exports.generateTransactionLinker = generateTransactionLinker;
10
10
  exports.calculateEVMTokenAddress = calculateEVMTokenAddress;
11
11
  exports.waitUntilSuccess = waitUntilSuccess;
12
12
  exports.formatObjectForLogging = formatObjectForLogging;
13
+ exports.getBouncedAddress = getBouncedAddress;
13
14
  exports.aggregateTokens = aggregateTokens;
14
15
  exports.sha256toBigInt = sha256toBigInt;
16
+ exports.mapAssetsToTonAssets = mapAssetsToTonAssets;
17
+ exports.normalizeAsset = normalizeAsset;
18
+ exports.normalizeAssets = normalizeAssets;
15
19
  const ton_1 = require("@ton/ton");
16
20
  const ethers_1 = require("ethers");
17
21
  const ton_crypto_1 = require("ton-crypto");
22
+ const assets_1 = require("../assets");
18
23
  const errors_1 = require("../errors");
19
24
  const Struct_1 = require("../structs/Struct");
20
25
  const Consts_1 = require("./Consts");
@@ -133,12 +138,14 @@ const generateFeeData = (feeParams) => {
133
138
  }
134
139
  };
135
140
  exports.generateFeeData = generateFeeData;
136
- async function waitUntilSuccess(options = {}, operation, ...args) {
141
+ async function waitUntilSuccess(options = {}, operation, operationDescription, ...args) {
137
142
  const timeout = options.timeout ?? 300000;
138
143
  const maxAttempts = options.maxAttempts ?? 30;
139
144
  const delay = options.delay ?? 10000;
140
145
  const successCheck = options.successCheck;
141
- options.logger?.debug(`Starting wait for success with timeout=${timeout}ms, maxAttempts=${maxAttempts}, delay=${delay}ms`);
146
+ const context = options.context;
147
+ const contextPrefix = operationDescription ? `[${operationDescription}] ` : '';
148
+ options.logger?.debug(`${contextPrefix}Starting wait for success with timeout=${timeout}ms, maxAttempts=${maxAttempts}, delay=${delay}ms`);
142
149
  const startTime = Date.now();
143
150
  let attempt = 1;
144
151
  while (true) {
@@ -146,27 +153,36 @@ async function waitUntilSuccess(options = {}, operation, ...args) {
146
153
  const elapsedTime = currentTime - startTime;
147
154
  try {
148
155
  const result = await operation(...args);
149
- if (!result) {
156
+ if (result === undefined || result === null) {
150
157
  throw new Error(`Empty result`);
151
158
  }
152
- options.logger?.debug(`Result: ${formatObjectForLogging(result)}`);
153
- if (successCheck && !successCheck(result)) {
159
+ options.logger?.debug(`${contextPrefix}Result: ${formatObjectForLogging(result)}`);
160
+ if (successCheck && !successCheck(result, context)) {
154
161
  throw new Error(`Result is not successful`);
155
162
  }
156
- options.logger?.debug(`Attempt ${attempt} successful`);
163
+ options.logger?.debug(`${contextPrefix}Attempt ${attempt} successful`);
164
+ // Execute custom onSuccess callback if provided
165
+ if (options.onSuccess) {
166
+ try {
167
+ await options.onSuccess(result, context);
168
+ }
169
+ catch (callbackError) {
170
+ options.logger?.warn(`${contextPrefix}onSuccess callback error: ${callbackError}`);
171
+ }
172
+ }
157
173
  return result;
158
174
  }
159
175
  catch (error) {
160
176
  if (elapsedTime >= timeout) {
161
- options.logger?.debug(`Timeout after ${elapsedTime}ms`);
177
+ options.logger?.debug(`${contextPrefix}Timeout after ${elapsedTime}ms`);
162
178
  throw error;
163
179
  }
164
180
  if (attempt >= maxAttempts) {
165
- options.logger?.debug(`Max attempts (${maxAttempts}) reached`);
181
+ options.logger?.debug(`${contextPrefix}Max attempts (${maxAttempts}) reached`);
166
182
  throw error;
167
183
  }
168
- options.logger?.debug(`Error on attempt ${attempt}: ${error}`);
169
- options.logger?.debug(`Waiting ${delay}ms before next attempt`);
184
+ options.logger?.debug(`${contextPrefix}Error on attempt ${attempt}: ${error}`);
185
+ options.logger?.debug(`${contextPrefix}Waiting ${delay}ms before next attempt`);
170
186
  await (0, exports.sleep)(delay);
171
187
  attempt++;
172
188
  }
@@ -175,6 +191,11 @@ async function waitUntilSuccess(options = {}, operation, ...args) {
175
191
  function formatObjectForLogging(obj) {
176
192
  return JSON.stringify(obj, (key, value) => (typeof value === 'bigint' ? value.toString() : value));
177
193
  }
194
+ function getBouncedAddress(tvmAddress) {
195
+ return ton_1.Address.parse(tvmAddress).toString({
196
+ bounceable: true,
197
+ });
198
+ }
178
199
  async function aggregateTokens(assets) {
179
200
  const uniqueAssetsMap = new Map();
180
201
  let ton;
@@ -182,7 +203,7 @@ async function aggregateTokens(assets) {
182
203
  if (asset.type !== Struct_1.AssetType.FT)
183
204
  continue;
184
205
  if (!asset.address) {
185
- ton = ton ? await ton.addAmount({ rawAmount: asset.rawAmount }) : asset.clone;
206
+ ton = ton ? ton.addRawAmount(asset.rawAmount) : asset.clone;
186
207
  continue;
187
208
  }
188
209
  let jetton = uniqueAssetsMap.get(asset.address);
@@ -190,7 +211,7 @@ async function aggregateTokens(assets) {
190
211
  jetton = asset.clone;
191
212
  }
192
213
  else {
193
- jetton = await jetton.addAmount({ rawAmount: asset.rawAmount });
214
+ jetton = jetton.addRawAmount(asset.rawAmount);
194
215
  }
195
216
  uniqueAssetsMap.set(asset.address, jetton);
196
217
  }
@@ -212,3 +233,50 @@ function sha256toBigInt(ContractName) {
212
233
  const hash = (0, ton_crypto_1.sha256_sync)(ContractName);
213
234
  return BigInt('0x' + hash.toString('hex'));
214
235
  }
236
+ function mapAssetsToTonAssets(assets) {
237
+ return assets.map((asset) => ({
238
+ amount: asset.rawAmount.toString(),
239
+ tokenAddress: asset.address || '',
240
+ assetType: asset.type,
241
+ }));
242
+ }
243
+ async function normalizeAsset(config, input) {
244
+ if (typeof input.generatePayload === 'function') {
245
+ return input;
246
+ }
247
+ const address = 'address' in input && input.address ? input.address : '';
248
+ if ('itemIndex' in input) {
249
+ const args = {
250
+ address,
251
+ tokenType: Struct_1.AssetType.NFT,
252
+ addressType: Struct_1.NFTAddressType.COLLECTION,
253
+ index: BigInt(input.itemIndex),
254
+ };
255
+ return await assets_1.AssetFactory.from(config, args);
256
+ }
257
+ if ('rawAmount' in input || 'amount' in input) {
258
+ const ftArgs = {
259
+ address,
260
+ tokenType: Struct_1.AssetType.FT,
261
+ };
262
+ const asset = await assets_1.AssetFactory.from(config, ftArgs);
263
+ return 'rawAmount' in input
264
+ ? asset.withRawAmount(input.rawAmount)
265
+ : asset.withAmount(input.amount);
266
+ }
267
+ const itemArgs = {
268
+ address,
269
+ tokenType: Struct_1.AssetType.NFT,
270
+ addressType: Struct_1.NFTAddressType.ITEM,
271
+ };
272
+ return await assets_1.AssetFactory.from(config, itemArgs);
273
+ }
274
+ async function normalizeAssets(config, assets) {
275
+ if (!assets || assets.length === 0)
276
+ return [];
277
+ const normalized = [];
278
+ for (const a of assets) {
279
+ normalized.push(await normalizeAsset(config, a));
280
+ }
281
+ return normalized;
282
+ }
@@ -1,6 +1,6 @@
1
- import { EvmProxyMsg, TACSimulationRequest } from '../structs/Struct';
1
+ import { EvmProxyMsg, TACSimulationParams } from '../structs/Struct';
2
2
  export declare class Validator {
3
- static validateTACSimulationRequest(req: TACSimulationRequest): void;
3
+ static validateTACSimulationParams(req: TACSimulationParams): void;
4
4
  static validateEVMProxyMsg(evmProxyMsg: EvmProxyMsg): void;
5
5
  static validateTVMAddresses(addresses?: string[]): void;
6
6
  static validateEVMAddresses(addresses?: string[]): void;
@@ -5,7 +5,7 @@ const ton_1 = require("@ton/ton");
5
5
  const ethers_1 = require("ethers");
6
6
  const errors_1 = require("../errors");
7
7
  class Validator {
8
- static validateTACSimulationRequest(req) {
8
+ static validateTACSimulationParams(req) {
9
9
  this.validateEVMAddress(req.tacCallParams.target);
10
10
  req.evmValidExecutors?.forEach(this.validateEVMAddress);
11
11
  req.tvmValidExecutors?.forEach(this.validateTVMAddress);
@@ -2,7 +2,7 @@ import { Cell } from '@ton/ton';
2
2
  import { mainnet, testnet } from '@tonappchain/artifacts';
3
3
  import { AbstractProvider, ethers } from 'ethers';
4
4
  import { ContractOpener } from '../interfaces';
5
- import { CurrencyType, ExecutionStagesByOperationId, Network, OperationIdsByShardsKey, OperationType, StatusInfosByOperationId, SuggestedTONExecutorFee, TACSimulationResult } from './Struct';
5
+ import { CurrencyType, ExecutionStagesByOperationId, Network, OperationIdsByShardsKey, OperationType, StatusInfosByOperationId, SuggestedTVMExecutorFee, TACSimulationResult } from './Struct';
6
6
  export type ShardMessage = {
7
7
  address: string;
8
8
  value: bigint;
@@ -38,6 +38,7 @@ export type InternalTACParams = {
38
38
  crossChainLayer: testnet.tac.wrappers.CrossChainLayerTAC | mainnet.tac.wrappers.CrossChainLayerTAC;
39
39
  settings: testnet.tac.wrappers.SettingsTAC | mainnet.tac.wrappers.SettingsTAC;
40
40
  tokenUtils: testnet.tac.wrappers.TokenUtilsTAC | mainnet.tac.wrappers.TokenUtilsTAC;
41
+ smartAccountFactory: testnet.tac.wrappers.TacSAFactoryTAC | mainnet.tac.wrappers.TacSAFactoryTAC;
41
42
  trustedTACExecutors: string[];
42
43
  trustedTONExecutors: string[];
43
44
  abiCoder: ethers.AbiCoder;
@@ -51,7 +52,7 @@ export type StatusesResponse = ResponseBase<StatusInfosByOperationId>;
51
52
  export type OperationIdsByShardsKeyResponse = ResponseBase<OperationIdsByShardsKey>;
52
53
  export type StageProfilingResponse = ResponseBase<ExecutionStagesByOperationId>;
53
54
  export type TACSimulationResponse = ResponseBase<TACSimulationResult>;
54
- export type SuggestedTONExecutorFeeResponse = ResponseBase<SuggestedTONExecutorFee>;
55
+ export type SuggestedTVMExecutorFeeResponse = ResponseBase<SuggestedTVMExecutorFee>;
55
56
  export type ConvertCurrencyResponse = ResponseBase<ConvertedCurrencyRawResult>;
56
57
  export interface SendResult {
57
58
  success: boolean;
@@ -77,6 +78,9 @@ export type ToncenterTransaction = {
77
78
  hash: string;
78
79
  opcode: string;
79
80
  };
81
+ outMsgs: {
82
+ hash: string;
83
+ }[];
80
84
  };
81
85
  export type TransactionDepth = {
82
86
  hash: string;
@@ -1,6 +1,8 @@
1
- import type { Address, Cell } from '@ton/ton';
2
- import { AbstractProvider, Addressable } from 'ethers';
1
+ import { Address, Cell, OpenedContract } from '@ton/ton';
2
+ import { AbstractProvider, Addressable, Interface, InterfaceAbi } from 'ethers';
3
+ import type { FT, NFT } from '../assets';
3
4
  import type { Asset, ContractOpener, ILogger } from '../interfaces';
5
+ import { JettonMaster, JettonMasterData } from '../wrappers/JettonMaster';
4
6
  export type ContractState = {
5
7
  balance: bigint;
6
8
  state: 'active' | 'uninitialized' | 'frozen';
@@ -41,6 +43,14 @@ export type TACParams = {
41
43
  * Address of TAC settings contract. Use only for tests.
42
44
  */
43
45
  settingsAddress?: string | Addressable;
46
+ /**
47
+ * Address of multicall contract. Use only for tests.
48
+ */
49
+ multicallAddress?: string | Addressable;
50
+ /**
51
+ * ABI of multicall contract. Use only for tests.
52
+ */
53
+ multicallABI?: Interface | InterfaceAbi;
44
54
  };
45
55
  export type TONParams = {
46
56
  /**
@@ -107,21 +117,23 @@ export type TransactionLinker = {
107
117
  export type TransactionLinkerWithOperationId = TransactionLinker & {
108
118
  operationId?: string;
109
119
  };
110
- export type TACSimulationRequest = {
111
- tacCallParams: {
112
- arguments: string;
113
- methodName: string;
114
- target: string;
115
- };
120
+ export type TONAsset = {
121
+ amount: string;
122
+ tokenAddress: string;
123
+ assetType: AssetType;
124
+ };
125
+ export type TACCallParams = {
126
+ arguments: string;
127
+ methodName: string;
128
+ target: string;
129
+ };
130
+ export type TACSimulationParams = {
131
+ tacCallParams: TACCallParams;
116
132
  evmValidExecutors?: string[];
117
133
  tvmValidExecutors?: string[];
118
134
  extraData?: string;
119
135
  shardsKey: string;
120
- tonAssets: {
121
- amount: string;
122
- tokenAddress: string;
123
- assetType: string;
124
- }[];
136
+ tonAssets: TONAsset[];
125
137
  tonCaller: string;
126
138
  calculateRollbackFee?: boolean;
127
139
  };
@@ -259,7 +271,7 @@ export type TACSimulationResult = {
259
271
  blockNumber: number;
260
272
  };
261
273
  };
262
- export type SuggestedTONExecutorFee = {
274
+ export type SuggestedTVMExecutorFee = {
263
275
  inTAC: string;
264
276
  inTON: string;
265
277
  };
@@ -279,6 +291,8 @@ export type CrossChainTransactionOptions = {
279
291
  tvmValidExecutors?: string[];
280
292
  tvmExecutorFee?: bigint;
281
293
  calculateRollbackFee?: boolean;
294
+ withoutSimulation?: boolean;
295
+ validateAssetsBalance?: boolean;
282
296
  };
283
297
  export type ExecutionFeeEstimationResult = {
284
298
  feeParams: FeeParams;
@@ -289,6 +303,25 @@ export type CrosschainTx = {
289
303
  assets?: Asset[];
290
304
  options?: CrossChainTransactionOptions;
291
305
  };
306
+ export type AssetLike = Asset | FT | NFT | {
307
+ rawAmount: bigint;
308
+ } | {
309
+ amount: number;
310
+ } | {
311
+ address: TVMAddress | EVMAddress;
312
+ } | {
313
+ address: TVMAddress | EVMAddress;
314
+ rawAmount: bigint;
315
+ } | {
316
+ address: TVMAddress | EVMAddress;
317
+ amount: number;
318
+ } | {
319
+ address: TVMAddress | EVMAddress;
320
+ itemIndex: bigint;
321
+ };
322
+ export type CrosschainTxWithAssetLike = Omit<CrosschainTx, 'assets'> & {
323
+ assets?: AssetLike[];
324
+ };
292
325
  export type NFTItemData = {
293
326
  init: boolean;
294
327
  index: number;
@@ -301,7 +334,7 @@ export type NFTCollectionData = {
301
334
  content: Cell;
302
335
  adminAddress: Address;
303
336
  };
304
- export interface WaitOptions<T = unknown> {
337
+ export interface WaitOptions<T = unknown, TContext = unknown> {
305
338
  /**
306
339
  * Timeout in milliseconds
307
340
  * @default 300000 (5 minutes)
@@ -321,11 +354,21 @@ export interface WaitOptions<T = unknown> {
321
354
  * Logger
322
355
  */
323
356
  logger?: ILogger;
357
+ /**
358
+ * Optional context object to pass additional parameters to callbacks
359
+ * This allows passing custom data like OperationTracker instances, configurations, etc.
360
+ */
361
+ context?: TContext;
324
362
  /**
325
363
  * Function to check if the result is successful
326
364
  * If not provided, any non-error result is considered successful
327
365
  */
328
- successCheck?: (result: T) => boolean;
366
+ successCheck?: (result: T, context?: TContext) => boolean;
367
+ /**
368
+ * Custom callback function that executes when request is successful
369
+ * Receives both the result and optional context with additional parameters
370
+ */
371
+ onSuccess?: (result: T, context?: TContext) => Promise<void> | void;
329
372
  }
330
373
  export declare const defaultWaitOptions: WaitOptions;
331
374
  export declare enum Origin {
@@ -366,3 +409,14 @@ export type ConvertedCurrencyResult = {
366
409
  tacPrice: USDPriceInfo;
367
410
  tonPrice: USDPriceInfo;
368
411
  };
412
+ export type GetTVMExecutorFeeParams = {
413
+ feeSymbol: string;
414
+ tonAssets: TONAsset[];
415
+ tvmValidExecutors: string[];
416
+ };
417
+ export type FTOriginAndData = {
418
+ origin: Origin;
419
+ jettonMinter: OpenedContract<JettonMaster>;
420
+ evmAddress?: string;
421
+ jettonData?: JettonMasterData;
422
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tonappchain/sdk",
3
- "version": "0.7.0-rc14",
3
+ "version": "0.7.0-rc15",
4
4
  "repository": "https://github.com/TacBuild/tac-sdk.git",
5
5
  "author": "TAC. <developers@tac>",
6
6
  "license": "MIT",
@@ -20,7 +20,8 @@
20
20
  "@aws-crypto/sha256-js": "^5.2.0",
21
21
  "@orbs-network/ton-access": "^2.3.3",
22
22
  "@ton/ton": "15.1.0",
23
- "@tonappchain/artifacts": "0.0.19-smart-accounts-4",
23
+ "@tonappchain/agnostic-sdk": "0.0.9",
24
+ "@tonappchain/artifacts": "0.0.19-smart-accounts-7",
24
25
  "@tonappchain/ton-lite-client": "3.0.6",
25
26
  "@tonconnect/ui": "^2.0.11",
26
27
  "bn.js": "^5.2.1",
@@ -64,4 +65,4 @@
64
65
  }
65
66
  },
66
67
  "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
67
- }
68
+ }
@@ -1,35 +0,0 @@
1
- import { Wallet } from 'ethers';
2
- import type { SenderAbstraction } from '../sender';
3
- import { CrossChainTransactionOptions, CrosschainTx, EvmProxyMsg, OperationIdsByShardsKey, TransactionLinkerWithOperationId, WaitOptions } from '../structs/Struct';
4
- import { Asset } from './Asset';
5
- export interface ITransactionManager {
6
- /**
7
- * Sends a single cross-chain transaction.
8
- * @param evmProxyMsg Encoded EVM proxy message to bridge.
9
- * @param sender Sender abstraction for TVM message sending.
10
- * @param assets Optional assets to attach to the cross-chain message.
11
- * @param options Optional cross-chain execution options (fees, executors, extra data).
12
- * @param waitOptions Optional policy to wait for operation id resolution.
13
- * @returns Transaction linker with operation id for tracking.
14
- */
15
- sendCrossChainTransaction(evmProxyMsg: EvmProxyMsg, sender: SenderAbstraction, assets?: Asset[], options?: CrossChainTransactionOptions, waitOptions?: WaitOptions<string>): Promise<TransactionLinkerWithOperationId>;
16
- /**
17
- * Sends multiple cross-chain transactions in a batch.
18
- * @param sender Sender abstraction for TVM message sending.
19
- * @param txs List of cross-chain transactions to broadcast.
20
- * @param waitOptions Optional policy for waiting on operation ids by shard keys.
21
- * @returns Array of transaction linkers, one per submitted transaction.
22
- */
23
- sendCrossChainTransactions(sender: SenderAbstraction, txs: CrosschainTx[], waitOptions?: WaitOptions<OperationIdsByShardsKey>): Promise<TransactionLinkerWithOperationId[]>;
24
- /**
25
- * Bridges native EVM value and optional assets to TON chain via executor.
26
- * @param signer Ethers Wallet used to sign EVM transaction.
27
- * @param value Amount of native EVM currency (wei as bigint).
28
- * @param tonTarget Recipient TVM address on TON.
29
- * @param assets Optional list of TAC assets to include.
30
- * @param tvmExecutorFee Optional explicit TON-side executor fee.
31
- * @param tvmValidExecutors Optional whitelist of allowed TVM executors.
32
- * @returns EVM transaction hash or bridge identifier.
33
- */
34
- bridgeTokensToTON(signer: Wallet, value: bigint, tonTarget: string, assets?: Asset[], tvmExecutorFee?: bigint, tvmValidExecutors?: string[]): Promise<string>;
35
- }