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