@t2000/sdk 0.21.10 → 0.21.11

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.
package/dist/index.cjs CHANGED
@@ -2353,21 +2353,31 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
2353
2353
  const toDecimals = toEntry ? toEntry[1].decimals : toType === "0x2::sui::SUI" ? 9 : 6;
2354
2354
  const fromAmount = Number(route.amountIn) / 10 ** fromDecimals;
2355
2355
  let toAmount = Number(route.amountOut) / 10 ** toDecimals;
2356
- try {
2357
- const txBlock = await this.client.getTransactionBlock({
2358
- digest: gasResult.digest,
2359
- options: { showBalanceChanges: true }
2360
- });
2361
- const changes = txBlock.balanceChanges ?? [];
2362
- const received = changes.find(
2363
- (c) => c.coinType === toType && BigInt(c.amount) > 0n && c.owner.AddressOwner === this._address
2364
- );
2365
- if (received) {
2366
- const actual = Number(BigInt(received.amount)) / 10 ** toDecimals;
2367
- if (actual > 0) toAmount = actual;
2356
+ const toTypeSuffix = toType.split("::").slice(1).join("::");
2357
+ for (let attempt = 0; attempt < 4; attempt++) {
2358
+ try {
2359
+ const txBlock = await this.client.getTransactionBlock({
2360
+ digest: gasResult.digest,
2361
+ options: { showBalanceChanges: true }
2362
+ });
2363
+ const changes = txBlock.balanceChanges ?? [];
2364
+ const received = changes.find((c) => {
2365
+ if (BigInt(c.amount) <= 0n) return false;
2366
+ const ownerAddr = c.owner?.AddressOwner;
2367
+ if (!ownerAddr || ownerAddr.toLowerCase() !== this._address.toLowerCase()) return false;
2368
+ if (c.coinType === toType) return true;
2369
+ return c.coinType.endsWith(toTypeSuffix);
2370
+ });
2371
+ if (received) {
2372
+ const actual = Number(BigInt(received.amount)) / 10 ** toDecimals;
2373
+ if (actual > 0) {
2374
+ toAmount = actual;
2375
+ break;
2376
+ }
2377
+ }
2378
+ } catch {
2368
2379
  }
2369
- } catch {
2370
- console.warn("[swap] Could not read balance changes, using route estimate");
2380
+ if (attempt < 3) await new Promise((r) => setTimeout(r, 600));
2371
2381
  }
2372
2382
  const fromName = fromEntry ? fromEntry[0] : this._resolveTokenName(fromType, params.from);
2373
2383
  const toName = toEntry ? toEntry[0] : this._resolveTokenName(toType, params.to);