@t2000/cli 0.25.11 → 0.25.13

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.
@@ -66008,6 +66008,14 @@ var T2000 = class _T2000 extends import_index.default {
66008
66008
  if (route.priceImpact > 0.05) {
66009
66009
  console.warn(`[swap] High price impact: ${(route.priceImpact * 100).toFixed(2)}%`);
66010
66010
  }
66011
+ const toEntry = Object.entries(SUPPORTED_ASSETS).find(([, v]) => v.type === toType);
66012
+ const toDecimals = toEntry ? toEntry[1].decimals : toType === "0x2::sui::SUI" ? 9 : 6;
66013
+ let preBalRaw = 0n;
66014
+ try {
66015
+ const preBal = await this.client.getBalance({ owner: this._address, coinType: toType });
66016
+ preBalRaw = BigInt(preBal.totalBalance);
66017
+ } catch {
66018
+ }
66011
66019
  const gasResult = await executeWithGas(this.client, this._signer, async () => {
66012
66020
  const tx = new Transaction();
66013
66021
  tx.setSender(this._address);
@@ -66030,35 +66038,54 @@ var T2000 = class _T2000 extends import_index.default {
66030
66038
  tx.transferObjects([outputCoin], this._address);
66031
66039
  return tx;
66032
66040
  });
66033
- const toEntry = Object.entries(SUPPORTED_ASSETS).find(([, v]) => v.type === toType);
66034
- const toDecimals = toEntry ? toEntry[1].decimals : toType === "0x2::sui::SUI" ? 9 : 6;
66035
66041
  const fromAmount = Number(route.amountIn) / 10 ** fromDecimals;
66036
66042
  let toAmount = Number(route.amountOut) / 10 ** toDecimals;
66037
66043
  const toTypeSuffix = toType.split("::").slice(1).join("::");
66038
- for (let attempt = 0; attempt < 4; attempt++) {
66044
+ try {
66045
+ const fullTx = await this.client.waitForTransaction({
66046
+ digest: gasResult.digest,
66047
+ options: { showBalanceChanges: true },
66048
+ timeout: 8e3,
66049
+ pollInterval: 400
66050
+ });
66051
+ const changes = fullTx.balanceChanges ?? [];
66052
+ console.error(`[swap] balanceChanges count=${changes.length}, toType=${toType}, suffix=${toTypeSuffix}`);
66053
+ for (const c of changes) {
66054
+ console.error(`[swap] coinType=${c.coinType} amount=${c.amount} owner=${JSON.stringify(c.owner)}`);
66055
+ }
66056
+ const received = changes.find((c) => {
66057
+ if (BigInt(c.amount) <= 0n) return false;
66058
+ const ownerAddr = c.owner?.AddressOwner;
66059
+ if (!ownerAddr || ownerAddr.toLowerCase() !== this._address.toLowerCase()) return false;
66060
+ if (c.coinType === toType) return true;
66061
+ return c.coinType.endsWith(toTypeSuffix);
66062
+ });
66063
+ if (received) {
66064
+ const actual = Number(BigInt(received.amount)) / 10 ** toDecimals;
66065
+ if (actual > 0) toAmount = actual;
66066
+ console.error(`[swap] Primary: toAmount=${toAmount}`);
66067
+ } else {
66068
+ console.error(`[swap] Primary: no matching balance change found`);
66069
+ }
66070
+ } catch (err) {
66071
+ console.error(`[swap] Primary failed:`, err);
66072
+ }
66073
+ const cetusEstimate = Number(route.amountOut) / 10 ** toDecimals;
66074
+ if (Math.abs(toAmount - cetusEstimate) < 1e-3) {
66075
+ console.error(`[swap] toAmount still equals Cetus estimate (${cetusEstimate}), trying balance diff`);
66039
66076
  try {
66040
- const txBlock = await this.client.getTransactionBlock({
66041
- digest: gasResult.digest,
66042
- options: { showBalanceChanges: true }
66043
- });
66044
- const changes = txBlock.balanceChanges ?? [];
66045
- const received = changes.find((c) => {
66046
- if (BigInt(c.amount) <= 0n) return false;
66047
- const ownerAddr = c.owner?.AddressOwner;
66048
- if (!ownerAddr || ownerAddr.toLowerCase() !== this._address.toLowerCase()) return false;
66049
- if (c.coinType === toType) return true;
66050
- return c.coinType.endsWith(toTypeSuffix);
66051
- });
66052
- if (received) {
66053
- const actual = Number(BigInt(received.amount)) / 10 ** toDecimals;
66054
- if (actual > 0) {
66055
- toAmount = actual;
66056
- break;
66057
- }
66077
+ await new Promise((r) => setTimeout(r, 2e3));
66078
+ const postBal = await this.client.getBalance({ owner: this._address, coinType: toType });
66079
+ const postRaw = BigInt(postBal.totalBalance);
66080
+ const delta = Number(postRaw - preBalRaw) / 10 ** toDecimals;
66081
+ console.error(`[swap] Fallback: pre=${preBalRaw} post=${postRaw} delta=${delta}`);
66082
+ if (delta > 0) {
66083
+ toAmount = delta;
66084
+ console.error(`[swap] Fallback: using balance diff: ${toAmount}`);
66058
66085
  }
66059
- } catch {
66086
+ } catch (err) {
66087
+ console.error(`[swap] Fallback failed:`, err);
66060
66088
  }
66061
- if (attempt < 3) await new Promise((r) => setTimeout(r, 600));
66062
66089
  }
66063
66090
  const fromName = fromEntry ? fromEntry[0] : this._resolveTokenName(fromType, params.from);
66064
66091
  const toName = toEntry ? toEntry[0] : this._resolveTokenName(toType, params.to);
@@ -67083,4 +67110,4 @@ axios/dist/node/axios.cjs:
67083
67110
  @scure/bip39/index.js:
67084
67111
  (*! scure-bip39 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) *)
67085
67112
  */
67086
- //# sourceMappingURL=chunk-CDQ2RJBX.js.map
67113
+ //# sourceMappingURL=chunk-LE7LKEOJ.js.map