@meteora-ag/dlmm 1.0.44 → 1.0.46-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);
@@ -6973,21 +7045,23 @@ var DLMM = class {
6973
7045
  _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _40 => _40.programId]), () => ( LBCLMM_PROGRAM_IDS[cluster])),
6974
7046
  provider
6975
7047
  );
6976
- const positions = await program.account.position.all([
6977
- {
6978
- memcmp: {
6979
- bytes: _bytes.bs58.encode(userPubKey.toBuffer()),
6980
- offset: 8 + 32
7048
+ const [positions, positionsV2] = await Promise.all([
7049
+ program.account.position.all([
7050
+ {
7051
+ memcmp: {
7052
+ bytes: _bytes.bs58.encode(userPubKey.toBuffer()),
7053
+ offset: 8 + 32
7054
+ }
6981
7055
  }
6982
- }
6983
- ]);
6984
- const positionsV2 = await program.account.positionV2.all([
6985
- {
6986
- memcmp: {
6987
- bytes: _bytes.bs58.encode(userPubKey.toBuffer()),
6988
- offset: 8 + 32
7056
+ ]),
7057
+ program.account.positionV2.all([
7058
+ {
7059
+ memcmp: {
7060
+ bytes: _bytes.bs58.encode(userPubKey.toBuffer()),
7061
+ offset: 8 + 32
7062
+ }
6989
7063
  }
6990
- }
7064
+ ])
6991
7065
  ]);
6992
7066
  const binArrayPubkeySet = /* @__PURE__ */ new Set();
6993
7067
  const lbPairSet = /* @__PURE__ */ new Set();
@@ -8164,31 +8238,8 @@ var DLMM = class {
8164
8238
  tokenXProgram: _spltoken.TOKEN_PROGRAM_ID,
8165
8239
  tokenYProgram: _spltoken.TOKEN_PROGRAM_ID
8166
8240
  };
8167
- const oneSideLiquidityParams = {
8168
- amount: totalXAmount.isZero() ? totalYAmount : totalXAmount,
8169
- activeId,
8170
- maxActiveBinSlippage,
8171
- strategyParameters
8172
- };
8173
- const oneSideAddLiquidityAccounts = {
8174
- binArrayLower,
8175
- binArrayUpper,
8176
- lbPair: this.pubkey,
8177
- binArrayBitmapExtension: null,
8178
- sender: user,
8179
- position: positionPubKey,
8180
- reserve: totalXAmount.isZero() ? this.lbPair.reserveY : this.lbPair.reserveX,
8181
- tokenMint: totalXAmount.isZero() ? this.lbPair.tokenYMint : this.lbPair.tokenXMint,
8182
- tokenProgram: _spltoken.TOKEN_PROGRAM_ID,
8183
- userToken: totalXAmount.isZero() ? userTokenY : userTokenX
8184
- };
8185
- const isOneSideDeposit = totalXAmount.isZero() || totalYAmount.isZero();
8186
- const programMethod = isOneSideDeposit ? this.program.methods.addLiquidityByStrategyOneSide(
8187
- oneSideLiquidityParams
8188
- ) : this.program.methods.addLiquidityByStrategy(liquidityParams);
8189
- const createPositionTx = await programMethod.accounts(
8190
- isOneSideDeposit ? oneSideAddLiquidityAccounts : addLiquidityAccounts
8191
- ).preInstructions(preInstructions).postInstructions(postInstructions).transaction();
8241
+ const programMethod = this.program.methods.addLiquidityByStrategy(liquidityParams);
8242
+ const createPositionTx = await programMethod.accounts(addLiquidityAccounts).preInstructions(preInstructions).postInstructions(postInstructions).transaction();
8192
8243
  const { blockhash, lastValidBlockHeight } = await this.program.provider.connection.getLatestBlockhash("confirmed");
8193
8244
  return new (0, _web3js.Transaction)({
8194
8245
  blockhash,
@@ -8513,31 +8564,8 @@ var DLMM = class {
8513
8564
  tokenXProgram: _spltoken.TOKEN_PROGRAM_ID,
8514
8565
  tokenYProgram: _spltoken.TOKEN_PROGRAM_ID
8515
8566
  };
8516
- const oneSideLiquidityParams = {
8517
- amount: totalXAmount.isZero() ? totalYAmount : totalXAmount,
8518
- activeId,
8519
- maxActiveBinSlippage,
8520
- strategyParameters
8521
- };
8522
- const oneSideAddLiquidityAccounts = {
8523
- binArrayLower,
8524
- binArrayUpper,
8525
- lbPair: this.pubkey,
8526
- binArrayBitmapExtension: null,
8527
- sender: user,
8528
- position: positionPubKey,
8529
- reserve: totalXAmount.isZero() ? this.lbPair.reserveY : this.lbPair.reserveX,
8530
- tokenMint: totalXAmount.isZero() ? this.lbPair.tokenYMint : this.lbPair.tokenXMint,
8531
- tokenProgram: _spltoken.TOKEN_PROGRAM_ID,
8532
- userToken: totalXAmount.isZero() ? userTokenY : userTokenX
8533
- };
8534
- const isOneSideDeposit = totalXAmount.isZero() || totalYAmount.isZero();
8535
- const programMethod = isOneSideDeposit ? this.program.methods.addLiquidityByStrategyOneSide(
8536
- oneSideLiquidityParams
8537
- ) : this.program.methods.addLiquidityByStrategy(liquidityParams);
8538
- const createPositionTx = await programMethod.accounts(
8539
- isOneSideDeposit ? oneSideAddLiquidityAccounts : addLiquidityAccounts
8540
- ).preInstructions(preInstructions).postInstructions(postInstructions).transaction();
8567
+ const programMethod = this.program.methods.addLiquidityByStrategy(liquidityParams);
8568
+ const createPositionTx = await programMethod.accounts(addLiquidityAccounts).preInstructions(preInstructions).postInstructions(postInstructions).transaction();
8541
8569
  const { blockhash, lastValidBlockHeight } = await this.program.provider.connection.getLatestBlockhash("confirmed");
8542
8570
  return new (0, _web3js.Transaction)({
8543
8571
  blockhash,