@magmaprotocol/magma-clmm-sdk 0.5.41 → 0.5.43

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, decimalsB - decimalsA));
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 = {
@@ -10455,20 +10466,6 @@ var GaugeModule = class {
10455
10466
  });
10456
10467
  return tx;
10457
10468
  }
10458
- async testTeacherCap() {
10459
- const tx = new Transaction11();
10460
- tx.moveCall({
10461
- target: `0xd1bf0385f6d298d3b6f140869c28700e85709d570984200cd82c8164401c5e49::hello_world::call_func1`,
10462
- arguments: [tx.object("0xe1af009a9212aa4bf936ff51794d39e8a75dfbd8e65e3265d3a8e93b4c9256bf")],
10463
- typeArguments: []
10464
- });
10465
- tx.moveCall({
10466
- target: `0xd1bf0385f6d298d3b6f140869c28700e85709d570984200cd82c8164401c5e49::hello_world::call_func2`,
10467
- arguments: [tx.object("0xe1af009a9212aa4bf936ff51794d39e8a75dfbd8e65e3265d3a8e93b4c9256bf")],
10468
- typeArguments: []
10469
- });
10470
- return tx;
10471
- }
10472
10469
  async getEpochRewardByPool(pool, incentive_tokens) {
10473
10470
  const tx = new Transaction11();
10474
10471
  const { integrate, simulationAccount } = this.sdk.sdkOptions;
@@ -10503,7 +10500,7 @@ var GaugeModule = class {
10503
10500
 
10504
10501
  // src/modules/dlmm.ts
10505
10502
  import { Transaction as Transaction12 } from "@mysten/sui/transactions";
10506
- import Decimal9 from "decimal.js";
10503
+ import Decimal10 from "decimal.js";
10507
10504
  import { get_real_id_from_price, get_storage_id_from_real_id } from "@magmaprotocol/calc_dlmm";
10508
10505
  var DlmmModule = class {
10509
10506
  _sdk;
@@ -10576,9 +10573,9 @@ var DlmmModule = class {
10576
10573
  }
10577
10574
  // params price: input (b/(10^b_decimal))/(a/(10^a_decimal))
10578
10575
  price_to_storage_id(price, bin_step, tokenADecimal, tokenBDecimal) {
10579
- const priceDec = new Decimal9(price);
10580
- const tenDec = new Decimal9(10);
10581
- const twoDec = new Decimal9(2);
10576
+ const priceDec = new Decimal10(price);
10577
+ const tenDec = new Decimal10(10);
10578
+ const twoDec = new Decimal10(2);
10582
10579
  const price_x128 = priceDec.mul(tenDec.pow(tokenBDecimal)).div(tenDec.pow(tokenADecimal)).mul(twoDec.pow(128));
10583
10580
  const active_id = get_real_id_from_price(price_x128.toFixed(0).toString(), bin_step);
10584
10581
  return get_storage_id_from_real_id(active_id);
@@ -11339,7 +11336,7 @@ var SDKConfig = {
11339
11336
  clmmConfig: {
11340
11337
  pools_id: "0xfa145b9de10fe858be81edd1c6cdffcf27be9d016de02a1345eb1009a68ba8b2",
11341
11338
  // clmm and dlmm both use this global_config
11342
- global_config_id: "0x4e39044c21fe04e27c67b110dec37807ad439516a1701cf2e0dc842e9e20f1f3",
11339
+ global_config_id: "0x4c4e1402401f72c7d8533d0ed8d5f8949da363c7a3319ccef261ffe153d32f8a",
11343
11340
  global_vault_id: "0xa7e1102f222b6eb81ccc8a126e7feb2353342be9df6f6646a77c4519da29c071",
11344
11341
  admin_cap_id: "0x89c1a321291d15ddae5a086c9abc533dff697fde3d89e0ca836c41af73e36a75"
11345
11342
  },
@@ -11360,7 +11357,7 @@ var SDKConfig = {
11360
11357
  minter_id: "0x4fa5766cd83b33b215b139fec27ac344040f3bbd84fcbee7b61fc671aadc51fa"
11361
11358
  },
11362
11359
  dlmmConfig: {
11363
- factory: "0xb7d4f7281bc604981e2caaa5d2af875b66f9422fcdbf6e310d8ed16b854a5d3e"
11360
+ factory: ""
11364
11361
  },
11365
11362
  gaugeConfig: {}
11366
11363
  };
@@ -11380,8 +11377,8 @@ var clmmMainnet = {
11380
11377
  config: SDKConfig.clmmConfig
11381
11378
  },
11382
11379
  dlmm_pool: {
11383
- package_id: "0xb3a44310c59536782d1b5c29d01a066798750ff0c15242a7f3eb7e55d188cfc3",
11384
- published_at: "0xb3a44310c59536782d1b5c29d01a066798750ff0c15242a7f3eb7e55d188cfc3",
11380
+ package_id: "",
11381
+ published_at: "",
11385
11382
  config: SDKConfig.dlmmConfig
11386
11383
  },
11387
11384
  distribution: {
@@ -11389,8 +11386,8 @@ var clmmMainnet = {
11389
11386
  published_at: "0xee4a1f231dc45a303389998fe26c4e39278cf68b404b32e4f0b9769129b8267b"
11390
11387
  },
11391
11388
  integrate: {
11392
- package_id: "0x228638b6ea17788e34971afee4b4580dbc4dcaa847ef62604d858ef5d3beb5a6",
11393
- published_at: "0x228638b6ea17788e34971afee4b4580dbc4dcaa847ef62604d858ef5d3beb5a6"
11389
+ package_id: "0x2e704d8afc1d6d7f154dee337cc14c153f6f9ce1708213e5dc04a32afe0e45f1",
11390
+ published_at: "0x2e704d8afc1d6d7f154dee337cc14c153f6f9ce1708213e5dc04a32afe0e45f1"
11394
11391
  },
11395
11392
  deepbook: {
11396
11393
  package_id: "0x000000000000000000000000000000000000000000000000000000000000dee9",
@@ -11506,6 +11503,7 @@ var src_default = MagmaClmmSDK;
11506
11503
  export {
11507
11504
  AMM_SWAP_MODULE,
11508
11505
  AmountSpecified,
11506
+ BinMath,
11509
11507
  CLOCK_ADDRESS,
11510
11508
  CachedContent,
11511
11509
  ClmmExpectSwapModule,