@cetusprotocol/aggregator-sdk 0.0.0-experimental-20250723103308 → 0.0.0-experimental-20250729170433

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.mts CHANGED
@@ -65,9 +65,9 @@ type ExtendedDetails = {
65
65
  steamm_bank_b?: string;
66
66
  steamm_lending_market?: string;
67
67
  steamm_lending_market_type?: string;
68
- steamm_b_coin_a_type?: string;
69
- steamm_b_coin_b_type?: string;
70
- steamm_lp_token?: string;
68
+ steamm_btoken_a_type?: string;
69
+ steamm_btoken_b_type?: string;
70
+ steamm_lp_token_type?: string;
71
71
  steamm_oracle_registry_id?: string;
72
72
  steamm_oracle_pyth_price_seed_a?: string;
73
73
  steamm_oracle_pyth_price_seed_b?: string;
@@ -129,7 +129,6 @@ type RouterData = {
129
129
  type FlattenedPath = {
130
130
  path: Path;
131
131
  isLastUseOfIntermediateToken: boolean;
132
- executionOrder: number;
133
132
  };
134
133
  type ProcessedRouterData = {
135
134
  quoteID: string;
package/dist/index.d.ts CHANGED
@@ -65,9 +65,9 @@ type ExtendedDetails = {
65
65
  steamm_bank_b?: string;
66
66
  steamm_lending_market?: string;
67
67
  steamm_lending_market_type?: string;
68
- steamm_b_coin_a_type?: string;
69
- steamm_b_coin_b_type?: string;
70
- steamm_lp_token?: string;
68
+ steamm_btoken_a_type?: string;
69
+ steamm_btoken_b_type?: string;
70
+ steamm_lp_token_type?: string;
71
71
  steamm_oracle_registry_id?: string;
72
72
  steamm_oracle_pyth_price_seed_a?: string;
73
73
  steamm_oracle_pyth_price_seed_b?: string;
@@ -129,7 +129,6 @@ type RouterData = {
129
129
  type FlattenedPath = {
130
130
  path: Path;
131
131
  isLastUseOfIntermediateToken: boolean;
132
- executionOrder: number;
133
132
  };
134
133
  type ProcessedRouterData = {
135
134
  quoteID: string;
package/dist/index.js CHANGED
@@ -5360,7 +5360,7 @@ var AGGREGATOR_V3_CONFIG = {
5360
5360
  "SCALLOP",
5361
5361
  "SUILEND",
5362
5362
  "SPRINGSUI",
5363
- // Phase 4: Oracle-driven Routers
5363
+ // Phase 4: Oracle-driven Routers
5364
5364
  "HAEDALPMM",
5365
5365
  "OBRIC",
5366
5366
  "SEVENK",
@@ -6093,11 +6093,12 @@ var restituteMsafeFastRouterSwapParams = (data) => {
6093
6093
  function printTransaction(tx, isPrint = true) {
6094
6094
  return __async(this, null, function* () {
6095
6095
  console.log(`inputs`, tx.getData().inputs);
6096
- let i = 0;
6097
6096
  tx.getData().commands.forEach((item, index) => {
6098
- if (isPrint && i < 15) {
6099
- console.log(`transaction ${index}: `, JSON.stringify(item, bigIntReplacer, 2));
6100
- i++;
6097
+ if (isPrint) {
6098
+ console.log(
6099
+ `transaction ${index}: `,
6100
+ JSON.stringify(item, bigIntReplacer, 2)
6101
+ );
6101
6102
  }
6102
6103
  });
6103
6104
  });
@@ -6130,7 +6131,7 @@ function parseRouterResponse(data, byAmountIn) {
6130
6131
  }
6131
6132
  }
6132
6133
  return {
6133
- quoteID: data.quote_id || "",
6134
+ quoteID: data.request_id || "",
6134
6135
  amountIn: new import_bn4.default(data.amount_in.toString()),
6135
6136
  amountOut: new import_bn4.default(data.amount_out.toString()),
6136
6137
  byAmountIn,
@@ -6390,68 +6391,27 @@ function sortAndFlattenRoutes(routerData) {
6390
6391
  }
6391
6392
  }
6392
6393
  }
6393
- for (const route of routerData.routes) {
6394
- for (let i = 0; i < route.path.length - 1; i++) {
6395
- const currentPath = route.path[i];
6396
- const nextPath = route.path[i + 1];
6397
- const currentPoolDirectionKey = createPoolDirectionKey(
6398
- currentPath.id,
6399
- currentPath.direction
6400
- );
6401
- const nextPoolDirectionKey = createPoolDirectionKey(
6402
- nextPath.id,
6403
- nextPath.direction
6404
- );
6405
- pathDependencies.get(nextPoolDirectionKey).add(currentPoolDirectionKey);
6406
- }
6407
- }
6408
- if (process.env.NODE_ENV === "development") {
6409
- console.log("Route merging dependency graph:");
6410
- for (const [poolDirectionKey, deps] of pathDependencies) {
6411
- if (deps.size > 0) {
6412
- console.log(
6413
- ` ${poolDirectionKey} depends on: [${Array.from(deps).join(", ")}]`
6414
- );
6415
- } else {
6416
- console.log(` ${poolDirectionKey} has no dependencies`);
6417
- }
6418
- }
6419
- }
6420
- const mergedPaths = /* @__PURE__ */ new Map();
6421
- for (const [poolDirectionKey, paths] of pathUsageMap) {
6422
- const firstPath = paths[0];
6423
- const totalAmountIn = paths.reduce((sum2, path) => {
6424
- return new import_bn4.default(sum2).add(new import_bn4.default(path.amountIn)).toString();
6425
- }, "0");
6426
- mergedPaths.set(poolDirectionKey, __spreadProps(__spreadValues({}, firstPath), {
6427
- amountIn: totalAmountIn
6428
- }));
6429
- }
6430
- const sortedPoolDirectionKeys = topologicalSortKahn(pathDependencies);
6431
- if (process.env.NODE_ENV === "development") {
6432
- console.log("Topological sort execution order:", sortedPoolDirectionKeys);
6433
- }
6434
6394
  const flattenedPaths = [];
6435
- let executionOrder = 0;
6436
- for (const poolDirectionKey of sortedPoolDirectionKeys) {
6437
- const path = mergedPaths.get(poolDirectionKey);
6395
+ if (routerData.routes.length !== 1) {
6396
+ console.warn(
6397
+ "Multiple routes detected, merging paths may lead to unexpected results"
6398
+ );
6399
+ }
6400
+ const paths = routerData.routes[0].path;
6401
+ for (const path of paths) {
6438
6402
  flattenedPaths.push({
6439
6403
  path,
6440
- isLastUseOfIntermediateToken: false,
6441
- // Will be set in second pass
6442
- executionOrder: executionOrder++
6404
+ isLastUseOfIntermediateToken: false
6443
6405
  });
6444
6406
  }
6445
- const lastOccurrenceIndex = /* @__PURE__ */ new Map();
6446
- for (let i = 0; i < flattenedPaths.length; i++) {
6407
+ const seenTokens = /* @__PURE__ */ new Map();
6408
+ for (let i = flattenedPaths.length - 1; i >= 0; i--) {
6447
6409
  const { from } = flattenedPaths[i].path;
6448
- if (from !== fromCoinType) {
6449
- lastOccurrenceIndex.set(from, i);
6410
+ if (from !== fromCoinType && !seenTokens.has(from)) {
6411
+ seenTokens.set(from, true);
6412
+ flattenedPaths[i].isLastUseOfIntermediateToken = true;
6450
6413
  }
6451
6414
  }
6452
- for (const [_tokenType, lastIndex] of lastOccurrenceIndex) {
6453
- flattenedPaths[lastIndex].isLastUseOfIntermediateToken = true;
6454
- }
6455
6415
  return {
6456
6416
  quoteID: routerData.quoteID || "",
6457
6417
  amountIn: routerData.amountIn,
@@ -6466,54 +6426,6 @@ function sortAndFlattenRoutes(routerData) {
6466
6426
  overlayFee: routerData.overlayFee
6467
6427
  };
6468
6428
  }
6469
- function topologicalSortKahn(dependencies) {
6470
- const inDegree = /* @__PURE__ */ new Map();
6471
- const graph = /* @__PURE__ */ new Map();
6472
- for (const [nodeId] of dependencies) {
6473
- inDegree.set(nodeId, 0);
6474
- graph.set(nodeId, /* @__PURE__ */ new Set());
6475
- }
6476
- for (const [nodeId, deps] of dependencies) {
6477
- for (const depId of deps) {
6478
- if (!graph.has(depId)) {
6479
- graph.set(depId, /* @__PURE__ */ new Set());
6480
- inDegree.set(depId, 0);
6481
- }
6482
- graph.get(depId).add(nodeId);
6483
- inDegree.set(nodeId, (inDegree.get(nodeId) || 0) + 1);
6484
- }
6485
- }
6486
- const queue = [];
6487
- for (const [nodeId, degree] of inDegree) {
6488
- if (degree === 0) {
6489
- queue.push(nodeId);
6490
- }
6491
- }
6492
- const result = [];
6493
- while (queue.length > 0) {
6494
- const nodeId = queue.shift();
6495
- result.push(nodeId);
6496
- const neighbors = graph.get(nodeId) || /* @__PURE__ */ new Set();
6497
- for (const neighbor of neighbors) {
6498
- const newDegree = inDegree.get(neighbor) - 1;
6499
- inDegree.set(neighbor, newDegree);
6500
- if (newDegree === 0) {
6501
- queue.push(neighbor);
6502
- }
6503
- }
6504
- }
6505
- if (result.length !== dependencies.size) {
6506
- const remainingNodes = Array.from(dependencies.keys()).filter(
6507
- (nodeId) => !result.includes(nodeId)
6508
- );
6509
- throw new Error(
6510
- `Circular dependency detected in route merging. Remaining nodes: ${remainingNodes.join(
6511
- ", "
6512
- )}`
6513
- );
6514
- }
6515
- return result;
6516
- }
6517
6429
 
6518
6430
  // src/utils/aggregator-config.ts
6519
6431
  var AggregatorConfig2 = class {
@@ -6917,21 +6829,29 @@ var Cetus = class {
6917
6829
  var import_bn7 = __toESM(require_bn());
6918
6830
 
6919
6831
  // src/math.ts
6920
- __toESM(require_bn());
6832
+ var import_bn6 = __toESM(require_bn());
6921
6833
  function CalculateAmountLimit(expectAmount, byAmountIn, slippage) {
6922
- let amountLimit = ZERO;
6923
- if (byAmountIn) {
6924
- amountLimit = expectAmount.muln(1 - slippage);
6925
- } else {
6926
- amountLimit = expectAmount.muln(1 + slippage);
6927
- }
6928
- return Number(amountLimit.toString());
6834
+ return Number(
6835
+ CalculateAmountLimitByDecimal(
6836
+ new decimal_default(expectAmount.toString()),
6837
+ byAmountIn,
6838
+ slippage
6839
+ ).toFixed(0)
6840
+ );
6929
6841
  }
6930
6842
  function CalculateAmountLimitBN(expectAmount, byAmountIn, slippage) {
6843
+ const amountLimit = CalculateAmountLimitByDecimal(
6844
+ new decimal_default(expectAmount.toString()),
6845
+ byAmountIn,
6846
+ slippage
6847
+ );
6848
+ return new import_bn6.default(amountLimit.toFixed(0));
6849
+ }
6850
+ function CalculateAmountLimitByDecimal(expectAmount, byAmountIn, slippage) {
6931
6851
  if (byAmountIn) {
6932
- return expectAmount.muln(1 - slippage);
6852
+ return expectAmount.mul(1 - slippage);
6933
6853
  } else {
6934
- return expectAmount.muln(1 + slippage);
6854
+ return expectAmount.mul(1 + slippage);
6935
6855
  }
6936
6856
  }
6937
6857
  function sqrtPriceX64ToPrice(sqrtPriceStr, decimalsA, decimalsB) {
@@ -7413,13 +7333,13 @@ var SteammCPMM = class {
7413
7333
  if (path.extendedDetails.steamm_lending_market_type == null) {
7414
7334
  throw new Error("Steamm lending market type not supported");
7415
7335
  }
7416
- if (path.extendedDetails.steamm_b_coin_a_type == null) {
7336
+ if (path.extendedDetails.steamm_btoken_a_type == null) {
7417
7337
  throw new Error("Steamm b coin a type not supported");
7418
7338
  }
7419
- if (path.extendedDetails.steamm_b_coin_b_type == null) {
7339
+ if (path.extendedDetails.steamm_btoken_b_type == null) {
7420
7340
  throw new Error("Steamm b coin b type not supported");
7421
7341
  }
7422
- if (path.extendedDetails.steamm_lp_token == null) {
7342
+ if (path.extendedDetails.steamm_lp_token_type == null) {
7423
7343
  throw new Error("Steamm lp token not supported");
7424
7344
  }
7425
7345
  }
@@ -7441,9 +7361,9 @@ var SteammCPMM = class {
7441
7361
  path.extendedDetails.steamm_lending_market_type,
7442
7362
  coinAType,
7443
7363
  coinBType,
7444
- path.extendedDetails.steamm_b_coin_a_type,
7445
- path.extendedDetails.steamm_b_coin_b_type,
7446
- path.extendedDetails.steamm_lp_token
7364
+ path.extendedDetails.steamm_btoken_a_type,
7365
+ path.extendedDetails.steamm_btoken_b_type,
7366
+ path.extendedDetails.steamm_lp_token_type
7447
7367
  ],
7448
7368
  arguments: args
7449
7369
  });
@@ -7479,13 +7399,13 @@ var SteammOmm = class {
7479
7399
  if (path.extendedDetails.steamm_lending_market_type == null) {
7480
7400
  throw new Error("Steamm lending market type not supported");
7481
7401
  }
7482
- if (path.extendedDetails.steamm_b_coin_a_type == null) {
7402
+ if (path.extendedDetails.steamm_btoken_a_type == null) {
7483
7403
  throw new Error("Steamm b coin a type not supported");
7484
7404
  }
7485
- if (path.extendedDetails.steamm_b_coin_b_type == null) {
7405
+ if (path.extendedDetails.steamm_btoken_b_type == null) {
7486
7406
  throw new Error("Steamm b coin b type not supported");
7487
7407
  }
7488
- if (path.extendedDetails.steamm_lp_token == null) {
7408
+ if (path.extendedDetails.steamm_lp_token_type == null) {
7489
7409
  throw new Error("Steamm lp token not supported");
7490
7410
  }
7491
7411
  if (path.extendedDetails.steamm_oracle_registry_id == null) {
@@ -7554,9 +7474,9 @@ var SteammOmm = class {
7554
7474
  path.extendedDetails.steamm_lending_market_type,
7555
7475
  coinAType,
7556
7476
  coinBType,
7557
- path.extendedDetails.steamm_b_coin_a_type,
7558
- path.extendedDetails.steamm_b_coin_b_type,
7559
- path.extendedDetails.steamm_lp_token
7477
+ path.extendedDetails.steamm_btoken_a_type,
7478
+ path.extendedDetails.steamm_btoken_b_type,
7479
+ path.extendedDetails.steamm_lp_token_type
7560
7480
  ],
7561
7481
  arguments: args
7562
7482
  });
@@ -7837,13 +7757,13 @@ var SteammOmmV2 = class {
7837
7757
  if (path.extendedDetails.steamm_lending_market_type == null) {
7838
7758
  throw new Error("Steamm lending market type not supported");
7839
7759
  }
7840
- if (path.extendedDetails.steamm_b_coin_a_type == null) {
7760
+ if (path.extendedDetails.steamm_btoken_a_type == null) {
7841
7761
  throw new Error("Steamm b coin a type not supported");
7842
7762
  }
7843
- if (path.extendedDetails.steamm_b_coin_b_type == null) {
7763
+ if (path.extendedDetails.steamm_btoken_b_type == null) {
7844
7764
  throw new Error("Steamm b coin b type not supported");
7845
7765
  }
7846
- if (path.extendedDetails.steamm_lp_token == null) {
7766
+ if (path.extendedDetails.steamm_lp_token_type == null) {
7847
7767
  throw new Error("Steamm lp token not supported");
7848
7768
  }
7849
7769
  if (path.extendedDetails.steamm_oracle_registry_id == null) {
@@ -7912,9 +7832,9 @@ var SteammOmmV2 = class {
7912
7832
  path.extendedDetails.steamm_lending_market_type,
7913
7833
  coinAType,
7914
7834
  coinBType,
7915
- path.extendedDetails.steamm_b_coin_a_type,
7916
- path.extendedDetails.steamm_b_coin_b_type,
7917
- path.extendedDetails.steamm_lp_token
7835
+ path.extendedDetails.steamm_btoken_a_type,
7836
+ path.extendedDetails.steamm_btoken_b_type,
7837
+ path.extendedDetails.steamm_lp_token_type
7918
7838
  ],
7919
7839
  arguments: args
7920
7840
  });
@@ -10677,6 +10597,10 @@ var AggregatorClientV3 = class extends AggregatorClient {
10677
10597
  throw new Error(CLIENT_CONFIG.ERRORS.QUOTE_ID_REQUIRED);
10678
10598
  }
10679
10599
  const processedData = sortAndFlattenRoutes(routerData);
10600
+ console.log(
10601
+ "processedData.flattenedPaths",
10602
+ JSON.stringify(processedData.flattenedPaths, null, 2)
10603
+ );
10680
10604
  const swapCtx = newSwapContext(
10681
10605
  {
10682
10606
  quoteID: processedData.quoteID,
@@ -11041,7 +10965,6 @@ var AggregatorClientV3 = class extends AggregatorClient {
11041
10965
  if (!this.signer) {
11042
10966
  this.signer = "0x0";
11043
10967
  }
11044
- printTransaction(tx);
11045
10968
  const simulateRes = yield this.client.devInspectTransactionBlock({
11046
10969
  transactionBlock: tx,
11047
10970
  sender: this.signer
package/dist/index.mjs CHANGED
@@ -5354,7 +5354,7 @@ var AGGREGATOR_V3_CONFIG = {
5354
5354
  "SCALLOP",
5355
5355
  "SUILEND",
5356
5356
  "SPRINGSUI",
5357
- // Phase 4: Oracle-driven Routers
5357
+ // Phase 4: Oracle-driven Routers
5358
5358
  "HAEDALPMM",
5359
5359
  "OBRIC",
5360
5360
  "SEVENK",
@@ -6087,11 +6087,12 @@ var restituteMsafeFastRouterSwapParams = (data) => {
6087
6087
  function printTransaction(tx, isPrint = true) {
6088
6088
  return __async(this, null, function* () {
6089
6089
  console.log(`inputs`, tx.getData().inputs);
6090
- let i = 0;
6091
6090
  tx.getData().commands.forEach((item, index) => {
6092
- if (isPrint && i < 15) {
6093
- console.log(`transaction ${index}: `, JSON.stringify(item, bigIntReplacer, 2));
6094
- i++;
6091
+ if (isPrint) {
6092
+ console.log(
6093
+ `transaction ${index}: `,
6094
+ JSON.stringify(item, bigIntReplacer, 2)
6095
+ );
6095
6096
  }
6096
6097
  });
6097
6098
  });
@@ -6124,7 +6125,7 @@ function parseRouterResponse(data, byAmountIn) {
6124
6125
  }
6125
6126
  }
6126
6127
  return {
6127
- quoteID: data.quote_id || "",
6128
+ quoteID: data.request_id || "",
6128
6129
  amountIn: new import_bn4.default(data.amount_in.toString()),
6129
6130
  amountOut: new import_bn4.default(data.amount_out.toString()),
6130
6131
  byAmountIn,
@@ -6384,68 +6385,27 @@ function sortAndFlattenRoutes(routerData) {
6384
6385
  }
6385
6386
  }
6386
6387
  }
6387
- for (const route of routerData.routes) {
6388
- for (let i = 0; i < route.path.length - 1; i++) {
6389
- const currentPath = route.path[i];
6390
- const nextPath = route.path[i + 1];
6391
- const currentPoolDirectionKey = createPoolDirectionKey(
6392
- currentPath.id,
6393
- currentPath.direction
6394
- );
6395
- const nextPoolDirectionKey = createPoolDirectionKey(
6396
- nextPath.id,
6397
- nextPath.direction
6398
- );
6399
- pathDependencies.get(nextPoolDirectionKey).add(currentPoolDirectionKey);
6400
- }
6401
- }
6402
- if (process.env.NODE_ENV === "development") {
6403
- console.log("Route merging dependency graph:");
6404
- for (const [poolDirectionKey, deps] of pathDependencies) {
6405
- if (deps.size > 0) {
6406
- console.log(
6407
- ` ${poolDirectionKey} depends on: [${Array.from(deps).join(", ")}]`
6408
- );
6409
- } else {
6410
- console.log(` ${poolDirectionKey} has no dependencies`);
6411
- }
6412
- }
6413
- }
6414
- const mergedPaths = /* @__PURE__ */ new Map();
6415
- for (const [poolDirectionKey, paths] of pathUsageMap) {
6416
- const firstPath = paths[0];
6417
- const totalAmountIn = paths.reduce((sum2, path) => {
6418
- return new import_bn4.default(sum2).add(new import_bn4.default(path.amountIn)).toString();
6419
- }, "0");
6420
- mergedPaths.set(poolDirectionKey, __spreadProps(__spreadValues({}, firstPath), {
6421
- amountIn: totalAmountIn
6422
- }));
6423
- }
6424
- const sortedPoolDirectionKeys = topologicalSortKahn(pathDependencies);
6425
- if (process.env.NODE_ENV === "development") {
6426
- console.log("Topological sort execution order:", sortedPoolDirectionKeys);
6427
- }
6428
6388
  const flattenedPaths = [];
6429
- let executionOrder = 0;
6430
- for (const poolDirectionKey of sortedPoolDirectionKeys) {
6431
- const path = mergedPaths.get(poolDirectionKey);
6389
+ if (routerData.routes.length !== 1) {
6390
+ console.warn(
6391
+ "Multiple routes detected, merging paths may lead to unexpected results"
6392
+ );
6393
+ }
6394
+ const paths = routerData.routes[0].path;
6395
+ for (const path of paths) {
6432
6396
  flattenedPaths.push({
6433
6397
  path,
6434
- isLastUseOfIntermediateToken: false,
6435
- // Will be set in second pass
6436
- executionOrder: executionOrder++
6398
+ isLastUseOfIntermediateToken: false
6437
6399
  });
6438
6400
  }
6439
- const lastOccurrenceIndex = /* @__PURE__ */ new Map();
6440
- for (let i = 0; i < flattenedPaths.length; i++) {
6401
+ const seenTokens = /* @__PURE__ */ new Map();
6402
+ for (let i = flattenedPaths.length - 1; i >= 0; i--) {
6441
6403
  const { from } = flattenedPaths[i].path;
6442
- if (from !== fromCoinType) {
6443
- lastOccurrenceIndex.set(from, i);
6404
+ if (from !== fromCoinType && !seenTokens.has(from)) {
6405
+ seenTokens.set(from, true);
6406
+ flattenedPaths[i].isLastUseOfIntermediateToken = true;
6444
6407
  }
6445
6408
  }
6446
- for (const [_tokenType, lastIndex] of lastOccurrenceIndex) {
6447
- flattenedPaths[lastIndex].isLastUseOfIntermediateToken = true;
6448
- }
6449
6409
  return {
6450
6410
  quoteID: routerData.quoteID || "",
6451
6411
  amountIn: routerData.amountIn,
@@ -6460,54 +6420,6 @@ function sortAndFlattenRoutes(routerData) {
6460
6420
  overlayFee: routerData.overlayFee
6461
6421
  };
6462
6422
  }
6463
- function topologicalSortKahn(dependencies) {
6464
- const inDegree = /* @__PURE__ */ new Map();
6465
- const graph = /* @__PURE__ */ new Map();
6466
- for (const [nodeId] of dependencies) {
6467
- inDegree.set(nodeId, 0);
6468
- graph.set(nodeId, /* @__PURE__ */ new Set());
6469
- }
6470
- for (const [nodeId, deps] of dependencies) {
6471
- for (const depId of deps) {
6472
- if (!graph.has(depId)) {
6473
- graph.set(depId, /* @__PURE__ */ new Set());
6474
- inDegree.set(depId, 0);
6475
- }
6476
- graph.get(depId).add(nodeId);
6477
- inDegree.set(nodeId, (inDegree.get(nodeId) || 0) + 1);
6478
- }
6479
- }
6480
- const queue = [];
6481
- for (const [nodeId, degree] of inDegree) {
6482
- if (degree === 0) {
6483
- queue.push(nodeId);
6484
- }
6485
- }
6486
- const result = [];
6487
- while (queue.length > 0) {
6488
- const nodeId = queue.shift();
6489
- result.push(nodeId);
6490
- const neighbors = graph.get(nodeId) || /* @__PURE__ */ new Set();
6491
- for (const neighbor of neighbors) {
6492
- const newDegree = inDegree.get(neighbor) - 1;
6493
- inDegree.set(neighbor, newDegree);
6494
- if (newDegree === 0) {
6495
- queue.push(neighbor);
6496
- }
6497
- }
6498
- }
6499
- if (result.length !== dependencies.size) {
6500
- const remainingNodes = Array.from(dependencies.keys()).filter(
6501
- (nodeId) => !result.includes(nodeId)
6502
- );
6503
- throw new Error(
6504
- `Circular dependency detected in route merging. Remaining nodes: ${remainingNodes.join(
6505
- ", "
6506
- )}`
6507
- );
6508
- }
6509
- return result;
6510
- }
6511
6423
 
6512
6424
  // src/utils/aggregator-config.ts
6513
6425
  var AggregatorConfig2 = class {
@@ -6911,21 +6823,29 @@ var Cetus = class {
6911
6823
  var import_bn7 = __toESM(require_bn());
6912
6824
 
6913
6825
  // src/math.ts
6914
- __toESM(require_bn());
6826
+ var import_bn6 = __toESM(require_bn());
6915
6827
  function CalculateAmountLimit(expectAmount, byAmountIn, slippage) {
6916
- let amountLimit = ZERO;
6917
- if (byAmountIn) {
6918
- amountLimit = expectAmount.muln(1 - slippage);
6919
- } else {
6920
- amountLimit = expectAmount.muln(1 + slippage);
6921
- }
6922
- return Number(amountLimit.toString());
6828
+ return Number(
6829
+ CalculateAmountLimitByDecimal(
6830
+ new decimal_default(expectAmount.toString()),
6831
+ byAmountIn,
6832
+ slippage
6833
+ ).toFixed(0)
6834
+ );
6923
6835
  }
6924
6836
  function CalculateAmountLimitBN(expectAmount, byAmountIn, slippage) {
6837
+ const amountLimit = CalculateAmountLimitByDecimal(
6838
+ new decimal_default(expectAmount.toString()),
6839
+ byAmountIn,
6840
+ slippage
6841
+ );
6842
+ return new import_bn6.default(amountLimit.toFixed(0));
6843
+ }
6844
+ function CalculateAmountLimitByDecimal(expectAmount, byAmountIn, slippage) {
6925
6845
  if (byAmountIn) {
6926
- return expectAmount.muln(1 - slippage);
6846
+ return expectAmount.mul(1 - slippage);
6927
6847
  } else {
6928
- return expectAmount.muln(1 + slippage);
6848
+ return expectAmount.mul(1 + slippage);
6929
6849
  }
6930
6850
  }
6931
6851
  function sqrtPriceX64ToPrice(sqrtPriceStr, decimalsA, decimalsB) {
@@ -7407,13 +7327,13 @@ var SteammCPMM = class {
7407
7327
  if (path.extendedDetails.steamm_lending_market_type == null) {
7408
7328
  throw new Error("Steamm lending market type not supported");
7409
7329
  }
7410
- if (path.extendedDetails.steamm_b_coin_a_type == null) {
7330
+ if (path.extendedDetails.steamm_btoken_a_type == null) {
7411
7331
  throw new Error("Steamm b coin a type not supported");
7412
7332
  }
7413
- if (path.extendedDetails.steamm_b_coin_b_type == null) {
7333
+ if (path.extendedDetails.steamm_btoken_b_type == null) {
7414
7334
  throw new Error("Steamm b coin b type not supported");
7415
7335
  }
7416
- if (path.extendedDetails.steamm_lp_token == null) {
7336
+ if (path.extendedDetails.steamm_lp_token_type == null) {
7417
7337
  throw new Error("Steamm lp token not supported");
7418
7338
  }
7419
7339
  }
@@ -7435,9 +7355,9 @@ var SteammCPMM = class {
7435
7355
  path.extendedDetails.steamm_lending_market_type,
7436
7356
  coinAType,
7437
7357
  coinBType,
7438
- path.extendedDetails.steamm_b_coin_a_type,
7439
- path.extendedDetails.steamm_b_coin_b_type,
7440
- path.extendedDetails.steamm_lp_token
7358
+ path.extendedDetails.steamm_btoken_a_type,
7359
+ path.extendedDetails.steamm_btoken_b_type,
7360
+ path.extendedDetails.steamm_lp_token_type
7441
7361
  ],
7442
7362
  arguments: args
7443
7363
  });
@@ -7473,13 +7393,13 @@ var SteammOmm = class {
7473
7393
  if (path.extendedDetails.steamm_lending_market_type == null) {
7474
7394
  throw new Error("Steamm lending market type not supported");
7475
7395
  }
7476
- if (path.extendedDetails.steamm_b_coin_a_type == null) {
7396
+ if (path.extendedDetails.steamm_btoken_a_type == null) {
7477
7397
  throw new Error("Steamm b coin a type not supported");
7478
7398
  }
7479
- if (path.extendedDetails.steamm_b_coin_b_type == null) {
7399
+ if (path.extendedDetails.steamm_btoken_b_type == null) {
7480
7400
  throw new Error("Steamm b coin b type not supported");
7481
7401
  }
7482
- if (path.extendedDetails.steamm_lp_token == null) {
7402
+ if (path.extendedDetails.steamm_lp_token_type == null) {
7483
7403
  throw new Error("Steamm lp token not supported");
7484
7404
  }
7485
7405
  if (path.extendedDetails.steamm_oracle_registry_id == null) {
@@ -7548,9 +7468,9 @@ var SteammOmm = class {
7548
7468
  path.extendedDetails.steamm_lending_market_type,
7549
7469
  coinAType,
7550
7470
  coinBType,
7551
- path.extendedDetails.steamm_b_coin_a_type,
7552
- path.extendedDetails.steamm_b_coin_b_type,
7553
- path.extendedDetails.steamm_lp_token
7471
+ path.extendedDetails.steamm_btoken_a_type,
7472
+ path.extendedDetails.steamm_btoken_b_type,
7473
+ path.extendedDetails.steamm_lp_token_type
7554
7474
  ],
7555
7475
  arguments: args
7556
7476
  });
@@ -7831,13 +7751,13 @@ var SteammOmmV2 = class {
7831
7751
  if (path.extendedDetails.steamm_lending_market_type == null) {
7832
7752
  throw new Error("Steamm lending market type not supported");
7833
7753
  }
7834
- if (path.extendedDetails.steamm_b_coin_a_type == null) {
7754
+ if (path.extendedDetails.steamm_btoken_a_type == null) {
7835
7755
  throw new Error("Steamm b coin a type not supported");
7836
7756
  }
7837
- if (path.extendedDetails.steamm_b_coin_b_type == null) {
7757
+ if (path.extendedDetails.steamm_btoken_b_type == null) {
7838
7758
  throw new Error("Steamm b coin b type not supported");
7839
7759
  }
7840
- if (path.extendedDetails.steamm_lp_token == null) {
7760
+ if (path.extendedDetails.steamm_lp_token_type == null) {
7841
7761
  throw new Error("Steamm lp token not supported");
7842
7762
  }
7843
7763
  if (path.extendedDetails.steamm_oracle_registry_id == null) {
@@ -7906,9 +7826,9 @@ var SteammOmmV2 = class {
7906
7826
  path.extendedDetails.steamm_lending_market_type,
7907
7827
  coinAType,
7908
7828
  coinBType,
7909
- path.extendedDetails.steamm_b_coin_a_type,
7910
- path.extendedDetails.steamm_b_coin_b_type,
7911
- path.extendedDetails.steamm_lp_token
7829
+ path.extendedDetails.steamm_btoken_a_type,
7830
+ path.extendedDetails.steamm_btoken_b_type,
7831
+ path.extendedDetails.steamm_lp_token_type
7912
7832
  ],
7913
7833
  arguments: args
7914
7834
  });
@@ -10671,6 +10591,10 @@ var AggregatorClientV3 = class extends AggregatorClient {
10671
10591
  throw new Error(CLIENT_CONFIG.ERRORS.QUOTE_ID_REQUIRED);
10672
10592
  }
10673
10593
  const processedData = sortAndFlattenRoutes(routerData);
10594
+ console.log(
10595
+ "processedData.flattenedPaths",
10596
+ JSON.stringify(processedData.flattenedPaths, null, 2)
10597
+ );
10674
10598
  const swapCtx = newSwapContext(
10675
10599
  {
10676
10600
  quoteID: processedData.quoteID,
@@ -11035,7 +10959,6 @@ var AggregatorClientV3 = class extends AggregatorClient {
11035
10959
  if (!this.signer) {
11036
10960
  this.signer = "0x0";
11037
10961
  }
11038
- printTransaction(tx);
11039
10962
  const simulateRes = yield this.client.devInspectTransactionBlock({
11040
10963
  transactionBlock: tx,
11041
10964
  sender: this.signer
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cetusprotocol/aggregator-sdk",
3
- "version": "0.0.0-experimental-20250723103308",
3
+ "version": "0.0.0-experimental-20250729170433",
4
4
  "sideEffects": false,
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",