@t2000/sdk 0.8.5 → 0.8.6

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
@@ -237,8 +237,8 @@ declare function getDecimals(asset: SupportedAsset): number;
237
237
  declare function formatUsd(amount: number): string;
238
238
  declare function formatSui(amount: number): string;
239
239
  /**
240
- * Case-insensitive lookup against SUPPORTED_ASSETS keys.
241
- * 'usde' → 'USDe', 'usdsui' → 'USDsui', 'usdc' → 'USDC'.
240
+ * Case-insensitive lookup against SUPPORTED_ASSETS keys AND display names.
241
+ * 'usde' → 'USDe', 'suiusde' → 'USDe', 'suiusdt' → 'USDT', 'usdsui' → 'USDsui'.
242
242
  * Returns the original input if not found so downstream validation can reject it.
243
243
  */
244
244
  declare function normalizeAsset(input: string): string;
@@ -282,7 +282,7 @@ declare function simulateTransaction(client: SuiJsonRpcClient, tx: Transaction,
282
282
  declare function throwIfSimulationFailed(sim: SimulationResult): void;
283
283
 
284
284
  declare function getPoolPrice(client: SuiJsonRpcClient): Promise<number>;
285
- declare function getSwapQuote(client: SuiJsonRpcClient, fromAsset: 'USDC' | 'SUI', toAsset: 'USDC' | 'SUI', amount: number): Promise<{
285
+ declare function getSwapQuote(client: SuiJsonRpcClient, fromAsset: string, toAsset: string, amount: number): Promise<{
286
286
  expectedOutput: number;
287
287
  priceImpact: number;
288
288
  poolPrice: number;
package/dist/index.d.ts CHANGED
@@ -237,8 +237,8 @@ declare function getDecimals(asset: SupportedAsset): number;
237
237
  declare function formatUsd(amount: number): string;
238
238
  declare function formatSui(amount: number): string;
239
239
  /**
240
- * Case-insensitive lookup against SUPPORTED_ASSETS keys.
241
- * 'usde' → 'USDe', 'usdsui' → 'USDsui', 'usdc' → 'USDC'.
240
+ * Case-insensitive lookup against SUPPORTED_ASSETS keys AND display names.
241
+ * 'usde' → 'USDe', 'suiusde' → 'USDe', 'suiusdt' → 'USDT', 'usdsui' → 'USDsui'.
242
242
  * Returns the original input if not found so downstream validation can reject it.
243
243
  */
244
244
  declare function normalizeAsset(input: string): string;
@@ -282,7 +282,7 @@ declare function simulateTransaction(client: SuiJsonRpcClient, tx: Transaction,
282
282
  declare function throwIfSimulationFailed(sim: SimulationResult): void;
283
283
 
284
284
  declare function getPoolPrice(client: SuiJsonRpcClient): Promise<number>;
285
- declare function getSwapQuote(client: SuiJsonRpcClient, fromAsset: 'USDC' | 'SUI', toAsset: 'USDC' | 'SUI', amount: number): Promise<{
285
+ declare function getSwapQuote(client: SuiJsonRpcClient, fromAsset: string, toAsset: string, amount: number): Promise<{
286
286
  expectedOutput: number;
287
287
  priceImpact: number;
288
288
  poolPrice: number;
package/dist/index.js CHANGED
@@ -276,9 +276,13 @@ function formatSui(amount) {
276
276
  if (amount < 1e-3) return `${amount.toFixed(6)} SUI`;
277
277
  return `${amount.toFixed(3)} SUI`;
278
278
  }
279
- var ASSET_LOOKUP = new Map(
280
- Object.keys(SUPPORTED_ASSETS).map((k) => [k.toUpperCase(), k])
281
- );
279
+ var ASSET_LOOKUP = /* @__PURE__ */ new Map();
280
+ for (const [key, info] of Object.entries(SUPPORTED_ASSETS)) {
281
+ ASSET_LOOKUP.set(key.toUpperCase(), key);
282
+ if (info.displayName && info.displayName.toUpperCase() !== key.toUpperCase()) {
283
+ ASSET_LOOKUP.set(info.displayName.toUpperCase(), key);
284
+ }
285
+ }
282
286
  function normalizeAsset(input) {
283
287
  return ASSET_LOOKUP.get(input.toUpperCase()) ?? input;
284
288
  }
@@ -1403,6 +1407,9 @@ async function buildSwapTx(params) {
1403
1407
  const { client, address, fromAsset, toAsset, amount, maxSlippageBps = DEFAULT_SLIPPAGE_BPS } = params;
1404
1408
  const fromInfo = SUPPORTED_ASSETS[fromAsset];
1405
1409
  const toInfo = SUPPORTED_ASSETS[toAsset];
1410
+ if (!fromInfo || !toInfo) {
1411
+ throw new T2000Error("ASSET_NOT_SUPPORTED", `Swap pair ${fromAsset}/${toAsset} is not supported`);
1412
+ }
1406
1413
  const rawAmount = BigInt(Math.floor(amount * 10 ** fromInfo.decimals));
1407
1414
  const aggClient = createAggregatorClient(client, address);
1408
1415
  const result = await aggClient.findRouters({
@@ -1455,6 +1462,9 @@ async function getPoolPrice(client) {
1455
1462
  async function getSwapQuote(client, fromAsset, toAsset, amount) {
1456
1463
  const fromInfo = SUPPORTED_ASSETS[fromAsset];
1457
1464
  const toInfo = SUPPORTED_ASSETS[toAsset];
1465
+ if (!fromInfo || !toInfo) {
1466
+ throw new T2000Error("ASSET_NOT_SUPPORTED", `Swap pair ${fromAsset}/${toAsset} is not supported`);
1467
+ }
1458
1468
  const rawAmount = BigInt(Math.floor(amount * 10 ** fromInfo.decimals));
1459
1469
  const poolPrice = await getPoolPrice(client);
1460
1470
  try {
@@ -1506,19 +1516,14 @@ var CetusAdapter = class {
1506
1516
  this.client = client;
1507
1517
  }
1508
1518
  async getQuote(from, to, amount) {
1509
- return getSwapQuote(
1510
- this.client,
1511
- from.toUpperCase(),
1512
- to.toUpperCase(),
1513
- amount
1514
- );
1519
+ return getSwapQuote(this.client, from, to, amount);
1515
1520
  }
1516
1521
  async buildSwapTx(address, from, to, amount, maxSlippageBps) {
1517
1522
  const result = await buildSwapTx({
1518
1523
  client: this.client,
1519
1524
  address,
1520
- fromAsset: from.toUpperCase(),
1521
- toAsset: to.toUpperCase(),
1525
+ fromAsset: from,
1526
+ toAsset: to,
1522
1527
  amount,
1523
1528
  maxSlippageBps
1524
1529
  });