@cetusprotocol/aggregator-sdk 0.0.0-experimental-20240929164543 → 0.0.0-experimental-20241010160019

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
@@ -5990,6 +5990,45 @@ var Bluemove = class {
5990
5990
  }
5991
5991
  };
5992
5992
 
5993
+ // src/transaction/deepbook_v3.ts
5994
+ var DeepbookV3 = class {
5995
+ constructor(env) {
5996
+ this.deepbookV3Config = env === 0 /* Mainnet */ ? "0x0" : "0xe19b5d072346cae83a037d4e3c8492068a74410a74e5830b3a68012db38296aa";
5997
+ this.deepCoinType = env === 0 /* Mainnet */ ? "0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP" : "0x36dbef866a1d62bf7328989a10fb2f07d769f4ee587c0de4a0a256e57e0a58a8::deep::DEEP";
5998
+ }
5999
+ swap(client, txb, path, inputCoin, deepbookv3DeepFee) {
6000
+ return __async(this, null, function* () {
6001
+ var _a, _b, _c;
6002
+ const { direction, from, target } = path;
6003
+ const [func, coinAType, coinBType] = direction ? ["swap_a2b", from, target] : ["swap_b2a", target, from];
6004
+ let deepFee;
6005
+ if (deepbookv3DeepFee) {
6006
+ if (((_a = path.extendedDetails) == null ? void 0 : _a.deepbookv3DeepFee) && ((_b = path.extendedDetails) == null ? void 0 : _b.deepbookv3DeepFee) > 0) {
6007
+ const splitAmounts = [(_c = path.extendedDetails) == null ? void 0 : _c.deepbookv3DeepFee];
6008
+ deepFee = txb.splitCoins(deepbookv3DeepFee, splitAmounts)[0];
6009
+ } else {
6010
+ deepFee = mintZeroCoin(txb, this.deepCoinType);
6011
+ }
6012
+ } else {
6013
+ deepFee = mintZeroCoin(txb, this.deepCoinType);
6014
+ }
6015
+ const args = [
6016
+ txb.object(this.deepbookV3Config),
6017
+ txb.object(path.id),
6018
+ inputCoin,
6019
+ deepFee,
6020
+ txb.object(CLOCK_ADDRESS)
6021
+ ];
6022
+ const res = txb.moveCall({
6023
+ target: `${client.publishedAt()}::deepbookv3::${func}`,
6024
+ typeArguments: [coinAType, coinBType],
6025
+ arguments: args
6026
+ });
6027
+ return res;
6028
+ });
6029
+ }
6030
+ };
6031
+
5993
6032
  // src/client.ts
5994
6033
  var CETUS = "CETUS";
5995
6034
  var DEEPBOOKV2 = "DEEPBOOK";
@@ -6003,9 +6042,10 @@ var HAEDAL = "HAEDAL";
6003
6042
  var VOLO = "VOLO";
6004
6043
  var AFSUI = "AFSUI";
6005
6044
  var BLUEMOVE = "BLUEMOVE";
6006
- var AggregatorClient6 = class {
6045
+ var DEEPBOOKV3 = "DEEPBOOKV3";
6046
+ var AggregatorClient7 = class {
6007
6047
  constructor(endpoint, signer, client, env) {
6008
- this.endpoint = endpoint;
6048
+ this.endpoint = processEndpoint(endpoint);
6009
6049
  this.client = client;
6010
6050
  this.signer = signer;
6011
6051
  this.env = env;
@@ -6042,7 +6082,7 @@ var AggregatorClient6 = class {
6042
6082
  return getRouterResult(this.endpoint, params);
6043
6083
  });
6044
6084
  }
6045
- expectInputSwap(txb, inputCoin, routers, amountOutLimit, partner) {
6085
+ expectInputSwap(txb, inputCoin, routers, amountOutLimit, partner, deepbookv3DeepFee) {
6046
6086
  return __async(this, null, function* () {
6047
6087
  if (routers.length === 0) {
6048
6088
  throw new Error("No router found");
@@ -6059,11 +6099,14 @@ var AggregatorClient6 = class {
6059
6099
  let nextCoin = inputCoins[i];
6060
6100
  for (const path of routers[i].path) {
6061
6101
  const dex = this.newDex(path.provider, partner);
6062
- nextCoin = yield dex.swap(this, txb, path, nextCoin);
6102
+ nextCoin = yield dex.swap(this, txb, path, nextCoin, deepbookv3DeepFee);
6063
6103
  }
6064
6104
  outputCoins.push(nextCoin);
6065
6105
  }
6066
6106
  this.transferOrDestoryCoin(txb, inputCoin, inputCoinType);
6107
+ if (deepbookv3DeepFee) {
6108
+ this.transferOrDestoryCoin(txb, deepbookv3DeepFee, this.deepbookv3DeepFeeType());
6109
+ }
6067
6110
  const mergedTargetCointhis = this.checkCoinThresholdAndMergeCoin(
6068
6111
  txb,
6069
6112
  outputCoins,
@@ -6135,7 +6178,7 @@ var AggregatorClient6 = class {
6135
6178
  }
6136
6179
  routerSwap(params) {
6137
6180
  return __async(this, null, function* () {
6138
- const { routers, inputCoin, slippage, byAmountIn, txb, partner } = params;
6181
+ const { routers, inputCoin, slippage, byAmountIn, txb, partner, deepbookv3DeepFee } = params;
6139
6182
  const amountIn = routers.reduce(
6140
6183
  (acc, router) => acc.add(router.amountIn),
6141
6184
  new import_bn5.default(0)
@@ -6155,7 +6198,8 @@ var AggregatorClient6 = class {
6155
6198
  inputCoin,
6156
6199
  routers,
6157
6200
  new import_bn5.default(amountLimit),
6158
- partner
6201
+ partner,
6202
+ deepbookv3DeepFee
6159
6203
  );
6160
6204
  return targetCoin2;
6161
6205
  }
@@ -6183,7 +6227,8 @@ var AggregatorClient6 = class {
6183
6227
  txb,
6184
6228
  partner,
6185
6229
  isMergeTragetCoin,
6186
- refreshAllCoins
6230
+ refreshAllCoins,
6231
+ deepbookv3DeepFee
6187
6232
  } = params;
6188
6233
  if (refreshAllCoins || this.allCoins.length === 0) {
6189
6234
  this.allCoins = yield this.getAllCoins();
@@ -6216,7 +6261,8 @@ var AggregatorClient6 = class {
6216
6261
  slippage,
6217
6262
  byAmountIn,
6218
6263
  txb,
6219
- partner
6264
+ partner,
6265
+ deepbookv3DeepFee
6220
6266
  });
6221
6267
  if (isMergeTragetCoin) {
6222
6268
  const targetCoinRes = buildInputCoin(
@@ -6242,7 +6288,14 @@ var AggregatorClient6 = class {
6242
6288
  if (this.env === 0 /* Mainnet */) {
6243
6289
  return "0x764b8132a94d35abc9dfd91b23a0757b2a717d5ecb04c03098794aa2a508db91";
6244
6290
  } else {
6245
- return "0x6cbaa3e9fbe902d90191b12f315932bc58079cba422bafbd4b4369f80e61f595";
6291
+ return "0xf92cdec6c2d73a12d8afa8dd41199b3e95b621272bbc655996539cd30de6a462";
6292
+ }
6293
+ }
6294
+ deepbookv3DeepFeeType() {
6295
+ if (this.env === 0 /* Mainnet */) {
6296
+ return "0x36dbef866a1d62bf7328989a10fb2f07d769f4ee587c0de4a0a256e57e0a58a8::deep::DEEP";
6297
+ } else {
6298
+ return "0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP";
6246
6299
  }
6247
6300
  }
6248
6301
  transferOrDestoryCoin(txb, coin, coinType) {
@@ -6276,6 +6329,8 @@ var AggregatorClient6 = class {
6276
6329
  return new Cetus(this.env, partner);
6277
6330
  case DEEPBOOKV2:
6278
6331
  return new DeepbookV2(this.env);
6332
+ case DEEPBOOKV3:
6333
+ return new DeepbookV3(this.env);
6279
6334
  case KRIYA:
6280
6335
  return new KriyaV2(this.env);
6281
6336
  case KRIYAV3:
@@ -6333,6 +6388,15 @@ var AggregatorClient6 = class {
6333
6388
  return res;
6334
6389
  });
6335
6390
  }
6391
+ getDeepbookV3Config() {
6392
+ return __async(this, null, function* () {
6393
+ const res = yield getDeepbookV3Config(this.endpoint);
6394
+ if (res) {
6395
+ return res.data;
6396
+ }
6397
+ return null;
6398
+ });
6399
+ }
6336
6400
  };
6337
6401
  function parseRouterResponse(data) {
6338
6402
  return {
@@ -6342,17 +6406,18 @@ function parseRouterResponse(data) {
6342
6406
  routes: data.routes.map((route) => {
6343
6407
  return {
6344
6408
  path: route.path.map((path) => {
6345
- var _a, _b, _c;
6409
+ var _a, _b, _c, _d;
6346
6410
  let version;
6347
6411
  if (path.provider === AFTERMATH) {
6348
6412
  version = path.extended_details.aftermath_pool_flatness === 0 ? "v2" : "v3";
6349
6413
  }
6350
6414
  let extendedDetails;
6351
- if (path.provider === TURBOS || path.provider === AFTERMATH || path.provider === CETUS) {
6415
+ if (path.provider === TURBOS || path.provider === AFTERMATH || path.provider === CETUS || path.provider === DEEPBOOKV3) {
6352
6416
  extendedDetails = {
6353
6417
  aftermathLpSupplyType: (_a = path.extended_details) == null ? void 0 : _a.aftermath_lp_supply_type,
6354
6418
  turbosFeeType: (_b = path.extended_details) == null ? void 0 : _b.turbos_fee_type,
6355
- afterSqrtPrice: (_c = path.extended_details) == null ? void 0 : _c.after_sqrt_price
6419
+ afterSqrtPrice: (_c = path.extended_details) == null ? void 0 : _c.after_sqrt_price,
6420
+ deepbookv3DeepFee: (_d = path.extended_details) == null ? void 0 : _d.deepbookv3_deep_fee
6356
6421
  };
6357
6422
  }
6358
6423
  return {
@@ -6404,6 +6469,14 @@ var restituteMsafeFastRouterSwapParams = (data) => {
6404
6469
  return result;
6405
6470
  };
6406
6471
 
6472
+ // src/utils/api.ts
6473
+ function processEndpoint(endpoint) {
6474
+ if (endpoint.endsWith("/find_routes")) {
6475
+ return endpoint.replace("/find_routes", "");
6476
+ }
6477
+ return endpoint;
6478
+ }
6479
+
6407
6480
  // src/api.ts
6408
6481
  function getRouterResult(endpoint, params) {
6409
6482
  return __async(this, null, function* () {
@@ -6466,7 +6539,7 @@ function getRouter(endpoint, params) {
6466
6539
  } = params;
6467
6540
  const fromCoin = completionCoin(from);
6468
6541
  const targetCoin = completionCoin(target);
6469
- let url = `${endpoint}?from=${fromCoin}&target=${targetCoin}&amount=${amount.toString()}&by_amount_in=${byAmountIn}`;
6542
+ let url = `${endpoint}/find_routes?from=${fromCoin}&target=${targetCoin}&amount=${amount.toString()}&by_amount_in=${byAmountIn}`;
6470
6543
  if (depth) {
6471
6544
  url += `&depth=${depth}`;
6472
6545
  }
@@ -6508,7 +6581,7 @@ function postRouterWithLiquidityChanges(endpoint, params) {
6508
6581
  } = params;
6509
6582
  const fromCoin = completionCoin(from);
6510
6583
  const targetCoin = completionCoin(target);
6511
- const url = `${endpoint}`;
6584
+ const url = `${endpoint}/find_routes`;
6512
6585
  const providersStr = providers == null ? void 0 : providers.join(",");
6513
6586
  const requestData = {
6514
6587
  from: fromCoin,
@@ -6527,7 +6600,6 @@ function postRouterWithLiquidityChanges(endpoint, params) {
6527
6600
  delta_liquidity: change.deltaLiquidity
6528
6601
  }))
6529
6602
  };
6530
- console.log("requestData", JSON.stringify(requestData, null, 2));
6531
6603
  try {
6532
6604
  const response = yield fetch(url, {
6533
6605
  method: "POST",
@@ -6543,6 +6615,18 @@ function postRouterWithLiquidityChanges(endpoint, params) {
6543
6615
  }
6544
6616
  });
6545
6617
  }
6618
+ function getDeepbookV3Config(endpoint) {
6619
+ return __async(this, null, function* () {
6620
+ const url = `${endpoint}/deepbookv3_config`;
6621
+ try {
6622
+ const response = yield fetch(url);
6623
+ return response.json();
6624
+ } catch (error) {
6625
+ console.error("Error:", error);
6626
+ return null;
6627
+ }
6628
+ });
6629
+ }
6546
6630
 
6547
6631
  // src/index.ts
6548
6632
  var Env = /* @__PURE__ */ ((Env2) => {
@@ -6562,4 +6646,4 @@ decimal.js/decimal.mjs:
6562
6646
  *)
6563
6647
  */
6564
6648
 
6565
- export { AFSUI, AFTERMATH, AggregatorClient6 as AggregatorClient, BLUEMOVE, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, 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 };
6649
+ 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, getDeepbookV3Config, getRouterResult, isSortedSymbols, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId, 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;
@@ -59,3 +60,17 @@ export type AggregatorResponse = {
59
60
  data: RouterData;
60
61
  };
61
62
  export declare function getRouterResult(endpoint: string, params: FindRouterParams): Promise<RouterData | null>;
63
+ export type DeepbookV3Config = {
64
+ id: string;
65
+ is_alternative_payment: boolean;
66
+ deep_fee_vault: number;
67
+ whitelist: number;
68
+ whitelist_pools: string[];
69
+ last_updated_time: number;
70
+ };
71
+ export type DeepbookV3ConfigResponse = {
72
+ code: number;
73
+ msg: string;
74
+ data: DeepbookV3Config;
75
+ };
76
+ 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";
@@ -16,6 +16,7 @@ export declare const HAEDAL = "HAEDAL";
16
16
  export declare const VOLO = "VOLO";
17
17
  export declare const AFSUI = "AFSUI";
18
18
  export declare const BLUEMOVE = "BLUEMOVE";
19
+ export declare const DEEPBOOKV3 = "DEEPBOOKV3";
19
20
  export type BuildRouterSwapParams = {
20
21
  routers: Router[];
21
22
  byAmountIn: boolean;
@@ -23,6 +24,7 @@ export type BuildRouterSwapParams = {
23
24
  slippage: number;
24
25
  txb: Transaction;
25
26
  partner?: string;
27
+ deepbookv3DeepFee?: TransactionObjectArgument;
26
28
  };
27
29
  export type BuildFastRouterSwapParams = {
28
30
  routers: Router[];
@@ -32,6 +34,7 @@ export type BuildFastRouterSwapParams = {
32
34
  partner?: string;
33
35
  isMergeTragetCoin?: boolean;
34
36
  refreshAllCoins?: boolean;
37
+ deepbookv3DeepFee?: TransactionObjectArgument;
35
38
  };
36
39
  export interface SwapInPoolsParams {
37
40
  from: string;
@@ -53,17 +56,19 @@ export declare class AggregatorClient {
53
56
  constructor(endpoint: string, signer: string, client: SuiClient, env: Env);
54
57
  getAllCoins(): Promise<CoinAsset[]>;
55
58
  findRouters(params: FindRouterParams): Promise<RouterData | null>;
56
- expectInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], amountOutLimit: BN, partner?: string): Promise<TransactionObjectArgument>;
59
+ expectInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], amountOutLimit: BN, partner?: string, deepbookv3DeepFee?: TransactionObjectArgument): Promise<TransactionObjectArgument>;
57
60
  expectOutputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], partner?: string): Promise<TransactionObjectArgument>;
58
61
  swapInPools(params: SwapInPoolsParams): Promise<SwapInPoolsResult | null>;
59
62
  routerSwap(params: BuildRouterSwapParams): Promise<TransactionObjectArgument>;
60
63
  fastRouterSwap(params: BuildFastRouterSwapParams): Promise<void>;
61
64
  publishedAt(): string;
65
+ deepbookv3DeepFeeType(): string;
62
66
  transferOrDestoryCoin(txb: Transaction, coin: TransactionObjectArgument, coinType: string): void;
63
67
  checkCoinThresholdAndMergeCoin(txb: Transaction, coins: TransactionObjectArgument[], coinType: string, amountLimit: BN): TransactionObjectArgument;
64
68
  newDex(provider: string, partner?: string): Dex;
65
69
  signAndExecuteTransaction(txb: Transaction, signer: Signer): Promise<import("@mysten/sui/client").SuiTransactionBlockResponse>;
66
70
  devInspectTransactionBlock(txb: Transaction): Promise<import("@mysten/sui/client").DevInspectResults>;
67
71
  sendTransaction(txb: Transaction, signer: Signer): Promise<import("@mysten/sui/client").SuiTransactionBlockResponse>;
72
+ getDeepbookV3Config(): Promise<DeepbookV3Config | null>;
68
73
  }
69
74
  export declare function parseRouterResponse(data: any): RouterData;
@@ -0,0 +1,13 @@
1
+ import { Transaction, TransactionArgument, TransactionObjectArgument } from "@mysten/sui/transactions";
2
+ import { AggregatorClient, Dex, Env, Path } from "..";
3
+ export type CetusFlashSwapResult = {
4
+ targetCoin: TransactionObjectArgument;
5
+ flashReceipt: TransactionObjectArgument;
6
+ payAmount: TransactionArgument;
7
+ };
8
+ export declare class DeepbookV3 implements Dex {
9
+ private deepbookV3Config;
10
+ private deepCoinType;
11
+ constructor(env: Env);
12
+ swap(client: AggregatorClient, txb: Transaction, path: Path, inputCoin: TransactionObjectArgument, deepbookv3DeepFee?: TransactionObjectArgument): Promise<TransactionObjectArgument>;
13
+ }
@@ -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,3 @@
1
1
  export * from './contracts';
2
2
  export * from './msafe';
3
+ export * from './api';
@@ -1,4 +1,5 @@
1
1
  export declare const T_USDC = "";
2
+ export declare const T_DEEP = "0x36dbef866a1d62bf7328989a10fb2f07d769f4ee587c0de4a0a256e57e0a58a8::deep::DEEP";
2
3
  export declare const M_USDC = "0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN";
3
4
  export declare const M_CETUS = "0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS";
4
5
  export declare const M_NAVI = "0xa99b8952d4f7d947ea77fe0ecdcc9e5fc0bcab2841d6e2a5aa00c3044e5544b5::navx::NAVX";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cetusprotocol/aggregator-sdk",
3
- "version": "0.0.0-experimental-20240929164543",
3
+ "version": "0.0.0-experimental-20241010160019",
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 = {
@@ -140,7 +141,7 @@ async function getRouter(endpoint: string, params: FindRouterParams) {
140
141
  const fromCoin = completionCoin(from)
141
142
  const targetCoin = completionCoin(target)
142
143
 
143
- let url = `${endpoint}?from=${fromCoin}&target=${targetCoin}&amount=${amount.toString()}&by_amount_in=${byAmountIn}`
144
+ let url = `${endpoint}/find_routes?from=${fromCoin}&target=${targetCoin}&amount=${amount.toString()}&by_amount_in=${byAmountIn}`
144
145
 
145
146
  if (depth) {
146
147
  url += `&depth=${depth}`
@@ -191,11 +192,8 @@ async function postRouterWithLiquidityChanges(
191
192
 
192
193
  const fromCoin = completionCoin(from)
193
194
  const targetCoin = completionCoin(target)
194
-
195
- const url = `${endpoint}`
196
-
195
+ const url = `${endpoint}/find_routes`
197
196
  const providersStr = providers?.join(",")
198
-
199
197
  const requestData = {
200
198
  from: fromCoin,
201
199
  target: targetCoin,
@@ -214,8 +212,6 @@ async function postRouterWithLiquidityChanges(
214
212
  })),
215
213
  }
216
214
 
217
- console.log("requestData", JSON.stringify(requestData, null, 2))
218
-
219
215
  try {
220
216
  const response = await fetch(url, {
221
217
  method: "POST",
@@ -231,3 +227,32 @@ async function postRouterWithLiquidityChanges(
231
227
  return null
232
228
  }
233
229
  }
230
+
231
+ export type DeepbookV3Config = {
232
+ id: string
233
+ is_alternative_payment: boolean
234
+ deep_fee_vault: number
235
+ whitelist: number
236
+ whitelist_pools: string[]
237
+ // unix timestamp in seconds
238
+ last_updated_time: number
239
+ }
240
+
241
+ export type DeepbookV3ConfigResponse = {
242
+ code: number
243
+ msg: string
244
+ data: DeepbookV3Config
245
+ }
246
+
247
+ export async function getDeepbookV3Config(
248
+ endpoint: string
249
+ ): Promise<DeepbookV3ConfigResponse | null> {
250
+ const url = `${endpoint}/deepbookv3_config`
251
+ try {
252
+ const response = await fetch(url)
253
+ return response.json() as Promise<DeepbookV3ConfigResponse>
254
+ } catch (error) {
255
+ console.error("Error:", error)
256
+ return null
257
+ }
258
+ }
package/src/client.ts CHANGED
@@ -15,6 +15,10 @@ import {
15
15
  getRouterResult,
16
16
  Router,
17
17
  RouterData,
18
+ getDeepbookV3Config,
19
+ DeepbookV3ConfigResponse,
20
+ processEndpoint,
21
+ DeepbookV3Config,
18
22
  } from "."
19
23
  import { Aftermath } from "./transaction/aftermath"
20
24
  import { DeepbookV2 } from "./transaction/deepbook_v2"
@@ -32,6 +36,7 @@ import { Volo } from "./transaction/volo"
32
36
  import { Bluemove } from "./transaction/bluemove"
33
37
  import { CoinAsset } from "./types/sui"
34
38
  import { buildInputCoin } from "./utils/coin"
39
+ import { DeepbookV3 } from "./transaction/deepbook_v3"
35
40
 
36
41
  export const CETUS = "CETUS"
37
42
  export const DEEPBOOKV2 = "DEEPBOOK"
@@ -45,6 +50,7 @@ export const HAEDAL = "HAEDAL"
45
50
  export const VOLO = "VOLO"
46
51
  export const AFSUI = "AFSUI"
47
52
  export const BLUEMOVE = "BLUEMOVE"
53
+ export const DEEPBOOKV3 = "DEEPBOOKV3"
48
54
 
49
55
  export type BuildRouterSwapParams = {
50
56
  routers: Router[]
@@ -53,6 +59,7 @@ export type BuildRouterSwapParams = {
53
59
  slippage: number
54
60
  txb: Transaction
55
61
  partner?: string
62
+ deepbookv3DeepFee?: TransactionObjectArgument
56
63
  }
57
64
 
58
65
  export type BuildFastRouterSwapParams = {
@@ -63,6 +70,7 @@ export type BuildFastRouterSwapParams = {
63
70
  partner?: string
64
71
  isMergeTragetCoin?: boolean
65
72
  refreshAllCoins?: boolean
73
+ deepbookv3DeepFee?: TransactionObjectArgument
66
74
  }
67
75
 
68
76
  export interface SwapInPoolsParams {
@@ -86,7 +94,7 @@ export class AggregatorClient {
86
94
  private allCoins: CoinAsset[]
87
95
 
88
96
  constructor(endpoint: string, signer: string, client: SuiClient, env: Env) {
89
- this.endpoint = endpoint
97
+ this.endpoint = processEndpoint(endpoint)
90
98
  this.client = client
91
99
  this.signer = signer
92
100
  this.env = env
@@ -127,7 +135,8 @@ export class AggregatorClient {
127
135
  inputCoin: TransactionObjectArgument,
128
136
  routers: Router[],
129
137
  amountOutLimit: BN,
130
- partner?: string
138
+ partner?: string,
139
+ deepbookv3DeepFee?: TransactionObjectArgument,
131
140
  ) {
132
141
  if (routers.length === 0) {
133
142
  throw new Error("No router found")
@@ -144,12 +153,15 @@ export class AggregatorClient {
144
153
  let nextCoin = inputCoins[i] as TransactionObjectArgument
145
154
  for (const path of routers[i].path) {
146
155
  const dex = this.newDex(path.provider, partner)
147
- nextCoin = await dex.swap(this, txb, path, nextCoin)
156
+ nextCoin = await dex.swap(this, txb, path, nextCoin, deepbookv3DeepFee)
148
157
  }
149
158
 
150
159
  outputCoins.push(nextCoin)
151
160
  }
152
161
  this.transferOrDestoryCoin(txb, inputCoin, inputCoinType)
162
+ if (deepbookv3DeepFee) {
163
+ this.transferOrDestoryCoin(txb, deepbookv3DeepFee, this.deepbookv3DeepFeeType())
164
+ }
153
165
  const mergedTargetCointhis = this.checkCoinThresholdAndMergeCoin(
154
166
  txb,
155
167
  outputCoins,
@@ -229,7 +241,7 @@ export class AggregatorClient {
229
241
  async routerSwap(
230
242
  params: BuildRouterSwapParams
231
243
  ): Promise<TransactionObjectArgument> {
232
- const { routers, inputCoin, slippage, byAmountIn, txb, partner } = params
244
+ const { routers, inputCoin, slippage, byAmountIn, txb, partner, deepbookv3DeepFee } = params
233
245
  const amountIn = routers.reduce(
234
246
  (acc, router) => acc.add(router.amountIn),
235
247
  new BN(0)
@@ -250,7 +262,8 @@ export class AggregatorClient {
250
262
  inputCoin,
251
263
  routers,
252
264
  new BN(amountLimit),
253
- partner
265
+ partner,
266
+ deepbookv3DeepFee
254
267
  )
255
268
  return targetCoin
256
269
  }
@@ -280,6 +293,7 @@ export class AggregatorClient {
280
293
  partner,
281
294
  isMergeTragetCoin,
282
295
  refreshAllCoins,
296
+ deepbookv3DeepFee,
283
297
  } = params
284
298
  if (refreshAllCoins || this.allCoins.length === 0) {
285
299
  this.allCoins = await this.getAllCoins()
@@ -313,6 +327,7 @@ export class AggregatorClient {
313
327
  byAmountIn,
314
328
  txb,
315
329
  partner,
330
+ deepbookv3DeepFee,
316
331
  })
317
332
 
318
333
  if (isMergeTragetCoin) {
@@ -339,7 +354,15 @@ export class AggregatorClient {
339
354
  if (this.env === Env.Mainnet) {
340
355
  return "0x764b8132a94d35abc9dfd91b23a0757b2a717d5ecb04c03098794aa2a508db91"
341
356
  } else {
342
- return "0x6cbaa3e9fbe902d90191b12f315932bc58079cba422bafbd4b4369f80e61f595"
357
+ return "0xf92cdec6c2d73a12d8afa8dd41199b3e95b621272bbc655996539cd30de6a462"
358
+ }
359
+ }
360
+
361
+ deepbookv3DeepFeeType(): string {
362
+ if (this.env === Env.Mainnet) {
363
+ return "0x36dbef866a1d62bf7328989a10fb2f07d769f4ee587c0de4a0a256e57e0a58a8::deep::DEEP"
364
+ } else {
365
+ return "0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP"
343
366
  }
344
367
  }
345
368
 
@@ -372,7 +395,7 @@ export class AggregatorClient {
372
395
  targetCoin = coins[0]
373
396
  }
374
397
 
375
- const res = txb.moveCall({
398
+ txb.moveCall({
376
399
  target: `${this.publishedAt()}::utils::check_coin_threshold`,
377
400
  typeArguments: [coinType],
378
401
  arguments: [targetCoin, txb.pure.u64(amountLimit.toString())],
@@ -386,6 +409,8 @@ export class AggregatorClient {
386
409
  return new Cetus(this.env, partner)
387
410
  case DEEPBOOKV2:
388
411
  return new DeepbookV2(this.env)
412
+ case DEEPBOOKV3:
413
+ return new DeepbookV3(this.env)
389
414
  case KRIYA:
390
415
  return new KriyaV2(this.env)
391
416
  case KRIYAV3:
@@ -441,6 +466,14 @@ export class AggregatorClient {
441
466
  })
442
467
  return res
443
468
  }
469
+
470
+ async getDeepbookV3Config(): Promise<DeepbookV3Config | null> {
471
+ const res = await getDeepbookV3Config(this.endpoint)
472
+ if (res) {
473
+ return res.data
474
+ }
475
+ return null
476
+ }
444
477
  }
445
478
 
446
479
  export function parseRouterResponse(data: any): RouterData {
@@ -461,13 +494,15 @@ export function parseRouterResponse(data: any): RouterData {
461
494
  if (
462
495
  path.provider === TURBOS ||
463
496
  path.provider === AFTERMATH ||
464
- path.provider === CETUS
497
+ path.provider === CETUS ||
498
+ path.provider === DEEPBOOKV3
465
499
  ) {
466
500
  extendedDetails = {
467
501
  aftermathLpSupplyType:
468
502
  path.extended_details?.aftermath_lp_supply_type,
469
503
  turbosFeeType: path.extended_details?.turbos_fee_type,
470
504
  afterSqrtPrice: path.extended_details?.after_sqrt_price,
505
+ deepbookv3DeepFee: path.extended_details?.deepbookv3_deep_fee,
471
506
  }
472
507
  }
473
508
 
@@ -3,7 +3,6 @@ import {
3
3
  TransactionObjectArgument,
4
4
  } from "@mysten/sui/transactions"
5
5
  import { AggregatorClient, Dex, Env, Path } from ".."
6
- import { SUI_SYSTEM_ADDRESS } from "@mysten/sui/utils"
7
6
 
8
7
  export class Afsui implements Dex {
9
8
  private stakedSuiVault: string
@@ -1,8 +1,6 @@
1
1
  import {
2
2
  Transaction,
3
- TransactionArgument,
4
3
  TransactionObjectArgument,
5
- TransactionResult,
6
4
  } from "@mysten/sui/transactions"
7
5
  import { AggregatorClient, Dex, Env, Path } from ".."
8
6
  import BN from "bn.js"
@@ -1,6 +1,5 @@
1
1
  import {
2
2
  Transaction,
3
- TransactionArgument,
4
3
  TransactionObjectArgument,
5
4
  } from "@mysten/sui/transactions"
6
5
  import { AggregatorClient, CLOCK_ADDRESS, Dex, Env, Path } from ".."