@t2000/sdk 0.21.6 → 0.21.8

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
@@ -313,6 +313,7 @@ declare class T2000 extends EventEmitter<T2000Events> {
313
313
  }): Promise<WithdrawResult>;
314
314
  private withdrawAllProtocols;
315
315
  private _fetchCoins;
316
+ private _resolveTokenName;
316
317
  private _mergeCoinsInTx;
317
318
  private _lastFundDigest;
318
319
  private _autoFundFromSavings;
@@ -516,6 +517,7 @@ declare class SafeguardError extends T2000Error {
516
517
  interface GasExecutionResult {
517
518
  digest: string;
518
519
  effects: unknown;
520
+ balanceChanges?: unknown[];
519
521
  gasMethod: GasMethod;
520
522
  gasCostSui: number;
521
523
  /** Pre-TX SUI balance in MIST — used internally for proactive gas maintenance. */
package/dist/index.d.ts CHANGED
@@ -313,6 +313,7 @@ declare class T2000 extends EventEmitter<T2000Events> {
313
313
  }): Promise<WithdrawResult>;
314
314
  private withdrawAllProtocols;
315
315
  private _fetchCoins;
316
+ private _resolveTokenName;
316
317
  private _mergeCoinsInTx;
317
318
  private _lastFundDigest;
318
319
  private _autoFundFromSavings;
@@ -516,6 +517,7 @@ declare class SafeguardError extends T2000Error {
516
517
  interface GasExecutionResult {
517
518
  digest: string;
518
519
  effects: unknown;
520
+ balanceChanges?: unknown[];
519
521
  gasMethod: GasMethod;
520
522
  gasCostSui: number;
521
523
  /** Pre-TX SUI balance in MIST — used internally for proactive gas maintenance. */
package/dist/index.js CHANGED
@@ -311,6 +311,8 @@ var init_cetus_swap = __esm({
311
311
  AUSD: "0x2053d08c1e2bd02791056171aab0fd12bd7cd7efad2ab8f6b9c8902f14df2ff2::ausd::AUSD",
312
312
  BUCK: "0xce7ff77a83ea0cb6fd39bd8748e2ec89a3f41e8efdc3f4eb123e0ca37b184db2::buck::BUCK",
313
313
  USDe: "0x41d587e5336f1c86cad50d38a7136db99333bb9bda91cea4ba69115defeb1402::sui_usde::SUI_USDE",
314
+ USDSUI: "0x44f838219cf67b058f3b37907b655f226153c18e33dfcd0da559a844fea9b1c1::usdsui::USDSUI",
315
+ MANIFEST: "0xc466c28d87b3d5cd34f3d5c088751532d71a38d93a8aae4551dd56272cfb4355::manifest::MANIFEST",
314
316
  NS: "0x5145494a5f5100e645e4b0aa950fa6b68f614e8c59e17bc5ded3495123a79178::ns::NS",
315
317
  BLUB: "0xfa7ac3951fdca12c1b6d18eb19e1aa2fbc31e4d45773c8e45b4ded3ef8d83f8a::blub::BLUB",
316
318
  SCA: "0x7016aae72cfc67f2fadf55769c0a7dd54291a583b63051a5ed71081cce836ac6::sca::SCA",
@@ -1676,13 +1678,14 @@ async function trySelfFunded(client, signer, tx) {
1676
1678
  const result = await client.executeTransactionBlock({
1677
1679
  transactionBlock: toBase64(builtBytes),
1678
1680
  signature: [signature],
1679
- options: { showEffects: true }
1681
+ options: { showEffects: true, showBalanceChanges: true }
1680
1682
  });
1681
1683
  await client.waitForTransaction({ digest: result.digest });
1682
1684
  await assertTxSuccess(result.effects, result.digest);
1683
1685
  return {
1684
1686
  digest: result.digest,
1685
1687
  effects: result.effects,
1688
+ balanceChanges: result.balanceChanges,
1686
1689
  gasMethod: "self-funded",
1687
1690
  gasCostSui: extractGasCost(result.effects),
1688
1691
  preTxSuiMist: suiBalance
@@ -1701,13 +1704,14 @@ async function tryAutoTopUpThenSelfFund(client, signer, buildTx) {
1701
1704
  const result = await client.executeTransactionBlock({
1702
1705
  transactionBlock: toBase64(builtBytes),
1703
1706
  signature: [signature],
1704
- options: { showEffects: true }
1707
+ options: { showEffects: true, showBalanceChanges: true }
1705
1708
  });
1706
1709
  await client.waitForTransaction({ digest: result.digest });
1707
1710
  await assertTxSuccess(result.effects, result.digest);
1708
1711
  return {
1709
1712
  digest: result.digest,
1710
1713
  effects: result.effects,
1714
+ balanceChanges: result.balanceChanges,
1711
1715
  gasMethod: "auto-topup",
1712
1716
  gasCostSui: extractGasCost(result.effects),
1713
1717
  preTxSuiMist: suiAfterTopUp
@@ -1731,7 +1735,7 @@ async function trySponsored(client, signer, tx) {
1731
1735
  const result = await client.executeTransactionBlock({
1732
1736
  transactionBlock: sponsoredResult.txBytes,
1733
1737
  signature: [agentSig, sponsoredResult.sponsorSignature],
1734
- options: { showEffects: true }
1738
+ options: { showEffects: true, showBalanceChanges: true }
1735
1739
  });
1736
1740
  await client.waitForTransaction({ digest: result.digest });
1737
1741
  await assertTxSuccess(result.effects, result.digest);
@@ -1740,6 +1744,7 @@ async function trySponsored(client, signer, tx) {
1740
1744
  return {
1741
1745
  digest: result.digest,
1742
1746
  effects: result.effects,
1747
+ balanceChanges: result.balanceChanges,
1743
1748
  gasMethod: "sponsored",
1744
1749
  gasCostSui: gasCost,
1745
1750
  preTxSuiMist: suiBalance
@@ -2345,13 +2350,23 @@ var T2000 = class _T2000 extends EventEmitter {
2345
2350
  const toEntry = Object.entries(SUPPORTED_ASSETS).find(([, v]) => v.type === toType);
2346
2351
  const toDecimals = toEntry ? toEntry[1].decimals : toType === "0x2::sui::SUI" ? 9 : 6;
2347
2352
  const fromAmount = Number(route.amountIn) / 10 ** fromDecimals;
2348
- const toAmount = Number(route.amountOut) / 10 ** toDecimals;
2353
+ let toAmount = Number(route.amountOut) / 10 ** toDecimals;
2354
+ const changes = gasResult.balanceChanges ?? [];
2355
+ const received = changes.find(
2356
+ (c) => c.coinType === toType && BigInt(c.amount) > 0n && c.owner.AddressOwner === this._address
2357
+ );
2358
+ if (received) {
2359
+ const actual = Number(BigInt(received.amount)) / 10 ** toDecimals;
2360
+ if (actual > 0) toAmount = actual;
2361
+ }
2362
+ const fromName = fromEntry ? fromEntry[0] : this._resolveTokenName(fromType, params.from);
2363
+ const toName = toEntry ? toEntry[0] : this._resolveTokenName(toType, params.to);
2349
2364
  const routeDesc = route.routerData.paths?.map((p) => p.provider).filter(Boolean).slice(0, 3).join(" + ") ?? "Cetus Aggregator";
2350
2365
  return {
2351
2366
  success: true,
2352
2367
  tx: gasResult.digest,
2353
- fromToken: params.from,
2354
- toToken: params.to,
2368
+ fromToken: fromName,
2369
+ toToken: toName,
2355
2370
  fromAmount,
2356
2371
  toAmount,
2357
2372
  priceImpact: route.priceImpact,
@@ -2756,6 +2771,12 @@ var T2000 = class _T2000 extends EventEmitter {
2756
2771
  }
2757
2772
  return all;
2758
2773
  }
2774
+ _resolveTokenName(coinType, fallback) {
2775
+ const entry = Object.entries(SUPPORTED_ASSETS).find(([, v]) => v.type === coinType);
2776
+ if (entry) return entry[0];
2777
+ const suffix = coinType.split("::").pop();
2778
+ return suffix && suffix !== coinType ? suffix : fallback;
2779
+ }
2759
2780
  _mergeCoinsInTx(tx, coins) {
2760
2781
  if (coins.length === 0) throw new T2000Error("INSUFFICIENT_BALANCE", "No coins to merge");
2761
2782
  const primary = tx.object(coins[0].coinObjectId);