@magmaprotocol/magma-clmm-sdk 0.4.2 → 0.5.0

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
@@ -983,11 +983,7 @@ var ClmmPoolUtil = class {
983
983
  coinB = new decimal_default(0);
984
984
  } else if (curSqrtPrice.lt(upperSqrtPrice)) {
985
985
  coinA = MathUtil.toX64_Decimal(liq).mul(upperPriceStr.sub(curSqrtPriceStr)).div(curSqrtPriceStr.mul(upperPriceStr));
986
- const a = curSqrtPriceStr.sub(lowerPriceStr);
987
- const b = liq.mul(a);
988
- const c = MathUtil.fromX64_Decimal(b);
989
- coinB = c;
990
- console.log("########## a, b, c", a, b, c);
986
+ coinB = MathUtil.fromX64_Decimal(liq.mul(curSqrtPriceStr.sub(lowerPriceStr)));
991
987
  } else {
992
988
  coinA = new decimal_default(0);
993
989
  coinB = MathUtil.fromX64_Decimal(liq.mul(upperPriceStr.sub(lowerPriceStr)));
@@ -2978,6 +2974,65 @@ var _TransactionUtil = class {
2978
2974
  });
2979
2975
  return tx;
2980
2976
  }
2977
+ static buildOpenPositionWithLiquidityByFixCoinWithProtection(sdk, params, allCoinAsset) {
2978
+ const tx = new Transaction();
2979
+ tx.setSender(sdk.senderAddress);
2980
+ const { clmm_pool, integrate } = sdk.sdkOptions;
2981
+ const globalConfigID = getPackagerConfigs(clmm_pool).global_config_id;
2982
+ const typeArguments = [params.coinAType, params.coinBType];
2983
+ const functionName = "open_position_with_liquidity_by_fix_coin_with_protection";
2984
+ const coinA = _TransactionUtil.buildCoinForAmount(tx, allCoinAsset, BigInt(params.max_amount_a), params.coinAType, false, true);
2985
+ const coinB = _TransactionUtil.buildCoinForAmount(tx, allCoinAsset, BigInt(params.max_amount_b), params.coinBType, false, true);
2986
+ const args = [
2987
+ tx.object(globalConfigID),
2988
+ tx.object(params.pool),
2989
+ tx.pure.u32(params.tick_lower),
2990
+ tx.pure.u32(params.tick_upper),
2991
+ coinA.targetCoin,
2992
+ coinB.targetCoin,
2993
+ tx.pure.u64(params.max_amount_a),
2994
+ tx.pure.u64(params.max_amount_b),
2995
+ tx.pure.u64(params.min_amount_a),
2996
+ tx.pure.u64(params.min_amount_b),
2997
+ tx.pure.bool(params.by_amount_a),
2998
+ tx.object(CLOCK_ADDRESS)
2999
+ ];
3000
+ tx.moveCall({
3001
+ target: `${integrate.published_at}::${Voter}::${functionName}`,
3002
+ typeArguments,
3003
+ arguments: args
3004
+ });
3005
+ return tx;
3006
+ }
3007
+ static buildAddLiquidityByFixCoinWithProtection(sdk, params, allCoinAsset) {
3008
+ const tx = new Transaction();
3009
+ tx.setSender(sdk.senderAddress);
3010
+ const { clmm_pool, integrate } = sdk.sdkOptions;
3011
+ const globalConfigID = getPackagerConfigs(clmm_pool).global_config_id;
3012
+ const typeArguments = [params.coinAType, params.coinBType];
3013
+ const functionName = "add_liquidity_by_fix_coin_with_protection";
3014
+ const coinA = _TransactionUtil.buildCoinForAmount(tx, allCoinAsset, BigInt(params.max_amount_a), params.coinAType, false, true);
3015
+ const coinB = _TransactionUtil.buildCoinForAmount(tx, allCoinAsset, BigInt(params.max_amount_b), params.coinBType, false, true);
3016
+ const args = [
3017
+ tx.object(globalConfigID),
3018
+ tx.object(params.pool),
3019
+ tx.object(params.position),
3020
+ coinA.targetCoin,
3021
+ coinB.targetCoin,
3022
+ tx.pure.u64(params.max_amount_a),
3023
+ tx.pure.u64(params.max_amount_b),
3024
+ tx.pure.u64(params.min_amount_a),
3025
+ tx.pure.u64(params.min_amount_b),
3026
+ tx.pure.bool(params.fix_amount_a),
3027
+ tx.object(CLOCK_ADDRESS)
3028
+ ];
3029
+ tx.moveCall({
3030
+ target: `${integrate.published_at}::${Voter}::${functionName}`,
3031
+ typeArguments,
3032
+ arguments: args
3033
+ });
3034
+ return tx;
3035
+ }
2981
3036
  static buildClaimVotingBribe(sdk, locks, incentive_tokens) {
2982
3037
  const tx = new Transaction();
2983
3038
  tx.setGasBudget(5e8);
@@ -5497,6 +5552,20 @@ var PositionModule = class {
5497
5552
  feeOwedB: "0"
5498
5553
  };
5499
5554
  }
5555
+ async openPositionWithLiquidityByFixCoinWithProtection(params) {
5556
+ if (this._sdk.senderAddress.length === 0) {
5557
+ throw Error("this config sdk senderAddress is empty");
5558
+ }
5559
+ const allCoinAsset = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress);
5560
+ return TransactionUtil.buildOpenPositionWithLiquidityByFixCoinWithProtection(this.sdk, params, allCoinAsset);
5561
+ }
5562
+ async addLiquidityByFixCoinWithProtection(params) {
5563
+ if (this._sdk.senderAddress.length === 0) {
5564
+ throw Error("this config sdk senderAddress is empty");
5565
+ }
5566
+ const allCoinAsset = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress);
5567
+ return TransactionUtil.buildAddLiquidityByFixCoinWithProtection(this.sdk, params, allCoinAsset);
5568
+ }
5500
5569
  /**
5501
5570
  * Updates the cache for the given key.
5502
5571
  * @param {string} key The key of the cache entry to update.