@cetusprotocol/aggregator-sdk 0.0.0-experimental-20241009201249 → 0.0.0-experimental-20241011180351

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
@@ -5712,6 +5712,16 @@ function buildInputCoin(txb, allCoins, amount, coinType) {
5712
5712
  }
5713
5713
 
5714
5714
  // src/utils/transaction.ts
5715
+ function printTransaction(tx, isPrint = true) {
5716
+ return __async(this, null, function* () {
5717
+ console.log(`inputs`, tx.getData().inputs);
5718
+ tx.getData().commands.forEach((item, index) => {
5719
+ if (isPrint) {
5720
+ console.log(`transaction ${index}: `, JSON.stringify(item, null, 2));
5721
+ }
5722
+ });
5723
+ });
5724
+ }
5715
5725
  function checkInvalidSuiAddress(address) {
5716
5726
  if (!address.startsWith("0x") || address.length !== 66) {
5717
5727
  return false;
@@ -5993,19 +6003,30 @@ var Bluemove = class {
5993
6003
  // src/transaction/deepbook_v3.ts
5994
6004
  var DeepbookV3 = class {
5995
6005
  constructor(env) {
5996
- this.deepbookV3Config = env === 0 /* Mainnet */ ? "0x0" : "0x77018927a5d7ed7b4c49312b71581f5f12ba52ba7e1219a15181ffc3d459f527";
6006
+ this.deepbookV3Config = env === 0 /* Mainnet */ ? "0x0" : "0xe19b5d072346cae83a037d4e3c8492068a74410a74e5830b3a68012db38296aa";
5997
6007
  this.deepCoinType = env === 0 /* Mainnet */ ? "0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP" : "0x36dbef866a1d62bf7328989a10fb2f07d769f4ee587c0de4a0a256e57e0a58a8::deep::DEEP";
5998
6008
  }
5999
- swap(client, txb, path, inputCoin) {
6009
+ swap(client, txb, path, inputCoin, deepbookv3DeepFee) {
6000
6010
  return __async(this, null, function* () {
6011
+ var _a, _b, _c;
6001
6012
  const { direction, from, target } = path;
6002
6013
  const [func, coinAType, coinBType] = direction ? ["swap_a2b", from, target] : ["swap_b2a", target, from];
6003
- const zeroDeep = mintZeroCoin(txb, this.deepCoinType);
6014
+ let deepFee;
6015
+ if (deepbookv3DeepFee) {
6016
+ if (((_a = path.extendedDetails) == null ? void 0 : _a.deepbookv3DeepFee) && ((_b = path.extendedDetails) == null ? void 0 : _b.deepbookv3DeepFee) > 0) {
6017
+ const splitAmounts = [(_c = path.extendedDetails) == null ? void 0 : _c.deepbookv3DeepFee];
6018
+ deepFee = txb.splitCoins(deepbookv3DeepFee, splitAmounts)[0];
6019
+ } else {
6020
+ deepFee = mintZeroCoin(txb, this.deepCoinType);
6021
+ }
6022
+ } else {
6023
+ deepFee = mintZeroCoin(txb, this.deepCoinType);
6024
+ }
6004
6025
  const args = [
6005
6026
  txb.object(this.deepbookV3Config),
6006
6027
  txb.object(path.id),
6007
6028
  inputCoin,
6008
- zeroDeep,
6029
+ deepFee,
6009
6030
  txb.object(CLOCK_ADDRESS)
6010
6031
  ];
6011
6032
  const res = txb.moveCall({
@@ -6034,7 +6055,7 @@ var BLUEMOVE = "BLUEMOVE";
6034
6055
  var DEEPBOOKV3 = "DEEPBOOKV3";
6035
6056
  var AggregatorClient7 = class {
6036
6057
  constructor(endpoint, signer, client, env) {
6037
- this.endpoint = endpoint;
6058
+ this.endpoint = processEndpoint(endpoint);
6038
6059
  this.client = client;
6039
6060
  this.signer = signer;
6040
6061
  this.env = env;
@@ -6071,7 +6092,7 @@ var AggregatorClient7 = class {
6071
6092
  return getRouterResult(this.endpoint, params);
6072
6093
  });
6073
6094
  }
6074
- expectInputSwap(txb, inputCoin, routers, amountOutLimit, partner) {
6095
+ expectInputSwap(txb, inputCoin, routers, amountOutLimit, partner, deepbookv3DeepFee) {
6075
6096
  return __async(this, null, function* () {
6076
6097
  if (routers.length === 0) {
6077
6098
  throw new Error("No router found");
@@ -6088,11 +6109,14 @@ var AggregatorClient7 = class {
6088
6109
  let nextCoin = inputCoins[i];
6089
6110
  for (const path of routers[i].path) {
6090
6111
  const dex = this.newDex(path.provider, partner);
6091
- nextCoin = yield dex.swap(this, txb, path, nextCoin);
6112
+ nextCoin = yield dex.swap(this, txb, path, nextCoin, deepbookv3DeepFee);
6092
6113
  }
6093
6114
  outputCoins.push(nextCoin);
6094
6115
  }
6095
6116
  this.transferOrDestoryCoin(txb, inputCoin, inputCoinType);
6117
+ if (deepbookv3DeepFee) {
6118
+ this.transferOrDestoryCoin(txb, deepbookv3DeepFee, this.deepbookv3DeepFeeType());
6119
+ }
6096
6120
  const mergedTargetCointhis = this.checkCoinThresholdAndMergeCoin(
6097
6121
  txb,
6098
6122
  outputCoins,
@@ -6164,7 +6188,7 @@ var AggregatorClient7 = class {
6164
6188
  }
6165
6189
  routerSwap(params) {
6166
6190
  return __async(this, null, function* () {
6167
- const { routers, inputCoin, slippage, byAmountIn, txb, partner } = params;
6191
+ const { routers, inputCoin, slippage, byAmountIn, txb, partner, deepbookv3DeepFee } = params;
6168
6192
  const amountIn = routers.reduce(
6169
6193
  (acc, router) => acc.add(router.amountIn),
6170
6194
  new import_bn5.default(0)
@@ -6184,7 +6208,8 @@ var AggregatorClient7 = class {
6184
6208
  inputCoin,
6185
6209
  routers,
6186
6210
  new import_bn5.default(amountLimit),
6187
- partner
6211
+ partner,
6212
+ deepbookv3DeepFee
6188
6213
  );
6189
6214
  return targetCoin2;
6190
6215
  }
@@ -6212,7 +6237,8 @@ var AggregatorClient7 = class {
6212
6237
  txb,
6213
6238
  partner,
6214
6239
  isMergeTragetCoin,
6215
- refreshAllCoins
6240
+ refreshAllCoins,
6241
+ payDeepFeeAmount
6216
6242
  } = params;
6217
6243
  if (refreshAllCoins || this.allCoins.length === 0) {
6218
6244
  this.allCoins = yield this.getAllCoins();
@@ -6239,13 +6265,30 @@ var AggregatorClient7 = class {
6239
6265
  BigInt(amount.toString()),
6240
6266
  fromCoinType
6241
6267
  );
6268
+ let buildDeepFeeCoinRes;
6269
+ if (payDeepFeeAmount && payDeepFeeAmount > 0) {
6270
+ buildDeepFeeCoinRes = buildInputCoin(
6271
+ txb,
6272
+ this.allCoins,
6273
+ BigInt(payDeepFeeAmount),
6274
+ this.deepbookv3DeepFeeType()
6275
+ );
6276
+ } else {
6277
+ buildDeepFeeCoinRes = buildInputCoin(
6278
+ txb,
6279
+ this.allCoins,
6280
+ BigInt(0),
6281
+ this.deepbookv3DeepFeeType()
6282
+ );
6283
+ }
6242
6284
  const targetCoin = yield this.routerSwap({
6243
6285
  routers,
6244
6286
  inputCoin: buildFromCoinRes.targetCoin,
6245
6287
  slippage,
6246
6288
  byAmountIn,
6247
6289
  txb,
6248
- partner
6290
+ partner,
6291
+ deepbookv3DeepFee: buildDeepFeeCoinRes.targetCoin
6249
6292
  });
6250
6293
  if (isMergeTragetCoin) {
6251
6294
  const targetCoinRes = buildInputCoin(
@@ -6271,7 +6314,14 @@ var AggregatorClient7 = class {
6271
6314
  if (this.env === 0 /* Mainnet */) {
6272
6315
  return "0x764b8132a94d35abc9dfd91b23a0757b2a717d5ecb04c03098794aa2a508db91";
6273
6316
  } else {
6274
- return "0xb2db335c85473e7ed952351bb594100eb8f61122703219c6b8dbcdcade2795b3";
6317
+ return "0xf92cdec6c2d73a12d8afa8dd41199b3e95b621272bbc655996539cd30de6a462";
6318
+ }
6319
+ }
6320
+ deepbookv3DeepFeeType() {
6321
+ if (this.env === 0 /* Mainnet */) {
6322
+ return "0x36dbef866a1d62bf7328989a10fb2f07d769f4ee587c0de4a0a256e57e0a58a8::deep::DEEP";
6323
+ } else {
6324
+ return "0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::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
  }
@@ -6539,7 +6617,7 @@ function postRouterWithLiquidityChanges(endpoint, params) {
6539
6617
  } = params;
6540
6618
  const fromCoin = completionCoin(from);
6541
6619
  const targetCoin = completionCoin(target);
6542
- const url = `${endpoint}`;
6620
+ const url = `${endpoint}/find_routes`;
6543
6621
  const providersStr = providers == null ? void 0 : providers.join(",");
6544
6622
  const requestData = {
6545
6623
  from: fromCoin,
@@ -6558,7 +6636,6 @@ function postRouterWithLiquidityChanges(endpoint, params) {
6558
6636
  delta_liquidity: change.deltaLiquidity
6559
6637
  }))
6560
6638
  };
6561
- console.log("requestData", JSON.stringify(requestData, null, 2));
6562
6639
  try {
6563
6640
  const response = yield fetch(url, {
6564
6641
  method: "POST",
@@ -6574,6 +6651,18 @@ function postRouterWithLiquidityChanges(endpoint, params) {
6574
6651
  }
6575
6652
  });
6576
6653
  }
6654
+ function getDeepbookV3Config(endpoint) {
6655
+ return __async(this, null, function* () {
6656
+ const url = `${endpoint}/deepbookv3_config`;
6657
+ try {
6658
+ const response = yield fetch(url);
6659
+ return response.json();
6660
+ } catch (error) {
6661
+ console.error("Error:", error);
6662
+ return null;
6663
+ }
6664
+ });
6665
+ }
6577
6666
 
6578
6667
  // src/index.ts
6579
6668
  var Env = /* @__PURE__ */ ((Env2) => {
@@ -6593,4 +6682,4 @@ decimal.js/decimal.mjs:
6593
6682
  *)
6594
6683
  */
6595
6684
 
6596
- 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 };
6685
+ 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, 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,17 @@ 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
+ deep_fee_vault: number;
68
+ whitelist: number;
69
+ whitelist_pools: string[];
70
+ last_updated_time: number;
71
+ };
72
+ export type DeepbookV3ConfigResponse = {
73
+ code: number;
74
+ msg: string;
75
+ data: DeepbookV3Config;
76
+ };
77
+ 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";
@@ -24,6 +24,7 @@ export type BuildRouterSwapParams = {
24
24
  slippage: number;
25
25
  txb: Transaction;
26
26
  partner?: string;
27
+ deepbookv3DeepFee?: TransactionObjectArgument;
27
28
  };
28
29
  export type BuildFastRouterSwapParams = {
29
30
  routers: Router[];
@@ -33,6 +34,7 @@ export type BuildFastRouterSwapParams = {
33
34
  partner?: string;
34
35
  isMergeTragetCoin?: boolean;
35
36
  refreshAllCoins?: boolean;
37
+ payDeepFeeAmount?: number;
36
38
  };
37
39
  export interface SwapInPoolsParams {
38
40
  from: string;
@@ -54,17 +56,19 @@ export declare class AggregatorClient {
54
56
  constructor(endpoint: string, signer: string, client: SuiClient, env: Env);
55
57
  getAllCoins(): Promise<CoinAsset[]>;
56
58
  findRouters(params: FindRouterParams): Promise<RouterData | null>;
57
- 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>;
58
60
  expectOutputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], partner?: string): Promise<TransactionObjectArgument>;
59
61
  swapInPools(params: SwapInPoolsParams): Promise<SwapInPoolsResult | null>;
60
62
  routerSwap(params: BuildRouterSwapParams): Promise<TransactionObjectArgument>;
61
63
  fastRouterSwap(params: BuildFastRouterSwapParams): Promise<void>;
62
64
  publishedAt(): string;
65
+ deepbookv3DeepFeeType(): string;
63
66
  transferOrDestoryCoin(txb: Transaction, coin: TransactionObjectArgument, coinType: string): void;
64
67
  checkCoinThresholdAndMergeCoin(txb: Transaction, coins: TransactionObjectArgument[], coinType: string, amountLimit: BN): TransactionObjectArgument;
65
68
  newDex(provider: string, partner?: string): Dex;
66
69
  signAndExecuteTransaction(txb: Transaction, signer: Signer): Promise<import("@mysten/sui/client").SuiTransactionBlockResponse>;
67
70
  devInspectTransactionBlock(txb: Transaction): Promise<import("@mysten/sui/client").DevInspectResults>;
68
71
  sendTransaction(txb: Transaction, signer: Signer): Promise<import("@mysten/sui/client").SuiTransactionBlockResponse>;
72
+ getDeepbookV3Config(): Promise<DeepbookV3Config | null>;
69
73
  }
70
74
  export declare function parseRouterResponse(data: any): RouterData;
@@ -9,5 +9,5 @@ export declare class DeepbookV3 implements Dex {
9
9
  private deepbookV3Config;
10
10
  private deepCoinType;
11
11
  constructor(env: Env);
12
- swap(client: AggregatorClient, txb: Transaction, path: Path, inputCoin: TransactionObjectArgument): Promise<TransactionObjectArgument>;
12
+ swap(client: AggregatorClient, txb: Transaction, path: Path, inputCoin: TransactionObjectArgument, deepbookv3DeepFee?: TransactionObjectArgument): Promise<TransactionObjectArgument>;
13
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,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";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cetusprotocol/aggregator-sdk",
3
- "version": "0.0.0-experimental-20241009201249",
3
+ "version": "0.0.0-experimental-20241011180351",
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}`
@@ -191,11 +193,8 @@ async function postRouterWithLiquidityChanges(
191
193
 
192
194
  const fromCoin = completionCoin(from)
193
195
  const targetCoin = completionCoin(target)
194
-
195
- const url = `${endpoint}`
196
-
196
+ const url = `${endpoint}/find_routes`
197
197
  const providersStr = providers?.join(",")
198
-
199
198
  const requestData = {
200
199
  from: fromCoin,
201
200
  target: targetCoin,
@@ -214,8 +213,6 @@ async function postRouterWithLiquidityChanges(
214
213
  })),
215
214
  }
216
215
 
217
- console.log("requestData", JSON.stringify(requestData, null, 2))
218
-
219
216
  try {
220
217
  const response = await fetch(url, {
221
218
  method: "POST",
@@ -231,3 +228,32 @@ async function postRouterWithLiquidityChanges(
231
228
  return null
232
229
  }
233
230
  }
231
+
232
+ export type DeepbookV3Config = {
233
+ id: string
234
+ is_alternative_payment: boolean
235
+ deep_fee_vault: number
236
+ whitelist: number
237
+ whitelist_pools: string[]
238
+ // unix timestamp in seconds
239
+ last_updated_time: number
240
+ }
241
+
242
+ export type DeepbookV3ConfigResponse = {
243
+ code: number
244
+ msg: string
245
+ data: DeepbookV3Config
246
+ }
247
+
248
+ export async function getDeepbookV3Config(
249
+ endpoint: string
250
+ ): Promise<DeepbookV3ConfigResponse | null> {
251
+ const url = `${endpoint}/deepbookv3_config`
252
+ try {
253
+ const response = await fetch(url)
254
+ return response.json() as Promise<DeepbookV3ConfigResponse>
255
+ } catch (error) {
256
+ console.error("Error:", error)
257
+ return null
258
+ }
259
+ }
package/src/client.ts CHANGED
@@ -15,6 +15,11 @@ import {
15
15
  getRouterResult,
16
16
  Router,
17
17
  RouterData,
18
+ getDeepbookV3Config,
19
+ DeepbookV3ConfigResponse,
20
+ processEndpoint,
21
+ DeepbookV3Config,
22
+ ZERO,
18
23
  } from "."
19
24
  import { Aftermath } from "./transaction/aftermath"
20
25
  import { DeepbookV2 } from "./transaction/deepbook_v2"
@@ -47,6 +52,7 @@ export const VOLO = "VOLO"
47
52
  export const AFSUI = "AFSUI"
48
53
  export const BLUEMOVE = "BLUEMOVE"
49
54
  export const DEEPBOOKV3 = "DEEPBOOKV3"
55
+
50
56
  export type BuildRouterSwapParams = {
51
57
  routers: Router[]
52
58
  byAmountIn: boolean
@@ -54,6 +60,9 @@ export type BuildRouterSwapParams = {
54
60
  slippage: number
55
61
  txb: Transaction
56
62
  partner?: string
63
+ // This parameter is used to pass the Deep token object. When using the DeepBook V3 provider,
64
+ // users must pay fees with Deep tokens in non-whitelisted pools.
65
+ deepbookv3DeepFee?: TransactionObjectArgument
57
66
  }
58
67
 
59
68
  export type BuildFastRouterSwapParams = {
@@ -64,6 +73,7 @@ export type BuildFastRouterSwapParams = {
64
73
  partner?: string
65
74
  isMergeTragetCoin?: boolean
66
75
  refreshAllCoins?: boolean
76
+ payDeepFeeAmount?: number
67
77
  }
68
78
 
69
79
  export interface SwapInPoolsParams {
@@ -87,7 +97,7 @@ export class AggregatorClient {
87
97
  private allCoins: CoinAsset[]
88
98
 
89
99
  constructor(endpoint: string, signer: string, client: SuiClient, env: Env) {
90
- this.endpoint = endpoint
100
+ this.endpoint = processEndpoint(endpoint)
91
101
  this.client = client
92
102
  this.signer = signer
93
103
  this.env = env
@@ -128,7 +138,8 @@ export class AggregatorClient {
128
138
  inputCoin: TransactionObjectArgument,
129
139
  routers: Router[],
130
140
  amountOutLimit: BN,
131
- partner?: string
141
+ partner?: string,
142
+ deepbookv3DeepFee?: TransactionObjectArgument,
132
143
  ) {
133
144
  if (routers.length === 0) {
134
145
  throw new Error("No router found")
@@ -145,12 +156,15 @@ export class AggregatorClient {
145
156
  let nextCoin = inputCoins[i] as TransactionObjectArgument
146
157
  for (const path of routers[i].path) {
147
158
  const dex = this.newDex(path.provider, partner)
148
- nextCoin = await dex.swap(this, txb, path, nextCoin)
159
+ nextCoin = await dex.swap(this, txb, path, nextCoin, deepbookv3DeepFee)
149
160
  }
150
161
 
151
162
  outputCoins.push(nextCoin)
152
163
  }
153
164
  this.transferOrDestoryCoin(txb, inputCoin, inputCoinType)
165
+ if (deepbookv3DeepFee) {
166
+ this.transferOrDestoryCoin(txb, deepbookv3DeepFee, this.deepbookv3DeepFeeType())
167
+ }
154
168
  const mergedTargetCointhis = this.checkCoinThresholdAndMergeCoin(
155
169
  txb,
156
170
  outputCoins,
@@ -230,7 +244,7 @@ export class AggregatorClient {
230
244
  async routerSwap(
231
245
  params: BuildRouterSwapParams
232
246
  ): Promise<TransactionObjectArgument> {
233
- const { routers, inputCoin, slippage, byAmountIn, txb, partner } = params
247
+ const { routers, inputCoin, slippage, byAmountIn, txb, partner, deepbookv3DeepFee } = params
234
248
  const amountIn = routers.reduce(
235
249
  (acc, router) => acc.add(router.amountIn),
236
250
  new BN(0)
@@ -251,7 +265,8 @@ export class AggregatorClient {
251
265
  inputCoin,
252
266
  routers,
253
267
  new BN(amountLimit),
254
- partner
268
+ partner,
269
+ deepbookv3DeepFee
255
270
  )
256
271
  return targetCoin
257
272
  }
@@ -281,6 +296,7 @@ export class AggregatorClient {
281
296
  partner,
282
297
  isMergeTragetCoin,
283
298
  refreshAllCoins,
299
+ payDeepFeeAmount,
284
300
  } = params
285
301
  if (refreshAllCoins || this.allCoins.length === 0) {
286
302
  this.allCoins = await this.getAllCoins()
@@ -307,6 +323,24 @@ export class AggregatorClient {
307
323
  BigInt(amount.toString()),
308
324
  fromCoinType
309
325
  )
326
+
327
+ let buildDeepFeeCoinRes
328
+ if (payDeepFeeAmount && payDeepFeeAmount > 0) {
329
+ buildDeepFeeCoinRes = buildInputCoin(
330
+ txb,
331
+ this.allCoins,
332
+ BigInt(payDeepFeeAmount),
333
+ this.deepbookv3DeepFeeType()
334
+ )
335
+ } else {
336
+ buildDeepFeeCoinRes = buildInputCoin(
337
+ txb,
338
+ this.allCoins,
339
+ BigInt(0),
340
+ this.deepbookv3DeepFeeType()
341
+ )
342
+ }
343
+
310
344
  const targetCoin = await this.routerSwap({
311
345
  routers,
312
346
  inputCoin: buildFromCoinRes.targetCoin,
@@ -314,6 +348,7 @@ export class AggregatorClient {
314
348
  byAmountIn,
315
349
  txb,
316
350
  partner,
351
+ deepbookv3DeepFee: buildDeepFeeCoinRes.targetCoin,
317
352
  })
318
353
 
319
354
  if (isMergeTragetCoin) {
@@ -340,7 +375,15 @@ export class AggregatorClient {
340
375
  if (this.env === Env.Mainnet) {
341
376
  return "0x764b8132a94d35abc9dfd91b23a0757b2a717d5ecb04c03098794aa2a508db91"
342
377
  } else {
343
- return "0xb2db335c85473e7ed952351bb594100eb8f61122703219c6b8dbcdcade2795b3"
378
+ return "0xf92cdec6c2d73a12d8afa8dd41199b3e95b621272bbc655996539cd30de6a462"
379
+ }
380
+ }
381
+
382
+ deepbookv3DeepFeeType(): string {
383
+ if (this.env === Env.Mainnet) {
384
+ return "0x36dbef866a1d62bf7328989a10fb2f07d769f4ee587c0de4a0a256e57e0a58a8::deep::DEEP"
385
+ } else {
386
+ return "0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP"
344
387
  }
345
388
  }
346
389
 
@@ -444,10 +487,27 @@ export class AggregatorClient {
444
487
  })
445
488
  return res
446
489
  }
490
+
491
+ async getDeepbookV3Config(): Promise<DeepbookV3Config | null> {
492
+ const res = await getDeepbookV3Config(this.endpoint)
493
+ if (res) {
494
+ return res.data
495
+ }
496
+ return null
497
+ }
447
498
  }
448
499
 
449
500
  export function parseRouterResponse(data: any): RouterData {
450
- return {
501
+ let totalDeepFee = 0
502
+ for (const route of data.routes) {
503
+ for (const path of route.path) {
504
+ if (path.extended_details && path.extended_details.deepbookv3_deep_fee) {
505
+ totalDeepFee += Number(path.extended_details.deepbookv3_deep_fee)
506
+ }
507
+ }
508
+ }
509
+
510
+ let routerData: RouterData = {
451
511
  amountIn: new BN(data.amount_in.toString()),
452
512
  amountOut: new BN(data.amount_out.toString()),
453
513
  insufficientLiquidity: false,
@@ -464,13 +524,15 @@ export function parseRouterResponse(data: any): RouterData {
464
524
  if (
465
525
  path.provider === TURBOS ||
466
526
  path.provider === AFTERMATH ||
467
- path.provider === CETUS
527
+ path.provider === CETUS ||
528
+ path.provider === DEEPBOOKV3
468
529
  ) {
469
530
  extendedDetails = {
470
531
  aftermathLpSupplyType:
471
532
  path.extended_details?.aftermath_lp_supply_type,
472
533
  turbosFeeType: path.extended_details?.turbos_fee_type,
473
534
  afterSqrtPrice: path.extended_details?.after_sqrt_price,
535
+ deepbookv3DeepFee: path.extended_details?.deepbookv3_deep_fee,
474
536
  }
475
537
  }
476
538
 
@@ -492,5 +554,8 @@ export function parseRouterResponse(data: any): RouterData {
492
554
  initialPrice: new Decimal(route.initial_price.toString()),
493
555
  }
494
556
  }),
557
+ totalDeepFee: totalDeepFee,
495
558
  }
559
+
560
+ return routerData
496
561
  }