@cetusprotocol/aggregator-sdk 0.2.1 → 0.2.2

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/bun.lockb CHANGED
Binary file
package/dist/index.d.mts CHANGED
@@ -165,11 +165,19 @@ interface FindRouterParams {
165
165
  splitFactor?: number;
166
166
  splitCount?: number;
167
167
  providers?: string[];
168
+ liquidityChanges?: PreSwapLpChangeParams[];
169
+ }
170
+ interface PreSwapLpChangeParams {
171
+ poolID: string;
172
+ ticklower: number;
173
+ tickUpper: number;
174
+ deltaLiquidity: number;
168
175
  }
169
176
  type ExtendedDetails = {
170
177
  aftermathPoolFlatness?: number;
171
178
  aftermathLpSupplyType?: string;
172
179
  turbosFeeType?: string;
180
+ afterSqrtPrice?: string;
173
181
  };
174
182
  type Path = {
175
183
  id: string;
@@ -212,4 +220,4 @@ declare enum Env {
212
220
  Testnet = 1
213
221
  }
214
222
 
215
- export { AFSUI, AFTERMATH, AggregatorClient, type AggregatorResponse, type BuildFastRouterSwapParams, type BuildRouterSwapParams, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, type Dex, Env, type ExtendedDetails, FLOWXV2, FLOWXV3, type FindRouterParams, HAEDAL, KRIYA, KRIYAV3, ONE, type Path, type Router, type RouterData, type RouterError, type SwapInPoolsParams, type SwapInPoolsResult, TEN_POW_NINE, TURBOS, TWO, U128, U64_MAX, U64_MAX_BN, VOLO, ZERO, composeType, createTarget, dealWithFastRouterSwapParamsForMsafe, extractAddressFromType, extractStructTagFromType, fixSuiObjectId, getRouterResult, isSortedSymbols, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId, restituteMsafeFastRouterSwapParams };
223
+ export { AFSUI, AFTERMATH, AggregatorClient, type AggregatorResponse, type BuildFastRouterSwapParams, type BuildRouterSwapParams, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, type Dex, Env, type ExtendedDetails, FLOWXV2, FLOWXV3, type FindRouterParams, HAEDAL, KRIYA, KRIYAV3, ONE, type Path, type PreSwapLpChangeParams, type Router, type RouterData, type RouterError, type SwapInPoolsParams, type SwapInPoolsResult, TEN_POW_NINE, TURBOS, TWO, U128, U64_MAX, U64_MAX_BN, VOLO, ZERO, composeType, createTarget, dealWithFastRouterSwapParamsForMsafe, extractAddressFromType, extractStructTagFromType, fixSuiObjectId, getRouterResult, isSortedSymbols, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId, restituteMsafeFastRouterSwapParams };
package/dist/index.d.ts CHANGED
@@ -165,11 +165,19 @@ interface FindRouterParams {
165
165
  splitFactor?: number;
166
166
  splitCount?: number;
167
167
  providers?: string[];
168
+ liquidityChanges?: PreSwapLpChangeParams[];
169
+ }
170
+ interface PreSwapLpChangeParams {
171
+ poolID: string;
172
+ ticklower: number;
173
+ tickUpper: number;
174
+ deltaLiquidity: number;
168
175
  }
169
176
  type ExtendedDetails = {
170
177
  aftermathPoolFlatness?: number;
171
178
  aftermathLpSupplyType?: string;
172
179
  turbosFeeType?: string;
180
+ afterSqrtPrice?: string;
173
181
  };
174
182
  type Path = {
175
183
  id: string;
@@ -212,4 +220,4 @@ declare enum Env {
212
220
  Testnet = 1
213
221
  }
214
222
 
215
- export { AFSUI, AFTERMATH, AggregatorClient, type AggregatorResponse, type BuildFastRouterSwapParams, type BuildRouterSwapParams, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, type Dex, Env, type ExtendedDetails, FLOWXV2, FLOWXV3, type FindRouterParams, HAEDAL, KRIYA, KRIYAV3, ONE, type Path, type Router, type RouterData, type RouterError, type SwapInPoolsParams, type SwapInPoolsResult, TEN_POW_NINE, TURBOS, TWO, U128, U64_MAX, U64_MAX_BN, VOLO, ZERO, composeType, createTarget, dealWithFastRouterSwapParamsForMsafe, extractAddressFromType, extractStructTagFromType, fixSuiObjectId, getRouterResult, isSortedSymbols, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId, restituteMsafeFastRouterSwapParams };
223
+ export { AFSUI, AFTERMATH, AggregatorClient, type AggregatorResponse, type BuildFastRouterSwapParams, type BuildRouterSwapParams, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, type Dex, Env, type ExtendedDetails, FLOWXV2, FLOWXV3, type FindRouterParams, HAEDAL, KRIYA, KRIYAV3, ONE, type Path, type PreSwapLpChangeParams, type Router, type RouterData, type RouterError, type SwapInPoolsParams, type SwapInPoolsResult, TEN_POW_NINE, TURBOS, TWO, U128, U64_MAX, U64_MAX_BN, VOLO, ZERO, composeType, createTarget, dealWithFastRouterSwapParamsForMsafe, extractAddressFromType, extractStructTagFromType, fixSuiObjectId, getRouterResult, isSortedSymbols, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId, restituteMsafeFastRouterSwapParams };
package/dist/index.js CHANGED
@@ -5207,7 +5207,7 @@ var Turbos = class {
5207
5207
  var Cetus = class {
5208
5208
  constructor(env, partner) {
5209
5209
  this.globalConfig = env === 0 /* Mainnet */ ? "0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f" : "0x6f4149091a5aea0e818e7243a13adcfb403842d670b9a2089de058512620687a";
5210
- this.partner = partner != null ? partner : "0x639b5e433da31739e800cd085f356e64cae222966d0f1b11bd9dc76b322ff58b";
5210
+ this.partner = (partner != null ? partner : env === 0 /* Mainnet */) ? "0x639b5e433da31739e800cd085f356e64cae222966d0f1b11bd9dc76b322ff58b" : "0x8e0b7668a79592f70fbfb1ae0aebaf9e2019a7049783b9a4b6fe7c6ae038b528";
5211
5211
  }
5212
5212
  flash_swap(client, txb, path, by_amount_in) {
5213
5213
  const { direction, from, target } = path;
@@ -5797,7 +5797,10 @@ function swapInPools(client, params, sender) {
5797
5797
  target: targetCoin,
5798
5798
  feeRate: event.fee_rate,
5799
5799
  amountIn: event.amount_in,
5800
- amountOut: event.amount_out
5800
+ amountOut: event.amount_out,
5801
+ extendedDetails: {
5802
+ afterSqrtPrice: event.after_sqrt_price
5803
+ }
5801
5804
  }
5802
5805
  ],
5803
5806
  amountIn: new import_bn4.BN((_d = event.amount_in) != null ? _d : 0),
@@ -6217,7 +6220,7 @@ var AggregatorClient6 = class {
6217
6220
  if (this.env === 0 /* Mainnet */) {
6218
6221
  return "0xeffc8ae61f439bb34c9b905ff8f29ec56873dcedf81c7123ff2f1f67c45ec302";
6219
6222
  } else {
6220
- return "0x0";
6223
+ return "0x6cbaa3e9fbe902d90191b12f315932bc58079cba422bafbd4b4369f80e61f595";
6221
6224
  }
6222
6225
  }
6223
6226
  transferOrDestoryCoin(txb, coin, coinType) {
@@ -6315,16 +6318,17 @@ function parseRouterResponse(data) {
6315
6318
  routes: data.routes.map((route) => {
6316
6319
  return {
6317
6320
  path: route.path.map((path) => {
6318
- var _a, _b;
6321
+ var _a, _b, _c;
6319
6322
  let version;
6320
6323
  if (path.provider === AFTERMATH) {
6321
6324
  version = path.extended_details.aftermath_pool_flatness === 0 ? "v2" : "v3";
6322
6325
  }
6323
6326
  let extendedDetails;
6324
- if (path.provider === TURBOS || path.provider === AFTERMATH) {
6327
+ if (path.provider === TURBOS || path.provider === AFTERMATH || path.provider === CETUS) {
6325
6328
  extendedDetails = {
6326
6329
  aftermathLpSupplyType: (_a = path.extended_details) == null ? void 0 : _a.aftermath_lp_supply_type,
6327
- turbosFeeType: (_b = path.extended_details) == null ? void 0 : _b.turbos_fee_type
6330
+ turbosFeeType: (_b = path.extended_details) == null ? void 0 : _b.turbos_fee_type,
6331
+ afterSqrtPrice: (_c = path.extended_details) == null ? void 0 : _c.after_sqrt_price
6328
6332
  };
6329
6333
  }
6330
6334
  return {
@@ -6379,38 +6383,15 @@ var restituteMsafeFastRouterSwapParams = (data) => {
6379
6383
  // src/api.ts
6380
6384
  function getRouterResult(endpoint, params) {
6381
6385
  return __async(this, null, function* () {
6382
- const {
6383
- from,
6384
- target,
6385
- amount,
6386
- byAmountIn,
6387
- depth,
6388
- splitAlgorithm,
6389
- splitFactor,
6390
- splitCount,
6391
- providers
6392
- } = params;
6393
- const fromCoin = completionCoin(from);
6394
- const targetCoin = completionCoin(target);
6395
- let url = `${endpoint}?from=${fromCoin}&target=${targetCoin}&amount=${amount.toString()}&by_amount_in=${byAmountIn}`;
6396
- if (depth) {
6397
- url += `&depth=${depth}`;
6398
- }
6399
- if (splitAlgorithm) {
6400
- url += `&split_algorithm=${splitAlgorithm}`;
6401
- }
6402
- if (splitFactor) {
6403
- url += `&split_factor=${splitFactor}`;
6404
- }
6405
- if (splitCount) {
6406
- url += `&split_count=${splitCount}`;
6386
+ let response;
6387
+ if (params.liquidityChanges && params.liquidityChanges.length > 0) {
6388
+ response = yield postRouterWithLiquidityChanges(endpoint, params);
6389
+ } else {
6390
+ response = yield getRouter(endpoint, params);
6407
6391
  }
6408
- if (providers) {
6409
- if (providers.length > 0) {
6410
- url += `&providers=${providers.join(",")}`;
6411
- }
6392
+ if (!response) {
6393
+ return null;
6412
6394
  }
6413
- const response = yield fetch(url);
6414
6395
  if (!response.ok) {
6415
6396
  return {
6416
6397
  amountIn: ZERO,
@@ -6445,6 +6426,99 @@ function getRouterResult(endpoint, params) {
6445
6426
  };
6446
6427
  });
6447
6428
  }
6429
+ function getRouter(endpoint, params) {
6430
+ return __async(this, null, function* () {
6431
+ try {
6432
+ const {
6433
+ from,
6434
+ target,
6435
+ amount,
6436
+ byAmountIn,
6437
+ depth,
6438
+ splitAlgorithm,
6439
+ splitFactor,
6440
+ splitCount,
6441
+ providers
6442
+ } = params;
6443
+ const fromCoin = completionCoin(from);
6444
+ const targetCoin = completionCoin(target);
6445
+ let url = `${endpoint}?from=${fromCoin}&target=${targetCoin}&amount=${amount.toString()}&by_amount_in=${byAmountIn}`;
6446
+ if (depth) {
6447
+ url += `&depth=${depth}`;
6448
+ }
6449
+ if (splitAlgorithm) {
6450
+ url += `&split_algorithm=${splitAlgorithm}`;
6451
+ }
6452
+ if (splitFactor) {
6453
+ url += `&split_factor=${splitFactor}`;
6454
+ }
6455
+ if (splitCount) {
6456
+ url += `&split_count=${splitCount}`;
6457
+ }
6458
+ if (providers) {
6459
+ if (providers.length > 0) {
6460
+ url += `&providers=${providers.join(",")}`;
6461
+ }
6462
+ }
6463
+ const response = yield fetch(url);
6464
+ return response;
6465
+ } catch (error) {
6466
+ console.error(error);
6467
+ return null;
6468
+ }
6469
+ });
6470
+ }
6471
+ function postRouterWithLiquidityChanges(endpoint, params) {
6472
+ return __async(this, null, function* () {
6473
+ const {
6474
+ from,
6475
+ target,
6476
+ amount,
6477
+ byAmountIn,
6478
+ depth,
6479
+ splitAlgorithm,
6480
+ splitFactor,
6481
+ splitCount,
6482
+ providers,
6483
+ liquidityChanges
6484
+ } = params;
6485
+ const fromCoin = completionCoin(from);
6486
+ const targetCoin = completionCoin(target);
6487
+ const url = `${endpoint}`;
6488
+ const providersStr = providers == null ? void 0 : providers.join(",");
6489
+ const requestData = {
6490
+ from: fromCoin,
6491
+ target: targetCoin,
6492
+ amount: Number(amount.toString()),
6493
+ by_amount_in: byAmountIn,
6494
+ depth,
6495
+ split_algorithm: splitAlgorithm,
6496
+ split_factor: splitFactor,
6497
+ split_count: splitCount,
6498
+ providers: providersStr,
6499
+ liquidity_changes: liquidityChanges.map((change) => ({
6500
+ pool: change.poolID,
6501
+ tick_lower: change.ticklower,
6502
+ tick_upper: change.tickUpper,
6503
+ delta_liquidity: change.deltaLiquidity
6504
+ }))
6505
+ };
6506
+ console.log("requestData", JSON.stringify(requestData, null, 2));
6507
+ try {
6508
+ const response = yield fetch(url, {
6509
+ method: "POST",
6510
+ headers: {
6511
+ "Content-Type": "application/json"
6512
+ },
6513
+ body: JSON.stringify(requestData)
6514
+ });
6515
+ return response;
6516
+ } catch (error) {
6517
+ console.error("Error:", error);
6518
+ return null;
6519
+ }
6520
+ });
6521
+ }
6448
6522
 
6449
6523
  // src/index.ts
6450
6524
  var Env = /* @__PURE__ */ ((Env2) => {
package/dist/index.mjs CHANGED
@@ -5205,7 +5205,7 @@ var Turbos = class {
5205
5205
  var Cetus = class {
5206
5206
  constructor(env, partner) {
5207
5207
  this.globalConfig = env === 0 /* Mainnet */ ? "0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f" : "0x6f4149091a5aea0e818e7243a13adcfb403842d670b9a2089de058512620687a";
5208
- this.partner = partner != null ? partner : "0x639b5e433da31739e800cd085f356e64cae222966d0f1b11bd9dc76b322ff58b";
5208
+ this.partner = (partner != null ? partner : env === 0 /* Mainnet */) ? "0x639b5e433da31739e800cd085f356e64cae222966d0f1b11bd9dc76b322ff58b" : "0x8e0b7668a79592f70fbfb1ae0aebaf9e2019a7049783b9a4b6fe7c6ae038b528";
5209
5209
  }
5210
5210
  flash_swap(client, txb, path, by_amount_in) {
5211
5211
  const { direction, from, target } = path;
@@ -5795,7 +5795,10 @@ function swapInPools(client, params, sender) {
5795
5795
  target: targetCoin,
5796
5796
  feeRate: event.fee_rate,
5797
5797
  amountIn: event.amount_in,
5798
- amountOut: event.amount_out
5798
+ amountOut: event.amount_out,
5799
+ extendedDetails: {
5800
+ afterSqrtPrice: event.after_sqrt_price
5801
+ }
5799
5802
  }
5800
5803
  ],
5801
5804
  amountIn: new import_bn4.BN((_d = event.amount_in) != null ? _d : 0),
@@ -6215,7 +6218,7 @@ var AggregatorClient6 = class {
6215
6218
  if (this.env === 0 /* Mainnet */) {
6216
6219
  return "0xeffc8ae61f439bb34c9b905ff8f29ec56873dcedf81c7123ff2f1f67c45ec302";
6217
6220
  } else {
6218
- return "0x0";
6221
+ return "0x6cbaa3e9fbe902d90191b12f315932bc58079cba422bafbd4b4369f80e61f595";
6219
6222
  }
6220
6223
  }
6221
6224
  transferOrDestoryCoin(txb, coin, coinType) {
@@ -6313,16 +6316,17 @@ function parseRouterResponse(data) {
6313
6316
  routes: data.routes.map((route) => {
6314
6317
  return {
6315
6318
  path: route.path.map((path) => {
6316
- var _a, _b;
6319
+ var _a, _b, _c;
6317
6320
  let version;
6318
6321
  if (path.provider === AFTERMATH) {
6319
6322
  version = path.extended_details.aftermath_pool_flatness === 0 ? "v2" : "v3";
6320
6323
  }
6321
6324
  let extendedDetails;
6322
- if (path.provider === TURBOS || path.provider === AFTERMATH) {
6325
+ if (path.provider === TURBOS || path.provider === AFTERMATH || path.provider === CETUS) {
6323
6326
  extendedDetails = {
6324
6327
  aftermathLpSupplyType: (_a = path.extended_details) == null ? void 0 : _a.aftermath_lp_supply_type,
6325
- turbosFeeType: (_b = path.extended_details) == null ? void 0 : _b.turbos_fee_type
6328
+ turbosFeeType: (_b = path.extended_details) == null ? void 0 : _b.turbos_fee_type,
6329
+ afterSqrtPrice: (_c = path.extended_details) == null ? void 0 : _c.after_sqrt_price
6326
6330
  };
6327
6331
  }
6328
6332
  return {
@@ -6377,38 +6381,15 @@ var restituteMsafeFastRouterSwapParams = (data) => {
6377
6381
  // src/api.ts
6378
6382
  function getRouterResult(endpoint, params) {
6379
6383
  return __async(this, null, function* () {
6380
- const {
6381
- from,
6382
- target,
6383
- amount,
6384
- byAmountIn,
6385
- depth,
6386
- splitAlgorithm,
6387
- splitFactor,
6388
- splitCount,
6389
- providers
6390
- } = params;
6391
- const fromCoin = completionCoin(from);
6392
- const targetCoin = completionCoin(target);
6393
- let url = `${endpoint}?from=${fromCoin}&target=${targetCoin}&amount=${amount.toString()}&by_amount_in=${byAmountIn}`;
6394
- if (depth) {
6395
- url += `&depth=${depth}`;
6396
- }
6397
- if (splitAlgorithm) {
6398
- url += `&split_algorithm=${splitAlgorithm}`;
6399
- }
6400
- if (splitFactor) {
6401
- url += `&split_factor=${splitFactor}`;
6402
- }
6403
- if (splitCount) {
6404
- url += `&split_count=${splitCount}`;
6384
+ let response;
6385
+ if (params.liquidityChanges && params.liquidityChanges.length > 0) {
6386
+ response = yield postRouterWithLiquidityChanges(endpoint, params);
6387
+ } else {
6388
+ response = yield getRouter(endpoint, params);
6405
6389
  }
6406
- if (providers) {
6407
- if (providers.length > 0) {
6408
- url += `&providers=${providers.join(",")}`;
6409
- }
6390
+ if (!response) {
6391
+ return null;
6410
6392
  }
6411
- const response = yield fetch(url);
6412
6393
  if (!response.ok) {
6413
6394
  return {
6414
6395
  amountIn: ZERO,
@@ -6443,6 +6424,99 @@ function getRouterResult(endpoint, params) {
6443
6424
  };
6444
6425
  });
6445
6426
  }
6427
+ function getRouter(endpoint, params) {
6428
+ return __async(this, null, function* () {
6429
+ try {
6430
+ const {
6431
+ from,
6432
+ target,
6433
+ amount,
6434
+ byAmountIn,
6435
+ depth,
6436
+ splitAlgorithm,
6437
+ splitFactor,
6438
+ splitCount,
6439
+ providers
6440
+ } = params;
6441
+ const fromCoin = completionCoin(from);
6442
+ const targetCoin = completionCoin(target);
6443
+ let url = `${endpoint}?from=${fromCoin}&target=${targetCoin}&amount=${amount.toString()}&by_amount_in=${byAmountIn}`;
6444
+ if (depth) {
6445
+ url += `&depth=${depth}`;
6446
+ }
6447
+ if (splitAlgorithm) {
6448
+ url += `&split_algorithm=${splitAlgorithm}`;
6449
+ }
6450
+ if (splitFactor) {
6451
+ url += `&split_factor=${splitFactor}`;
6452
+ }
6453
+ if (splitCount) {
6454
+ url += `&split_count=${splitCount}`;
6455
+ }
6456
+ if (providers) {
6457
+ if (providers.length > 0) {
6458
+ url += `&providers=${providers.join(",")}`;
6459
+ }
6460
+ }
6461
+ const response = yield fetch(url);
6462
+ return response;
6463
+ } catch (error) {
6464
+ console.error(error);
6465
+ return null;
6466
+ }
6467
+ });
6468
+ }
6469
+ function postRouterWithLiquidityChanges(endpoint, params) {
6470
+ return __async(this, null, function* () {
6471
+ const {
6472
+ from,
6473
+ target,
6474
+ amount,
6475
+ byAmountIn,
6476
+ depth,
6477
+ splitAlgorithm,
6478
+ splitFactor,
6479
+ splitCount,
6480
+ providers,
6481
+ liquidityChanges
6482
+ } = params;
6483
+ const fromCoin = completionCoin(from);
6484
+ const targetCoin = completionCoin(target);
6485
+ const url = `${endpoint}`;
6486
+ const providersStr = providers == null ? void 0 : providers.join(",");
6487
+ const requestData = {
6488
+ from: fromCoin,
6489
+ target: targetCoin,
6490
+ amount: Number(amount.toString()),
6491
+ by_amount_in: byAmountIn,
6492
+ depth,
6493
+ split_algorithm: splitAlgorithm,
6494
+ split_factor: splitFactor,
6495
+ split_count: splitCount,
6496
+ providers: providersStr,
6497
+ liquidity_changes: liquidityChanges.map((change) => ({
6498
+ pool: change.poolID,
6499
+ tick_lower: change.ticklower,
6500
+ tick_upper: change.tickUpper,
6501
+ delta_liquidity: change.deltaLiquidity
6502
+ }))
6503
+ };
6504
+ console.log("requestData", JSON.stringify(requestData, null, 2));
6505
+ try {
6506
+ const response = yield fetch(url, {
6507
+ method: "POST",
6508
+ headers: {
6509
+ "Content-Type": "application/json"
6510
+ },
6511
+ body: JSON.stringify(requestData)
6512
+ });
6513
+ return response;
6514
+ } catch (error) {
6515
+ console.error("Error:", error);
6516
+ return null;
6517
+ }
6518
+ });
6519
+ }
6446
6520
 
6447
6521
  // src/index.ts
6448
6522
  var Env = /* @__PURE__ */ ((Env2) => {
package/dist/src/api.d.ts CHANGED
@@ -10,11 +10,19 @@ export interface FindRouterParams {
10
10
  splitFactor?: number;
11
11
  splitCount?: number;
12
12
  providers?: string[];
13
+ liquidityChanges?: PreSwapLpChangeParams[];
14
+ }
15
+ export interface PreSwapLpChangeParams {
16
+ poolID: string;
17
+ ticklower: number;
18
+ tickUpper: number;
19
+ deltaLiquidity: number;
13
20
  }
14
21
  export type ExtendedDetails = {
15
22
  aftermathPoolFlatness?: number;
16
23
  aftermathLpSupplyType?: string;
17
24
  turbosFeeType?: string;
25
+ afterSqrtPrice?: string;
18
26
  };
19
27
  export type Path = {
20
28
  id: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cetusprotocol/aggregator-sdk",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "sideEffects": false,
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/api.ts CHANGED
@@ -18,12 +18,21 @@ export interface FindRouterParams {
18
18
  splitFactor?: number
19
19
  splitCount?: number
20
20
  providers?: string[]
21
+ liquidityChanges?: PreSwapLpChangeParams[]
22
+ }
23
+
24
+ export interface PreSwapLpChangeParams {
25
+ poolID: string
26
+ ticklower: number
27
+ tickUpper: number
28
+ deltaLiquidity: number
21
29
  }
22
30
 
23
31
  export type ExtendedDetails = {
24
32
  aftermathPoolFlatness?: number
25
33
  aftermathLpSupplyType?: string
26
34
  turbosFeeType?: string
35
+ afterSqrtPrice?: string
27
36
  }
28
37
 
29
38
  export type Path = {
@@ -69,45 +78,17 @@ export async function getRouterResult(
69
78
  endpoint: string,
70
79
  params: FindRouterParams
71
80
  ): Promise<RouterData | null> {
72
- const {
73
- from,
74
- target,
75
- amount,
76
- byAmountIn,
77
- depth,
78
- splitAlgorithm,
79
- splitFactor,
80
- splitCount,
81
- providers,
82
- } = params
83
- const fromCoin = completionCoin(from)
84
- const targetCoin = completionCoin(target)
85
-
86
- let url = `${endpoint}?from=${fromCoin}&target=${targetCoin}&amount=${amount.toString()}&by_amount_in=${byAmountIn}`
87
-
88
- if (depth) {
89
- url += `&depth=${depth}`
81
+ let response
82
+ if (params.liquidityChanges && params.liquidityChanges.length > 0) {
83
+ response = await postRouterWithLiquidityChanges(endpoint, params)
84
+ } else {
85
+ response = await getRouter(endpoint, params)
90
86
  }
91
87
 
92
- if (splitAlgorithm) {
93
- url += `&split_algorithm=${splitAlgorithm}`
88
+ if (!response) {
89
+ return null
94
90
  }
95
91
 
96
- if (splitFactor) {
97
- url += `&split_factor=${splitFactor}`
98
- }
99
-
100
- if (splitCount) {
101
- url += `&split_count=${splitCount}`
102
- }
103
-
104
- if (providers) {
105
- if (providers.length > 0) {
106
- url += `&providers=${providers.join(",")}`
107
- }
108
- }
109
-
110
- const response = await fetch(url)
111
92
  if (!response.ok) {
112
93
  return {
113
94
  amountIn: ZERO,
@@ -142,3 +123,111 @@ export async function getRouterResult(
142
123
  },
143
124
  }
144
125
  }
126
+
127
+ async function getRouter(endpoint: string, params: FindRouterParams) {
128
+ try {
129
+ const {
130
+ from,
131
+ target,
132
+ amount,
133
+ byAmountIn,
134
+ depth,
135
+ splitAlgorithm,
136
+ splitFactor,
137
+ splitCount,
138
+ providers,
139
+ } = params
140
+ const fromCoin = completionCoin(from)
141
+ const targetCoin = completionCoin(target)
142
+
143
+ let url = `${endpoint}?from=${fromCoin}&target=${targetCoin}&amount=${amount.toString()}&by_amount_in=${byAmountIn}`
144
+
145
+ if (depth) {
146
+ url += `&depth=${depth}`
147
+ }
148
+
149
+ if (splitAlgorithm) {
150
+ url += `&split_algorithm=${splitAlgorithm}`
151
+ }
152
+
153
+ if (splitFactor) {
154
+ url += `&split_factor=${splitFactor}`
155
+ }
156
+
157
+ if (splitCount) {
158
+ url += `&split_count=${splitCount}`
159
+ }
160
+
161
+ if (providers) {
162
+ if (providers.length > 0) {
163
+ url += `&providers=${providers.join(",")}`
164
+ }
165
+ }
166
+
167
+ const response = await fetch(url)
168
+ return response
169
+ } catch (error) {
170
+ console.error(error)
171
+ return null
172
+ }
173
+ }
174
+
175
+ async function postRouterWithLiquidityChanges(
176
+ endpoint: string,
177
+ params: FindRouterParams
178
+ ) {
179
+ const {
180
+ from,
181
+ target,
182
+ amount,
183
+ byAmountIn,
184
+ depth,
185
+ splitAlgorithm,
186
+ splitFactor,
187
+ splitCount,
188
+ providers,
189
+ liquidityChanges,
190
+ } = params
191
+
192
+ const fromCoin = completionCoin(from)
193
+ const targetCoin = completionCoin(target)
194
+
195
+ const url = `${endpoint}`
196
+
197
+ const providersStr = providers?.join(",")
198
+
199
+ const requestData = {
200
+ from: fromCoin,
201
+ target: targetCoin,
202
+ amount: Number(amount.toString()),
203
+ by_amount_in: byAmountIn,
204
+ depth,
205
+ split_algorithm: splitAlgorithm,
206
+ split_factor: splitFactor,
207
+ split_count: splitCount,
208
+ providers: providersStr,
209
+ liquidity_changes: liquidityChanges!.map((change) => ({
210
+ pool: change.poolID,
211
+ tick_lower: change.ticklower,
212
+ tick_upper: change.tickUpper,
213
+ delta_liquidity: change.deltaLiquidity,
214
+ })),
215
+ }
216
+
217
+ console.log("requestData", JSON.stringify(requestData, null, 2))
218
+
219
+ try {
220
+ const response = await fetch(url, {
221
+ method: "POST",
222
+ headers: {
223
+ "Content-Type": "application/json",
224
+ },
225
+ body: JSON.stringify(requestData),
226
+ })
227
+
228
+ return response
229
+ } catch (error) {
230
+ console.error("Error:", error)
231
+ return null
232
+ }
233
+ }
package/src/client.ts CHANGED
@@ -337,7 +337,7 @@ export class AggregatorClient {
337
337
  if (this.env === Env.Mainnet) {
338
338
  return "0xeffc8ae61f439bb34c9b905ff8f29ec56873dcedf81c7123ff2f1f67c45ec302"
339
339
  } else {
340
- return "0x0"
340
+ return "0x6cbaa3e9fbe902d90191b12f315932bc58079cba422bafbd4b4369f80e61f595"
341
341
  }
342
342
  }
343
343
 
@@ -454,11 +454,16 @@ export function parseRouterResponse(data: any): RouterData {
454
454
  }
455
455
 
456
456
  let extendedDetails
457
- if (path.provider === TURBOS || path.provider === AFTERMATH) {
457
+ if (
458
+ path.provider === TURBOS ||
459
+ path.provider === AFTERMATH ||
460
+ path.provider === CETUS
461
+ ) {
458
462
  extendedDetails = {
459
463
  aftermathLpSupplyType:
460
464
  path.extended_details?.aftermath_lp_supply_type,
461
465
  turbosFeeType: path.extended_details?.turbos_fee_type,
466
+ afterSqrtPrice: path.extended_details?.after_sqrt_price,
462
467
  }
463
468
  }
464
469
 
@@ -22,8 +22,9 @@ export class Cetus implements Dex {
22
22
  : "0x6f4149091a5aea0e818e7243a13adcfb403842d670b9a2089de058512620687a"
23
23
 
24
24
  this.partner =
25
- partner ??
26
- "0x639b5e433da31739e800cd085f356e64cae222966d0f1b11bd9dc76b322ff58b"
25
+ partner ?? env === Env.Mainnet
26
+ ? "0x639b5e433da31739e800cd085f356e64cae222966d0f1b11bd9dc76b322ff58b"
27
+ : "0x8e0b7668a79592f70fbfb1ae0aebaf9e2019a7049783b9a4b6fe7c6ae038b528"
27
28
  }
28
29
 
29
30
  flash_swap(
@@ -131,6 +131,9 @@ export async function swapInPools(
131
131
  feeRate: event.fee_rate,
132
132
  amountIn: event.amount_in,
133
133
  amountOut: event.amount_out,
134
+ extendedDetails: {
135
+ afterSqrtPrice: event.after_sqrt_price,
136
+ },
134
137
  },
135
138
  ],
136
139
  amountIn: new BN(event.amount_in ?? 0),
@@ -1,7 +1,14 @@
1
1
  import { describe, test } from "@jest/globals"
2
2
  import dotenv from "dotenv"
3
3
  import { AggregatorClient } from "~/client"
4
- import { M_CETUS, M_NAVI, M_SSWP, M_SUI, M_USDC } from "./test_data.test"
4
+ import {
5
+ M_CETUS,
6
+ M_HASUI,
7
+ M_NAVI,
8
+ M_SSWP,
9
+ M_SUI,
10
+ M_USDC,
11
+ } from "./test_data.test"
5
12
  import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519"
6
13
  import { printTransaction } from "~/utils/transaction"
7
14
  import BN from "bn.js"
@@ -116,7 +123,7 @@ describe("router module", () => {
116
123
  byAmountIn: true,
117
124
  depth: 3,
118
125
  splitCount: 1,
119
- // providers: ["CETUS"],
126
+ providers: ["CETUS"],
120
127
  })
121
128
 
122
129
  if (res != null) {
@@ -290,4 +297,88 @@ describe("router module", () => {
290
297
  }
291
298
  }
292
299
  }, 60000000)
300
+
301
+ test("Build router with liquidity changes", async () => {
302
+ const byAmountIn = true
303
+ const amount = "1000000000"
304
+
305
+ // const from = M_USDC
306
+ // const target = M_SUI
307
+
308
+ const from = M_SUI
309
+ // const target =
310
+ // "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI"
311
+ // const target =
312
+ // "0xf325ce1300e8dac124071d3152c5c5ee6174914f8bc2161e88329cf579246efc::afsui::AFSUI"
313
+
314
+ const target = M_HASUI
315
+
316
+ const res = await client.findRouters({
317
+ from,
318
+ target,
319
+ amount: new BN(amount),
320
+ byAmountIn,
321
+ depth: 2,
322
+ providers: [
323
+ "CETUS",
324
+ // "DEEPBOOK",
325
+ // "AFTERMATH",
326
+ // "FLOWX",
327
+ // "KRIYA",
328
+ // "KRIYAV3",
329
+ // "TURBOS",
330
+ // "FLOWXV3",
331
+ ],
332
+ liquidityChanges: [
333
+ {
334
+ poolID:
335
+ "0x871d8a227114f375170f149f7e9d45be822dd003eba225e83c05ac80828596bc",
336
+ ticklower: 100,
337
+ tickUpper: 394,
338
+ deltaLiquidity: -5498684,
339
+ },
340
+ {
341
+ poolID:
342
+ "0x871d8a227114f375170f149f7e9d45be822dd003eba225e83c05ac80828596bc",
343
+ ticklower: 100,
344
+ tickUpper: 394,
345
+ deltaLiquidity: 986489,
346
+ },
347
+ ],
348
+ })
349
+
350
+ if (res != null) {
351
+ console.log(JSON.stringify(res, null, 2))
352
+ }
353
+
354
+ console.log("amount in", res?.amountIn.toString())
355
+ console.log("amount out", res?.amountOut.toString())
356
+
357
+ const txb = new Transaction()
358
+
359
+ if (res != null) {
360
+ console.log(JSON.stringify(res, null, 2))
361
+ await client.fastRouterSwap({
362
+ routers: res.routes,
363
+ byAmountIn,
364
+ txb,
365
+ slippage: 0.01,
366
+ isMergeTragetCoin: false,
367
+ refreshAllCoins: true,
368
+ })
369
+
370
+ printTransaction(txb)
371
+
372
+ let result = await client.devInspectTransactionBlock(txb)
373
+ console.log("🚀 ~ file: router.test.ts:180 ~ test ~ result:", result)
374
+
375
+ // if (result.effects.status.status === "success") {
376
+ // console.log("Sim exec transaction success")
377
+ // const result = await client.signAndExecuteTransaction(txb, keypair)
378
+ // // console.log("result", result)
379
+ // } else {
380
+ // console.log("result", result)
381
+ // }
382
+ }
383
+ }, 600000)
293
384
  })