@magmaprotocol/magma-clmm-sdk 0.5.64 → 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,12 @@ 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_real_id_from_price_x128 as get_real_id_from_price_x1282, 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";
10510
10515
  import Decimal10 from "decimal.js";
10511
10516
  var DlmmModule = class {
10512
10517
  _sdk;
@@ -10532,7 +10537,9 @@ var DlmmModule = class {
10532
10537
  coin_b: fields.y.fields.name,
10533
10538
  base_factor: fields.params.fields.base_factor,
10534
10539
  base_fee: fields.params.fields.base_factor / 1e4 * (fields.bin_step / 1e4),
10535
- active_index: fields.params.fields.active_index
10540
+ active_index: fields.params.fields.active_index,
10541
+ coinAmountA: fields.reserve_x,
10542
+ coinAmountB: fields.reserve_y
10536
10543
  });
10537
10544
  });
10538
10545
  return poolList;
@@ -10578,18 +10585,11 @@ var DlmmModule = class {
10578
10585
  });
10579
10586
  return res;
10580
10587
  }
10581
- // params price: input (b/(10^b_decimal))/(a/(10^a_decimal))
10582
- price_to_storage_id(price, bin_step, tokenADecimal, tokenBDecimal) {
10583
- const priceDec = new Decimal10(price);
10584
- const tenDec = new Decimal10(10);
10585
- const twoDec = new Decimal10(2);
10586
- const price_x128 = priceDec.mul(tenDec.pow(tokenBDecimal)).div(tenDec.pow(tokenADecimal)).mul(twoDec.pow(128));
10587
- const active_id = get_real_id_from_price_x1282(price_x128.toFixed(0).toString(), bin_step);
10588
- return get_storage_id_from_real_id(active_id);
10589
- }
10590
10588
  // NOTE: x, y should be sorted
10591
10589
  async createPairPayload(params) {
10592
- const storage_id = this.price_to_storage_id(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
+ );
10593
10593
  const tx = new Transaction12();
10594
10594
  tx.setSender(this.sdk.senderAddress);
10595
10595
  const { clmm_pool, dlmm_pool, integrate } = this.sdk.sdkOptions;
@@ -10610,6 +10610,64 @@ var DlmmModule = class {
10610
10610
  });
10611
10611
  return tx;
10612
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
+ }
10613
10671
  // Create a position by percent
10614
10672
  async mintPercent(params) {
10615
10673
  const tx = new Transaction12();
@@ -10778,8 +10836,16 @@ var DlmmModule = class {
10778
10836
  });
10779
10837
  return tx;
10780
10838
  }
10781
- async collectReward(params) {
10782
- const tx = new Transaction12();
10839
+ async collectFeeAndReward(params) {
10840
+ let tx = new Transaction12();
10841
+ tx = await this.collectFees(params);
10842
+ if (params.rewards_token.length > 0) {
10843
+ tx = await this.collectReward(params);
10844
+ }
10845
+ return tx;
10846
+ }
10847
+ async collectReward(params, transaction) {
10848
+ const tx = transaction || new Transaction12();
10783
10849
  tx.setSender(this.sdk.senderAddress);
10784
10850
  const { integrate, clmm_pool } = this.sdk.sdkOptions;
10785
10851
  const clmmConfigs = getPackagerConfigs(clmm_pool);
@@ -10801,8 +10867,8 @@ var DlmmModule = class {
10801
10867
  });
10802
10868
  return tx;
10803
10869
  }
10804
- async collectFees(params) {
10805
- const tx = new Transaction12();
10870
+ async collectFees(params, transaction) {
10871
+ const tx = transaction || new Transaction12();
10806
10872
  tx.setSender(this.sdk.senderAddress);
10807
10873
  const { integrate } = this.sdk.sdkOptions;
10808
10874
  const typeArguments = [params.coin_a, params.coin_b];
@@ -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`) {