@t2000/sdk 0.21.8 → 0.21.10

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.js CHANGED
@@ -2351,13 +2351,21 @@ var T2000 = class _T2000 extends EventEmitter {
2351
2351
  const toDecimals = toEntry ? toEntry[1].decimals : toType === "0x2::sui::SUI" ? 9 : 6;
2352
2352
  const fromAmount = Number(route.amountIn) / 10 ** fromDecimals;
2353
2353
  let toAmount = Number(route.amountOut) / 10 ** toDecimals;
2354
- const changes = gasResult.balanceChanges ?? [];
2355
- const received = changes.find(
2356
- (c) => c.coinType === toType && BigInt(c.amount) > 0n && c.owner.AddressOwner === this._address
2357
- );
2358
- if (received) {
2359
- const actual = Number(BigInt(received.amount)) / 10 ** toDecimals;
2360
- if (actual > 0) toAmount = actual;
2354
+ try {
2355
+ const txBlock = await this.client.getTransactionBlock({
2356
+ digest: gasResult.digest,
2357
+ options: { showBalanceChanges: true }
2358
+ });
2359
+ const changes = txBlock.balanceChanges ?? [];
2360
+ const received = changes.find(
2361
+ (c) => c.coinType === toType && BigInt(c.amount) > 0n && c.owner.AddressOwner === this._address
2362
+ );
2363
+ if (received) {
2364
+ const actual = Number(BigInt(received.amount)) / 10 ** toDecimals;
2365
+ if (actual > 0) toAmount = actual;
2366
+ }
2367
+ } catch {
2368
+ console.warn("[swap] Could not read balance changes, using route estimate");
2361
2369
  }
2362
2370
  const fromName = fromEntry ? fromEntry[0] : this._resolveTokenName(fromType, params.from);
2363
2371
  const toName = toEntry ? toEntry[0] : this._resolveTokenName(toType, params.to);