@t2000/sdk 0.21.10 → 0.21.11
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 +24 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +24 -14
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2351,21 +2351,31 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
2351
2351
|
const toDecimals = toEntry ? toEntry[1].decimals : toType === "0x2::sui::SUI" ? 9 : 6;
|
|
2352
2352
|
const fromAmount = Number(route.amountIn) / 10 ** fromDecimals;
|
|
2353
2353
|
let toAmount = Number(route.amountOut) / 10 ** toDecimals;
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2354
|
+
const toTypeSuffix = toType.split("::").slice(1).join("::");
|
|
2355
|
+
for (let attempt = 0; attempt < 4; attempt++) {
|
|
2356
|
+
try {
|
|
2357
|
+
const txBlock = await this.client.getTransactionBlock({
|
|
2358
|
+
digest: gasResult.digest,
|
|
2359
|
+
options: { showBalanceChanges: true }
|
|
2360
|
+
});
|
|
2361
|
+
const changes = txBlock.balanceChanges ?? [];
|
|
2362
|
+
const received = changes.find((c) => {
|
|
2363
|
+
if (BigInt(c.amount) <= 0n) return false;
|
|
2364
|
+
const ownerAddr = c.owner?.AddressOwner;
|
|
2365
|
+
if (!ownerAddr || ownerAddr.toLowerCase() !== this._address.toLowerCase()) return false;
|
|
2366
|
+
if (c.coinType === toType) return true;
|
|
2367
|
+
return c.coinType.endsWith(toTypeSuffix);
|
|
2368
|
+
});
|
|
2369
|
+
if (received) {
|
|
2370
|
+
const actual = Number(BigInt(received.amount)) / 10 ** toDecimals;
|
|
2371
|
+
if (actual > 0) {
|
|
2372
|
+
toAmount = actual;
|
|
2373
|
+
break;
|
|
2374
|
+
}
|
|
2375
|
+
}
|
|
2376
|
+
} catch {
|
|
2366
2377
|
}
|
|
2367
|
-
|
|
2368
|
-
console.warn("[swap] Could not read balance changes, using route estimate");
|
|
2378
|
+
if (attempt < 3) await new Promise((r) => setTimeout(r, 600));
|
|
2369
2379
|
}
|
|
2370
2380
|
const fromName = fromEntry ? fromEntry[0] : this._resolveTokenName(fromType, params.from);
|
|
2371
2381
|
const toName = toEntry ? toEntry[0] : this._resolveTokenName(toType, params.to);
|