@cetusprotocol/aggregator-sdk 0.3.1 → 0.3.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/dist/index.mjs CHANGED
@@ -1,3 +1,4 @@
1
+ import { SuiClient, getFullnodeUrl } from '@mysten/sui/client';
1
2
  import { normalizeSuiObjectId, SUI_FRAMEWORK_ADDRESS } from '@mysten/sui/utils';
2
3
  import { Transaction } from '@mysten/sui/transactions';
3
4
 
@@ -5674,8 +5675,8 @@ function buildInputCoin(txb, allCoins, amount, coinType) {
5674
5675
  let totalCoinBalance = CoinUtils.calculateTotalBalance(usedCoinAsests);
5675
5676
  if (totalCoinBalance < amount) {
5676
5677
  throw new AggregateError(
5677
- "Insufficient balance when build merge coin",
5678
- "InsufficientBalance" /* InsufficientBalance */
5678
+ "Insufficient balance when build merge coin, coinType: " + coinType,
5679
+ "InsufficientBalance" /* InsufficientBalance */ + coinType
5679
5680
  );
5680
5681
  }
5681
5682
  if (CoinUtils.isSuiCoin(coinType)) {
@@ -5712,6 +5713,16 @@ function buildInputCoin(txb, allCoins, amount, coinType) {
5712
5713
  }
5713
5714
 
5714
5715
  // src/utils/transaction.ts
5716
+ function printTransaction(tx, isPrint = true) {
5717
+ return __async(this, null, function* () {
5718
+ console.log(`inputs`, tx.getData().inputs);
5719
+ tx.getData().commands.forEach((item, index) => {
5720
+ if (isPrint) {
5721
+ console.log(`transaction ${index}: `, JSON.stringify(item, null, 2));
5722
+ }
5723
+ });
5724
+ });
5725
+ }
5715
5726
  function checkInvalidSuiAddress(address) {
5716
5727
  if (!address.startsWith("0x") || address.length !== 66) {
5717
5728
  return false;
@@ -5763,6 +5774,8 @@ function swapInPools(client, params, sender) {
5763
5774
  const coinA = direction ? fromCoin : targetCoin;
5764
5775
  const coinB = direction ? targetCoin : fromCoin;
5765
5776
  const typeArguments = [coinA, coinB];
5777
+ console.log("typeArguments", typeArguments);
5778
+ console.log("pools", pools);
5766
5779
  for (let i = 0; i < pools.length; i++) {
5767
5780
  const args = [
5768
5781
  tx.object(pools[i]),
@@ -5787,6 +5800,7 @@ function swapInPools(client, params, sender) {
5787
5800
  sender
5788
5801
  });
5789
5802
  if (simulateRes.error != null) {
5803
+ console.log("simulateRes.error", simulateRes.error);
5790
5804
  throw new AggregateError(
5791
5805
  "Aggregator package not set",
5792
5806
  "SimulateError" /* SimulateError */
@@ -5993,23 +6007,27 @@ var Bluemove = class {
5993
6007
  // src/transaction/deepbook_v3.ts
5994
6008
  var DeepbookV3 = class {
5995
6009
  constructor(env) {
5996
- this.deepbookV3Config = env === 0 /* Mainnet */ ? "0x0" : "0x77018927a5d7ed7b4c49312b71581f5f12ba52ba7e1219a15181ffc3d459f527";
5997
- this.deepCoinType = env === 0 /* Mainnet */ ? "0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP" : "0x36dbef866a1d62bf7328989a10fb2f07d769f4ee587c0de4a0a256e57e0a58a8::deep::DEEP";
6010
+ this.deepbookV3Config = env === 0 /* Mainnet */ ? "0xe4099d0cda04f3aa80028fac91a9b3dbe50d08f2ff42aa2c29473926e34ca48c" : "0xe19b5d072346cae83a037d4e3c8492068a74410a74e5830b3a68012db38296aa";
5998
6011
  }
5999
- swap(client, txb, path, inputCoin) {
6012
+ swap(client, txb, path, inputCoin, deepbookv3DeepFee) {
6000
6013
  return __async(this, null, function* () {
6001
6014
  const { direction, from, target } = path;
6002
6015
  const [func, coinAType, coinBType] = direction ? ["swap_a2b", from, target] : ["swap_b2a", target, from];
6003
- const zeroDeep = mintZeroCoin(txb, this.deepCoinType);
6016
+ let deepFee;
6017
+ if (deepbookv3DeepFee) {
6018
+ deepFee = deepbookv3DeepFee;
6019
+ } else {
6020
+ deepFee = mintZeroCoin(txb, client.deepbookv3DeepFeeType());
6021
+ }
6004
6022
  const args = [
6005
6023
  txb.object(this.deepbookV3Config),
6006
6024
  txb.object(path.id),
6007
6025
  inputCoin,
6008
- zeroDeep,
6026
+ deepFee,
6009
6027
  txb.object(CLOCK_ADDRESS)
6010
6028
  ];
6011
6029
  const res = txb.moveCall({
6012
- target: `${client.publishedAt()}::deepbookv3::${func}`,
6030
+ target: `${client.publishedAtV2()}::deepbookv3::${func}`,
6013
6031
  typeArguments: [coinAType, coinBType],
6014
6032
  arguments: args
6015
6033
  });
@@ -6032,16 +6050,20 @@ var VOLO = "VOLO";
6032
6050
  var AFSUI = "AFSUI";
6033
6051
  var BLUEMOVE = "BLUEMOVE";
6034
6052
  var DEEPBOOKV3 = "DEEPBOOKV3";
6053
+ var DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
6035
6054
  var AggregatorClient7 = class {
6036
6055
  constructor(endpoint, signer, client, env) {
6037
- this.endpoint = endpoint;
6038
- this.client = client;
6039
- this.signer = signer;
6040
- this.env = env;
6056
+ this.endpoint = endpoint ? processEndpoint(endpoint) : DEFAULT_ENDPOINT;
6057
+ this.client = client || new SuiClient({ url: getFullnodeUrl("mainnet") });
6058
+ this.signer = signer || "";
6059
+ this.env = env || 0 /* Mainnet */;
6041
6060
  this.allCoins = [];
6042
6061
  }
6043
6062
  getAllCoins() {
6044
6063
  return __async(this, null, function* () {
6064
+ if (this.signer === "") {
6065
+ throw new Error("Signer is required, but not provided.");
6066
+ }
6045
6067
  let cursor = null;
6046
6068
  let limit = 50;
6047
6069
  const allCoins = [];
@@ -6071,7 +6093,7 @@ var AggregatorClient7 = class {
6071
6093
  return getRouterResult(this.endpoint, params);
6072
6094
  });
6073
6095
  }
6074
- expectInputSwap(txb, inputCoin, routers, amountOutLimit, partner) {
6096
+ expectInputSwap(txb, inputCoin, routers, amountOutLimit, partner, deepbookv3DeepFee) {
6075
6097
  return __async(this, null, function* () {
6076
6098
  if (routers.length === 0) {
6077
6099
  throw new Error("No router found");
@@ -6088,7 +6110,7 @@ var AggregatorClient7 = class {
6088
6110
  let nextCoin = inputCoins[i];
6089
6111
  for (const path of routers[i].path) {
6090
6112
  const dex = this.newDex(path.provider, partner);
6091
- nextCoin = yield dex.swap(this, txb, path, nextCoin);
6113
+ nextCoin = yield dex.swap(this, txb, path, nextCoin, deepbookv3DeepFee);
6092
6114
  }
6093
6115
  outputCoins.push(nextCoin);
6094
6116
  }
@@ -6164,7 +6186,7 @@ var AggregatorClient7 = class {
6164
6186
  }
6165
6187
  routerSwap(params) {
6166
6188
  return __async(this, null, function* () {
6167
- const { routers, inputCoin, slippage, byAmountIn, txb, partner } = params;
6189
+ const { routers, inputCoin, slippage, byAmountIn, txb, partner, deepbookv3DeepFee } = params;
6168
6190
  const amountIn = routers.reduce(
6169
6191
  (acc, router) => acc.add(router.amountIn),
6170
6192
  new import_bn5.default(0)
@@ -6184,7 +6206,8 @@ var AggregatorClient7 = class {
6184
6206
  inputCoin,
6185
6207
  routers,
6186
6208
  new import_bn5.default(amountLimit),
6187
- partner
6209
+ partner,
6210
+ deepbookv3DeepFee
6188
6211
  );
6189
6212
  return targetCoin2;
6190
6213
  }
@@ -6212,7 +6235,8 @@ var AggregatorClient7 = class {
6212
6235
  txb,
6213
6236
  partner,
6214
6237
  isMergeTragetCoin,
6215
- refreshAllCoins
6238
+ refreshAllCoins,
6239
+ payDeepFeeAmount
6216
6240
  } = params;
6217
6241
  if (refreshAllCoins || this.allCoins.length === 0) {
6218
6242
  this.allCoins = yield this.getAllCoins();
@@ -6239,13 +6263,23 @@ var AggregatorClient7 = class {
6239
6263
  BigInt(amount.toString()),
6240
6264
  fromCoinType
6241
6265
  );
6266
+ let deepCoin;
6267
+ if (payDeepFeeAmount && payDeepFeeAmount > 0) {
6268
+ deepCoin = buildInputCoin(
6269
+ txb,
6270
+ this.allCoins,
6271
+ BigInt(payDeepFeeAmount),
6272
+ this.deepbookv3DeepFeeType()
6273
+ ).targetCoin;
6274
+ }
6242
6275
  const targetCoin = yield this.routerSwap({
6243
6276
  routers,
6244
6277
  inputCoin: buildFromCoinRes.targetCoin,
6245
6278
  slippage,
6246
6279
  byAmountIn,
6247
6280
  txb,
6248
- partner
6281
+ partner,
6282
+ deepbookv3DeepFee: deepCoin
6249
6283
  });
6250
6284
  if (isMergeTragetCoin) {
6251
6285
  const targetCoinRes = buildInputCoin(
@@ -6267,11 +6301,27 @@ var AggregatorClient7 = class {
6267
6301
  }
6268
6302
  });
6269
6303
  }
6304
+ // Include cetus、deepbookv2、flowxv2 & v3、kriyav2 & v3、turbos、aftermath、haedal、afsui、volo、bluemove
6270
6305
  publishedAt() {
6271
6306
  if (this.env === 0 /* Mainnet */) {
6272
6307
  return "0xf98ed029af555e4a103febf26243dc33ac09a7ea1b2da7e414c728b25b729086";
6273
6308
  } else {
6274
- return "0xb2db335c85473e7ed952351bb594100eb8f61122703219c6b8dbcdcade2795b3";
6309
+ return "0x0ed287d6c3fe4962d0994ffddc1d19a15fba6a81533f3f0dcc2bbcedebce0637";
6310
+ }
6311
+ }
6312
+ // Include deepbookv3
6313
+ publishedAtV2() {
6314
+ if (this.env === 0 /* Mainnet */) {
6315
+ return "0x43811be4677f5a5de7bf2dac740c10abddfaa524aee6b18e910eeadda8a2f6ae";
6316
+ } else {
6317
+ return "0x0ed287d6c3fe4962d0994ffddc1d19a15fba6a81533f3f0dcc2bbcedebce0637";
6318
+ }
6319
+ }
6320
+ deepbookv3DeepFeeType() {
6321
+ if (this.env === 0 /* Mainnet */) {
6322
+ return "0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP";
6323
+ } else {
6324
+ return "0x36dbef866a1d62bf7328989a10fb2f07d769f4ee587c0de4a0a256e57e0a58a8::deep::DEEP";
6275
6325
  }
6276
6326
  }
6277
6327
  transferOrDestoryCoin(txb, coin, coinType) {
@@ -6364,26 +6414,44 @@ var AggregatorClient7 = class {
6364
6414
  return res;
6365
6415
  });
6366
6416
  }
6417
+ getDeepbookV3Config() {
6418
+ return __async(this, null, function* () {
6419
+ const res = yield getDeepbookV3Config(this.endpoint);
6420
+ if (res) {
6421
+ return res.data;
6422
+ }
6423
+ return null;
6424
+ });
6425
+ }
6367
6426
  };
6368
6427
  function parseRouterResponse(data) {
6369
- return {
6428
+ let totalDeepFee = 0;
6429
+ for (const route of data.routes) {
6430
+ for (const path of route.path) {
6431
+ if (path.extended_details && path.extended_details.deepbookv3_deep_fee) {
6432
+ totalDeepFee += Number(path.extended_details.deepbookv3_deep_fee);
6433
+ }
6434
+ }
6435
+ }
6436
+ let routerData = {
6370
6437
  amountIn: new import_bn5.default(data.amount_in.toString()),
6371
6438
  amountOut: new import_bn5.default(data.amount_out.toString()),
6372
6439
  insufficientLiquidity: false,
6373
6440
  routes: data.routes.map((route) => {
6374
6441
  return {
6375
6442
  path: route.path.map((path) => {
6376
- var _a, _b, _c;
6443
+ var _a, _b, _c, _d;
6377
6444
  let version;
6378
6445
  if (path.provider === AFTERMATH) {
6379
6446
  version = path.extended_details.aftermath_pool_flatness === 0 ? "v2" : "v3";
6380
6447
  }
6381
6448
  let extendedDetails;
6382
- if (path.provider === TURBOS || path.provider === AFTERMATH || path.provider === CETUS) {
6449
+ if (path.provider === TURBOS || path.provider === AFTERMATH || path.provider === CETUS || path.provider === DEEPBOOKV3) {
6383
6450
  extendedDetails = {
6384
6451
  aftermathLpSupplyType: (_a = path.extended_details) == null ? void 0 : _a.aftermath_lp_supply_type,
6385
6452
  turbosFeeType: (_b = path.extended_details) == null ? void 0 : _b.turbos_fee_type,
6386
- afterSqrtPrice: (_c = path.extended_details) == null ? void 0 : _c.after_sqrt_price
6453
+ afterSqrtPrice: (_c = path.extended_details) == null ? void 0 : _c.after_sqrt_price,
6454
+ deepbookv3DeepFee: (_d = path.extended_details) == null ? void 0 : _d.deepbookv3_deep_fee
6387
6455
  };
6388
6456
  }
6389
6457
  return {
@@ -6403,8 +6471,10 @@ function parseRouterResponse(data) {
6403
6471
  amountOut: new import_bn5.default(route.amount_out.toString()),
6404
6472
  initialPrice: new decimal_default(route.initial_price.toString())
6405
6473
  };
6406
- })
6474
+ }),
6475
+ totalDeepFee
6407
6476
  };
6477
+ return routerData;
6408
6478
  }
6409
6479
 
6410
6480
  // src/transaction/index.ts
@@ -6435,6 +6505,14 @@ var restituteMsafeFastRouterSwapParams = (data) => {
6435
6505
  return result;
6436
6506
  };
6437
6507
 
6508
+ // src/utils/api.ts
6509
+ function processEndpoint(endpoint) {
6510
+ if (endpoint.endsWith("/find_routes")) {
6511
+ return endpoint.replace("/find_routes", "");
6512
+ }
6513
+ return endpoint;
6514
+ }
6515
+
6438
6516
  // src/api.ts
6439
6517
  function getRouterResult(endpoint, params) {
6440
6518
  return __async(this, null, function* () {
@@ -6497,7 +6575,7 @@ function getRouter(endpoint, params) {
6497
6575
  } = params;
6498
6576
  const fromCoin = completionCoin(from);
6499
6577
  const targetCoin = completionCoin(target);
6500
- let url = `${endpoint}?from=${fromCoin}&target=${targetCoin}&amount=${amount.toString()}&by_amount_in=${byAmountIn}`;
6578
+ let url = `${endpoint}/find_routes?from=${fromCoin}&target=${targetCoin}&amount=${amount.toString()}&by_amount_in=${byAmountIn}`;
6501
6579
  if (depth) {
6502
6580
  url += `&depth=${depth}`;
6503
6581
  }
@@ -6515,7 +6593,7 @@ function getRouter(endpoint, params) {
6515
6593
  url += `&providers=${providers.join(",")}`;
6516
6594
  }
6517
6595
  }
6518
- url += "&v=1000301";
6596
+ url += "&v=1000302";
6519
6597
  const response = yield fetch(url);
6520
6598
  return response;
6521
6599
  } catch (error) {
@@ -6540,7 +6618,7 @@ function postRouterWithLiquidityChanges(endpoint, params) {
6540
6618
  } = params;
6541
6619
  const fromCoin = completionCoin(from);
6542
6620
  const targetCoin = completionCoin(target);
6543
- const url = `${endpoint}`;
6621
+ const url = `${endpoint}/find_routes`;
6544
6622
  const providersStr = providers == null ? void 0 : providers.join(",");
6545
6623
  const requestData = {
6546
6624
  from: fromCoin,
@@ -6559,7 +6637,6 @@ function postRouterWithLiquidityChanges(endpoint, params) {
6559
6637
  delta_liquidity: change.deltaLiquidity
6560
6638
  }))
6561
6639
  };
6562
- console.log("requestData", JSON.stringify(requestData, null, 2));
6563
6640
  try {
6564
6641
  const response = yield fetch(url, {
6565
6642
  method: "POST",
@@ -6575,6 +6652,18 @@ function postRouterWithLiquidityChanges(endpoint, params) {
6575
6652
  }
6576
6653
  });
6577
6654
  }
6655
+ function getDeepbookV3Config(endpoint) {
6656
+ return __async(this, null, function* () {
6657
+ const url = `${endpoint}/deepbookv3_config`;
6658
+ try {
6659
+ const response = yield fetch(url);
6660
+ return response.json();
6661
+ } catch (error) {
6662
+ console.error("Error:", error);
6663
+ return null;
6664
+ }
6665
+ });
6666
+ }
6578
6667
 
6579
6668
  // src/index.ts
6580
6669
  var Env = /* @__PURE__ */ ((Env2) => {
@@ -6594,4 +6683,4 @@ decimal.js/decimal.mjs:
6594
6683
  *)
6595
6684
  */
6596
6685
 
6597
- export { AFSUI, AFTERMATH, AggregatorClient7 as AggregatorClient, BLUEMOVE, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, DEEPBOOKV3, Env, FLOWXV2, FLOWXV3, HAEDAL, KRIYA, KRIYAV3, ONE, 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 };
6686
+ export { AFSUI, AFTERMATH, AggregatorClient7 as AggregatorClient, BLUEMOVE, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, DEEPBOOKV3, DEFAULT_ENDPOINT, Env, FLOWXV2, FLOWXV3, HAEDAL, KRIYA, KRIYAV3, ONE, TEN_POW_NINE, TURBOS, TWO, U128, U64_MAX, U64_MAX_BN, VOLO, ZERO, buildInputCoin, checkInvalidSuiAddress, compareCoins, completionCoin, composeType, createTarget, dealWithFastRouterSwapParamsForMsafe, extractAddressFromType, extractStructTagFromType, fixSuiObjectId, getDeepbookV3Config, getRouterResult, isSortedSymbols, mintZeroCoin, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId, printTransaction, processEndpoint, restituteMsafeFastRouterSwapParams };
package/dist/src/api.d.ts CHANGED
@@ -23,6 +23,7 @@ export type ExtendedDetails = {
23
23
  aftermathLpSupplyType?: string;
24
24
  turbosFeeType?: string;
25
25
  afterSqrtPrice?: string;
26
+ deepbookv3DeepFee?: number;
26
27
  };
27
28
  export type Path = {
28
29
  id: string;
@@ -51,6 +52,7 @@ export type RouterData = {
51
52
  amountOut: BN;
52
53
  routes: Router[];
53
54
  insufficientLiquidity: boolean;
55
+ totalDeepFee?: number;
54
56
  error?: RouterError;
55
57
  };
56
58
  export type AggregatorResponse = {
@@ -59,3 +61,21 @@ export type AggregatorResponse = {
59
61
  data: RouterData;
60
62
  };
61
63
  export declare function getRouterResult(endpoint: string, params: FindRouterParams): Promise<RouterData | null>;
64
+ export type DeepbookV3Config = {
65
+ id: string;
66
+ is_alternative_payment: boolean;
67
+ alternative_payment_amount: number;
68
+ trade_cap: string;
69
+ balance_manager: string;
70
+ deep_fee_vault: number;
71
+ whitelist: number;
72
+ package_version: 0;
73
+ last_updated_time: number;
74
+ whitelist_pools: string[];
75
+ };
76
+ export type DeepbookV3ConfigResponse = {
77
+ code: number;
78
+ msg: string;
79
+ data: DeepbookV3Config;
80
+ };
81
+ export declare function getDeepbookV3Config(endpoint: string): Promise<DeepbookV3ConfigResponse | null>;
@@ -2,7 +2,7 @@ import { SuiClient } from "@mysten/sui/client";
2
2
  import { Transaction, TransactionObjectArgument } from "@mysten/sui/transactions";
3
3
  import { Signer } from "@mysten/sui/cryptography";
4
4
  import BN from "bn.js";
5
- import { Dex, Env, FindRouterParams, Router, RouterData } from ".";
5
+ import { Dex, Env, FindRouterParams, Router, RouterData, DeepbookV3Config } from ".";
6
6
  import { CoinAsset } from "./types/sui";
7
7
  export declare const CETUS = "CETUS";
8
8
  export declare const DEEPBOOKV2 = "DEEPBOOK";
@@ -17,6 +17,7 @@ export declare const VOLO = "VOLO";
17
17
  export declare const AFSUI = "AFSUI";
18
18
  export declare const BLUEMOVE = "BLUEMOVE";
19
19
  export declare const DEEPBOOKV3 = "DEEPBOOKV3";
20
+ export declare const DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
20
21
  export type BuildRouterSwapParams = {
21
22
  routers: Router[];
22
23
  byAmountIn: boolean;
@@ -24,6 +25,7 @@ export type BuildRouterSwapParams = {
24
25
  slippage: number;
25
26
  txb: Transaction;
26
27
  partner?: string;
28
+ deepbookv3DeepFee?: TransactionObjectArgument;
27
29
  };
28
30
  export type BuildFastRouterSwapParams = {
29
31
  routers: Router[];
@@ -33,6 +35,7 @@ export type BuildFastRouterSwapParams = {
33
35
  partner?: string;
34
36
  isMergeTragetCoin?: boolean;
35
37
  refreshAllCoins?: boolean;
38
+ payDeepFeeAmount?: number;
36
39
  };
37
40
  export interface SwapInPoolsParams {
38
41
  from: string;
@@ -51,20 +54,23 @@ export declare class AggregatorClient {
51
54
  client: SuiClient;
52
55
  env: Env;
53
56
  private allCoins;
54
- constructor(endpoint: string, signer: string, client: SuiClient, env: Env);
57
+ constructor(endpoint?: string, signer?: string, client?: SuiClient, env?: Env);
55
58
  getAllCoins(): Promise<CoinAsset[]>;
56
59
  findRouters(params: FindRouterParams): Promise<RouterData | null>;
57
- expectInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], amountOutLimit: BN, partner?: string): Promise<TransactionObjectArgument>;
60
+ expectInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], amountOutLimit: BN, partner?: string, deepbookv3DeepFee?: TransactionObjectArgument): Promise<TransactionObjectArgument>;
58
61
  expectOutputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], partner?: string): Promise<TransactionObjectArgument>;
59
62
  swapInPools(params: SwapInPoolsParams): Promise<SwapInPoolsResult | null>;
60
63
  routerSwap(params: BuildRouterSwapParams): Promise<TransactionObjectArgument>;
61
64
  fastRouterSwap(params: BuildFastRouterSwapParams): Promise<void>;
62
65
  publishedAt(): string;
66
+ publishedAtV2(): string;
67
+ deepbookv3DeepFeeType(): string;
63
68
  transferOrDestoryCoin(txb: Transaction, coin: TransactionObjectArgument, coinType: string): void;
64
69
  checkCoinThresholdAndMergeCoin(txb: Transaction, coins: TransactionObjectArgument[], coinType: string, amountLimit: BN): TransactionObjectArgument;
65
70
  newDex(provider: string, partner?: string): Dex;
66
71
  signAndExecuteTransaction(txb: Transaction, signer: Signer): Promise<import("@mysten/sui/client").SuiTransactionBlockResponse>;
67
72
  devInspectTransactionBlock(txb: Transaction): Promise<import("@mysten/sui/client").DevInspectResults>;
68
73
  sendTransaction(txb: Transaction, signer: Signer): Promise<import("@mysten/sui/client").SuiTransactionBlockResponse>;
74
+ getDeepbookV3Config(): Promise<DeepbookV3Config | null>;
69
75
  }
70
76
  export declare function parseRouterResponse(data: any): RouterData;
@@ -7,7 +7,6 @@ export type CetusFlashSwapResult = {
7
7
  };
8
8
  export declare class DeepbookV3 implements Dex {
9
9
  private deepbookV3Config;
10
- private deepCoinType;
11
10
  constructor(env: Env);
12
- swap(client: AggregatorClient, txb: Transaction, path: Path, inputCoin: TransactionObjectArgument): Promise<TransactionObjectArgument>;
11
+ swap(client: AggregatorClient, txb: Transaction, path: Path, inputCoin: TransactionObjectArgument, deepbookv3DeepFee?: TransactionObjectArgument): Promise<TransactionObjectArgument>;
13
12
  }
@@ -2,5 +2,5 @@ import { Transaction, TransactionObjectArgument } from "@mysten/sui/transactions
2
2
  import { AggregatorClient, Path } from "..";
3
3
  export declare const CLOCK_ADDRESS = "0x0000000000000000000000000000000000000000000000000000000000000006";
4
4
  export interface Dex {
5
- swap(client: AggregatorClient, ptb: Transaction, path: Path, inputCoin: TransactionObjectArgument): Promise<TransactionObjectArgument>;
5
+ swap(client: AggregatorClient, ptb: Transaction, path: Path, inputCoin: TransactionObjectArgument, deepbookv3DeepFee?: TransactionObjectArgument): Promise<TransactionObjectArgument>;
6
6
  }
@@ -0,0 +1 @@
1
+ export declare function processEndpoint(endpoint: string): string;
@@ -1,2 +1,5 @@
1
1
  export * from './contracts';
2
2
  export * from './msafe';
3
+ export * from './api';
4
+ export * from './coin';
5
+ export * from './transaction';
@@ -1,4 +1,7 @@
1
1
  export declare const T_USDC = "";
2
+ export declare const T_DEEP = "0x36dbef866a1d62bf7328989a10fb2f07d769f4ee587c0de4a0a256e57e0a58a8::deep::DEEP";
3
+ export declare const T_DBUSDC = "0xf7152c05930480cd740d7311b5b8b45c6f488e3a53a11c3f74a6fac36a52e0d7::DBUSDC::DBUSDC";
4
+ export declare const T_DBUSDT = "0xf7152c05930480cd740d7311b5b8b45c6f488e3a53a11c3f74a6fac36a52e0d7::DBUSDT::DBUSDT";
2
5
  export declare const M_USDC = "0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN";
3
6
  export declare const M_CETUS = "0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS";
4
7
  export declare const M_NAVI = "0xa99b8952d4f7d947ea77fe0ecdcc9e5fc0bcab2841d6e2a5aa00c3044e5544b5::navx::NAVX";
@@ -7,3 +10,4 @@ export declare const M_VSUI = "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2
7
10
  export declare const M_VAPOR = "0xa1f2c11169f32165ad4efb4468ec5bdfc880cd66b22094024b32ab7b76d14d30::vapor::VAPOR";
8
11
  export declare const M_HASUI = "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI";
9
12
  export declare const M_SSWP = "0x361dd589b98e8fcda9a7ee53b85efabef3569d00416640d2faa516e3801d7ffc::TOKEN::TOKEN";
13
+ export declare const M_MICHI = "0x50d796fde5709a97883e29e00bf511d66f2656de958ea0c2ce4c1147cdd20a23::MICHI::MICHI";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cetusprotocol/aggregator-sdk",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "sideEffects": false,
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/api.ts CHANGED
@@ -33,6 +33,7 @@ export type ExtendedDetails = {
33
33
  aftermathLpSupplyType?: string
34
34
  turbosFeeType?: string
35
35
  afterSqrtPrice?: string
36
+ deepbookv3DeepFee?: number
36
37
  }
37
38
 
38
39
  export type Path = {
@@ -65,6 +66,7 @@ export type RouterData = {
65
66
  amountOut: BN
66
67
  routes: Router[]
67
68
  insufficientLiquidity: boolean
69
+ totalDeepFee?: number
68
70
  error?: RouterError
69
71
  }
70
72
 
@@ -140,7 +142,7 @@ async function getRouter(endpoint: string, params: FindRouterParams) {
140
142
  const fromCoin = completionCoin(from)
141
143
  const targetCoin = completionCoin(target)
142
144
 
143
- let url = `${endpoint}?from=${fromCoin}&target=${targetCoin}&amount=${amount.toString()}&by_amount_in=${byAmountIn}`
145
+ let url = `${endpoint}/find_routes?from=${fromCoin}&target=${targetCoin}&amount=${amount.toString()}&by_amount_in=${byAmountIn}`
144
146
 
145
147
  if (depth) {
146
148
  url += `&depth=${depth}`
@@ -165,7 +167,7 @@ async function getRouter(endpoint: string, params: FindRouterParams) {
165
167
  }
166
168
 
167
169
  // set newest sdk version
168
- url += "&v=1000301"
170
+ url += "&v=1000302"
169
171
 
170
172
  const response = await fetch(url)
171
173
  return response
@@ -194,11 +196,8 @@ async function postRouterWithLiquidityChanges(
194
196
 
195
197
  const fromCoin = completionCoin(from)
196
198
  const targetCoin = completionCoin(target)
197
-
198
- const url = `${endpoint}`
199
-
199
+ const url = `${endpoint}/find_routes`
200
200
  const providersStr = providers?.join(",")
201
-
202
201
  const requestData = {
203
202
  from: fromCoin,
204
203
  target: targetCoin,
@@ -217,8 +216,6 @@ async function postRouterWithLiquidityChanges(
217
216
  })),
218
217
  }
219
218
 
220
- console.log("requestData", JSON.stringify(requestData, null, 2))
221
-
222
219
  try {
223
220
  const response = await fetch(url, {
224
221
  method: "POST",
@@ -234,3 +231,36 @@ async function postRouterWithLiquidityChanges(
234
231
  return null
235
232
  }
236
233
  }
234
+
235
+ export type DeepbookV3Config = {
236
+ id: string
237
+ is_alternative_payment: boolean
238
+ alternative_payment_amount: number
239
+ trade_cap: string
240
+ balance_manager: string
241
+ deep_fee_vault: number
242
+ whitelist: number
243
+ package_version: 0
244
+ // unix timestamp in seconds
245
+ last_updated_time: number
246
+ whitelist_pools: string[]
247
+ }
248
+
249
+ export type DeepbookV3ConfigResponse = {
250
+ code: number
251
+ msg: string
252
+ data: DeepbookV3Config
253
+ }
254
+
255
+ export async function getDeepbookV3Config(
256
+ endpoint: string
257
+ ): Promise<DeepbookV3ConfigResponse | null> {
258
+ const url = `${endpoint}/deepbookv3_config`
259
+ try {
260
+ const response = await fetch(url)
261
+ return response.json() as Promise<DeepbookV3ConfigResponse>
262
+ } catch (error) {
263
+ console.error("Error:", error)
264
+ return null
265
+ }
266
+ }