@cetusprotocol/aggregator-sdk 1.1.4 → 1.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -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 = "0x0000000000000000000000000000000000000000000000000000000000000005";
2996
+ var SUI_SYSTEM_STATE_OBJECT_ID = "0x0000000000000000000000000000000000000005";
2997
2997
  var CoinUtils = class _CoinUtils {
2998
2998
  /**
2999
2999
  * Get the coin type argument from a SuiMoveObject.
@@ -3101,18 +3101,10 @@ 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(
3105
- coins,
3106
- amount,
3107
- exclude
3108
- );
3109
- const objectArray = selectedResult.selectedCoins.map(
3110
- (item) => item.coinObjectId
3111
- );
3104
+ const selectedResult = _CoinUtils.selectCoinAssetGreaterThanOrEqual(coins, amount, exclude);
3105
+ const objectArray = selectedResult.selectedCoins.map((item) => item.coinObjectId);
3112
3106
  const remainCoins = selectedResult.remainingCoins;
3113
- const amountArray = selectedResult.selectedCoins.map(
3114
- (item) => item.balance.toString()
3115
- );
3107
+ const amountArray = selectedResult.selectedCoins.map((item) => item.balance.toString());
3116
3108
  return { objectArray, remainCoins, amountArray };
3117
3109
  }
3118
3110
  /**
@@ -3124,9 +3116,7 @@ var CoinUtils = class _CoinUtils {
3124
3116
  * @returns The CoinAsset objects that have a balance greater than or equal to the given amount.
3125
3117
  */
3126
3118
  static selectCoinAssetGreaterThanOrEqual(coins, amount, exclude = []) {
3127
- const sortedCoins = _CoinUtils.sortByBalance(
3128
- coins.filter((c) => !exclude.includes(c.coinObjectId))
3129
- );
3119
+ const sortedCoins = _CoinUtils.sortByBalance(coins.filter((c) => !exclude.includes(c.coinObjectId)));
3130
3120
  const total = _CoinUtils.calculateTotalBalance(sortedCoins);
3131
3121
  if (total < amount) {
3132
3122
  return { selectedCoins: [], remainingCoins: sortedCoins };
@@ -3139,13 +3129,9 @@ var CoinUtils = class _CoinUtils {
3139
3129
  const remainingCoins = [...sortedCoins];
3140
3130
  while (sum2 < total) {
3141
3131
  const target = amount - sum2;
3142
- const coinWithSmallestSufficientBalanceIndex = remainingCoins.findIndex(
3143
- (c) => c.balance >= target
3144
- );
3132
+ const coinWithSmallestSufficientBalanceIndex = remainingCoins.findIndex((c) => c.balance >= target);
3145
3133
  if (coinWithSmallestSufficientBalanceIndex !== -1) {
3146
- selectedCoins.push(
3147
- remainingCoins[coinWithSmallestSufficientBalanceIndex]
3148
- );
3134
+ selectedCoins.push(remainingCoins[coinWithSmallestSufficientBalanceIndex]);
3149
3135
  remainingCoins.splice(coinWithSmallestSufficientBalanceIndex, 1);
3150
3136
  break;
3151
3137
  }
@@ -3155,10 +3141,7 @@ var CoinUtils = class _CoinUtils {
3155
3141
  sum2 += coinWithLargestBalance.balance;
3156
3142
  }
3157
3143
  }
3158
- return {
3159
- selectedCoins: _CoinUtils.sortByBalance(selectedCoins),
3160
- remainingCoins: _CoinUtils.sortByBalance(remainingCoins)
3161
- };
3144
+ return { selectedCoins: _CoinUtils.sortByBalance(selectedCoins), remainingCoins: _CoinUtils.sortByBalance(remainingCoins) };
3162
3145
  }
3163
3146
  /**
3164
3147
  * Sort the CoinAsset objects by their balance.
@@ -3167,14 +3150,10 @@ var CoinUtils = class _CoinUtils {
3167
3150
  * @returns The sorted CoinAsset objects.
3168
3151
  */
3169
3152
  static sortByBalance(coins) {
3170
- return coins.sort(
3171
- (a, b) => a.balance < b.balance ? -1 : a.balance > b.balance ? 1 : 0
3172
- );
3153
+ return coins.sort((a, b) => a.balance < b.balance ? -1 : a.balance > b.balance ? 1 : 0);
3173
3154
  }
3174
3155
  static sortByBalanceDes(coins) {
3175
- return coins.sort(
3176
- (a, b) => a.balance > b.balance ? -1 : a.balance < b.balance ? 0 : 1
3177
- );
3156
+ return coins.sort((a, b) => a.balance > b.balance ? -1 : a.balance < b.balance ? 0 : 1);
3178
3157
  }
3179
3158
  /**
3180
3159
  * Calculate the total balance of a list of CoinAsset objects.
@@ -3355,7 +3334,7 @@ var SuiZeroCoinFn = "0x2::coin::zero";
3355
3334
  var DEEPBOOK_PACKAGE_ID = "0x000000000000000000000000000000000000000000000000000000000000dee9";
3356
3335
  var DEEPBOOK_PUBLISHED_AT = "0x000000000000000000000000000000000000000000000000000000000000dee9";
3357
3336
  var CETUS_PUBLISHED_AT = "0x70968826ad1b4ba895753f634b0aea68d0672908ca1075a2abdf0fc9e0b2fc6a";
3358
- var CETUS_V3_PUBLISHED_AT = "0x550dcd6070230d8bf18d99d34e3b2ca1d3657b76cc80ffdacdb2b5d28d7e0124";
3337
+ var CETUS_V3_PUBLISHED_AT = "0xb1e11ceaf3e7cd3031ef5e24804478ec3441c5aecdace910bdaca317a0c1c535";
3359
3338
  var MAINNET_CETUS_GLOBAL_CONFIG_ID = "0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f";
3360
3339
  var TESTNET_CETUS_GLOBAL_CONFIG_ID = "0x6f4149091a5aea0e818e7243a13adcfb403842d670b9a2089de058512620687a";
3361
3340
  var MAINNET_FLOWX_AMM_CONTAINER_ID = "0xb65dcbf63fd3ad5d0ebfbf334780dc9f785eff38a4459e37ab08fa79576ee511";
@@ -3412,9 +3391,9 @@ var DEEPBOOK_V3_DEEP_FEE_TYPES = {
3412
3391
  var CLIENT_CONFIG = {
3413
3392
  DEFAULT_PYTH_URL: "https://hermes.pyth.network",
3414
3393
  PYTH_TIMEOUT: 3e3,
3415
- MAX_OVERLAY_FEE_RATE_PARAMS: 0.1,
3394
+ MAX_OVERLAY_FEE_RATE: 0.1,
3395
+ MAX_OVERLAY_FEE_RATE_NUMERATOR: 1e5,
3416
3396
  FEE_RATE_MULTIPLIER: 1e6,
3417
- MAX_FEE_RATE: 1e5,
3418
3397
  DEFAULT_OVERLAY_FEE_RECEIVER: "0x0",
3419
3398
  // Error Messages
3420
3399
  ERRORS: {
@@ -3437,13 +3416,13 @@ var AGGREGATOR_V3_CONFIG = {
3437
3416
  // 10%
3438
3417
  MAX_AMOUNT_IN: U64_MAX,
3439
3418
  DEFAULT_PUBLISHED_AT: {
3440
- Mainnet: "0x07c27e879ba9282506284b0fef26d393978906fc9496550d978c6f493dbfa3e5",
3419
+ Mainnet: "0x33ec64e9bb369bf045ddc198c81adbf2acab424da37465d95296ee02045d2b17",
3441
3420
  Testnet: "0x0"
3442
3421
  }
3443
3422
  };
3444
3423
 
3445
3424
  // src/api.ts
3446
- var SDK_VERSION = 1010104;
3425
+ var SDK_VERSION = 1010105;
3447
3426
  function parseRouterResponse(data, byAmountIn) {
3448
3427
  let packages = /* @__PURE__ */ new Map();
3449
3428
  if (data.packages) {
@@ -3606,7 +3585,6 @@ function getRouter(endpoint, apiKey, params) {
3606
3585
  url += `&apiKey=${apiKey}`;
3607
3586
  }
3608
3587
  url += `&v=${SDK_VERSION}`;
3609
- console.log("url", url);
3610
3588
  const response = yield fetch(url);
3611
3589
  return response;
3612
3590
  } catch (error) {
@@ -3697,7 +3675,6 @@ function processFlattenRoutes(routerData) {
3697
3675
  flattenedPaths[i].isLastUseOfIntermediateToken = true;
3698
3676
  }
3699
3677
  }
3700
- console.log("flattenedPaths", flattenedPaths);
3701
3678
  return {
3702
3679
  quoteID: routerData.quoteID || "",
3703
3680
  amountIn: routerData.amountIn,
@@ -6713,7 +6690,7 @@ var SpringsuiRouter = class {
6713
6690
  const args = [
6714
6691
  swapContext,
6715
6692
  txb.object(swapData.poolId),
6716
- txb.object(SUI_SYSTEM_STATE_OBJECT_ID),
6693
+ txb.object("0x5"),
6717
6694
  txb.pure.u64(swapData.amountIn),
6718
6695
  txb.pure.bool(swapData.direction)
6719
6696
  ];
@@ -7395,7 +7372,8 @@ var VoloRouter = class {
7395
7372
  swapContext,
7396
7373
  txb.object(this.stakePool),
7397
7374
  txb.object(this.metadata),
7398
- txb.object(SUI_SYSTEM_STATE_OBJECT_ID),
7375
+ txb.object("0x5"),
7376
+ // SuiSystemState
7399
7377
  txb.pure.bool(swapData.direction),
7400
7378
  txb.pure.u64(swapData.amountIn)
7401
7379
  ];
@@ -7446,7 +7424,8 @@ var AfsuiRouter = class {
7446
7424
  swapContext,
7447
7425
  txb.object(this.stakedSuiVault),
7448
7426
  txb.object(this.safe),
7449
- txb.object(SUI_SYSTEM_STATE_OBJECT_ID),
7427
+ txb.object("0x5"),
7428
+ // SuiSystemState
7450
7429
  txb.object(this.referVault),
7451
7430
  txb.object(this.validator),
7452
7431
  txb.pure.bool(swapData.direction),
@@ -7491,7 +7470,8 @@ var HaedalRouter = class {
7491
7470
  const args = [
7492
7471
  swapContext,
7493
7472
  txb.object(swapData.poolId),
7494
- txb.object(SUI_SYSTEM_STATE_OBJECT_ID),
7473
+ txb.object("0x5"),
7474
+ // SuiSystemState
7495
7475
  txb.pure.bool(swapData.direction),
7496
7476
  txb.pure.u64(swapData.amountIn)
7497
7477
  ];
@@ -8250,7 +8230,7 @@ var _AggregatorClient = class _AggregatorClient {
8250
8230
  this.apiKey = params.apiKey || "";
8251
8231
  this.partner = params.partner;
8252
8232
  if (params.overlayFeeRate) {
8253
- if (params.overlayFeeRate > 0 && params.overlayFeeRate <= CLIENT_CONFIG.MAX_OVERLAY_FEE_RATE_PARAMS) {
8233
+ if (params.overlayFeeRate > 0 && params.overlayFeeRate <= CLIENT_CONFIG.MAX_OVERLAY_FEE_RATE) {
8254
8234
  this.overlayFeeRate = params.overlayFeeRate * AGGREGATOR_V3_CONFIG.FEE_DENOMINATOR;
8255
8235
  if (this.overlayFeeRate > AGGREGATOR_V3_CONFIG.MAX_FEE_RATE) {
8256
8236
  throw new Error(
@@ -8891,7 +8871,7 @@ function recordFirstCoinIndex(paths) {
8891
8871
  return newCoinRecord;
8892
8872
  }
8893
8873
  function checkOverlayFeeConfig(overlayFeeRate, overlayFeeReceiver) {
8894
- if (overlayFeeRate > CLIENT_CONFIG.MAX_FEE_RATE) {
8874
+ if (overlayFeeRate > CLIENT_CONFIG.MAX_OVERLAY_FEE_RATE_NUMERATOR) {
8895
8875
  throw new Error(CLIENT_CONFIG.ERRORS.INVALID_OVERLAY_FEE_RATE);
8896
8876
  }
8897
8877
  if (overlayFeeReceiver === "0x0" && overlayFeeRate > 0) {