@cetusprotocol/aggregator-sdk 1.1.2 → 1.1.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.
@@ -0,0 +1,41 @@
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "mcp__ide__executeCode",
5
+ "Bash(node:*)",
6
+ "Bash(rm:*)",
7
+ "Bash(npm install:*)",
8
+ "Bash(npm run:*)",
9
+ "Bash(grep:*)",
10
+ "Bash(git add:*)",
11
+ "Bash(bun test:*)",
12
+ "Bash(bun run:*)",
13
+ "Bash(find:*)",
14
+ "Bash(mkdir:*)",
15
+ "Bash(mv:*)",
16
+ "Bash(git commit:*)",
17
+ "Bash(ls:*)",
18
+ "Bash(NODE_ENV=development bun test tests/aggregatorv3/router/sort.test.ts --verbose)",
19
+ "Bash(npx tsc:*)",
20
+ "mcp__ide__getDiagnostics",
21
+ "Bash(for:*)",
22
+ "Bash(do)",
23
+ "Bash(if grep -q \"import.*ENV\" \"$file\")",
24
+ "Bash(then)",
25
+ "Bash(sed:*)",
26
+ "Bash(echo \"Updated: $file\")",
27
+ "Bash(fi)",
28
+ "Bash(done)",
29
+ "Bash(if grep -q \"import.*Env\" \"$file\")",
30
+ "Bash(git reset:*)",
31
+ "Bash(cp:*)",
32
+ "WebFetch(domain:docs.blockvision.org)",
33
+ "Bash(git restore:*)",
34
+ "Bash(bun tsc:*)",
35
+ "Bash(git checkout:*)",
36
+ "Bash(do echo \"=== $file ===\")",
37
+ "Bash(true)"
38
+ ],
39
+ "deny": []
40
+ }
41
+ }
package/dist/index.d.mts CHANGED
@@ -107,7 +107,7 @@ type RouterDataV3 = {
107
107
  byAmountIn: boolean;
108
108
  paths: Path[];
109
109
  insufficientLiquidity: boolean;
110
- deviationRatio?: number;
110
+ deviationRatio: number;
111
111
  packages?: Map<string, string>;
112
112
  totalDeepFee?: number;
113
113
  error?: RouterError;
@@ -309,6 +309,7 @@ declare class AggregatorClient {
309
309
  constructor(params: AggregatorClientParams);
310
310
  newPythClients(pythUrls: string[]): SuiPriceServiceConnection[];
311
311
  deepbookv3DeepFeeType(): string;
312
+ getDeepbookV3Config(): Promise<DeepbookV3ConfigResponse | null>;
312
313
  getOneCoinUsedToMerge(coinType: string): Promise<string | null>;
313
314
  findRouters(params: FindRouterParams): Promise<RouterDataV3 | null>;
314
315
  executeFlexibleInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routerData: RouterDataV3, expectedAmountOut: string, amountLimit: string, pythPriceIDs: Map<string, string>, partner?: string, deepbookv3DeepFee?: TransactionObjectArgument, packages?: Map<string, string>): Promise<void>;
@@ -678,8 +679,9 @@ declare const DEEPBOOK_V3_DEEP_FEE_TYPES: {
678
679
  declare const CLIENT_CONFIG: {
679
680
  readonly DEFAULT_PYTH_URL: "https://hermes.pyth.network";
680
681
  readonly PYTH_TIMEOUT: 3000;
681
- readonly MAX_OVERLAY_FEE_RATE: 0.1;
682
+ readonly MAX_OVERLAY_FEE_RATE_PARAMS: 0.1;
682
683
  readonly FEE_RATE_MULTIPLIER: 1000000;
684
+ readonly MAX_FEE_RATE: 100000;
683
685
  readonly DEFAULT_OVERLAY_FEE_RECEIVER: "0x0";
684
686
  readonly ERRORS: {
685
687
  readonly SIGNER_REQUIRED: "Signer is required, but not provided.";
@@ -692,6 +694,7 @@ declare const CLIENT_CONFIG: {
692
694
  readonly QUOTE_ID_REQUIRED: "Quote ID is required";
693
695
  readonly AGGREGATOR_V3_PACKAGE_REQUIRED: "Aggregator V3 package is required";
694
696
  readonly PACKAGES_REQUIRED: "Packages are required";
697
+ readonly OVERLAY_FEE_RECEIVER_REQUIRED: "Overlay fee rate is set, but overlay fee receiver is not set";
695
698
  };
696
699
  };
697
700
  declare const AGGREGATOR_V3_CONFIG: {
@@ -791,7 +794,7 @@ declare const GAS_TYPE_ARG = "0x2::sui::SUI";
791
794
  declare const GAS_TYPE_ARG_LONG = "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI";
792
795
  declare const GAS_SYMBOL = "SUI";
793
796
  declare const DEFAULT_NFT_TRANSFER_GAS_FEE = 450;
794
- declare const SUI_SYSTEM_STATE_OBJECT_ID = "0x0000000000000000000000000000000000000005";
797
+ declare const SUI_SYSTEM_STATE_OBJECT_ID = "0x0000000000000000000000000000000000000000000000000000000000000005";
795
798
  /**
796
799
  * This class provides helper methods for working with coins.
797
800
  */
package/dist/index.d.ts CHANGED
@@ -107,7 +107,7 @@ type RouterDataV3 = {
107
107
  byAmountIn: boolean;
108
108
  paths: Path[];
109
109
  insufficientLiquidity: boolean;
110
- deviationRatio?: number;
110
+ deviationRatio: number;
111
111
  packages?: Map<string, string>;
112
112
  totalDeepFee?: number;
113
113
  error?: RouterError;
@@ -309,6 +309,7 @@ declare class AggregatorClient {
309
309
  constructor(params: AggregatorClientParams);
310
310
  newPythClients(pythUrls: string[]): SuiPriceServiceConnection[];
311
311
  deepbookv3DeepFeeType(): string;
312
+ getDeepbookV3Config(): Promise<DeepbookV3ConfigResponse | null>;
312
313
  getOneCoinUsedToMerge(coinType: string): Promise<string | null>;
313
314
  findRouters(params: FindRouterParams): Promise<RouterDataV3 | null>;
314
315
  executeFlexibleInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routerData: RouterDataV3, expectedAmountOut: string, amountLimit: string, pythPriceIDs: Map<string, string>, partner?: string, deepbookv3DeepFee?: TransactionObjectArgument, packages?: Map<string, string>): Promise<void>;
@@ -678,8 +679,9 @@ declare const DEEPBOOK_V3_DEEP_FEE_TYPES: {
678
679
  declare const CLIENT_CONFIG: {
679
680
  readonly DEFAULT_PYTH_URL: "https://hermes.pyth.network";
680
681
  readonly PYTH_TIMEOUT: 3000;
681
- readonly MAX_OVERLAY_FEE_RATE: 0.1;
682
+ readonly MAX_OVERLAY_FEE_RATE_PARAMS: 0.1;
682
683
  readonly FEE_RATE_MULTIPLIER: 1000000;
684
+ readonly MAX_FEE_RATE: 100000;
683
685
  readonly DEFAULT_OVERLAY_FEE_RECEIVER: "0x0";
684
686
  readonly ERRORS: {
685
687
  readonly SIGNER_REQUIRED: "Signer is required, but not provided.";
@@ -692,6 +694,7 @@ declare const CLIENT_CONFIG: {
692
694
  readonly QUOTE_ID_REQUIRED: "Quote ID is required";
693
695
  readonly AGGREGATOR_V3_PACKAGE_REQUIRED: "Aggregator V3 package is required";
694
696
  readonly PACKAGES_REQUIRED: "Packages are required";
697
+ readonly OVERLAY_FEE_RECEIVER_REQUIRED: "Overlay fee rate is set, but overlay fee receiver is not set";
695
698
  };
696
699
  };
697
700
  declare const AGGREGATOR_V3_CONFIG: {
@@ -791,7 +794,7 @@ declare const GAS_TYPE_ARG = "0x2::sui::SUI";
791
794
  declare const GAS_TYPE_ARG_LONG = "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI";
792
795
  declare const GAS_SYMBOL = "SUI";
793
796
  declare const DEFAULT_NFT_TRANSFER_GAS_FEE = 450;
794
- declare const SUI_SYSTEM_STATE_OBJECT_ID = "0x0000000000000000000000000000000000000005";
797
+ declare const SUI_SYSTEM_STATE_OBJECT_ID = "0x0000000000000000000000000000000000000000000000000000000000000005";
795
798
  /**
796
799
  * This class provides helper methods for working with coins.
797
800
  */
package/dist/index.js CHANGED
@@ -2999,7 +2999,7 @@ var GAS_TYPE_ARG = "0x2::sui::SUI";
2999
2999
  var GAS_TYPE_ARG_LONG = "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI";
3000
3000
  var GAS_SYMBOL = "SUI";
3001
3001
  var DEFAULT_NFT_TRANSFER_GAS_FEE = 450;
3002
- var SUI_SYSTEM_STATE_OBJECT_ID = "0x0000000000000000000000000000000000000005";
3002
+ var SUI_SYSTEM_STATE_OBJECT_ID = "0x0000000000000000000000000000000000000000000000000000000000000005";
3003
3003
  var CoinUtils = class _CoinUtils {
3004
3004
  /**
3005
3005
  * Get the coin type argument from a SuiMoveObject.
@@ -3107,10 +3107,18 @@ var CoinUtils = class _CoinUtils {
3107
3107
  * @returns The CoinAsset objects that have a balance greater than or equal to the given amount.
3108
3108
  */
3109
3109
  static selectCoinObjectIdGreaterThanOrEqual(coins, amount, exclude = []) {
3110
- const selectedResult = _CoinUtils.selectCoinAssetGreaterThanOrEqual(coins, amount, exclude);
3111
- const objectArray = selectedResult.selectedCoins.map((item) => item.coinObjectId);
3110
+ const selectedResult = _CoinUtils.selectCoinAssetGreaterThanOrEqual(
3111
+ coins,
3112
+ amount,
3113
+ exclude
3114
+ );
3115
+ const objectArray = selectedResult.selectedCoins.map(
3116
+ (item) => item.coinObjectId
3117
+ );
3112
3118
  const remainCoins = selectedResult.remainingCoins;
3113
- const amountArray = selectedResult.selectedCoins.map((item) => item.balance.toString());
3119
+ const amountArray = selectedResult.selectedCoins.map(
3120
+ (item) => item.balance.toString()
3121
+ );
3114
3122
  return { objectArray, remainCoins, amountArray };
3115
3123
  }
3116
3124
  /**
@@ -3122,7 +3130,9 @@ var CoinUtils = class _CoinUtils {
3122
3130
  * @returns The CoinAsset objects that have a balance greater than or equal to the given amount.
3123
3131
  */
3124
3132
  static selectCoinAssetGreaterThanOrEqual(coins, amount, exclude = []) {
3125
- const sortedCoins = _CoinUtils.sortByBalance(coins.filter((c) => !exclude.includes(c.coinObjectId)));
3133
+ const sortedCoins = _CoinUtils.sortByBalance(
3134
+ coins.filter((c) => !exclude.includes(c.coinObjectId))
3135
+ );
3126
3136
  const total = _CoinUtils.calculateTotalBalance(sortedCoins);
3127
3137
  if (total < amount) {
3128
3138
  return { selectedCoins: [], remainingCoins: sortedCoins };
@@ -3135,9 +3145,13 @@ var CoinUtils = class _CoinUtils {
3135
3145
  const remainingCoins = [...sortedCoins];
3136
3146
  while (sum2 < total) {
3137
3147
  const target = amount - sum2;
3138
- const coinWithSmallestSufficientBalanceIndex = remainingCoins.findIndex((c) => c.balance >= target);
3148
+ const coinWithSmallestSufficientBalanceIndex = remainingCoins.findIndex(
3149
+ (c) => c.balance >= target
3150
+ );
3139
3151
  if (coinWithSmallestSufficientBalanceIndex !== -1) {
3140
- selectedCoins.push(remainingCoins[coinWithSmallestSufficientBalanceIndex]);
3152
+ selectedCoins.push(
3153
+ remainingCoins[coinWithSmallestSufficientBalanceIndex]
3154
+ );
3141
3155
  remainingCoins.splice(coinWithSmallestSufficientBalanceIndex, 1);
3142
3156
  break;
3143
3157
  }
@@ -3147,7 +3161,10 @@ var CoinUtils = class _CoinUtils {
3147
3161
  sum2 += coinWithLargestBalance.balance;
3148
3162
  }
3149
3163
  }
3150
- return { selectedCoins: _CoinUtils.sortByBalance(selectedCoins), remainingCoins: _CoinUtils.sortByBalance(remainingCoins) };
3164
+ return {
3165
+ selectedCoins: _CoinUtils.sortByBalance(selectedCoins),
3166
+ remainingCoins: _CoinUtils.sortByBalance(remainingCoins)
3167
+ };
3151
3168
  }
3152
3169
  /**
3153
3170
  * Sort the CoinAsset objects by their balance.
@@ -3156,10 +3173,14 @@ var CoinUtils = class _CoinUtils {
3156
3173
  * @returns The sorted CoinAsset objects.
3157
3174
  */
3158
3175
  static sortByBalance(coins) {
3159
- return coins.sort((a, b) => a.balance < b.balance ? -1 : a.balance > b.balance ? 1 : 0);
3176
+ return coins.sort(
3177
+ (a, b) => a.balance < b.balance ? -1 : a.balance > b.balance ? 1 : 0
3178
+ );
3160
3179
  }
3161
3180
  static sortByBalanceDes(coins) {
3162
- return coins.sort((a, b) => a.balance > b.balance ? -1 : a.balance < b.balance ? 0 : 1);
3181
+ return coins.sort(
3182
+ (a, b) => a.balance > b.balance ? -1 : a.balance < b.balance ? 0 : 1
3183
+ );
3163
3184
  }
3164
3185
  /**
3165
3186
  * Calculate the total balance of a list of CoinAsset objects.
@@ -3397,8 +3418,9 @@ var DEEPBOOK_V3_DEEP_FEE_TYPES = {
3397
3418
  var CLIENT_CONFIG = {
3398
3419
  DEFAULT_PYTH_URL: "https://hermes.pyth.network",
3399
3420
  PYTH_TIMEOUT: 3e3,
3400
- MAX_OVERLAY_FEE_RATE: 0.1,
3421
+ MAX_OVERLAY_FEE_RATE_PARAMS: 0.1,
3401
3422
  FEE_RATE_MULTIPLIER: 1e6,
3423
+ MAX_FEE_RATE: 1e5,
3402
3424
  DEFAULT_OVERLAY_FEE_RECEIVER: "0x0",
3403
3425
  // Error Messages
3404
3426
  ERRORS: {
@@ -3411,7 +3433,8 @@ var CLIENT_CONFIG = {
3411
3433
  PYTH_UNAVAILABLE: "All Pyth price nodes are unavailable. Cannot fetch price data. Please switch to or add new available Pyth nodes",
3412
3434
  QUOTE_ID_REQUIRED: "Quote ID is required",
3413
3435
  AGGREGATOR_V3_PACKAGE_REQUIRED: "Aggregator V3 package is required",
3414
- PACKAGES_REQUIRED: "Packages are required"
3436
+ PACKAGES_REQUIRED: "Packages are required",
3437
+ OVERLAY_FEE_RECEIVER_REQUIRED: "Overlay fee rate is set, but overlay fee receiver is not set"
3415
3438
  }
3416
3439
  };
3417
3440
  var AGGREGATOR_V3_CONFIG = {
@@ -3426,7 +3449,7 @@ var AGGREGATOR_V3_CONFIG = {
3426
3449
  };
3427
3450
 
3428
3451
  // src/api.ts
3429
- var SDK_VERSION = 1010102;
3452
+ var SDK_VERSION = 1010103;
3430
3453
  function parseRouterResponse(data, byAmountIn) {
3431
3454
  let packages = /* @__PURE__ */ new Map();
3432
3455
  if (data.packages) {
@@ -3444,6 +3467,7 @@ function parseRouterResponse(data, byAmountIn) {
3444
3467
  amountOut: new import_bn2.default(data.amount_out.toString()),
3445
3468
  byAmountIn,
3446
3469
  insufficientLiquidity: false,
3470
+ deviationRatio: data.deviation_ratio,
3447
3471
  packages,
3448
3472
  paths: data.paths.map((path) => ({
3449
3473
  id: path.id,
@@ -6695,7 +6719,7 @@ var SpringsuiRouter = class {
6695
6719
  const args = [
6696
6720
  swapContext,
6697
6721
  txb.object(swapData.poolId),
6698
- txb.object("0x5"),
6722
+ txb.object(SUI_SYSTEM_STATE_OBJECT_ID),
6699
6723
  txb.pure.u64(swapData.amountIn),
6700
6724
  txb.pure.bool(swapData.direction)
6701
6725
  ];
@@ -7377,8 +7401,7 @@ var VoloRouter = class {
7377
7401
  swapContext,
7378
7402
  txb.object(this.stakePool),
7379
7403
  txb.object(this.metadata),
7380
- txb.object("0x5"),
7381
- // SuiSystemState
7404
+ txb.object(SUI_SYSTEM_STATE_OBJECT_ID),
7382
7405
  txb.pure.bool(swapData.direction),
7383
7406
  txb.pure.u64(swapData.amountIn)
7384
7407
  ];
@@ -7429,8 +7452,7 @@ var AfsuiRouter = class {
7429
7452
  swapContext,
7430
7453
  txb.object(this.stakedSuiVault),
7431
7454
  txb.object(this.safe),
7432
- txb.object("0x5"),
7433
- // SuiSystemState
7455
+ txb.object(SUI_SYSTEM_STATE_OBJECT_ID),
7434
7456
  txb.object(this.referVault),
7435
7457
  txb.object(this.validator),
7436
7458
  txb.pure.bool(swapData.direction),
@@ -7475,8 +7497,7 @@ var HaedalRouter = class {
7475
7497
  const args = [
7476
7498
  swapContext,
7477
7499
  txb.object(swapData.poolId),
7478
- txb.object("0x5"),
7479
- // SuiSystemState
7500
+ txb.object(SUI_SYSTEM_STATE_OBJECT_ID),
7480
7501
  txb.pure.bool(swapData.direction),
7481
7502
  txb.pure.u64(swapData.amountIn)
7482
7503
  ];
@@ -8235,7 +8256,7 @@ var _AggregatorClient = class _AggregatorClient {
8235
8256
  this.apiKey = params.apiKey || "";
8236
8257
  this.partner = params.partner;
8237
8258
  if (params.overlayFeeRate) {
8238
- if (params.overlayFeeRate > 0 && params.overlayFeeRate <= CLIENT_CONFIG.MAX_OVERLAY_FEE_RATE) {
8259
+ if (params.overlayFeeRate > 0 && params.overlayFeeRate <= CLIENT_CONFIG.MAX_OVERLAY_FEE_RATE_PARAMS) {
8239
8260
  this.overlayFeeRate = params.overlayFeeRate * AGGREGATOR_V3_CONFIG.FEE_DENOMINATOR;
8240
8261
  if (this.overlayFeeRate > AGGREGATOR_V3_CONFIG.MAX_FEE_RATE) {
8241
8262
  throw new Error(
@@ -8266,6 +8287,11 @@ var _AggregatorClient = class _AggregatorClient {
8266
8287
  return DEEPBOOK_V3_DEEP_FEE_TYPES.Testnet;
8267
8288
  }
8268
8289
  }
8290
+ getDeepbookV3Config() {
8291
+ return __async(this, null, function* () {
8292
+ return yield getDeepbookV3Config(this.endpoint);
8293
+ });
8294
+ }
8269
8295
  getOneCoinUsedToMerge(coinType) {
8270
8296
  return __async(this, null, function* () {
8271
8297
  try {
@@ -8516,20 +8542,22 @@ var _AggregatorClient = class _AggregatorClient {
8516
8542
  }
8517
8543
  routerSwap(params) {
8518
8544
  return __async(this, null, function* () {
8519
- const { router, inputCoin, slippage, txb, fixable, partner } = params;
8545
+ const { router, inputCoin, slippage, txb, partner } = params;
8520
8546
  if (slippage > 1 || slippage < 0) {
8521
8547
  throw new Error(CLIENT_CONFIG.ERRORS.INVALID_SLIPPAGE);
8522
8548
  }
8549
+ if (!params.router.packages || !params.router.packages.get(PACKAGE_NAMES.AGGREGATOR_V3)) {
8550
+ throw new Error(CLIENT_CONFIG.ERRORS.PACKAGES_REQUIRED);
8551
+ }
8523
8552
  const byAmountIn = params.router.byAmountIn;
8524
8553
  const amountIn = router.amountIn;
8525
8554
  const amountOut = router.amountOut;
8555
+ checkOverlayFeeConfig(this.overlayFeeRate, this.overlayFeeReceiver);
8526
8556
  let overlayFee = new import_bn6.default(0);
8527
- if (this.overlayFeeRate > 0 && this.overlayFeeReceiver !== "0x0") {
8528
- if (byAmountIn) {
8529
- overlayFee = amountOut.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6));
8530
- } else {
8531
- overlayFee = amountIn.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6));
8532
- }
8557
+ if (byAmountIn) {
8558
+ overlayFee = amountOut.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6));
8559
+ } else {
8560
+ overlayFee = amountIn.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6));
8533
8561
  }
8534
8562
  const expectedAmountOut = byAmountIn ? amountOut.sub(overlayFee) : amountOut;
8535
8563
  const expectedAmountIn = byAmountIn ? amountIn : amountIn.add(overlayFee);
@@ -8538,9 +8566,6 @@ var _AggregatorClient = class _AggregatorClient {
8538
8566
  byAmountIn,
8539
8567
  slippage
8540
8568
  );
8541
- if (!params.router.packages || !params.router.packages.get(PACKAGE_NAMES.AGGREGATOR_V3)) {
8542
- throw new Error(CLIENT_CONFIG.ERRORS.PACKAGES_REQUIRED);
8543
- }
8544
8569
  const priceIDs = findPythPriceIDs(router.paths);
8545
8570
  const priceInfoObjectIds = priceIDs.length > 0 ? yield this.updatePythPriceIDs(priceIDs, txb) : /* @__PURE__ */ new Map();
8546
8571
  if (byAmountIn) {
@@ -8573,17 +8598,16 @@ var _AggregatorClient = class _AggregatorClient {
8573
8598
  const fromCoinType = router.paths[0].from;
8574
8599
  const targetCoinType = router.paths[router.paths.length - 1].target;
8575
8600
  const byAmountIn = router.byAmountIn;
8601
+ checkOverlayFeeConfig(this.overlayFeeRate, this.overlayFeeReceiver);
8576
8602
  let overlayFee = 0;
8577
- if (this.overlayFeeRate > 0 && this.overlayFeeReceiver !== "0x0") {
8578
- if (byAmountIn) {
8579
- overlayFee = Number(
8580
- router.amountOut.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6)).toString()
8581
- );
8582
- } else {
8583
- overlayFee = Number(
8584
- router.amountIn.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6)).toString()
8585
- );
8586
- }
8603
+ if (byAmountIn) {
8604
+ overlayFee = Number(
8605
+ router.amountOut.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6)).toString()
8606
+ );
8607
+ } else {
8608
+ overlayFee = Number(
8609
+ router.amountIn.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6)).toString()
8610
+ );
8587
8611
  }
8588
8612
  const expectedAmountOut = byAmountIn ? router.amountOut.sub(new import_bn6.default(overlayFee)) : router.amountOut;
8589
8613
  const expectedAmountIn = byAmountIn ? router.amountIn : router.amountIn.add(new import_bn6.default(overlayFee));
@@ -8635,18 +8659,17 @@ var _AggregatorClient = class _AggregatorClient {
8635
8659
  }
8636
8660
  fixableRouterSwapV3(params) {
8637
8661
  return __async(this, null, function* () {
8638
- const { router, inputCoin, slippage, txb, deepbookv3DeepFee, partner } = params;
8662
+ const { router, inputCoin, slippage, txb, partner } = params;
8663
+ checkOverlayFeeConfig(this.overlayFeeRate, this.overlayFeeReceiver);
8639
8664
  let overlayFee = 0;
8640
- if (this.overlayFeeRate > 0 && this.overlayFeeReceiver !== "0x0") {
8641
- if (router.byAmountIn) {
8642
- overlayFee = Number(
8643
- router.amountOut.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6)).toString()
8644
- );
8645
- } else {
8646
- overlayFee = Number(
8647
- router.amountIn.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6)).toString()
8648
- );
8649
- }
8665
+ if (router.byAmountIn) {
8666
+ overlayFee = Number(
8667
+ router.amountOut.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6)).toString()
8668
+ );
8669
+ } else {
8670
+ overlayFee = Number(
8671
+ router.amountIn.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6)).toString()
8672
+ );
8650
8673
  }
8651
8674
  const expectedAmountOut = router.byAmountIn ? router.amountOut.sub(new import_bn6.default(overlayFee)) : router.amountOut;
8652
8675
  const expectedAmountIn = router.byAmountIn ? router.amountIn : router.amountIn.add(new import_bn6.default(overlayFee));
@@ -8755,6 +8778,7 @@ var _AggregatorClient = class _AggregatorClient {
8755
8778
  const routeData = {
8756
8779
  amountIn,
8757
8780
  amountOut: new import_bn6.default((_d = event.amount_out) != null ? _d : 0),
8781
+ deviationRatio: 0,
8758
8782
  paths: [
8759
8783
  {
8760
8784
  id: pools[tempIndex],
@@ -8872,6 +8896,16 @@ function recordFirstCoinIndex(paths) {
8872
8896
  }
8873
8897
  return newCoinRecord;
8874
8898
  }
8899
+ function checkOverlayFeeConfig(overlayFeeRate, overlayFeeReceiver) {
8900
+ if (overlayFeeRate > CLIENT_CONFIG.MAX_FEE_RATE) {
8901
+ throw new Error(CLIENT_CONFIG.ERRORS.INVALID_OVERLAY_FEE_RATE);
8902
+ }
8903
+ if (overlayFeeReceiver === "0x0" && overlayFeeRate > 0) {
8904
+ throw new Error(
8905
+ CLIENT_CONFIG.ERRORS.OVERLAY_FEE_RECEIVER_REQUIRED
8906
+ );
8907
+ }
8908
+ }
8875
8909
 
8876
8910
  // src/types/sui.ts
8877
8911
  var getDefaultSuiInputType = (value) => {
package/dist/index.mjs CHANGED
@@ -2993,7 +2993,7 @@ var GAS_TYPE_ARG = "0x2::sui::SUI";
2993
2993
  var GAS_TYPE_ARG_LONG = "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI";
2994
2994
  var GAS_SYMBOL = "SUI";
2995
2995
  var DEFAULT_NFT_TRANSFER_GAS_FEE = 450;
2996
- var SUI_SYSTEM_STATE_OBJECT_ID = "0x0000000000000000000000000000000000000005";
2996
+ var SUI_SYSTEM_STATE_OBJECT_ID = "0x0000000000000000000000000000000000000000000000000000000000000005";
2997
2997
  var CoinUtils = class _CoinUtils {
2998
2998
  /**
2999
2999
  * Get the coin type argument from a SuiMoveObject.
@@ -3101,10 +3101,18 @@ var CoinUtils = class _CoinUtils {
3101
3101
  * @returns The CoinAsset objects that have a balance greater than or equal to the given amount.
3102
3102
  */
3103
3103
  static selectCoinObjectIdGreaterThanOrEqual(coins, amount, exclude = []) {
3104
- const selectedResult = _CoinUtils.selectCoinAssetGreaterThanOrEqual(coins, amount, exclude);
3105
- const objectArray = selectedResult.selectedCoins.map((item) => item.coinObjectId);
3104
+ const selectedResult = _CoinUtils.selectCoinAssetGreaterThanOrEqual(
3105
+ coins,
3106
+ amount,
3107
+ exclude
3108
+ );
3109
+ const objectArray = selectedResult.selectedCoins.map(
3110
+ (item) => item.coinObjectId
3111
+ );
3106
3112
  const remainCoins = selectedResult.remainingCoins;
3107
- const amountArray = selectedResult.selectedCoins.map((item) => item.balance.toString());
3113
+ const amountArray = selectedResult.selectedCoins.map(
3114
+ (item) => item.balance.toString()
3115
+ );
3108
3116
  return { objectArray, remainCoins, amountArray };
3109
3117
  }
3110
3118
  /**
@@ -3116,7 +3124,9 @@ var CoinUtils = class _CoinUtils {
3116
3124
  * @returns The CoinAsset objects that have a balance greater than or equal to the given amount.
3117
3125
  */
3118
3126
  static selectCoinAssetGreaterThanOrEqual(coins, amount, exclude = []) {
3119
- const sortedCoins = _CoinUtils.sortByBalance(coins.filter((c) => !exclude.includes(c.coinObjectId)));
3127
+ const sortedCoins = _CoinUtils.sortByBalance(
3128
+ coins.filter((c) => !exclude.includes(c.coinObjectId))
3129
+ );
3120
3130
  const total = _CoinUtils.calculateTotalBalance(sortedCoins);
3121
3131
  if (total < amount) {
3122
3132
  return { selectedCoins: [], remainingCoins: sortedCoins };
@@ -3129,9 +3139,13 @@ var CoinUtils = class _CoinUtils {
3129
3139
  const remainingCoins = [...sortedCoins];
3130
3140
  while (sum2 < total) {
3131
3141
  const target = amount - sum2;
3132
- const coinWithSmallestSufficientBalanceIndex = remainingCoins.findIndex((c) => c.balance >= target);
3142
+ const coinWithSmallestSufficientBalanceIndex = remainingCoins.findIndex(
3143
+ (c) => c.balance >= target
3144
+ );
3133
3145
  if (coinWithSmallestSufficientBalanceIndex !== -1) {
3134
- selectedCoins.push(remainingCoins[coinWithSmallestSufficientBalanceIndex]);
3146
+ selectedCoins.push(
3147
+ remainingCoins[coinWithSmallestSufficientBalanceIndex]
3148
+ );
3135
3149
  remainingCoins.splice(coinWithSmallestSufficientBalanceIndex, 1);
3136
3150
  break;
3137
3151
  }
@@ -3141,7 +3155,10 @@ var CoinUtils = class _CoinUtils {
3141
3155
  sum2 += coinWithLargestBalance.balance;
3142
3156
  }
3143
3157
  }
3144
- return { selectedCoins: _CoinUtils.sortByBalance(selectedCoins), remainingCoins: _CoinUtils.sortByBalance(remainingCoins) };
3158
+ return {
3159
+ selectedCoins: _CoinUtils.sortByBalance(selectedCoins),
3160
+ remainingCoins: _CoinUtils.sortByBalance(remainingCoins)
3161
+ };
3145
3162
  }
3146
3163
  /**
3147
3164
  * Sort the CoinAsset objects by their balance.
@@ -3150,10 +3167,14 @@ var CoinUtils = class _CoinUtils {
3150
3167
  * @returns The sorted CoinAsset objects.
3151
3168
  */
3152
3169
  static sortByBalance(coins) {
3153
- return coins.sort((a, b) => a.balance < b.balance ? -1 : a.balance > b.balance ? 1 : 0);
3170
+ return coins.sort(
3171
+ (a, b) => a.balance < b.balance ? -1 : a.balance > b.balance ? 1 : 0
3172
+ );
3154
3173
  }
3155
3174
  static sortByBalanceDes(coins) {
3156
- return coins.sort((a, b) => a.balance > b.balance ? -1 : a.balance < b.balance ? 0 : 1);
3175
+ return coins.sort(
3176
+ (a, b) => a.balance > b.balance ? -1 : a.balance < b.balance ? 0 : 1
3177
+ );
3157
3178
  }
3158
3179
  /**
3159
3180
  * Calculate the total balance of a list of CoinAsset objects.
@@ -3391,8 +3412,9 @@ var DEEPBOOK_V3_DEEP_FEE_TYPES = {
3391
3412
  var CLIENT_CONFIG = {
3392
3413
  DEFAULT_PYTH_URL: "https://hermes.pyth.network",
3393
3414
  PYTH_TIMEOUT: 3e3,
3394
- MAX_OVERLAY_FEE_RATE: 0.1,
3415
+ MAX_OVERLAY_FEE_RATE_PARAMS: 0.1,
3395
3416
  FEE_RATE_MULTIPLIER: 1e6,
3417
+ MAX_FEE_RATE: 1e5,
3396
3418
  DEFAULT_OVERLAY_FEE_RECEIVER: "0x0",
3397
3419
  // Error Messages
3398
3420
  ERRORS: {
@@ -3405,7 +3427,8 @@ var CLIENT_CONFIG = {
3405
3427
  PYTH_UNAVAILABLE: "All Pyth price nodes are unavailable. Cannot fetch price data. Please switch to or add new available Pyth nodes",
3406
3428
  QUOTE_ID_REQUIRED: "Quote ID is required",
3407
3429
  AGGREGATOR_V3_PACKAGE_REQUIRED: "Aggregator V3 package is required",
3408
- PACKAGES_REQUIRED: "Packages are required"
3430
+ PACKAGES_REQUIRED: "Packages are required",
3431
+ OVERLAY_FEE_RECEIVER_REQUIRED: "Overlay fee rate is set, but overlay fee receiver is not set"
3409
3432
  }
3410
3433
  };
3411
3434
  var AGGREGATOR_V3_CONFIG = {
@@ -3420,7 +3443,7 @@ var AGGREGATOR_V3_CONFIG = {
3420
3443
  };
3421
3444
 
3422
3445
  // src/api.ts
3423
- var SDK_VERSION = 1010102;
3446
+ var SDK_VERSION = 1010103;
3424
3447
  function parseRouterResponse(data, byAmountIn) {
3425
3448
  let packages = /* @__PURE__ */ new Map();
3426
3449
  if (data.packages) {
@@ -3438,6 +3461,7 @@ function parseRouterResponse(data, byAmountIn) {
3438
3461
  amountOut: new import_bn2.default(data.amount_out.toString()),
3439
3462
  byAmountIn,
3440
3463
  insufficientLiquidity: false,
3464
+ deviationRatio: data.deviation_ratio,
3441
3465
  packages,
3442
3466
  paths: data.paths.map((path) => ({
3443
3467
  id: path.id,
@@ -6689,7 +6713,7 @@ var SpringsuiRouter = class {
6689
6713
  const args = [
6690
6714
  swapContext,
6691
6715
  txb.object(swapData.poolId),
6692
- txb.object("0x5"),
6716
+ txb.object(SUI_SYSTEM_STATE_OBJECT_ID),
6693
6717
  txb.pure.u64(swapData.amountIn),
6694
6718
  txb.pure.bool(swapData.direction)
6695
6719
  ];
@@ -7371,8 +7395,7 @@ var VoloRouter = class {
7371
7395
  swapContext,
7372
7396
  txb.object(this.stakePool),
7373
7397
  txb.object(this.metadata),
7374
- txb.object("0x5"),
7375
- // SuiSystemState
7398
+ txb.object(SUI_SYSTEM_STATE_OBJECT_ID),
7376
7399
  txb.pure.bool(swapData.direction),
7377
7400
  txb.pure.u64(swapData.amountIn)
7378
7401
  ];
@@ -7423,8 +7446,7 @@ var AfsuiRouter = class {
7423
7446
  swapContext,
7424
7447
  txb.object(this.stakedSuiVault),
7425
7448
  txb.object(this.safe),
7426
- txb.object("0x5"),
7427
- // SuiSystemState
7449
+ txb.object(SUI_SYSTEM_STATE_OBJECT_ID),
7428
7450
  txb.object(this.referVault),
7429
7451
  txb.object(this.validator),
7430
7452
  txb.pure.bool(swapData.direction),
@@ -7469,8 +7491,7 @@ var HaedalRouter = class {
7469
7491
  const args = [
7470
7492
  swapContext,
7471
7493
  txb.object(swapData.poolId),
7472
- txb.object("0x5"),
7473
- // SuiSystemState
7494
+ txb.object(SUI_SYSTEM_STATE_OBJECT_ID),
7474
7495
  txb.pure.bool(swapData.direction),
7475
7496
  txb.pure.u64(swapData.amountIn)
7476
7497
  ];
@@ -8229,7 +8250,7 @@ var _AggregatorClient = class _AggregatorClient {
8229
8250
  this.apiKey = params.apiKey || "";
8230
8251
  this.partner = params.partner;
8231
8252
  if (params.overlayFeeRate) {
8232
- if (params.overlayFeeRate > 0 && params.overlayFeeRate <= CLIENT_CONFIG.MAX_OVERLAY_FEE_RATE) {
8253
+ if (params.overlayFeeRate > 0 && params.overlayFeeRate <= CLIENT_CONFIG.MAX_OVERLAY_FEE_RATE_PARAMS) {
8233
8254
  this.overlayFeeRate = params.overlayFeeRate * AGGREGATOR_V3_CONFIG.FEE_DENOMINATOR;
8234
8255
  if (this.overlayFeeRate > AGGREGATOR_V3_CONFIG.MAX_FEE_RATE) {
8235
8256
  throw new Error(
@@ -8260,6 +8281,11 @@ var _AggregatorClient = class _AggregatorClient {
8260
8281
  return DEEPBOOK_V3_DEEP_FEE_TYPES.Testnet;
8261
8282
  }
8262
8283
  }
8284
+ getDeepbookV3Config() {
8285
+ return __async(this, null, function* () {
8286
+ return yield getDeepbookV3Config(this.endpoint);
8287
+ });
8288
+ }
8263
8289
  getOneCoinUsedToMerge(coinType) {
8264
8290
  return __async(this, null, function* () {
8265
8291
  try {
@@ -8510,20 +8536,22 @@ var _AggregatorClient = class _AggregatorClient {
8510
8536
  }
8511
8537
  routerSwap(params) {
8512
8538
  return __async(this, null, function* () {
8513
- const { router, inputCoin, slippage, txb, fixable, partner } = params;
8539
+ const { router, inputCoin, slippage, txb, partner } = params;
8514
8540
  if (slippage > 1 || slippage < 0) {
8515
8541
  throw new Error(CLIENT_CONFIG.ERRORS.INVALID_SLIPPAGE);
8516
8542
  }
8543
+ if (!params.router.packages || !params.router.packages.get(PACKAGE_NAMES.AGGREGATOR_V3)) {
8544
+ throw new Error(CLIENT_CONFIG.ERRORS.PACKAGES_REQUIRED);
8545
+ }
8517
8546
  const byAmountIn = params.router.byAmountIn;
8518
8547
  const amountIn = router.amountIn;
8519
8548
  const amountOut = router.amountOut;
8549
+ checkOverlayFeeConfig(this.overlayFeeRate, this.overlayFeeReceiver);
8520
8550
  let overlayFee = new import_bn6.default(0);
8521
- if (this.overlayFeeRate > 0 && this.overlayFeeReceiver !== "0x0") {
8522
- if (byAmountIn) {
8523
- overlayFee = amountOut.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6));
8524
- } else {
8525
- overlayFee = amountIn.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6));
8526
- }
8551
+ if (byAmountIn) {
8552
+ overlayFee = amountOut.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6));
8553
+ } else {
8554
+ overlayFee = amountIn.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6));
8527
8555
  }
8528
8556
  const expectedAmountOut = byAmountIn ? amountOut.sub(overlayFee) : amountOut;
8529
8557
  const expectedAmountIn = byAmountIn ? amountIn : amountIn.add(overlayFee);
@@ -8532,9 +8560,6 @@ var _AggregatorClient = class _AggregatorClient {
8532
8560
  byAmountIn,
8533
8561
  slippage
8534
8562
  );
8535
- if (!params.router.packages || !params.router.packages.get(PACKAGE_NAMES.AGGREGATOR_V3)) {
8536
- throw new Error(CLIENT_CONFIG.ERRORS.PACKAGES_REQUIRED);
8537
- }
8538
8563
  const priceIDs = findPythPriceIDs(router.paths);
8539
8564
  const priceInfoObjectIds = priceIDs.length > 0 ? yield this.updatePythPriceIDs(priceIDs, txb) : /* @__PURE__ */ new Map();
8540
8565
  if (byAmountIn) {
@@ -8567,17 +8592,16 @@ var _AggregatorClient = class _AggregatorClient {
8567
8592
  const fromCoinType = router.paths[0].from;
8568
8593
  const targetCoinType = router.paths[router.paths.length - 1].target;
8569
8594
  const byAmountIn = router.byAmountIn;
8595
+ checkOverlayFeeConfig(this.overlayFeeRate, this.overlayFeeReceiver);
8570
8596
  let overlayFee = 0;
8571
- if (this.overlayFeeRate > 0 && this.overlayFeeReceiver !== "0x0") {
8572
- if (byAmountIn) {
8573
- overlayFee = Number(
8574
- router.amountOut.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6)).toString()
8575
- );
8576
- } else {
8577
- overlayFee = Number(
8578
- router.amountIn.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6)).toString()
8579
- );
8580
- }
8597
+ if (byAmountIn) {
8598
+ overlayFee = Number(
8599
+ router.amountOut.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6)).toString()
8600
+ );
8601
+ } else {
8602
+ overlayFee = Number(
8603
+ router.amountIn.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6)).toString()
8604
+ );
8581
8605
  }
8582
8606
  const expectedAmountOut = byAmountIn ? router.amountOut.sub(new import_bn6.default(overlayFee)) : router.amountOut;
8583
8607
  const expectedAmountIn = byAmountIn ? router.amountIn : router.amountIn.add(new import_bn6.default(overlayFee));
@@ -8629,18 +8653,17 @@ var _AggregatorClient = class _AggregatorClient {
8629
8653
  }
8630
8654
  fixableRouterSwapV3(params) {
8631
8655
  return __async(this, null, function* () {
8632
- const { router, inputCoin, slippage, txb, deepbookv3DeepFee, partner } = params;
8656
+ const { router, inputCoin, slippage, txb, partner } = params;
8657
+ checkOverlayFeeConfig(this.overlayFeeRate, this.overlayFeeReceiver);
8633
8658
  let overlayFee = 0;
8634
- if (this.overlayFeeRate > 0 && this.overlayFeeReceiver !== "0x0") {
8635
- if (router.byAmountIn) {
8636
- overlayFee = Number(
8637
- router.amountOut.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6)).toString()
8638
- );
8639
- } else {
8640
- overlayFee = Number(
8641
- router.amountIn.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6)).toString()
8642
- );
8643
- }
8659
+ if (router.byAmountIn) {
8660
+ overlayFee = Number(
8661
+ router.amountOut.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6)).toString()
8662
+ );
8663
+ } else {
8664
+ overlayFee = Number(
8665
+ router.amountIn.mul(new import_bn6.default(this.overlayFeeRate)).div(new import_bn6.default(1e6)).toString()
8666
+ );
8644
8667
  }
8645
8668
  const expectedAmountOut = router.byAmountIn ? router.amountOut.sub(new import_bn6.default(overlayFee)) : router.amountOut;
8646
8669
  const expectedAmountIn = router.byAmountIn ? router.amountIn : router.amountIn.add(new import_bn6.default(overlayFee));
@@ -8749,6 +8772,7 @@ var _AggregatorClient = class _AggregatorClient {
8749
8772
  const routeData = {
8750
8773
  amountIn,
8751
8774
  amountOut: new import_bn6.default((_d = event.amount_out) != null ? _d : 0),
8775
+ deviationRatio: 0,
8752
8776
  paths: [
8753
8777
  {
8754
8778
  id: pools[tempIndex],
@@ -8866,6 +8890,16 @@ function recordFirstCoinIndex(paths) {
8866
8890
  }
8867
8891
  return newCoinRecord;
8868
8892
  }
8893
+ function checkOverlayFeeConfig(overlayFeeRate, overlayFeeReceiver) {
8894
+ if (overlayFeeRate > CLIENT_CONFIG.MAX_FEE_RATE) {
8895
+ throw new Error(CLIENT_CONFIG.ERRORS.INVALID_OVERLAY_FEE_RATE);
8896
+ }
8897
+ if (overlayFeeReceiver === "0x0" && overlayFeeRate > 0) {
8898
+ throw new Error(
8899
+ CLIENT_CONFIG.ERRORS.OVERLAY_FEE_RECEIVER_REQUIRED
8900
+ );
8901
+ }
8902
+ }
8869
8903
 
8870
8904
  // src/types/sui.ts
8871
8905
  var getDefaultSuiInputType = (value) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cetusprotocol/aggregator-sdk",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "sideEffects": false,
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -45,4 +45,4 @@
45
45
  "ts-jest": "^29.1.3",
46
46
  "typescript": "^5.0.0"
47
47
  }
48
- }
48
+ }