@meteora-ag/dlmm 1.7.6 → 1.8.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
@@ -30,7 +30,7 @@ var dlmm_default = {
30
30
  address: "LBUZKhRxPF3XUpBCjp4YzTKgLccjZhTSDM9YuVaPwxo",
31
31
  metadata: {
32
32
  name: "lb_clmm",
33
- version: "0.9.1",
33
+ version: "0.10.1",
34
34
  spec: "0.1.0",
35
35
  description: "Created with Anchor"
36
36
  },
@@ -1547,6 +1547,25 @@ var dlmm_default = {
1547
1547
  ],
1548
1548
  args: []
1549
1549
  },
1550
+ {
1551
+ name: "close_token_badge",
1552
+ discriminator: [108, 146, 86, 110, 179, 254, 10, 104],
1553
+ accounts: [
1554
+ {
1555
+ name: "token_badge",
1556
+ writable: true
1557
+ },
1558
+ {
1559
+ name: "rent_receiver",
1560
+ writable: true
1561
+ },
1562
+ {
1563
+ name: "admin",
1564
+ signer: true
1565
+ }
1566
+ ],
1567
+ args: []
1568
+ },
1550
1569
  {
1551
1570
  name: "create_claim_protocol_fee_operator",
1552
1571
  discriminator: [51, 19, 150, 252, 105, 157, 48, 91],
@@ -1945,6 +1964,72 @@ var dlmm_default = {
1945
1964
  }
1946
1965
  ]
1947
1966
  },
1967
+ {
1968
+ name: "increase_position_length2",
1969
+ discriminator: [255, 210, 204, 71, 115, 137, 225, 113],
1970
+ accounts: [
1971
+ {
1972
+ name: "funder",
1973
+ writable: true,
1974
+ signer: true
1975
+ },
1976
+ {
1977
+ name: "lb_pair",
1978
+ relations: ["position"]
1979
+ },
1980
+ {
1981
+ name: "position",
1982
+ writable: true
1983
+ },
1984
+ {
1985
+ name: "owner",
1986
+ signer: true,
1987
+ relations: ["position"]
1988
+ },
1989
+ {
1990
+ name: "system_program",
1991
+ address: "11111111111111111111111111111111"
1992
+ },
1993
+ {
1994
+ name: "event_authority",
1995
+ pda: {
1996
+ seeds: [
1997
+ {
1998
+ kind: "const",
1999
+ value: [
2000
+ 95,
2001
+ 95,
2002
+ 101,
2003
+ 118,
2004
+ 101,
2005
+ 110,
2006
+ 116,
2007
+ 95,
2008
+ 97,
2009
+ 117,
2010
+ 116,
2011
+ 104,
2012
+ 111,
2013
+ 114,
2014
+ 105,
2015
+ 116,
2016
+ 121
2017
+ ]
2018
+ }
2019
+ ]
2020
+ }
2021
+ },
2022
+ {
2023
+ name: "program"
2024
+ }
2025
+ ],
2026
+ args: [
2027
+ {
2028
+ name: "minimum_upper_bin_id",
2029
+ type: "i32"
2030
+ }
2031
+ ]
2032
+ },
1948
2033
  {
1949
2034
  name: "initialize_bin_array",
1950
2035
  discriminator: [35, 86, 19, 185, 78, 212, 75, 211],
@@ -2844,6 +2929,75 @@ var dlmm_default = {
2844
2929
  }
2845
2930
  ]
2846
2931
  },
2932
+ {
2933
+ name: "initialize_position2",
2934
+ discriminator: [143, 19, 242, 145, 213, 15, 104, 115],
2935
+ accounts: [
2936
+ {
2937
+ name: "payer",
2938
+ writable: true,
2939
+ signer: true
2940
+ },
2941
+ {
2942
+ name: "position",
2943
+ writable: true,
2944
+ signer: true
2945
+ },
2946
+ {
2947
+ name: "lb_pair"
2948
+ },
2949
+ {
2950
+ name: "owner",
2951
+ signer: true
2952
+ },
2953
+ {
2954
+ name: "system_program",
2955
+ address: "11111111111111111111111111111111"
2956
+ },
2957
+ {
2958
+ name: "event_authority",
2959
+ pda: {
2960
+ seeds: [
2961
+ {
2962
+ kind: "const",
2963
+ value: [
2964
+ 95,
2965
+ 95,
2966
+ 101,
2967
+ 118,
2968
+ 101,
2969
+ 110,
2970
+ 116,
2971
+ 95,
2972
+ 97,
2973
+ 117,
2974
+ 116,
2975
+ 104,
2976
+ 111,
2977
+ 114,
2978
+ 105,
2979
+ 116,
2980
+ 121
2981
+ ]
2982
+ }
2983
+ ]
2984
+ }
2985
+ },
2986
+ {
2987
+ name: "program"
2988
+ }
2989
+ ],
2990
+ args: [
2991
+ {
2992
+ name: "lower_bin_id",
2993
+ type: "i32"
2994
+ },
2995
+ {
2996
+ name: "width",
2997
+ type: "i32"
2998
+ }
2999
+ ]
3000
+ },
2847
3001
  {
2848
3002
  name: "initialize_position_by_operator",
2849
3003
  discriminator: [251, 189, 190, 244, 117, 254, 35, 148],
@@ -5312,38 +5466,38 @@ var dlmm_default = {
5312
5466
  {
5313
5467
  kind: "const",
5314
5468
  value: [
5315
- 48,
5316
- 9,
5317
- 89,
5318
- 123,
5319
- 106,
5320
- 114,
5321
- 131,
5322
- 251,
5323
- 50,
5469
+ 8,
5470
+ 234,
5471
+ 192,
5472
+ 109,
5473
+ 87,
5474
+ 125,
5475
+ 190,
5476
+ 55,
5477
+ 129,
5324
5478
  173,
5325
- 254,
5326
- 250,
5327
- 10,
5479
+ 227,
5480
+ 8,
5481
+ 104,
5482
+ 201,
5483
+ 104,
5484
+ 13,
5485
+ 31,
5486
+ 178,
5487
+ 74,
5328
5488
  80,
5329
- 160,
5330
- 84,
5331
- 143,
5332
- 100,
5333
- 81,
5334
- 249,
5335
- 134,
5336
- 112,
5337
- 30,
5338
- 213,
5339
- 50,
5340
- 166,
5341
- 239,
5489
+ 54,
5490
+ 14,
5491
+ 77,
5342
5492
  78,
5343
- 53,
5344
- 175,
5345
- 188,
5346
- 85
5493
+ 226,
5494
+ 57,
5495
+ 47,
5496
+ 122,
5497
+ 166,
5498
+ 165,
5499
+ 57,
5500
+ 144
5347
5501
  ]
5348
5502
  },
5349
5503
  {
@@ -5402,38 +5556,38 @@ var dlmm_default = {
5402
5556
  {
5403
5557
  kind: "const",
5404
5558
  value: [
5405
- 48,
5406
- 9,
5407
- 89,
5408
- 123,
5409
- 106,
5410
- 114,
5411
- 131,
5412
- 251,
5413
- 50,
5559
+ 8,
5560
+ 234,
5561
+ 192,
5562
+ 109,
5563
+ 87,
5564
+ 125,
5565
+ 190,
5566
+ 55,
5567
+ 129,
5414
5568
  173,
5415
- 254,
5416
- 250,
5417
- 10,
5569
+ 227,
5570
+ 8,
5571
+ 104,
5572
+ 201,
5573
+ 104,
5574
+ 13,
5575
+ 31,
5576
+ 178,
5577
+ 74,
5418
5578
  80,
5419
- 160,
5420
- 84,
5421
- 143,
5422
- 100,
5423
- 81,
5424
- 249,
5425
- 134,
5426
- 112,
5427
- 30,
5428
- 213,
5429
- 50,
5430
- 166,
5431
- 239,
5579
+ 54,
5580
+ 14,
5581
+ 77,
5432
5582
  78,
5433
- 53,
5434
- 175,
5435
- 188,
5436
- 85
5583
+ 226,
5584
+ 57,
5585
+ 47,
5586
+ 122,
5587
+ 166,
5588
+ 165,
5589
+ 57,
5590
+ 144
5437
5591
  ]
5438
5592
  },
5439
5593
  {
@@ -5579,10 +5733,18 @@ var dlmm_default = {
5579
5733
  name: "ClaimFee",
5580
5734
  discriminator: [75, 122, 154, 48, 140, 74, 123, 163]
5581
5735
  },
5736
+ {
5737
+ name: "ClaimFee2",
5738
+ discriminator: [232, 171, 242, 97, 58, 77, 35, 45]
5739
+ },
5582
5740
  {
5583
5741
  name: "ClaimReward",
5584
5742
  discriminator: [148, 116, 134, 204, 22, 171, 85, 95]
5585
5743
  },
5744
+ {
5745
+ name: "ClaimReward2",
5746
+ discriminator: [27, 143, 244, 33, 80, 43, 110, 146]
5747
+ },
5586
5748
  {
5587
5749
  name: "CompositionFee",
5588
5750
  discriminator: [128, 151, 123, 106, 17, 102, 113, 142]
@@ -6089,6 +6251,31 @@ var dlmm_default = {
6089
6251
  code: 6084,
6090
6252
  name: "InvalidRewardAccounts",
6091
6253
  msg: "Invalid reward accounts"
6254
+ },
6255
+ {
6256
+ code: 6085,
6257
+ name: "UndeterminedError",
6258
+ msg: "Undetermined error"
6259
+ },
6260
+ {
6261
+ code: 6086,
6262
+ name: "ReallocExceedMaxLengthPerInstruction",
6263
+ msg: "Realloc exceed max length per instruction"
6264
+ },
6265
+ {
6266
+ code: 6087,
6267
+ name: "InvalidBaseFeeMantissa",
6268
+ msg: "Mantissa cannot more than two significant digits"
6269
+ },
6270
+ {
6271
+ code: 6088,
6272
+ name: "InvalidPositionOwner",
6273
+ msg: "Invalid position owner"
6274
+ },
6275
+ {
6276
+ code: 6089,
6277
+ name: "InvalidPoolAddress",
6278
+ msg: "Invalid pool address"
6092
6279
  }
6093
6280
  ],
6094
6281
  types: [
@@ -6532,6 +6719,38 @@ var dlmm_default = {
6532
6719
  ]
6533
6720
  }
6534
6721
  },
6722
+ {
6723
+ name: "ClaimFee2",
6724
+ type: {
6725
+ kind: "struct",
6726
+ fields: [
6727
+ {
6728
+ name: "lb_pair",
6729
+ type: "pubkey"
6730
+ },
6731
+ {
6732
+ name: "position",
6733
+ type: "pubkey"
6734
+ },
6735
+ {
6736
+ name: "owner",
6737
+ type: "pubkey"
6738
+ },
6739
+ {
6740
+ name: "fee_x",
6741
+ type: "u64"
6742
+ },
6743
+ {
6744
+ name: "fee_y",
6745
+ type: "u64"
6746
+ },
6747
+ {
6748
+ name: "active_bin_id",
6749
+ type: "i32"
6750
+ }
6751
+ ]
6752
+ }
6753
+ },
6535
6754
  {
6536
6755
  name: "ClaimFeeOperator",
6537
6756
  docs: ["Parameter that set by the protocol"],
@@ -6585,6 +6804,38 @@ var dlmm_default = {
6585
6804
  ]
6586
6805
  }
6587
6806
  },
6807
+ {
6808
+ name: "ClaimReward2",
6809
+ type: {
6810
+ kind: "struct",
6811
+ fields: [
6812
+ {
6813
+ name: "lb_pair",
6814
+ type: "pubkey"
6815
+ },
6816
+ {
6817
+ name: "position",
6818
+ type: "pubkey"
6819
+ },
6820
+ {
6821
+ name: "owner",
6822
+ type: "pubkey"
6823
+ },
6824
+ {
6825
+ name: "reward_index",
6826
+ type: "u64"
6827
+ },
6828
+ {
6829
+ name: "total_reward",
6830
+ type: "u64"
6831
+ },
6832
+ {
6833
+ name: "active_bin_id",
6834
+ type: "i32"
6835
+ }
6836
+ ]
6837
+ }
6838
+ },
6588
6839
  {
6589
6840
  name: "CompositionFee",
6590
6841
  type: {
@@ -8257,11 +8508,16 @@ var dlmm_default = {
8257
8508
  docs: ["threshold for deposit token y"],
8258
8509
  type: "u64"
8259
8510
  },
8511
+ {
8512
+ name: "shrink_mode",
8513
+ docs: ["shrink mode"],
8514
+ type: "u8"
8515
+ },
8260
8516
  {
8261
8517
  name: "padding",
8262
8518
  docs: ["padding 32 bytes for future usage"],
8263
8519
  type: {
8264
- array: ["u8", 32]
8520
+ array: ["u8", 31]
8265
8521
  }
8266
8522
  },
8267
8523
  {
@@ -8302,6 +8558,14 @@ var dlmm_default = {
8302
8558
  name: "position",
8303
8559
  type: "pubkey"
8304
8560
  },
8561
+ {
8562
+ name: "owner",
8563
+ type: "pubkey"
8564
+ },
8565
+ {
8566
+ name: "active_bin_id",
8567
+ type: "i32"
8568
+ },
8305
8569
  {
8306
8570
  name: "x_withdrawn_amount",
8307
8571
  type: "u64"
@@ -8496,17 +8760,17 @@ var dlmm_default = {
8496
8760
  },
8497
8761
  {
8498
8762
  name: "reward_duration",
8499
- docs: ["TODO check whether we need to store it in pool"],
8763
+ docs: ["LM reward duration in seconds."],
8500
8764
  type: "u64"
8501
8765
  },
8502
8766
  {
8503
8767
  name: "reward_duration_end",
8504
- docs: ["TODO check whether we need to store it in pool"],
8768
+ docs: ["LM reward duration end time."],
8505
8769
  type: "u64"
8506
8770
  },
8507
8771
  {
8508
8772
  name: "reward_rate",
8509
- docs: ["TODO check whether we need to store it in pool"],
8773
+ docs: ["LM reward rate"],
8510
8774
  type: "u128"
8511
8775
  },
8512
8776
  {
@@ -9072,7 +9336,7 @@ var dlmm_default = {
9072
9336
  {
9073
9337
  name: "MAX_RESIZE_LENGTH",
9074
9338
  type: "u64",
9075
- value: "70"
9339
+ value: "91"
9076
9340
  },
9077
9341
  {
9078
9342
  name: "MAX_REWARD_BIN_SPLIT",
@@ -9151,6 +9415,10 @@ var LBCLMM_PROGRAM_IDS = {
9151
9415
  localhost: "LbVRzDTvBDEcrthxfZ4RL6yiq3uZw8bS6MwtdY6UhFQ",
9152
9416
  "mainnet-beta": "LBUZKhRxPF3XUpBCjp4YzTKgLccjZhTSDM9YuVaPwxo"
9153
9417
  };
9418
+ var ALT_ADDRESS = {
9419
+ "mainnet-beta": "JA5F83HUK9L78Y12TRLCsJZbu3Tv8pCK1GfK8mVNp1sz",
9420
+ devnet: "BD6E8oYV52P829MxDq3sEtqWKJrHh9pDSUHeaWR1jRBs"
9421
+ };
9154
9422
  var ADMIN = {
9155
9423
  devnet: "6WaLrrRfReGKBYUSkmx2K6AuT21ida4j8at2SUiZdXu8",
9156
9424
  localhost: "bossj3JvwiNK7pvjr149DqdtJxf2gdygbcmEPTkb2F1"
@@ -9304,6 +9572,13 @@ var PairType = /* @__PURE__ */ ((PairType2) => {
9304
9572
  PairType2[PairType2["Permissioned"] = 1] = "Permissioned";
9305
9573
  return PairType2;
9306
9574
  })(PairType || {});
9575
+ var ShrinkMode = /* @__PURE__ */ ((ShrinkMode2) => {
9576
+ ShrinkMode2[ShrinkMode2["ShrinkBoth"] = 0] = "ShrinkBoth";
9577
+ ShrinkMode2[ShrinkMode2["NoShrinkLeft"] = 1] = "NoShrinkLeft";
9578
+ ShrinkMode2[ShrinkMode2["NoShrinkRight"] = 2] = "NoShrinkRight";
9579
+ ShrinkMode2[ShrinkMode2["NoShrinkBoth"] = 3] = "NoShrinkBoth";
9580
+ return ShrinkMode2;
9581
+ })(ShrinkMode || {});
9307
9582
  var Strategy = {
9308
9583
  SpotBalanced: { spotBalanced: {} },
9309
9584
  CurveBalanced: { curveBalanced: {} },
@@ -9390,6 +9665,7 @@ var ResizeSide = /* @__PURE__ */ ((ResizeSide2) => {
9390
9665
  var MEMO_PROGRAM_ID = new PublicKey2(
9391
9666
  "MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"
9392
9667
  );
9668
+ var REBALANCE_POSITION_PADDING = Array(31).fill(0);
9393
9669
 
9394
9670
  // src/dlmm/helpers/binArray.ts
9395
9671
  import { BN as BN8 } from "@coral-xyz/anchor";
@@ -11753,7 +12029,7 @@ function simulateDepositBin(binId, binStep, amountX, amountY, bin) {
11753
12029
  amountYIntoBin
11754
12030
  };
11755
12031
  }
11756
- var RebalancePosition = class {
12032
+ var RebalancePosition = class _RebalancePosition {
11757
12033
  address;
11758
12034
  lowerBinId;
11759
12035
  upperBinId;
@@ -11807,7 +12083,7 @@ var RebalancePosition = class {
11807
12083
  upperBinId
11808
12084
  );
11809
12085
  const activeBin = activeBinArrayState[idx.toNumber()];
11810
- return new RebalancePosition(
12086
+ return new _RebalancePosition(
11811
12087
  positionAddress,
11812
12088
  positionData,
11813
12089
  lbPair,
@@ -12950,8 +13226,7 @@ async function getTokensMintFromPoolAddress(connection, poolAddress, opt) {
12950
13226
  const poolAccount = await program.account.lbPair.fetchNullable(
12951
13227
  new PublicKey8(poolAddress)
12952
13228
  );
12953
- if (!poolAccount)
12954
- throw new Error("Pool account not found");
13229
+ if (!poolAccount) throw new Error("Pool account not found");
12955
13230
  return {
12956
13231
  tokenXMint: poolAccount.tokenXMint,
12957
13232
  tokenYMint: poolAccount.tokenYMint
@@ -13550,8 +13825,7 @@ async function getTokenBalance(conn, tokenAccount) {
13550
13825
  return acc.amount;
13551
13826
  }
13552
13827
  var parseLogs = (eventParser, logs) => {
13553
- if (!logs.length)
13554
- throw new Error("No logs found");
13828
+ if (!logs.length) throw new Error("No logs found");
13555
13829
  for (const event of eventParser?.parseLogs(logs)) {
13556
13830
  return event.data;
13557
13831
  }
@@ -13603,17 +13877,22 @@ async function chunkedGetMultipleAccountInfos(connection, pks, chunkSize = 100)
13603
13877
  )).flat();
13604
13878
  return accountInfos;
13605
13879
  }
13606
- var getEstimatedComputeUnitUsageWithBuffer = async (connection, instructions, feePayer, buffer) => {
13880
+ var getEstimatedComputeUnitUsageWithBuffer = async (connection, instructions, feePayer, buffer, altAddress) => {
13607
13881
  if (!buffer) {
13608
13882
  buffer = 0.1;
13609
13883
  }
13610
13884
  buffer = Math.max(0, buffer);
13611
13885
  buffer = Math.min(1, buffer);
13886
+ const altAccounts = [];
13887
+ if (altAddress) {
13888
+ const altAccountInfo = await connection.getAddressLookupTable(altAddress);
13889
+ altAccounts.push(altAccountInfo.value);
13890
+ }
13612
13891
  const estimatedComputeUnitUsage = await getSimulationComputeUnits(
13613
13892
  connection,
13614
13893
  instructions,
13615
13894
  feePayer,
13616
- []
13895
+ altAccounts
13617
13896
  );
13618
13897
  let extraComputeUnitBuffer = estimatedComputeUnitUsage * buffer;
13619
13898
  if (extraComputeUnitBuffer > MAX_CU_BUFFER) {
@@ -13623,12 +13902,13 @@ var getEstimatedComputeUnitUsageWithBuffer = async (connection, instructions, fe
13623
13902
  }
13624
13903
  return estimatedComputeUnitUsage + extraComputeUnitBuffer;
13625
13904
  };
13626
- var getEstimatedComputeUnitIxWithBuffer = async (connection, instructions, feePayer, buffer) => {
13905
+ var getEstimatedComputeUnitIxWithBuffer = async (connection, instructions, feePayer, buffer, altAddress) => {
13627
13906
  const units = await getEstimatedComputeUnitUsageWithBuffer(
13628
13907
  connection,
13629
13908
  instructions,
13630
13909
  feePayer,
13631
- buffer
13910
+ buffer,
13911
+ altAddress
13632
13912
  ).catch((error) => {
13633
13913
  console.error("Error::getEstimatedComputeUnitUsageWithBuffer", error);
13634
13914
  return 14e5;
@@ -13711,7 +13991,7 @@ function resetUninvolvedLiquidityParams(minDeltaId, maxDeltaId, favorXInActiveId
13711
13991
  deltaY
13712
13992
  };
13713
13993
  }
13714
- async function chunkDepositWithRebalanceEndpoint(dlmm, strategy, slippagePercentage, maxActiveBinSlippage, position, positionMinBinId, positionMaxBinId, liquidityStrategyParameters, owner, payer, simulateCU) {
13994
+ async function chunkDepositWithRebalanceEndpoint(dlmm, strategy, slippagePercentage, maxActiveBinSlippage, position, positionMinBinId, positionMaxBinId, liquidityStrategyParameters, owner, payer, isParallel, skipSolWrappingOperation = false) {
13715
13995
  const { slices, accounts: transferHookAccounts } = dlmm.getPotentialToken2022IxDataAndAccounts(0 /* Liquidity */);
13716
13996
  const userTokenX = getAssociatedTokenAddressSync(
13717
13997
  dlmm.lbPair.tokenXMint,
@@ -13773,12 +14053,14 @@ async function chunkDepositWithRebalanceEndpoint(dlmm, strategy, slippagePercent
13773
14053
  (index) => deriveBinArray(dlmm.pubkey, index, dlmm.program.programId)[0]
13774
14054
  );
13775
14055
  for (const [idx, binArrayPubkey] of binArrayPubkeys.entries()) {
13776
- if (!binArrayOrBitmapInitTracking.has(binArrayPubkey.toBase58())) {
13777
- const initBinArrayIx = await dlmm.program.methods.initializeBinArray(binArrayIndexes[idx]).accountsPartial({
13778
- binArray: binArrayPubkey,
13779
- funder: payer,
13780
- lbPair: dlmm.pubkey
13781
- }).instruction();
14056
+ const initBinArrayIx = await dlmm.program.methods.initializeBinArray(binArrayIndexes[idx]).accountsPartial({
14057
+ binArray: binArrayPubkey,
14058
+ funder: payer,
14059
+ lbPair: dlmm.pubkey
14060
+ }).instruction();
14061
+ if (isParallel) {
14062
+ initBinArrayIxs.push(initBinArrayIx);
14063
+ } else if (!binArrayOrBitmapInitTracking.has(binArrayPubkey.toBase58())) {
13782
14064
  binArrayOrBitmapInitTracking.add(binArrayPubkey.toBase58());
13783
14065
  initBinArrayIxs.push(initBinArrayIx);
13784
14066
  calculatedAddLiquidityCU += DEFAULT_INIT_BIN_ARRAY_CU;
@@ -13846,6 +14128,18 @@ async function chunkDepositWithRebalanceEndpoint(dlmm, strategy, slippagePercent
13846
14128
  totalYAmountIncludeTransferFee,
13847
14129
  slippagePercentage
13848
14130
  );
14131
+ let shrinkMode;
14132
+ if (isParallel) {
14133
+ if (i == 0) {
14134
+ shrinkMode = 2 /* NoShrinkRight */;
14135
+ } else if (i == chunkBinRange.length - 1) {
14136
+ shrinkMode = 1 /* NoShrinkLeft */;
14137
+ } else {
14138
+ shrinkMode = 3 /* NoShrinkBoth */;
14139
+ }
14140
+ } else {
14141
+ shrinkMode = 0 /* ShrinkBoth */;
14142
+ }
13849
14143
  const rebalanceIx = await dlmm.program.methods.rebalanceLiquidity(
13850
14144
  {
13851
14145
  activeId: dlmm.lbPair.activeId,
@@ -13858,7 +14152,8 @@ async function chunkDepositWithRebalanceEndpoint(dlmm, strategy, slippagePercent
13858
14152
  maxDepositYAmount,
13859
14153
  removes: [],
13860
14154
  adds: [addParam],
13861
- padding: Array(32).fill(0)
14155
+ shrinkMode,
14156
+ padding: REBALANCE_POSITION_PADDING
13862
14157
  },
13863
14158
  {
13864
14159
  slices
@@ -13887,26 +14182,34 @@ async function chunkDepositWithRebalanceEndpoint(dlmm, strategy, slippagePercent
13887
14182
  calculatedAddLiquidityCU += DEFAULT_ADD_LIQUIDITY_CU;
13888
14183
  const addLiquidityIxs = [];
13889
14184
  addLiquidityIxs.push(...initBitmapIxs, ...initBinArrayIxs);
13890
- if (dlmm.tokenX.publicKey.equals(NATIVE_MINT)) {
14185
+ if (isParallel) {
14186
+ addLiquidityIxs.push(createUserTokenXIx);
14187
+ addLiquidityIxs.push(createUserTokenYIx);
14188
+ }
14189
+ if (dlmm.tokenX.publicKey.equals(NATIVE_MINT) && !skipSolWrappingOperation) {
13891
14190
  const wrapSOLIx = wrapSOLInstruction(
13892
14191
  owner,
13893
14192
  userTokenX,
13894
14193
  BigInt(totalXAmount.toString())
13895
14194
  );
13896
- addLiquidityIxs.push(createUserTokenXIx);
14195
+ if (!isParallel) {
14196
+ addLiquidityIxs.push(createUserTokenXIx);
14197
+ }
13897
14198
  addLiquidityIxs.push(...wrapSOLIx);
13898
14199
  }
13899
- if (dlmm.tokenY.publicKey.equals(NATIVE_MINT)) {
14200
+ if (dlmm.tokenY.publicKey.equals(NATIVE_MINT) && !skipSolWrappingOperation) {
13900
14201
  const wrapSOLIx = wrapSOLInstruction(
13901
14202
  owner,
13902
14203
  userTokenY,
13903
14204
  BigInt(totalYAmount.toString())
13904
14205
  );
13905
- addLiquidityIxs.push(createUserTokenYIx);
14206
+ if (!isParallel) {
14207
+ addLiquidityIxs.push(createUserTokenYIx);
14208
+ }
13906
14209
  addLiquidityIxs.push(...wrapSOLIx);
13907
14210
  }
13908
14211
  addLiquidityIxs.push(rebalanceIx);
13909
- if (dlmm.tokenX.publicKey.equals(NATIVE_MINT) && !totalXAmount.isZero()) {
14212
+ if (dlmm.tokenX.publicKey.equals(NATIVE_MINT) && !totalXAmount.isZero() && !skipSolWrappingOperation) {
13910
14213
  addLiquidityIxs.push(
13911
14214
  createCloseAccountInstruction(
13912
14215
  userTokenX,
@@ -13917,7 +14220,7 @@ async function chunkDepositWithRebalanceEndpoint(dlmm, strategy, slippagePercent
13917
14220
  )
13918
14221
  );
13919
14222
  }
13920
- if (dlmm.tokenY.publicKey.equals(NATIVE_MINT) && !totalYAmount.isZero()) {
14223
+ if (dlmm.tokenY.publicKey.equals(NATIVE_MINT) && !totalYAmount.isZero() && !skipSolWrappingOperation) {
13921
14224
  addLiquidityIxs.push(
13922
14225
  createCloseAccountInstruction(
13923
14226
  userTokenY,
@@ -13928,14 +14231,7 @@ async function chunkDepositWithRebalanceEndpoint(dlmm, strategy, slippagePercent
13928
14231
  )
13929
14232
  );
13930
14233
  }
13931
- if (simulateCU) {
13932
- const cuIx = await getEstimatedComputeUnitIxWithBuffer(
13933
- dlmm.program.provider.connection,
13934
- addLiquidityIxs,
13935
- payer
13936
- );
13937
- addLiquidityIxs.unshift(cuIx);
13938
- } else {
14234
+ if (!isParallel) {
13939
14235
  addLiquidityIxs.unshift(
13940
14236
  ComputeBudgetProgram2.setComputeUnitLimit({
13941
14237
  units: Math.min(calculatedAddLiquidityCU, MAX_CU)
@@ -14092,7 +14388,7 @@ var BalancedStrategyBuilder = class {
14092
14388
  };
14093
14389
 
14094
14390
  // src/dlmm/index.ts
14095
- var DLMM = class {
14391
+ var DLMM = class _DLMM {
14096
14392
  constructor(pubkey, program, lbPair, binArrayBitmapExtension, tokenX, tokenY, rewards, clock, opt) {
14097
14393
  this.pubkey = pubkey;
14098
14394
  this.program = program;
@@ -14190,8 +14486,7 @@ var DLMM = class {
14190
14486
  program.programId
14191
14487
  );
14192
14488
  const account = await program.account.lbPair.fetchNullable(lpPair);
14193
- if (account)
14194
- return lpPair;
14489
+ if (account) return lpPair;
14195
14490
  return null;
14196
14491
  } catch (error) {
14197
14492
  return null;
@@ -14239,8 +14534,7 @@ var DLMM = class {
14239
14534
  );
14240
14535
  }
14241
14536
  const clockAccountInfoBuffer = accountsInfo[2]?.data;
14242
- if (!clockAccountInfoBuffer)
14243
- throw new Error(`Clock account not found`);
14537
+ if (!clockAccountInfoBuffer) throw new Error(`Clock account not found`);
14244
14538
  const clock = ClockLayout.decode(clockAccountInfoBuffer);
14245
14539
  accountsToFetch = [
14246
14540
  lbPairAccInfo.reserveX,
@@ -14355,7 +14649,7 @@ var DLMM = class {
14355
14649
  owner: reward1MintAccount.owner,
14356
14650
  transferHookAccountMetas: reward1TransferHook
14357
14651
  } : null;
14358
- return new DLMM(
14652
+ return new _DLMM(
14359
14653
  dlmm,
14360
14654
  program,
14361
14655
  lbPairAccInfo,
@@ -14392,8 +14686,7 @@ var DLMM = class {
14392
14686
  );
14393
14687
  const clockAccount = accountsInfo.pop();
14394
14688
  const clockAccountInfoBuffer = clockAccount?.data;
14395
- if (!clockAccountInfoBuffer)
14396
- throw new Error(`Clock account not found`);
14689
+ if (!clockAccountInfoBuffer) throw new Error(`Clock account not found`);
14397
14690
  const clock = ClockLayout.decode(clockAccountInfoBuffer);
14398
14691
  const lbPairArraysMap = /* @__PURE__ */ new Map();
14399
14692
  for (let i = 0; i < dlmmList.length; i++) {
@@ -14557,7 +14850,7 @@ var DLMM = class {
14557
14850
  lbPairState.rewardInfos[1].mint.toBase58()
14558
14851
  ) ?? []
14559
14852
  } : null;
14560
- return new DLMM(
14853
+ return new _DLMM(
14561
14854
  lbPair,
14562
14855
  program,
14563
14856
  lbPairState,
@@ -14763,7 +15056,7 @@ var DLMM = class {
14763
15056
  transferHookAccountMetas: []
14764
15057
  // No need, the TokenReserve created just for processing position info, doesn't require any transaction
14765
15058
  };
14766
- const positionData = await DLMM.processPosition(
15059
+ const positionData = await _DLMM.processPosition(
14767
15060
  program,
14768
15061
  lbPairAcc,
14769
15062
  clock,
@@ -14866,7 +15159,7 @@ var DLMM = class {
14866
15159
  }
14867
15160
  const positionsLockInfo = await Promise.all(
14868
15161
  positionsWithLock.map(async (position) => {
14869
- const positionData = await DLMM.processPosition(
15162
+ const positionData = await _DLMM.processPosition(
14870
15163
  this.program,
14871
15164
  this.lbPair,
14872
15165
  clock,
@@ -15366,8 +15659,7 @@ var DLMM = class {
15366
15659
  this.lbPair,
15367
15660
  this.binArrayBitmapExtension?.account ?? null
15368
15661
  );
15369
- if (binArrayIndex === null)
15370
- shouldStop = true;
15662
+ if (binArrayIndex === null) shouldStop = true;
15371
15663
  else {
15372
15664
  const [binArrayPubKey] = deriveBinArray(
15373
15665
  this.pubkey,
@@ -15378,8 +15670,7 @@ var DLMM = class {
15378
15670
  const [lowerBinId, upperBinId] = getBinArrayLowerUpperBinId(binArrayIndex);
15379
15671
  activeIdToLoop = swapForY ? lowerBinId.toNumber() - 1 : upperBinId.toNumber() + 1;
15380
15672
  }
15381
- if (binArraysPubkey.size === count)
15382
- shouldStop = true;
15673
+ if (binArraysPubkey.size === count) shouldStop = true;
15383
15674
  }
15384
15675
  const accountsToFetch = Array.from(binArraysPubkey).map(
15385
15676
  (pubkey) => new PublicKey10(pubkey)
@@ -15428,7 +15719,7 @@ var DLMM = class {
15428
15719
  */
15429
15720
  getFeeInfo() {
15430
15721
  const { baseFactor, protocolShare } = this.lbPair.parameters;
15431
- const { baseFeeRatePercentage, maxFeeRatePercentage } = DLMM.calculateFeeInfo(
15722
+ const { baseFeeRatePercentage, maxFeeRatePercentage } = _DLMM.calculateFeeInfo(
15432
15723
  baseFactor,
15433
15724
  this.lbPair.binStep,
15434
15725
  this.lbPair.parameters.baseFeePowerFactor
@@ -15449,13 +15740,13 @@ var DLMM = class {
15449
15740
  let activeId = new BN21(this.lbPair.activeId);
15450
15741
  const sParameters3 = this.lbPair.parameters;
15451
15742
  const currentTimestamp = Date.now() / 1e3;
15452
- DLMM.updateReference(
15743
+ _DLMM.updateReference(
15453
15744
  activeId.toNumber(),
15454
15745
  vParameterClone,
15455
15746
  sParameters3,
15456
15747
  currentTimestamp
15457
15748
  );
15458
- DLMM.updateVolatilityAccumulator(
15749
+ _DLMM.updateVolatilityAccumulator(
15459
15750
  vParameterClone,
15460
15751
  sParameters3,
15461
15752
  activeId.toNumber()
@@ -15559,7 +15850,7 @@ var DLMM = class {
15559
15850
  * @returns {string} price per Lamport of bin
15560
15851
  */
15561
15852
  toPricePerLamport(price) {
15562
- return DLMM.getPricePerLamport(
15853
+ return _DLMM.getPricePerLamport(
15563
15854
  this.tokenX.mint.decimals,
15564
15855
  this.tokenY.mint.decimals,
15565
15856
  price
@@ -15604,7 +15895,7 @@ var DLMM = class {
15604
15895
  * value should be used.
15605
15896
  */
15606
15897
  getBinIdFromPrice(price, min) {
15607
- return DLMM.getBinIdFromPrice(price, this.lbPair.binStep, min);
15898
+ return _DLMM.getBinIdFromPrice(price, this.lbPair.binStep, min);
15608
15899
  }
15609
15900
  /**
15610
15901
  * The function `getPositionsByUserAndLbPair` retrieves positions by user and LB pair, including
@@ -15688,7 +15979,7 @@ var DLMM = class {
15688
15979
  positions.map(async (position) => {
15689
15980
  return {
15690
15981
  publicKey: position.address(),
15691
- positionData: await DLMM.processPosition(
15982
+ positionData: await _DLMM.processPosition(
15692
15983
  this.program,
15693
15984
  this.lbPair,
15694
15985
  clock,
@@ -15876,7 +16167,7 @@ var DLMM = class {
15876
16167
  }
15877
16168
  return {
15878
16169
  publicKey: positionPubKey,
15879
- positionData: await DLMM.processPosition(
16170
+ positionData: await _DLMM.processPosition(
15880
16171
  this.program,
15881
16172
  this.lbPair,
15882
16173
  clock,
@@ -15890,6 +16181,112 @@ var DLMM = class {
15890
16181
  version: position.version()
15891
16182
  };
15892
16183
  }
16184
+ /**
16185
+ * Creates multiple positions and adds liquidity by strategy. It allow parallel execution of transactions.
16186
+ * @param positionKeypairGenerator A function that generates a specified number of keypairs.
16187
+ * @param totalXAmount The total amount of token X to be added.
16188
+ * @param totalYAmount The total amount of token Y to be added.
16189
+ * @param strategy The strategy for adding liquidity.
16190
+ * @param owner The owner of the position.
16191
+ * @param payer The payer of the transaction.
16192
+ * @param slippagePercentage The slippage percentage for adding liquidity.
16193
+ * @returns An object with two properties: `initPositionIxs` and `addLiquidityIxs`.
16194
+ */
16195
+ async initializeMultiplePositionAndAddLiquidityByStrategy2(positionKeypairGenerator, totalXAmount, totalYAmount, strategy, owner, payer, slippagePercentage, altAddress) {
16196
+ const maxActiveBinSlippage = getAndCapMaxActiveBinSlippage(
16197
+ slippagePercentage,
16198
+ this.lbPair.binStep,
16199
+ MAX_ACTIVE_BIN_SLIPPAGE
16200
+ );
16201
+ const { minBinId, maxBinId } = strategy;
16202
+ const binCount = getBinCount(minBinId, maxBinId);
16203
+ const defaultAltAddressString = altAddress ?? ALT_ADDRESS[this.opt?.cluster];
16204
+ if (defaultAltAddressString) {
16205
+ altAddress = new PublicKey10(defaultAltAddressString);
16206
+ }
16207
+ const maxResizeIxAllowed = altAddress ? 5 : 3;
16208
+ const maxBinPerParallelizedPosition = DEFAULT_BIN_PER_POSITION.toNumber() + MAX_RESIZE_LENGTH.toNumber() * maxResizeIxAllowed;
16209
+ const positionCount = Math.ceil(binCount / maxBinPerParallelizedPosition);
16210
+ const positionKeypairs = await positionKeypairGenerator(positionCount);
16211
+ const liquidityStrategyParameters = buildLiquidityStrategyParameters(
16212
+ totalXAmount,
16213
+ totalYAmount,
16214
+ new BN21(minBinId - this.lbPair.activeId),
16215
+ new BN21(maxBinId - this.lbPair.activeId),
16216
+ new BN21(this.lbPair.binStep),
16217
+ strategy.singleSidedX,
16218
+ new BN21(this.lbPair.activeId),
16219
+ getLiquidityStrategyParameterBuilder(strategy.strategyType)
16220
+ );
16221
+ let startBinId = minBinId;
16222
+ const response = { instructionsByPositions: [], lookupTableAddress: altAddress };
16223
+ for (const position of positionKeypairs) {
16224
+ const txsIxs = [];
16225
+ const endBinId = Math.min(
16226
+ startBinId + maxBinPerParallelizedPosition - 1,
16227
+ maxBinId
16228
+ );
16229
+ const finalPositionWidth = endBinId - startBinId + 1;
16230
+ const initialPositionWidth = finalPositionWidth > DEFAULT_BIN_PER_POSITION.toNumber() ? DEFAULT_BIN_PER_POSITION.toNumber() : finalPositionWidth;
16231
+ const initPositionIx = await this.program.methods.initializePosition2(startBinId, initialPositionWidth).accountsPartial({
16232
+ position: position.publicKey,
16233
+ lbPair: this.pubkey,
16234
+ owner,
16235
+ payer
16236
+ }).instruction();
16237
+ const extendPositionIxs = [];
16238
+ let currentEndBinId = startBinId + initialPositionWidth - 1;
16239
+ while (true) {
16240
+ if (currentEndBinId == endBinId) break;
16241
+ currentEndBinId = Math.min(
16242
+ currentEndBinId + MAX_RESIZE_LENGTH.toNumber(),
16243
+ endBinId
16244
+ );
16245
+ const increaseLengthIx = await this.program.methods.increasePositionLength2(currentEndBinId).accountsPartial({
16246
+ lbPair: this.pubkey,
16247
+ position: position.publicKey,
16248
+ funder: payer,
16249
+ owner
16250
+ }).instruction();
16251
+ extendPositionIxs.push(increaseLengthIx);
16252
+ }
16253
+ const addLiquidityIxs = await chunkDepositWithRebalanceEndpoint(
16254
+ this,
16255
+ strategy,
16256
+ slippagePercentage,
16257
+ maxActiveBinSlippage,
16258
+ position.publicKey,
16259
+ startBinId,
16260
+ endBinId,
16261
+ liquidityStrategyParameters,
16262
+ owner,
16263
+ payer,
16264
+ true,
16265
+ this.opt?.skipSolWrappingOperation
16266
+ );
16267
+ for (const instructions of addLiquidityIxs) {
16268
+ const txIxs = [];
16269
+ txIxs.push(initPositionIx);
16270
+ txIxs.push(...extendPositionIxs);
16271
+ txIxs.push(...instructions);
16272
+ const setCuIx = await getEstimatedComputeUnitIxWithBuffer(
16273
+ this.program.provider.connection,
16274
+ txIxs,
16275
+ payer,
16276
+ 0.1,
16277
+ altAddress
16278
+ );
16279
+ txIxs.unshift(setCuIx);
16280
+ txsIxs.push(txIxs);
16281
+ }
16282
+ response.instructionsByPositions.push({
16283
+ positionKeypair: position,
16284
+ transactionInstructions: txsIxs
16285
+ });
16286
+ startBinId = endBinId + 1;
16287
+ }
16288
+ return response;
16289
+ }
15893
16290
  /**
15894
16291
  * Creates multiple positions and adds liquidity by strategy without chainsaw issues.
15895
16292
  * @param positionKeypairGenerator A function that generates a specified number of keypairs.
@@ -15985,7 +16382,8 @@ var DLMM = class {
15985
16382
  liquidityStrategyParameters,
15986
16383
  owner,
15987
16384
  payer,
15988
- false
16385
+ false,
16386
+ this.opt?.skipSolWrappingOperation
15989
16387
  );
15990
16388
  instructionsByPositions.push({
15991
16389
  positionKeypair: position,
@@ -16048,7 +16446,8 @@ var DLMM = class {
16048
16446
  liquidityStrategyParameters,
16049
16447
  user,
16050
16448
  user,
16051
- true
16449
+ true,
16450
+ this.opt?.skipSolWrappingOperation
16052
16451
  );
16053
16452
  const latestBlockhashInfo = await this.program.provider.connection.getLatestBlockhash();
16054
16453
  return chunkedAddLiquidityIx.map((ixs) => {
@@ -16122,7 +16521,7 @@ var DLMM = class {
16122
16521
  ]);
16123
16522
  createPayerTokenXIx && preInstructions.push(createPayerTokenXIx);
16124
16523
  createPayerTokenYIx && preInstructions.push(createPayerTokenYIx);
16125
- if (this.tokenX.publicKey.equals(NATIVE_MINT2) && !totalXAmount.isZero()) {
16524
+ if (this.tokenX.publicKey.equals(NATIVE_MINT2) && !totalXAmount.isZero() && !this.opt?.skipSolWrappingOperation) {
16126
16525
  const wrapSOLIx = wrapSOLInstruction(
16127
16526
  user,
16128
16527
  userTokenX,
@@ -16130,7 +16529,7 @@ var DLMM = class {
16130
16529
  );
16131
16530
  preInstructions.push(...wrapSOLIx);
16132
16531
  }
16133
- if (this.tokenY.publicKey.equals(NATIVE_MINT2) && !totalYAmount.isZero()) {
16532
+ if (this.tokenY.publicKey.equals(NATIVE_MINT2) && !totalYAmount.isZero() && !this.opt?.skipSolWrappingOperation) {
16134
16533
  const wrapSOLIx = wrapSOLInstruction(
16135
16534
  user,
16136
16535
  userTokenY,
@@ -16142,7 +16541,7 @@ var DLMM = class {
16142
16541
  if ([
16143
16542
  this.tokenX.publicKey.toBase58(),
16144
16543
  this.tokenY.publicKey.toBase58()
16145
- ].includes(NATIVE_MINT2.toBase58())) {
16544
+ ].includes(NATIVE_MINT2.toBase58()) && !this.opt?.skipSolWrappingOperation) {
16146
16545
  const closeWrappedSOLIx = await unwrapSOLInstruction(user);
16147
16546
  closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
16148
16547
  }
@@ -16275,7 +16674,7 @@ var DLMM = class {
16275
16674
  ]);
16276
16675
  createPayerTokenXIx && preInstructions.push(createPayerTokenXIx);
16277
16676
  createPayerTokenYIx && preInstructions.push(createPayerTokenYIx);
16278
- if (this.tokenX.publicKey.equals(NATIVE_MINT2) && !totalXAmount.isZero()) {
16677
+ if (this.tokenX.publicKey.equals(NATIVE_MINT2) && !totalXAmount.isZero() && !this.opt?.skipSolWrappingOperation) {
16279
16678
  const wrapSOLIx = wrapSOLInstruction(
16280
16679
  user,
16281
16680
  userTokenX,
@@ -16283,7 +16682,7 @@ var DLMM = class {
16283
16682
  );
16284
16683
  preInstructions.push(...wrapSOLIx);
16285
16684
  }
16286
- if (this.tokenY.publicKey.equals(NATIVE_MINT2) && !totalYAmount.isZero()) {
16685
+ if (this.tokenY.publicKey.equals(NATIVE_MINT2) && !totalYAmount.isZero() && !this.opt?.skipSolWrappingOperation) {
16287
16686
  const wrapSOLIx = wrapSOLInstruction(
16288
16687
  user,
16289
16688
  userTokenY,
@@ -16295,7 +16694,7 @@ var DLMM = class {
16295
16694
  if ([
16296
16695
  this.tokenX.publicKey.toBase58(),
16297
16696
  this.tokenY.publicKey.toBase58()
16298
- ].includes(NATIVE_MINT2.toBase58())) {
16697
+ ].includes(NATIVE_MINT2.toBase58()) && !this.opt?.skipSolWrappingOperation) {
16299
16698
  const closeWrappedSOLIx = await unwrapSOLInstruction(user);
16300
16699
  closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
16301
16700
  }
@@ -16479,7 +16878,7 @@ var DLMM = class {
16479
16878
  ]);
16480
16879
  createPayerTokenXIx && preInstructions.push(createPayerTokenXIx);
16481
16880
  createPayerTokenYIx && preInstructions.push(createPayerTokenYIx);
16482
- if (this.tokenX.publicKey.equals(NATIVE_MINT2) && !totalXAmount.isZero()) {
16881
+ if (this.tokenX.publicKey.equals(NATIVE_MINT2) && !totalXAmount.isZero() && !this.opt?.skipSolWrappingOperation) {
16483
16882
  const wrapSOLIx = wrapSOLInstruction(
16484
16883
  user,
16485
16884
  userTokenX,
@@ -16487,7 +16886,7 @@ var DLMM = class {
16487
16886
  );
16488
16887
  preInstructions.push(...wrapSOLIx);
16489
16888
  }
16490
- if (this.tokenY.publicKey.equals(NATIVE_MINT2) && !totalYAmount.isZero()) {
16889
+ if (this.tokenY.publicKey.equals(NATIVE_MINT2) && !totalYAmount.isZero() && !this.opt?.skipSolWrappingOperation) {
16491
16890
  const wrapSOLIx = wrapSOLInstruction(
16492
16891
  user,
16493
16892
  userTokenY,
@@ -16499,7 +16898,7 @@ var DLMM = class {
16499
16898
  if ([
16500
16899
  this.tokenX.publicKey.toBase58(),
16501
16900
  this.tokenY.publicKey.toBase58()
16502
- ].includes(NATIVE_MINT2.toBase58())) {
16901
+ ].includes(NATIVE_MINT2.toBase58()) && !this.opt?.skipSolWrappingOperation) {
16503
16902
  const closeWrappedSOLIx = await unwrapSOLInstruction(user);
16504
16903
  closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
16505
16904
  }
@@ -16647,7 +17046,7 @@ var DLMM = class {
16647
17046
  ]);
16648
17047
  createPayerTokenXIx && preInstructions.push(createPayerTokenXIx);
16649
17048
  createPayerTokenYIx && preInstructions.push(createPayerTokenYIx);
16650
- if (this.tokenX.publicKey.equals(NATIVE_MINT2) && !totalXAmount.isZero()) {
17049
+ if (this.tokenX.publicKey.equals(NATIVE_MINT2) && !totalXAmount.isZero() && !this.opt?.skipSolWrappingOperation) {
16651
17050
  const wrapSOLIx = wrapSOLInstruction(
16652
17051
  user,
16653
17052
  userTokenX,
@@ -16655,7 +17054,7 @@ var DLMM = class {
16655
17054
  );
16656
17055
  preInstructions.push(...wrapSOLIx);
16657
17056
  }
16658
- if (this.tokenY.publicKey.equals(NATIVE_MINT2) && !totalYAmount.isZero()) {
17057
+ if (this.tokenY.publicKey.equals(NATIVE_MINT2) && !totalYAmount.isZero() && !this.opt?.skipSolWrappingOperation) {
16659
17058
  const wrapSOLIx = wrapSOLInstruction(
16660
17059
  user,
16661
17060
  userTokenY,
@@ -16667,7 +17066,7 @@ var DLMM = class {
16667
17066
  if ([
16668
17067
  this.tokenX.publicKey.toBase58(),
16669
17068
  this.tokenY.publicKey.toBase58()
16670
- ].includes(NATIVE_MINT2.toBase58())) {
17069
+ ].includes(NATIVE_MINT2.toBase58()) && !this.opt?.skipSolWrappingOperation) {
16671
17070
  const closeWrappedSOLIx = await unwrapSOLInstruction(user);
16672
17071
  closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
16673
17072
  }
@@ -16944,7 +17343,7 @@ var DLMM = class {
16944
17343
  if ([
16945
17344
  this.tokenX.publicKey.toBase58(),
16946
17345
  this.tokenY.publicKey.toBase58()
16947
- ].includes(NATIVE_MINT2.toBase58()) && !skipUnwrapSOL) {
17346
+ ].includes(NATIVE_MINT2.toBase58()) && (!skipUnwrapSOL || !this.opt?.skipSolWrappingOperation)) {
16948
17347
  const closeWrappedSOLIx = await unwrapSOLInstruction(user);
16949
17348
  closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
16950
17349
  }
@@ -17083,7 +17482,7 @@ var DLMM = class {
17083
17482
  let activeId = new BN21(this.lbPair.activeId);
17084
17483
  const binStep = this.lbPair.binStep;
17085
17484
  const sParameters3 = this.lbPair.parameters;
17086
- DLMM.updateReference(
17485
+ _DLMM.updateReference(
17087
17486
  activeId.toNumber(),
17088
17487
  vParameterClone,
17089
17488
  sParameters3,
@@ -17109,7 +17508,7 @@ var DLMM = class {
17109
17508
  );
17110
17509
  }
17111
17510
  binArraysForSwap.set(binArrayAccountToSwap.publicKey, true);
17112
- DLMM.updateVolatilityAccumulator(
17511
+ _DLMM.updateVolatilityAccumulator(
17113
17512
  vParameterClone,
17114
17513
  sParameters3,
17115
17514
  activeId.toNumber()
@@ -17244,7 +17643,7 @@ var DLMM = class {
17244
17643
  let activeId = new BN21(this.lbPair.activeId);
17245
17644
  const binStep = this.lbPair.binStep;
17246
17645
  const sParameters3 = this.lbPair.parameters;
17247
- DLMM.updateReference(
17646
+ _DLMM.updateReference(
17248
17647
  activeId.toNumber(),
17249
17648
  vParameterClone,
17250
17649
  sParameters3,
@@ -17275,7 +17674,7 @@ var DLMM = class {
17275
17674
  }
17276
17675
  }
17277
17676
  binArraysForSwap.set(binArrayAccountToSwap.publicKey, true);
17278
- DLMM.updateVolatilityAccumulator(
17677
+ _DLMM.updateVolatilityAccumulator(
17279
17678
  vParameterClone,
17280
17679
  sParameters3,
17281
17680
  activeId.toNumber()
@@ -17431,7 +17830,7 @@ var DLMM = class {
17431
17830
  ]);
17432
17831
  createInTokenAccountIx && preInstructions.push(createInTokenAccountIx);
17433
17832
  createOutTokenAccountIx && preInstructions.push(createOutTokenAccountIx);
17434
- if (inToken.equals(NATIVE_MINT2)) {
17833
+ if (inToken.equals(NATIVE_MINT2) && !this.opt?.skipSolWrappingOperation) {
17435
17834
  const wrapSOLIx = wrapSOLInstruction(
17436
17835
  user,
17437
17836
  userTokenIn,
@@ -17441,7 +17840,7 @@ var DLMM = class {
17441
17840
  const closeWrappedSOLIx = await unwrapSOLInstruction(user);
17442
17841
  closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
17443
17842
  }
17444
- if (outToken.equals(NATIVE_MINT2)) {
17843
+ if (outToken.equals(NATIVE_MINT2) && !this.opt?.skipSolWrappingOperation) {
17445
17844
  const closeWrappedSOLIx = await unwrapSOLInstruction(user);
17446
17845
  closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
17447
17846
  }
@@ -17524,7 +17923,7 @@ var DLMM = class {
17524
17923
  ]);
17525
17924
  createInTokenAccountIx && preInstructions.push(createInTokenAccountIx);
17526
17925
  createOutTokenAccountIx && preInstructions.push(createOutTokenAccountIx);
17527
- if (inToken.equals(NATIVE_MINT2)) {
17926
+ if (inToken.equals(NATIVE_MINT2) && !this.opt?.skipSolWrappingOperation) {
17528
17927
  const wrapSOLIx = wrapSOLInstruction(
17529
17928
  user,
17530
17929
  userTokenIn,
@@ -17534,7 +17933,7 @@ var DLMM = class {
17534
17933
  const closeWrappedSOLIx = await unwrapSOLInstruction(user);
17535
17934
  closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
17536
17935
  }
17537
- if (outToken.equals(NATIVE_MINT2)) {
17936
+ if (outToken.equals(NATIVE_MINT2) && !this.opt?.skipSolWrappingOperation) {
17538
17937
  const closeWrappedSOLIx = await unwrapSOLInstruction(user);
17539
17938
  closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
17540
17939
  }
@@ -17626,7 +18025,7 @@ var DLMM = class {
17626
18025
  ]);
17627
18026
  createInTokenAccountIx && preInstructions.push(createInTokenAccountIx);
17628
18027
  createOutTokenAccountIx && preInstructions.push(createOutTokenAccountIx);
17629
- if (inToken.equals(NATIVE_MINT2)) {
18028
+ if (inToken.equals(NATIVE_MINT2) && !this.opt?.skipSolWrappingOperation) {
17630
18029
  const wrapSOLIx = wrapSOLInstruction(
17631
18030
  user,
17632
18031
  userTokenIn,
@@ -17636,7 +18035,7 @@ var DLMM = class {
17636
18035
  const closeWrappedSOLIx = await unwrapSOLInstruction(user);
17637
18036
  closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
17638
18037
  }
17639
- if (outToken.equals(NATIVE_MINT2)) {
18038
+ if (outToken.equals(NATIVE_MINT2) && !this.opt?.skipSolWrappingOperation) {
17640
18039
  const closeWrappedSOLIx = await unwrapSOLInstruction(user);
17641
18040
  closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
17642
18041
  }
@@ -17696,8 +18095,7 @@ var DLMM = class {
17696
18095
  owner,
17697
18096
  position
17698
18097
  });
17699
- if (!claimTransactions.length)
17700
- return;
18098
+ if (!claimTransactions.length) return;
17701
18099
  const claimTransactionWithCUIx = await Promise.all(
17702
18100
  claimTransactions.map(async (tx) => {
17703
18101
  const setCUIx = await getEstimatedComputeUnitIxWithBuffer(
@@ -17743,8 +18141,7 @@ var DLMM = class {
17743
18141
  })
17744
18142
  )).flat();
17745
18143
  const chunkedClaimAllTx = chunks(claimAllTxs, MAX_CLAIM_ALL_ALLOWED);
17746
- if (chunkedClaimAllTx.length === 0)
17747
- return [];
18144
+ if (chunkedClaimAllTx.length === 0) return [];
17748
18145
  const chunkedClaimAllTxIx = await Promise.all(
17749
18146
  chunkedClaimAllTx.map(async (txs) => {
17750
18147
  const ixs = txs.map((t) => t.instructions).flat();
@@ -17855,8 +18252,7 @@ var DLMM = class {
17855
18252
  })
17856
18253
  )).flat();
17857
18254
  const chunkedClaimAllTx = chunks(claimAllTxs, MAX_CLAIM_ALL_ALLOWED);
17858
- if (chunkedClaimAllTx.length === 0)
17859
- return [];
18255
+ if (chunkedClaimAllTx.length === 0) return [];
17860
18256
  const chunkedClaimAllTxIxs = await Promise.all(
17861
18257
  chunkedClaimAllTx.map(async (tx) => {
17862
18258
  const ixs = tx.map((t) => t.instructions).flat();
@@ -17952,10 +18348,10 @@ var DLMM = class {
17952
18348
  const minPricePerLamport = new Decimal9(minPrice).mul(toLamportMultiplier);
17953
18349
  const maxPricePerLamport = new Decimal9(maxPrice).mul(toLamportMultiplier);
17954
18350
  const minBinId = new BN21(
17955
- DLMM.getBinIdFromPrice(minPricePerLamport, this.lbPair.binStep, false)
18351
+ _DLMM.getBinIdFromPrice(minPricePerLamport, this.lbPair.binStep, false)
17956
18352
  );
17957
18353
  const maxBinId = new BN21(
17958
- DLMM.getBinIdFromPrice(maxPricePerLamport, this.lbPair.binStep, true)
18354
+ _DLMM.getBinIdFromPrice(maxPricePerLamport, this.lbPair.binStep, true)
17959
18355
  );
17960
18356
  if (minBinId.toNumber() < this.lbPair.activeId) {
17961
18357
  throw new Error("minPrice < current pair price");
@@ -18295,12 +18691,12 @@ var DLMM = class {
18295
18691
  let totalBinArraysCount = new BN21(0);
18296
18692
  let totalBinArraysLamports = new BN21(0);
18297
18693
  let binArrayBitmapLamports = new BN21(0);
18298
- const pricePerLamport = DLMM.getPricePerLamport(
18694
+ const pricePerLamport = _DLMM.getPricePerLamport(
18299
18695
  this.tokenX.mint.decimals,
18300
18696
  this.tokenY.mint.decimals,
18301
18697
  price
18302
18698
  );
18303
- const binIdNumber = DLMM.getBinIdFromPrice(
18699
+ const binIdNumber = _DLMM.getBinIdFromPrice(
18304
18700
  pricePerLamport,
18305
18701
  this.lbPair.binStep,
18306
18702
  !roundingUp
@@ -18679,7 +19075,7 @@ var DLMM = class {
18679
19075
  canSyncWithMarketPrice(marketPrice, activeBinId) {
18680
19076
  const marketPriceBinId = this.getBinIdFromPrice(
18681
19077
  Number(
18682
- DLMM.getPricePerLamport(
19078
+ _DLMM.getPricePerLamport(
18683
19079
  this.tokenX.mint.decimals,
18684
19080
  this.tokenY.mint.decimals,
18685
19081
  marketPrice
@@ -18697,8 +19093,7 @@ var DLMM = class {
18697
19093
  this.lbPair,
18698
19094
  this.binArrayBitmapExtension?.account ?? null
18699
19095
  );
18700
- if (toBinArrayIndex === null)
18701
- return true;
19096
+ if (toBinArrayIndex === null) return true;
18702
19097
  return swapForY ? marketPriceBinArrayIndex.gt(toBinArrayIndex) : marketPriceBinArrayIndex.lt(toBinArrayIndex);
18703
19098
  }
18704
19099
  /**
@@ -18711,7 +19106,7 @@ var DLMM = class {
18711
19106
  async syncWithMarketPrice(marketPrice, owner) {
18712
19107
  const marketPriceBinId = this.getBinIdFromPrice(
18713
19108
  Number(
18714
- DLMM.getPricePerLamport(
19109
+ _DLMM.getPricePerLamport(
18715
19110
  this.tokenX.mint.decimals,
18716
19111
  this.tokenY.mint.decimals,
18717
19112
  marketPrice
@@ -18749,8 +19144,7 @@ var DLMM = class {
18749
19144
  );
18750
19145
  accountsToFetch.push(fromBinArrayPubkey);
18751
19146
  const toBinArrayPubkey = (() => {
18752
- if (!toBinArrayIndex)
18753
- return null;
19147
+ if (!toBinArrayIndex) return null;
18754
19148
  const [toBinArrayPubkey2] = deriveBinArray(
18755
19149
  this.pubkey,
18756
19150
  toBinArrayIndex,
@@ -19226,7 +19620,7 @@ var DLMM = class {
19226
19620
  slippage
19227
19621
  );
19228
19622
  const postInstructions = [];
19229
- if (this.tokenX.publicKey.equals(NATIVE_MINT2) && simulationResult.actualAmountXDeposited.gtn(0)) {
19623
+ if (this.tokenX.publicKey.equals(NATIVE_MINT2) && simulationResult.actualAmountXDeposited.gtn(0) && !this.opt?.skipSolWrappingOperation) {
19230
19624
  const wrapSOLIx = wrapSOLInstruction(
19231
19625
  owner,
19232
19626
  userTokenX,
@@ -19234,7 +19628,7 @@ var DLMM = class {
19234
19628
  );
19235
19629
  preInstructions.push(...wrapSOLIx);
19236
19630
  }
19237
- if (this.tokenY.publicKey.equals(NATIVE_MINT2) && simulationResult.actualAmountYDeposited.gtn(0)) {
19631
+ if (this.tokenY.publicKey.equals(NATIVE_MINT2) && simulationResult.actualAmountYDeposited.gtn(0) && !this.opt?.skipSolWrappingOperation) {
19238
19632
  const wrapSOLIx = wrapSOLInstruction(
19239
19633
  owner,
19240
19634
  userTokenY,
@@ -19242,7 +19636,7 @@ var DLMM = class {
19242
19636
  );
19243
19637
  preInstructions.push(...wrapSOLIx);
19244
19638
  }
19245
- if (this.tokenX.publicKey.equals(NATIVE_MINT2) || this.tokenY.publicKey.equals(NATIVE_MINT2)) {
19639
+ if ((this.tokenX.publicKey.equals(NATIVE_MINT2) || this.tokenY.publicKey.equals(NATIVE_MINT2)) && !this.opt?.skipSolWrappingOperation) {
19246
19640
  const closeWrappedSOLIx = await unwrapSOLInstruction(owner);
19247
19641
  closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
19248
19642
  }
@@ -19258,7 +19652,8 @@ var DLMM = class {
19258
19652
  maxDepositYAmount,
19259
19653
  minWithdrawXAmount,
19260
19654
  minWithdrawYAmount,
19261
- padding: Array(32).fill(0)
19655
+ shrinkMode: 0 /* ShrinkBoth */,
19656
+ padding: REBALANCE_POSITION_PADDING
19262
19657
  },
19263
19658
  {
19264
19659
  slices
@@ -19433,8 +19828,7 @@ var DLMM = class {
19433
19828
  binArrayMap,
19434
19829
  program.programId
19435
19830
  );
19436
- if (!bins.length)
19437
- return null;
19831
+ if (!bins.length) return null;
19438
19832
  const positionData = [];
19439
19833
  let totalXAmount = new Decimal9(0);
19440
19834
  let totalYAmount = new Decimal9(0);
@@ -19766,8 +20160,7 @@ var DLMM = class {
19766
20160
  const maybeClaimableBinRange = getPositionLowerUpperBinIdWithLiquidity(
19767
20161
  position.positionData
19768
20162
  );
19769
- if (!maybeClaimableBinRange)
19770
- return [];
20163
+ if (!maybeClaimableBinRange) return [];
19771
20164
  const { lowerBinId, upperBinId } = maybeClaimableBinRange;
19772
20165
  const chunkedBinRange = chunkBinRange(
19773
20166
  lowerBinId.toNumber(),
@@ -19786,8 +20179,7 @@ var DLMM = class {
19786
20179
  );
19787
20180
  for (let i = 0; i < 2; i++) {
19788
20181
  const rewardInfo = this.lbPair.rewardInfos[i];
19789
- if (!rewardInfo || rewardInfo.mint.equals(PublicKey10.default))
19790
- continue;
20182
+ if (!rewardInfo || rewardInfo.mint.equals(PublicKey10.default)) continue;
19791
20183
  const preInstructions = [];
19792
20184
  const userRewardToken = getAssociatedTokenAddressSync2(
19793
20185
  rewardInfo.mint,
@@ -19828,8 +20220,7 @@ var DLMM = class {
19828
20220
  const maybeClaimableBinRange = getPositionLowerUpperBinIdWithLiquidity(
19829
20221
  position.positionData
19830
20222
  );
19831
- if (!maybeClaimableBinRange)
19832
- return [];
20223
+ if (!maybeClaimableBinRange) return [];
19833
20224
  const { lowerBinId, upperBinId } = maybeClaimableBinRange;
19834
20225
  const chunkedBinRange = chunkBinRange(
19835
20226
  lowerBinId.toNumber(),
@@ -19881,7 +20272,7 @@ var DLMM = class {
19881
20272
  if ([
19882
20273
  this.tokenX.publicKey.toBase58(),
19883
20274
  this.tokenY.publicKey.toBase58()
19884
- ].includes(NATIVE_MINT2.toBase58())) {
20275
+ ].includes(NATIVE_MINT2.toBase58()) && !this.opt?.skipSolWrappingOperation) {
19885
20276
  const closeWrappedSOLIx = await unwrapSOLInstruction(owner);
19886
20277
  closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
19887
20278
  }
@@ -19943,9 +20334,10 @@ var DLMM = class {
19943
20334
  };
19944
20335
 
19945
20336
  // src/index.ts
19946
- var src_default = DLMM;
20337
+ var index_default = DLMM;
19947
20338
  export {
19948
20339
  ADMIN,
20340
+ ALT_ADDRESS,
19949
20341
  ActionType,
19950
20342
  ActivationType,
19951
20343
  BASIS_POINT_MAX,
@@ -19987,11 +20379,13 @@ export {
19987
20379
  PairType,
19988
20380
  PositionV2Wrapper,
19989
20381
  PositionVersion,
20382
+ REBALANCE_POSITION_PADDING,
19990
20383
  RebalancePosition,
19991
20384
  ResizeSide,
19992
20385
  SCALE,
19993
20386
  SCALE_OFFSET,
19994
20387
  SIMULATION_USER,
20388
+ ShrinkMode,
19995
20389
  Strategy,
19996
20390
  StrategyType,
19997
20391
  TOKEN_ACCOUNT_FEE,
@@ -20024,7 +20418,7 @@ export {
20024
20418
  createProgram,
20025
20419
  decodeAccount,
20026
20420
  decodeExtendedPosition,
20027
- src_default as default,
20421
+ index_default as default,
20028
20422
  deriveBinArray,
20029
20423
  deriveBinArrayBitmapExtension,
20030
20424
  deriveCustomizablePermissionlessLbPair,