@t2000/sdk 0.21.7 → 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
@@ -147,7 +147,7 @@ interface TxMetadata {
147
147
  operation: 'send' | 'save' | 'withdraw' | 'borrow' | 'repay' | 'pay';
148
148
  amount?: number;
149
149
  }
150
- declare const OUTBOUND_OPS: Set<"save" | "withdraw" | "borrow" | "repay" | "send" | "pay">;
150
+ declare const OUTBOUND_OPS: Set<"save" | "borrow" | "send" | "withdraw" | "repay" | "pay">;
151
151
  declare const DEFAULT_SAFEGUARD_CONFIG: SafeguardConfig;
152
152
 
153
153
  declare class SafeguardEnforcer {
@@ -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
@@ -147,7 +147,7 @@ interface TxMetadata {
147
147
  operation: 'send' | 'save' | 'withdraw' | 'borrow' | 'repay' | 'pay';
148
148
  amount?: number;
149
149
  }
150
- declare const OUTBOUND_OPS: Set<"save" | "withdraw" | "borrow" | "repay" | "send" | "pay">;
150
+ declare const OUTBOUND_OPS: Set<"save" | "borrow" | "send" | "withdraw" | "repay" | "pay">;
151
151
  declare const DEFAULT_SAFEGUARD_CONFIG: SafeguardConfig;
152
152
 
153
153
  declare class SafeguardEnforcer {
@@ -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
@@ -1678,13 +1678,14 @@ async function trySelfFunded(client, signer, tx) {
1678
1678
  const result = await client.executeTransactionBlock({
1679
1679
  transactionBlock: toBase64(builtBytes),
1680
1680
  signature: [signature],
1681
- options: { showEffects: true }
1681
+ options: { showEffects: true, showBalanceChanges: true }
1682
1682
  });
1683
1683
  await client.waitForTransaction({ digest: result.digest });
1684
1684
  await assertTxSuccess(result.effects, result.digest);
1685
1685
  return {
1686
1686
  digest: result.digest,
1687
1687
  effects: result.effects,
1688
+ balanceChanges: result.balanceChanges,
1688
1689
  gasMethod: "self-funded",
1689
1690
  gasCostSui: extractGasCost(result.effects),
1690
1691
  preTxSuiMist: suiBalance
@@ -1703,13 +1704,14 @@ async function tryAutoTopUpThenSelfFund(client, signer, buildTx) {
1703
1704
  const result = await client.executeTransactionBlock({
1704
1705
  transactionBlock: toBase64(builtBytes),
1705
1706
  signature: [signature],
1706
- options: { showEffects: true }
1707
+ options: { showEffects: true, showBalanceChanges: true }
1707
1708
  });
1708
1709
  await client.waitForTransaction({ digest: result.digest });
1709
1710
  await assertTxSuccess(result.effects, result.digest);
1710
1711
  return {
1711
1712
  digest: result.digest,
1712
1713
  effects: result.effects,
1714
+ balanceChanges: result.balanceChanges,
1713
1715
  gasMethod: "auto-topup",
1714
1716
  gasCostSui: extractGasCost(result.effects),
1715
1717
  preTxSuiMist: suiAfterTopUp
@@ -1733,7 +1735,7 @@ async function trySponsored(client, signer, tx) {
1733
1735
  const result = await client.executeTransactionBlock({
1734
1736
  transactionBlock: sponsoredResult.txBytes,
1735
1737
  signature: [agentSig, sponsoredResult.sponsorSignature],
1736
- options: { showEffects: true }
1738
+ options: { showEffects: true, showBalanceChanges: true }
1737
1739
  });
1738
1740
  await client.waitForTransaction({ digest: result.digest });
1739
1741
  await assertTxSuccess(result.effects, result.digest);
@@ -1742,6 +1744,7 @@ async function trySponsored(client, signer, tx) {
1742
1744
  return {
1743
1745
  digest: result.digest,
1744
1746
  effects: result.effects,
1747
+ balanceChanges: result.balanceChanges,
1745
1748
  gasMethod: "sponsored",
1746
1749
  gasCostSui: gasCost,
1747
1750
  preTxSuiMist: suiBalance
@@ -2348,28 +2351,22 @@ var T2000 = class _T2000 extends EventEmitter {
2348
2351
  const toDecimals = toEntry ? toEntry[1].decimals : toType === "0x2::sui::SUI" ? 9 : 6;
2349
2352
  const fromAmount = Number(route.amountIn) / 10 ** fromDecimals;
2350
2353
  let toAmount = Number(route.amountOut) / 10 ** toDecimals;
2351
- try {
2352
- const txBlock = await this.client.getTransactionBlock({
2353
- digest: gasResult.digest,
2354
- options: { showBalanceChanges: true }
2355
- });
2356
- const changes = txBlock.balanceChanges ?? [];
2357
- const received = changes.find(
2358
- (c) => c.coinType === toType && BigInt(c.amount) > 0n && c.owner.AddressOwner === this._address
2359
- );
2360
- if (received) {
2361
- const actual = Number(BigInt(received.amount)) / 10 ** toDecimals;
2362
- if (actual > 0) toAmount = actual;
2363
- }
2364
- } catch (e) {
2365
- console.warn("[swap] Could not parse on-chain balance changes, using route estimate:", e);
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;
2366
2361
  }
2362
+ const fromName = fromEntry ? fromEntry[0] : this._resolveTokenName(fromType, params.from);
2363
+ const toName = toEntry ? toEntry[0] : this._resolveTokenName(toType, params.to);
2367
2364
  const routeDesc = route.routerData.paths?.map((p) => p.provider).filter(Boolean).slice(0, 3).join(" + ") ?? "Cetus Aggregator";
2368
2365
  return {
2369
2366
  success: true,
2370
2367
  tx: gasResult.digest,
2371
- fromToken: params.from,
2372
- toToken: params.to,
2368
+ fromToken: fromName,
2369
+ toToken: toName,
2373
2370
  fromAmount,
2374
2371
  toAmount,
2375
2372
  priceImpact: route.priceImpact,
@@ -2774,6 +2771,12 @@ var T2000 = class _T2000 extends EventEmitter {
2774
2771
  }
2775
2772
  return all;
2776
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
+ }
2777
2780
  _mergeCoinsInTx(tx, coins) {
2778
2781
  if (coins.length === 0) throw new T2000Error("INSUFFICIENT_BALANCE", "No coins to merge");
2779
2782
  const primary = tx.object(coins[0].coinObjectId);