@t2000/sdk 0.20.0 → 0.20.1

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
@@ -3169,6 +3169,41 @@ function parseMoveAbort(errorStr) {
3169
3169
  return { reason: errorStr };
3170
3170
  }
3171
3171
 
3172
+ // src/swap-quote.ts
3173
+ async function getSwapQuote(params) {
3174
+ const { findSwapRoute: findSwapRoute2, resolveTokenType: resolveTokenType2, TOKEN_MAP: TOKEN_MAP2 } = await Promise.resolve().then(() => (init_cetus_swap(), cetus_swap_exports));
3175
+ const fromType = resolveTokenType2(params.from);
3176
+ const toType = resolveTokenType2(params.to);
3177
+ if (!fromType) throw new Error(`Unknown token: ${params.from}. Provide the full coin type.`);
3178
+ if (!toType) throw new Error(`Unknown token: ${params.to}. Provide the full coin type.`);
3179
+ const byAmountIn = params.byAmountIn ?? true;
3180
+ const fromEntry = Object.values(TOKEN_MAP2).includes(fromType) ? Object.entries(SUPPORTED_ASSETS).find(([, v]) => v.type === fromType) : null;
3181
+ const fromDecimals = fromEntry ? fromEntry[1].decimals : fromType === "0x2::sui::SUI" ? 9 : 6;
3182
+ const rawAmount = BigInt(Math.floor(params.amount * 10 ** fromDecimals));
3183
+ const route = await findSwapRoute2({
3184
+ walletAddress: params.walletAddress,
3185
+ from: fromType,
3186
+ to: toType,
3187
+ amount: rawAmount,
3188
+ byAmountIn
3189
+ });
3190
+ if (!route) throw new Error(`No swap route found for ${params.from} -> ${params.to}.`);
3191
+ if (route.insufficientLiquidity) throw new Error(`Insufficient liquidity for ${params.from} -> ${params.to}.`);
3192
+ const toEntry = Object.entries(SUPPORTED_ASSETS).find(([, v]) => v.type === toType);
3193
+ const toDecimals = toEntry ? toEntry[1].decimals : toType === "0x2::sui::SUI" ? 9 : 6;
3194
+ const fromAmount = Number(route.amountIn) / 10 ** fromDecimals;
3195
+ const toAmount = Number(route.amountOut) / 10 ** toDecimals;
3196
+ const routeDesc = route.routerData.paths?.map((p) => p.provider).filter(Boolean).slice(0, 3).join(" + ") ?? "Cetus Aggregator";
3197
+ return {
3198
+ fromToken: params.from,
3199
+ toToken: params.to,
3200
+ fromAmount,
3201
+ toAmount,
3202
+ priceImpact: route.priceImpact,
3203
+ route: routeDesc
3204
+ };
3205
+ }
3206
+
3172
3207
  exports.BPS_DENOMINATOR = BPS_DENOMINATOR;
3173
3208
  exports.CETUS_USDC_SUI_POOL = CETUS_USDC_SUI_POOL;
3174
3209
  exports.CLOCK_ID = CLOCK_ID;
@@ -3203,6 +3238,7 @@ exports.getAddress = getAddress;
3203
3238
  exports.getDecimals = getDecimals;
3204
3239
  exports.getGasStatus = getGasStatus;
3205
3240
  exports.getRates = getRates;
3241
+ exports.getSwapQuote = getSwapQuote;
3206
3242
  exports.keypairFromPrivateKey = keypairFromPrivateKey;
3207
3243
  exports.loadKey = loadKey;
3208
3244
  exports.mapMoveAbortCode = mapMoveAbortCode;