@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.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 preBalance = 0n;
|
|
2333
|
+
try {
|
|
2334
|
+
const bal = await this.client.getBalance({ owner: this._address, coinType: toType });
|
|
2335
|
+
preBalance = BigInt(bal.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,17 +2357,17 @@ 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
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2362
|
+
try {
|
|
2363
|
+
const postBal = await this.client.getBalance({ owner: this._address, coinType: toType });
|
|
2364
|
+
const postBalance = BigInt(postBal.totalBalance);
|
|
2365
|
+
const diff = postBalance - preBalance;
|
|
2366
|
+
if (diff > 0n) {
|
|
2367
|
+
toAmount = Number(diff) / 10 ** toDecimals;
|
|
2368
|
+
}
|
|
2369
|
+
} catch {
|
|
2370
|
+
console.warn("[swap] Could not read post-swap balance, using route estimate");
|
|
2363
2371
|
}
|
|
2364
2372
|
const fromName = fromEntry ? fromEntry[0] : this._resolveTokenName(fromType, params.from);
|
|
2365
2373
|
const toName = toEntry ? toEntry[0] : this._resolveTokenName(toType, params.to);
|