@t2000/sdk 5.3.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/browser.cjs +11 -0
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.js +11 -0
- package/dist/browser.js.map +1 -1
- package/dist/index.cjs +23 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -2
- package/dist/index.d.ts +10 -2
- package/dist/index.js +23 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -239,8 +239,8 @@ declare class T2000 extends EventEmitter<T2000Events> {
|
|
|
239
239
|
/**
|
|
240
240
|
* [SPEC_AGENTIC_STACK P1 / SDK F2 — 2026-05-25; refreshed S.342 / 2026-05-26]
|
|
241
241
|
* Preferred alias of `deposit()`. Was introduced to mirror the v3 `t2000 fund`
|
|
242
|
-
* CLI command; the v4 CLI surface is `t2
|
|
243
|
-
* S.
|
|
242
|
+
* CLI command; the v4 CLI surface is `t2 fund` (renamed back from the
|
|
243
|
+
* interim `t2 receive` in S.464). `deposit()` stays as the canonical method name for
|
|
244
244
|
* back-compat; `fund()` stays as a programmatic alias for audric + other
|
|
245
245
|
* SDK consumers that prefer the verb.
|
|
246
246
|
*/
|
|
@@ -828,6 +828,14 @@ declare function getSwapQuote(params: {
|
|
|
828
828
|
* keep access to the full provider set including Pyth-dependent pools.
|
|
829
829
|
*/
|
|
830
830
|
providers?: string[];
|
|
831
|
+
/**
|
|
832
|
+
* [2.11] On-chain-resolved decimals for `from` / `to`, supplied by callers
|
|
833
|
+
* that hold a client (e.g. `T2000.swapQuote`). When omitted (standalone /
|
|
834
|
+
* sponsored callers), falls back to the registry — correct for registry
|
|
835
|
+
* tokens, a 9-decimal guess for an unknown coin type.
|
|
836
|
+
*/
|
|
837
|
+
fromDecimals?: number;
|
|
838
|
+
toDecimals?: number;
|
|
831
839
|
}): Promise<SwapQuoteResult>;
|
|
832
840
|
|
|
833
841
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -239,8 +239,8 @@ declare class T2000 extends EventEmitter<T2000Events> {
|
|
|
239
239
|
/**
|
|
240
240
|
* [SPEC_AGENTIC_STACK P1 / SDK F2 — 2026-05-25; refreshed S.342 / 2026-05-26]
|
|
241
241
|
* Preferred alias of `deposit()`. Was introduced to mirror the v3 `t2000 fund`
|
|
242
|
-
* CLI command; the v4 CLI surface is `t2
|
|
243
|
-
* S.
|
|
242
|
+
* CLI command; the v4 CLI surface is `t2 fund` (renamed back from the
|
|
243
|
+
* interim `t2 receive` in S.464). `deposit()` stays as the canonical method name for
|
|
244
244
|
* back-compat; `fund()` stays as a programmatic alias for audric + other
|
|
245
245
|
* SDK consumers that prefer the verb.
|
|
246
246
|
*/
|
|
@@ -828,6 +828,14 @@ declare function getSwapQuote(params: {
|
|
|
828
828
|
* keep access to the full provider set including Pyth-dependent pools.
|
|
829
829
|
*/
|
|
830
830
|
providers?: string[];
|
|
831
|
+
/**
|
|
832
|
+
* [2.11] On-chain-resolved decimals for `from` / `to`, supplied by callers
|
|
833
|
+
* that hold a client (e.g. `T2000.swapQuote`). When omitted (standalone /
|
|
834
|
+
* sponsored callers), falls back to the registry — correct for registry
|
|
835
|
+
* tokens, a 9-decimal guess for an unknown coin type.
|
|
836
|
+
*/
|
|
837
|
+
fromDecimals?: number;
|
|
838
|
+
toDecimals?: number;
|
|
831
839
|
}): Promise<SwapQuoteResult>;
|
|
832
840
|
|
|
833
841
|
/**
|
package/dist/index.js
CHANGED
|
@@ -133,6 +133,7 @@ __export(token_registry_exports, {
|
|
|
133
133
|
getCoinMeta: () => getCoinMeta,
|
|
134
134
|
getDecimalsForCoinType: () => getDecimalsForCoinType,
|
|
135
135
|
isInRegistry: () => isInRegistry,
|
|
136
|
+
resolveCoinDecimals: () => resolveCoinDecimals,
|
|
136
137
|
resolveSymbol: () => resolveSymbol,
|
|
137
138
|
resolveTokenType: () => resolveTokenType
|
|
138
139
|
});
|
|
@@ -154,6 +155,16 @@ function getDecimalsForCoinType(coinType) {
|
|
|
154
155
|
}
|
|
155
156
|
return 9;
|
|
156
157
|
}
|
|
158
|
+
async function resolveCoinDecimals(client, coinType) {
|
|
159
|
+
if (isInRegistry(coinType)) return getDecimalsForCoinType(coinType);
|
|
160
|
+
try {
|
|
161
|
+
const res = await client.core.getCoinMetadata({ coinType });
|
|
162
|
+
const d = res?.metadata?.decimals ?? res?.decimals;
|
|
163
|
+
if (typeof d === "number" && Number.isFinite(d)) return d;
|
|
164
|
+
} catch {
|
|
165
|
+
}
|
|
166
|
+
return getDecimalsForCoinType(coinType);
|
|
167
|
+
}
|
|
157
168
|
function resolveSymbol(coinType) {
|
|
158
169
|
const direct = BY_TYPE.get(coinType);
|
|
159
170
|
if (direct) return direct.symbol;
|
|
@@ -648,7 +659,7 @@ async function getSwapQuote(params) {
|
|
|
648
659
|
);
|
|
649
660
|
}
|
|
650
661
|
const byAmountIn = params.byAmountIn ?? true;
|
|
651
|
-
const fromDecimals = getDecimalsForCoinType(fromType);
|
|
662
|
+
const fromDecimals = params.fromDecimals ?? getDecimalsForCoinType(fromType);
|
|
652
663
|
const rawAmount = BigInt(Math.floor(params.amount * 10 ** fromDecimals));
|
|
653
664
|
const route = await findSwapRoute2({
|
|
654
665
|
walletAddress: params.walletAddress,
|
|
@@ -662,7 +673,7 @@ async function getSwapQuote(params) {
|
|
|
662
673
|
if (route.insufficientLiquidity) {
|
|
663
674
|
throw new T2000Error("SWAP_FAILED", `Insufficient liquidity for ${params.from} -> ${params.to}.`);
|
|
664
675
|
}
|
|
665
|
-
const toDecimals = getDecimalsForCoinType(toType);
|
|
676
|
+
const toDecimals = params.toDecimals ?? getDecimalsForCoinType(toType);
|
|
666
677
|
const fromAmount = Number(route.amountIn) / 10 ** fromDecimals;
|
|
667
678
|
const toAmount = Number(route.amountOut) / 10 ** toDecimals;
|
|
668
679
|
const routeDesc = route.routerData.paths?.map((p) => p.provider).filter(Boolean).slice(0, 3).join(" + ") ?? "Cetus Aggregator";
|
|
@@ -2039,7 +2050,7 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
2039
2050
|
if (!toType) throw new T2000Error("ASSET_NOT_SUPPORTED", `Unknown token: ${params.to}. Provide the full coin type.`);
|
|
2040
2051
|
const byAmountIn = params.byAmountIn ?? true;
|
|
2041
2052
|
const slippage = Math.min(params.slippage ?? 0.01, 0.05);
|
|
2042
|
-
const fromDecimals =
|
|
2053
|
+
const fromDecimals = await resolveCoinDecimals(this.client, fromType);
|
|
2043
2054
|
const rawAmount = BigInt(Math.floor(params.amount * 10 ** fromDecimals));
|
|
2044
2055
|
const route = await findSwapRoute2({
|
|
2045
2056
|
walletAddress: this._address,
|
|
@@ -2053,7 +2064,7 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
2053
2064
|
if (route.priceImpact > 0.05) {
|
|
2054
2065
|
console.warn(`[swap] High price impact: ${(route.priceImpact * 100).toFixed(2)}%`);
|
|
2055
2066
|
}
|
|
2056
|
-
const toDecimals =
|
|
2067
|
+
const toDecimals = await resolveCoinDecimals(this.client, toType);
|
|
2057
2068
|
let preBalRaw = 0n;
|
|
2058
2069
|
try {
|
|
2059
2070
|
const preBal = await this.client.core.getBalance({ owner: this._address, coinType: toType });
|
|
@@ -2146,13 +2157,18 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
2146
2157
|
*/
|
|
2147
2158
|
async swapQuote(params) {
|
|
2148
2159
|
const { getSwapQuote: getSwapQuote2 } = await Promise.resolve().then(() => (init_swap_quote(), swap_quote_exports));
|
|
2160
|
+
const { resolveTokenType: resolveTokenType2 } = await Promise.resolve().then(() => (init_cetus_swap(), cetus_swap_exports));
|
|
2161
|
+
const fromType = resolveTokenType2(params.from);
|
|
2162
|
+
const toType = resolveTokenType2(params.to);
|
|
2149
2163
|
return getSwapQuote2({
|
|
2150
2164
|
walletAddress: this._address,
|
|
2151
2165
|
from: params.from,
|
|
2152
2166
|
to: params.to,
|
|
2153
2167
|
amount: params.amount,
|
|
2154
2168
|
byAmountIn: params.byAmountIn,
|
|
2155
|
-
providers: params.providers
|
|
2169
|
+
providers: params.providers,
|
|
2170
|
+
fromDecimals: fromType ? await resolveCoinDecimals(this.client, fromType) : void 0,
|
|
2171
|
+
toDecimals: toType ? await resolveCoinDecimals(this.client, toType) : void 0
|
|
2156
2172
|
});
|
|
2157
2173
|
}
|
|
2158
2174
|
// -- Wallet --
|
|
@@ -2288,8 +2304,8 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
2288
2304
|
/**
|
|
2289
2305
|
* [SPEC_AGENTIC_STACK P1 / SDK F2 — 2026-05-25; refreshed S.342 / 2026-05-26]
|
|
2290
2306
|
* Preferred alias of `deposit()`. Was introduced to mirror the v3 `t2000 fund`
|
|
2291
|
-
* CLI command; the v4 CLI surface is `t2
|
|
2292
|
-
* S.
|
|
2307
|
+
* CLI command; the v4 CLI surface is `t2 fund` (renamed back from the
|
|
2308
|
+
* interim `t2 receive` in S.464). `deposit()` stays as the canonical method name for
|
|
2293
2309
|
* back-compat; `fund()` stays as a programmatic alias for audric + other
|
|
2294
2310
|
* SDK consumers that prefer the verb.
|
|
2295
2311
|
*/
|