@cetusprotocol/aggregator-sdk 0.0.0-experimental-20250724183511 → 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
@@ -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
@@ -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
@@ -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 {
@@ -10685,8 +10597,10 @@ var AggregatorClientV3 = class extends AggregatorClient {
10685
10597
  throw new Error(CLIENT_CONFIG.ERRORS.QUOTE_ID_REQUIRED);
10686
10598
  }
10687
10599
  const processedData = sortAndFlattenRoutes(routerData);
10688
- console.log("expectAmountOut", expectAmountOut);
10689
- console.log("amountOutLimit", amountOutLimit);
10600
+ console.log(
10601
+ "processedData.flattenedPaths",
10602
+ JSON.stringify(processedData.flattenedPaths, null, 2)
10603
+ );
10690
10604
  const swapCtx = newSwapContext(
10691
10605
  {
10692
10606
  quoteID: processedData.quoteID,
@@ -10823,9 +10737,6 @@ var AggregatorClientV3 = class extends AggregatorClient {
10823
10737
  byAmountIn,
10824
10738
  slippage
10825
10739
  );
10826
- console.log("expectedAmountOut", expectedAmountOut.toString());
10827
- console.log("expectedAmountIn", expectedAmountIn.toString());
10828
- console.log("amountLimit", amountLimit.toString());
10829
10740
  if (!params.routers.packages || !params.routers.packages.get(PACKAGE_NAMES.AGGREGATOR_V3)) {
10830
10741
  throw new Error(CLIENT_CONFIG.ERRORS.PACKAGES_REQUIRED);
10831
10742
  }
package/dist/index.mjs CHANGED
@@ -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 {
@@ -10679,8 +10591,10 @@ var AggregatorClientV3 = class extends AggregatorClient {
10679
10591
  throw new Error(CLIENT_CONFIG.ERRORS.QUOTE_ID_REQUIRED);
10680
10592
  }
10681
10593
  const processedData = sortAndFlattenRoutes(routerData);
10682
- console.log("expectAmountOut", expectAmountOut);
10683
- console.log("amountOutLimit", amountOutLimit);
10594
+ console.log(
10595
+ "processedData.flattenedPaths",
10596
+ JSON.stringify(processedData.flattenedPaths, null, 2)
10597
+ );
10684
10598
  const swapCtx = newSwapContext(
10685
10599
  {
10686
10600
  quoteID: processedData.quoteID,
@@ -10817,9 +10731,6 @@ var AggregatorClientV3 = class extends AggregatorClient {
10817
10731
  byAmountIn,
10818
10732
  slippage
10819
10733
  );
10820
- console.log("expectedAmountOut", expectedAmountOut.toString());
10821
- console.log("expectedAmountIn", expectedAmountIn.toString());
10822
- console.log("amountLimit", amountLimit.toString());
10823
10734
  if (!params.routers.packages || !params.routers.packages.get(PACKAGE_NAMES.AGGREGATOR_V3)) {
10824
10735
  throw new Error(CLIENT_CONFIG.ERRORS.PACKAGES_REQUIRED);
10825
10736
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cetusprotocol/aggregator-sdk",
3
- "version": "0.0.0-experimental-20250724183511",
3
+ "version": "0.0.0-experimental-20250729170433",
4
4
  "sideEffects": false,
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",