@magmaprotocol/magma-clmm-sdk 0.5.66 → 0.5.68

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.js CHANGED
@@ -257,7 +257,7 @@ var CachedContent = class {
257
257
  };
258
258
 
259
259
  // src/utils/common.ts
260
- var import_bn13 = __toESM(require("bn.js"));
260
+ var import_bn12 = __toESM(require("bn.js"));
261
261
  var import_bcs = require("@mysten/bcs");
262
262
  var import_ed25519 = require("@mysten/sui/keypairs/ed25519");
263
263
  var import_secp256k1 = require("@mysten/sui/keypairs/secp256k1");
@@ -1812,9 +1812,6 @@ function collectFeesQuote(param) {
1812
1812
  return updateFees(param.position, fee_growth_inside_a, fee_growth_inside_b);
1813
1813
  }
1814
1814
 
1815
- // src/math/dlmmStrategy.ts
1816
- var import_bn10 = __toESM(require("bn.js"));
1817
-
1818
1815
  // src/math/dlmmWeightToAmounts.ts
1819
1816
  var import_bn9 = __toESM(require("bn.js"));
1820
1817
  var import_decimal6 = __toESM(require("decimal.js"));
@@ -2098,31 +2095,11 @@ function toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBi
2098
2095
 
2099
2096
  // src/math/dlmmStrategy.ts
2100
2097
  var StrategyType = /* @__PURE__ */ ((StrategyType2) => {
2101
- StrategyType2[StrategyType2["Spot"] = 0] = "Spot";
2102
- StrategyType2[StrategyType2["Curve"] = 1] = "Curve";
2103
- StrategyType2[StrategyType2["BidAsk"] = 2] = "BidAsk";
2098
+ StrategyType2[StrategyType2["Spot"] = 1] = "Spot";
2099
+ StrategyType2[StrategyType2["Curve"] = 2] = "Curve";
2100
+ StrategyType2[StrategyType2["BidAsk"] = 3] = "BidAsk";
2104
2101
  return StrategyType2;
2105
2102
  })(StrategyType || {});
2106
- function toWeightDecendingOrder(minBinId, maxBinId) {
2107
- const distributions = [];
2108
- for (let i = minBinId; i <= maxBinId; i++) {
2109
- distributions.push({
2110
- binId: i,
2111
- weight: maxBinId - i + 1
2112
- });
2113
- }
2114
- return distributions;
2115
- }
2116
- function toWeightAscendingOrder(minBinId, maxBinId) {
2117
- const distributions = [];
2118
- for (let i = minBinId; i <= maxBinId; i++) {
2119
- distributions.push({
2120
- binId: i,
2121
- weight: i - minBinId + 1
2122
- });
2123
- }
2124
- return distributions;
2125
- }
2126
2103
  function toWeightSpotBalanced(minBinId, maxBinId) {
2127
2104
  const distributions = [];
2128
2105
  for (let i = minBinId; i <= maxBinId; i++) {
@@ -2197,15 +2174,15 @@ function toWeightBidAsk(minBinId, maxBinId, activeId) {
2197
2174
  }
2198
2175
  function autoFillYByStrategy(activeId, binStep, amountX, amountXInActiveBin, amountYInActiveBin, minBinId, maxBinId, strategyType) {
2199
2176
  switch (strategyType) {
2200
- case 0 /* Spot */: {
2177
+ case 1 /* Spot */: {
2201
2178
  const weights = toWeightSpotBalanced(minBinId, maxBinId);
2202
2179
  return autoFillYByWeight(activeId, binStep, amountX, amountXInActiveBin, amountYInActiveBin, weights);
2203
2180
  }
2204
- case 1 /* Curve */: {
2181
+ case 2 /* Curve */: {
2205
2182
  const weights = toWeightCurve(minBinId, maxBinId, activeId);
2206
2183
  return autoFillYByWeight(activeId, binStep, amountX, amountXInActiveBin, amountYInActiveBin, weights);
2207
2184
  }
2208
- case 2 /* BidAsk */: {
2185
+ case 3 /* BidAsk */: {
2209
2186
  const weights = toWeightBidAsk(minBinId, maxBinId, activeId);
2210
2187
  return autoFillYByWeight(activeId, binStep, amountX, amountXInActiveBin, amountYInActiveBin, weights);
2211
2188
  }
@@ -2215,15 +2192,15 @@ function autoFillYByStrategy(activeId, binStep, amountX, amountXInActiveBin, amo
2215
2192
  }
2216
2193
  function autoFillXByStrategy(activeId, binStep, amountY, amountXInActiveBin, amountYInActiveBin, minBinId, maxBinId, strategyType) {
2217
2194
  switch (strategyType) {
2218
- case 0 /* Spot */: {
2195
+ case 1 /* Spot */: {
2219
2196
  const weights = toWeightSpotBalanced(minBinId, maxBinId);
2220
2197
  return autoFillXByWeight(activeId, binStep, amountY, amountXInActiveBin, amountYInActiveBin, weights);
2221
2198
  }
2222
- case 1 /* Curve */: {
2199
+ case 2 /* Curve */: {
2223
2200
  const weights = toWeightCurve(minBinId, maxBinId, activeId);
2224
2201
  return autoFillXByWeight(activeId, binStep, amountY, amountXInActiveBin, amountYInActiveBin, weights);
2225
2202
  }
2226
- case 2 /* BidAsk */: {
2203
+ case 3 /* BidAsk */: {
2227
2204
  const weights = toWeightBidAsk(minBinId, maxBinId, activeId);
2228
2205
  return autoFillXByWeight(activeId, binStep, amountY, amountXInActiveBin, amountYInActiveBin, weights);
2229
2206
  }
@@ -2234,178 +2211,17 @@ function autoFillXByStrategy(activeId, binStep, amountY, amountXInActiveBin, amo
2234
2211
  function toAmountsBothSideByStrategy(activeId, binStep, minBinId, maxBinId, amountX, amountY, amountXInActiveBin, amountYInActiveBin, strategyType) {
2235
2212
  const isSingleSideX = amountY.isZero();
2236
2213
  switch (strategyType) {
2237
- case 0 /* Spot */: {
2238
- if (activeId < minBinId || activeId > maxBinId) {
2239
- const weights = toWeightSpotBalanced(minBinId, maxBinId);
2240
- return toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights);
2241
- }
2242
- const amountsInBin = [];
2243
- if (!isSingleSideX) {
2244
- if (minBinId <= activeId) {
2245
- const weights = toWeightSpotBalanced(minBinId, activeId);
2246
- const amounts = toAmountBidSide(activeId, amountY, weights);
2247
- for (const bin of amounts) {
2248
- amountsInBin.push({
2249
- binId: bin.binId,
2250
- amountX: new import_bn10.default(0),
2251
- amountY: bin.amount
2252
- });
2253
- }
2254
- }
2255
- if (activeId < maxBinId) {
2256
- const weights = toWeightSpotBalanced(activeId + 1, maxBinId);
2257
- const amounts = toAmountAskSide(activeId, binStep, amountX, weights);
2258
- for (const bin of amounts) {
2259
- amountsInBin.push({
2260
- binId: bin.binId,
2261
- amountX: bin.amount,
2262
- amountY: new import_bn10.default(0)
2263
- });
2264
- }
2265
- }
2266
- } else {
2267
- if (minBinId < activeId) {
2268
- const weights = toWeightSpotBalanced(minBinId, activeId - 1);
2269
- const amountsIntoBidSide = toAmountBidSide(activeId, amountY, weights);
2270
- for (const bin of amountsIntoBidSide) {
2271
- amountsInBin.push({
2272
- binId: bin.binId,
2273
- amountX: new import_bn10.default(0),
2274
- amountY: bin.amount
2275
- });
2276
- }
2277
- }
2278
- if (activeId <= maxBinId) {
2279
- const weights = toWeightSpotBalanced(activeId, maxBinId);
2280
- const amountsIntoAskSide = toAmountAskSide(activeId, binStep, amountX, weights);
2281
- for (const bin of amountsIntoAskSide) {
2282
- amountsInBin.push({
2283
- binId: bin.binId,
2284
- amountX: bin.amount,
2285
- amountY: new import_bn10.default(0)
2286
- });
2287
- }
2288
- }
2289
- }
2290
- return amountsInBin;
2291
- }
2292
- case 1 /* Curve */: {
2293
- if (activeId < minBinId) {
2294
- const weights = toWeightDecendingOrder(minBinId, maxBinId);
2295
- return toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights);
2296
- }
2297
- if (activeId > maxBinId) {
2298
- const weights = toWeightAscendingOrder(minBinId, maxBinId);
2299
- return toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights);
2300
- }
2301
- const amountsInBin = [];
2302
- if (!isSingleSideX) {
2303
- if (minBinId <= activeId) {
2304
- const weights = toWeightAscendingOrder(minBinId, activeId);
2305
- const amounts = toAmountBidSide(activeId, amountY, weights);
2306
- for (const bin of amounts) {
2307
- amountsInBin.push({
2308
- binId: bin.binId,
2309
- amountX: new import_bn10.default(0),
2310
- amountY: bin.amount
2311
- });
2312
- }
2313
- }
2314
- if (activeId < maxBinId) {
2315
- const weights = toWeightDecendingOrder(activeId + 1, maxBinId);
2316
- const amounts = toAmountAskSide(activeId, binStep, amountX, weights);
2317
- for (const bin of amounts) {
2318
- amountsInBin.push({
2319
- binId: bin.binId,
2320
- amountX: bin.amount,
2321
- amountY: new import_bn10.default(0)
2322
- });
2323
- }
2324
- }
2325
- } else {
2326
- if (minBinId < activeId) {
2327
- const weights = toWeightAscendingOrder(minBinId, activeId - 1);
2328
- const amountsIntoBidSide = toAmountBidSide(activeId, amountY, weights);
2329
- for (const bin of amountsIntoBidSide) {
2330
- amountsInBin.push({
2331
- binId: bin.binId,
2332
- amountX: new import_bn10.default(0),
2333
- amountY: bin.amount
2334
- });
2335
- }
2336
- }
2337
- if (activeId <= maxBinId) {
2338
- const weights = toWeightDecendingOrder(activeId, maxBinId);
2339
- const amountsIntoAskSide = toAmountAskSide(activeId, binStep, amountX, weights);
2340
- for (const bin of amountsIntoAskSide) {
2341
- amountsInBin.push({
2342
- binId: bin.binId,
2343
- amountX: bin.amount,
2344
- amountY: new import_bn10.default(0)
2345
- });
2346
- }
2347
- }
2348
- }
2349
- return amountsInBin;
2350
- }
2351
- case 2 /* BidAsk */: {
2352
- if (activeId < minBinId) {
2353
- const weights = toWeightAscendingOrder(minBinId, maxBinId);
2354
- return toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights);
2355
- }
2356
- if (activeId > maxBinId) {
2357
- const weights = toWeightDecendingOrder(minBinId, maxBinId);
2358
- return toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights);
2359
- }
2360
- const amountsInBin = [];
2361
- if (!isSingleSideX) {
2362
- if (minBinId <= activeId) {
2363
- const weights = toWeightDecendingOrder(minBinId, activeId);
2364
- const amounts = toAmountBidSide(activeId, amountY, weights);
2365
- for (const bin of amounts) {
2366
- amountsInBin.push({
2367
- binId: bin.binId,
2368
- amountX: new import_bn10.default(0),
2369
- amountY: bin.amount
2370
- });
2371
- }
2372
- }
2373
- if (activeId < maxBinId) {
2374
- const weights = toWeightAscendingOrder(activeId + 1, maxBinId);
2375
- const amounts = toAmountAskSide(activeId, binStep, amountX, weights);
2376
- for (const bin of amounts) {
2377
- amountsInBin.push({
2378
- binId: bin.binId,
2379
- amountX: bin.amount,
2380
- amountY: new import_bn10.default(0)
2381
- });
2382
- }
2383
- }
2384
- } else {
2385
- if (minBinId < activeId) {
2386
- const weights = toWeightDecendingOrder(minBinId, activeId - 1);
2387
- const amountsIntoBidSide = toAmountBidSide(activeId, amountY, weights);
2388
- for (const bin of amountsIntoBidSide) {
2389
- amountsInBin.push({
2390
- binId: bin.binId,
2391
- amountX: new import_bn10.default(0),
2392
- amountY: bin.amount
2393
- });
2394
- }
2395
- }
2396
- if (activeId <= maxBinId) {
2397
- const weights = toWeightAscendingOrder(activeId, maxBinId);
2398
- const amountsIntoAskSide = toAmountAskSide(activeId, binStep, amountX, weights);
2399
- for (const bin of amountsIntoAskSide) {
2400
- amountsInBin.push({
2401
- binId: bin.binId,
2402
- amountX: bin.amount,
2403
- amountY: new import_bn10.default(0)
2404
- });
2405
- }
2406
- }
2407
- }
2408
- return amountsInBin;
2214
+ case 1 /* Spot */: {
2215
+ const weights = toWeightSpotBalanced(minBinId, maxBinId);
2216
+ return toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights);
2217
+ }
2218
+ case 2 /* Curve */: {
2219
+ const weights = toWeightCurve(minBinId, maxBinId, activeId);
2220
+ return toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights);
2221
+ }
2222
+ case 3 /* BidAsk */: {
2223
+ const weights = toWeightBidAsk(minBinId, maxBinId, activeId);
2224
+ return toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights);
2409
2225
  }
2410
2226
  default:
2411
2227
  throw new Error(`Unsupported strategy type: ${strategyType}`);
@@ -2465,7 +2281,7 @@ function getCoinXYForLiquidity(liquidity, reserveInSize, reserveOutSize, lpSuply
2465
2281
  }
2466
2282
 
2467
2283
  // src/math/percentage.ts
2468
- var import_bn11 = __toESM(require("bn.js"));
2284
+ var import_bn10 = __toESM(require("bn.js"));
2469
2285
  var Percentage = class {
2470
2286
  numerator;
2471
2287
  denominator;
@@ -2493,8 +2309,8 @@ var Percentage = class {
2493
2309
  * @returns
2494
2310
  */
2495
2311
  static fromFraction(numerator, denominator) {
2496
- const num = typeof numerator === "number" ? new import_bn11.default(numerator.toString()) : numerator;
2497
- const denom = typeof denominator === "number" ? new import_bn11.default(denominator.toString()) : denominator;
2312
+ const num = typeof numerator === "number" ? new import_bn10.default(numerator.toString()) : numerator;
2313
+ const denom = typeof denominator === "number" ? new import_bn10.default(denominator.toString()) : denominator;
2498
2314
  return new Percentage(num, denom);
2499
2315
  }
2500
2316
  };
@@ -2594,7 +2410,7 @@ function adjustForCoinSlippage(tokenAmount, slippage, adjustUp) {
2594
2410
  }
2595
2411
 
2596
2412
  // src/math/SplitSwap.ts
2597
- var import_bn12 = __toESM(require("bn.js"));
2413
+ var import_bn11 = __toESM(require("bn.js"));
2598
2414
  var SplitUnit = /* @__PURE__ */ ((SplitUnit2) => {
2599
2415
  SplitUnit2[SplitUnit2["FIVE"] = 5] = "FIVE";
2600
2416
  SplitUnit2[SplitUnit2["TEN"] = 10] = "TEN";
@@ -2652,7 +2468,7 @@ function updateSplitSwapResult(maxIndex, currentIndex, splitSwapResult, stepResu
2652
2468
  return splitSwapResult;
2653
2469
  }
2654
2470
  function computeSplitSwap(a2b, byAmountIn, amounts, poolData, swapTicks) {
2655
- let currentLiquidity = new import_bn12.default(poolData.liquidity);
2471
+ let currentLiquidity = new import_bn11.default(poolData.liquidity);
2656
2472
  let { currentSqrtPrice } = poolData;
2657
2473
  let splitSwapResult = {
2658
2474
  amountInArray: [],
@@ -2715,7 +2531,7 @@ function computeSplitSwap(a2b, byAmountIn, amounts, poolData, swapTicks) {
2715
2531
  targetSqrtPrice,
2716
2532
  currentLiquidity,
2717
2533
  remainerAmount,
2718
- new import_bn12.default(poolData.feeRate),
2534
+ new import_bn11.default(poolData.feeRate),
2719
2535
  byAmountIn
2720
2536
  );
2721
2537
  tempStepResult = stepResult;
@@ -2727,7 +2543,7 @@ function computeSplitSwap(a2b, byAmountIn, amounts, poolData, swapTicks) {
2727
2543
  splitSwapResult.amountOutArray[i] = splitSwapResult.amountOutArray[i].add(stepResult.amountOut);
2728
2544
  splitSwapResult.feeAmountArray[i] = splitSwapResult.feeAmountArray[i].add(stepResult.feeAmount);
2729
2545
  if (stepResult.nextSqrtPrice.eq(tick.sqrtPrice)) {
2730
- signedLiquidityChange = a2b ? tick.liquidityNet.mul(new import_bn12.default(-1)) : tick.liquidityNet;
2546
+ signedLiquidityChange = a2b ? tick.liquidityNet.mul(new import_bn11.default(-1)) : tick.liquidityNet;
2731
2547
  currentLiquidity = signedLiquidityChange.gt(ZERO) ? currentLiquidity.add(signedLiquidityChange) : currentLiquidity.sub(signedLiquidityChange.abs());
2732
2548
  currentSqrtPrice = tick.sqrtPrice;
2733
2549
  } else {
@@ -2752,7 +2568,7 @@ function computeSplitSwap(a2b, byAmountIn, amounts, poolData, swapTicks) {
2752
2568
  break;
2753
2569
  }
2754
2570
  if (tempStepResult.nextSqrtPrice.eq(tick.sqrtPrice)) {
2755
- signedLiquidityChange = a2b ? tick.liquidityNet.mul(new import_bn12.default(-1)) : tick.liquidityNet;
2571
+ signedLiquidityChange = a2b ? tick.liquidityNet.mul(new import_bn11.default(-1)) : tick.liquidityNet;
2756
2572
  currentLiquidity = signedLiquidityChange.gt(ZERO) ? currentLiquidity.add(signedLiquidityChange) : currentLiquidity.sub(signedLiquidityChange.abs());
2757
2573
  currentSqrtPrice = tick.sqrtPrice;
2758
2574
  } else {
@@ -2977,7 +2793,7 @@ function buildPool(objects) {
2977
2793
  const rewarders = [];
2978
2794
  fields.rewarder_manager.fields.rewarders.forEach((item) => {
2979
2795
  const { emissions_per_second } = item.fields;
2980
- const emissionSeconds = MathUtil.fromX64(new import_bn13.default(emissions_per_second));
2796
+ const emissionSeconds = MathUtil.fromX64(new import_bn12.default(emissions_per_second));
2981
2797
  const emissionsEveryDay = Math.floor(emissionSeconds.toNumber() * 60 * 60 * 24);
2982
2798
  rewarders.push({
2983
2799
  emissions_per_second,
@@ -3169,11 +2985,11 @@ function buildTickData(objects) {
3169
2985
  const possition = {
3170
2986
  objectId: getObjectId(objects),
3171
2987
  index: asIntN(BigInt(valueItem.index.fields.bits)),
3172
- sqrtPrice: new import_bn13.default(valueItem.sqrt_price),
3173
- liquidityNet: new import_bn13.default(valueItem.liquidity_net.fields.bits),
3174
- liquidityGross: new import_bn13.default(valueItem.liquidity_gross),
3175
- feeGrowthOutsideA: new import_bn13.default(valueItem.fee_growth_outside_a),
3176
- feeGrowthOutsideB: new import_bn13.default(valueItem.fee_growth_outside_b),
2988
+ sqrtPrice: new import_bn12.default(valueItem.sqrt_price),
2989
+ liquidityNet: new import_bn12.default(valueItem.liquidity_net.fields.bits),
2990
+ liquidityGross: new import_bn12.default(valueItem.liquidity_gross),
2991
+ feeGrowthOutsideA: new import_bn12.default(valueItem.fee_growth_outside_a),
2992
+ feeGrowthOutsideB: new import_bn12.default(valueItem.fee_growth_outside_b),
3177
2993
  rewardersGrowthOutside: valueItem.rewards_growth_outside
3178
2994
  };
3179
2995
  return possition;
@@ -3183,11 +2999,11 @@ function buildTickDataByEvent(fields) {
3183
2999
  throw new ClmmpoolsError(`Invalid tick fields.`, "InvalidTickFields" /* InvalidTickFields */);
3184
3000
  }
3185
3001
  const index = asIntN(BigInt(fields.index.bits));
3186
- const sqrtPrice = new import_bn13.default(fields.sqrt_price);
3187
- const liquidityNet = new import_bn13.default(fields.liquidity_net.bits);
3188
- const liquidityGross = new import_bn13.default(fields.liquidity_gross);
3189
- const feeGrowthOutsideA = new import_bn13.default(fields.fee_growth_outside_a);
3190
- const feeGrowthOutsideB = new import_bn13.default(fields.fee_growth_outside_b);
3002
+ const sqrtPrice = new import_bn12.default(fields.sqrt_price);
3003
+ const liquidityNet = new import_bn12.default(fields.liquidity_net.bits);
3004
+ const liquidityGross = new import_bn12.default(fields.liquidity_gross);
3005
+ const feeGrowthOutsideA = new import_bn12.default(fields.fee_growth_outside_a);
3006
+ const feeGrowthOutsideB = new import_bn12.default(fields.fee_growth_outside_b);
3191
3007
  const rewardersGrowthOutside = fields.rewards_growth_outside || [];
3192
3008
  const tick = {
3193
3009
  objectId: "",
@@ -3206,7 +3022,7 @@ function buildClmmPositionName(pool_index, position_index) {
3206
3022
  }
3207
3023
 
3208
3024
  // src/utils/tick.ts
3209
- var import_bn14 = __toESM(require("bn.js"));
3025
+ var import_bn13 = __toESM(require("bn.js"));
3210
3026
  var TickUtil = class {
3211
3027
  /**
3212
3028
  * Get min tick index.
@@ -3246,22 +3062,22 @@ function getRewardInTickRange(pool, tickLower, tickUpper, tickLowerIndex, tickUp
3246
3062
  let rewarder_growth_below = growthGlobal[i];
3247
3063
  if (tickLower !== null) {
3248
3064
  if (pool.current_tick_index < tickLowerIndex) {
3249
- rewarder_growth_below = growthGlobal[i].sub(new import_bn14.default(tickLower.rewardersGrowthOutside[i]));
3065
+ rewarder_growth_below = growthGlobal[i].sub(new import_bn13.default(tickLower.rewardersGrowthOutside[i]));
3250
3066
  } else {
3251
3067
  rewarder_growth_below = tickLower.rewardersGrowthOutside[i];
3252
3068
  }
3253
3069
  }
3254
- let rewarder_growth_above = new import_bn14.default(0);
3070
+ let rewarder_growth_above = new import_bn13.default(0);
3255
3071
  if (tickUpper !== null) {
3256
3072
  if (pool.current_tick_index >= tickUpperIndex) {
3257
- rewarder_growth_above = growthGlobal[i].sub(new import_bn14.default(tickUpper.rewardersGrowthOutside[i]));
3073
+ rewarder_growth_above = growthGlobal[i].sub(new import_bn13.default(tickUpper.rewardersGrowthOutside[i]));
3258
3074
  } else {
3259
3075
  rewarder_growth_above = tickUpper.rewardersGrowthOutside[i];
3260
3076
  }
3261
3077
  }
3262
3078
  const rewGrowthInside = MathUtil.subUnderflowU128(
3263
- MathUtil.subUnderflowU128(new import_bn14.default(growthGlobal[i]), new import_bn14.default(rewarder_growth_below)),
3264
- new import_bn14.default(rewarder_growth_above)
3079
+ MathUtil.subUnderflowU128(new import_bn13.default(growthGlobal[i]), new import_bn13.default(rewarder_growth_below)),
3080
+ new import_bn13.default(rewarder_growth_above)
3265
3081
  );
3266
3082
  rewarderGrowthInside.push(rewGrowthInside);
3267
3083
  }
@@ -3269,7 +3085,7 @@ function getRewardInTickRange(pool, tickLower, tickUpper, tickLowerIndex, tickUp
3269
3085
  }
3270
3086
 
3271
3087
  // src/utils/transaction-util.ts
3272
- var import_bn15 = __toESM(require("bn.js"));
3088
+ var import_bn14 = __toESM(require("bn.js"));
3273
3089
  var import_decimal10 = __toESM(require("decimal.js"));
3274
3090
  var import_transactions = require("@mysten/sui/transactions");
3275
3091
  function findAdjustCoin(coinPair) {
@@ -3578,7 +3394,7 @@ var _TransactionUtil = class {
3578
3394
  const liquidityInput = ClmmPoolUtil.estLiquidityAndcoinAmountFromOneAmounts(
3579
3395
  Number(params.tick_lower),
3580
3396
  Number(params.tick_upper),
3581
- new import_bn15.default(coinAmount),
3397
+ new import_bn14.default(coinAmount),
3582
3398
  params.fix_amount_a,
3583
3399
  true,
3584
3400
  slippage,
@@ -4646,7 +4462,7 @@ var _TransactionUtil = class {
4646
4462
  const basePath = splitPath.basePaths[i];
4647
4463
  a2b.push(basePath.direction);
4648
4464
  poolAddress.push(basePath.poolAddress);
4649
- rawAmountLimit.push(new import_bn15.default(basePath.inputAmount.toString()));
4465
+ rawAmountLimit.push(new import_bn14.default(basePath.inputAmount.toString()));
4650
4466
  if (i === 0) {
4651
4467
  coinType.push(basePath.fromCoin, basePath.toCoin);
4652
4468
  } else {
@@ -4654,8 +4470,8 @@ var _TransactionUtil = class {
4654
4470
  }
4655
4471
  }
4656
4472
  const onePath = {
4657
- amountIn: new import_bn15.default(splitPath.inputAmount.toString()),
4658
- amountOut: new import_bn15.default(splitPath.outputAmount.toString()),
4473
+ amountIn: new import_bn14.default(splitPath.inputAmount.toString()),
4474
+ amountOut: new import_bn14.default(splitPath.outputAmount.toString()),
4659
4475
  poolAddress,
4660
4476
  a2b,
4661
4477
  rawAmountLimit,
@@ -5012,9 +4828,9 @@ var TxBlock = class {
5012
4828
  };
5013
4829
 
5014
4830
  // src/utils/deepbook-utils.ts
5015
- var import_bn16 = __toESM(require("bn.js"));
4831
+ var import_bn15 = __toESM(require("bn.js"));
5016
4832
  var import_transactions3 = require("@mysten/sui/transactions");
5017
- var FLOAT_SCALING = new import_bn16.default(1e9);
4833
+ var FLOAT_SCALING = new import_bn15.default(1e9);
5018
4834
  var DeepbookUtils = class {
5019
4835
  static createAccountCap(senderAddress, sdkOptions, tx, isTransfer = false) {
5020
4836
  if (senderAddress.length === 0) {
@@ -5160,9 +4976,9 @@ var DeepbookUtils = class {
5160
4976
  static async preSwap(sdk, pool, a2b, amountIn) {
5161
4977
  let isExceed = false;
5162
4978
  let amountOut = ZERO;
5163
- let remainAmount = new import_bn16.default(amountIn);
4979
+ let remainAmount = new import_bn15.default(amountIn);
5164
4980
  let feeAmount = ZERO;
5165
- const initAmountIn = new import_bn16.default(amountIn);
4981
+ const initAmountIn = new import_bn15.default(amountIn);
5166
4982
  if (a2b) {
5167
4983
  let bids = await this.getPoolBids(sdk, pool.poolID, pool.baseAsset, pool.quoteAsset);
5168
4984
  if (bids === null) {
@@ -5172,16 +4988,16 @@ var DeepbookUtils = class {
5172
4988
  return b.price - a.price;
5173
4989
  });
5174
4990
  for (let i = 0; i < bids.length; i += 1) {
5175
- const curBidAmount = new import_bn16.default(bids[i].quantity);
5176
- const curBidPrice = new import_bn16.default(bids[i].price);
5177
- const fee = curBidAmount.mul(new import_bn16.default(curBidPrice)).mul(new import_bn16.default(pool.takerFeeRate)).div(FLOAT_SCALING).div(FLOAT_SCALING);
4991
+ const curBidAmount = new import_bn15.default(bids[i].quantity);
4992
+ const curBidPrice = new import_bn15.default(bids[i].price);
4993
+ const fee = curBidAmount.mul(new import_bn15.default(curBidPrice)).mul(new import_bn15.default(pool.takerFeeRate)).div(FLOAT_SCALING).div(FLOAT_SCALING);
5178
4994
  if (remainAmount.gt(curBidAmount)) {
5179
4995
  remainAmount = remainAmount.sub(curBidAmount);
5180
4996
  amountOut = amountOut.add(curBidAmount.mul(curBidPrice).div(FLOAT_SCALING).sub(fee));
5181
4997
  feeAmount = feeAmount.add(fee);
5182
4998
  } else {
5183
- const curOut = remainAmount.mul(new import_bn16.default(bids[i].price)).div(FLOAT_SCALING);
5184
- const curFee = curOut.mul(new import_bn16.default(pool.takerFeeRate)).div(FLOAT_SCALING);
4999
+ const curOut = remainAmount.mul(new import_bn15.default(bids[i].price)).div(FLOAT_SCALING);
5000
+ const curFee = curOut.mul(new import_bn15.default(pool.takerFeeRate)).div(FLOAT_SCALING);
5185
5001
  amountOut = amountOut.add(curOut.sub(curFee));
5186
5002
  remainAmount = remainAmount.sub(remainAmount);
5187
5003
  feeAmount = feeAmount.add(curFee);
@@ -5196,15 +5012,15 @@ var DeepbookUtils = class {
5196
5012
  isExceed = true;
5197
5013
  }
5198
5014
  for (let i = 0; i < asks.length; i += 1) {
5199
- const curAskAmount = new import_bn16.default(asks[i].price).mul(new import_bn16.default(asks[i].quantity)).div(new import_bn16.default(1e9));
5200
- const fee = curAskAmount.mul(new import_bn16.default(pool.takerFeeRate)).div(FLOAT_SCALING);
5015
+ const curAskAmount = new import_bn15.default(asks[i].price).mul(new import_bn15.default(asks[i].quantity)).div(new import_bn15.default(1e9));
5016
+ const fee = curAskAmount.mul(new import_bn15.default(pool.takerFeeRate)).div(FLOAT_SCALING);
5201
5017
  const curAskAmountWithFee = curAskAmount.add(fee);
5202
5018
  if (remainAmount.gt(curAskAmount)) {
5203
- amountOut = amountOut.add(new import_bn16.default(asks[i].quantity));
5019
+ amountOut = amountOut.add(new import_bn15.default(asks[i].quantity));
5204
5020
  remainAmount = remainAmount.sub(curAskAmountWithFee);
5205
5021
  feeAmount = feeAmount.add(fee);
5206
5022
  } else {
5207
- const splitNums = new import_bn16.default(asks[i].quantity).div(new import_bn16.default(pool.lotSize));
5023
+ const splitNums = new import_bn15.default(asks[i].quantity).div(new import_bn15.default(pool.lotSize));
5208
5024
  const splitAmount = curAskAmountWithFee.div(splitNums);
5209
5025
  const swapSplitNum = remainAmount.div(splitAmount);
5210
5026
  amountOut = amountOut.add(swapSplitNum.muln(pool.lotSize));
@@ -6065,7 +5881,7 @@ var PoolModule = class {
6065
5881
  };
6066
5882
 
6067
5883
  // src/modules/positionModule.ts
6068
- var import_bn17 = __toESM(require("bn.js"));
5884
+ var import_bn16 = __toESM(require("bn.js"));
6069
5885
  var import_transactions5 = require("@mysten/sui/transactions");
6070
5886
  var import_utils15 = require("@mysten/sui/utils");
6071
5887
  var PositionModule = class {
@@ -6287,8 +6103,8 @@ var PositionModule = class {
6287
6103
  for (let i = 0; i < valueData.length; i += 1) {
6288
6104
  const { parsedJson } = valueData[i];
6289
6105
  const posRrewarderResult = {
6290
- feeOwedA: new import_bn17.default(parsedJson.fee_owned_a),
6291
- feeOwedB: new import_bn17.default(parsedJson.fee_owned_b),
6106
+ feeOwedA: new import_bn16.default(parsedJson.fee_owned_a),
6107
+ feeOwedB: new import_bn16.default(parsedJson.fee_owned_b),
6292
6108
  position_id: parsedJson.position_id
6293
6109
  };
6294
6110
  result.push(posRrewarderResult);
@@ -6664,7 +6480,7 @@ var PositionModule = class {
6664
6480
  };
6665
6481
 
6666
6482
  // src/modules/rewarderModule.ts
6667
- var import_bn18 = __toESM(require("bn.js"));
6483
+ var import_bn17 = __toESM(require("bn.js"));
6668
6484
  var import_transactions6 = require("@mysten/sui/transactions");
6669
6485
  var RewarderModule = class {
6670
6486
  _sdk;
@@ -6690,7 +6506,7 @@ var RewarderModule = class {
6690
6506
  }
6691
6507
  const emissionsEveryDay = [];
6692
6508
  for (const rewarderInfo of rewarderInfos) {
6693
- const emissionSeconds = MathUtil.fromX64(new import_bn18.default(rewarderInfo.emissions_per_second));
6509
+ const emissionSeconds = MathUtil.fromX64(new import_bn17.default(rewarderInfo.emissions_per_second));
6694
6510
  emissionsEveryDay.push({
6695
6511
  emissions: Math.floor(emissionSeconds.toNumber() * 60 * 60 * 24),
6696
6512
  coin_address: rewarderInfo.coinAddress
@@ -6709,20 +6525,20 @@ var RewarderModule = class {
6709
6525
  const currentPool = await this.sdk.Pool.getPool(poolID);
6710
6526
  const lastTime = currentPool.rewarder_last_updated_time;
6711
6527
  currentPool.rewarder_last_updated_time = currentTime.toString();
6712
- if (Number(currentPool.liquidity) === 0 || currentTime.eq(new import_bn18.default(lastTime))) {
6528
+ if (Number(currentPool.liquidity) === 0 || currentTime.eq(new import_bn17.default(lastTime))) {
6713
6529
  return currentPool;
6714
6530
  }
6715
- const timeDelta = currentTime.div(new import_bn18.default(1e3)).sub(new import_bn18.default(lastTime)).add(new import_bn18.default(15));
6531
+ const timeDelta = currentTime.div(new import_bn17.default(1e3)).sub(new import_bn17.default(lastTime)).add(new import_bn17.default(15));
6716
6532
  const rewarderInfos = currentPool.rewarder_infos;
6717
6533
  for (let i = 0; i < rewarderInfos.length; i += 1) {
6718
6534
  const rewarderInfo = rewarderInfos[i];
6719
6535
  const rewarderGrowthDelta = MathUtil.checkMulDivFloor(
6720
6536
  timeDelta,
6721
- new import_bn18.default(rewarderInfo.emissions_per_second),
6722
- new import_bn18.default(currentPool.liquidity),
6537
+ new import_bn17.default(rewarderInfo.emissions_per_second),
6538
+ new import_bn17.default(currentPool.liquidity),
6723
6539
  128
6724
6540
  );
6725
- this.growthGlobal[i] = new import_bn18.default(rewarderInfo.growth_global).add(new import_bn18.default(rewarderGrowthDelta));
6541
+ this.growthGlobal[i] = new import_bn17.default(rewarderInfo.growth_global).add(new import_bn17.default(rewarderGrowthDelta));
6726
6542
  }
6727
6543
  return currentPool;
6728
6544
  }
@@ -6737,7 +6553,7 @@ var RewarderModule = class {
6737
6553
  */
6738
6554
  async posRewardersAmount(poolID, positionHandle, positionID) {
6739
6555
  const currentTime = Date.parse((/* @__PURE__ */ new Date()).toString());
6740
- const pool = await this.updatePoolRewarder(poolID, new import_bn18.default(currentTime));
6556
+ const pool = await this.updatePoolRewarder(poolID, new import_bn17.default(currentTime));
6741
6557
  const position = await this.sdk.Position.getPositionRewarders(positionHandle, positionID);
6742
6558
  if (position === void 0) {
6743
6559
  return [];
@@ -6758,7 +6574,7 @@ var RewarderModule = class {
6758
6574
  */
6759
6575
  async poolRewardersAmount(accountAddress, poolID) {
6760
6576
  const currentTime = Date.parse((/* @__PURE__ */ new Date()).toString());
6761
- const pool = await this.updatePoolRewarder(poolID, new import_bn18.default(currentTime));
6577
+ const pool = await this.updatePoolRewarder(poolID, new import_bn17.default(currentTime));
6762
6578
  const positions = await this.sdk.Position.getPositionList(accountAddress, [poolID]);
6763
6579
  const tickDatas = await this.getPoolLowerAndUpperTicks(pool.ticks_handle, positions);
6764
6580
  const rewarderAmount = [ZERO, ZERO, ZERO];
@@ -6785,38 +6601,38 @@ var RewarderModule = class {
6785
6601
  const growthInside = [];
6786
6602
  const AmountOwed = [];
6787
6603
  if (rewardersInside.length > 0) {
6788
- let growthDelta0 = MathUtil.subUnderflowU128(rewardersInside[0], new import_bn18.default(position.reward_growth_inside_0));
6789
- if (growthDelta0.gt(new import_bn18.default("3402823669209384634633745948738404"))) {
6604
+ let growthDelta0 = MathUtil.subUnderflowU128(rewardersInside[0], new import_bn17.default(position.reward_growth_inside_0));
6605
+ if (growthDelta0.gt(new import_bn17.default("3402823669209384634633745948738404"))) {
6790
6606
  growthDelta0 = ONE;
6791
6607
  }
6792
- const amountOwed_0 = MathUtil.checkMulShiftRight(new import_bn18.default(position.liquidity), growthDelta0, 64, 128);
6608
+ const amountOwed_0 = MathUtil.checkMulShiftRight(new import_bn17.default(position.liquidity), growthDelta0, 64, 128);
6793
6609
  growthInside.push(rewardersInside[0]);
6794
6610
  AmountOwed.push({
6795
- amount_owed: new import_bn18.default(position.reward_amount_owed_0).add(amountOwed_0),
6611
+ amount_owed: new import_bn17.default(position.reward_amount_owed_0).add(amountOwed_0),
6796
6612
  coin_address: pool.rewarder_infos[0].coinAddress
6797
6613
  });
6798
6614
  }
6799
6615
  if (rewardersInside.length > 1) {
6800
- let growthDelta_1 = MathUtil.subUnderflowU128(rewardersInside[1], new import_bn18.default(position.reward_growth_inside_1));
6801
- if (growthDelta_1.gt(new import_bn18.default("3402823669209384634633745948738404"))) {
6616
+ let growthDelta_1 = MathUtil.subUnderflowU128(rewardersInside[1], new import_bn17.default(position.reward_growth_inside_1));
6617
+ if (growthDelta_1.gt(new import_bn17.default("3402823669209384634633745948738404"))) {
6802
6618
  growthDelta_1 = ONE;
6803
6619
  }
6804
- const amountOwed_1 = MathUtil.checkMulShiftRight(new import_bn18.default(position.liquidity), growthDelta_1, 64, 128);
6620
+ const amountOwed_1 = MathUtil.checkMulShiftRight(new import_bn17.default(position.liquidity), growthDelta_1, 64, 128);
6805
6621
  growthInside.push(rewardersInside[1]);
6806
6622
  AmountOwed.push({
6807
- amount_owed: new import_bn18.default(position.reward_amount_owed_1).add(amountOwed_1),
6623
+ amount_owed: new import_bn17.default(position.reward_amount_owed_1).add(amountOwed_1),
6808
6624
  coin_address: pool.rewarder_infos[1].coinAddress
6809
6625
  });
6810
6626
  }
6811
6627
  if (rewardersInside.length > 2) {
6812
- let growthDelta_2 = MathUtil.subUnderflowU128(rewardersInside[2], new import_bn18.default(position.reward_growth_inside_2));
6813
- if (growthDelta_2.gt(new import_bn18.default("3402823669209384634633745948738404"))) {
6628
+ let growthDelta_2 = MathUtil.subUnderflowU128(rewardersInside[2], new import_bn17.default(position.reward_growth_inside_2));
6629
+ if (growthDelta_2.gt(new import_bn17.default("3402823669209384634633745948738404"))) {
6814
6630
  growthDelta_2 = ONE;
6815
6631
  }
6816
- const amountOwed_2 = MathUtil.checkMulShiftRight(new import_bn18.default(position.liquidity), growthDelta_2, 64, 128);
6632
+ const amountOwed_2 = MathUtil.checkMulShiftRight(new import_bn17.default(position.liquidity), growthDelta_2, 64, 128);
6817
6633
  growthInside.push(rewardersInside[2]);
6818
6634
  AmountOwed.push({
6819
- amount_owed: new import_bn18.default(position.reward_amount_owed_2).add(amountOwed_2),
6635
+ amount_owed: new import_bn17.default(position.reward_amount_owed_2).add(amountOwed_2),
6820
6636
  coin_address: pool.rewarder_infos[2].coinAddress
6821
6637
  });
6822
6638
  }
@@ -6930,8 +6746,8 @@ var RewarderModule = class {
6930
6746
  for (let i = 0; i < valueData.length; i += 1) {
6931
6747
  const { parsedJson } = valueData[i];
6932
6748
  const posRrewarderResult = {
6933
- feeOwedA: new import_bn18.default(parsedJson.fee_owned_a),
6934
- feeOwedB: new import_bn18.default(parsedJson.fee_owned_b),
6749
+ feeOwedA: new import_bn17.default(parsedJson.fee_owned_a),
6750
+ feeOwedB: new import_bn17.default(parsedJson.fee_owned_b),
6935
6751
  position_id: parsedJson.position_id
6936
6752
  };
6937
6753
  result.push(posRrewarderResult);
@@ -6994,7 +6810,7 @@ var RewarderModule = class {
6994
6810
  };
6995
6811
  for (let j = 0; j < params[i].rewarderInfo.length; j += 1) {
6996
6812
  posRrewarderResult.rewarderAmountOwed.push({
6997
- amount_owed: new import_bn18.default(valueData[i].parsedJson.data[j]),
6813
+ amount_owed: new import_bn17.default(valueData[i].parsedJson.data[j]),
6998
6814
  coin_address: params[i].rewarderInfo[j].coinAddress
6999
6815
  });
7000
6816
  }
@@ -7183,7 +6999,7 @@ var RewarderModule = class {
7183
6999
  };
7184
7000
 
7185
7001
  // src/modules/routerModule.ts
7186
- var import_bn19 = __toESM(require("bn.js"));
7002
+ var import_bn18 = __toESM(require("bn.js"));
7187
7003
  var import_cc_graph = require("@syntsugar/cc-graph");
7188
7004
  var import_transactions7 = require("@mysten/sui/transactions");
7189
7005
  function _pairSymbol(base, quote) {
@@ -7465,8 +7281,8 @@ var RouterModule = class {
7465
7281
  if (swapWithMultiPoolParams != null) {
7466
7282
  const preSwapResult2 = await this.sdk.Swap.preSwapWithMultiPool(swapWithMultiPoolParams);
7467
7283
  const onePath2 = {
7468
- amountIn: new import_bn19.default(preSwapResult2.estimatedAmountIn),
7469
- amountOut: new import_bn19.default(preSwapResult2.estimatedAmountOut),
7284
+ amountIn: new import_bn18.default(preSwapResult2.estimatedAmountIn),
7285
+ amountOut: new import_bn18.default(preSwapResult2.estimatedAmountOut),
7470
7286
  poolAddress: [preSwapResult2.poolAddress],
7471
7287
  a2b: [preSwapResult2.aToB],
7472
7288
  rawAmountLimit: byAmountIn ? [preSwapResult2.estimatedAmountOut] : [preSwapResult2.estimatedAmountIn],
@@ -7479,8 +7295,8 @@ var RouterModule = class {
7479
7295
  priceSlippagePoint
7480
7296
  };
7481
7297
  const result2 = {
7482
- amountIn: new import_bn19.default(preSwapResult2.estimatedAmountIn),
7483
- amountOut: new import_bn19.default(preSwapResult2.estimatedAmountOut),
7298
+ amountIn: new import_bn18.default(preSwapResult2.estimatedAmountIn),
7299
+ amountOut: new import_bn18.default(preSwapResult2.estimatedAmountOut),
7484
7300
  paths: [onePath2],
7485
7301
  a2b: preSwapResult2.aToB,
7486
7302
  b2c: void 0,
@@ -7502,8 +7318,8 @@ var RouterModule = class {
7502
7318
  if (swapWithMultiPoolParams != null) {
7503
7319
  const preSwapResult2 = await this.sdk.Swap.preSwapWithMultiPool(swapWithMultiPoolParams);
7504
7320
  const onePath2 = {
7505
- amountIn: new import_bn19.default(preSwapResult2.estimatedAmountIn),
7506
- amountOut: new import_bn19.default(preSwapResult2.estimatedAmountOut),
7321
+ amountIn: new import_bn18.default(preSwapResult2.estimatedAmountIn),
7322
+ amountOut: new import_bn18.default(preSwapResult2.estimatedAmountOut),
7507
7323
  poolAddress: [preSwapResult2.poolAddress],
7508
7324
  a2b: [preSwapResult2.aToB],
7509
7325
  rawAmountLimit: byAmountIn ? [preSwapResult2.estimatedAmountOut] : [preSwapResult2.estimatedAmountIn],
@@ -7516,8 +7332,8 @@ var RouterModule = class {
7516
7332
  priceSlippagePoint
7517
7333
  };
7518
7334
  const result3 = {
7519
- amountIn: new import_bn19.default(preSwapResult2.estimatedAmountIn),
7520
- amountOut: new import_bn19.default(preSwapResult2.estimatedAmountOut),
7335
+ amountIn: new import_bn18.default(preSwapResult2.estimatedAmountIn),
7336
+ amountOut: new import_bn18.default(preSwapResult2.estimatedAmountOut),
7521
7337
  paths: [onePath2],
7522
7338
  a2b: preSwapResult2.aToB,
7523
7339
  b2c: void 0,
@@ -7598,8 +7414,8 @@ var RouterModule = class {
7598
7414
  if (swapWithMultiPoolParams != null) {
7599
7415
  const preSwapResult = await this.sdk.Swap.preSwapWithMultiPool(swapWithMultiPoolParams);
7600
7416
  const onePath = {
7601
- amountIn: new import_bn19.default(preSwapResult.estimatedAmountIn),
7602
- amountOut: new import_bn19.default(preSwapResult.estimatedAmountOut),
7417
+ amountIn: new import_bn18.default(preSwapResult.estimatedAmountIn),
7418
+ amountOut: new import_bn18.default(preSwapResult.estimatedAmountOut),
7603
7419
  poolAddress: [preSwapResult.poolAddress],
7604
7420
  a2b: [preSwapResult.aToB],
7605
7421
  rawAmountLimit: byAmountIn ? [preSwapResult.estimatedAmountOut] : [preSwapResult.estimatedAmountIn],
@@ -7612,8 +7428,8 @@ var RouterModule = class {
7612
7428
  priceSlippagePoint
7613
7429
  };
7614
7430
  const result = {
7615
- amountIn: new import_bn19.default(preSwapResult.estimatedAmountIn),
7616
- amountOut: new import_bn19.default(preSwapResult.estimatedAmountOut),
7431
+ amountIn: new import_bn18.default(preSwapResult.estimatedAmountIn),
7432
+ amountOut: new import_bn18.default(preSwapResult.estimatedAmountOut),
7617
7433
  paths: [onePath],
7618
7434
  a2b: preSwapResult.aToB,
7619
7435
  b2c: void 0,
@@ -7697,13 +7513,13 @@ var RouterModule = class {
7697
7513
  continue;
7698
7514
  }
7699
7515
  if (params[0].byAmountIn) {
7700
- const amount = new import_bn19.default(valueData[i].parsedJson.data.amount_out);
7516
+ const amount = new import_bn18.default(valueData[i].parsedJson.data.amount_out);
7701
7517
  if (amount.gt(tempMaxAmount)) {
7702
7518
  tempIndex = i;
7703
7519
  tempMaxAmount = amount;
7704
7520
  }
7705
7521
  } else {
7706
- const amount = params[i].stepNums > 1 ? new import_bn19.default(valueData[i].parsedJson.data.amount_in) : new import_bn19.default(valueData[i].parsedJson.data.amount_in).add(new import_bn19.default(valueData[i].parsedJson.data.fee_amount));
7522
+ const amount = params[i].stepNums > 1 ? new import_bn18.default(valueData[i].parsedJson.data.amount_in) : new import_bn18.default(valueData[i].parsedJson.data.amount_in).add(new import_bn18.default(valueData[i].parsedJson.data.fee_amount));
7707
7523
  if (amount.lt(tempMaxAmount)) {
7708
7524
  tempIndex = i;
7709
7525
  tempMaxAmount = amount;
@@ -7773,7 +7589,7 @@ var RouterModule = class {
7773
7589
  };
7774
7590
 
7775
7591
  // src/modules/swapModule.ts
7776
- var import_bn20 = __toESM(require("bn.js"));
7592
+ var import_bn19 = __toESM(require("bn.js"));
7777
7593
  var import_decimal11 = __toESM(require("decimal.js"));
7778
7594
  var import_transactions8 = require("@mysten/sui/transactions");
7779
7595
  var AMM_SWAP_MODULE = "amm_swap";
@@ -7889,13 +7705,13 @@ var SwapModule = class {
7889
7705
  continue;
7890
7706
  }
7891
7707
  if (params.byAmountIn) {
7892
- const amount = new import_bn20.default(valueData[i].parsedJson.data.amount_out);
7708
+ const amount = new import_bn19.default(valueData[i].parsedJson.data.amount_out);
7893
7709
  if (amount.gt(tempMaxAmount)) {
7894
7710
  tempIndex = i;
7895
7711
  tempMaxAmount = amount;
7896
7712
  }
7897
7713
  } else {
7898
- const amount = new import_bn20.default(valueData[i].parsedJson.data.amount_out);
7714
+ const amount = new import_bn19.default(valueData[i].parsedJson.data.amount_out);
7899
7715
  if (amount.lt(tempMaxAmount)) {
7900
7716
  tempIndex = i;
7901
7717
  tempMaxAmount = amount;
@@ -7959,7 +7775,7 @@ var SwapModule = class {
7959
7775
  return this.transformSwapData(params, valueData[0].parsedJson.data);
7960
7776
  }
7961
7777
  transformSwapData(params, data) {
7962
- const estimatedAmountIn = data.amount_in && data.fee_amount ? new import_bn20.default(data.amount_in).add(new import_bn20.default(data.fee_amount)).toString() : "";
7778
+ const estimatedAmountIn = data.amount_in && data.fee_amount ? new import_bn19.default(data.amount_in).add(new import_bn19.default(data.fee_amount)).toString() : "";
7963
7779
  return {
7964
7780
  poolAddress: params.pool.poolAddress,
7965
7781
  currentSqrtPrice: params.currentSqrtPrice,
@@ -7976,7 +7792,7 @@ var SwapModule = class {
7976
7792
  transformSwapWithMultiPoolData(params, jsonData) {
7977
7793
  const { data } = jsonData;
7978
7794
  console.log("json data. ", data);
7979
- const estimatedAmountIn = data.amount_in && data.fee_amount ? new import_bn20.default(data.amount_in).add(new import_bn20.default(data.fee_amount)).toString() : "";
7795
+ const estimatedAmountIn = data.amount_in && data.fee_amount ? new import_bn19.default(data.amount_in).add(new import_bn19.default(data.fee_amount)).toString() : "";
7980
7796
  return {
7981
7797
  poolAddress: params.poolAddress,
7982
7798
  estimatedAmountIn,
@@ -9489,7 +9305,7 @@ var TokenModule = class {
9489
9305
  };
9490
9306
 
9491
9307
  // src/modules/routerModuleV2.ts
9492
- var import_bn21 = __toESM(require("bn.js"));
9308
+ var import_bn20 = __toESM(require("bn.js"));
9493
9309
  var import_decimal12 = __toESM(require("decimal.js"));
9494
9310
  var import_uuid = require("uuid");
9495
9311
  var import_axios = __toESM(require("axios"));
@@ -9533,12 +9349,12 @@ var RouterModuleV2 = class {
9533
9349
  outputAmount: basePath.output_amount,
9534
9350
  inputAmount: basePath.input_amount,
9535
9351
  feeRate: basePath.fee_rate,
9536
- currentSqrtPrice: new import_bn21.default(basePath.current_sqrt_price.toString()),
9537
- afterSqrtPrice: basePath.label === "Magma" ? new import_bn21.default(basePath.after_sqrt_price.toString()) : ZERO,
9352
+ currentSqrtPrice: new import_bn20.default(basePath.current_sqrt_price.toString()),
9353
+ afterSqrtPrice: basePath.label === "Magma" ? new import_bn20.default(basePath.after_sqrt_price.toString()) : ZERO,
9538
9354
  fromDecimal: basePath.from_decimal,
9539
9355
  toDecimal: basePath.to_decimal,
9540
9356
  currentPrice: this.calculatePrice(
9541
- new import_bn21.default(basePath.current_sqrt_price.toString()),
9357
+ new import_bn20.default(basePath.current_sqrt_price.toString()),
9542
9358
  basePath.from_decimal,
9543
9359
  basePath.to_decimal,
9544
9360
  basePath.direction,
@@ -9621,7 +9437,7 @@ var RouterModuleV2 = class {
9621
9437
  const priceResult = await this.sdk.Router.priceUseV1(
9622
9438
  from,
9623
9439
  to,
9624
- new import_bn21.default(amount),
9440
+ new import_bn20.default(amount),
9625
9441
  byAmountIn,
9626
9442
  priceSplitPoint,
9627
9443
  partner,
@@ -9633,7 +9449,7 @@ var RouterModuleV2 = class {
9633
9449
  if (path.poolAddress.length > 1) {
9634
9450
  const fromDecimal0 = this.sdk.Router.tokenInfo(path.coinType[0]).decimals;
9635
9451
  const toDecimal0 = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
9636
- const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new import_bn21.default(priceResult.currentSqrtPrice[0]), fromDecimal0, toDecimal0) : TickMath.sqrtPriceX64ToPrice(new import_bn21.default(priceResult.currentSqrtPrice[0]), toDecimal0, fromDecimal0);
9452
+ const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new import_bn20.default(priceResult.currentSqrtPrice[0]), fromDecimal0, toDecimal0) : TickMath.sqrtPriceX64ToPrice(new import_bn20.default(priceResult.currentSqrtPrice[0]), toDecimal0, fromDecimal0);
9637
9453
  const path0 = {
9638
9454
  direction: path.a2b[0],
9639
9455
  label: "Magma",
@@ -9650,7 +9466,7 @@ var RouterModuleV2 = class {
9650
9466
  };
9651
9467
  const fromDecimal1 = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
9652
9468
  const toDecimal1 = this.sdk.Router.tokenInfo(path.coinType[2]).decimals;
9653
- const currentPrice1 = path.a2b[1] ? TickMath.sqrtPriceX64ToPrice(new import_bn21.default(priceResult.currentSqrtPrice[1]), fromDecimal1, toDecimal1) : TickMath.sqrtPriceX64ToPrice(new import_bn21.default(priceResult.currentSqrtPrice[1]), toDecimal1, fromDecimal1);
9469
+ const currentPrice1 = path.a2b[1] ? TickMath.sqrtPriceX64ToPrice(new import_bn20.default(priceResult.currentSqrtPrice[1]), fromDecimal1, toDecimal1) : TickMath.sqrtPriceX64ToPrice(new import_bn20.default(priceResult.currentSqrtPrice[1]), toDecimal1, fromDecimal1);
9654
9470
  const path1 = {
9655
9471
  direction: path.a2b[1],
9656
9472
  label: "Magma",
@@ -9669,7 +9485,7 @@ var RouterModuleV2 = class {
9669
9485
  } else {
9670
9486
  const fromDecimal = this.sdk.Router.tokenInfo(path.coinType[0]).decimals;
9671
9487
  const toDecimal = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
9672
- const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new import_bn21.default(priceResult.currentSqrtPrice[0]), fromDecimal, toDecimal) : TickMath.sqrtPriceX64ToPrice(new import_bn21.default(priceResult.currentSqrtPrice[0]), toDecimal, fromDecimal);
9488
+ const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new import_bn20.default(priceResult.currentSqrtPrice[0]), fromDecimal, toDecimal) : TickMath.sqrtPriceX64ToPrice(new import_bn20.default(priceResult.currentSqrtPrice[0]), toDecimal, fromDecimal);
9673
9489
  const path0 = {
9674
9490
  direction: path.a2b[0],
9675
9491
  label: "Magma",
@@ -9754,7 +9570,7 @@ var RouterModuleV2 = class {
9754
9570
  const priceResult = await this.sdk.Router.priceUseV1(
9755
9571
  from,
9756
9572
  to,
9757
- new import_bn21.default(amount),
9573
+ new import_bn20.default(amount),
9758
9574
  byAmountIn,
9759
9575
  priceSplitPoint,
9760
9576
  partner,
@@ -9766,7 +9582,7 @@ var RouterModuleV2 = class {
9766
9582
  if (path.poolAddress.length > 1) {
9767
9583
  const fromDecimal0 = this.sdk.Router.tokenInfo(path.coinType[0]).decimals;
9768
9584
  const toDecimal0 = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
9769
- const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new import_bn21.default(priceResult.currentSqrtPrice[0]), fromDecimal0, toDecimal0) : TickMath.sqrtPriceX64ToPrice(new import_bn21.default(priceResult.currentSqrtPrice[0]), toDecimal0, fromDecimal0);
9585
+ const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new import_bn20.default(priceResult.currentSqrtPrice[0]), fromDecimal0, toDecimal0) : TickMath.sqrtPriceX64ToPrice(new import_bn20.default(priceResult.currentSqrtPrice[0]), toDecimal0, fromDecimal0);
9770
9586
  const path0 = {
9771
9587
  direction: path.a2b[0],
9772
9588
  label: "Magma",
@@ -9783,7 +9599,7 @@ var RouterModuleV2 = class {
9783
9599
  };
9784
9600
  const fromDecimal1 = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
9785
9601
  const toDecimal1 = this.sdk.Router.tokenInfo(path.coinType[2]).decimals;
9786
- const currentPrice1 = path.a2b[1] ? TickMath.sqrtPriceX64ToPrice(new import_bn21.default(priceResult.currentSqrtPrice[1]), fromDecimal1, toDecimal1) : TickMath.sqrtPriceX64ToPrice(new import_bn21.default(priceResult.currentSqrtPrice[1]), toDecimal1, fromDecimal1);
9602
+ const currentPrice1 = path.a2b[1] ? TickMath.sqrtPriceX64ToPrice(new import_bn20.default(priceResult.currentSqrtPrice[1]), fromDecimal1, toDecimal1) : TickMath.sqrtPriceX64ToPrice(new import_bn20.default(priceResult.currentSqrtPrice[1]), toDecimal1, fromDecimal1);
9787
9603
  const path1 = {
9788
9604
  direction: path.a2b[1],
9789
9605
  label: "Magma",
@@ -9802,7 +9618,7 @@ var RouterModuleV2 = class {
9802
9618
  } else {
9803
9619
  const fromDecimal = this.sdk.Router.tokenInfo(path.coinType[0]).decimals;
9804
9620
  const toDecimal = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
9805
- const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new import_bn21.default(priceResult.currentSqrtPrice[0]), fromDecimal, toDecimal) : TickMath.sqrtPriceX64ToPrice(new import_bn21.default(priceResult.currentSqrtPrice[0]), toDecimal, fromDecimal);
9621
+ const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new import_bn20.default(priceResult.currentSqrtPrice[0]), fromDecimal, toDecimal) : TickMath.sqrtPriceX64ToPrice(new import_bn20.default(priceResult.currentSqrtPrice[0]), toDecimal, fromDecimal);
9806
9622
  const path0 = {
9807
9623
  direction: path.a2b[0],
9808
9624
  label: "Magma",
@@ -10823,10 +10639,11 @@ var DlmmModule = class {
10823
10639
  });
10824
10640
  return tx;
10825
10641
  }
10642
+ // async mintByStrategySingle(params: MintByStrategySingleParams): Promise<Transaction> {}
10826
10643
  async mintByStrategy(params) {
10827
10644
  const tx = new import_transactions12.Transaction();
10828
10645
  const slippage = new import_decimal13.default(params.slippage);
10829
- const lower_slippage = new import_decimal13.default(1).plus(slippage.div(new import_decimal13.default(1e4)));
10646
+ const lower_slippage = new import_decimal13.default(1).sub(slippage.div(new import_decimal13.default(1e4)));
10830
10647
  const upper_slippage = new import_decimal13.default(1).plus(slippage.div(new import_decimal13.default(1e4)));
10831
10648
  tx.setSender(this.sdk.senderAddress);
10832
10649
  const { dlmm_pool, integrate } = this.sdk.sdkOptions;
@@ -10843,13 +10660,13 @@ var DlmmModule = class {
10843
10660
  let amount_min = 0;
10844
10661
  let amount_max = 0;
10845
10662
  if (params.fixCoinA) {
10846
- amount_min = new import_decimal13.default(params.amountATotal).mul(lower_slippage).toDecimalPlaces(0).toNumber();
10847
- amount_max = new import_decimal13.default(params.amountATotal).mul(upper_slippage).toDecimalPlaces(0).toNumber();
10663
+ amount_min = new import_decimal13.default(params.amountBTotal).mul(lower_slippage).toDecimalPlaces(0).toNumber();
10664
+ amount_max = new import_decimal13.default(params.amountBTotal).mul(upper_slippage).toDecimalPlaces(0).toNumber();
10848
10665
  primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amount_max), params.coinTypeB, false, true);
10849
10666
  }
10850
10667
  if (params.fixCoinB) {
10851
- amount_min = new import_decimal13.default(params.amountBTotal).mul(lower_slippage).toDecimalPlaces(0).toNumber();
10852
- amount_max = new import_decimal13.default(params.amountBTotal).mul(upper_slippage).toDecimalPlaces(0).toNumber();
10668
+ amount_min = new import_decimal13.default(params.amountATotal).mul(lower_slippage).toDecimalPlaces(0).toNumber();
10669
+ amount_max = new import_decimal13.default(params.amountATotal).mul(upper_slippage).toDecimalPlaces(0).toNumber();
10853
10670
  primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amount_max), params.coinTypeB, false, true);
10854
10671
  }
10855
10672
  if (params.fixCoinA && params.fixCoinB) {
@@ -10866,8 +10683,8 @@ var DlmmModule = class {
10866
10683
  tx.pure.u64(params.amountATotal),
10867
10684
  tx.pure.u64(params.amountBTotal),
10868
10685
  tx.pure.u8(params.strategy),
10869
- tx.pure.u32(params.min_bin),
10870
- tx.pure.u32(params.max_bin),
10686
+ tx.pure.u32((0, import_calc_dlmm3.get_storage_id_from_real_id)(params.min_bin)),
10687
+ tx.pure.u32((0, import_calc_dlmm3.get_storage_id_from_real_id)(params.max_bin)),
10871
10688
  tx.pure.u32(active_min),
10872
10689
  tx.pure.u32(active_max),
10873
10690
  tx.pure.u64(amount_min),
@@ -10875,7 +10692,7 @@ var DlmmModule = class {
10875
10692
  tx.object(CLOCK_ADDRESS)
10876
10693
  ];
10877
10694
  tx.moveCall({
10878
- target: `${integrate.published_at}::${DlmmScript}::mint_percent`,
10695
+ target: `${integrate.published_at}::${DlmmScript}::mint_by_strategy`,
10879
10696
  typeArguments,
10880
10697
  arguments: args
10881
10698
  });
@@ -11097,7 +10914,8 @@ var DlmmModule = class {
11097
10914
  async createPairAddLiquidity(params) {
11098
10915
  const tx = new import_transactions12.Transaction();
11099
10916
  tx.setSender(this.sdk.senderAddress);
11100
- const { dlmm_pool, integrate } = this.sdk.sdkOptions;
10917
+ const { clmm_pool, dlmm_pool, integrate } = this.sdk.sdkOptions;
10918
+ const { global_config_id } = getPackagerConfigs(clmm_pool);
11101
10919
  const dlmmConfig = getPackagerConfigs(dlmm_pool);
11102
10920
  const typeArguments = [params.coinTypeA, params.coinTypeB];
11103
10921
  const allCoins = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress);
@@ -11105,14 +10923,19 @@ var DlmmModule = class {
11105
10923
  const amountBTotal = params.amountsY.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
11106
10924
  const primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amountATotal), params.coinTypeA, false, true);
11107
10925
  const primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amountBTotal), params.coinTypeB, false, true);
10926
+ const storageIds = [];
10927
+ params.realIds.forEach((i) => {
10928
+ storageIds.push((0, import_calc_dlmm3.get_storage_id_from_real_id)(i));
10929
+ });
11108
10930
  const args = [
11109
10931
  tx.object(dlmmConfig.factory),
10932
+ tx.object(global_config_id),
11110
10933
  tx.pure.u64(params.baseFee),
11111
10934
  tx.pure.u16(params.binStep),
11112
- tx.pure.u32(params.activeId),
10935
+ tx.pure.u32((0, import_calc_dlmm3.get_storage_id_from_real_id)(params.activeId)),
11113
10936
  primaryCoinAInputs.targetCoin,
11114
10937
  primaryCoinBInputs.targetCoin,
11115
- tx.pure.vector("u32", params.storageIds),
10938
+ tx.pure.vector("u32", storageIds),
11116
10939
  tx.pure.vector("u64", params.amountsX),
11117
10940
  tx.pure.vector("u64", params.amountsY),
11118
10941
  tx.pure.address(params.to),
@@ -11224,8 +11047,8 @@ var DlmmModule = class {
11224
11047
  const positionLiquidity = await this.getPositionLiquidity({
11225
11048
  pair: position.pool,
11226
11049
  positionId: position.pos_object_id,
11227
- coinTypeA: pool?.coin_a,
11228
- coinTypeB: pool?.coin_b
11050
+ coinTypeA: pool.coin_a,
11051
+ coinTypeB: pool.coin_b
11229
11052
  });
11230
11053
  const rewards_token = pool_reward_coins.get(position.pool) || [];
11231
11054
  let positionRewards = { position_id: position.pos_object_id, reward: [], amount: [] };
@@ -11233,16 +11056,16 @@ var DlmmModule = class {
11233
11056
  positionRewards = await this.getEarnedRewards({
11234
11057
  pool_id: position.pool,
11235
11058
  position_id: position.pos_object_id,
11236
- coin_a: pool?.coin_a,
11237
- coin_b: pool?.coin_b,
11059
+ coin_a: pool.coin_a,
11060
+ coin_b: pool.coin_b,
11238
11061
  rewards_token: pool_reward_coins.get(position.pool) || []
11239
11062
  });
11240
11063
  }
11241
11064
  const positionFees = await this.getEarnedFees({
11242
11065
  pool_id: position.pool,
11243
11066
  position_id: position.pos_object_id,
11244
- coin_a: pool?.coin_a,
11245
- coin_b: pool?.coin_b
11067
+ coin_a: pool.coin_a,
11068
+ coin_b: pool.coin_b
11246
11069
  });
11247
11070
  return {
11248
11071
  position,
@@ -11301,8 +11124,8 @@ var DlmmModule = class {
11301
11124
  const positionLiquidity = await this.getPositionLiquidity({
11302
11125
  pair: item.pool,
11303
11126
  positionId: item.pos_object_id,
11304
- coinTypeA: pool?.coin_a,
11305
- coinTypeB: pool?.coin_b
11127
+ coinTypeA: pool.coin_a,
11128
+ coinTypeB: pool.coin_b
11306
11129
  });
11307
11130
  const rewards_token = pool_reward_coins.get(item.pool) || [];
11308
11131
  let positionRewards = { position_id: item.pos_object_id, reward: [], amount: [] };
@@ -11310,16 +11133,16 @@ var DlmmModule = class {
11310
11133
  positionRewards = await this.getEarnedRewards({
11311
11134
  pool_id: item.pool,
11312
11135
  position_id: item.pos_object_id,
11313
- coin_a: pool?.coin_a,
11314
- coin_b: pool?.coin_b,
11136
+ coin_a: pool.coin_a,
11137
+ coin_b: pool.coin_b,
11315
11138
  rewards_token: pool_reward_coins.get(item.pool) || []
11316
11139
  });
11317
11140
  }
11318
11141
  const positionFees = await this.getEarnedFees({
11319
11142
  pool_id: item.pool,
11320
11143
  position_id: item.pos_object_id,
11321
- coin_a: pool?.coin_a,
11322
- coin_b: pool?.coin_b
11144
+ coin_a: pool.coin_a,
11145
+ coin_b: pool.coin_b
11323
11146
  });
11324
11147
  out.push({
11325
11148
  position: item,