@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.d.ts CHANGED
@@ -1752,6 +1752,10 @@ type DlmmPoolInfo = {
1752
1752
  base_factor: number;
1753
1753
  base_fee: number;
1754
1754
  active_index: number;
1755
+ real_bin_id: number;
1756
+ coinAmountA: string;
1757
+ coinAmountB: string;
1758
+ index?: number;
1755
1759
  };
1756
1760
  type DlmmAddLiquidityParams = {
1757
1761
  pool_id: string;
@@ -2913,7 +2917,7 @@ declare class RewarderModule implements IModule {
2913
2917
  * @param tx
2914
2918
  * @returns
2915
2919
  */
2916
- batchCollectRewardePayload(params: CollectRewarderParams[], tx?: Transaction): Promise<Transaction>;
2920
+ batchCollectRewardePayload(params: CollectRewarderParams[], tx?: Transaction, inputCoinA?: TransactionObjectArgument, inputCoinB?: TransactionObjectArgument): Promise<Transaction>;
2917
2921
  createCollectRewarderPaylod(params: CollectRewarderParams, tx: Transaction, primaryCoinInputs: TransactionArgument[]): Transaction;
2918
2922
  createCollectRewarderNoSendPaylod(params: CollectRewarderParams, tx: Transaction, primaryCoinInputs: TransactionArgument[]): Transaction;
2919
2923
  }
package/dist/index.js CHANGED
@@ -6881,21 +6881,45 @@ var RewarderModule = class {
6881
6881
  * @param tx
6882
6882
  * @returns
6883
6883
  */
6884
- async batchCollectRewardePayload(params, tx) {
6884
+ async batchCollectRewardePayload(params, tx, inputCoinA, inputCoinB) {
6885
6885
  if (!checkInvalidSuiAddress(this._sdk.senderAddress)) {
6886
6886
  throw new ClmmpoolsError("this config sdk senderAddress is not set right", "InvalidSendAddress" /* InvalidSendAddress */);
6887
6887
  }
6888
6888
  const allCoinAsset = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress, null);
6889
6889
  tx = tx || new import_transactions6.Transaction();
6890
- const coinIdList = [];
6890
+ const coinIdMaps = {};
6891
6891
  params.forEach((item) => {
6892
6892
  const coinTypeA = normalizeCoinType(item.coinTypeA);
6893
6893
  const coinTypeB = normalizeCoinType(item.coinTypeB);
6894
6894
  if (item.collect_fee) {
6895
- const coinAInput = TransactionUtil.buildCoinForAmount(tx, allCoinAsset, BigInt(0), coinTypeA, false, true);
6896
- const coinBInput = TransactionUtil.buildCoinForAmount(tx, allCoinAsset, BigInt(0), coinTypeB, false, true);
6897
- coinIdList.push({ coin: coinAInput, coin_addr: coinTypeA });
6898
- coinIdList.push({ coin: coinBInput, coin_addr: coinTypeB });
6895
+ let coinAInput = coinIdMaps[coinTypeA];
6896
+ if (coinAInput == null) {
6897
+ if (inputCoinA == null) {
6898
+ coinAInput = TransactionUtil.buildCoinForAmount(tx, allCoinAsset, BigInt(0), coinTypeA, false);
6899
+ } else {
6900
+ coinAInput = {
6901
+ targetCoin: inputCoinA,
6902
+ remainCoins: [],
6903
+ isMintZeroCoin: false,
6904
+ tragetCoinAmount: "0"
6905
+ };
6906
+ }
6907
+ coinIdMaps[coinTypeA] = coinAInput;
6908
+ }
6909
+ let coinBInput = coinIdMaps[coinTypeB];
6910
+ if (coinBInput == null) {
6911
+ if (inputCoinB == null) {
6912
+ coinBInput = TransactionUtil.buildCoinForAmount(tx, allCoinAsset, BigInt(0), coinTypeB, false);
6913
+ } else {
6914
+ coinBInput = {
6915
+ targetCoin: inputCoinB,
6916
+ remainCoins: [],
6917
+ isMintZeroCoin: false,
6918
+ tragetCoinAmount: "0"
6919
+ };
6920
+ }
6921
+ coinIdMaps[coinTypeB] = coinBInput;
6922
+ }
6899
6923
  tx = this._sdk.Position.createCollectFeeNoSendPaylod(
6900
6924
  {
6901
6925
  pool_id: item.pool_id,
@@ -6911,14 +6935,20 @@ var RewarderModule = class {
6911
6935
  const primaryCoinInputs = [];
6912
6936
  item.rewarder_coin_types.forEach((type) => {
6913
6937
  const coinType = normalizeCoinType(type);
6914
- const coinInput = TransactionUtil.buildCoinForAmount(tx, allCoinAsset, BigInt(0), coinType, false, true);
6938
+ let coinInput = coinIdMaps[type];
6939
+ if (coinInput === void 0) {
6940
+ coinInput = TransactionUtil.buildCoinForAmount(tx, allCoinAsset, BigInt(0), coinType, false);
6941
+ coinIdMaps[coinType] = coinInput;
6942
+ }
6915
6943
  primaryCoinInputs.push(coinInput.targetCoin);
6916
- coinIdList.push({ coin: coinInput, coin_addr: coinType });
6917
6944
  });
6918
6945
  tx = this.createCollectRewarderNoSendPaylod(item, tx, primaryCoinInputs);
6919
6946
  });
6920
- coinIdList.forEach((item) => {
6921
- TransactionUtil.buildTransferCoin(this._sdk, tx, item.coin.targetCoin, item.coin_addr, this._sdk.senderAddress);
6947
+ Object.keys(coinIdMaps).forEach((key) => {
6948
+ const value = coinIdMaps[key];
6949
+ if (value.isMintZeroCoin) {
6950
+ TransactionUtil.buildTransferCoin(this._sdk, tx, value.targetCoin, key, this._sdk.senderAddress);
6951
+ }
6922
6952
  });
6923
6953
  return tx;
6924
6954
  }
@@ -10536,7 +10566,10 @@ var DlmmModule = class {
10536
10566
  coin_b: fields.y.fields.name,
10537
10567
  base_factor: fields.params.fields.base_factor,
10538
10568
  base_fee: fields.params.fields.base_factor / 1e4 * (fields.bin_step / 1e4),
10539
- active_index: fields.params.fields.active_index
10569
+ active_index: fields.params.fields.active_index,
10570
+ real_bin_id: (0, import_calc_dlmm3.get_real_id)(fields.params.fields.active_index),
10571
+ coinAmountA: fields.reserve_x,
10572
+ coinAmountB: fields.reserve_y
10540
10573
  });
10541
10574
  });
10542
10575
  return poolList;