@meteora-ag/dlmm 1.0.43 → 1.0.44-rc.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.js CHANGED
@@ -4898,6 +4898,26 @@ function toAmountAskSide(activeId, binStep, totalAmount, distributions) {
4898
4898
  });
4899
4899
  }
4900
4900
  function toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, distributions) {
4901
+ if (activeId > distributions[distributions.length - 1].binId) {
4902
+ let amounts = toAmountBidSide(activeId, amountY, distributions);
4903
+ return amounts.map((bin) => {
4904
+ return {
4905
+ binId: bin.binId,
4906
+ amountX: new (0, _anchor.BN)(0),
4907
+ amountY: bin.amount
4908
+ };
4909
+ });
4910
+ }
4911
+ if (activeId < distributions[0].binId) {
4912
+ let amounts = toAmountAskSide(activeId, binStep, amountX, distributions);
4913
+ return amounts.map((bin) => {
4914
+ return {
4915
+ binId: bin.binId,
4916
+ amountX: bin.amount,
4917
+ amountY: new (0, _anchor.BN)(0)
4918
+ };
4919
+ });
4920
+ }
4901
4921
  const activeBins = distributions.filter((element) => {
4902
4922
  return element.binId === activeId;
4903
4923
  });
@@ -6280,6 +6300,10 @@ function toAmountsBothSideByStrategy(activeId, binStep, minBinId, maxBinId, amou
6280
6300
  throw "Invalid Strategy Parameters";
6281
6301
  }
6282
6302
  case 3 /* SpotImBalanced */: {
6303
+ if (activeId < minBinId || activeId > maxBinId) {
6304
+ let weights = toWeightSpotBalanced(minBinId, maxBinId);
6305
+ return toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights);
6306
+ }
6283
6307
  let amountsInBin = [];
6284
6308
  if (minBinId <= activeId) {
6285
6309
  let weights = toWeightSpotBalanced(minBinId, activeId);
@@ -6306,6 +6330,30 @@ function toAmountsBothSideByStrategy(activeId, binStep, minBinId, maxBinId, amou
6306
6330
  return amountsInBin;
6307
6331
  }
6308
6332
  case 4 /* CurveImBalanced */: {
6333
+ if (activeId < minBinId) {
6334
+ let weights = toWeightDecendingOrder(minBinId, maxBinId);
6335
+ return toAmountBothSide(
6336
+ activeId,
6337
+ binStep,
6338
+ amountX,
6339
+ amountY,
6340
+ amountXInActiveBin,
6341
+ amountYInActiveBin,
6342
+ weights
6343
+ );
6344
+ }
6345
+ if (activeId > maxBinId) {
6346
+ let weights = toWeightAscendingOrder(minBinId, maxBinId);
6347
+ return toAmountBothSide(
6348
+ activeId,
6349
+ binStep,
6350
+ amountX,
6351
+ amountY,
6352
+ amountXInActiveBin,
6353
+ amountYInActiveBin,
6354
+ weights
6355
+ );
6356
+ }
6309
6357
  let amountsInBin = [];
6310
6358
  if (minBinId <= activeId) {
6311
6359
  let weights = toWeightAscendingOrder(minBinId, activeId);
@@ -6332,6 +6380,30 @@ function toAmountsBothSideByStrategy(activeId, binStep, minBinId, maxBinId, amou
6332
6380
  return amountsInBin;
6333
6381
  }
6334
6382
  case 5 /* BidAskImBalanced */: {
6383
+ if (activeId < minBinId) {
6384
+ let weights = toWeightAscendingOrder(minBinId, maxBinId);
6385
+ return toAmountBothSide(
6386
+ activeId,
6387
+ binStep,
6388
+ amountX,
6389
+ amountY,
6390
+ amountXInActiveBin,
6391
+ amountYInActiveBin,
6392
+ weights
6393
+ );
6394
+ }
6395
+ if (activeId > maxBinId) {
6396
+ let weights = toWeightDecendingOrder(minBinId, maxBinId);
6397
+ return toAmountBothSide(
6398
+ activeId,
6399
+ binStep,
6400
+ amountX,
6401
+ amountY,
6402
+ amountXInActiveBin,
6403
+ amountYInActiveBin,
6404
+ weights
6405
+ );
6406
+ }
6335
6407
  let amountsInBin = [];
6336
6408
  if (minBinId <= activeId) {
6337
6409
  let weights = toWeightDecendingOrder(minBinId, activeId);
@@ -8161,31 +8233,8 @@ var DLMM = class {
8161
8233
  tokenXProgram: _spltoken.TOKEN_PROGRAM_ID,
8162
8234
  tokenYProgram: _spltoken.TOKEN_PROGRAM_ID
8163
8235
  };
8164
- const oneSideLiquidityParams = {
8165
- amount: totalXAmount.isZero() ? totalYAmount : totalXAmount,
8166
- activeId,
8167
- maxActiveBinSlippage,
8168
- strategyParameters
8169
- };
8170
- const oneSideAddLiquidityAccounts = {
8171
- binArrayLower,
8172
- binArrayUpper,
8173
- lbPair: this.pubkey,
8174
- binArrayBitmapExtension: null,
8175
- sender: user,
8176
- position: positionPubKey,
8177
- reserve: totalXAmount.isZero() ? this.lbPair.reserveY : this.lbPair.reserveX,
8178
- tokenMint: totalXAmount.isZero() ? this.lbPair.tokenYMint : this.lbPair.tokenXMint,
8179
- tokenProgram: _spltoken.TOKEN_PROGRAM_ID,
8180
- userToken: totalXAmount.isZero() ? userTokenY : userTokenX
8181
- };
8182
- const isOneSideDeposit = totalXAmount.isZero() || totalYAmount.isZero();
8183
- const programMethod = isOneSideDeposit ? this.program.methods.addLiquidityByStrategyOneSide(
8184
- oneSideLiquidityParams
8185
- ) : this.program.methods.addLiquidityByStrategy(liquidityParams);
8186
- const createPositionTx = await programMethod.accounts(
8187
- isOneSideDeposit ? oneSideAddLiquidityAccounts : addLiquidityAccounts
8188
- ).preInstructions(preInstructions).postInstructions(postInstructions).transaction();
8236
+ const programMethod = this.program.methods.addLiquidityByStrategy(liquidityParams);
8237
+ const createPositionTx = await programMethod.accounts(addLiquidityAccounts).preInstructions(preInstructions).postInstructions(postInstructions).transaction();
8189
8238
  const { blockhash, lastValidBlockHeight } = await this.program.provider.connection.getLatestBlockhash("confirmed");
8190
8239
  return new (0, _web3js.Transaction)({
8191
8240
  blockhash,
@@ -8510,31 +8559,8 @@ var DLMM = class {
8510
8559
  tokenXProgram: _spltoken.TOKEN_PROGRAM_ID,
8511
8560
  tokenYProgram: _spltoken.TOKEN_PROGRAM_ID
8512
8561
  };
8513
- const oneSideLiquidityParams = {
8514
- amount: totalXAmount.isZero() ? totalYAmount : totalXAmount,
8515
- activeId,
8516
- maxActiveBinSlippage,
8517
- strategyParameters
8518
- };
8519
- const oneSideAddLiquidityAccounts = {
8520
- binArrayLower,
8521
- binArrayUpper,
8522
- lbPair: this.pubkey,
8523
- binArrayBitmapExtension: null,
8524
- sender: user,
8525
- position: positionPubKey,
8526
- reserve: totalXAmount.isZero() ? this.lbPair.reserveY : this.lbPair.reserveX,
8527
- tokenMint: totalXAmount.isZero() ? this.lbPair.tokenYMint : this.lbPair.tokenXMint,
8528
- tokenProgram: _spltoken.TOKEN_PROGRAM_ID,
8529
- userToken: totalXAmount.isZero() ? userTokenY : userTokenX
8530
- };
8531
- const isOneSideDeposit = totalXAmount.isZero() || totalYAmount.isZero();
8532
- const programMethod = isOneSideDeposit ? this.program.methods.addLiquidityByStrategyOneSide(
8533
- oneSideLiquidityParams
8534
- ) : this.program.methods.addLiquidityByStrategy(liquidityParams);
8535
- const createPositionTx = await programMethod.accounts(
8536
- isOneSideDeposit ? oneSideAddLiquidityAccounts : addLiquidityAccounts
8537
- ).preInstructions(preInstructions).postInstructions(postInstructions).transaction();
8562
+ const programMethod = this.program.methods.addLiquidityByStrategy(liquidityParams);
8563
+ const createPositionTx = await programMethod.accounts(addLiquidityAccounts).preInstructions(preInstructions).postInstructions(postInstructions).transaction();
8538
8564
  const { blockhash, lastValidBlockHeight } = await this.program.provider.connection.getLatestBlockhash("confirmed");
8539
8565
  return new (0, _web3js.Transaction)({
8540
8566
  blockhash,