@t2000/sdk 0.21.12 → 0.21.14

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,7 +313,6 @@ declare class T2000 extends EventEmitter<T2000Events> {
313
313
  }): Promise<WithdrawResult>;
314
314
  private withdrawAllProtocols;
315
315
  private _fetchCoins;
316
- private _resolveTokenName;
317
316
  private _mergeCoinsInTx;
318
317
  private _lastFundDigest;
319
318
  private _autoFundFromSavings;
@@ -423,6 +422,58 @@ declare function getSwapQuote(params: {
423
422
  byAmountIn?: boolean;
424
423
  }): Promise<SwapQuoteResult>;
425
424
 
425
+ /**
426
+ * Unified token registry — single source of truth for coin types, decimals, and symbols.
427
+ *
428
+ * ZERO heavy dependencies. Safe to import from any context (server, browser, Edge).
429
+ * All other token maps (KNOWN_COINS, DEC_MAP, TOKEN_DECIMALS, etc.) should be replaced
430
+ * with imports from this file.
431
+ *
432
+ * To add a new token: add ONE entry to COIN_REGISTRY below. Everything else derives from it.
433
+ */
434
+ interface CoinMeta {
435
+ type: string;
436
+ decimals: number;
437
+ symbol: string;
438
+ }
439
+ /**
440
+ * Canonical coin registry. Merges NAVI lending assets + swap-supported tokens.
441
+ * Key = user-friendly name (used in swap_execute, CLI, prompts).
442
+ */
443
+ declare const COIN_REGISTRY: Record<string, CoinMeta>;
444
+ /**
445
+ * Get decimals for any coin type. Checks full type match, then suffix match, then defaults to 9.
446
+ * Handles address normalization differences (leading zeros, casing).
447
+ */
448
+ declare function getDecimalsForCoinType(coinType: string): number;
449
+ /**
450
+ * Resolve a full coin type to a user-friendly symbol.
451
+ * Returns the last `::` segment if not in the registry.
452
+ */
453
+ declare function resolveSymbol(coinType: string): string;
454
+ /**
455
+ * Name → type map for swap resolution. Derived from COIN_REGISTRY.
456
+ * Contains BOTH original-case and UPPERCASE keys for case-insensitive lookup.
457
+ * Backward-compatible with the original TOKEN_MAP in cetus-swap.ts.
458
+ */
459
+ declare const TOKEN_MAP: Record<string, string>;
460
+ /**
461
+ * Resolve a user-friendly token name to its full coin type.
462
+ * Returns the input unchanged if already a full coin type (contains "::").
463
+ * Case-insensitive: 'usde', 'USDe', 'USDE' all resolve correctly.
464
+ */
465
+ declare function resolveTokenType(nameOrType: string): string | null;
466
+ /** Common type constants for direct import (avoid hardcoding strings). */
467
+ declare const SUI_TYPE: string;
468
+ declare const USDC_TYPE: string;
469
+ declare const USDT_TYPE: string;
470
+ declare const USDSUI_TYPE: string;
471
+ declare const USDE_TYPE: string;
472
+ declare const ETH_TYPE: string;
473
+ declare const WBTC_TYPE: string;
474
+ declare const WAL_TYPE: string;
475
+ declare const NAVX_TYPE: string;
476
+
426
477
  /**
427
478
  * Cetus Aggregator V3 SDK wrapper — the ONLY file that imports @cetusprotocol/aggregator-sdk.
428
479
  * Documented CLAUDE.md exception: multi-DEX routing cannot be feasibly replaced by thin tx builders.
@@ -457,12 +508,6 @@ declare function buildSwapTx(params: {
457
508
  inputCoin: TransactionObjectArgument;
458
509
  slippage: number;
459
510
  }): Promise<TransactionObjectArgument>;
460
- declare const TOKEN_MAP: Record<string, string>;
461
- /**
462
- * Resolve a user-friendly token name ("SUI", "USDC") to its full coin type string.
463
- * Returns the input unchanged if already a full coin type (contains "::").
464
- */
465
- declare function resolveTokenType(nameOrType: string): string | null;
466
511
 
467
512
  /**
468
513
  * VOLO vSUI liquid staking — thin transaction builders.
@@ -562,4 +607,4 @@ interface GasStatusResponse {
562
607
  }
563
608
  declare function getGasStatus(address?: string): Promise<GasStatusResponse>;
564
609
 
565
- export { ALL_NAVI_ASSETS, type AutoTopUpResult, BPS_DENOMINATOR, BalanceResponse, BorrowResult, CETUS_USDC_SUI_POOL, CLOCK_ID, ClaimRewardsResult, ContactManager, DEFAULT_NETWORK, DEFAULT_SAFEGUARD_CONFIG, DepositInfo, EarningsResult, type FeeOperation, FundStatusResult, GAS_RESERVE_MIN, type GasExecutionResult, GasMethod, type GasRequestType, type GasSponsorResponse, type GasStatusResponse, HealthFactorResult, KeypairSigner, LendingAdapter, LendingRates, MIST_PER_SUI, MaxBorrowResult, MaxWithdrawResult, OUTBOUND_OPS, PayOptions, PayResult, PendingReward, PositionsResult, type ProtocolFeeInfo, RatesResult, RepayResult, STABLE_ASSETS, SUI_DECIMALS, SUPPORTED_ASSETS, type SafeguardConfig, SafeguardEnforcer, SafeguardError, type SafeguardErrorDetails, type SafeguardRule, SaveResult, SendResult, type SimulationResult, type StableAsset, StakeVSuiResult, type SupportedAsset, SwapQuoteResult, SwapResult, type SwapRouteResult, T2000, T2000Error, type T2000ErrorCode, type T2000ErrorData, T2000Options, TOKEN_MAP, TransactionRecord, type TransactionSigner, type TxMetadata, USDC_DECIMALS, UnstakeVSuiResult, VOLO_METADATA, VOLO_PKG, VOLO_POOL, VSUI_TYPE, type VoloStats, WithdrawResult, type ZkLoginProof, ZkLoginSigner, addCollectFeeToTx, buildStakeVSuiTx, buildSwapTx, buildUnstakeVSuiTx, calculateFee, executeAutoTopUp, executeWithGas, exportPrivateKey, findSwapRoute, formatAssetAmount, formatSui, formatUsd, generateKeypair, getAddress, getDecimals, getGasStatus, getRates, getSwapQuote, getVoloStats, keypairFromPrivateKey, loadKey, mapMoveAbortCode, mapWalletError, mistToSui, rawToStable, rawToUsdc, resolveTokenType, saveKey, shouldAutoTopUp, simulateTransaction, solveHashcash, stableToRaw, suiToMist, throwIfSimulationFailed, truncateAddress, usdcToRaw, validateAddress, walletExists };
610
+ export { ALL_NAVI_ASSETS, type AutoTopUpResult, BPS_DENOMINATOR, BalanceResponse, BorrowResult, CETUS_USDC_SUI_POOL, CLOCK_ID, COIN_REGISTRY, ClaimRewardsResult, type CoinMeta, ContactManager, DEFAULT_NETWORK, DEFAULT_SAFEGUARD_CONFIG, DepositInfo, ETH_TYPE, EarningsResult, type FeeOperation, FundStatusResult, GAS_RESERVE_MIN, type GasExecutionResult, GasMethod, type GasRequestType, type GasSponsorResponse, type GasStatusResponse, HealthFactorResult, KeypairSigner, LendingAdapter, LendingRates, MIST_PER_SUI, MaxBorrowResult, MaxWithdrawResult, NAVX_TYPE, OUTBOUND_OPS, PayOptions, PayResult, PendingReward, PositionsResult, type ProtocolFeeInfo, RatesResult, RepayResult, STABLE_ASSETS, SUI_DECIMALS, SUI_TYPE, SUPPORTED_ASSETS, type SafeguardConfig, SafeguardEnforcer, SafeguardError, type SafeguardErrorDetails, type SafeguardRule, SaveResult, SendResult, type SimulationResult, type StableAsset, StakeVSuiResult, type SupportedAsset, SwapQuoteResult, SwapResult, type SwapRouteResult, T2000, T2000Error, type T2000ErrorCode, type T2000ErrorData, T2000Options, TOKEN_MAP, TransactionRecord, type TransactionSigner, type TxMetadata, USDC_DECIMALS, USDC_TYPE, USDE_TYPE, USDSUI_TYPE, USDT_TYPE, UnstakeVSuiResult, VOLO_METADATA, VOLO_PKG, VOLO_POOL, VSUI_TYPE, type VoloStats, WAL_TYPE, WBTC_TYPE, WithdrawResult, type ZkLoginProof, ZkLoginSigner, addCollectFeeToTx, buildStakeVSuiTx, buildSwapTx, buildUnstakeVSuiTx, calculateFee, executeAutoTopUp, executeWithGas, exportPrivateKey, findSwapRoute, formatAssetAmount, formatSui, formatUsd, generateKeypair, getAddress, getDecimals, getDecimalsForCoinType, getGasStatus, getRates, getSwapQuote, getVoloStats, keypairFromPrivateKey, loadKey, mapMoveAbortCode, mapWalletError, mistToSui, rawToStable, rawToUsdc, resolveSymbol, resolveTokenType, saveKey, shouldAutoTopUp, simulateTransaction, solveHashcash, stableToRaw, suiToMist, throwIfSimulationFailed, truncateAddress, usdcToRaw, validateAddress, walletExists };
package/dist/index.d.ts CHANGED
@@ -313,7 +313,6 @@ declare class T2000 extends EventEmitter<T2000Events> {
313
313
  }): Promise<WithdrawResult>;
314
314
  private withdrawAllProtocols;
315
315
  private _fetchCoins;
316
- private _resolveTokenName;
317
316
  private _mergeCoinsInTx;
318
317
  private _lastFundDigest;
319
318
  private _autoFundFromSavings;
@@ -423,6 +422,58 @@ declare function getSwapQuote(params: {
423
422
  byAmountIn?: boolean;
424
423
  }): Promise<SwapQuoteResult>;
425
424
 
425
+ /**
426
+ * Unified token registry — single source of truth for coin types, decimals, and symbols.
427
+ *
428
+ * ZERO heavy dependencies. Safe to import from any context (server, browser, Edge).
429
+ * All other token maps (KNOWN_COINS, DEC_MAP, TOKEN_DECIMALS, etc.) should be replaced
430
+ * with imports from this file.
431
+ *
432
+ * To add a new token: add ONE entry to COIN_REGISTRY below. Everything else derives from it.
433
+ */
434
+ interface CoinMeta {
435
+ type: string;
436
+ decimals: number;
437
+ symbol: string;
438
+ }
439
+ /**
440
+ * Canonical coin registry. Merges NAVI lending assets + swap-supported tokens.
441
+ * Key = user-friendly name (used in swap_execute, CLI, prompts).
442
+ */
443
+ declare const COIN_REGISTRY: Record<string, CoinMeta>;
444
+ /**
445
+ * Get decimals for any coin type. Checks full type match, then suffix match, then defaults to 9.
446
+ * Handles address normalization differences (leading zeros, casing).
447
+ */
448
+ declare function getDecimalsForCoinType(coinType: string): number;
449
+ /**
450
+ * Resolve a full coin type to a user-friendly symbol.
451
+ * Returns the last `::` segment if not in the registry.
452
+ */
453
+ declare function resolveSymbol(coinType: string): string;
454
+ /**
455
+ * Name → type map for swap resolution. Derived from COIN_REGISTRY.
456
+ * Contains BOTH original-case and UPPERCASE keys for case-insensitive lookup.
457
+ * Backward-compatible with the original TOKEN_MAP in cetus-swap.ts.
458
+ */
459
+ declare const TOKEN_MAP: Record<string, string>;
460
+ /**
461
+ * Resolve a user-friendly token name to its full coin type.
462
+ * Returns the input unchanged if already a full coin type (contains "::").
463
+ * Case-insensitive: 'usde', 'USDe', 'USDE' all resolve correctly.
464
+ */
465
+ declare function resolveTokenType(nameOrType: string): string | null;
466
+ /** Common type constants for direct import (avoid hardcoding strings). */
467
+ declare const SUI_TYPE: string;
468
+ declare const USDC_TYPE: string;
469
+ declare const USDT_TYPE: string;
470
+ declare const USDSUI_TYPE: string;
471
+ declare const USDE_TYPE: string;
472
+ declare const ETH_TYPE: string;
473
+ declare const WBTC_TYPE: string;
474
+ declare const WAL_TYPE: string;
475
+ declare const NAVX_TYPE: string;
476
+
426
477
  /**
427
478
  * Cetus Aggregator V3 SDK wrapper — the ONLY file that imports @cetusprotocol/aggregator-sdk.
428
479
  * Documented CLAUDE.md exception: multi-DEX routing cannot be feasibly replaced by thin tx builders.
@@ -457,12 +508,6 @@ declare function buildSwapTx(params: {
457
508
  inputCoin: TransactionObjectArgument;
458
509
  slippage: number;
459
510
  }): Promise<TransactionObjectArgument>;
460
- declare const TOKEN_MAP: Record<string, string>;
461
- /**
462
- * Resolve a user-friendly token name ("SUI", "USDC") to its full coin type string.
463
- * Returns the input unchanged if already a full coin type (contains "::").
464
- */
465
- declare function resolveTokenType(nameOrType: string): string | null;
466
511
 
467
512
  /**
468
513
  * VOLO vSUI liquid staking — thin transaction builders.
@@ -562,4 +607,4 @@ interface GasStatusResponse {
562
607
  }
563
608
  declare function getGasStatus(address?: string): Promise<GasStatusResponse>;
564
609
 
565
- export { ALL_NAVI_ASSETS, type AutoTopUpResult, BPS_DENOMINATOR, BalanceResponse, BorrowResult, CETUS_USDC_SUI_POOL, CLOCK_ID, ClaimRewardsResult, ContactManager, DEFAULT_NETWORK, DEFAULT_SAFEGUARD_CONFIG, DepositInfo, EarningsResult, type FeeOperation, FundStatusResult, GAS_RESERVE_MIN, type GasExecutionResult, GasMethod, type GasRequestType, type GasSponsorResponse, type GasStatusResponse, HealthFactorResult, KeypairSigner, LendingAdapter, LendingRates, MIST_PER_SUI, MaxBorrowResult, MaxWithdrawResult, OUTBOUND_OPS, PayOptions, PayResult, PendingReward, PositionsResult, type ProtocolFeeInfo, RatesResult, RepayResult, STABLE_ASSETS, SUI_DECIMALS, SUPPORTED_ASSETS, type SafeguardConfig, SafeguardEnforcer, SafeguardError, type SafeguardErrorDetails, type SafeguardRule, SaveResult, SendResult, type SimulationResult, type StableAsset, StakeVSuiResult, type SupportedAsset, SwapQuoteResult, SwapResult, type SwapRouteResult, T2000, T2000Error, type T2000ErrorCode, type T2000ErrorData, T2000Options, TOKEN_MAP, TransactionRecord, type TransactionSigner, type TxMetadata, USDC_DECIMALS, UnstakeVSuiResult, VOLO_METADATA, VOLO_PKG, VOLO_POOL, VSUI_TYPE, type VoloStats, WithdrawResult, type ZkLoginProof, ZkLoginSigner, addCollectFeeToTx, buildStakeVSuiTx, buildSwapTx, buildUnstakeVSuiTx, calculateFee, executeAutoTopUp, executeWithGas, exportPrivateKey, findSwapRoute, formatAssetAmount, formatSui, formatUsd, generateKeypair, getAddress, getDecimals, getGasStatus, getRates, getSwapQuote, getVoloStats, keypairFromPrivateKey, loadKey, mapMoveAbortCode, mapWalletError, mistToSui, rawToStable, rawToUsdc, resolveTokenType, saveKey, shouldAutoTopUp, simulateTransaction, solveHashcash, stableToRaw, suiToMist, throwIfSimulationFailed, truncateAddress, usdcToRaw, validateAddress, walletExists };
610
+ export { ALL_NAVI_ASSETS, type AutoTopUpResult, BPS_DENOMINATOR, BalanceResponse, BorrowResult, CETUS_USDC_SUI_POOL, CLOCK_ID, COIN_REGISTRY, ClaimRewardsResult, type CoinMeta, ContactManager, DEFAULT_NETWORK, DEFAULT_SAFEGUARD_CONFIG, DepositInfo, ETH_TYPE, EarningsResult, type FeeOperation, FundStatusResult, GAS_RESERVE_MIN, type GasExecutionResult, GasMethod, type GasRequestType, type GasSponsorResponse, type GasStatusResponse, HealthFactorResult, KeypairSigner, LendingAdapter, LendingRates, MIST_PER_SUI, MaxBorrowResult, MaxWithdrawResult, NAVX_TYPE, OUTBOUND_OPS, PayOptions, PayResult, PendingReward, PositionsResult, type ProtocolFeeInfo, RatesResult, RepayResult, STABLE_ASSETS, SUI_DECIMALS, SUI_TYPE, SUPPORTED_ASSETS, type SafeguardConfig, SafeguardEnforcer, SafeguardError, type SafeguardErrorDetails, type SafeguardRule, SaveResult, SendResult, type SimulationResult, type StableAsset, StakeVSuiResult, type SupportedAsset, SwapQuoteResult, SwapResult, type SwapRouteResult, T2000, T2000Error, type T2000ErrorCode, type T2000ErrorData, T2000Options, TOKEN_MAP, TransactionRecord, type TransactionSigner, type TxMetadata, USDC_DECIMALS, USDC_TYPE, USDE_TYPE, USDSUI_TYPE, USDT_TYPE, UnstakeVSuiResult, VOLO_METADATA, VOLO_PKG, VOLO_POOL, VSUI_TYPE, type VoloStats, WAL_TYPE, WBTC_TYPE, WithdrawResult, type ZkLoginProof, ZkLoginSigner, addCollectFeeToTx, buildStakeVSuiTx, buildSwapTx, buildUnstakeVSuiTx, calculateFee, executeAutoTopUp, executeWithGas, exportPrivateKey, findSwapRoute, formatAssetAmount, formatSui, formatUsd, generateKeypair, getAddress, getDecimals, getDecimalsForCoinType, getGasStatus, getRates, getSwapQuote, getVoloStats, keypairFromPrivateKey, loadKey, mapMoveAbortCode, mapWalletError, mistToSui, rawToStable, rawToUsdc, resolveSymbol, resolveTokenType, saveKey, shouldAutoTopUp, simulateTransaction, solveHashcash, stableToRaw, suiToMist, throwIfSimulationFailed, truncateAddress, usdcToRaw, validateAddress, walletExists };
package/dist/index.js CHANGED
@@ -111,6 +111,87 @@ var init_errors = __esm({
111
111
  }
112
112
  });
113
113
 
114
+ // src/token-registry.ts
115
+ function getDecimalsForCoinType(coinType) {
116
+ const direct = BY_TYPE.get(coinType);
117
+ if (direct) return direct.decimals;
118
+ const suffix = coinType.split("::").slice(1).join("::").toUpperCase();
119
+ if (suffix) {
120
+ for (const meta of BY_TYPE.values()) {
121
+ const metaSuffix = meta.type.split("::").slice(1).join("::").toUpperCase();
122
+ if (metaSuffix === suffix) return meta.decimals;
123
+ }
124
+ }
125
+ return 9;
126
+ }
127
+ function resolveSymbol(coinType) {
128
+ const direct = BY_TYPE.get(coinType);
129
+ if (direct) return direct.symbol;
130
+ const suffix = coinType.split("::").slice(1).join("::").toUpperCase();
131
+ if (suffix) {
132
+ for (const meta of BY_TYPE.values()) {
133
+ const metaSuffix = meta.type.split("::").slice(1).join("::").toUpperCase();
134
+ if (metaSuffix === suffix) return meta.symbol;
135
+ }
136
+ }
137
+ return coinType.split("::").pop() ?? coinType;
138
+ }
139
+ function resolveTokenType(nameOrType) {
140
+ if (nameOrType.includes("::")) return nameOrType;
141
+ return TOKEN_MAP[nameOrType] ?? TOKEN_MAP[nameOrType.toUpperCase()] ?? null;
142
+ }
143
+ var COIN_REGISTRY, BY_TYPE, TOKEN_MAP, SUI_TYPE, USDC_TYPE, USDT_TYPE, USDSUI_TYPE, USDE_TYPE, ETH_TYPE, WBTC_TYPE, WAL_TYPE, NAVX_TYPE;
144
+ var init_token_registry = __esm({
145
+ "src/token-registry.ts"() {
146
+ COIN_REGISTRY = {
147
+ SUI: { type: "0x2::sui::SUI", decimals: 9, symbol: "SUI" },
148
+ USDC: { type: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC", decimals: 6, symbol: "USDC" },
149
+ USDT: { type: "0x375f70cf2ae4c00bf37117d0c85a2c71545e6ee05c4a5c7d282cd66a4504b068::usdt::USDT", decimals: 6, symbol: "USDT" },
150
+ USDe: { type: "0x41d587e5336f1c86cad50d38a7136db99333bb9bda91cea4ba69115defeb1402::sui_usde::SUI_USDE", decimals: 6, symbol: "USDe" },
151
+ USDSUI: { type: "0x44f838219cf67b058f3b37907b655f226153c18e33dfcd0da559a844fea9b1c1::usdsui::USDSUI", decimals: 6, symbol: "USDsui" },
152
+ WAL: { type: "0x356a26eb9e012a68958082340d4c4116e7f55615cf27affcff209cf0ae544f59::wal::WAL", decimals: 9, symbol: "WAL" },
153
+ ETH: { type: "0xd0e89b2af5e4910726fbcd8b8dd37bb79b29e5f83f7491bca830e94f7f226d29::eth::ETH", decimals: 8, symbol: "ETH" },
154
+ wBTC: { type: "0x0041f9f9344cac094454cd574e333c4fdb132d7bcc9379bcd4aab485b2a63942::wbtc::WBTC", decimals: 8, symbol: "wBTC" },
155
+ NAVX: { type: "0xa99b8952d4f7d947ea77fe0ecdcc9e5fc0bcab2841d6e2a5aa00c3044e5544b5::navx::NAVX", decimals: 9, symbol: "NAVX" },
156
+ CETUS: { type: "0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS", decimals: 9, symbol: "CETUS" },
157
+ DEEP: { type: "0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP", decimals: 6, symbol: "DEEP" },
158
+ NS: { type: "0x5145494a5f5100e645e4b0aa950fa6b68f614e8c59e17bc5ded3495123a79178::ns::NS", decimals: 6, symbol: "NS" },
159
+ GOLD: { type: "0x9d297676e7a4b771ab023291377b2adfaa4938fb9080b8d12430e4b108b836a9::xaum::XAUM", decimals: 6, symbol: "GOLD" },
160
+ MANIFEST: { type: "0xc466c28d87b3d5cd34f3d5c088751532d71a38d93a8aae4551dd56272cfb4355::manifest::MANIFEST", decimals: 9, symbol: "MANIFEST" },
161
+ vSUI: { type: "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT", decimals: 9, symbol: "vSUI" },
162
+ haSUI: { type: "0xbde4ba4c2e274a60ce15c1cfff9e5c42e136a8bc::hasui::HASUI", decimals: 9, symbol: "haSUI" },
163
+ afSUI: { type: "0xf325ce1300e8dac124071d3152c5c5ee6174914f8bc2161e88329cf579246efc::afsui::AFSUI", decimals: 9, symbol: "afSUI" },
164
+ FDUSD: { type: "0xf16e6b723f242ec745dfd7634ad072c42d5c1d9ac9d62a39c381303eaa57693a::fdusd::FDUSD", decimals: 6, symbol: "FDUSD" },
165
+ AUSD: { type: "0x2053d08c1e2bd02791056171aab0fd12bd7cd7efad2ab8f6b9c8902f14df2ff2::ausd::AUSD", decimals: 6, symbol: "AUSD" },
166
+ BUCK: { type: "0xce7ff77a83ea0cb6fd39bd8748e2ec89a3f41e8efdc3f4eb123e0ca37b184db2::buck::BUCK", decimals: 9, symbol: "BUCK" },
167
+ BLUB: { type: "0xfa7ac3951fdca12c1b6d18eb19e1aa2fbc31e4d45773c8e45b4ded3ef8d83f8a::blub::BLUB", decimals: 9, symbol: "BLUB" },
168
+ SCA: { type: "0x7016aae72cfc67f2fadf55769c0a7dd54291a583b63051a5ed71081cce836ac6::sca::SCA", decimals: 9, symbol: "SCA" },
169
+ TURBOS: { type: "0x5d1f47ea69bb0de31c313d7acf89b890dbb8991ea8e03c6c355171f84bb1ba4a::turbos::TURBOS", decimals: 9, symbol: "TURBOS" }
170
+ };
171
+ BY_TYPE = /* @__PURE__ */ new Map();
172
+ for (const meta of Object.values(COIN_REGISTRY)) {
173
+ BY_TYPE.set(meta.type, meta);
174
+ }
175
+ TOKEN_MAP = (() => {
176
+ const map = {};
177
+ for (const [name, meta] of Object.entries(COIN_REGISTRY)) {
178
+ map[name] = meta.type;
179
+ map[name.toUpperCase()] = meta.type;
180
+ }
181
+ return map;
182
+ })();
183
+ SUI_TYPE = COIN_REGISTRY.SUI.type;
184
+ USDC_TYPE = COIN_REGISTRY.USDC.type;
185
+ USDT_TYPE = COIN_REGISTRY.USDT.type;
186
+ USDSUI_TYPE = COIN_REGISTRY.USDSUI.type;
187
+ USDE_TYPE = COIN_REGISTRY.USDe.type;
188
+ ETH_TYPE = COIN_REGISTRY.ETH.type;
189
+ WBTC_TYPE = COIN_REGISTRY.wBTC.type;
190
+ WAL_TYPE = COIN_REGISTRY.WAL.type;
191
+ NAVX_TYPE = COIN_REGISTRY.NAVX.type;
192
+ }
193
+ });
194
+
114
195
  // src/protocols/volo.ts
115
196
  var volo_exports = {};
116
197
  __export(volo_exports, {
@@ -286,38 +367,11 @@ async function simulateSwap(params) {
286
367
  return { success: false, error: err instanceof Error ? err.message : String(err) };
287
368
  }
288
369
  }
289
- function resolveTokenType(nameOrType) {
290
- if (nameOrType.includes("::")) return nameOrType;
291
- return TOKEN_MAP[nameOrType.toUpperCase()] ?? null;
292
- }
293
- var clientInstance, TOKEN_MAP;
370
+ var clientInstance;
294
371
  var init_cetus_swap = __esm({
295
372
  "src/protocols/cetus-swap.ts"() {
373
+ init_token_registry();
296
374
  clientInstance = null;
297
- TOKEN_MAP = {
298
- SUI: "0x2::sui::SUI",
299
- USDC: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC",
300
- USDT: "0x375f70cf2ae4c00bf37117d0c85a2c71545e6ee05c4a5c7d282cd66a4504b068::usdt::USDT",
301
- CETUS: "0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS",
302
- DEEP: "0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP",
303
- NAVX: "0xa99b8952d4f7d947ea77fe0ecdcc9e5fc0bcab2841d6e2a5aa00c3044e5544b5::navx::NAVX",
304
- vSUI: "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT",
305
- haSUI: "0xbde4ba4c2e274a60ce15c1cfff9e5c42e136a8bc::hasui::HASUI",
306
- afSUI: "0xf325ce1300e8dac124071d3152c5c5ee6174914f8bc2161e88329cf579246efc::afsui::AFSUI",
307
- WAL: "0x356a26eb9e012a68958082340d4c4116e7f55615cf27affcff209cf0ae544f59::wal::WAL",
308
- ETH: "0xd0e89b2af5e4910726fbcd8b8dd37bb79b29e5f83f7491bca830e94f7f226d29::eth::ETH",
309
- wBTC: "0x0041f9f9344cac094454cd574e333c4fdb132d7bcc9379bcd4aab485b2a63942::wbtc::WBTC",
310
- FDUSD: "0xf16e6b723f242ec745dfd7634ad072c42d5c1d9ac9d62a39c381303eaa57693a::fdusd::FDUSD",
311
- AUSD: "0x2053d08c1e2bd02791056171aab0fd12bd7cd7efad2ab8f6b9c8902f14df2ff2::ausd::AUSD",
312
- BUCK: "0xce7ff77a83ea0cb6fd39bd8748e2ec89a3f41e8efdc3f4eb123e0ca37b184db2::buck::BUCK",
313
- USDe: "0x41d587e5336f1c86cad50d38a7136db99333bb9bda91cea4ba69115defeb1402::sui_usde::SUI_USDE",
314
- USDSUI: "0x44f838219cf67b058f3b37907b655f226153c18e33dfcd0da559a844fea9b1c1::usdsui::USDSUI",
315
- MANIFEST: "0xc466c28d87b3d5cd34f3d5c088751532d71a38d93a8aae4551dd56272cfb4355::manifest::MANIFEST",
316
- NS: "0x5145494a5f5100e645e4b0aa950fa6b68f614e8c59e17bc5ded3495123a79178::ns::NS",
317
- BLUB: "0xfa7ac3951fdca12c1b6d18eb19e1aa2fbc31e4d45773c8e45b4ded3ef8d83f8a::blub::BLUB",
318
- SCA: "0x7016aae72cfc67f2fadf55769c0a7dd54291a583b63051a5ed71081cce836ac6::sca::SCA",
319
- TURBOS: "0x5d1f47ea69bb0de31c313d7acf89b890dbb8991ea8e03c6c355171f84bb1ba4a::turbos::TURBOS"
320
- };
321
375
  }
322
376
  });
323
377
 
@@ -720,7 +774,7 @@ async function queryBalance(client, address) {
720
774
  }
721
775
 
722
776
  // src/wallet/history.ts
723
- var SUI_TYPE = "0x2::sui::SUI";
777
+ init_token_registry();
724
778
  var KNOWN_TARGETS = [
725
779
  [/::suilend|::obligation/, "lending"],
726
780
  [/::navi|::incentive_v\d+|::oracle_pro/, "lending"],
@@ -776,9 +830,9 @@ function extractTransferDetails(changes, sender) {
776
830
  const primaryOutflow = outflows.filter((c) => c.coinType !== SUI_TYPE).sort((a, b) => Number(BigInt(a.amount) - BigInt(b.amount)))[0] ?? outflows[0];
777
831
  if (!primaryOutflow) return {};
778
832
  const coinType = primaryOutflow.coinType;
779
- const decimals = coinType.includes("::usdc::") ? 6 : 9;
833
+ const decimals = getDecimalsForCoinType(coinType);
780
834
  const amount = Math.abs(Number(BigInt(primaryOutflow.amount))) / 10 ** decimals;
781
- const asset = coinType === SUI_TYPE ? "SUI" : coinType.includes("::usdc::") ? "USDC" : coinType.split("::").pop() ?? "unknown";
835
+ const asset = resolveSymbol(coinType);
782
836
  const recipientChange = inflows.find((c) => c.coinType === coinType);
783
837
  const recipient = recipientChange ? resolveOwner(recipientChange.owner) ?? void 0 : void 0;
784
838
  return { amount, asset, recipient };
@@ -819,6 +873,9 @@ function classifyAction(targets, commandTypes) {
819
873
  return "transaction";
820
874
  }
821
875
 
876
+ // src/t2000.ts
877
+ init_token_registry();
878
+
822
879
  // src/protocols/protocolFee.ts
823
880
  var FEE_RATES = {
824
881
  save: SAVE_FEE_BPS,
@@ -2310,8 +2367,7 @@ var T2000 = class _T2000 extends EventEmitter {
2310
2367
  if (!toType) throw new T2000Error("ASSET_NOT_SUPPORTED", `Unknown token: ${params.to}. Provide the full coin type.`);
2311
2368
  const byAmountIn = params.byAmountIn ?? true;
2312
2369
  const slippage = Math.min(params.slippage ?? 0.01, 0.05);
2313
- const fromEntry = Object.values(TOKEN_MAP2).includes(fromType) ? Object.entries(SUPPORTED_ASSETS).find(([, v]) => v.type === fromType) : null;
2314
- const fromDecimals = fromEntry ? fromEntry[1].decimals : fromType === "0x2::sui::SUI" ? 9 : 6;
2370
+ const fromDecimals = getDecimalsForCoinType(fromType);
2315
2371
  const rawAmount = BigInt(Math.floor(params.amount * 10 ** fromDecimals));
2316
2372
  const route = await findSwapRoute2({
2317
2373
  walletAddress: this._address,
@@ -2325,6 +2381,13 @@ var T2000 = class _T2000 extends EventEmitter {
2325
2381
  if (route.priceImpact > 0.05) {
2326
2382
  console.warn(`[swap] High price impact: ${(route.priceImpact * 100).toFixed(2)}%`);
2327
2383
  }
2384
+ const toDecimals = getDecimalsForCoinType(toType);
2385
+ let preBalRaw = 0n;
2386
+ try {
2387
+ const preBal = await this.client.getBalance({ owner: this._address, coinType: toType });
2388
+ preBalRaw = BigInt(preBal.totalBalance);
2389
+ } catch {
2390
+ }
2328
2391
  const gasResult = await executeWithGas(this.client, this._signer, async () => {
2329
2392
  const tx = new Transaction();
2330
2393
  tx.setSender(this._address);
@@ -2347,8 +2410,6 @@ var T2000 = class _T2000 extends EventEmitter {
2347
2410
  tx.transferObjects([outputCoin], this._address);
2348
2411
  return tx;
2349
2412
  });
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
2413
  const fromAmount = Number(route.amountIn) / 10 ** fromDecimals;
2353
2414
  let toAmount = Number(route.amountOut) / 10 ** toDecimals;
2354
2415
  const toTypeSuffix = toType.split("::").slice(1).join("::");
@@ -2360,10 +2421,6 @@ var T2000 = class _T2000 extends EventEmitter {
2360
2421
  pollInterval: 400
2361
2422
  });
2362
2423
  const changes = fullTx.balanceChanges ?? [];
2363
- console.error(`[swap] balanceChanges count=${changes.length}, toType=${toType}`);
2364
- for (const c of changes) {
2365
- console.error(`[swap] coinType=${c.coinType} amount=${c.amount} owner=${JSON.stringify(c.owner)}`);
2366
- }
2367
2424
  const received = changes.find((c) => {
2368
2425
  if (BigInt(c.amount) <= 0n) return false;
2369
2426
  const ownerAddr = c.owner?.AddressOwner;
@@ -2374,32 +2431,22 @@ var T2000 = class _T2000 extends EventEmitter {
2374
2431
  if (received) {
2375
2432
  const actual = Number(BigInt(received.amount)) / 10 ** toDecimals;
2376
2433
  if (actual > 0) toAmount = actual;
2377
- console.error(`[swap] Approach 1 success: toAmount=${toAmount}`);
2378
- } else {
2379
- console.error(`[swap] Approach 1: no matching balance change found`);
2380
2434
  }
2381
- } catch (err) {
2382
- console.error(`[swap] Approach 1 failed:`, err);
2435
+ } catch {
2383
2436
  }
2384
2437
  const cetusEstimate = Number(route.amountOut) / 10 ** toDecimals;
2385
2438
  if (Math.abs(toAmount - cetusEstimate) < 1e-3) {
2386
- console.error(`[swap] toAmount still equals Cetus estimate (${cetusEstimate}), trying balance diff`);
2387
2439
  try {
2388
2440
  await new Promise((r) => setTimeout(r, 2e3));
2389
2441
  const postBal = await this.client.getBalance({ owner: this._address, coinType: toType });
2390
2442
  const postRaw = BigInt(postBal.totalBalance);
2391
- const human = Number(postRaw) / 10 ** toDecimals;
2392
- console.error(`[swap] Approach 2: postBalance raw=${postRaw} human=${human}`);
2393
- if (human > toAmount * 10) {
2394
- toAmount = human;
2395
- console.error(`[swap] Approach 2: using total balance as estimate: ${toAmount}`);
2396
- }
2397
- } catch (err) {
2398
- console.error(`[swap] Approach 2 failed:`, err);
2443
+ const delta = Number(postRaw - preBalRaw) / 10 ** toDecimals;
2444
+ if (delta > 0) toAmount = delta;
2445
+ } catch {
2399
2446
  }
2400
2447
  }
2401
- const fromName = fromEntry ? fromEntry[0] : this._resolveTokenName(fromType, params.from);
2402
- const toName = toEntry ? toEntry[0] : this._resolveTokenName(toType, params.to);
2448
+ const fromName = resolveSymbol(fromType);
2449
+ const toName = resolveSymbol(toType);
2403
2450
  const routeDesc = route.routerData.paths?.map((p) => p.provider).filter(Boolean).slice(0, 3).join(" + ") ?? "Cetus Aggregator";
2404
2451
  return {
2405
2452
  success: true,
@@ -2421,8 +2468,7 @@ var T2000 = class _T2000 extends EventEmitter {
2421
2468
  if (!fromType) throw new T2000Error("ASSET_NOT_SUPPORTED", `Unknown token: ${params.from}. Provide the full coin type.`);
2422
2469
  if (!toType) throw new T2000Error("ASSET_NOT_SUPPORTED", `Unknown token: ${params.to}. Provide the full coin type.`);
2423
2470
  const byAmountIn = params.byAmountIn ?? true;
2424
- const fromEntry = Object.values(TOKEN_MAP2).includes(fromType) ? Object.entries(SUPPORTED_ASSETS).find(([, v]) => v.type === fromType) : null;
2425
- const fromDecimals = fromEntry ? fromEntry[1].decimals : fromType === "0x2::sui::SUI" ? 9 : 6;
2471
+ const fromDecimals = getDecimalsForCoinType(fromType);
2426
2472
  const rawAmount = BigInt(Math.floor(params.amount * 10 ** fromDecimals));
2427
2473
  const route = await findSwapRoute2({
2428
2474
  walletAddress: this._address,
@@ -2433,8 +2479,7 @@ var T2000 = class _T2000 extends EventEmitter {
2433
2479
  });
2434
2480
  if (!route) throw new T2000Error("SWAP_NO_ROUTE", `No swap route found for ${params.from} -> ${params.to}.`);
2435
2481
  if (route.insufficientLiquidity) throw new T2000Error("SWAP_NO_ROUTE", `Insufficient liquidity for ${params.from} -> ${params.to}.`);
2436
- const toEntry = Object.entries(SUPPORTED_ASSETS).find(([, v]) => v.type === toType);
2437
- const toDecimals = toEntry ? toEntry[1].decimals : toType === "0x2::sui::SUI" ? 9 : 6;
2482
+ const toDecimals = getDecimalsForCoinType(toType);
2438
2483
  const fromAmount = Number(route.amountIn) / 10 ** fromDecimals;
2439
2484
  const toAmount = Number(route.amountOut) / 10 ** toDecimals;
2440
2485
  const routeDesc = route.routerData.paths?.map((p) => p.provider).filter(Boolean).slice(0, 3).join(" + ") ?? "Cetus Aggregator";
@@ -2810,12 +2855,6 @@ var T2000 = class _T2000 extends EventEmitter {
2810
2855
  }
2811
2856
  return all;
2812
2857
  }
2813
- _resolveTokenName(coinType, fallback) {
2814
- const entry = Object.entries(SUPPORTED_ASSETS).find(([, v]) => v.type === coinType);
2815
- if (entry) return entry[0];
2816
- const suffix = coinType.split("::").pop();
2817
- return suffix && suffix !== coinType ? suffix : fallback;
2818
- }
2819
2858
  _mergeCoinsInTx(tx, coins) {
2820
2859
  if (coins.length === 0) throw new T2000Error("INSUFFICIENT_BALANCE", "No coins to merge");
2821
2860
  const primary = tx.object(coins[0].coinObjectId);
@@ -3271,6 +3310,7 @@ function parseMoveAbort(errorStr) {
3271
3310
  }
3272
3311
 
3273
3312
  // src/swap-quote.ts
3313
+ init_token_registry();
3274
3314
  async function getSwapQuote(params) {
3275
3315
  const { findSwapRoute: findSwapRoute2, resolveTokenType: resolveTokenType2, TOKEN_MAP: TOKEN_MAP2 } = await Promise.resolve().then(() => (init_cetus_swap(), cetus_swap_exports));
3276
3316
  const fromType = resolveTokenType2(params.from);
@@ -3278,8 +3318,7 @@ async function getSwapQuote(params) {
3278
3318
  if (!fromType) throw new Error(`Unknown token: ${params.from}. Provide the full coin type.`);
3279
3319
  if (!toType) throw new Error(`Unknown token: ${params.to}. Provide the full coin type.`);
3280
3320
  const byAmountIn = params.byAmountIn ?? true;
3281
- const fromEntry = Object.values(TOKEN_MAP2).includes(fromType) ? Object.entries(SUPPORTED_ASSETS).find(([, v]) => v.type === fromType) : null;
3282
- const fromDecimals = fromEntry ? fromEntry[1].decimals : fromType === "0x2::sui::SUI" ? 9 : 6;
3321
+ const fromDecimals = getDecimalsForCoinType(fromType);
3283
3322
  const rawAmount = BigInt(Math.floor(params.amount * 10 ** fromDecimals));
3284
3323
  const route = await findSwapRoute2({
3285
3324
  walletAddress: params.walletAddress,
@@ -3290,8 +3329,7 @@ async function getSwapQuote(params) {
3290
3329
  });
3291
3330
  if (!route) throw new Error(`No swap route found for ${params.from} -> ${params.to}.`);
3292
3331
  if (route.insufficientLiquidity) throw new Error(`Insufficient liquidity for ${params.from} -> ${params.to}.`);
3293
- const toEntry = Object.entries(SUPPORTED_ASSETS).find(([, v]) => v.type === toType);
3294
- const toDecimals = toEntry ? toEntry[1].decimals : toType === "0x2::sui::SUI" ? 9 : 6;
3332
+ const toDecimals = getDecimalsForCoinType(toType);
3295
3333
  const fromAmount = Number(route.amountIn) / 10 ** fromDecimals;
3296
3334
  const toAmount = Number(route.amountOut) / 10 ** toDecimals;
3297
3335
  const routeDesc = route.routerData.paths?.map((p) => p.provider).filter(Boolean).slice(0, 3).join(" + ") ?? "Cetus Aggregator";
@@ -3307,8 +3345,9 @@ async function getSwapQuote(params) {
3307
3345
 
3308
3346
  // src/index.ts
3309
3347
  init_cetus_swap();
3348
+ init_token_registry();
3310
3349
  init_volo();
3311
3350
 
3312
- export { ALL_NAVI_ASSETS, BPS_DENOMINATOR, CETUS_USDC_SUI_POOL, CLOCK_ID, ContactManager, DEFAULT_NETWORK, DEFAULT_SAFEGUARD_CONFIG, GAS_RESERVE_MIN, KeypairSigner, MIST_PER_SUI, NaviAdapter, OUTBOUND_OPS, ProtocolRegistry, STABLE_ASSETS, SUI_DECIMALS, SUPPORTED_ASSETS, SafeguardEnforcer, SafeguardError, T2000, T2000Error, TOKEN_MAP, USDC_DECIMALS, VOLO_METADATA, VOLO_PKG, VOLO_POOL, VSUI_TYPE, ZkLoginSigner, addCollectFeeToTx, allDescriptors, buildStakeVSuiTx, buildSwapTx, buildUnstakeVSuiTx, calculateFee, executeAutoTopUp, executeWithGas, exportPrivateKey, findSwapRoute, formatAssetAmount, formatSui, formatUsd, generateKeypair, getAddress, getDecimals, getGasStatus, getRates, getSwapQuote, getVoloStats, keypairFromPrivateKey, loadKey, mapMoveAbortCode, mapWalletError, mistToSui, naviDescriptor, rawToStable, rawToUsdc, resolveTokenType, saveKey, shouldAutoTopUp, simulateTransaction, solveHashcash, stableToRaw, suiToMist, throwIfSimulationFailed, truncateAddress, usdcToRaw, validateAddress, walletExists };
3351
+ export { ALL_NAVI_ASSETS, BPS_DENOMINATOR, CETUS_USDC_SUI_POOL, CLOCK_ID, COIN_REGISTRY, ContactManager, DEFAULT_NETWORK, DEFAULT_SAFEGUARD_CONFIG, ETH_TYPE, GAS_RESERVE_MIN, KeypairSigner, MIST_PER_SUI, NAVX_TYPE, NaviAdapter, OUTBOUND_OPS, ProtocolRegistry, STABLE_ASSETS, SUI_DECIMALS, SUI_TYPE, SUPPORTED_ASSETS, SafeguardEnforcer, SafeguardError, T2000, T2000Error, TOKEN_MAP, USDC_DECIMALS, USDC_TYPE, USDE_TYPE, USDSUI_TYPE, USDT_TYPE, VOLO_METADATA, VOLO_PKG, VOLO_POOL, VSUI_TYPE, WAL_TYPE, WBTC_TYPE, ZkLoginSigner, addCollectFeeToTx, allDescriptors, buildStakeVSuiTx, buildSwapTx, buildUnstakeVSuiTx, calculateFee, executeAutoTopUp, executeWithGas, exportPrivateKey, findSwapRoute, formatAssetAmount, formatSui, formatUsd, generateKeypair, getAddress, getDecimals, getDecimalsForCoinType, getGasStatus, getRates, getSwapQuote, getVoloStats, keypairFromPrivateKey, loadKey, mapMoveAbortCode, mapWalletError, mistToSui, naviDescriptor, rawToStable, rawToUsdc, resolveSymbol, resolveTokenType, saveKey, shouldAutoTopUp, simulateTransaction, solveHashcash, stableToRaw, suiToMist, throwIfSimulationFailed, truncateAddress, usdcToRaw, validateAddress, walletExists };
3313
3352
  //# sourceMappingURL=index.js.map
3314
3353
  //# sourceMappingURL=index.js.map