@magmaprotocol/magma-clmm-sdk 0.5.76 → 0.5.78

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
@@ -6661,21 +6661,45 @@ var RewarderModule = class {
6661
6661
  * @param tx
6662
6662
  * @returns
6663
6663
  */
6664
- async batchCollectRewardePayload(params, tx) {
6664
+ async batchCollectRewardePayload(params, tx, inputCoinA, inputCoinB) {
6665
6665
  if (!checkInvalidSuiAddress(this._sdk.senderAddress)) {
6666
6666
  throw new ClmmpoolsError("this config sdk senderAddress is not set right", "InvalidSendAddress" /* InvalidSendAddress */);
6667
6667
  }
6668
6668
  const allCoinAsset = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress, null);
6669
6669
  tx = tx || new Transaction6();
6670
- const coinIdList = [];
6670
+ const coinIdMaps = {};
6671
6671
  params.forEach((item) => {
6672
6672
  const coinTypeA = normalizeCoinType(item.coinTypeA);
6673
6673
  const coinTypeB = normalizeCoinType(item.coinTypeB);
6674
6674
  if (item.collect_fee) {
6675
- const coinAInput = TransactionUtil.buildCoinForAmount(tx, allCoinAsset, BigInt(0), coinTypeA, false, true);
6676
- const coinBInput = TransactionUtil.buildCoinForAmount(tx, allCoinAsset, BigInt(0), coinTypeB, false, true);
6677
- coinIdList.push({ coin: coinAInput, coin_addr: coinTypeA });
6678
- coinIdList.push({ coin: coinBInput, coin_addr: coinTypeB });
6675
+ let coinAInput = coinIdMaps[coinTypeA];
6676
+ if (coinAInput == null) {
6677
+ if (inputCoinA == null) {
6678
+ coinAInput = TransactionUtil.buildCoinForAmount(tx, allCoinAsset, BigInt(0), coinTypeA, false);
6679
+ } else {
6680
+ coinAInput = {
6681
+ targetCoin: inputCoinA,
6682
+ remainCoins: [],
6683
+ isMintZeroCoin: false,
6684
+ tragetCoinAmount: "0"
6685
+ };
6686
+ }
6687
+ coinIdMaps[coinTypeA] = coinAInput;
6688
+ }
6689
+ let coinBInput = coinIdMaps[coinTypeB];
6690
+ if (coinBInput == null) {
6691
+ if (inputCoinB == null) {
6692
+ coinBInput = TransactionUtil.buildCoinForAmount(tx, allCoinAsset, BigInt(0), coinTypeB, false);
6693
+ } else {
6694
+ coinBInput = {
6695
+ targetCoin: inputCoinB,
6696
+ remainCoins: [],
6697
+ isMintZeroCoin: false,
6698
+ tragetCoinAmount: "0"
6699
+ };
6700
+ }
6701
+ coinIdMaps[coinTypeB] = coinBInput;
6702
+ }
6679
6703
  tx = this._sdk.Position.createCollectFeeNoSendPaylod(
6680
6704
  {
6681
6705
  pool_id: item.pool_id,
@@ -6691,14 +6715,20 @@ var RewarderModule = class {
6691
6715
  const primaryCoinInputs = [];
6692
6716
  item.rewarder_coin_types.forEach((type) => {
6693
6717
  const coinType = normalizeCoinType(type);
6694
- const coinInput = TransactionUtil.buildCoinForAmount(tx, allCoinAsset, BigInt(0), coinType, false, true);
6718
+ let coinInput = coinIdMaps[type];
6719
+ if (coinInput === void 0) {
6720
+ coinInput = TransactionUtil.buildCoinForAmount(tx, allCoinAsset, BigInt(0), coinType, false);
6721
+ coinIdMaps[coinType] = coinInput;
6722
+ }
6695
6723
  primaryCoinInputs.push(coinInput.targetCoin);
6696
- coinIdList.push({ coin: coinInput, coin_addr: coinType });
6697
6724
  });
6698
6725
  tx = this.createCollectRewarderNoSendPaylod(item, tx, primaryCoinInputs);
6699
6726
  });
6700
- coinIdList.forEach((item) => {
6701
- TransactionUtil.buildTransferCoin(this._sdk, tx, item.coin.targetCoin, item.coin_addr, this._sdk.senderAddress);
6727
+ Object.keys(coinIdMaps).forEach((key) => {
6728
+ const value = coinIdMaps[key];
6729
+ if (value.isMintZeroCoin) {
6730
+ TransactionUtil.buildTransferCoin(this._sdk, tx, value.targetCoin, key, this._sdk.senderAddress);
6731
+ }
6702
6732
  });
6703
6733
  return tx;
6704
6734
  }
@@ -10323,7 +10353,10 @@ var DlmmModule = class {
10323
10353
  coin_b: fields.y.fields.name,
10324
10354
  base_factor: fields.params.fields.base_factor,
10325
10355
  base_fee: fields.params.fields.base_factor / 1e4 * (fields.bin_step / 1e4),
10326
- active_index: fields.params.fields.active_index
10356
+ active_index: fields.params.fields.active_index,
10357
+ real_bin_id: get_real_id(fields.params.fields.active_index),
10358
+ coinAmountA: fields.reserve_x,
10359
+ coinAmountB: fields.reserve_y
10327
10360
  });
10328
10361
  });
10329
10362
  return poolList;