@magmaprotocol/magma-clmm-sdk 0.5.65 → 0.5.66

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
@@ -10506,7 +10506,13 @@ var GaugeModule = class {
10506
10506
 
10507
10507
  // src/modules/dlmm.ts
10508
10508
  import { Transaction as Transaction12 } from "@mysten/sui/transactions";
10509
- import { get_real_id, get_storage_id_from_real_id } from "@magmaprotocol/calc_dlmm";
10509
+ import {
10510
+ get_price_x128_from_real_id as get_price_x128_from_real_id3,
10511
+ get_real_id,
10512
+ get_real_id_from_price_x128 as get_real_id_from_price_x1282,
10513
+ get_storage_id_from_real_id
10514
+ } from "@magmaprotocol/calc_dlmm";
10515
+ import Decimal10 from "decimal.js";
10510
10516
  var DlmmModule = class {
10511
10517
  _sdk;
10512
10518
  _cache = {};
@@ -10581,7 +10587,9 @@ var DlmmModule = class {
10581
10587
  }
10582
10588
  // NOTE: x, y should be sorted
10583
10589
  async createPairPayload(params) {
10584
- const storage_id = get_storage_id_from_real_id(BinMath.getBinIdFromPrice(params.priceTokenBPerTokenA, params.bin_step, params.coinADecimal, params.coinBDecimal));
10590
+ const storage_id = get_storage_id_from_real_id(
10591
+ BinMath.getBinIdFromPrice(params.priceTokenBPerTokenA, params.bin_step, params.coinADecimal, params.coinBDecimal)
10592
+ );
10585
10593
  const tx = new Transaction12();
10586
10594
  tx.setSender(this.sdk.senderAddress);
10587
10595
  const { clmm_pool, dlmm_pool, integrate } = this.sdk.sdkOptions;
@@ -10602,6 +10610,64 @@ var DlmmModule = class {
10602
10610
  });
10603
10611
  return tx;
10604
10612
  }
10613
+ async mintByStrategy(params) {
10614
+ const tx = new Transaction12();
10615
+ const slippage = new Decimal10(params.slippage);
10616
+ const lower_slippage = new Decimal10(1).plus(slippage.div(new Decimal10(1e4)));
10617
+ const upper_slippage = new Decimal10(1).plus(slippage.div(new Decimal10(1e4)));
10618
+ tx.setSender(this.sdk.senderAddress);
10619
+ const { dlmm_pool, integrate } = this.sdk.sdkOptions;
10620
+ const dlmmConfig = getPackagerConfigs(dlmm_pool);
10621
+ const typeArguments = [params.coinTypeA, params.coinTypeB];
10622
+ const price = get_price_x128_from_real_id3(params.active_bin, params.bin_step);
10623
+ const min_price = new Decimal10(price).mul(lower_slippage);
10624
+ const max_price = new Decimal10(price).mul(upper_slippage);
10625
+ const active_min = get_storage_id_from_real_id(get_real_id_from_price_x1282(min_price.toDecimalPlaces(0).toString(), params.bin_step));
10626
+ const active_max = get_storage_id_from_real_id(get_real_id_from_price_x1282(max_price.toDecimalPlaces(0).toString(), params.bin_step));
10627
+ const allCoins = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress);
10628
+ let primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountATotal), params.coinTypeA, false, true);
10629
+ let primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountBTotal), params.coinTypeB, false, true);
10630
+ let amount_min = 0;
10631
+ let amount_max = 0;
10632
+ if (params.fixCoinA) {
10633
+ amount_min = new Decimal10(params.amountATotal).mul(lower_slippage).toDecimalPlaces(0).toNumber();
10634
+ amount_max = new Decimal10(params.amountATotal).mul(upper_slippage).toDecimalPlaces(0).toNumber();
10635
+ primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amount_max), params.coinTypeB, false, true);
10636
+ }
10637
+ if (params.fixCoinB) {
10638
+ amount_min = new Decimal10(params.amountBTotal).mul(lower_slippage).toDecimalPlaces(0).toNumber();
10639
+ amount_max = new Decimal10(params.amountBTotal).mul(upper_slippage).toDecimalPlaces(0).toNumber();
10640
+ primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amount_max), params.coinTypeB, false, true);
10641
+ }
10642
+ if (params.fixCoinA && params.fixCoinB) {
10643
+ } else if (params.fixCoinA) {
10644
+ params.amountBTotal = 0;
10645
+ } else if (params.fixCoinB) {
10646
+ params.amountATotal = 0;
10647
+ }
10648
+ const args = [
10649
+ tx.object(params.pair),
10650
+ tx.object(dlmmConfig.factory),
10651
+ primaryCoinAInputs.targetCoin,
10652
+ primaryCoinBInputs.targetCoin,
10653
+ tx.pure.u64(params.amountATotal),
10654
+ tx.pure.u64(params.amountBTotal),
10655
+ tx.pure.u8(params.strategy),
10656
+ tx.pure.u32(params.min_bin),
10657
+ tx.pure.u32(params.max_bin),
10658
+ tx.pure.u32(active_min),
10659
+ tx.pure.u32(active_max),
10660
+ tx.pure.u64(amount_min),
10661
+ tx.pure.u64(amount_max),
10662
+ tx.object(CLOCK_ADDRESS)
10663
+ ];
10664
+ tx.moveCall({
10665
+ target: `${integrate.published_at}::${DlmmScript}::mint_percent`,
10666
+ typeArguments,
10667
+ arguments: args
10668
+ });
10669
+ return tx;
10670
+ }
10605
10671
  // Create a position by percent
10606
10672
  async mintPercent(params) {
10607
10673
  const tx = new Transaction12();
@@ -10853,11 +10919,28 @@ var DlmmModule = class {
10853
10919
  const { clmm_pool, integrate } = this.sdk.sdkOptions;
10854
10920
  const { global_config_id } = getPackagerConfigs(clmm_pool);
10855
10921
  const typeArguments = [params.coinTypeA, params.coinTypeB];
10922
+ const allCoinAsset = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress);
10923
+ const primaryCoinInputA = TransactionUtil.buildCoinForAmount(
10924
+ tx,
10925
+ allCoinAsset,
10926
+ params.swapForY ? BigInt(params.amountIn) : BigInt(0),
10927
+ params.coinTypeA,
10928
+ false,
10929
+ true
10930
+ );
10931
+ const primaryCoinInputB = TransactionUtil.buildCoinForAmount(
10932
+ tx,
10933
+ allCoinAsset,
10934
+ params.swapForY ? BigInt(0) : BigInt(params.amountIn),
10935
+ params.coinTypeB,
10936
+ false,
10937
+ true
10938
+ );
10856
10939
  const args = [
10857
10940
  tx.object(params.pair),
10858
10941
  tx.object(global_config_id),
10859
- tx.object(params.coinTypeA),
10860
- tx.object(params.coinTypeB),
10942
+ primaryCoinInputA.targetCoin,
10943
+ primaryCoinInputB.targetCoin,
10861
10944
  tx.pure.u64(params.amountIn),
10862
10945
  tx.pure.u64(params.minAmountOut),
10863
10946
  tx.pure.bool(params.swapForY),
@@ -10898,11 +10981,11 @@ var DlmmModule = class {
10898
10981
  return res;
10899
10982
  }
10900
10983
  /**
10901
- * Gets a list of positions for the given account address.
10902
- * @param accountAddress The account address to get positions for.
10903
- * @param assignPoolIds An array of pool IDs to filter the positions by.
10904
- * @returns array of Position objects.
10905
- */
10984
+ * Gets a list of positions for the given account address.
10985
+ * @param accountAddress The account address to get positions for.
10986
+ * @param assignPoolIds An array of pool IDs to filter the positions by.
10987
+ * @returns array of Position objects.
10988
+ */
10906
10989
  async getUserPositionById(positionId, showDisplay = true) {
10907
10990
  let position;
10908
10991
  const ownerRes = await this._sdk.fullClient.getObject({
@@ -11168,7 +11251,7 @@ var DlmmModule = class {
11168
11251
  fee_y: 0
11169
11252
  };
11170
11253
  if (simulateRes.error != null) {
11171
- throw new Error(`fetchBins error code: ${simulateRes.error ?? "unknown error"}`);
11254
+ throw new Error(`fetchPairRewards error code: ${simulateRes.error ?? "unknown error"}`);
11172
11255
  }
11173
11256
  simulateRes.events?.forEach((item) => {
11174
11257
  if (extractStructTagFromType(item.type).name === `EventPositionLiquidity`) {