@t2000/sdk 5.2.0 → 5.4.0

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 CHANGED
@@ -139,6 +139,7 @@ __export(token_registry_exports, {
139
139
  getCoinMeta: () => getCoinMeta,
140
140
  getDecimalsForCoinType: () => getDecimalsForCoinType,
141
141
  isInRegistry: () => isInRegistry,
142
+ resolveCoinDecimals: () => resolveCoinDecimals,
142
143
  resolveSymbol: () => resolveSymbol,
143
144
  resolveTokenType: () => resolveTokenType
144
145
  });
@@ -160,6 +161,16 @@ function getDecimalsForCoinType(coinType) {
160
161
  }
161
162
  return 9;
162
163
  }
164
+ async function resolveCoinDecimals(client, coinType) {
165
+ if (isInRegistry(coinType)) return getDecimalsForCoinType(coinType);
166
+ try {
167
+ const res = await client.core.getCoinMetadata({ coinType });
168
+ const d = res?.metadata?.decimals ?? res?.decimals;
169
+ if (typeof d === "number" && Number.isFinite(d)) return d;
170
+ } catch {
171
+ }
172
+ return getDecimalsForCoinType(coinType);
173
+ }
163
174
  function resolveSymbol(coinType) {
164
175
  const direct = BY_TYPE.get(coinType);
165
176
  if (direct) return direct.symbol;
@@ -654,7 +665,7 @@ async function getSwapQuote(params) {
654
665
  );
655
666
  }
656
667
  const byAmountIn = params.byAmountIn ?? true;
657
- const fromDecimals = getDecimalsForCoinType(fromType);
668
+ const fromDecimals = params.fromDecimals ?? getDecimalsForCoinType(fromType);
658
669
  const rawAmount = BigInt(Math.floor(params.amount * 10 ** fromDecimals));
659
670
  const route = await findSwapRoute2({
660
671
  walletAddress: params.walletAddress,
@@ -668,7 +679,7 @@ async function getSwapQuote(params) {
668
679
  if (route.insufficientLiquidity) {
669
680
  throw new exports.T2000Error("SWAP_FAILED", `Insufficient liquidity for ${params.from} -> ${params.to}.`);
670
681
  }
671
- const toDecimals = getDecimalsForCoinType(toType);
682
+ const toDecimals = params.toDecimals ?? getDecimalsForCoinType(toType);
672
683
  const fromAmount = Number(route.amountIn) / 10 ** fromDecimals;
673
684
  const toAmount = Number(route.amountOut) / 10 ** toDecimals;
674
685
  const routeDesc = route.routerData.paths?.map((p) => p.provider).filter(Boolean).slice(0, 3).join(" + ") ?? "Cetus Aggregator";
@@ -2045,7 +2056,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
2045
2056
  if (!toType) throw new exports.T2000Error("ASSET_NOT_SUPPORTED", `Unknown token: ${params.to}. Provide the full coin type.`);
2046
2057
  const byAmountIn = params.byAmountIn ?? true;
2047
2058
  const slippage = Math.min(params.slippage ?? 0.01, 0.05);
2048
- const fromDecimals = getDecimalsForCoinType(fromType);
2059
+ const fromDecimals = await resolveCoinDecimals(this.client, fromType);
2049
2060
  const rawAmount = BigInt(Math.floor(params.amount * 10 ** fromDecimals));
2050
2061
  const route = await findSwapRoute2({
2051
2062
  walletAddress: this._address,
@@ -2059,7 +2070,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
2059
2070
  if (route.priceImpact > 0.05) {
2060
2071
  console.warn(`[swap] High price impact: ${(route.priceImpact * 100).toFixed(2)}%`);
2061
2072
  }
2062
- const toDecimals = getDecimalsForCoinType(toType);
2073
+ const toDecimals = await resolveCoinDecimals(this.client, toType);
2063
2074
  let preBalRaw = 0n;
2064
2075
  try {
2065
2076
  const preBal = await this.client.core.getBalance({ owner: this._address, coinType: toType });
@@ -2152,13 +2163,18 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
2152
2163
  */
2153
2164
  async swapQuote(params) {
2154
2165
  const { getSwapQuote: getSwapQuote2 } = await Promise.resolve().then(() => (init_swap_quote(), swap_quote_exports));
2166
+ const { resolveTokenType: resolveTokenType2 } = await Promise.resolve().then(() => (init_cetus_swap(), cetus_swap_exports));
2167
+ const fromType = resolveTokenType2(params.from);
2168
+ const toType = resolveTokenType2(params.to);
2155
2169
  return getSwapQuote2({
2156
2170
  walletAddress: this._address,
2157
2171
  from: params.from,
2158
2172
  to: params.to,
2159
2173
  amount: params.amount,
2160
2174
  byAmountIn: params.byAmountIn,
2161
- providers: params.providers
2175
+ providers: params.providers,
2176
+ fromDecimals: fromType ? await resolveCoinDecimals(this.client, fromType) : void 0,
2177
+ toDecimals: toType ? await resolveCoinDecimals(this.client, toType) : void 0
2162
2178
  });
2163
2179
  }
2164
2180
  // -- Wallet --
@@ -2294,8 +2310,8 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
2294
2310
  /**
2295
2311
  * [SPEC_AGENTIC_STACK P1 / SDK F2 — 2026-05-25; refreshed S.342 / 2026-05-26]
2296
2312
  * Preferred alias of `deposit()`. Was introduced to mirror the v3 `t2000 fund`
2297
- * CLI command; the v4 CLI surface is `t2 receive` (deleted `fund` in the
2298
- * S.332 bulk cut). `deposit()` stays as the canonical method name for
2313
+ * CLI command; the v4 CLI surface is `t2 fund` (renamed back from the
2314
+ * interim `t2 receive` in S.464). `deposit()` stays as the canonical method name for
2299
2315
  * back-compat; `fund()` stays as a programmatic alias for audric + other
2300
2316
  * SDK consumers that prefer the verb.
2301
2317
  */