@t2000/sdk 0.21.8 → 0.21.9
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 +17 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +17 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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 preBalance = 0n;
|
|
2331
|
+
try {
|
|
2332
|
+
const bal = await this.client.getBalance({ owner: this._address, coinType: toType });
|
|
2333
|
+
preBalance = BigInt(bal.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,17 +2355,17 @@ 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
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2360
|
+
try {
|
|
2361
|
+
const postBal = await this.client.getBalance({ owner: this._address, coinType: toType });
|
|
2362
|
+
const postBalance = BigInt(postBal.totalBalance);
|
|
2363
|
+
const diff = postBalance - preBalance;
|
|
2364
|
+
if (diff > 0n) {
|
|
2365
|
+
toAmount = Number(diff) / 10 ** toDecimals;
|
|
2366
|
+
}
|
|
2367
|
+
} catch {
|
|
2368
|
+
console.warn("[swap] Could not read post-swap balance, 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);
|