@cetusprotocol/aggregator-sdk 1.2.0 → 1.3.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.mjs CHANGED
@@ -2845,37 +2845,61 @@ var TransactionErrorCode = /* @__PURE__ */ ((TransactionErrorCode2) => {
2845
2845
  TransactionErrorCode2["MissAftermathLpSupplyType"] = `MissAftermathLpSupplyType`;
2846
2846
  return TransactionErrorCode2;
2847
2847
  })(TransactionErrorCode || {});
2848
+ var AggregatorError = class _AggregatorError extends Error {
2849
+ constructor(message, errorCode) {
2850
+ super(message);
2851
+ this.message = message;
2852
+ this.errorCode = errorCode;
2853
+ }
2854
+ static isAggregatorErrorCode(e, code) {
2855
+ return e instanceof _AggregatorError && e.errorCode === code;
2856
+ }
2857
+ };
2848
2858
  var AggregatorServerErrorCode = /* @__PURE__ */ ((AggregatorServerErrorCode2) => {
2849
2859
  AggregatorServerErrorCode2[AggregatorServerErrorCode2["NumberTooLarge"] = 1e3] = "NumberTooLarge";
2850
2860
  AggregatorServerErrorCode2[AggregatorServerErrorCode2["RateLimitExceeded"] = 1001] = "RateLimitExceeded";
2851
2861
  AggregatorServerErrorCode2[AggregatorServerErrorCode2["InsufficientLiquidity"] = 1002] = "InsufficientLiquidity";
2852
2862
  AggregatorServerErrorCode2[AggregatorServerErrorCode2["HoneyPot"] = 1003] = "HoneyPot";
2863
+ AggregatorServerErrorCode2[AggregatorServerErrorCode2["BadRequest"] = 1004] = "BadRequest";
2864
+ AggregatorServerErrorCode2[AggregatorServerErrorCode2["Forbidden"] = 1005] = "Forbidden";
2865
+ AggregatorServerErrorCode2[AggregatorServerErrorCode2["InternalServerError"] = 1006] = "InternalServerError";
2866
+ AggregatorServerErrorCode2[AggregatorServerErrorCode2["NotFoundRoute"] = 1007] = "NotFoundRoute";
2867
+ AggregatorServerErrorCode2[AggregatorServerErrorCode2["ServiceUnavailable"] = 1008] = "ServiceUnavailable";
2868
+ AggregatorServerErrorCode2[AggregatorServerErrorCode2["UnsupportedApiVersion"] = 1009] = "UnsupportedApiVersion";
2869
+ AggregatorServerErrorCode2[AggregatorServerErrorCode2["HoneyPotScam"] = 1010] = "HoneyPotScam";
2870
+ AggregatorServerErrorCode2[AggregatorServerErrorCode2["UnknownError"] = 400] = "UnknownError";
2853
2871
  return AggregatorServerErrorCode2;
2854
2872
  })(AggregatorServerErrorCode || {});
2855
- function getAggregatorServerErrorMessage(code) {
2873
+ function getAggregatorServerErrorMessage(code, msg) {
2856
2874
  switch (code) {
2857
2875
  case 1e3 /* NumberTooLarge */:
2858
- return "Number too large";
2876
+ return "Number too large" + (msg ? `: ${msg}` : "");
2859
2877
  case 1001 /* RateLimitExceeded */:
2860
- return "Rate limit exceeded";
2878
+ return "Rate limit exceeded" + (msg ? `: ${msg}` : "");
2861
2879
  case 1002 /* InsufficientLiquidity */:
2862
- return "Insufficient liquidity";
2880
+ return "Insufficient liquidity" + (msg ? `: ${msg}` : "");
2863
2881
  case 1003 /* HoneyPot */:
2864
- return "HoneyPot scam detected";
2882
+ return "HoneyPot scam detected" + (msg ? `: ${msg}` : "");
2883
+ case 1005 /* Forbidden */:
2884
+ return "Forbidden" + (msg ? `: ${msg}` : "");
2885
+ case 1004 /* BadRequest */:
2886
+ return "Bad request" + (msg ? `: ${msg}` : "");
2887
+ case 1006 /* InternalServerError */:
2888
+ return "Internal server error" + (msg ? `: ${msg}` : "");
2889
+ case 1007 /* NotFoundRoute */:
2890
+ return "Not found route" + (msg ? `: ${msg}` : "");
2891
+ case 1008 /* ServiceUnavailable */:
2892
+ return "Service unavailable" + (msg ? `: ${msg}` : "");
2893
+ case 1009 /* UnsupportedApiVersion */:
2894
+ return "Unsupported API version" + (msg ? `: ${msg}` : "");
2895
+ case 1010 /* HoneyPotScam */:
2896
+ return "Detected HoneyPot Scam" + (msg ? `: ${msg}` : "");
2897
+ case 400 /* UnknownError */:
2898
+ return "Unknown error" + (msg ? `: ${msg}` : "");
2865
2899
  default:
2866
2900
  return "Unknown error";
2867
2901
  }
2868
2902
  }
2869
- var AggregatorError = class _AggregatorError extends Error {
2870
- constructor(message, errorCode) {
2871
- super(message);
2872
- this.message = message;
2873
- this.errorCode = errorCode;
2874
- }
2875
- static isAggregatorErrorCode(e, code) {
2876
- return e instanceof _AggregatorError && e.errorCode === code;
2877
- }
2878
- };
2879
2903
  var EQUAL = 0;
2880
2904
  var LESS_THAN = 1;
2881
2905
  var GREATER_THAN = 2;
@@ -3423,7 +3447,7 @@ var AGGREGATOR_V3_CONFIG = {
3423
3447
  };
3424
3448
 
3425
3449
  // src/api.ts
3426
- var SDK_VERSION = 1010200;
3450
+ var SDK_VERSION = 1010300;
3427
3451
  function parseRouterResponse(data, byAmountIn) {
3428
3452
  let packages = /* @__PURE__ */ new Map();
3429
3453
  if (data.packages) {
@@ -3458,6 +3482,50 @@ function parseRouterResponse(data, byAmountIn) {
3458
3482
  }))
3459
3483
  };
3460
3484
  }
3485
+ function parseMergeSwapResponse(data) {
3486
+ var _a;
3487
+ let packages = /* @__PURE__ */ new Map();
3488
+ if (data.packages) {
3489
+ if (data.packages instanceof Map) {
3490
+ packages = data.packages;
3491
+ } else if (typeof data.packages === "object") {
3492
+ Object.entries(data.packages).forEach(([key, value]) => {
3493
+ packages.set(key, value);
3494
+ });
3495
+ }
3496
+ }
3497
+ const allRoutes = [];
3498
+ if (data.all_routes) {
3499
+ for (const route of data.all_routes) {
3500
+ const mergeRoute = {
3501
+ amountIn: new import_bn2.default(route.amount_in.toString()),
3502
+ amountOut: new import_bn2.default(route.amount_out.toString()),
3503
+ deviationRatio: route.deviation_ratio,
3504
+ paths: route.paths.map((path) => ({
3505
+ id: path.id,
3506
+ direction: path.direction,
3507
+ provider: path.provider,
3508
+ from: path.from,
3509
+ target: path.target,
3510
+ feeRate: path.fee_rate,
3511
+ amountIn: path.amount_in.toString(),
3512
+ amountOut: path.amount_out.toString(),
3513
+ version: path.version,
3514
+ publishedAt: path.published_at,
3515
+ extendedDetails: path.extended_details
3516
+ }))
3517
+ };
3518
+ allRoutes.push(mergeRoute);
3519
+ }
3520
+ }
3521
+ return {
3522
+ quoteID: data.request_id || "",
3523
+ totalAmountOut: new import_bn2.default(((_a = data.total_amount_out) == null ? void 0 : _a.toString()) || "0"),
3524
+ allRoutes,
3525
+ packages,
3526
+ gas: data.gas
3527
+ };
3528
+ }
3461
3529
  function getRouterResult(endpoint, apiKey, params, overlayFee, overlayFeeReceiver) {
3462
3530
  return __async(this, null, function* () {
3463
3531
  let response;
@@ -3470,7 +3538,7 @@ function getRouterResult(endpoint, apiKey, params, overlayFee, overlayFeeReceive
3470
3538
  return null;
3471
3539
  }
3472
3540
  if (!response.ok) {
3473
- let errorCode = 1e3 /* NumberTooLarge */;
3541
+ let errorCode = 1004 /* BadRequest */;
3474
3542
  if (response.status === 429) {
3475
3543
  errorCode = 1001 /* RateLimitExceeded */;
3476
3544
  }
@@ -3489,24 +3557,6 @@ function getRouterResult(endpoint, apiKey, params, overlayFee, overlayFeeReceive
3489
3557
  };
3490
3558
  }
3491
3559
  const data = JSONbig.parse(yield response.text());
3492
- const insufficientLiquidity = data.msg === "liquidity is not enough";
3493
- if (data.msg && data.msg.indexOf("HoneyPot scam") > -1) {
3494
- return {
3495
- quoteID: "",
3496
- amountIn: ZERO,
3497
- amountOut: ZERO,
3498
- paths: [],
3499
- byAmountIn: params.byAmountIn,
3500
- insufficientLiquidity,
3501
- deviationRatio: 0,
3502
- error: {
3503
- code: 1003 /* HoneyPot */,
3504
- msg: getAggregatorServerErrorMessage(
3505
- 1003 /* HoneyPot */
3506
- )
3507
- }
3508
- };
3509
- }
3510
3560
  if (data.data != null) {
3511
3561
  const res = parseRouterResponse(data.data, params.byAmountIn);
3512
3562
  if (overlayFee > 0 && overlayFeeReceiver !== "0x0") {
@@ -3531,6 +3581,9 @@ function getRouterResult(endpoint, apiKey, params, overlayFee, overlayFeeReceive
3531
3581
  }
3532
3582
  return res;
3533
3583
  }
3584
+ const code = processErrorStatusCode(data.code);
3585
+ const msg = getAggregatorServerErrorMessage(code, data.msg);
3586
+ const insufficientLiquidity = msg.includes("Insufficient liquidity");
3534
3587
  return {
3535
3588
  quoteID: "",
3536
3589
  amountIn: ZERO,
@@ -3540,10 +3593,8 @@ function getRouterResult(endpoint, apiKey, params, overlayFee, overlayFeeReceive
3540
3593
  byAmountIn: params.byAmountIn,
3541
3594
  deviationRatio: 0,
3542
3595
  error: {
3543
- code: 1002 /* InsufficientLiquidity */,
3544
- msg: getAggregatorServerErrorMessage(
3545
- 1002 /* InsufficientLiquidity */
3546
- )
3596
+ code,
3597
+ msg
3547
3598
  }
3548
3599
  };
3549
3600
  });
@@ -3645,6 +3696,103 @@ function postRouterWithLiquidityChanges(endpoint, params) {
3645
3696
  }
3646
3697
  });
3647
3698
  }
3699
+ function getMergeSwapRouter(endpoint, apiKey, params) {
3700
+ return __async(this, null, function* () {
3701
+ try {
3702
+ const { target, byAmountIn, depth, providers, froms } = params;
3703
+ const targetCoin = completionCoin(target);
3704
+ let url = `${endpoint}/multi_find_routes?target=${targetCoin}&by_amount_in=${byAmountIn}`;
3705
+ if (depth) {
3706
+ url += `&depth=${depth}`;
3707
+ }
3708
+ if (providers && providers.length > 0) {
3709
+ url += `&providers=${providers.join(",")}`;
3710
+ }
3711
+ if (apiKey.length > 0) {
3712
+ url += `&apiKey=${apiKey}`;
3713
+ }
3714
+ url += `&v=${SDK_VERSION}`;
3715
+ const fromsData = froms.map((from) => ({
3716
+ coin_type: completionCoin(from.coinType),
3717
+ amount: Number(from.amount.toString())
3718
+ }));
3719
+ url += `&froms=${encodeURIComponent(JSON.stringify(fromsData))}`;
3720
+ const response = yield fetch(url);
3721
+ console.log("response", response);
3722
+ return response;
3723
+ } catch (error) {
3724
+ console.error(error);
3725
+ return null;
3726
+ }
3727
+ });
3728
+ }
3729
+ function getMergeSwapResult(endpoint, apiKey, params, overlayFee, overlayFeeReceiver) {
3730
+ return __async(this, null, function* () {
3731
+ const response = yield getMergeSwapRouter(endpoint, apiKey, params);
3732
+ if (!response) {
3733
+ return null;
3734
+ }
3735
+ if (!response.ok) {
3736
+ let errorCode = 1004 /* BadRequest */;
3737
+ if (response.status === 429) {
3738
+ errorCode = 1001 /* RateLimitExceeded */;
3739
+ }
3740
+ return {
3741
+ quoteID: "",
3742
+ totalAmountOut: ZERO,
3743
+ allRoutes: [],
3744
+ error: {
3745
+ code: errorCode,
3746
+ msg: getAggregatorServerErrorMessage(errorCode)
3747
+ }
3748
+ };
3749
+ }
3750
+ if (!response.ok) {
3751
+ const code2 = processErrorStatusCode(response.status);
3752
+ const responseText2 = yield response.text();
3753
+ const data2 = JSONbig.parse(responseText2);
3754
+ const msg2 = getAggregatorServerErrorMessage(code2, data2.msg);
3755
+ return {
3756
+ quoteID: "",
3757
+ totalAmountOut: ZERO,
3758
+ allRoutes: [],
3759
+ error: {
3760
+ code: code2,
3761
+ msg: msg2
3762
+ }
3763
+ };
3764
+ }
3765
+ const responseText = yield response.text();
3766
+ const data = JSONbig.parse(responseText);
3767
+ if (data.data != null) {
3768
+ console.log("data.data not null", data.data);
3769
+ const res = parseMergeSwapResponse(data.data);
3770
+ if (overlayFee > 0 && overlayFeeReceiver !== "0x0" && params.byAmountIn) {
3771
+ const overlayFeeAmount = res.totalAmountOut.mul(new import_bn2.default(overlayFee)).div(new import_bn2.default(1e6));
3772
+ res.totalAmountOut = res.totalAmountOut.sub(overlayFeeAmount);
3773
+ for (const route of res.allRoutes) {
3774
+ const routeFee = route.amountOut.mul(new import_bn2.default(overlayFee)).div(new import_bn2.default(1e6));
3775
+ route.amountOut = route.amountOut.sub(routeFee);
3776
+ }
3777
+ }
3778
+ if (!res.packages) {
3779
+ res.packages = /* @__PURE__ */ new Map();
3780
+ }
3781
+ return res;
3782
+ }
3783
+ const code = processErrorStatusCode(data.code);
3784
+ const msg = getAggregatorServerErrorMessage(code, data.msg);
3785
+ return {
3786
+ quoteID: "",
3787
+ totalAmountOut: ZERO,
3788
+ allRoutes: [],
3789
+ error: {
3790
+ code,
3791
+ msg
3792
+ }
3793
+ };
3794
+ });
3795
+ }
3648
3796
  function getDeepbookV3Config(endpoint) {
3649
3797
  return __async(this, null, function* () {
3650
3798
  const url = `${endpoint}/deepbookv3_config`;
@@ -3690,6 +3838,32 @@ function processFlattenRoutes(routerData) {
3690
3838
  overlayFee: routerData.overlayFee
3691
3839
  };
3692
3840
  }
3841
+ function processErrorStatusCode(status) {
3842
+ switch (status) {
3843
+ case 400:
3844
+ return 1004 /* BadRequest */;
3845
+ case 403:
3846
+ return 1005 /* Forbidden */;
3847
+ case 429:
3848
+ return 1001 /* RateLimitExceeded */;
3849
+ case 4e3:
3850
+ return 1004 /* BadRequest */;
3851
+ case 4030:
3852
+ return 1005 /* Forbidden */;
3853
+ case 4040:
3854
+ return 1010 /* HoneyPotScam */;
3855
+ case 5e3:
3856
+ return 1002 /* InsufficientLiquidity */;
3857
+ case 5001:
3858
+ return 1007 /* NotFoundRoute */;
3859
+ case 5030:
3860
+ return 1008 /* ServiceUnavailable */;
3861
+ case 5040:
3862
+ return 1009 /* UnsupportedApiVersion */;
3863
+ default:
3864
+ return 400 /* UnknownError */;
3865
+ }
3866
+ }
3693
3867
 
3694
3868
  // src/config.ts
3695
3869
  var Env = /* @__PURE__ */ ((Env2) => {
@@ -8101,6 +8275,96 @@ var FullsailRouter = class {
8101
8275
  });
8102
8276
  }
8103
8277
  };
8278
+ var CetusDlmmRouter = class {
8279
+ constructor(env, partner) {
8280
+ if (env !== 0 /* Mainnet */) {
8281
+ throw new Error("CetusRouter only supported on mainnet");
8282
+ }
8283
+ this.globalConfig = "0xf31b605d117f959b9730e8c07b08b856cb05143c5e81d5751c90d2979e82f599";
8284
+ this.partner = partner != null ? partner : "0x59ae16f6c42f578063c2da9b9c0173fe58120ceae08e40fd8212c8eceb80bb86";
8285
+ this.versioned = "0x05370b2d656612dd5759cbe80463de301e3b94a921dfc72dd9daa2ecdeb2d0a8";
8286
+ }
8287
+ swap(txb, flattenedPath, swapContext, _extends) {
8288
+ const swapData = this.prepareSwapData(flattenedPath);
8289
+ this.executeSwapContract(txb, swapData, swapContext);
8290
+ }
8291
+ prepareSwapData(flattenedPath) {
8292
+ if (flattenedPath.path.publishedAt == null) {
8293
+ throw new Error("Cetus not set publishedAt");
8294
+ }
8295
+ const path = flattenedPath.path;
8296
+ const [coinAType, coinBType] = path.direction ? [path.from, path.target] : [path.target, path.from];
8297
+ const amountIn = flattenedPath.isLastUseOfIntermediateToken ? AGGREGATOR_V3_CONFIG.MAX_AMOUNT_IN : path.amountIn;
8298
+ return {
8299
+ coinAType,
8300
+ coinBType,
8301
+ direction: path.direction,
8302
+ amountIn,
8303
+ publishedAt: path.publishedAt,
8304
+ poolId: path.id
8305
+ };
8306
+ }
8307
+ executeSwapContract(txb, swapData, swapContext) {
8308
+ const args = [
8309
+ swapContext,
8310
+ txb.object(this.globalConfig),
8311
+ txb.object(swapData.poolId),
8312
+ txb.object(this.partner),
8313
+ txb.pure.bool(swapData.direction),
8314
+ txb.pure.u64(swapData.amountIn),
8315
+ txb.object(this.versioned),
8316
+ txb.object(SUI_CLOCK_OBJECT_ID)
8317
+ ];
8318
+ txb.moveCall({
8319
+ target: `${swapData.publishedAt}::cetus_dlmm::swap`,
8320
+ typeArguments: [swapData.coinAType, swapData.coinBType],
8321
+ arguments: args
8322
+ });
8323
+ }
8324
+ };
8325
+ var FerraDlmmRouter = class {
8326
+ constructor(env) {
8327
+ if (env !== 0 /* Mainnet */) {
8328
+ throw new Error("FerraRouter only supported on mainnet");
8329
+ }
8330
+ this.globalConfig = "0x5c9dacf5a678ea15b8569d65960330307e23d429289ca380e665b1aa175ebeca";
8331
+ }
8332
+ swap(txb, flattenedPath, swapContext, _extends) {
8333
+ const swapData = this.prepareSwapData(flattenedPath);
8334
+ this.executeSwapContract(txb, swapData, swapContext);
8335
+ }
8336
+ prepareSwapData(flattenedPath) {
8337
+ if (flattenedPath.path.publishedAt == null) {
8338
+ throw new Error("Ferra not set publishedAt");
8339
+ }
8340
+ const path = flattenedPath.path;
8341
+ const [coinAType, coinBType] = path.direction ? [path.from, path.target] : [path.target, path.from];
8342
+ const amountIn = flattenedPath.isLastUseOfIntermediateToken ? AGGREGATOR_V3_CONFIG.MAX_AMOUNT_IN : path.amountIn;
8343
+ return {
8344
+ coinAType,
8345
+ coinBType,
8346
+ direction: path.direction,
8347
+ amountIn,
8348
+ publishedAt: path.publishedAt,
8349
+ poolId: path.id
8350
+ };
8351
+ }
8352
+ executeSwapContract(txb, swapData, swapContext) {
8353
+ const args = [
8354
+ swapContext,
8355
+ txb.object(this.globalConfig),
8356
+ txb.object(swapData.poolId),
8357
+ txb.pure.bool(swapData.direction),
8358
+ txb.pure.u64(swapData.amountIn),
8359
+ txb.object(SUI_CLOCK_OBJECT_ID)
8360
+ ];
8361
+ txb.moveCall({
8362
+ target: `${swapData.publishedAt}::ferra_dlmm::swap`,
8363
+ typeArguments: [swapData.coinAType, swapData.coinBType],
8364
+ arguments: args
8365
+ });
8366
+ }
8367
+ };
8104
8368
 
8105
8369
  // src/client.ts
8106
8370
  var CETUS = "CETUS";
@@ -8133,6 +8397,8 @@ var MAGMA = "MAGMA";
8133
8397
  var SEVENK = "SEVENK";
8134
8398
  var HAEDALHMMV2 = "HAEDALHMMV2";
8135
8399
  var FULLSAIL = "FULLSAIL";
8400
+ var CETUSDLMM = "CETUSDLMM";
8401
+ var FERRADLMM = "FERRADLMM";
8136
8402
  var DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v3";
8137
8403
  var ALL_DEXES = [
8138
8404
  CETUS,
@@ -8163,7 +8429,9 @@ var ALL_DEXES = [
8163
8429
  MAGMA,
8164
8430
  SEVENK,
8165
8431
  HAEDALHMMV2,
8166
- FULLSAIL
8432
+ FULLSAIL,
8433
+ CETUSDLMM,
8434
+ FERRADLMM
8167
8435
  ];
8168
8436
  function getAllProviders() {
8169
8437
  return ALL_DEXES;
@@ -8242,6 +8510,7 @@ var _AggregatorClient = class _AggregatorClient {
8242
8510
  );
8243
8511
  this.apiKey = params.apiKey || "";
8244
8512
  this.partner = params.partner;
8513
+ this.cetusDlmmPartner = params.cetusDlmmPartner;
8245
8514
  if (params.overlayFeeRate) {
8246
8515
  if (params.overlayFeeRate > 0 && params.overlayFeeRate <= CLIENT_CONFIG.MAX_OVERLAY_FEE_RATE) {
8247
8516
  this.overlayFeeRate = params.overlayFeeRate * AGGREGATOR_V3_CONFIG.FEE_DENOMINATOR;
@@ -8307,11 +8576,22 @@ var _AggregatorClient = class _AggregatorClient {
8307
8576
  );
8308
8577
  });
8309
8578
  }
8579
+ findMergeSwapRouters(params) {
8580
+ return __async(this, null, function* () {
8581
+ return getMergeSwapResult(
8582
+ this.endpoint,
8583
+ this.apiKey,
8584
+ params,
8585
+ this.overlayFeeRate,
8586
+ this.overlayFeeReceiver
8587
+ );
8588
+ });
8589
+ }
8310
8590
  executeFlexibleInputSwap(txb, inputCoin, routerData, expectedAmountOut, amountLimit, pythPriceIDs, partner, deepbookv3DeepFee, packages) {
8311
8591
  return __async(this, null, function* () {
8312
8592
  });
8313
8593
  }
8314
- newDexRouterV3(provider, pythPriceIDs, partner) {
8594
+ newDexRouterV3(provider, pythPriceIDs, partner, cetusDlmmPartner) {
8315
8595
  switch (provider) {
8316
8596
  case CETUS:
8317
8597
  return new CetusRouter(this.env, partner);
@@ -8371,13 +8651,17 @@ var _AggregatorClient = class _AggregatorClient {
8371
8651
  return new HaedalHMMV2Router(this.env, pythPriceIDs);
8372
8652
  case FULLSAIL:
8373
8653
  return new FullsailRouter(this.env);
8654
+ case CETUSDLMM:
8655
+ return new CetusDlmmRouter(this.env, cetusDlmmPartner);
8656
+ case FERRADLMM:
8657
+ return new FerraDlmmRouter(this.env);
8374
8658
  default:
8375
8659
  throw new Error(
8376
8660
  `${CLIENT_CONFIG.ERRORS.UNSUPPORTED_DEX} ${provider}`
8377
8661
  );
8378
8662
  }
8379
8663
  }
8380
- expectInputSwapV3(txb, inputCoin, routerData, expectAmountOut, amountOutLimit, pythPriceIDs, partner) {
8664
+ expectInputSwapV3(txb, inputCoin, routerData, expectAmountOut, amountOutLimit, pythPriceIDs, partner, cetusDlmmPartner) {
8381
8665
  if (routerData.quoteID == null) {
8382
8666
  throw new Error(CLIENT_CONFIG.ERRORS.QUOTE_ID_REQUIRED);
8383
8667
  }
@@ -8402,7 +8686,12 @@ var _AggregatorClient = class _AggregatorClient {
8402
8686
  if (!dexRouters.has(path.provider)) {
8403
8687
  dexRouters.set(
8404
8688
  path.provider,
8405
- this.newDexRouterV3(path.provider, pythPriceIDs, partner)
8689
+ this.newDexRouterV3(
8690
+ path.provider,
8691
+ pythPriceIDs,
8692
+ partner,
8693
+ cetusDlmmPartner
8694
+ )
8406
8695
  );
8407
8696
  }
8408
8697
  const dex = dexRouters.get(path.provider);
@@ -8644,6 +8933,103 @@ var _AggregatorClient = class _AggregatorClient {
8644
8933
  }
8645
8934
  });
8646
8935
  }
8936
+ mergeSwap(params) {
8937
+ return __async(this, null, function* () {
8938
+ const { router, inputCoins, slippage, txb, partner } = params;
8939
+ if (slippage > 1 || slippage < 0) {
8940
+ throw new Error(CLIENT_CONFIG.ERRORS.INVALID_SLIPPAGE);
8941
+ }
8942
+ if (!router.packages || !router.packages.get(PACKAGE_NAMES.AGGREGATOR_V3)) {
8943
+ throw new Error(CLIENT_CONFIG.ERRORS.PACKAGES_REQUIRED);
8944
+ }
8945
+ if (!router.allRoutes || router.allRoutes.length === 0) {
8946
+ throw new Error("No routes found in merge swap response");
8947
+ }
8948
+ const outputCoins = [];
8949
+ for (let i = 0; i < router.allRoutes.length && i < inputCoins.length; i++) {
8950
+ const route = router.allRoutes[i];
8951
+ const inputCoin = inputCoins[i];
8952
+ const routeRouter = {
8953
+ quoteID: router.quoteID,
8954
+ amountIn: route.amountIn,
8955
+ amountOut: route.amountOut,
8956
+ deviationRatio: Number(route.deviationRatio),
8957
+ byAmountIn: true,
8958
+ // Merge swap is always by amount in
8959
+ paths: route.paths,
8960
+ insufficientLiquidity: false,
8961
+ packages: router.packages
8962
+ };
8963
+ const routerParams = {
8964
+ router: routeRouter,
8965
+ inputCoin: inputCoin.coin,
8966
+ slippage,
8967
+ txb,
8968
+ partner: partner != null ? partner : this.partner
8969
+ };
8970
+ const outputCoin = yield this.routerSwap(routerParams);
8971
+ outputCoins.push(outputCoin);
8972
+ }
8973
+ if (outputCoins.length === 0) {
8974
+ throw new Error("No output coins generated from merge swap");
8975
+ }
8976
+ let finalOutputCoin = outputCoins[0];
8977
+ if (outputCoins.length > 1) {
8978
+ txb.mergeCoins(finalOutputCoin, outputCoins.slice(1));
8979
+ }
8980
+ return finalOutputCoin;
8981
+ });
8982
+ }
8983
+ fastMergeSwap(params) {
8984
+ return __async(this, null, function* () {
8985
+ const { router, slippage, txb, partner } = params;
8986
+ if (!router || !router.allRoutes || router.allRoutes.length === 0) {
8987
+ throw new Error("Invalid router: no routes found");
8988
+ }
8989
+ const firstRoute = router.allRoutes[0];
8990
+ const targetCoinType = firstRoute.paths[firstRoute.paths.length - 1].target;
8991
+ const inputCoins = [];
8992
+ const coinTypeSet = /* @__PURE__ */ new Set();
8993
+ for (const route of router.allRoutes) {
8994
+ const firstCoinType = route.paths[0].from;
8995
+ if (coinTypeSet.has(firstCoinType)) {
8996
+ continue;
8997
+ }
8998
+ coinTypeSet.add(firstCoinType);
8999
+ const coin = coinWithBalance({
9000
+ balance: BigInt(route.amountIn.toString()),
9001
+ useGasCoin: CoinUtils.isSuiCoin(firstCoinType),
9002
+ type: firstCoinType
9003
+ });
9004
+ inputCoins.push({ coinType: firstCoinType, coin });
9005
+ }
9006
+ const mergeSwapParams = {
9007
+ router,
9008
+ inputCoins,
9009
+ slippage,
9010
+ txb,
9011
+ partner: partner != null ? partner : this.partner
9012
+ };
9013
+ const targetCoin = yield this.mergeSwap(mergeSwapParams);
9014
+ if (CoinUtils.isSuiCoin(targetCoinType)) {
9015
+ txb.mergeCoins(txb.gas, [targetCoin]);
9016
+ } else {
9017
+ const targetCoinObjID = yield this.getOneCoinUsedToMerge(targetCoinType);
9018
+ if (targetCoinObjID != null) {
9019
+ txb.mergeCoins(txb.object(targetCoinObjID), [targetCoin]);
9020
+ } else {
9021
+ transferOrDestroyCoin(
9022
+ {
9023
+ coin: targetCoin,
9024
+ coinType: targetCoinType,
9025
+ packages: router.packages
9026
+ },
9027
+ txb
9028
+ );
9029
+ }
9030
+ }
9031
+ });
9032
+ }
8647
9033
  fixableRouterSwapV3(params) {
8648
9034
  return __async(this, null, function* () {
8649
9035
  const { router, inputCoin, slippage, txb, partner } = params;
@@ -8922,4 +9308,4 @@ decimal.js/decimal.mjs:
8922
9308
  *)
8923
9309
  */
8924
9310
 
8925
- export { AFSUI, AFTERMATH, AFTERMATH_AMM, AFTERMATH_MODULE, AGGREGATOR, AGGREGATOR_V3_CONFIG, ALL_DEXES, ALPHAFI, AggregatorClient, AggregatorConfig, AggregatorError, AggregatorServerErrorCode, BLUEFIN, BLUEMOVE, CETUS, CETUS_DEX, CETUS_MODULE, CETUS_PUBLISHED_AT, CETUS_V3_PUBLISHED_AT, CHECK_COINS_THRESHOLD_FUNC, CLIENT_CONFIG, CLOCK_ADDRESS, CoinInfoAddress, CoinStoreAddress, CoinUtils, ConfigErrorCode, DEEPBOOKV2, DEEPBOOKV3, DEEPBOOK_CLOB_V2_MODULE, DEEPBOOK_CUSTODIAN_V2_MODULE, DEEPBOOK_DEX, DEEPBOOK_MODULE, DEEPBOOK_PACKAGE_ID, DEEPBOOK_PUBLISHED_AT, DEEPBOOK_V3_DEEP_FEE_TYPES, DEFAULT_AGG_V2_ENDPOINT, DEFAULT_AGG_V3_ENDPOINT, DEFAULT_ENDPOINT, DEFAULT_GAS_BUDGET_FOR_MERGE, DEFAULT_GAS_BUDGET_FOR_SPLIT, DEFAULT_GAS_BUDGET_FOR_STAKE, DEFAULT_GAS_BUDGET_FOR_TRANSFER, DEFAULT_GAS_BUDGET_FOR_TRANSFER_SUI, DEFAULT_NFT_TRANSFER_GAS_FEE, Env, FLOWXV2, FLOWXV3, FLOWX_AMM, FLOWX_AMM_MODULE, FULLSAIL, FlashSwapA2BFunc, FlashSwapB2AFunc, FlashSwapFunc, FlashSwapWithPartnerA2BFunc, FlashSwapWithPartnerB2AFunc, FlashSwapWithPartnerFunc, GAS_SYMBOL, GAS_TYPE_ARG, GAS_TYPE_ARG_LONG, HAEDAL, HAEDALHMMV2, HAEDALPMM, HAWAL, INTEGRATE, JOIN_FUNC, KRIYA, KRIYAV3, KRIYA_DEX, KRIYA_MODULE, MAGMA, MAINNET_AFTERMATH_INSURANCE_FUND_ID, MAINNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID, MAINNET_AFTERMATH_REFERRAL_VAULT_ID, MAINNET_AFTERMATH_REGISTRY_ID, MAINNET_AFTERMATH_TREASURY_ID, MAINNET_CETUS_GLOBAL_CONFIG_ID, MAINNET_FLOWX_AMM_CONTAINER_ID, METASTABLE, MOMENTUM, OBRIC, ONE, PACKAGE_NAMES, PAY_MODULE, POOL_MODULT, PUBLISHED_ADDRESSES, PYTH_CONFIG, REPAY_FLASH_SWAP_A2B_FUNC, REPAY_FLASH_SWAP_B2A_FUNC, REPAY_FLASH_SWAP_WITH_PARTNER_A2B_FUNC, REPAY_FLASH_SWAP_WITH_PARTNER_B2A_FUNC, RepayFalshSwapFunc, RepayFlashSwapWithPartnerFunc, SCALLOP, SEVENK, SPRINGSUI, STEAMM, STEAMM_OMM, STEAMM_OMM_V2, SUILEND, SUI_SYSTEM_STATE_OBJECT_ID, SWAP_A2B_FUNC, SWAP_B2A_FUNC, SuiZeroCoinFn, TEN_POW_NINE, TESTNET_AFTERMATH_INSURANCE_FUND_ID, TESTNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID, TESTNET_AFTERMATH_REFERRAL_VAULT_ID, TESTNET_AFTERMATH_REGISTRY_ID, TESTNET_AFTERMATH_TREASURY_ID, TESTNET_CETUS_GLOBAL_CONFIG_ID, TESTNET_FLOWX_AMM_CONTAINER_ID, TRANSFER_ACCOUNT_CAP, TRANSFER_OR_DESTORY_COIN_FUNC, TURBOS, TURBOS_DEX, TURBOS_MODULE, TURBOS_VERSIONED, TWO, TransactionErrorCode, TypesErrorCode, U128, U64_MAX, U64_MAX_BN, UTILS_MODULE, VOLO, ZERO, buildInputCoin, calculateGasEfficiency, calculatePriceImpact, checkInvalidSuiAddress, compareCoins, compareGasMetrics, completionCoin, composeType, createTarget, dealWithFastRouterSwapParamsForMsafe, exportToCSV, exportToJSON, extractAddressFromType, extractGasMetrics, extractStructTagFromType, extractTimestampFromDowngradeUuid6, fixSuiObjectId, formatGasMetrics, generateDowngradeUuid6, generateSimpleDowngradeUuid6, getAggregatorServerErrorMessage, getAggregatorV2Extend2PublishedAt, getAggregatorV2ExtendPublishedAt, getAggregatorV2PublishedAt, getAllProviders, getDeepbookV3Config, getDefaultSuiInputType, getOrCreateAccountCap, getProvidersExcluding, getProvidersIncluding, getRouterResult, isSortedSymbols, isValidDowngradeUuid6, mintZeroCoin, normalizeCoinType, parseAftermathFeeType, parseTurbosPoolFeeType, patchFixSuiObjectId, printTransaction, processEndpoint, processFlattenRoutes, restituteMsafeFastRouterSwapParams };
9311
+ export { AFSUI, AFTERMATH, AFTERMATH_AMM, AFTERMATH_MODULE, AGGREGATOR, AGGREGATOR_V3_CONFIG, ALL_DEXES, ALPHAFI, AggregatorClient, AggregatorConfig, AggregatorError, AggregatorServerErrorCode, BLUEFIN, BLUEMOVE, CETUS, CETUSDLMM, CETUS_DEX, CETUS_MODULE, CETUS_PUBLISHED_AT, CETUS_V3_PUBLISHED_AT, CHECK_COINS_THRESHOLD_FUNC, CLIENT_CONFIG, CLOCK_ADDRESS, CoinInfoAddress, CoinStoreAddress, CoinUtils, ConfigErrorCode, DEEPBOOKV2, DEEPBOOKV3, DEEPBOOK_CLOB_V2_MODULE, DEEPBOOK_CUSTODIAN_V2_MODULE, DEEPBOOK_DEX, DEEPBOOK_MODULE, DEEPBOOK_PACKAGE_ID, DEEPBOOK_PUBLISHED_AT, DEEPBOOK_V3_DEEP_FEE_TYPES, DEFAULT_AGG_V2_ENDPOINT, DEFAULT_AGG_V3_ENDPOINT, DEFAULT_ENDPOINT, DEFAULT_GAS_BUDGET_FOR_MERGE, DEFAULT_GAS_BUDGET_FOR_SPLIT, DEFAULT_GAS_BUDGET_FOR_STAKE, DEFAULT_GAS_BUDGET_FOR_TRANSFER, DEFAULT_GAS_BUDGET_FOR_TRANSFER_SUI, DEFAULT_NFT_TRANSFER_GAS_FEE, Env, FERRADLMM, FLOWXV2, FLOWXV3, FLOWX_AMM, FLOWX_AMM_MODULE, FULLSAIL, FlashSwapA2BFunc, FlashSwapB2AFunc, FlashSwapFunc, FlashSwapWithPartnerA2BFunc, FlashSwapWithPartnerB2AFunc, FlashSwapWithPartnerFunc, GAS_SYMBOL, GAS_TYPE_ARG, GAS_TYPE_ARG_LONG, HAEDAL, HAEDALHMMV2, HAEDALPMM, HAWAL, INTEGRATE, JOIN_FUNC, KRIYA, KRIYAV3, KRIYA_DEX, KRIYA_MODULE, MAGMA, MAINNET_AFTERMATH_INSURANCE_FUND_ID, MAINNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID, MAINNET_AFTERMATH_REFERRAL_VAULT_ID, MAINNET_AFTERMATH_REGISTRY_ID, MAINNET_AFTERMATH_TREASURY_ID, MAINNET_CETUS_GLOBAL_CONFIG_ID, MAINNET_FLOWX_AMM_CONTAINER_ID, METASTABLE, MOMENTUM, OBRIC, ONE, PACKAGE_NAMES, PAY_MODULE, POOL_MODULT, PUBLISHED_ADDRESSES, PYTH_CONFIG, REPAY_FLASH_SWAP_A2B_FUNC, REPAY_FLASH_SWAP_B2A_FUNC, REPAY_FLASH_SWAP_WITH_PARTNER_A2B_FUNC, REPAY_FLASH_SWAP_WITH_PARTNER_B2A_FUNC, RepayFalshSwapFunc, RepayFlashSwapWithPartnerFunc, SCALLOP, SEVENK, SPRINGSUI, STEAMM, STEAMM_OMM, STEAMM_OMM_V2, SUILEND, SUI_SYSTEM_STATE_OBJECT_ID, SWAP_A2B_FUNC, SWAP_B2A_FUNC, SuiZeroCoinFn, TEN_POW_NINE, TESTNET_AFTERMATH_INSURANCE_FUND_ID, TESTNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID, TESTNET_AFTERMATH_REFERRAL_VAULT_ID, TESTNET_AFTERMATH_REGISTRY_ID, TESTNET_AFTERMATH_TREASURY_ID, TESTNET_CETUS_GLOBAL_CONFIG_ID, TESTNET_FLOWX_AMM_CONTAINER_ID, TRANSFER_ACCOUNT_CAP, TRANSFER_OR_DESTORY_COIN_FUNC, TURBOS, TURBOS_DEX, TURBOS_MODULE, TURBOS_VERSIONED, TWO, TransactionErrorCode, TypesErrorCode, U128, U64_MAX, U64_MAX_BN, UTILS_MODULE, VOLO, ZERO, buildInputCoin, calculateGasEfficiency, calculatePriceImpact, checkInvalidSuiAddress, compareCoins, compareGasMetrics, completionCoin, composeType, createTarget, dealWithFastRouterSwapParamsForMsafe, exportToCSV, exportToJSON, extractAddressFromType, extractGasMetrics, extractStructTagFromType, extractTimestampFromDowngradeUuid6, fixSuiObjectId, formatGasMetrics, generateDowngradeUuid6, generateSimpleDowngradeUuid6, getAggregatorServerErrorMessage, getAggregatorV2Extend2PublishedAt, getAggregatorV2ExtendPublishedAt, getAggregatorV2PublishedAt, getAllProviders, getDeepbookV3Config, getDefaultSuiInputType, getMergeSwapResult, getOrCreateAccountCap, getProvidersExcluding, getProvidersIncluding, getRouterResult, isSortedSymbols, isValidDowngradeUuid6, mintZeroCoin, normalizeCoinType, parseAftermathFeeType, parseTurbosPoolFeeType, patchFixSuiObjectId, printTransaction, processEndpoint, processFlattenRoutes, restituteMsafeFastRouterSwapParams };