@t2000/cli 0.25.12 → 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,8 +66038,6 @@ 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("::");
@@ -66043,7 +66049,7 @@ var T2000 = class _T2000 extends import_index.default {
66043
66049
  pollInterval: 400
66044
66050
  });
66045
66051
  const changes = fullTx.balanceChanges ?? [];
66046
- console.error(`[swap] balanceChanges count=${changes.length}, toType=${toType}`);
66052
+ console.error(`[swap] balanceChanges count=${changes.length}, toType=${toType}, suffix=${toTypeSuffix}`);
66047
66053
  for (const c of changes) {
66048
66054
  console.error(`[swap] coinType=${c.coinType} amount=${c.amount} owner=${JSON.stringify(c.owner)}`);
66049
66055
  }
@@ -66057,12 +66063,12 @@ var T2000 = class _T2000 extends import_index.default {
66057
66063
  if (received) {
66058
66064
  const actual = Number(BigInt(received.amount)) / 10 ** toDecimals;
66059
66065
  if (actual > 0) toAmount = actual;
66060
- console.error(`[swap] Approach 1 success: toAmount=${toAmount}`);
66066
+ console.error(`[swap] Primary: toAmount=${toAmount}`);
66061
66067
  } else {
66062
- console.error(`[swap] Approach 1: no matching balance change found`);
66068
+ console.error(`[swap] Primary: no matching balance change found`);
66063
66069
  }
66064
66070
  } catch (err) {
66065
- console.error(`[swap] Approach 1 failed:`, err);
66071
+ console.error(`[swap] Primary failed:`, err);
66066
66072
  }
66067
66073
  const cetusEstimate = Number(route.amountOut) / 10 ** toDecimals;
66068
66074
  if (Math.abs(toAmount - cetusEstimate) < 1e-3) {
@@ -66071,14 +66077,14 @@ var T2000 = class _T2000 extends import_index.default {
66071
66077
  await new Promise((r) => setTimeout(r, 2e3));
66072
66078
  const postBal = await this.client.getBalance({ owner: this._address, coinType: toType });
66073
66079
  const postRaw = BigInt(postBal.totalBalance);
66074
- const human = Number(postRaw) / 10 ** toDecimals;
66075
- console.error(`[swap] Approach 2: postBalance raw=${postRaw} human=${human}`);
66076
- if (human > toAmount * 10) {
66077
- toAmount = human;
66078
- console.error(`[swap] Approach 2: using total balance as estimate: ${toAmount}`);
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}`);
66079
66085
  }
66080
66086
  } catch (err) {
66081
- console.error(`[swap] Approach 2 failed:`, err);
66087
+ console.error(`[swap] Fallback failed:`, err);
66082
66088
  }
66083
66089
  }
66084
66090
  const fromName = fromEntry ? fromEntry[0] : this._resolveTokenName(fromType, params.from);
@@ -67104,4 +67110,4 @@ axios/dist/node/axios.cjs:
67104
67110
  @scure/bip39/index.js:
67105
67111
  (*! scure-bip39 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) *)
67106
67112
  */
67107
- //# sourceMappingURL=chunk-XNKVJ4IY.js.map
67113
+ //# sourceMappingURL=chunk-LE7LKEOJ.js.map