@magmaprotocol/magma-clmm-sdk 0.4.3 → 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.d.ts CHANGED
@@ -965,6 +965,45 @@ type RewarderAmountOwed = {
965
965
  * @returns {T} The retrieved configuration.
966
966
  */
967
967
  declare function getPackagerConfigs<T>(packageObj: Package<T>): T & ({} | null);
968
+ type OpenPositionAddLiquidityWithProtectionParams = {
969
+ pool: SuiAddressType;
970
+ tick_lower: number;
971
+ tick_upper: number;
972
+ coin_a: number | string;
973
+ coin_b: number | string;
974
+ /**
975
+ * The address type of the coin A.
976
+ */
977
+ coinAType: SuiAddressType;
978
+ /**
979
+ * The address type of the coin A.
980
+ */
981
+ coinBType: SuiAddressType;
982
+ max_amount_a: number;
983
+ max_amount_b: number;
984
+ min_amount_a: number;
985
+ min_amount_b: number;
986
+ by_amount_a: boolean;
987
+ };
988
+ type AddLiquidityWithProtectionParams = {
989
+ pool: SuiAddressType;
990
+ position: SuiObjectIdType;
991
+ coin_a: number | string;
992
+ coin_b: number | string;
993
+ /**
994
+ * The address type of the coin A.
995
+ */
996
+ coinAType: SuiAddressType;
997
+ /**
998
+ * The address type of the coin A.
999
+ */
1000
+ coinBType: SuiAddressType;
1001
+ max_amount_a: number;
1002
+ max_amount_b: number;
1003
+ min_amount_a: number;
1004
+ min_amount_b: number;
1005
+ fix_amount_a: boolean;
1006
+ };
968
1007
 
969
1008
  /**
970
1009
  * Represents tick data for a liquidity pool.
@@ -2635,6 +2674,8 @@ declare class PositionModule implements IModule {
2635
2674
  feeOwedA: any;
2636
2675
  feeOwedB: any;
2637
2676
  }>;
2677
+ openPositionWithLiquidityByFixCoinWithProtection(params: OpenPositionAddLiquidityWithProtectionParams): Promise<Transaction>;
2678
+ addLiquidityByFixCoinWithProtection(params: AddLiquidityWithProtectionParams): Promise<Transaction>;
2638
2679
  /**
2639
2680
  * Updates the cache for the given key.
2640
2681
  * @param {string} key The key of the cache entry to update.
@@ -3729,6 +3770,8 @@ declare class TransactionUtil {
3729
3770
  static buildClaimVotingRewardsPoolsTransaction(sdk: MagmaClmmSDK, params: ClaimFeesPoolsParams): Transaction;
3730
3771
  static buildClaimAndLockRebases(sdk: MagmaClmmSDK, params: ClaimAndLockParams): Transaction;
3731
3772
  static buildPoke(sdk: MagmaClmmSDK, params: PokeParams): Transaction;
3773
+ static buildOpenPositionWithLiquidityByFixCoinWithProtection(sdk: MagmaClmmSDK, params: OpenPositionAddLiquidityWithProtectionParams, allCoinAsset: CoinAsset[]): Transaction;
3774
+ static buildAddLiquidityByFixCoinWithProtection(sdk: MagmaClmmSDK, params: AddLiquidityWithProtectionParams, allCoinAsset: CoinAsset[]): Transaction;
3732
3775
  static buildClaimVotingBribe(sdk: MagmaClmmSDK, locks: string[], incentive_tokens: string[]): Transaction;
3733
3776
  /**
3734
3777
  * build swap transaction
@@ -3959,4 +4002,4 @@ interface InitMagmaSDKOptions {
3959
4002
  */
3960
4003
  declare function initMagmaSDK(options: InitMagmaSDKOptions): MagmaClmmSDK;
3961
4004
 
3962
- export { AMM_SWAP_MODULE, AddLiquidityCommonParams, AddLiquidityFixTokenParams, AddLiquidityParams, AddressAndDirection, AdjustResult, AggregatorResult, AmountSpecified, BasePath, BigNumber, Bits, BuildCoinResult, CLOCK_ADDRESS, CachedContent, CalculateRatesParams, CalculateRatesResult, ClaimAndLockParams, ClaimFeesParams, ClaimFeesPoolsParams, ClmmConfig, ClmmExpectSwapModule, ClmmFetcherModule, ClmmIntegratePoolModule, ClmmIntegratePoolV2Module, ClmmIntegratePoolV3Module, ClmmIntegrateRouterModule, ClmmIntegrateRouterWithPartnerModule, ClmmIntegrateUtilsModule, ClmmPartnerModule, ClmmPoolConfig, ClmmPoolUtil, ClmmPositionStatus, ClmmpoolData, ClosePositionParams, CoinAmounts, CoinAsset, CoinAssist, CoinConfig, CoinInfoAddress, CoinNode, CoinPairType, CoinProvider, CoinStoreAddress, CollectFeeParams, CollectFeesQuote, CollectFeesQuoteParam, CollectRewarderParams, ConfigModule, CreateLockParams, CreatePartnerEvent, CreatePoolAddLiquidityParams, CreatePoolParams, DEFAULT_GAS_BUDGET_FOR_MERGE, DEFAULT_GAS_BUDGET_FOR_SPLIT, DEFAULT_GAS_BUDGET_FOR_STAKE, DEFAULT_GAS_BUDGET_FOR_TRANSFER, DEFAULT_GAS_BUDGET_FOR_TRANSFER_SUI, DEFAULT_NFT_TRANSFER_GAS_FEE, DataPage, DeepbookClobV2Moudle, DeepbookCustodianV2Moudle, DeepbookEndpointsV2Moudle, DeepbookPool, DeepbookUtils, FEE_RATE_DENOMINATOR, FaucetCoin, FetchParams, GAS_SYMBOL, GAS_TYPE_ARG, GAS_TYPE_ARG_LONG, IncreaseLockAmountParams, IncreaseUnlockTimeParams, LaunchpadPoolConfig, LiquidityInput, LockModule, LockPermanentParams, MAX_SQRT_PRICE, MAX_TICK_INDEX, MIN_SQRT_PRICE, MIN_TICK_INDEX, MagmaClmmSDK, MagmaConfigs, MathUtil, MergeLockParams, NFT, ONE, OnePath, OpenPositionParams, Order, POOL_STRUCT, Package, PageQuery, PaginationArgs, PathLink, PathProvider, Percentage, PokeParams, Pool, PoolImmutables, PoolInfo, PoolModule, Position, PositionModule, PositionReward, PositionStatus, PositionUtil, PreRouterSwapParams, PreSwapLpChangeParams, PreSwapParams, PreSwapResult, PreSwapWithMultiPoolParams, PriceResult, RemoveLiquidityParams, RewardDistributor, Rewarder, RewarderAmountOwed, RouterModule, RouterModuleV2, RpcModule, SUI_SYSTEM_STATE_OBJECT_ID, SdkOptions, SplitPath, SplitSwap, SplitSwapResult, SplitUnit, SuiAddressType, SuiBasicTypes, SuiInputTypes, SuiObjectDataWithContent, SuiObjectIdType, SuiResource, SuiStructTag, SuiTxArg, SwapDirection, SwapModule, SwapParams, SwapResult, SwapStepResult, SwapUtils, SwapWithRouterParams, TICK_ARRAY_SIZE, TWO, Tick, TickData, TickMath, TickUtil, TokenConfig, TokenConfigEvent, TokenInfo, TokenModule, TransPreSwapWithMultiPoolParams, TransactionUtil, TransferLockParams, TxBlock, U128, U128_MAX, U64_MAX, VoteParams, Voter, VotingEscrow, ZERO, addHexPrefix, adjustForCoinSlippage, adjustForSlippage, asIntN, asUintN, bufferToHex, buildClmmPositionName, buildNFT, buildPool, buildPosition, buildPositionReward, buildTickData, buildTickDataByEvent, cacheTime24h, cacheTime5min, checkAddress, checkInvalidSuiAddress, clmmMainnet, clmmTestnet, collectFeesQuote, composeType, computeSwap, computeSwapStep, createSplitAmountArray, createSplitArray, createTestTransferTxPayloadParams, d, decimalsMultiplier, MagmaClmmSDK as default, estPoolAPR, estPosAPRResult, estPositionAPRWithDeltaMethod, estPositionAPRWithMultiMethod, estimateLiquidityForCoinA, estimateLiquidityForCoinB, extractAddressFromType, extractStructTagFromType, findAdjustCoin, fixCoinType, fixSuiObjectId, fromDecimalsAmount, getAmountFixedDelta, getAmountUnfixedDelta, getCoinAFromLiquidity, getCoinBFromLiquidity, getDefaultSuiInputType, getDeltaA, getDeltaB, getDeltaDownFromOutput, getDeltaUpFromInput, getFutureTime, getLiquidityFromCoinA, getLiquidityFromCoinB, getLowerSqrtPriceFromCoinA, getLowerSqrtPriceFromCoinB, getMoveObject, getMoveObjectType, getMovePackageContent, getNearestTickByTick, getNextSqrtPriceAUp, getNextSqrtPriceBDown, getNextSqrtPriceFromInput, getNextSqrtPriceFromOutput, getObjectDeletedResponse, getObjectDisplay, getObjectFields, getObjectId, getObjectNotExistsResponse, getObjectOwner, getObjectPreviousTransactionDigest, getObjectReference, getObjectType, getObjectVersion, getPackagerConfigs, getRewardInTickRange, getSuiObjectData, getTickDataFromUrlData, getUpperSqrtPriceFromCoinA, getUpperSqrtPriceFromCoinB, hasPublicTransfer, hexToNumber, hexToString, initMagmaSDK, initMainnetSDK, initTestnetSDK, isSortedSymbols, isSuiObjectResponse, newBits, normalizeCoinType, patchFixSuiObjectId, printTransaction, removeHexPrefix, secretKeyToEd25519Keypair, secretKeyToSecp256k1Keypair, shortAddress, shortString, tickScore, toBuffer, toCoinAmount, toDecimalsAmount, transClmmpoolDataWithoutTicks, utf8to16 };
4005
+ export { AMM_SWAP_MODULE, AddLiquidityCommonParams, AddLiquidityFixTokenParams, AddLiquidityParams, AddLiquidityWithProtectionParams, AddressAndDirection, AdjustResult, AggregatorResult, AmountSpecified, BasePath, BigNumber, Bits, BuildCoinResult, CLOCK_ADDRESS, CachedContent, CalculateRatesParams, CalculateRatesResult, ClaimAndLockParams, ClaimFeesParams, ClaimFeesPoolsParams, ClmmConfig, ClmmExpectSwapModule, ClmmFetcherModule, ClmmIntegratePoolModule, ClmmIntegratePoolV2Module, ClmmIntegratePoolV3Module, ClmmIntegrateRouterModule, ClmmIntegrateRouterWithPartnerModule, ClmmIntegrateUtilsModule, ClmmPartnerModule, ClmmPoolConfig, ClmmPoolUtil, ClmmPositionStatus, ClmmpoolData, ClosePositionParams, CoinAmounts, CoinAsset, CoinAssist, CoinConfig, CoinInfoAddress, CoinNode, CoinPairType, CoinProvider, CoinStoreAddress, CollectFeeParams, CollectFeesQuote, CollectFeesQuoteParam, CollectRewarderParams, ConfigModule, CreateLockParams, CreatePartnerEvent, CreatePoolAddLiquidityParams, CreatePoolParams, DEFAULT_GAS_BUDGET_FOR_MERGE, DEFAULT_GAS_BUDGET_FOR_SPLIT, DEFAULT_GAS_BUDGET_FOR_STAKE, DEFAULT_GAS_BUDGET_FOR_TRANSFER, DEFAULT_GAS_BUDGET_FOR_TRANSFER_SUI, DEFAULT_NFT_TRANSFER_GAS_FEE, DataPage, DeepbookClobV2Moudle, DeepbookCustodianV2Moudle, DeepbookEndpointsV2Moudle, DeepbookPool, DeepbookUtils, FEE_RATE_DENOMINATOR, FaucetCoin, FetchParams, GAS_SYMBOL, GAS_TYPE_ARG, GAS_TYPE_ARG_LONG, IncreaseLockAmountParams, IncreaseUnlockTimeParams, LaunchpadPoolConfig, LiquidityInput, LockModule, LockPermanentParams, MAX_SQRT_PRICE, MAX_TICK_INDEX, MIN_SQRT_PRICE, MIN_TICK_INDEX, MagmaClmmSDK, MagmaConfigs, MathUtil, MergeLockParams, NFT, ONE, OnePath, OpenPositionAddLiquidityWithProtectionParams, OpenPositionParams, Order, POOL_STRUCT, Package, PageQuery, PaginationArgs, PathLink, PathProvider, Percentage, PokeParams, Pool, PoolImmutables, PoolInfo, PoolModule, Position, PositionModule, PositionReward, PositionStatus, PositionUtil, PreRouterSwapParams, PreSwapLpChangeParams, PreSwapParams, PreSwapResult, PreSwapWithMultiPoolParams, PriceResult, RemoveLiquidityParams, RewardDistributor, Rewarder, RewarderAmountOwed, RouterModule, RouterModuleV2, RpcModule, SUI_SYSTEM_STATE_OBJECT_ID, SdkOptions, SplitPath, SplitSwap, SplitSwapResult, SplitUnit, SuiAddressType, SuiBasicTypes, SuiInputTypes, SuiObjectDataWithContent, SuiObjectIdType, SuiResource, SuiStructTag, SuiTxArg, SwapDirection, SwapModule, SwapParams, SwapResult, SwapStepResult, SwapUtils, SwapWithRouterParams, TICK_ARRAY_SIZE, TWO, Tick, TickData, TickMath, TickUtil, TokenConfig, TokenConfigEvent, TokenInfo, TokenModule, TransPreSwapWithMultiPoolParams, TransactionUtil, TransferLockParams, TxBlock, U128, U128_MAX, U64_MAX, VoteParams, Voter, VotingEscrow, ZERO, addHexPrefix, adjustForCoinSlippage, adjustForSlippage, asIntN, asUintN, bufferToHex, buildClmmPositionName, buildNFT, buildPool, buildPosition, buildPositionReward, buildTickData, buildTickDataByEvent, cacheTime24h, cacheTime5min, checkAddress, checkInvalidSuiAddress, clmmMainnet, clmmTestnet, collectFeesQuote, composeType, computeSwap, computeSwapStep, createSplitAmountArray, createSplitArray, createTestTransferTxPayloadParams, d, decimalsMultiplier, MagmaClmmSDK as default, estPoolAPR, estPosAPRResult, estPositionAPRWithDeltaMethod, estPositionAPRWithMultiMethod, estimateLiquidityForCoinA, estimateLiquidityForCoinB, extractAddressFromType, extractStructTagFromType, findAdjustCoin, fixCoinType, fixSuiObjectId, fromDecimalsAmount, getAmountFixedDelta, getAmountUnfixedDelta, getCoinAFromLiquidity, getCoinBFromLiquidity, getDefaultSuiInputType, getDeltaA, getDeltaB, getDeltaDownFromOutput, getDeltaUpFromInput, getFutureTime, getLiquidityFromCoinA, getLiquidityFromCoinB, getLowerSqrtPriceFromCoinA, getLowerSqrtPriceFromCoinB, getMoveObject, getMoveObjectType, getMovePackageContent, getNearestTickByTick, getNextSqrtPriceAUp, getNextSqrtPriceBDown, getNextSqrtPriceFromInput, getNextSqrtPriceFromOutput, getObjectDeletedResponse, getObjectDisplay, getObjectFields, getObjectId, getObjectNotExistsResponse, getObjectOwner, getObjectPreviousTransactionDigest, getObjectReference, getObjectType, getObjectVersion, getPackagerConfigs, getRewardInTickRange, getSuiObjectData, getTickDataFromUrlData, getUpperSqrtPriceFromCoinA, getUpperSqrtPriceFromCoinB, hasPublicTransfer, hexToNumber, hexToString, initMagmaSDK, initMainnetSDK, initTestnetSDK, isSortedSymbols, isSuiObjectResponse, newBits, normalizeCoinType, patchFixSuiObjectId, printTransaction, removeHexPrefix, secretKeyToEd25519Keypair, secretKeyToSecp256k1Keypair, shortAddress, shortString, tickScore, toBuffer, toCoinAmount, toDecimalsAmount, transClmmpoolDataWithoutTicks, utf8to16 };
package/dist/index.js CHANGED
@@ -1186,11 +1186,7 @@ var ClmmPoolUtil = class {
1186
1186
  coinB = new decimal_default(0);
1187
1187
  } else if (curSqrtPrice.lt(upperSqrtPrice)) {
1188
1188
  coinA = MathUtil.toX64_Decimal(liq).mul(upperPriceStr.sub(curSqrtPriceStr)).div(curSqrtPriceStr.mul(upperPriceStr));
1189
- const a = curSqrtPriceStr.sub(lowerPriceStr);
1190
- const b = liq.mul(a);
1191
- const c = MathUtil.fromX64_Decimal(b);
1192
- coinB = c;
1193
- console.log("########## a, b, c", a, b, c);
1189
+ coinB = MathUtil.fromX64_Decimal(liq.mul(curSqrtPriceStr.sub(lowerPriceStr)));
1194
1190
  } else {
1195
1191
  coinA = new decimal_default(0);
1196
1192
  coinB = MathUtil.fromX64_Decimal(liq.mul(upperPriceStr.sub(lowerPriceStr)));
@@ -3181,6 +3177,65 @@ var _TransactionUtil = class {
3181
3177
  });
3182
3178
  return tx;
3183
3179
  }
3180
+ static buildOpenPositionWithLiquidityByFixCoinWithProtection(sdk, params, allCoinAsset) {
3181
+ const tx = new import_transactions.Transaction();
3182
+ tx.setSender(sdk.senderAddress);
3183
+ const { clmm_pool, integrate } = sdk.sdkOptions;
3184
+ const globalConfigID = getPackagerConfigs(clmm_pool).global_config_id;
3185
+ const typeArguments = [params.coinAType, params.coinBType];
3186
+ const functionName = "open_position_with_liquidity_by_fix_coin_with_protection";
3187
+ const coinA = _TransactionUtil.buildCoinForAmount(tx, allCoinAsset, BigInt(params.max_amount_a), params.coinAType, false, true);
3188
+ const coinB = _TransactionUtil.buildCoinForAmount(tx, allCoinAsset, BigInt(params.max_amount_b), params.coinBType, false, true);
3189
+ const args = [
3190
+ tx.object(globalConfigID),
3191
+ tx.object(params.pool),
3192
+ tx.pure.u32(params.tick_lower),
3193
+ tx.pure.u32(params.tick_upper),
3194
+ coinA.targetCoin,
3195
+ coinB.targetCoin,
3196
+ tx.pure.u64(params.max_amount_a),
3197
+ tx.pure.u64(params.max_amount_b),
3198
+ tx.pure.u64(params.min_amount_a),
3199
+ tx.pure.u64(params.min_amount_b),
3200
+ tx.pure.bool(params.by_amount_a),
3201
+ tx.object(CLOCK_ADDRESS)
3202
+ ];
3203
+ tx.moveCall({
3204
+ target: `${integrate.published_at}::${Voter}::${functionName}`,
3205
+ typeArguments,
3206
+ arguments: args
3207
+ });
3208
+ return tx;
3209
+ }
3210
+ static buildAddLiquidityByFixCoinWithProtection(sdk, params, allCoinAsset) {
3211
+ const tx = new import_transactions.Transaction();
3212
+ tx.setSender(sdk.senderAddress);
3213
+ const { clmm_pool, integrate } = sdk.sdkOptions;
3214
+ const globalConfigID = getPackagerConfigs(clmm_pool).global_config_id;
3215
+ const typeArguments = [params.coinAType, params.coinBType];
3216
+ const functionName = "add_liquidity_by_fix_coin_with_protection";
3217
+ const coinA = _TransactionUtil.buildCoinForAmount(tx, allCoinAsset, BigInt(params.max_amount_a), params.coinAType, false, true);
3218
+ const coinB = _TransactionUtil.buildCoinForAmount(tx, allCoinAsset, BigInt(params.max_amount_b), params.coinBType, false, true);
3219
+ const args = [
3220
+ tx.object(globalConfigID),
3221
+ tx.object(params.pool),
3222
+ tx.object(params.position),
3223
+ coinA.targetCoin,
3224
+ coinB.targetCoin,
3225
+ tx.pure.u64(params.max_amount_a),
3226
+ tx.pure.u64(params.max_amount_b),
3227
+ tx.pure.u64(params.min_amount_a),
3228
+ tx.pure.u64(params.min_amount_b),
3229
+ tx.pure.bool(params.fix_amount_a),
3230
+ tx.object(CLOCK_ADDRESS)
3231
+ ];
3232
+ tx.moveCall({
3233
+ target: `${integrate.published_at}::${Voter}::${functionName}`,
3234
+ typeArguments,
3235
+ arguments: args
3236
+ });
3237
+ return tx;
3238
+ }
3184
3239
  static buildClaimVotingBribe(sdk, locks, incentive_tokens) {
3185
3240
  const tx = new import_transactions.Transaction();
3186
3241
  tx.setGasBudget(5e8);
@@ -5700,6 +5755,20 @@ var PositionModule = class {
5700
5755
  feeOwedB: "0"
5701
5756
  };
5702
5757
  }
5758
+ async openPositionWithLiquidityByFixCoinWithProtection(params) {
5759
+ if (this._sdk.senderAddress.length === 0) {
5760
+ throw Error("this config sdk senderAddress is empty");
5761
+ }
5762
+ const allCoinAsset = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress);
5763
+ return TransactionUtil.buildOpenPositionWithLiquidityByFixCoinWithProtection(this.sdk, params, allCoinAsset);
5764
+ }
5765
+ async addLiquidityByFixCoinWithProtection(params) {
5766
+ if (this._sdk.senderAddress.length === 0) {
5767
+ throw Error("this config sdk senderAddress is empty");
5768
+ }
5769
+ const allCoinAsset = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress);
5770
+ return TransactionUtil.buildAddLiquidityByFixCoinWithProtection(this.sdk, params, allCoinAsset);
5771
+ }
5703
5772
  /**
5704
5773
  * Updates the cache for the given key.
5705
5774
  * @param {string} key The key of the cache entry to update.