@magmaprotocol/magma-clmm-sdk 0.5.42 → 0.5.44

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
@@ -2587,6 +2587,17 @@ var SplitSwap = class {
2587
2587
  }
2588
2588
  };
2589
2589
 
2590
+ // src/math/bin.ts
2591
+ import Decimal6 from "decimal.js";
2592
+ import { get_price_from_real_id as get_price_from_real_id2 } from "@magmaprotocol/calc_dlmm";
2593
+ var BinMath = class {
2594
+ static getPriceOfBinByBinId(binId, binStep, decimalsA, decimalsB) {
2595
+ const twoDec = new Decimal6(2);
2596
+ const price = new Decimal6(get_price_from_real_id2(binId, binStep));
2597
+ return price.div(twoDec.pow(128)).mul(Decimal6.pow(10, decimalsA - decimalsB));
2598
+ }
2599
+ };
2600
+
2590
2601
  // src/utils/objects.ts
2591
2602
  function getSuiObjectData(resp) {
2592
2603
  return resp.data;
@@ -3033,7 +3044,7 @@ function getRewardInTickRange(pool, tickLower, tickUpper, tickLowerIndex, tickUp
3033
3044
 
3034
3045
  // src/utils/transaction-util.ts
3035
3046
  import BN15 from "bn.js";
3036
- import Decimal6 from "decimal.js";
3047
+ import Decimal7 from "decimal.js";
3037
3048
  import { Transaction } from "@mysten/sui/transactions";
3038
3049
  function findAdjustCoin(coinPair) {
3039
3050
  const isAdjustCoinA = CoinAssist.isSuiCoin(coinPair.coinTypeA);
@@ -3041,7 +3052,7 @@ function findAdjustCoin(coinPair) {
3041
3052
  return { isAdjustCoinA, isAdjustCoinB };
3042
3053
  }
3043
3054
  function reverSlippageAmount(slippageAmount, slippage) {
3044
- return Decimal6.ceil(d(slippageAmount).div(1 + slippage)).toString();
3055
+ return Decimal7.ceil(d(slippageAmount).div(1 + slippage)).toString();
3045
3056
  }
3046
3057
  async function printTransaction(tx, isPrint = true) {
3047
3058
  console.log(`inputs`, tx.blockData.inputs);
@@ -3415,12 +3426,12 @@ var _TransactionUtil = class {
3415
3426
  max_amount_a = params.amount_a;
3416
3427
  min_amount_a = params.amount_a;
3417
3428
  max_amount_b = params.amount_b;
3418
- min_amount_b = new Decimal6(params.amount_b).div(new Decimal6(1).plus(new Decimal6(params.slippage))).mul(new Decimal6(1).minus(new Decimal6(params.slippage))).toDecimalPlaces(0).toNumber();
3429
+ min_amount_b = new Decimal7(params.amount_b).div(new Decimal7(1).plus(new Decimal7(params.slippage))).mul(new Decimal7(1).minus(new Decimal7(params.slippage))).toDecimalPlaces(0).toNumber();
3419
3430
  } else {
3420
3431
  max_amount_b = params.amount_b;
3421
3432
  min_amount_b = params.amount_b;
3422
3433
  max_amount_a = params.amount_a;
3423
- min_amount_a = new Decimal6(params.amount_a).div(new Decimal6(1).plus(new Decimal6(params.slippage))).mul(new Decimal6(1).minus(new Decimal6(params.slippage))).toDecimalPlaces(0).toNumber();
3434
+ min_amount_a = new Decimal7(params.amount_a).div(new Decimal7(1).plus(new Decimal7(params.slippage))).mul(new Decimal7(1).minus(new Decimal7(params.slippage))).toDecimalPlaces(0).toNumber();
3424
3435
  }
3425
3436
  const args = params.is_open ? [
3426
3437
  tx.object(clmmConfig.global_config_id),
@@ -7537,7 +7548,7 @@ var RouterModule = class {
7537
7548
 
7538
7549
  // src/modules/swapModule.ts
7539
7550
  import BN20 from "bn.js";
7540
- import Decimal7 from "decimal.js";
7551
+ import Decimal8 from "decimal.js";
7541
7552
  import { Transaction as Transaction8 } from "@mysten/sui/transactions";
7542
7553
  var AMM_SWAP_MODULE = "amm_swap";
7543
7554
  var POOL_STRUCT = "Pool";
@@ -7555,14 +7566,14 @@ var SwapModule = class {
7555
7566
  const pathCount = item.basePaths.length;
7556
7567
  if (pathCount > 0) {
7557
7568
  const path = item.basePaths[0];
7558
- const feeRate = path.label === "Magma" ? new Decimal7(path.feeRate).div(10 ** 6) : new Decimal7(path.feeRate).div(10 ** 9);
7569
+ const feeRate = path.label === "Magma" ? new Decimal8(path.feeRate).div(10 ** 6) : new Decimal8(path.feeRate).div(10 ** 9);
7559
7570
  const feeAmount = d(path.inputAmount).div(10 ** path.fromDecimal).mul(feeRate);
7560
7571
  fee = fee.add(feeAmount);
7561
7572
  if (pathCount > 1) {
7562
7573
  const path2 = item.basePaths[1];
7563
- const price1 = path.direction ? path.currentPrice : new Decimal7(1).div(path.currentPrice);
7564
- const price2 = path2.direction ? path2.currentPrice : new Decimal7(1).div(path2.currentPrice);
7565
- const feeRate2 = path2.label === "Magma" ? new Decimal7(path2.feeRate).div(10 ** 6) : new Decimal7(path2.feeRate).div(10 ** 9);
7574
+ const price1 = path.direction ? path.currentPrice : new Decimal8(1).div(path.currentPrice);
7575
+ const price2 = path2.direction ? path2.currentPrice : new Decimal8(1).div(path2.currentPrice);
7576
+ const feeRate2 = path2.label === "Magma" ? new Decimal8(path2.feeRate).div(10 ** 6) : new Decimal8(path2.feeRate).div(10 ** 9);
7566
7577
  const feeAmount2 = d(path2.outputAmount).div(10 ** path2.toDecimal).mul(feeRate2);
7567
7578
  const fee2 = feeAmount2.div(price1.mul(price2));
7568
7579
  fee = fee.add(fee2);
@@ -7580,17 +7591,17 @@ var SwapModule = class {
7580
7591
  const outputAmount = d(path.outputAmount).div(10 ** path.toDecimal);
7581
7592
  const inputAmount = d(path.inputAmount).div(10 ** path.fromDecimal);
7582
7593
  const rate = outputAmount.div(inputAmount);
7583
- const cprice = path.direction ? new Decimal7(path.currentPrice) : new Decimal7(1).div(path.currentPrice);
7594
+ const cprice = path.direction ? new Decimal8(path.currentPrice) : new Decimal8(1).div(path.currentPrice);
7584
7595
  impactValue = impactValue.add(this.calculateSingleImpact(rate, cprice));
7585
7596
  }
7586
7597
  if (pathCount === 2) {
7587
7598
  const path = item.basePaths[0];
7588
7599
  const path2 = item.basePaths[1];
7589
- const cprice1 = path.direction ? new Decimal7(path.currentPrice) : new Decimal7(1).div(path.currentPrice);
7590
- const cprice2 = path2.direction ? new Decimal7(path2.currentPrice) : new Decimal7(1).div(path2.currentPrice);
7600
+ const cprice1 = path.direction ? new Decimal8(path.currentPrice) : new Decimal8(1).div(path.currentPrice);
7601
+ const cprice2 = path2.direction ? new Decimal8(path2.currentPrice) : new Decimal8(1).div(path2.currentPrice);
7591
7602
  const cprice = cprice1.mul(cprice2);
7592
- const outputAmount = new Decimal7(path2.outputAmount).div(10 ** path2.toDecimal);
7593
- const inputAmount = new Decimal7(path.inputAmount).div(10 ** path.fromDecimal);
7603
+ const outputAmount = new Decimal8(path2.outputAmount).div(10 ** path2.toDecimal);
7604
+ const inputAmount = new Decimal8(path.inputAmount).div(10 ** path.fromDecimal);
7594
7605
  const rate = outputAmount.div(inputAmount);
7595
7606
  impactValue = impactValue.add(this.calculateSingleImpact(rate, cprice));
7596
7607
  }
@@ -9253,7 +9264,7 @@ var TokenModule = class {
9253
9264
 
9254
9265
  // src/modules/routerModuleV2.ts
9255
9266
  import BN21 from "bn.js";
9256
- import Decimal8 from "decimal.js";
9267
+ import Decimal9 from "decimal.js";
9257
9268
  import { v4 as uuidv4 } from "uuid";
9258
9269
  import axios from "axios";
9259
9270
  var RouterModuleV2 = class {
@@ -9270,7 +9281,7 @@ var RouterModuleV2 = class {
9270
9281
  if (label === "Magma") {
9271
9282
  return TickMath.sqrtPriceX64ToPrice(currentSqrtPrice, decimalA, decimalB);
9272
9283
  }
9273
- return new Decimal8(currentSqrtPrice.toString()).div(new Decimal8(10).pow(new Decimal8(decimalB + 9 - decimalA)));
9284
+ return new Decimal9(currentSqrtPrice.toString()).div(new Decimal9(10).pow(new Decimal9(decimalB + 9 - decimalA)));
9274
9285
  }
9275
9286
  parseJsonResult(data) {
9276
9287
  const result = {
@@ -10489,7 +10500,7 @@ var GaugeModule = class {
10489
10500
 
10490
10501
  // src/modules/dlmm.ts
10491
10502
  import { Transaction as Transaction12 } from "@mysten/sui/transactions";
10492
- import Decimal9 from "decimal.js";
10503
+ import Decimal10 from "decimal.js";
10493
10504
  import { get_real_id_from_price, get_storage_id_from_real_id } from "@magmaprotocol/calc_dlmm";
10494
10505
  var DlmmModule = class {
10495
10506
  _sdk;
@@ -10562,9 +10573,9 @@ var DlmmModule = class {
10562
10573
  }
10563
10574
  // params price: input (b/(10^b_decimal))/(a/(10^a_decimal))
10564
10575
  price_to_storage_id(price, bin_step, tokenADecimal, tokenBDecimal) {
10565
- const priceDec = new Decimal9(price);
10566
- const tenDec = new Decimal9(10);
10567
- const twoDec = new Decimal9(2);
10576
+ const priceDec = new Decimal10(price);
10577
+ const tenDec = new Decimal10(10);
10578
+ const twoDec = new Decimal10(2);
10568
10579
  const price_x128 = priceDec.mul(tenDec.pow(tokenBDecimal)).div(tenDec.pow(tokenADecimal)).mul(twoDec.pow(128));
10569
10580
  const active_id = get_real_id_from_price(price_x128.toFixed(0).toString(), bin_step);
10570
10581
  return get_storage_id_from_real_id(active_id);
@@ -11492,6 +11503,7 @@ var src_default = MagmaClmmSDK;
11492
11503
  export {
11493
11504
  AMM_SWAP_MODULE,
11494
11505
  AmountSpecified,
11506
+ BinMath,
11495
11507
  CLOCK_ADDRESS,
11496
11508
  CachedContent,
11497
11509
  ClmmExpectSwapModule,