@t2000/sdk 0.21.12 → 0.21.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.
package/dist/index.d.cts CHANGED
@@ -147,7 +147,7 @@ interface TxMetadata {
147
147
  operation: 'send' | 'save' | 'withdraw' | 'borrow' | 'repay' | 'pay';
148
148
  amount?: number;
149
149
  }
150
- declare const OUTBOUND_OPS: Set<"save" | "borrow" | "send" | "withdraw" | "repay" | "pay">;
150
+ declare const OUTBOUND_OPS: Set<"save" | "withdraw" | "borrow" | "repay" | "send" | "pay">;
151
151
  declare const DEFAULT_SAFEGUARD_CONFIG: SafeguardConfig;
152
152
 
153
153
  declare class SafeguardEnforcer {
package/dist/index.d.ts CHANGED
@@ -147,7 +147,7 @@ interface TxMetadata {
147
147
  operation: 'send' | 'save' | 'withdraw' | 'borrow' | 'repay' | 'pay';
148
148
  amount?: number;
149
149
  }
150
- declare const OUTBOUND_OPS: Set<"save" | "borrow" | "send" | "withdraw" | "repay" | "pay">;
150
+ declare const OUTBOUND_OPS: Set<"save" | "withdraw" | "borrow" | "repay" | "send" | "pay">;
151
151
  declare const DEFAULT_SAFEGUARD_CONFIG: SafeguardConfig;
152
152
 
153
153
  declare class SafeguardEnforcer {
package/dist/index.js CHANGED
@@ -2325,6 +2325,14 @@ var T2000 = class _T2000 extends EventEmitter {
2325
2325
  if (route.priceImpact > 0.05) {
2326
2326
  console.warn(`[swap] High price impact: ${(route.priceImpact * 100).toFixed(2)}%`);
2327
2327
  }
2328
+ const toEntry = Object.entries(SUPPORTED_ASSETS).find(([, v]) => v.type === toType);
2329
+ const toDecimals = toEntry ? toEntry[1].decimals : toType === "0x2::sui::SUI" ? 9 : 6;
2330
+ let preBalRaw = 0n;
2331
+ try {
2332
+ const preBal = await this.client.getBalance({ owner: this._address, coinType: toType });
2333
+ preBalRaw = BigInt(preBal.totalBalance);
2334
+ } catch {
2335
+ }
2328
2336
  const gasResult = await executeWithGas(this.client, this._signer, async () => {
2329
2337
  const tx = new Transaction();
2330
2338
  tx.setSender(this._address);
@@ -2347,8 +2355,6 @@ var T2000 = class _T2000 extends EventEmitter {
2347
2355
  tx.transferObjects([outputCoin], this._address);
2348
2356
  return tx;
2349
2357
  });
2350
- const toEntry = Object.entries(SUPPORTED_ASSETS).find(([, v]) => v.type === toType);
2351
- const toDecimals = toEntry ? toEntry[1].decimals : toType === "0x2::sui::SUI" ? 9 : 6;
2352
2358
  const fromAmount = Number(route.amountIn) / 10 ** fromDecimals;
2353
2359
  let toAmount = Number(route.amountOut) / 10 ** toDecimals;
2354
2360
  const toTypeSuffix = toType.split("::").slice(1).join("::");
@@ -2360,7 +2366,7 @@ var T2000 = class _T2000 extends EventEmitter {
2360
2366
  pollInterval: 400
2361
2367
  });
2362
2368
  const changes = fullTx.balanceChanges ?? [];
2363
- console.error(`[swap] balanceChanges count=${changes.length}, toType=${toType}`);
2369
+ console.error(`[swap] balanceChanges count=${changes.length}, toType=${toType}, suffix=${toTypeSuffix}`);
2364
2370
  for (const c of changes) {
2365
2371
  console.error(`[swap] coinType=${c.coinType} amount=${c.amount} owner=${JSON.stringify(c.owner)}`);
2366
2372
  }
@@ -2374,12 +2380,12 @@ var T2000 = class _T2000 extends EventEmitter {
2374
2380
  if (received) {
2375
2381
  const actual = Number(BigInt(received.amount)) / 10 ** toDecimals;
2376
2382
  if (actual > 0) toAmount = actual;
2377
- console.error(`[swap] Approach 1 success: toAmount=${toAmount}`);
2383
+ console.error(`[swap] Primary: toAmount=${toAmount}`);
2378
2384
  } else {
2379
- console.error(`[swap] Approach 1: no matching balance change found`);
2385
+ console.error(`[swap] Primary: no matching balance change found`);
2380
2386
  }
2381
2387
  } catch (err) {
2382
- console.error(`[swap] Approach 1 failed:`, err);
2388
+ console.error(`[swap] Primary failed:`, err);
2383
2389
  }
2384
2390
  const cetusEstimate = Number(route.amountOut) / 10 ** toDecimals;
2385
2391
  if (Math.abs(toAmount - cetusEstimate) < 1e-3) {
@@ -2388,14 +2394,14 @@ var T2000 = class _T2000 extends EventEmitter {
2388
2394
  await new Promise((r) => setTimeout(r, 2e3));
2389
2395
  const postBal = await this.client.getBalance({ owner: this._address, coinType: toType });
2390
2396
  const postRaw = BigInt(postBal.totalBalance);
2391
- const human = Number(postRaw) / 10 ** toDecimals;
2392
- console.error(`[swap] Approach 2: postBalance raw=${postRaw} human=${human}`);
2393
- if (human > toAmount * 10) {
2394
- toAmount = human;
2395
- console.error(`[swap] Approach 2: using total balance as estimate: ${toAmount}`);
2397
+ const delta = Number(postRaw - preBalRaw) / 10 ** toDecimals;
2398
+ console.error(`[swap] Fallback: pre=${preBalRaw} post=${postRaw} delta=${delta}`);
2399
+ if (delta > 0) {
2400
+ toAmount = delta;
2401
+ console.error(`[swap] Fallback: using balance diff: ${toAmount}`);
2396
2402
  }
2397
2403
  } catch (err) {
2398
- console.error(`[swap] Approach 2 failed:`, err);
2404
+ console.error(`[swap] Fallback failed:`, err);
2399
2405
  }
2400
2406
  }
2401
2407
  const fromName = fromEntry ? fromEntry[0] : this._resolveTokenName(fromType, params.from);