@cetusprotocol/aggregator-sdk 0.3.1 → 0.3.3

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
@@ -73,6 +73,7 @@ declare const VOLO = "VOLO";
73
73
  declare const AFSUI = "AFSUI";
74
74
  declare const BLUEMOVE = "BLUEMOVE";
75
75
  declare const DEEPBOOKV3 = "DEEPBOOKV3";
76
+ declare const DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
76
77
  type BuildRouterSwapParams = {
77
78
  routers: Router[];
78
79
  byAmountIn: boolean;
@@ -80,6 +81,7 @@ type BuildRouterSwapParams = {
80
81
  slippage: number;
81
82
  txb: Transaction;
82
83
  partner?: string;
84
+ deepbookv3DeepFee?: TransactionObjectArgument;
83
85
  };
84
86
  type BuildFastRouterSwapParams = {
85
87
  routers: Router[];
@@ -89,6 +91,7 @@ type BuildFastRouterSwapParams = {
89
91
  partner?: string;
90
92
  isMergeTragetCoin?: boolean;
91
93
  refreshAllCoins?: boolean;
94
+ payDeepFeeAmount?: number;
92
95
  };
93
96
  interface SwapInPoolsParams {
94
97
  from: string;
@@ -107,27 +110,30 @@ declare class AggregatorClient {
107
110
  client: SuiClient;
108
111
  env: Env;
109
112
  private allCoins;
110
- constructor(endpoint: string, signer: string, client: SuiClient, env: Env);
113
+ constructor(endpoint?: string, signer?: string, client?: SuiClient, env?: Env);
111
114
  getAllCoins(): Promise<CoinAsset[]>;
112
115
  findRouters(params: FindRouterParams): Promise<RouterData | null>;
113
- expectInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], amountOutLimit: BN, partner?: string): Promise<TransactionObjectArgument>;
116
+ expectInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], amountOutLimit: BN, partner?: string, deepbookv3DeepFee?: TransactionObjectArgument): Promise<TransactionObjectArgument>;
114
117
  expectOutputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], partner?: string): Promise<TransactionObjectArgument>;
115
118
  swapInPools(params: SwapInPoolsParams): Promise<SwapInPoolsResult | null>;
116
119
  routerSwap(params: BuildRouterSwapParams): Promise<TransactionObjectArgument>;
117
120
  fastRouterSwap(params: BuildFastRouterSwapParams): Promise<void>;
118
121
  publishedAt(): string;
122
+ publishedAtV2(): string;
123
+ deepbookv3DeepFeeType(): string;
119
124
  transferOrDestoryCoin(txb: Transaction, coin: TransactionObjectArgument, coinType: string): void;
120
125
  checkCoinThresholdAndMergeCoin(txb: Transaction, coins: TransactionObjectArgument[], coinType: string, amountLimit: BN): TransactionObjectArgument;
121
126
  newDex(provider: string, partner?: string): Dex;
122
127
  signAndExecuteTransaction(txb: Transaction, signer: Signer): Promise<_mysten_sui_client.SuiTransactionBlockResponse>;
123
128
  devInspectTransactionBlock(txb: Transaction): Promise<_mysten_sui_client.DevInspectResults>;
124
129
  sendTransaction(txb: Transaction, signer: Signer): Promise<_mysten_sui_client.SuiTransactionBlockResponse>;
130
+ getDeepbookV3Config(): Promise<DeepbookV3Config | null>;
125
131
  }
126
132
  declare function parseRouterResponse(data: any): RouterData;
127
133
 
128
134
  declare const CLOCK_ADDRESS = "0x0000000000000000000000000000000000000000000000000000000000000006";
129
135
  interface Dex {
130
- swap(client: AggregatorClient, ptb: Transaction, path: Path, inputCoin: TransactionObjectArgument): Promise<TransactionObjectArgument>;
136
+ swap(client: AggregatorClient, ptb: Transaction, path: Path, inputCoin: TransactionObjectArgument, deepbookv3DeepFee?: TransactionObjectArgument): Promise<TransactionObjectArgument>;
131
137
  }
132
138
 
133
139
  declare function isSortedSymbols(symbolX: string, symbolY: string): boolean;
@@ -149,6 +155,21 @@ declare function createTarget(packageName: string, moduleName: string, functionN
149
155
  declare const dealWithFastRouterSwapParamsForMsafe: (data: any) => any;
150
156
  declare const restituteMsafeFastRouterSwapParams: (data: any) => any;
151
157
 
158
+ declare function processEndpoint(endpoint: string): string;
159
+
160
+ declare function completionCoin(s: string): string;
161
+ declare function compareCoins(coinA: string, coinB: string): boolean;
162
+ declare function mintZeroCoin(txb: Transaction, coinType: string): TransactionObjectArgument;
163
+ type BuildCoinResult = {
164
+ targetCoin: TransactionObjectArgument;
165
+ isMintZeroCoin: boolean;
166
+ targetCoinAmount: number;
167
+ };
168
+ declare function buildInputCoin(txb: Transaction, allCoins: CoinAsset[], amount: bigint, coinType: string): BuildCoinResult;
169
+
170
+ declare function printTransaction(tx: Transaction, isPrint?: boolean): Promise<void>;
171
+ declare function checkInvalidSuiAddress(address: string): boolean;
172
+
152
173
  declare const ZERO: BN;
153
174
  declare const ONE: BN;
154
175
  declare const TWO: BN;
@@ -180,6 +201,7 @@ type ExtendedDetails = {
180
201
  aftermathLpSupplyType?: string;
181
202
  turbosFeeType?: string;
182
203
  afterSqrtPrice?: string;
204
+ deepbookv3DeepFee?: number;
183
205
  };
184
206
  type Path = {
185
207
  id: string;
@@ -208,6 +230,7 @@ type RouterData = {
208
230
  amountOut: BN;
209
231
  routes: Router[];
210
232
  insufficientLiquidity: boolean;
233
+ totalDeepFee?: number;
211
234
  error?: RouterError;
212
235
  };
213
236
  type AggregatorResponse = {
@@ -216,10 +239,28 @@ type AggregatorResponse = {
216
239
  data: RouterData;
217
240
  };
218
241
  declare function getRouterResult(endpoint: string, params: FindRouterParams): Promise<RouterData | null>;
242
+ type DeepbookV3Config = {
243
+ id: string;
244
+ is_alternative_payment: boolean;
245
+ alternative_payment_amount: number;
246
+ trade_cap: string;
247
+ balance_manager: string;
248
+ deep_fee_vault: number;
249
+ whitelist: number;
250
+ package_version: 0;
251
+ last_updated_time: number;
252
+ whitelist_pools: string[];
253
+ };
254
+ type DeepbookV3ConfigResponse = {
255
+ code: number;
256
+ msg: string;
257
+ data: DeepbookV3Config;
258
+ };
259
+ declare function getDeepbookV3Config(endpoint: string): Promise<DeepbookV3ConfigResponse | null>;
219
260
 
220
261
  declare enum Env {
221
262
  Mainnet = 0,
222
263
  Testnet = 1
223
264
  }
224
265
 
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 };
266
+ export { AFSUI, AFTERMATH, AggregatorClient, type AggregatorResponse, BLUEMOVE, type BuildCoinResult, type BuildFastRouterSwapParams, type BuildRouterSwapParams, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, DEEPBOOKV3, DEFAULT_ENDPOINT, 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, buildInputCoin, checkInvalidSuiAddress, compareCoins, completionCoin, composeType, createTarget, dealWithFastRouterSwapParamsForMsafe, extractAddressFromType, extractStructTagFromType, fixSuiObjectId, getDeepbookV3Config, getRouterResult, isSortedSymbols, mintZeroCoin, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId, printTransaction, processEndpoint, restituteMsafeFastRouterSwapParams };
package/dist/index.d.ts CHANGED
@@ -73,6 +73,7 @@ declare const VOLO = "VOLO";
73
73
  declare const AFSUI = "AFSUI";
74
74
  declare const BLUEMOVE = "BLUEMOVE";
75
75
  declare const DEEPBOOKV3 = "DEEPBOOKV3";
76
+ declare const DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
76
77
  type BuildRouterSwapParams = {
77
78
  routers: Router[];
78
79
  byAmountIn: boolean;
@@ -80,6 +81,7 @@ type BuildRouterSwapParams = {
80
81
  slippage: number;
81
82
  txb: Transaction;
82
83
  partner?: string;
84
+ deepbookv3DeepFee?: TransactionObjectArgument;
83
85
  };
84
86
  type BuildFastRouterSwapParams = {
85
87
  routers: Router[];
@@ -89,6 +91,7 @@ type BuildFastRouterSwapParams = {
89
91
  partner?: string;
90
92
  isMergeTragetCoin?: boolean;
91
93
  refreshAllCoins?: boolean;
94
+ payDeepFeeAmount?: number;
92
95
  };
93
96
  interface SwapInPoolsParams {
94
97
  from: string;
@@ -107,27 +110,30 @@ declare class AggregatorClient {
107
110
  client: SuiClient;
108
111
  env: Env;
109
112
  private allCoins;
110
- constructor(endpoint: string, signer: string, client: SuiClient, env: Env);
113
+ constructor(endpoint?: string, signer?: string, client?: SuiClient, env?: Env);
111
114
  getAllCoins(): Promise<CoinAsset[]>;
112
115
  findRouters(params: FindRouterParams): Promise<RouterData | null>;
113
- expectInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], amountOutLimit: BN, partner?: string): Promise<TransactionObjectArgument>;
116
+ expectInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], amountOutLimit: BN, partner?: string, deepbookv3DeepFee?: TransactionObjectArgument): Promise<TransactionObjectArgument>;
114
117
  expectOutputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], partner?: string): Promise<TransactionObjectArgument>;
115
118
  swapInPools(params: SwapInPoolsParams): Promise<SwapInPoolsResult | null>;
116
119
  routerSwap(params: BuildRouterSwapParams): Promise<TransactionObjectArgument>;
117
120
  fastRouterSwap(params: BuildFastRouterSwapParams): Promise<void>;
118
121
  publishedAt(): string;
122
+ publishedAtV2(): string;
123
+ deepbookv3DeepFeeType(): string;
119
124
  transferOrDestoryCoin(txb: Transaction, coin: TransactionObjectArgument, coinType: string): void;
120
125
  checkCoinThresholdAndMergeCoin(txb: Transaction, coins: TransactionObjectArgument[], coinType: string, amountLimit: BN): TransactionObjectArgument;
121
126
  newDex(provider: string, partner?: string): Dex;
122
127
  signAndExecuteTransaction(txb: Transaction, signer: Signer): Promise<_mysten_sui_client.SuiTransactionBlockResponse>;
123
128
  devInspectTransactionBlock(txb: Transaction): Promise<_mysten_sui_client.DevInspectResults>;
124
129
  sendTransaction(txb: Transaction, signer: Signer): Promise<_mysten_sui_client.SuiTransactionBlockResponse>;
130
+ getDeepbookV3Config(): Promise<DeepbookV3Config | null>;
125
131
  }
126
132
  declare function parseRouterResponse(data: any): RouterData;
127
133
 
128
134
  declare const CLOCK_ADDRESS = "0x0000000000000000000000000000000000000000000000000000000000000006";
129
135
  interface Dex {
130
- swap(client: AggregatorClient, ptb: Transaction, path: Path, inputCoin: TransactionObjectArgument): Promise<TransactionObjectArgument>;
136
+ swap(client: AggregatorClient, ptb: Transaction, path: Path, inputCoin: TransactionObjectArgument, deepbookv3DeepFee?: TransactionObjectArgument): Promise<TransactionObjectArgument>;
131
137
  }
132
138
 
133
139
  declare function isSortedSymbols(symbolX: string, symbolY: string): boolean;
@@ -149,6 +155,21 @@ declare function createTarget(packageName: string, moduleName: string, functionN
149
155
  declare const dealWithFastRouterSwapParamsForMsafe: (data: any) => any;
150
156
  declare const restituteMsafeFastRouterSwapParams: (data: any) => any;
151
157
 
158
+ declare function processEndpoint(endpoint: string): string;
159
+
160
+ declare function completionCoin(s: string): string;
161
+ declare function compareCoins(coinA: string, coinB: string): boolean;
162
+ declare function mintZeroCoin(txb: Transaction, coinType: string): TransactionObjectArgument;
163
+ type BuildCoinResult = {
164
+ targetCoin: TransactionObjectArgument;
165
+ isMintZeroCoin: boolean;
166
+ targetCoinAmount: number;
167
+ };
168
+ declare function buildInputCoin(txb: Transaction, allCoins: CoinAsset[], amount: bigint, coinType: string): BuildCoinResult;
169
+
170
+ declare function printTransaction(tx: Transaction, isPrint?: boolean): Promise<void>;
171
+ declare function checkInvalidSuiAddress(address: string): boolean;
172
+
152
173
  declare const ZERO: BN;
153
174
  declare const ONE: BN;
154
175
  declare const TWO: BN;
@@ -180,6 +201,7 @@ type ExtendedDetails = {
180
201
  aftermathLpSupplyType?: string;
181
202
  turbosFeeType?: string;
182
203
  afterSqrtPrice?: string;
204
+ deepbookv3DeepFee?: number;
183
205
  };
184
206
  type Path = {
185
207
  id: string;
@@ -208,6 +230,7 @@ type RouterData = {
208
230
  amountOut: BN;
209
231
  routes: Router[];
210
232
  insufficientLiquidity: boolean;
233
+ totalDeepFee?: number;
211
234
  error?: RouterError;
212
235
  };
213
236
  type AggregatorResponse = {
@@ -216,10 +239,28 @@ type AggregatorResponse = {
216
239
  data: RouterData;
217
240
  };
218
241
  declare function getRouterResult(endpoint: string, params: FindRouterParams): Promise<RouterData | null>;
242
+ type DeepbookV3Config = {
243
+ id: string;
244
+ is_alternative_payment: boolean;
245
+ alternative_payment_amount: number;
246
+ trade_cap: string;
247
+ balance_manager: string;
248
+ deep_fee_vault: number;
249
+ whitelist: number;
250
+ package_version: 0;
251
+ last_updated_time: number;
252
+ whitelist_pools: string[];
253
+ };
254
+ type DeepbookV3ConfigResponse = {
255
+ code: number;
256
+ msg: string;
257
+ data: DeepbookV3Config;
258
+ };
259
+ declare function getDeepbookV3Config(endpoint: string): Promise<DeepbookV3ConfigResponse | null>;
219
260
 
220
261
  declare enum Env {
221
262
  Mainnet = 0,
222
263
  Testnet = 1
223
264
  }
224
265
 
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 };
266
+ export { AFSUI, AFTERMATH, AggregatorClient, type AggregatorResponse, BLUEMOVE, type BuildCoinResult, type BuildFastRouterSwapParams, type BuildRouterSwapParams, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, DEEPBOOKV3, DEFAULT_ENDPOINT, 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, buildInputCoin, checkInvalidSuiAddress, compareCoins, completionCoin, composeType, createTarget, dealWithFastRouterSwapParamsForMsafe, extractAddressFromType, extractStructTagFromType, fixSuiObjectId, getDeepbookV3Config, getRouterResult, isSortedSymbols, mintZeroCoin, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId, printTransaction, processEndpoint, restituteMsafeFastRouterSwapParams };
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ var client = require('@mysten/sui/client');
3
4
  var utils = require('@mysten/sui/utils');
4
5
  var transactions = require('@mysten/sui/transactions');
5
6
 
@@ -5265,7 +5266,7 @@ var Turbos = class {
5265
5266
  var Cetus = class {
5266
5267
  constructor(env, partner) {
5267
5268
  this.globalConfig = env === 0 /* Mainnet */ ? "0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f" : "0x6f4149091a5aea0e818e7243a13adcfb403842d670b9a2089de058512620687a";
5268
- this.partner = (partner != null ? partner : env === 0 /* Mainnet */) ? "0x639b5e433da31739e800cd085f356e64cae222966d0f1b11bd9dc76b322ff58b" : "0x8e0b7668a79592f70fbfb1ae0aebaf9e2019a7049783b9a4b6fe7c6ae038b528";
5269
+ this.partner = partner != null ? partner : env === 0 /* Mainnet */ ? "0x639b5e433da31739e800cd085f356e64cae222966d0f1b11bd9dc76b322ff58b" : "0x8e0b7668a79592f70fbfb1ae0aebaf9e2019a7049783b9a4b6fe7c6ae038b528";
5269
5270
  }
5270
5271
  flash_swap(client, txb, path, by_amount_in) {
5271
5272
  const { direction, from, target } = path;
@@ -5676,8 +5677,8 @@ function buildInputCoin(txb, allCoins, amount, coinType) {
5676
5677
  let totalCoinBalance = CoinUtils.calculateTotalBalance(usedCoinAsests);
5677
5678
  if (totalCoinBalance < amount) {
5678
5679
  throw new AggregateError(
5679
- "Insufficient balance when build merge coin",
5680
- "InsufficientBalance" /* InsufficientBalance */
5680
+ "Insufficient balance when build merge coin, coinType: " + coinType,
5681
+ "InsufficientBalance" /* InsufficientBalance */ + coinType
5681
5682
  );
5682
5683
  }
5683
5684
  if (CoinUtils.isSuiCoin(coinType)) {
@@ -5714,6 +5715,16 @@ function buildInputCoin(txb, allCoins, amount, coinType) {
5714
5715
  }
5715
5716
 
5716
5717
  // src/utils/transaction.ts
5718
+ function printTransaction(tx, isPrint = true) {
5719
+ return __async(this, null, function* () {
5720
+ console.log(`inputs`, tx.getData().inputs);
5721
+ tx.getData().commands.forEach((item, index) => {
5722
+ if (isPrint) {
5723
+ console.log(`transaction ${index}: `, JSON.stringify(item, null, 2));
5724
+ }
5725
+ });
5726
+ });
5727
+ }
5717
5728
  function checkInvalidSuiAddress(address) {
5718
5729
  if (!address.startsWith("0x") || address.length !== 66) {
5719
5730
  return false;
@@ -5765,6 +5776,8 @@ function swapInPools(client, params, sender) {
5765
5776
  const coinA = direction ? fromCoin : targetCoin;
5766
5777
  const coinB = direction ? targetCoin : fromCoin;
5767
5778
  const typeArguments = [coinA, coinB];
5779
+ console.log("typeArguments", typeArguments);
5780
+ console.log("pools", pools);
5768
5781
  for (let i = 0; i < pools.length; i++) {
5769
5782
  const args = [
5770
5783
  tx.object(pools[i]),
@@ -5789,6 +5802,7 @@ function swapInPools(client, params, sender) {
5789
5802
  sender
5790
5803
  });
5791
5804
  if (simulateRes.error != null) {
5805
+ console.log("simulateRes.error", simulateRes.error);
5792
5806
  throw new AggregateError(
5793
5807
  "Aggregator package not set",
5794
5808
  "SimulateError" /* SimulateError */
@@ -5995,23 +6009,27 @@ var Bluemove = class {
5995
6009
  // src/transaction/deepbook_v3.ts
5996
6010
  var DeepbookV3 = class {
5997
6011
  constructor(env) {
5998
- this.deepbookV3Config = env === 0 /* Mainnet */ ? "0x0" : "0x77018927a5d7ed7b4c49312b71581f5f12ba52ba7e1219a15181ffc3d459f527";
5999
- this.deepCoinType = env === 0 /* Mainnet */ ? "0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP" : "0x36dbef866a1d62bf7328989a10fb2f07d769f4ee587c0de4a0a256e57e0a58a8::deep::DEEP";
6012
+ this.deepbookV3Config = env === 0 /* Mainnet */ ? "0xe4099d0cda04f3aa80028fac91a9b3dbe50d08f2ff42aa2c29473926e34ca48c" : "0xe19b5d072346cae83a037d4e3c8492068a74410a74e5830b3a68012db38296aa";
6000
6013
  }
6001
- swap(client, txb, path, inputCoin) {
6014
+ swap(client, txb, path, inputCoin, deepbookv3DeepFee) {
6002
6015
  return __async(this, null, function* () {
6003
6016
  const { direction, from, target } = path;
6004
6017
  const [func, coinAType, coinBType] = direction ? ["swap_a2b", from, target] : ["swap_b2a", target, from];
6005
- const zeroDeep = mintZeroCoin(txb, this.deepCoinType);
6018
+ let deepFee;
6019
+ if (deepbookv3DeepFee) {
6020
+ deepFee = deepbookv3DeepFee;
6021
+ } else {
6022
+ deepFee = mintZeroCoin(txb, client.deepbookv3DeepFeeType());
6023
+ }
6006
6024
  const args = [
6007
6025
  txb.object(this.deepbookV3Config),
6008
6026
  txb.object(path.id),
6009
6027
  inputCoin,
6010
- zeroDeep,
6028
+ deepFee,
6011
6029
  txb.object(CLOCK_ADDRESS)
6012
6030
  ];
6013
6031
  const res = txb.moveCall({
6014
- target: `${client.publishedAt()}::deepbookv3::${func}`,
6032
+ target: `${client.publishedAtV2()}::deepbookv3::${func}`,
6015
6033
  typeArguments: [coinAType, coinBType],
6016
6034
  arguments: args
6017
6035
  });
@@ -6034,16 +6052,20 @@ var VOLO = "VOLO";
6034
6052
  var AFSUI = "AFSUI";
6035
6053
  var BLUEMOVE = "BLUEMOVE";
6036
6054
  var DEEPBOOKV3 = "DEEPBOOKV3";
6055
+ var DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
6037
6056
  var AggregatorClient7 = class {
6038
- constructor(endpoint, signer, client, env) {
6039
- this.endpoint = endpoint;
6040
- this.client = client;
6041
- this.signer = signer;
6042
- this.env = env;
6057
+ constructor(endpoint, signer, client$1, env) {
6058
+ this.endpoint = endpoint ? processEndpoint(endpoint) : DEFAULT_ENDPOINT;
6059
+ this.client = client$1 || new client.SuiClient({ url: client.getFullnodeUrl("mainnet") });
6060
+ this.signer = signer || "";
6061
+ this.env = env || 0 /* Mainnet */;
6043
6062
  this.allCoins = [];
6044
6063
  }
6045
6064
  getAllCoins() {
6046
6065
  return __async(this, null, function* () {
6066
+ if (this.signer === "") {
6067
+ throw new Error("Signer is required, but not provided.");
6068
+ }
6047
6069
  let cursor = null;
6048
6070
  let limit = 50;
6049
6071
  const allCoins = [];
@@ -6073,7 +6095,7 @@ var AggregatorClient7 = class {
6073
6095
  return getRouterResult(this.endpoint, params);
6074
6096
  });
6075
6097
  }
6076
- expectInputSwap(txb, inputCoin, routers, amountOutLimit, partner) {
6098
+ expectInputSwap(txb, inputCoin, routers, amountOutLimit, partner, deepbookv3DeepFee) {
6077
6099
  return __async(this, null, function* () {
6078
6100
  if (routers.length === 0) {
6079
6101
  throw new Error("No router found");
@@ -6090,7 +6112,7 @@ var AggregatorClient7 = class {
6090
6112
  let nextCoin = inputCoins[i];
6091
6113
  for (const path of routers[i].path) {
6092
6114
  const dex = this.newDex(path.provider, partner);
6093
- nextCoin = yield dex.swap(this, txb, path, nextCoin);
6115
+ nextCoin = yield dex.swap(this, txb, path, nextCoin, deepbookv3DeepFee);
6094
6116
  }
6095
6117
  outputCoins.push(nextCoin);
6096
6118
  }
@@ -6166,7 +6188,7 @@ var AggregatorClient7 = class {
6166
6188
  }
6167
6189
  routerSwap(params) {
6168
6190
  return __async(this, null, function* () {
6169
- const { routers, inputCoin, slippage, byAmountIn, txb, partner } = params;
6191
+ const { routers, inputCoin, slippage, byAmountIn, txb, partner, deepbookv3DeepFee } = params;
6170
6192
  const amountIn = routers.reduce(
6171
6193
  (acc, router) => acc.add(router.amountIn),
6172
6194
  new import_bn5.default(0)
@@ -6186,7 +6208,8 @@ var AggregatorClient7 = class {
6186
6208
  inputCoin,
6187
6209
  routers,
6188
6210
  new import_bn5.default(amountLimit),
6189
- partner
6211
+ partner,
6212
+ deepbookv3DeepFee
6190
6213
  );
6191
6214
  return targetCoin2;
6192
6215
  }
@@ -6214,7 +6237,8 @@ var AggregatorClient7 = class {
6214
6237
  txb,
6215
6238
  partner,
6216
6239
  isMergeTragetCoin,
6217
- refreshAllCoins
6240
+ refreshAllCoins,
6241
+ payDeepFeeAmount
6218
6242
  } = params;
6219
6243
  if (refreshAllCoins || this.allCoins.length === 0) {
6220
6244
  this.allCoins = yield this.getAllCoins();
@@ -6241,13 +6265,23 @@ var AggregatorClient7 = class {
6241
6265
  BigInt(amount.toString()),
6242
6266
  fromCoinType
6243
6267
  );
6268
+ let deepCoin;
6269
+ if (payDeepFeeAmount && payDeepFeeAmount > 0) {
6270
+ deepCoin = buildInputCoin(
6271
+ txb,
6272
+ this.allCoins,
6273
+ BigInt(payDeepFeeAmount),
6274
+ this.deepbookv3DeepFeeType()
6275
+ ).targetCoin;
6276
+ }
6244
6277
  const targetCoin = yield this.routerSwap({
6245
6278
  routers,
6246
6279
  inputCoin: buildFromCoinRes.targetCoin,
6247
6280
  slippage,
6248
6281
  byAmountIn,
6249
6282
  txb,
6250
- partner
6283
+ partner,
6284
+ deepbookv3DeepFee: deepCoin
6251
6285
  });
6252
6286
  if (isMergeTragetCoin) {
6253
6287
  const targetCoinRes = buildInputCoin(
@@ -6269,11 +6303,27 @@ var AggregatorClient7 = class {
6269
6303
  }
6270
6304
  });
6271
6305
  }
6306
+ // Include cetus、deepbookv2、flowxv2 & v3、kriyav2 & v3、turbos、aftermath、haedal、afsui、volo、bluemove
6272
6307
  publishedAt() {
6273
6308
  if (this.env === 0 /* Mainnet */) {
6274
6309
  return "0xf98ed029af555e4a103febf26243dc33ac09a7ea1b2da7e414c728b25b729086";
6275
6310
  } else {
6276
- return "0xb2db335c85473e7ed952351bb594100eb8f61122703219c6b8dbcdcade2795b3";
6311
+ return "0x0ed287d6c3fe4962d0994ffddc1d19a15fba6a81533f3f0dcc2bbcedebce0637";
6312
+ }
6313
+ }
6314
+ // Include deepbookv3
6315
+ publishedAtV2() {
6316
+ if (this.env === 0 /* Mainnet */) {
6317
+ return "0x43811be4677f5a5de7bf2dac740c10abddfaa524aee6b18e910eeadda8a2f6ae";
6318
+ } else {
6319
+ return "0x0ed287d6c3fe4962d0994ffddc1d19a15fba6a81533f3f0dcc2bbcedebce0637";
6320
+ }
6321
+ }
6322
+ deepbookv3DeepFeeType() {
6323
+ if (this.env === 0 /* Mainnet */) {
6324
+ return "0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP";
6325
+ } else {
6326
+ return "0x36dbef866a1d62bf7328989a10fb2f07d769f4ee587c0de4a0a256e57e0a58a8::deep::DEEP";
6277
6327
  }
6278
6328
  }
6279
6329
  transferOrDestoryCoin(txb, coin, coinType) {
@@ -6366,26 +6416,44 @@ var AggregatorClient7 = class {
6366
6416
  return res;
6367
6417
  });
6368
6418
  }
6419
+ getDeepbookV3Config() {
6420
+ return __async(this, null, function* () {
6421
+ const res = yield getDeepbookV3Config(this.endpoint);
6422
+ if (res) {
6423
+ return res.data;
6424
+ }
6425
+ return null;
6426
+ });
6427
+ }
6369
6428
  };
6370
6429
  function parseRouterResponse(data) {
6371
- return {
6430
+ let totalDeepFee = 0;
6431
+ for (const route of data.routes) {
6432
+ for (const path of route.path) {
6433
+ if (path.extended_details && path.extended_details.deepbookv3_deep_fee) {
6434
+ totalDeepFee += Number(path.extended_details.deepbookv3_deep_fee);
6435
+ }
6436
+ }
6437
+ }
6438
+ let routerData = {
6372
6439
  amountIn: new import_bn5.default(data.amount_in.toString()),
6373
6440
  amountOut: new import_bn5.default(data.amount_out.toString()),
6374
6441
  insufficientLiquidity: false,
6375
6442
  routes: data.routes.map((route) => {
6376
6443
  return {
6377
6444
  path: route.path.map((path) => {
6378
- var _a, _b, _c;
6445
+ var _a, _b, _c, _d;
6379
6446
  let version;
6380
6447
  if (path.provider === AFTERMATH) {
6381
6448
  version = path.extended_details.aftermath_pool_flatness === 0 ? "v2" : "v3";
6382
6449
  }
6383
6450
  let extendedDetails;
6384
- if (path.provider === TURBOS || path.provider === AFTERMATH || path.provider === CETUS) {
6451
+ if (path.provider === TURBOS || path.provider === AFTERMATH || path.provider === CETUS || path.provider === DEEPBOOKV3) {
6385
6452
  extendedDetails = {
6386
6453
  aftermathLpSupplyType: (_a = path.extended_details) == null ? void 0 : _a.aftermath_lp_supply_type,
6387
6454
  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
6455
+ afterSqrtPrice: (_c = path.extended_details) == null ? void 0 : _c.after_sqrt_price,
6456
+ deepbookv3DeepFee: (_d = path.extended_details) == null ? void 0 : _d.deepbookv3_deep_fee
6389
6457
  };
6390
6458
  }
6391
6459
  return {
@@ -6405,8 +6473,10 @@ function parseRouterResponse(data) {
6405
6473
  amountOut: new import_bn5.default(route.amount_out.toString()),
6406
6474
  initialPrice: new decimal_default(route.initial_price.toString())
6407
6475
  };
6408
- })
6476
+ }),
6477
+ totalDeepFee
6409
6478
  };
6479
+ return routerData;
6410
6480
  }
6411
6481
 
6412
6482
  // src/transaction/index.ts
@@ -6437,6 +6507,14 @@ var restituteMsafeFastRouterSwapParams = (data) => {
6437
6507
  return result;
6438
6508
  };
6439
6509
 
6510
+ // src/utils/api.ts
6511
+ function processEndpoint(endpoint) {
6512
+ if (endpoint.endsWith("/find_routes")) {
6513
+ return endpoint.replace("/find_routes", "");
6514
+ }
6515
+ return endpoint;
6516
+ }
6517
+
6440
6518
  // src/api.ts
6441
6519
  function getRouterResult(endpoint, params) {
6442
6520
  return __async(this, null, function* () {
@@ -6499,7 +6577,7 @@ function getRouter(endpoint, params) {
6499
6577
  } = params;
6500
6578
  const fromCoin = completionCoin(from);
6501
6579
  const targetCoin = completionCoin(target);
6502
- let url = `${endpoint}?from=${fromCoin}&target=${targetCoin}&amount=${amount.toString()}&by_amount_in=${byAmountIn}`;
6580
+ let url = `${endpoint}/find_routes?from=${fromCoin}&target=${targetCoin}&amount=${amount.toString()}&by_amount_in=${byAmountIn}`;
6503
6581
  if (depth) {
6504
6582
  url += `&depth=${depth}`;
6505
6583
  }
@@ -6517,7 +6595,7 @@ function getRouter(endpoint, params) {
6517
6595
  url += `&providers=${providers.join(",")}`;
6518
6596
  }
6519
6597
  }
6520
- url += "&v=1000301";
6598
+ url += "&v=1000302";
6521
6599
  const response = yield fetch(url);
6522
6600
  return response;
6523
6601
  } catch (error) {
@@ -6542,7 +6620,7 @@ function postRouterWithLiquidityChanges(endpoint, params) {
6542
6620
  } = params;
6543
6621
  const fromCoin = completionCoin(from);
6544
6622
  const targetCoin = completionCoin(target);
6545
- const url = `${endpoint}`;
6623
+ const url = `${endpoint}/find_routes`;
6546
6624
  const providersStr = providers == null ? void 0 : providers.join(",");
6547
6625
  const requestData = {
6548
6626
  from: fromCoin,
@@ -6561,7 +6639,6 @@ function postRouterWithLiquidityChanges(endpoint, params) {
6561
6639
  delta_liquidity: change.deltaLiquidity
6562
6640
  }))
6563
6641
  };
6564
- console.log("requestData", JSON.stringify(requestData, null, 2));
6565
6642
  try {
6566
6643
  const response = yield fetch(url, {
6567
6644
  method: "POST",
@@ -6577,6 +6654,18 @@ function postRouterWithLiquidityChanges(endpoint, params) {
6577
6654
  }
6578
6655
  });
6579
6656
  }
6657
+ function getDeepbookV3Config(endpoint) {
6658
+ return __async(this, null, function* () {
6659
+ const url = `${endpoint}/deepbookv3_config`;
6660
+ try {
6661
+ const response = yield fetch(url);
6662
+ return response.json();
6663
+ } catch (error) {
6664
+ console.error("Error:", error);
6665
+ return null;
6666
+ }
6667
+ });
6668
+ }
6580
6669
 
6581
6670
  // src/index.ts
6582
6671
  var Env = /* @__PURE__ */ ((Env2) => {
@@ -6604,6 +6693,7 @@ exports.CETUS = CETUS;
6604
6693
  exports.CLOCK_ADDRESS = CLOCK_ADDRESS;
6605
6694
  exports.DEEPBOOKV2 = DEEPBOOKV2;
6606
6695
  exports.DEEPBOOKV3 = DEEPBOOKV3;
6696
+ exports.DEFAULT_ENDPOINT = DEFAULT_ENDPOINT;
6607
6697
  exports.Env = Env;
6608
6698
  exports.FLOWXV2 = FLOWXV2;
6609
6699
  exports.FLOWXV3 = FLOWXV3;
@@ -6619,15 +6709,23 @@ exports.U64_MAX = U64_MAX;
6619
6709
  exports.U64_MAX_BN = U64_MAX_BN;
6620
6710
  exports.VOLO = VOLO;
6621
6711
  exports.ZERO = ZERO;
6712
+ exports.buildInputCoin = buildInputCoin;
6713
+ exports.checkInvalidSuiAddress = checkInvalidSuiAddress;
6714
+ exports.compareCoins = compareCoins;
6715
+ exports.completionCoin = completionCoin;
6622
6716
  exports.composeType = composeType;
6623
6717
  exports.createTarget = createTarget;
6624
6718
  exports.dealWithFastRouterSwapParamsForMsafe = dealWithFastRouterSwapParamsForMsafe;
6625
6719
  exports.extractAddressFromType = extractAddressFromType;
6626
6720
  exports.extractStructTagFromType = extractStructTagFromType;
6627
6721
  exports.fixSuiObjectId = fixSuiObjectId;
6722
+ exports.getDeepbookV3Config = getDeepbookV3Config;
6628
6723
  exports.getRouterResult = getRouterResult;
6629
6724
  exports.isSortedSymbols = isSortedSymbols;
6725
+ exports.mintZeroCoin = mintZeroCoin;
6630
6726
  exports.normalizeCoinType = normalizeCoinType;
6631
6727
  exports.parseRouterResponse = parseRouterResponse;
6632
6728
  exports.patchFixSuiObjectId = patchFixSuiObjectId;
6729
+ exports.printTransaction = printTransaction;
6730
+ exports.processEndpoint = processEndpoint;
6633
6731
  exports.restituteMsafeFastRouterSwapParams = restituteMsafeFastRouterSwapParams;