@tonappchain/sdk 0.7.0-rc31 → 0.7.0-rc33

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.
@@ -27,7 +27,7 @@ class Simulator {
27
27
  Validator_1.Validator.validateEVMAddress(evmProxyMsg.evmTargetAddress);
28
28
  Validator_1.Validator.validateEVMAddresses(evmValidExecutors);
29
29
  Validator_1.Validator.validateTVMAddresses(tvmValidExecutors);
30
- const aggregatedData = await (0, Utils_1.aggregateTokens)(assets);
30
+ const aggregatedData = (0, Utils_1.aggregateTokens)(assets);
31
31
  const shardCount = aggregatedData.jettons.length || 1;
32
32
  const transactionLinker = (0, Utils_1.generateTransactionLinker)(sender.getSenderAddress(), shardCount);
33
33
  const tacSimulationParams = {
@@ -54,7 +54,7 @@ class TONTransactionManager {
54
54
  const { allowSimulationError = false, isRoundTrip = undefined, calculateRollbackFee = true, validateAssetsBalance = true, } = options || {};
55
55
  const { evmValidExecutors = [], tvmValidExecutors = [] } = options || {};
56
56
  Validator_1.Validator.validateEVMAddress(evmProxyMsg.evmTargetAddress);
57
- const aggregatedData = await (0, Utils_1.aggregateTokens)(assets);
57
+ const aggregatedData = (0, Utils_1.aggregateTokens)(assets);
58
58
  Validator_1.Validator.validateEVMAddresses(evmValidExecutors);
59
59
  Validator_1.Validator.validateTVMAddresses(tvmValidExecutors);
60
60
  const shouldValidateAssets = validateAssetsBalance && !skipAssetsBalanceValidation;
@@ -183,7 +183,7 @@ class TONTransactionManager {
183
183
  if (txsRequiringValidation.length) {
184
184
  // Aggregate only assets from txs that require validation and validate once per unique asset
185
185
  const assetsToValidate = txsRequiringValidation.flatMap((tx) => tx.assets ?? []);
186
- const aggregatedData = await (0, Utils_1.aggregateTokens)(assetsToValidate);
186
+ const aggregatedData = (0, Utils_1.aggregateTokens)(assetsToValidate);
187
187
  await Promise.all([
188
188
  ...aggregatedData.jettons.map((jetton) => jetton.checkCanBeTransferredBy(caller)),
189
189
  ...aggregatedData.nfts.map((nft) => nft.checkCanBeTransferredBy(caller)),
@@ -20,11 +20,11 @@ export declare const generateFeeData: (feeParams?: FeeParams) => Cell | undefine
20
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
22
  export declare function getBouncedAddress(tvmAddress: string): string;
23
- export declare function aggregateTokens(assets?: Asset[]): Promise<{
23
+ export declare function aggregateTokens(assets?: Asset[]): {
24
24
  jettons: FT[];
25
25
  nfts: NFT[];
26
26
  ton?: TON;
27
- }>;
27
+ };
28
28
  export declare function sha256toBigInt(ContractName: string): bigint;
29
29
  export declare function mapAssetsToTonAssets(assets: Asset[]): TONAsset[];
30
30
  export declare function normalizeAsset(config: IConfiguration, input: AssetLike): Promise<Asset>;
@@ -199,39 +199,30 @@ function getBouncedAddress(tvmAddress) {
199
199
  bounceable: true,
200
200
  });
201
201
  }
202
- async function aggregateTokens(assets) {
203
- const uniqueAssetsMap = new Map();
202
+ function aggregateTokens(assets) {
203
+ const jettonsMap = new Map();
204
+ const nftsMap = new Map();
204
205
  let ton;
205
- for await (const asset of assets ?? []) {
206
- if (asset.type !== Struct_1.AssetType.FT)
207
- continue;
208
- if (asset.rawAmount === 0n) {
206
+ for (const asset of assets ?? []) {
207
+ if (asset.rawAmount === 0n && asset.type === Struct_1.AssetType.FT) {
209
208
  throw (0, errors_1.zeroRawAmountError)(asset.address || 'NATIVE TON');
210
209
  }
211
- if (!asset.address) {
212
- ton = ton ? ton.addRawAmount(asset.rawAmount) : asset.clone;
213
- continue;
214
- }
215
- let jetton = uniqueAssetsMap.get(asset.address);
216
- if (!jetton) {
217
- jetton = asset.clone;
210
+ if (asset.type === Struct_1.AssetType.FT) {
211
+ if (!asset.address) {
212
+ ton = ton ? ton.addRawAmount(asset.rawAmount) : asset.clone;
213
+ }
214
+ else {
215
+ const existing = jettonsMap.get(asset.address);
216
+ jettonsMap.set(asset.address, (existing ? existing.addRawAmount(asset.rawAmount) : asset.clone));
217
+ }
218
218
  }
219
- else {
220
- jetton = jetton.addRawAmount(asset.rawAmount);
219
+ else if (asset.type === Struct_1.AssetType.NFT) {
220
+ nftsMap.set(asset.address, asset.clone);
221
221
  }
222
- uniqueAssetsMap.set(asset.address, jetton);
223
- }
224
- const jettons = Array.from(uniqueAssetsMap.values());
225
- uniqueAssetsMap.clear();
226
- for await (const asset of assets ?? []) {
227
- if (asset.type !== Struct_1.AssetType.NFT)
228
- continue;
229
- uniqueAssetsMap.set(asset.address, asset.clone);
230
222
  }
231
- const nfts = Array.from(uniqueAssetsMap.values());
232
223
  return {
233
- jettons,
234
- nfts,
224
+ jettons: Array.from(jettonsMap.values()),
225
+ nfts: Array.from(nftsMap.values()),
235
226
  ton,
236
227
  };
237
228
  }
@@ -240,7 +231,11 @@ function sha256toBigInt(ContractName) {
240
231
  return BigInt('0x' + hash.toString('hex'));
241
232
  }
242
233
  function mapAssetsToTonAssets(assets) {
243
- return assets.map((asset) => ({
234
+ const { jettons, nfts, ton } = aggregateTokens(assets);
235
+ const result = [...jettons, ...nfts];
236
+ if (ton)
237
+ result.push(ton);
238
+ return result.map((asset) => ({
244
239
  amount: asset.rawAmount.toString(),
245
240
  tokenAddress: asset.address || '',
246
241
  assetType: asset.type,
@@ -268,9 +263,15 @@ async function normalizeAsset(config, input) {
268
263
  const asset = await assets_1.AssetFactory.from(config, ftArgs);
269
264
  const rawAmount = 'rawAmount' in input ? input.rawAmount : undefined;
270
265
  const amount = 'amount' in input ? input.amount : 0;
266
+ if (!rawAmount && !amount && asset.type === Struct_1.AssetType.FT) {
267
+ throw (0, errors_1.zeroRawAmountError)(asset.address || 'NATIVE TON');
268
+ }
271
269
  return rawAmount ? asset.withRawAmount(rawAmount) : asset.withAmount(amount);
272
270
  }
273
271
  catch (e) {
272
+ if (e instanceof errors_1.TokenError && e.errorCode === (0, errors_1.zeroRawAmountError)('').errorCode) {
273
+ throw e;
274
+ }
274
275
  console.warn('Failed to normalize FT asset', e);
275
276
  }
276
277
  const itemArgs = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tonappchain/sdk",
3
- "version": "0.7.0-rc31",
3
+ "version": "0.7.0-rc33",
4
4
  "repository": "https://github.com/TacBuild/tac-sdk.git",
5
5
  "author": "TAC. <developers@tac>",
6
6
  "license": "MIT",