@cetusprotocol/aggregator-sdk 0.0.0-experimental-20241009201249 → 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.d.mts CHANGED
@@ -80,6 +80,7 @@ type BuildRouterSwapParams = {
80
80
  slippage: number;
81
81
  txb: Transaction;
82
82
  partner?: string;
83
+ deepbookv3DeepFee?: TransactionObjectArgument;
83
84
  };
84
85
  type BuildFastRouterSwapParams = {
85
86
  routers: Router[];
@@ -89,6 +90,7 @@ type BuildFastRouterSwapParams = {
89
90
  partner?: string;
90
91
  isMergeTragetCoin?: boolean;
91
92
  refreshAllCoins?: boolean;
93
+ deepbookv3DeepFee?: TransactionObjectArgument;
92
94
  };
93
95
  interface SwapInPoolsParams {
94
96
  from: string;
@@ -110,24 +112,26 @@ declare class AggregatorClient {
110
112
  constructor(endpoint: string, signer: string, client: SuiClient, env: Env);
111
113
  getAllCoins(): Promise<CoinAsset[]>;
112
114
  findRouters(params: FindRouterParams): Promise<RouterData | null>;
113
- expectInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], amountOutLimit: BN, partner?: string): Promise<TransactionObjectArgument>;
115
+ expectInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], amountOutLimit: BN, partner?: string, deepbookv3DeepFee?: TransactionObjectArgument): Promise<TransactionObjectArgument>;
114
116
  expectOutputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], partner?: string): Promise<TransactionObjectArgument>;
115
117
  swapInPools(params: SwapInPoolsParams): Promise<SwapInPoolsResult | null>;
116
118
  routerSwap(params: BuildRouterSwapParams): Promise<TransactionObjectArgument>;
117
119
  fastRouterSwap(params: BuildFastRouterSwapParams): Promise<void>;
118
120
  publishedAt(): string;
121
+ deepbookv3DeepFeeType(): string;
119
122
  transferOrDestoryCoin(txb: Transaction, coin: TransactionObjectArgument, coinType: string): void;
120
123
  checkCoinThresholdAndMergeCoin(txb: Transaction, coins: TransactionObjectArgument[], coinType: string, amountLimit: BN): TransactionObjectArgument;
121
124
  newDex(provider: string, partner?: string): Dex;
122
125
  signAndExecuteTransaction(txb: Transaction, signer: Signer): Promise<_mysten_sui_client.SuiTransactionBlockResponse>;
123
126
  devInspectTransactionBlock(txb: Transaction): Promise<_mysten_sui_client.DevInspectResults>;
124
127
  sendTransaction(txb: Transaction, signer: Signer): Promise<_mysten_sui_client.SuiTransactionBlockResponse>;
128
+ getDeepbookV3Config(): Promise<DeepbookV3Config | null>;
125
129
  }
126
130
  declare function parseRouterResponse(data: any): RouterData;
127
131
 
128
132
  declare const CLOCK_ADDRESS = "0x0000000000000000000000000000000000000000000000000000000000000006";
129
133
  interface Dex {
130
- swap(client: AggregatorClient, ptb: Transaction, path: Path, inputCoin: TransactionObjectArgument): Promise<TransactionObjectArgument>;
134
+ swap(client: AggregatorClient, ptb: Transaction, path: Path, inputCoin: TransactionObjectArgument, deepbookv3DeepFee?: TransactionObjectArgument): Promise<TransactionObjectArgument>;
131
135
  }
132
136
 
133
137
  declare function isSortedSymbols(symbolX: string, symbolY: string): boolean;
@@ -149,6 +153,8 @@ declare function createTarget(packageName: string, moduleName: string, functionN
149
153
  declare const dealWithFastRouterSwapParamsForMsafe: (data: any) => any;
150
154
  declare const restituteMsafeFastRouterSwapParams: (data: any) => any;
151
155
 
156
+ declare function processEndpoint(endpoint: string): string;
157
+
152
158
  declare const ZERO: BN;
153
159
  declare const ONE: BN;
154
160
  declare const TWO: BN;
@@ -180,6 +186,7 @@ type ExtendedDetails = {
180
186
  aftermathLpSupplyType?: string;
181
187
  turbosFeeType?: string;
182
188
  afterSqrtPrice?: string;
189
+ deepbookv3DeepFee?: number;
183
190
  };
184
191
  type Path = {
185
192
  id: string;
@@ -216,10 +223,24 @@ type AggregatorResponse = {
216
223
  data: RouterData;
217
224
  };
218
225
  declare function getRouterResult(endpoint: string, params: FindRouterParams): Promise<RouterData | null>;
226
+ type DeepbookV3Config = {
227
+ id: string;
228
+ is_alternative_payment: boolean;
229
+ deep_fee_vault: number;
230
+ whitelist: number;
231
+ whitelist_pools: string[];
232
+ last_updated_time: number;
233
+ };
234
+ type DeepbookV3ConfigResponse = {
235
+ code: number;
236
+ msg: string;
237
+ data: DeepbookV3Config;
238
+ };
239
+ declare function getDeepbookV3Config(endpoint: string): Promise<DeepbookV3ConfigResponse | null>;
219
240
 
220
241
  declare enum Env {
221
242
  Mainnet = 0,
222
243
  Testnet = 1
223
244
  }
224
245
 
225
- export { AFSUI, AFTERMATH, AggregatorClient, type AggregatorResponse, BLUEMOVE, type BuildFastRouterSwapParams, type BuildRouterSwapParams, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, DEEPBOOKV3, 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 };
246
+ export { AFSUI, AFTERMATH, AggregatorClient, type AggregatorResponse, BLUEMOVE, type BuildFastRouterSwapParams, type BuildRouterSwapParams, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, DEEPBOOKV3, type DeepbookV3Config, type DeepbookV3ConfigResponse, 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, getDeepbookV3Config, getRouterResult, isSortedSymbols, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId, processEndpoint, restituteMsafeFastRouterSwapParams };
package/dist/index.d.ts CHANGED
@@ -80,6 +80,7 @@ type BuildRouterSwapParams = {
80
80
  slippage: number;
81
81
  txb: Transaction;
82
82
  partner?: string;
83
+ deepbookv3DeepFee?: TransactionObjectArgument;
83
84
  };
84
85
  type BuildFastRouterSwapParams = {
85
86
  routers: Router[];
@@ -89,6 +90,7 @@ type BuildFastRouterSwapParams = {
89
90
  partner?: string;
90
91
  isMergeTragetCoin?: boolean;
91
92
  refreshAllCoins?: boolean;
93
+ deepbookv3DeepFee?: TransactionObjectArgument;
92
94
  };
93
95
  interface SwapInPoolsParams {
94
96
  from: string;
@@ -110,24 +112,26 @@ declare class AggregatorClient {
110
112
  constructor(endpoint: string, signer: string, client: SuiClient, env: Env);
111
113
  getAllCoins(): Promise<CoinAsset[]>;
112
114
  findRouters(params: FindRouterParams): Promise<RouterData | null>;
113
- expectInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], amountOutLimit: BN, partner?: string): Promise<TransactionObjectArgument>;
115
+ expectInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], amountOutLimit: BN, partner?: string, deepbookv3DeepFee?: TransactionObjectArgument): Promise<TransactionObjectArgument>;
114
116
  expectOutputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], partner?: string): Promise<TransactionObjectArgument>;
115
117
  swapInPools(params: SwapInPoolsParams): Promise<SwapInPoolsResult | null>;
116
118
  routerSwap(params: BuildRouterSwapParams): Promise<TransactionObjectArgument>;
117
119
  fastRouterSwap(params: BuildFastRouterSwapParams): Promise<void>;
118
120
  publishedAt(): string;
121
+ deepbookv3DeepFeeType(): string;
119
122
  transferOrDestoryCoin(txb: Transaction, coin: TransactionObjectArgument, coinType: string): void;
120
123
  checkCoinThresholdAndMergeCoin(txb: Transaction, coins: TransactionObjectArgument[], coinType: string, amountLimit: BN): TransactionObjectArgument;
121
124
  newDex(provider: string, partner?: string): Dex;
122
125
  signAndExecuteTransaction(txb: Transaction, signer: Signer): Promise<_mysten_sui_client.SuiTransactionBlockResponse>;
123
126
  devInspectTransactionBlock(txb: Transaction): Promise<_mysten_sui_client.DevInspectResults>;
124
127
  sendTransaction(txb: Transaction, signer: Signer): Promise<_mysten_sui_client.SuiTransactionBlockResponse>;
128
+ getDeepbookV3Config(): Promise<DeepbookV3Config | null>;
125
129
  }
126
130
  declare function parseRouterResponse(data: any): RouterData;
127
131
 
128
132
  declare const CLOCK_ADDRESS = "0x0000000000000000000000000000000000000000000000000000000000000006";
129
133
  interface Dex {
130
- swap(client: AggregatorClient, ptb: Transaction, path: Path, inputCoin: TransactionObjectArgument): Promise<TransactionObjectArgument>;
134
+ swap(client: AggregatorClient, ptb: Transaction, path: Path, inputCoin: TransactionObjectArgument, deepbookv3DeepFee?: TransactionObjectArgument): Promise<TransactionObjectArgument>;
131
135
  }
132
136
 
133
137
  declare function isSortedSymbols(symbolX: string, symbolY: string): boolean;
@@ -149,6 +153,8 @@ declare function createTarget(packageName: string, moduleName: string, functionN
149
153
  declare const dealWithFastRouterSwapParamsForMsafe: (data: any) => any;
150
154
  declare const restituteMsafeFastRouterSwapParams: (data: any) => any;
151
155
 
156
+ declare function processEndpoint(endpoint: string): string;
157
+
152
158
  declare const ZERO: BN;
153
159
  declare const ONE: BN;
154
160
  declare const TWO: BN;
@@ -180,6 +186,7 @@ type ExtendedDetails = {
180
186
  aftermathLpSupplyType?: string;
181
187
  turbosFeeType?: string;
182
188
  afterSqrtPrice?: string;
189
+ deepbookv3DeepFee?: number;
183
190
  };
184
191
  type Path = {
185
192
  id: string;
@@ -216,10 +223,24 @@ type AggregatorResponse = {
216
223
  data: RouterData;
217
224
  };
218
225
  declare function getRouterResult(endpoint: string, params: FindRouterParams): Promise<RouterData | null>;
226
+ type DeepbookV3Config = {
227
+ id: string;
228
+ is_alternative_payment: boolean;
229
+ deep_fee_vault: number;
230
+ whitelist: number;
231
+ whitelist_pools: string[];
232
+ last_updated_time: number;
233
+ };
234
+ type DeepbookV3ConfigResponse = {
235
+ code: number;
236
+ msg: string;
237
+ data: DeepbookV3Config;
238
+ };
239
+ declare function getDeepbookV3Config(endpoint: string): Promise<DeepbookV3ConfigResponse | null>;
219
240
 
220
241
  declare enum Env {
221
242
  Mainnet = 0,
222
243
  Testnet = 1
223
244
  }
224
245
 
225
- export { AFSUI, AFTERMATH, AggregatorClient, type AggregatorResponse, BLUEMOVE, type BuildFastRouterSwapParams, type BuildRouterSwapParams, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, DEEPBOOKV3, 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 };
246
+ export { AFSUI, AFTERMATH, AggregatorClient, type AggregatorResponse, BLUEMOVE, type BuildFastRouterSwapParams, type BuildRouterSwapParams, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, DEEPBOOKV3, type DeepbookV3Config, type DeepbookV3ConfigResponse, 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, getDeepbookV3Config, getRouterResult, isSortedSymbols, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId, processEndpoint, restituteMsafeFastRouterSwapParams };
package/dist/index.js CHANGED
@@ -5995,19 +5995,30 @@ var Bluemove = class {
5995
5995
  // src/transaction/deepbook_v3.ts
5996
5996
  var DeepbookV3 = class {
5997
5997
  constructor(env) {
5998
- this.deepbookV3Config = env === 0 /* Mainnet */ ? "0x0" : "0x77018927a5d7ed7b4c49312b71581f5f12ba52ba7e1219a15181ffc3d459f527";
5998
+ this.deepbookV3Config = env === 0 /* Mainnet */ ? "0x0" : "0xe19b5d072346cae83a037d4e3c8492068a74410a74e5830b3a68012db38296aa";
5999
5999
  this.deepCoinType = env === 0 /* Mainnet */ ? "0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP" : "0x36dbef866a1d62bf7328989a10fb2f07d769f4ee587c0de4a0a256e57e0a58a8::deep::DEEP";
6000
6000
  }
6001
- swap(client, txb, path, inputCoin) {
6001
+ swap(client, txb, path, inputCoin, deepbookv3DeepFee) {
6002
6002
  return __async(this, null, function* () {
6003
+ var _a, _b, _c;
6003
6004
  const { direction, from, target } = path;
6004
6005
  const [func, coinAType, coinBType] = direction ? ["swap_a2b", from, target] : ["swap_b2a", target, from];
6005
- const zeroDeep = mintZeroCoin(txb, this.deepCoinType);
6006
+ let deepFee;
6007
+ if (deepbookv3DeepFee) {
6008
+ if (((_a = path.extendedDetails) == null ? void 0 : _a.deepbookv3DeepFee) && ((_b = path.extendedDetails) == null ? void 0 : _b.deepbookv3DeepFee) > 0) {
6009
+ const splitAmounts = [(_c = path.extendedDetails) == null ? void 0 : _c.deepbookv3DeepFee];
6010
+ deepFee = txb.splitCoins(deepbookv3DeepFee, splitAmounts)[0];
6011
+ } else {
6012
+ deepFee = mintZeroCoin(txb, this.deepCoinType);
6013
+ }
6014
+ } else {
6015
+ deepFee = mintZeroCoin(txb, this.deepCoinType);
6016
+ }
6006
6017
  const args = [
6007
6018
  txb.object(this.deepbookV3Config),
6008
6019
  txb.object(path.id),
6009
6020
  inputCoin,
6010
- zeroDeep,
6021
+ deepFee,
6011
6022
  txb.object(CLOCK_ADDRESS)
6012
6023
  ];
6013
6024
  const res = txb.moveCall({
@@ -6036,7 +6047,7 @@ var BLUEMOVE = "BLUEMOVE";
6036
6047
  var DEEPBOOKV3 = "DEEPBOOKV3";
6037
6048
  var AggregatorClient7 = class {
6038
6049
  constructor(endpoint, signer, client, env) {
6039
- this.endpoint = endpoint;
6050
+ this.endpoint = processEndpoint(endpoint);
6040
6051
  this.client = client;
6041
6052
  this.signer = signer;
6042
6053
  this.env = env;
@@ -6073,7 +6084,7 @@ var AggregatorClient7 = class {
6073
6084
  return getRouterResult(this.endpoint, params);
6074
6085
  });
6075
6086
  }
6076
- expectInputSwap(txb, inputCoin, routers, amountOutLimit, partner) {
6087
+ expectInputSwap(txb, inputCoin, routers, amountOutLimit, partner, deepbookv3DeepFee) {
6077
6088
  return __async(this, null, function* () {
6078
6089
  if (routers.length === 0) {
6079
6090
  throw new Error("No router found");
@@ -6090,11 +6101,14 @@ var AggregatorClient7 = class {
6090
6101
  let nextCoin = inputCoins[i];
6091
6102
  for (const path of routers[i].path) {
6092
6103
  const dex = this.newDex(path.provider, partner);
6093
- nextCoin = yield dex.swap(this, txb, path, nextCoin);
6104
+ nextCoin = yield dex.swap(this, txb, path, nextCoin, deepbookv3DeepFee);
6094
6105
  }
6095
6106
  outputCoins.push(nextCoin);
6096
6107
  }
6097
6108
  this.transferOrDestoryCoin(txb, inputCoin, inputCoinType);
6109
+ if (deepbookv3DeepFee) {
6110
+ this.transferOrDestoryCoin(txb, deepbookv3DeepFee, this.deepbookv3DeepFeeType());
6111
+ }
6098
6112
  const mergedTargetCointhis = this.checkCoinThresholdAndMergeCoin(
6099
6113
  txb,
6100
6114
  outputCoins,
@@ -6166,7 +6180,7 @@ var AggregatorClient7 = class {
6166
6180
  }
6167
6181
  routerSwap(params) {
6168
6182
  return __async(this, null, function* () {
6169
- const { routers, inputCoin, slippage, byAmountIn, txb, partner } = params;
6183
+ const { routers, inputCoin, slippage, byAmountIn, txb, partner, deepbookv3DeepFee } = params;
6170
6184
  const amountIn = routers.reduce(
6171
6185
  (acc, router) => acc.add(router.amountIn),
6172
6186
  new import_bn5.default(0)
@@ -6186,7 +6200,8 @@ var AggregatorClient7 = class {
6186
6200
  inputCoin,
6187
6201
  routers,
6188
6202
  new import_bn5.default(amountLimit),
6189
- partner
6203
+ partner,
6204
+ deepbookv3DeepFee
6190
6205
  );
6191
6206
  return targetCoin2;
6192
6207
  }
@@ -6214,7 +6229,8 @@ var AggregatorClient7 = class {
6214
6229
  txb,
6215
6230
  partner,
6216
6231
  isMergeTragetCoin,
6217
- refreshAllCoins
6232
+ refreshAllCoins,
6233
+ deepbookv3DeepFee
6218
6234
  } = params;
6219
6235
  if (refreshAllCoins || this.allCoins.length === 0) {
6220
6236
  this.allCoins = yield this.getAllCoins();
@@ -6247,7 +6263,8 @@ var AggregatorClient7 = class {
6247
6263
  slippage,
6248
6264
  byAmountIn,
6249
6265
  txb,
6250
- partner
6266
+ partner,
6267
+ deepbookv3DeepFee
6251
6268
  });
6252
6269
  if (isMergeTragetCoin) {
6253
6270
  const targetCoinRes = buildInputCoin(
@@ -6273,7 +6290,14 @@ var AggregatorClient7 = class {
6273
6290
  if (this.env === 0 /* Mainnet */) {
6274
6291
  return "0x764b8132a94d35abc9dfd91b23a0757b2a717d5ecb04c03098794aa2a508db91";
6275
6292
  } else {
6276
- return "0xb2db335c85473e7ed952351bb594100eb8f61122703219c6b8dbcdcade2795b3";
6293
+ return "0xf92cdec6c2d73a12d8afa8dd41199b3e95b621272bbc655996539cd30de6a462";
6294
+ }
6295
+ }
6296
+ deepbookv3DeepFeeType() {
6297
+ if (this.env === 0 /* Mainnet */) {
6298
+ return "0x36dbef866a1d62bf7328989a10fb2f07d769f4ee587c0de4a0a256e57e0a58a8::deep::DEEP";
6299
+ } else {
6300
+ return "0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP";
6277
6301
  }
6278
6302
  }
6279
6303
  transferOrDestoryCoin(txb, coin, coinType) {
@@ -6366,6 +6390,15 @@ var AggregatorClient7 = class {
6366
6390
  return res;
6367
6391
  });
6368
6392
  }
6393
+ getDeepbookV3Config() {
6394
+ return __async(this, null, function* () {
6395
+ const res = yield getDeepbookV3Config(this.endpoint);
6396
+ if (res) {
6397
+ return res.data;
6398
+ }
6399
+ return null;
6400
+ });
6401
+ }
6369
6402
  };
6370
6403
  function parseRouterResponse(data) {
6371
6404
  return {
@@ -6375,17 +6408,18 @@ function parseRouterResponse(data) {
6375
6408
  routes: data.routes.map((route) => {
6376
6409
  return {
6377
6410
  path: route.path.map((path) => {
6378
- var _a, _b, _c;
6411
+ var _a, _b, _c, _d;
6379
6412
  let version;
6380
6413
  if (path.provider === AFTERMATH) {
6381
6414
  version = path.extended_details.aftermath_pool_flatness === 0 ? "v2" : "v3";
6382
6415
  }
6383
6416
  let extendedDetails;
6384
- if (path.provider === TURBOS || path.provider === AFTERMATH || path.provider === CETUS) {
6417
+ if (path.provider === TURBOS || path.provider === AFTERMATH || path.provider === CETUS || path.provider === DEEPBOOKV3) {
6385
6418
  extendedDetails = {
6386
6419
  aftermathLpSupplyType: (_a = path.extended_details) == null ? void 0 : _a.aftermath_lp_supply_type,
6387
6420
  turbosFeeType: (_b = path.extended_details) == null ? void 0 : _b.turbos_fee_type,
6388
- afterSqrtPrice: (_c = path.extended_details) == null ? void 0 : _c.after_sqrt_price
6421
+ afterSqrtPrice: (_c = path.extended_details) == null ? void 0 : _c.after_sqrt_price,
6422
+ deepbookv3DeepFee: (_d = path.extended_details) == null ? void 0 : _d.deepbookv3_deep_fee
6389
6423
  };
6390
6424
  }
6391
6425
  return {
@@ -6437,6 +6471,14 @@ var restituteMsafeFastRouterSwapParams = (data) => {
6437
6471
  return result;
6438
6472
  };
6439
6473
 
6474
+ // src/utils/api.ts
6475
+ function processEndpoint(endpoint) {
6476
+ if (endpoint.endsWith("/find_routes")) {
6477
+ return endpoint.replace("/find_routes", "");
6478
+ }
6479
+ return endpoint;
6480
+ }
6481
+
6440
6482
  // src/api.ts
6441
6483
  function getRouterResult(endpoint, params) {
6442
6484
  return __async(this, null, function* () {
@@ -6499,7 +6541,7 @@ function getRouter(endpoint, params) {
6499
6541
  } = params;
6500
6542
  const fromCoin = completionCoin(from);
6501
6543
  const targetCoin = completionCoin(target);
6502
- let url = `${endpoint}?from=${fromCoin}&target=${targetCoin}&amount=${amount.toString()}&by_amount_in=${byAmountIn}`;
6544
+ let url = `${endpoint}/find_routes?from=${fromCoin}&target=${targetCoin}&amount=${amount.toString()}&by_amount_in=${byAmountIn}`;
6503
6545
  if (depth) {
6504
6546
  url += `&depth=${depth}`;
6505
6547
  }
@@ -6541,7 +6583,7 @@ function postRouterWithLiquidityChanges(endpoint, params) {
6541
6583
  } = params;
6542
6584
  const fromCoin = completionCoin(from);
6543
6585
  const targetCoin = completionCoin(target);
6544
- const url = `${endpoint}`;
6586
+ const url = `${endpoint}/find_routes`;
6545
6587
  const providersStr = providers == null ? void 0 : providers.join(",");
6546
6588
  const requestData = {
6547
6589
  from: fromCoin,
@@ -6560,7 +6602,6 @@ function postRouterWithLiquidityChanges(endpoint, params) {
6560
6602
  delta_liquidity: change.deltaLiquidity
6561
6603
  }))
6562
6604
  };
6563
- console.log("requestData", JSON.stringify(requestData, null, 2));
6564
6605
  try {
6565
6606
  const response = yield fetch(url, {
6566
6607
  method: "POST",
@@ -6576,6 +6617,18 @@ function postRouterWithLiquidityChanges(endpoint, params) {
6576
6617
  }
6577
6618
  });
6578
6619
  }
6620
+ function getDeepbookV3Config(endpoint) {
6621
+ return __async(this, null, function* () {
6622
+ const url = `${endpoint}/deepbookv3_config`;
6623
+ try {
6624
+ const response = yield fetch(url);
6625
+ return response.json();
6626
+ } catch (error) {
6627
+ console.error("Error:", error);
6628
+ return null;
6629
+ }
6630
+ });
6631
+ }
6579
6632
 
6580
6633
  // src/index.ts
6581
6634
  var Env = /* @__PURE__ */ ((Env2) => {
@@ -6624,9 +6677,11 @@ exports.dealWithFastRouterSwapParamsForMsafe = dealWithFastRouterSwapParamsForMs
6624
6677
  exports.extractAddressFromType = extractAddressFromType;
6625
6678
  exports.extractStructTagFromType = extractStructTagFromType;
6626
6679
  exports.fixSuiObjectId = fixSuiObjectId;
6680
+ exports.getDeepbookV3Config = getDeepbookV3Config;
6627
6681
  exports.getRouterResult = getRouterResult;
6628
6682
  exports.isSortedSymbols = isSortedSymbols;
6629
6683
  exports.normalizeCoinType = normalizeCoinType;
6630
6684
  exports.parseRouterResponse = parseRouterResponse;
6631
6685
  exports.patchFixSuiObjectId = patchFixSuiObjectId;
6686
+ exports.processEndpoint = processEndpoint;
6632
6687
  exports.restituteMsafeFastRouterSwapParams = restituteMsafeFastRouterSwapParams;
package/dist/index.mjs CHANGED
@@ -5993,19 +5993,30 @@ var Bluemove = class {
5993
5993
  // src/transaction/deepbook_v3.ts
5994
5994
  var DeepbookV3 = class {
5995
5995
  constructor(env) {
5996
- this.deepbookV3Config = env === 0 /* Mainnet */ ? "0x0" : "0x77018927a5d7ed7b4c49312b71581f5f12ba52ba7e1219a15181ffc3d459f527";
5996
+ this.deepbookV3Config = env === 0 /* Mainnet */ ? "0x0" : "0xe19b5d072346cae83a037d4e3c8492068a74410a74e5830b3a68012db38296aa";
5997
5997
  this.deepCoinType = env === 0 /* Mainnet */ ? "0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP" : "0x36dbef866a1d62bf7328989a10fb2f07d769f4ee587c0de4a0a256e57e0a58a8::deep::DEEP";
5998
5998
  }
5999
- swap(client, txb, path, inputCoin) {
5999
+ swap(client, txb, path, inputCoin, deepbookv3DeepFee) {
6000
6000
  return __async(this, null, function* () {
6001
+ var _a, _b, _c;
6001
6002
  const { direction, from, target } = path;
6002
6003
  const [func, coinAType, coinBType] = direction ? ["swap_a2b", from, target] : ["swap_b2a", target, from];
6003
- const zeroDeep = mintZeroCoin(txb, this.deepCoinType);
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
+ }
6004
6015
  const args = [
6005
6016
  txb.object(this.deepbookV3Config),
6006
6017
  txb.object(path.id),
6007
6018
  inputCoin,
6008
- zeroDeep,
6019
+ deepFee,
6009
6020
  txb.object(CLOCK_ADDRESS)
6010
6021
  ];
6011
6022
  const res = txb.moveCall({
@@ -6034,7 +6045,7 @@ var BLUEMOVE = "BLUEMOVE";
6034
6045
  var DEEPBOOKV3 = "DEEPBOOKV3";
6035
6046
  var AggregatorClient7 = class {
6036
6047
  constructor(endpoint, signer, client, env) {
6037
- this.endpoint = endpoint;
6048
+ this.endpoint = processEndpoint(endpoint);
6038
6049
  this.client = client;
6039
6050
  this.signer = signer;
6040
6051
  this.env = env;
@@ -6071,7 +6082,7 @@ var AggregatorClient7 = class {
6071
6082
  return getRouterResult(this.endpoint, params);
6072
6083
  });
6073
6084
  }
6074
- expectInputSwap(txb, inputCoin, routers, amountOutLimit, partner) {
6085
+ expectInputSwap(txb, inputCoin, routers, amountOutLimit, partner, deepbookv3DeepFee) {
6075
6086
  return __async(this, null, function* () {
6076
6087
  if (routers.length === 0) {
6077
6088
  throw new Error("No router found");
@@ -6088,11 +6099,14 @@ var AggregatorClient7 = class {
6088
6099
  let nextCoin = inputCoins[i];
6089
6100
  for (const path of routers[i].path) {
6090
6101
  const dex = this.newDex(path.provider, partner);
6091
- nextCoin = yield dex.swap(this, txb, path, nextCoin);
6102
+ nextCoin = yield dex.swap(this, txb, path, nextCoin, deepbookv3DeepFee);
6092
6103
  }
6093
6104
  outputCoins.push(nextCoin);
6094
6105
  }
6095
6106
  this.transferOrDestoryCoin(txb, inputCoin, inputCoinType);
6107
+ if (deepbookv3DeepFee) {
6108
+ this.transferOrDestoryCoin(txb, deepbookv3DeepFee, this.deepbookv3DeepFeeType());
6109
+ }
6096
6110
  const mergedTargetCointhis = this.checkCoinThresholdAndMergeCoin(
6097
6111
  txb,
6098
6112
  outputCoins,
@@ -6164,7 +6178,7 @@ var AggregatorClient7 = class {
6164
6178
  }
6165
6179
  routerSwap(params) {
6166
6180
  return __async(this, null, function* () {
6167
- const { routers, inputCoin, slippage, byAmountIn, txb, partner } = params;
6181
+ const { routers, inputCoin, slippage, byAmountIn, txb, partner, deepbookv3DeepFee } = params;
6168
6182
  const amountIn = routers.reduce(
6169
6183
  (acc, router) => acc.add(router.amountIn),
6170
6184
  new import_bn5.default(0)
@@ -6184,7 +6198,8 @@ var AggregatorClient7 = class {
6184
6198
  inputCoin,
6185
6199
  routers,
6186
6200
  new import_bn5.default(amountLimit),
6187
- partner
6201
+ partner,
6202
+ deepbookv3DeepFee
6188
6203
  );
6189
6204
  return targetCoin2;
6190
6205
  }
@@ -6212,7 +6227,8 @@ var AggregatorClient7 = class {
6212
6227
  txb,
6213
6228
  partner,
6214
6229
  isMergeTragetCoin,
6215
- refreshAllCoins
6230
+ refreshAllCoins,
6231
+ deepbookv3DeepFee
6216
6232
  } = params;
6217
6233
  if (refreshAllCoins || this.allCoins.length === 0) {
6218
6234
  this.allCoins = yield this.getAllCoins();
@@ -6245,7 +6261,8 @@ var AggregatorClient7 = class {
6245
6261
  slippage,
6246
6262
  byAmountIn,
6247
6263
  txb,
6248
- partner
6264
+ partner,
6265
+ deepbookv3DeepFee
6249
6266
  });
6250
6267
  if (isMergeTragetCoin) {
6251
6268
  const targetCoinRes = buildInputCoin(
@@ -6271,7 +6288,14 @@ var AggregatorClient7 = class {
6271
6288
  if (this.env === 0 /* Mainnet */) {
6272
6289
  return "0x764b8132a94d35abc9dfd91b23a0757b2a717d5ecb04c03098794aa2a508db91";
6273
6290
  } else {
6274
- return "0xb2db335c85473e7ed952351bb594100eb8f61122703219c6b8dbcdcade2795b3";
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";
6275
6299
  }
6276
6300
  }
6277
6301
  transferOrDestoryCoin(txb, coin, coinType) {
@@ -6364,6 +6388,15 @@ var AggregatorClient7 = class {
6364
6388
  return res;
6365
6389
  });
6366
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
+ }
6367
6400
  };
6368
6401
  function parseRouterResponse(data) {
6369
6402
  return {
@@ -6373,17 +6406,18 @@ function parseRouterResponse(data) {
6373
6406
  routes: data.routes.map((route) => {
6374
6407
  return {
6375
6408
  path: route.path.map((path) => {
6376
- var _a, _b, _c;
6409
+ var _a, _b, _c, _d;
6377
6410
  let version;
6378
6411
  if (path.provider === AFTERMATH) {
6379
6412
  version = path.extended_details.aftermath_pool_flatness === 0 ? "v2" : "v3";
6380
6413
  }
6381
6414
  let extendedDetails;
6382
- if (path.provider === TURBOS || path.provider === AFTERMATH || path.provider === CETUS) {
6415
+ if (path.provider === TURBOS || path.provider === AFTERMATH || path.provider === CETUS || path.provider === DEEPBOOKV3) {
6383
6416
  extendedDetails = {
6384
6417
  aftermathLpSupplyType: (_a = path.extended_details) == null ? void 0 : _a.aftermath_lp_supply_type,
6385
6418
  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
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
6387
6421
  };
6388
6422
  }
6389
6423
  return {
@@ -6435,6 +6469,14 @@ var restituteMsafeFastRouterSwapParams = (data) => {
6435
6469
  return result;
6436
6470
  };
6437
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
+
6438
6480
  // src/api.ts
6439
6481
  function getRouterResult(endpoint, params) {
6440
6482
  return __async(this, null, function* () {
@@ -6497,7 +6539,7 @@ function getRouter(endpoint, params) {
6497
6539
  } = params;
6498
6540
  const fromCoin = completionCoin(from);
6499
6541
  const targetCoin = completionCoin(target);
6500
- 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}`;
6501
6543
  if (depth) {
6502
6544
  url += `&depth=${depth}`;
6503
6545
  }
@@ -6539,7 +6581,7 @@ function postRouterWithLiquidityChanges(endpoint, params) {
6539
6581
  } = params;
6540
6582
  const fromCoin = completionCoin(from);
6541
6583
  const targetCoin = completionCoin(target);
6542
- const url = `${endpoint}`;
6584
+ const url = `${endpoint}/find_routes`;
6543
6585
  const providersStr = providers == null ? void 0 : providers.join(",");
6544
6586
  const requestData = {
6545
6587
  from: fromCoin,
@@ -6558,7 +6600,6 @@ function postRouterWithLiquidityChanges(endpoint, params) {
6558
6600
  delta_liquidity: change.deltaLiquidity
6559
6601
  }))
6560
6602
  };
6561
- console.log("requestData", JSON.stringify(requestData, null, 2));
6562
6603
  try {
6563
6604
  const response = yield fetch(url, {
6564
6605
  method: "POST",
@@ -6574,6 +6615,18 @@ function postRouterWithLiquidityChanges(endpoint, params) {
6574
6615
  }
6575
6616
  });
6576
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
+ }
6577
6630
 
6578
6631
  // src/index.ts
6579
6632
  var Env = /* @__PURE__ */ ((Env2) => {
@@ -6593,4 +6646,4 @@ decimal.js/decimal.mjs:
6593
6646
  *)
6594
6647
  */
6595
6648
 
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 };
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";
@@ -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
+ deepbookv3DeepFee?: TransactionObjectArgument;
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,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-20241009201249",
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"
@@ -47,6 +51,7 @@ export const VOLO = "VOLO"
47
51
  export const AFSUI = "AFSUI"
48
52
  export const BLUEMOVE = "BLUEMOVE"
49
53
  export const DEEPBOOKV3 = "DEEPBOOKV3"
54
+
50
55
  export type BuildRouterSwapParams = {
51
56
  routers: Router[]
52
57
  byAmountIn: boolean
@@ -54,6 +59,7 @@ export type BuildRouterSwapParams = {
54
59
  slippage: number
55
60
  txb: Transaction
56
61
  partner?: string
62
+ deepbookv3DeepFee?: TransactionObjectArgument
57
63
  }
58
64
 
59
65
  export type BuildFastRouterSwapParams = {
@@ -64,6 +70,7 @@ export type BuildFastRouterSwapParams = {
64
70
  partner?: string
65
71
  isMergeTragetCoin?: boolean
66
72
  refreshAllCoins?: boolean
73
+ deepbookv3DeepFee?: TransactionObjectArgument
67
74
  }
68
75
 
69
76
  export interface SwapInPoolsParams {
@@ -87,7 +94,7 @@ export class AggregatorClient {
87
94
  private allCoins: CoinAsset[]
88
95
 
89
96
  constructor(endpoint: string, signer: string, client: SuiClient, env: Env) {
90
- this.endpoint = endpoint
97
+ this.endpoint = processEndpoint(endpoint)
91
98
  this.client = client
92
99
  this.signer = signer
93
100
  this.env = env
@@ -128,7 +135,8 @@ export class AggregatorClient {
128
135
  inputCoin: TransactionObjectArgument,
129
136
  routers: Router[],
130
137
  amountOutLimit: BN,
131
- partner?: string
138
+ partner?: string,
139
+ deepbookv3DeepFee?: TransactionObjectArgument,
132
140
  ) {
133
141
  if (routers.length === 0) {
134
142
  throw new Error("No router found")
@@ -145,12 +153,15 @@ export class AggregatorClient {
145
153
  let nextCoin = inputCoins[i] as TransactionObjectArgument
146
154
  for (const path of routers[i].path) {
147
155
  const dex = this.newDex(path.provider, partner)
148
- nextCoin = await dex.swap(this, txb, path, nextCoin)
156
+ nextCoin = await dex.swap(this, txb, path, nextCoin, deepbookv3DeepFee)
149
157
  }
150
158
 
151
159
  outputCoins.push(nextCoin)
152
160
  }
153
161
  this.transferOrDestoryCoin(txb, inputCoin, inputCoinType)
162
+ if (deepbookv3DeepFee) {
163
+ this.transferOrDestoryCoin(txb, deepbookv3DeepFee, this.deepbookv3DeepFeeType())
164
+ }
154
165
  const mergedTargetCointhis = this.checkCoinThresholdAndMergeCoin(
155
166
  txb,
156
167
  outputCoins,
@@ -230,7 +241,7 @@ export class AggregatorClient {
230
241
  async routerSwap(
231
242
  params: BuildRouterSwapParams
232
243
  ): Promise<TransactionObjectArgument> {
233
- const { routers, inputCoin, slippage, byAmountIn, txb, partner } = params
244
+ const { routers, inputCoin, slippage, byAmountIn, txb, partner, deepbookv3DeepFee } = params
234
245
  const amountIn = routers.reduce(
235
246
  (acc, router) => acc.add(router.amountIn),
236
247
  new BN(0)
@@ -251,7 +262,8 @@ export class AggregatorClient {
251
262
  inputCoin,
252
263
  routers,
253
264
  new BN(amountLimit),
254
- partner
265
+ partner,
266
+ deepbookv3DeepFee
255
267
  )
256
268
  return targetCoin
257
269
  }
@@ -281,6 +293,7 @@ export class AggregatorClient {
281
293
  partner,
282
294
  isMergeTragetCoin,
283
295
  refreshAllCoins,
296
+ deepbookv3DeepFee,
284
297
  } = params
285
298
  if (refreshAllCoins || this.allCoins.length === 0) {
286
299
  this.allCoins = await this.getAllCoins()
@@ -314,6 +327,7 @@ export class AggregatorClient {
314
327
  byAmountIn,
315
328
  txb,
316
329
  partner,
330
+ deepbookv3DeepFee,
317
331
  })
318
332
 
319
333
  if (isMergeTragetCoin) {
@@ -340,7 +354,15 @@ export class AggregatorClient {
340
354
  if (this.env === Env.Mainnet) {
341
355
  return "0x764b8132a94d35abc9dfd91b23a0757b2a717d5ecb04c03098794aa2a508db91"
342
356
  } else {
343
- return "0xb2db335c85473e7ed952351bb594100eb8f61122703219c6b8dbcdcade2795b3"
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"
344
366
  }
345
367
  }
346
368
 
@@ -444,6 +466,14 @@ export class AggregatorClient {
444
466
  })
445
467
  return res
446
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
+ }
447
477
  }
448
478
 
449
479
  export function parseRouterResponse(data: any): RouterData {
@@ -464,13 +494,15 @@ export function parseRouterResponse(data: any): RouterData {
464
494
  if (
465
495
  path.provider === TURBOS ||
466
496
  path.provider === AFTERMATH ||
467
- path.provider === CETUS
497
+ path.provider === CETUS ||
498
+ path.provider === DEEPBOOKV3
468
499
  ) {
469
500
  extendedDetails = {
470
501
  aftermathLpSupplyType:
471
502
  path.extended_details?.aftermath_lp_supply_type,
472
503
  turbosFeeType: path.extended_details?.turbos_fee_type,
473
504
  afterSqrtPrice: path.extended_details?.after_sqrt_price,
505
+ deepbookv3DeepFee: path.extended_details?.deepbookv3_deep_fee,
474
506
  }
475
507
  }
476
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"
@@ -20,7 +20,7 @@ export class DeepbookV3 implements Dex {
20
20
  this.deepbookV3Config =
21
21
  env === Env.Mainnet
22
22
  ? "0x0"
23
- : "0x77018927a5d7ed7b4c49312b71581f5f12ba52ba7e1219a15181ffc3d459f527"
23
+ : "0xe19b5d072346cae83a037d4e3c8492068a74410a74e5830b3a68012db38296aa"
24
24
  this.deepCoinType =
25
25
  env === Env.Mainnet
26
26
  ? "0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP"
@@ -31,19 +31,31 @@ export class DeepbookV3 implements Dex {
31
31
  client: AggregatorClient,
32
32
  txb: Transaction,
33
33
  path: Path,
34
- inputCoin: TransactionObjectArgument
34
+ inputCoin: TransactionObjectArgument,
35
+ deepbookv3DeepFee?: TransactionObjectArgument
35
36
  ): Promise<TransactionObjectArgument> {
36
37
  const { direction, from, target } = path
37
38
  const [func, coinAType, coinBType] = direction
38
39
  ? ["swap_a2b", from, target]
39
40
  : ["swap_b2a", target, from]
40
41
 
41
- const zeroDeep = mintZeroCoin(txb, this.deepCoinType)
42
+ let deepFee
43
+ if (deepbookv3DeepFee) {
44
+ if (path.extendedDetails?.deepbookv3DeepFee && path.extendedDetails?.deepbookv3DeepFee > 0) {
45
+ const splitAmounts = [path.extendedDetails?.deepbookv3DeepFee]
46
+ deepFee = txb.splitCoins(deepbookv3DeepFee, splitAmounts)[0] as TransactionObjectArgument
47
+ } else {
48
+ deepFee = mintZeroCoin(txb, this.deepCoinType)
49
+ }
50
+ } else {
51
+ deepFee = mintZeroCoin(txb, this.deepCoinType)
52
+ }
53
+
42
54
  const args = [
43
55
  txb.object(this.deepbookV3Config),
44
56
  txb.object(path.id),
45
57
  inputCoin,
46
- zeroDeep,
58
+ deepFee,
47
59
  txb.object(CLOCK_ADDRESS),
48
60
  ]
49
61
  const res = txb.moveCall({
@@ -12,6 +12,7 @@ export interface Dex {
12
12
  client: AggregatorClient,
13
13
  ptb: Transaction,
14
14
  path: Path,
15
- inputCoin: TransactionObjectArgument
15
+ inputCoin: TransactionObjectArgument,
16
+ deepbookv3DeepFee?: TransactionObjectArgument
16
17
  ): Promise<TransactionObjectArgument>
17
18
  }
@@ -0,0 +1,6 @@
1
+ export function processEndpoint(endpoint: string) {
2
+ if (endpoint.endsWith("/find_routes")) {
3
+ return endpoint.replace("/find_routes", "")
4
+ }
5
+ return endpoint
6
+ }
@@ -1,2 +1,3 @@
1
1
  export * from './contracts'
2
2
  export * from './msafe'
3
+ export * from './api'
@@ -8,6 +8,7 @@ import {
8
8
  M_SSWP,
9
9
  M_SUI,
10
10
  M_USDC,
11
+ T_DEEP,
11
12
  } from "./test_data.test"
12
13
  import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519"
13
14
  import { printTransaction } from "~/utils/transaction"
@@ -40,12 +41,12 @@ describe("router module", () => {
40
41
  keypair = buildTestAccount()
41
42
  }
42
43
 
43
- // const wallet = keypair.getPublicKey().toSuiAddress()
44
+ const wallet = keypair.getPublicKey().toSuiAddress()
44
45
 
45
46
  // console.log("wallet", wallet, "\n", wallet.toString())
46
47
 
47
- const wallet =
48
- "0xfba94aa36e93ccc7d84a6a57040fc51983223f1b522a8d0be3c3bf2c98977ebb"
48
+ // const wallet =
49
+ // "0xfba94aa36e93ccc7d84a6a57040fc51983223f1b522a8d0be3c3bf2c98977ebb"
49
50
  // const wallet =
50
51
  // "0xa459702162b73204eed77420d93d9453b7a7b893a0edea1e268607cf7fa76e03"
51
52
  // const wallet =
@@ -69,12 +70,15 @@ describe("router module", () => {
69
70
  publishedAt:
70
71
  "0x8faab90228e4c4df91c41626bbaefa19fc25c514405ac64de54578dec9e6f5ee",
71
72
  }
73
+ // const endpoint =
74
+ // "https://api-sui-cloudfront.cetus.zone/router_v2/find_routes"
72
75
  const endpoint =
73
- "https://api-sui-cloudfront.cetus.zone/router_v2/find_routes"
76
+ "http://localhost:8080/router_v2/find_routes"
77
+
74
78
  const suiClient = new SuiClient({
75
- url: "https://fullnode.mainnet.sui.io:443",
79
+ url: "https://fullnode.testnet.sui.io:443",
76
80
  })
77
- client = new AggregatorClient(endpoint, wallet, suiClient, Env.Mainnet)
81
+ client = new AggregatorClient(endpoint, wallet, suiClient, Env.Testnet)
78
82
  })
79
83
 
80
84
  test("Get all coins", () => {
@@ -135,15 +139,9 @@ describe("router module", () => {
135
139
 
136
140
  test("Build router tx", async () => {
137
141
  const byAmountIn = true
138
- const amount = "1000000000"
139
-
142
+ const amount = "20000000000"
140
143
  const from = M_SUI
141
- // const target =
142
- // "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI"
143
- // const target =
144
- // "0xf325ce1300e8dac124071d3152c5c5ee6174914f8bc2161e88329cf579246efc::afsui::AFSUI"
145
-
146
- const target = M_USDC
144
+ const target = T_DEEP
147
145
 
148
146
  const res = await client.findRouters({
149
147
  from,
@@ -152,14 +150,14 @@ describe("router module", () => {
152
150
  byAmountIn,
153
151
  depth: 3,
154
152
  providers: [
155
- // "CETUS",
153
+ "CETUS",
156
154
  // "DEEPBOOK",
157
155
  // "AFTERMATH",
158
156
  // "FLOWX",
159
157
  // "KRIYA",
160
158
  // "KRIYAV3",
161
159
  // "TURBOS",
162
- "BLUEMOVE",
160
+ "DEEPBOOKV3",
163
161
  ],
164
162
  })
165
163
 
@@ -188,13 +186,13 @@ describe("router module", () => {
188
186
  let result = await client.devInspectTransactionBlock(txb)
189
187
  console.log("🚀 ~ file: router.test.ts:180 ~ test ~ result:", result)
190
188
 
191
- // if (result.effects.status.status === "success") {
192
- // console.log("Sim exec transaction success")
193
- // const result = await client.signAndExecuteTransaction(txb, keypair)
194
- // // console.log("result", result)
195
- // } else {
196
- // console.log("result", result)
197
- // }
189
+ if (result.effects.status.status === "success") {
190
+ // console.log("Sim exec transaction success")
191
+ const result = await client.signAndExecuteTransaction(txb, keypair)
192
+ console.log("result", result)
193
+ } else {
194
+ console.log("result", result)
195
+ }
198
196
  }
199
197
  }, 600000)
200
198
 
@@ -348,9 +346,6 @@ describe("router module", () => {
348
346
  console.log(JSON.stringify(res, null, 2))
349
347
  }
350
348
 
351
- console.log("amount in", res?.amountIn.toString())
352
- console.log("amount out", res?.amountOut.toString())
353
-
354
349
  const txb = new Transaction()
355
350
 
356
351
  if (res != null) {
@@ -378,4 +373,9 @@ describe("router module", () => {
378
373
  // }
379
374
  }
380
375
  }, 600000)
376
+
377
+ test("Get deepbook v3 config", async () => {
378
+ const config = await client.getDeepbookV3Config()
379
+ console.log("config", config)
380
+ }, 60000)
381
381
  })
@@ -1,5 +1,6 @@
1
1
  // Testnet
2
2
  export const T_USDC = ""
3
+ export const T_DEEP = "0x36dbef866a1d62bf7328989a10fb2f07d769f4ee587c0de4a0a256e57e0a58a8::deep::DEEP"
3
4
 
4
5
  // Mainnet
5
6
  export const M_USDC =