@meteora-ag/dlmm 1.3.13-rc.5 → 1.3.14-sam.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
@@ -11,8 +11,8 @@ import {
11
11
  getAssociatedTokenAddressSync as getAssociatedTokenAddressSync2
12
12
  } from "@solana/spl-token";
13
13
  import {
14
- ComputeBudgetProgram as ComputeBudgetProgram3,
15
- PublicKey as PublicKey7,
14
+ ComputeBudgetProgram as ComputeBudgetProgram2,
15
+ PublicKey as PublicKey6,
16
16
  SYSVAR_CLOCK_PUBKEY,
17
17
  SYSVAR_RENT_PUBKEY,
18
18
  SystemProgram as SystemProgram2,
@@ -25,7 +25,7 @@ import { PublicKey } from "@solana/web3.js";
25
25
 
26
26
  // src/dlmm/idl.ts
27
27
  var IDL = {
28
- "version": "0.8.5",
28
+ "version": "0.8.2",
29
29
  "name": "lb_clmm",
30
30
  "constants": [
31
31
  {
@@ -113,16 +113,6 @@ var IDL = {
113
113
  },
114
114
  "value": "15"
115
115
  },
116
- {
117
- "name": "ILM_PROTOCOL_SHARE",
118
- "type": "u16",
119
- "value": "2000"
120
- },
121
- {
122
- "name": "PROTOCOL_SHARE",
123
- "type": "u16",
124
- "value": "500"
125
- },
126
116
  {
127
117
  "name": "MAX_BIN_STEP",
128
118
  "type": "u16",
@@ -395,7 +385,7 @@ var IDL = {
395
385
  "isSigner": false
396
386
  },
397
387
  {
398
- "name": "userTokenY",
388
+ "name": "rent",
399
389
  "isMut": false,
400
390
  "isSigner": false
401
391
  },
@@ -1974,7 +1964,7 @@ var IDL = {
1974
1964
  "args": []
1975
1965
  },
1976
1966
  {
1977
- "name": "updateBaseFeeParameters",
1967
+ "name": "updateFeeParameters",
1978
1968
  "accounts": [
1979
1969
  {
1980
1970
  "name": "lbPair",
@@ -2001,40 +1991,7 @@ var IDL = {
2001
1991
  {
2002
1992
  "name": "feeParameter",
2003
1993
  "type": {
2004
- "defined": "BaseFeeParameter"
2005
- }
2006
- }
2007
- ]
2008
- },
2009
- {
2010
- "name": "updateDynamicFeeParameters",
2011
- "accounts": [
2012
- {
2013
- "name": "lbPair",
2014
- "isMut": true,
2015
- "isSigner": false
2016
- },
2017
- {
2018
- "name": "admin",
2019
- "isMut": false,
2020
- "isSigner": true
2021
- },
2022
- {
2023
- "name": "eventAuthority",
2024
- "isMut": false,
2025
- "isSigner": false
2026
- },
2027
- {
2028
- "name": "program",
2029
- "isMut": false,
2030
- "isSigner": false
2031
- }
2032
- ],
2033
- "args": [
2034
- {
2035
- "name": "feeParameter",
2036
- "type": {
2037
- "defined": "DynamicFeeParameter"
1994
+ "defined": "FeeParameter"
2038
1995
  }
2039
1996
  }
2040
1997
  ]
@@ -2217,7 +2174,7 @@ var IDL = {
2217
2174
  "args": []
2218
2175
  },
2219
2176
  {
2220
- "name": "setPairStatus",
2177
+ "name": "togglePairStatus",
2221
2178
  "accounts": [
2222
2179
  {
2223
2180
  "name": "lbPair",
@@ -2230,12 +2187,7 @@ var IDL = {
2230
2187
  "isSigner": true
2231
2188
  }
2232
2189
  ],
2233
- "args": [
2234
- {
2235
- "name": "status",
2236
- "type": "u8"
2237
- }
2238
- ]
2190
+ "args": []
2239
2191
  },
2240
2192
  {
2241
2193
  "name": "migratePosition",
@@ -3496,7 +3448,7 @@ var IDL = {
3496
3448
  }
3497
3449
  },
3498
3450
  {
3499
- "name": "BaseFeeParameter",
3451
+ "name": "FeeParameter",
3500
3452
  "type": {
3501
3453
  "kind": "struct",
3502
3454
  "fields": [
@@ -3517,49 +3469,6 @@ var IDL = {
3517
3469
  ]
3518
3470
  }
3519
3471
  },
3520
- {
3521
- "name": "DynamicFeeParameter",
3522
- "type": {
3523
- "kind": "struct",
3524
- "fields": [
3525
- {
3526
- "name": "filterPeriod",
3527
- "docs": [
3528
- "Filter period determine high frequency trading time window."
3529
- ],
3530
- "type": "u16"
3531
- },
3532
- {
3533
- "name": "decayPeriod",
3534
- "docs": [
3535
- "Decay period determine when the volatile fee start decay / decrease."
3536
- ],
3537
- "type": "u16"
3538
- },
3539
- {
3540
- "name": "reductionFactor",
3541
- "docs": [
3542
- "Reduction factor controls the volatile fee rate decrement rate."
3543
- ],
3544
- "type": "u16"
3545
- },
3546
- {
3547
- "name": "variableFeeControl",
3548
- "docs": [
3549
- "Used to scale the variable fee component depending on the dynamic of the market"
3550
- ],
3551
- "type": "u32"
3552
- },
3553
- {
3554
- "name": "maxVolatilityAccumulator",
3555
- "docs": [
3556
- "Maximum number of bin crossed can be accumulated. Used to cap volatile fee rate."
3557
- ],
3558
- "type": "u32"
3559
- }
3560
- ]
3561
- }
3562
- },
3563
3472
  {
3564
3473
  "name": "LiquidityParameterByStrategyOneSide",
3565
3474
  "type": {
@@ -4925,41 +4834,6 @@ var IDL = {
4925
4834
  }
4926
4835
  ]
4927
4836
  },
4928
- {
4929
- "name": "DynamicFeeParameterUpdate",
4930
- "fields": [
4931
- {
4932
- "name": "lbPair",
4933
- "type": "publicKey",
4934
- "index": false
4935
- },
4936
- {
4937
- "name": "filterPeriod",
4938
- "type": "u16",
4939
- "index": false
4940
- },
4941
- {
4942
- "name": "decayPeriod",
4943
- "type": "u16",
4944
- "index": false
4945
- },
4946
- {
4947
- "name": "reductionFactor",
4948
- "type": "u16",
4949
- "index": false
4950
- },
4951
- {
4952
- "name": "variableFeeControl",
4953
- "type": "u32",
4954
- "index": false
4955
- },
4956
- {
4957
- "name": "maxVolatilityAccumulator",
4958
- "type": "u32",
4959
- "index": false
4960
- }
4961
- ]
4962
- },
4963
4837
  {
4964
4838
  "name": "IncreaseObservation",
4965
4839
  "fields": [
@@ -5396,11 +5270,6 @@ var IDL = {
5396
5270
  "code": 6065,
5397
5271
  "name": "AlreadyPassPreActivationSwapPoint",
5398
5272
  "msg": "Already pass pre-activation swap point"
5399
- },
5400
- {
5401
- "code": 6066,
5402
- "name": "InvalidStatus",
5403
- "msg": "Invalid status"
5404
5273
  }
5405
5274
  ]
5406
5275
  };
@@ -5504,16 +5373,16 @@ import {
5504
5373
  TOKEN_PROGRAM_ID,
5505
5374
  TokenAccountNotFoundError,
5506
5375
  TokenInvalidAccountOwnerError,
5507
- createAssociatedTokenAccountIdempotentInstruction,
5376
+ createAssociatedTokenAccountInstruction,
5508
5377
  createCloseAccountInstruction,
5509
5378
  getAccount,
5510
5379
  getAssociatedTokenAddressSync,
5511
5380
  getMint
5512
5381
  } from "@solana/spl-token";
5513
5382
  import {
5514
- ComputeBudgetProgram as ComputeBudgetProgram2,
5383
+ ComputeBudgetProgram,
5515
5384
  SystemProgram,
5516
- TransactionInstruction as TransactionInstruction2
5385
+ TransactionInstruction
5517
5386
  } from "@solana/web3.js";
5518
5387
 
5519
5388
  // src/dlmm/helpers/math.ts
@@ -6472,51 +6341,22 @@ function generateBinAmount(amount, binStep, binId, tokenXDecimal, tokenYDecimal,
6472
6341
  return new BN5(c1.sub(c0).floor().toString());
6473
6342
  }
6474
6343
 
6344
+ // src/dlmm/helpers/index.ts
6345
+ import { getSimulationComputeUnits } from "@solana-developers/helpers";
6346
+
6475
6347
  // src/dlmm/helpers/computeUnit.ts
6476
- import { ComputeBudgetProgram, PublicKey as PublicKey2, TransactionMessage, VersionedTransaction } from "@solana/web3.js";
6477
6348
  var DEFAULT_ADD_LIQUIDITY_CU = 8e5;
6478
6349
  var MIN_CU_BUFFER = 5e4;
6479
6350
  var MAX_CU_BUFFER = 2e5;
6480
- var getSimulationComputeUnits = async (connection, instructions, payer, lookupTables, commitment = "confirmed") => {
6481
- const testInstructions = [
6482
- // Set an arbitrarily high number in simulation
6483
- // so we can be sure the transaction will succeed
6484
- // and get the real compute units used
6485
- ComputeBudgetProgram.setComputeUnitLimit({ units: 14e5 }),
6486
- ...instructions
6487
- ];
6488
- const testTransaction = new VersionedTransaction(
6489
- new TransactionMessage({
6490
- instructions: testInstructions,
6491
- payerKey: payer,
6492
- // RecentBlockhash can by any public key during simulation
6493
- // since 'replaceRecentBlockhash' is set to 'true' below
6494
- recentBlockhash: PublicKey2.default.toString()
6495
- }).compileToV0Message(lookupTables)
6496
- );
6497
- const rpcResponse = await connection.simulateTransaction(testTransaction, {
6498
- replaceRecentBlockhash: true,
6499
- sigVerify: false,
6500
- commitment
6501
- });
6502
- if (rpcResponse?.value?.err) {
6503
- const logs = rpcResponse.value.logs?.join("\n \u2022 ") || "No logs available";
6504
- throw new Error(
6505
- `Transaction simulation failed:
6506
- \u2022${logs}` + JSON.stringify(rpcResponse?.value?.err)
6507
- );
6508
- }
6509
- return rpcResponse.value.unitsConsumed || null;
6510
- };
6511
6351
 
6512
6352
  // src/dlmm/helpers/derive.ts
6513
- import { PublicKey as PublicKey3 } from "@solana/web3.js";
6353
+ import { PublicKey as PublicKey2 } from "@solana/web3.js";
6514
6354
  function sortTokenMints(tokenX, tokenY) {
6515
6355
  const [minKey, maxKey] = tokenX.toBuffer().compare(tokenY.toBuffer()) == 1 ? [tokenY, tokenX] : [tokenX, tokenY];
6516
6356
  return [minKey, maxKey];
6517
6357
  }
6518
6358
  function derivePresetParameter(binStep, programId) {
6519
- return PublicKey3.findProgramAddressSync(
6359
+ return PublicKey2.findProgramAddressSync(
6520
6360
  [
6521
6361
  Buffer.from("preset_parameter"),
6522
6362
  new Uint8Array(binStep.toArrayLike(Buffer, "le", 2))
@@ -6525,7 +6365,7 @@ function derivePresetParameter(binStep, programId) {
6525
6365
  );
6526
6366
  }
6527
6367
  function derivePresetParameter2(binStep, baseFactor, programId) {
6528
- return PublicKey3.findProgramAddressSync(
6368
+ return PublicKey2.findProgramAddressSync(
6529
6369
  [
6530
6370
  Buffer.from("preset_parameter"),
6531
6371
  new Uint8Array(binStep.toArrayLike(Buffer, "le", 2)),
@@ -6536,7 +6376,7 @@ function derivePresetParameter2(binStep, baseFactor, programId) {
6536
6376
  }
6537
6377
  function deriveLbPair2(tokenX, tokenY, binStep, baseFactor, programId) {
6538
6378
  const [minKey, maxKey] = sortTokenMints(tokenX, tokenY);
6539
- return PublicKey3.findProgramAddressSync(
6379
+ return PublicKey2.findProgramAddressSync(
6540
6380
  [
6541
6381
  minKey.toBuffer(),
6542
6382
  maxKey.toBuffer(),
@@ -6548,7 +6388,7 @@ function deriveLbPair2(tokenX, tokenY, binStep, baseFactor, programId) {
6548
6388
  }
6549
6389
  function deriveLbPair(tokenX, tokenY, binStep, programId) {
6550
6390
  const [minKey, maxKey] = sortTokenMints(tokenX, tokenY);
6551
- return PublicKey3.findProgramAddressSync(
6391
+ return PublicKey2.findProgramAddressSync(
6552
6392
  [
6553
6393
  minKey.toBuffer(),
6554
6394
  maxKey.toBuffer(),
@@ -6559,14 +6399,14 @@ function deriveLbPair(tokenX, tokenY, binStep, programId) {
6559
6399
  }
6560
6400
  function deriveCustomizablePermissionlessLbPair(tokenX, tokenY, programId) {
6561
6401
  const [minKey, maxKey] = sortTokenMints(tokenX, tokenY);
6562
- return PublicKey3.findProgramAddressSync(
6402
+ return PublicKey2.findProgramAddressSync(
6563
6403
  [ILM_BASE.toBuffer(), minKey.toBuffer(), maxKey.toBuffer()],
6564
6404
  programId
6565
6405
  );
6566
6406
  }
6567
6407
  function derivePermissionLbPair(baseKey, tokenX, tokenY, binStep, programId) {
6568
6408
  const [minKey, maxKey] = sortTokenMints(tokenX, tokenY);
6569
- return PublicKey3.findProgramAddressSync(
6409
+ return PublicKey2.findProgramAddressSync(
6570
6410
  [
6571
6411
  baseKey.toBuffer(),
6572
6412
  minKey.toBuffer(),
@@ -6577,7 +6417,7 @@ function derivePermissionLbPair(baseKey, tokenX, tokenY, binStep, programId) {
6577
6417
  );
6578
6418
  }
6579
6419
  function deriveOracle(lbPair, programId) {
6580
- return PublicKey3.findProgramAddressSync(
6420
+ return PublicKey2.findProgramAddressSync(
6581
6421
  [Buffer.from("oracle"), lbPair.toBytes()],
6582
6422
  programId
6583
6423
  );
@@ -6591,7 +6431,7 @@ function derivePosition(lbPair, base, lowerBinId, width, programId) {
6591
6431
  } else {
6592
6432
  lowerBinIdBytes = new Uint8Array(lowerBinId.toArrayLike(Buffer, "le", 4));
6593
6433
  }
6594
- return PublicKey3.findProgramAddressSync(
6434
+ return PublicKey2.findProgramAddressSync(
6595
6435
  [
6596
6436
  Buffer.from("position"),
6597
6437
  lbPair.toBuffer(),
@@ -6611,13 +6451,13 @@ function deriveBinArray(lbPair, index, programId) {
6611
6451
  } else {
6612
6452
  binArrayBytes = new Uint8Array(index.toArrayLike(Buffer, "le", 8));
6613
6453
  }
6614
- return PublicKey3.findProgramAddressSync(
6454
+ return PublicKey2.findProgramAddressSync(
6615
6455
  [Buffer.from("bin_array"), lbPair.toBytes(), binArrayBytes],
6616
6456
  programId
6617
6457
  );
6618
6458
  }
6619
6459
  function deriveReserve(token, lbPair, programId) {
6620
- return PublicKey3.findProgramAddressSync(
6460
+ return PublicKey2.findProgramAddressSync(
6621
6461
  [lbPair.toBuffer(), token.toBuffer()],
6622
6462
  programId
6623
6463
  );
@@ -6625,7 +6465,7 @@ function deriveReserve(token, lbPair, programId) {
6625
6465
 
6626
6466
  // src/dlmm/helpers/binArray.ts
6627
6467
  import { BN as BN7 } from "@coral-xyz/anchor";
6628
- import { PublicKey as PublicKey4 } from "@solana/web3.js";
6468
+ import { PublicKey as PublicKey3 } from "@solana/web3.js";
6629
6469
 
6630
6470
  // src/dlmm/types/index.ts
6631
6471
  import {
@@ -6644,6 +6484,9 @@ var PairType = /* @__PURE__ */ ((PairType2) => {
6644
6484
  return PairType2;
6645
6485
  })(PairType || {});
6646
6486
  var Strategy = {
6487
+ SpotOneSide: { spotOneSide: {} },
6488
+ CurveOneSide: { curveOneSide: {} },
6489
+ BidAskOneSide: { bidAskOneSide: {} },
6647
6490
  SpotBalanced: { spotBalanced: {} },
6648
6491
  CurveBalanced: { curveBalanced: {} },
6649
6492
  BidAskBalanced: { bidAskBalanced: {} },
@@ -6652,12 +6495,15 @@ var Strategy = {
6652
6495
  BidAskImBalanced: { bidAskImBalanced: {} }
6653
6496
  };
6654
6497
  var StrategyType = /* @__PURE__ */ ((StrategyType2) => {
6655
- StrategyType2[StrategyType2["SpotImBalanced"] = 0] = "SpotImBalanced";
6656
- StrategyType2[StrategyType2["CurveImBalanced"] = 1] = "CurveImBalanced";
6657
- StrategyType2[StrategyType2["BidAskImBalanced"] = 2] = "BidAskImBalanced";
6658
- StrategyType2[StrategyType2["SpotBalanced"] = 3] = "SpotBalanced";
6659
- StrategyType2[StrategyType2["CurveBalanced"] = 4] = "CurveBalanced";
6660
- StrategyType2[StrategyType2["BidAskBalanced"] = 5] = "BidAskBalanced";
6498
+ StrategyType2[StrategyType2["SpotOneSide"] = 0] = "SpotOneSide";
6499
+ StrategyType2[StrategyType2["CurveOneSide"] = 1] = "CurveOneSide";
6500
+ StrategyType2[StrategyType2["BidAskOneSide"] = 2] = "BidAskOneSide";
6501
+ StrategyType2[StrategyType2["SpotImBalanced"] = 3] = "SpotImBalanced";
6502
+ StrategyType2[StrategyType2["CurveImBalanced"] = 4] = "CurveImBalanced";
6503
+ StrategyType2[StrategyType2["BidAskImBalanced"] = 5] = "BidAskImBalanced";
6504
+ StrategyType2[StrategyType2["SpotBalanced"] = 6] = "SpotBalanced";
6505
+ StrategyType2[StrategyType2["CurveBalanced"] = 7] = "CurveBalanced";
6506
+ StrategyType2[StrategyType2["BidAskBalanced"] = 8] = "BidAskBalanced";
6661
6507
  return StrategyType2;
6662
6508
  })(StrategyType || {});
6663
6509
  var ActivationType = /* @__PURE__ */ ((ActivationType2) => {
@@ -6813,7 +6659,7 @@ function isOverflowDefaultBinArrayBitmap(binArrayIndex) {
6813
6659
  return binArrayIndex.gt(maxBinArrayIndex) || binArrayIndex.lt(minBinArrayIndex);
6814
6660
  }
6815
6661
  function deriveBinArrayBitmapExtension(lbPair, programId) {
6816
- return PublicKey4.findProgramAddressSync(
6662
+ return PublicKey3.findProgramAddressSync(
6817
6663
  [Buffer.from("bitmap"), lbPair.toBytes()],
6818
6664
  programId
6819
6665
  );
@@ -6962,7 +6808,7 @@ function getBinArraysRequiredByPositionRange(pair, fromBinId, toBinId, programId
6962
6808
  binArrays.set(upperBinArray.toBase58(), upperBinArrayIndex);
6963
6809
  }
6964
6810
  return Array.from(binArrays, ([key, index]) => ({
6965
- key: new PublicKey4(key),
6811
+ key: new PublicKey3(key),
6966
6812
  index
6967
6813
  }));
6968
6814
  }
@@ -7209,10 +7055,53 @@ function toWeightBidAsk(minBinId, maxBinId, activeId) {
7209
7055
  }
7210
7056
  return distributions;
7211
7057
  }
7058
+ function toAmountsOneSideByStrategy(activeId, binStep, minBinId, maxBinId, amount, strategyType, depositForY) {
7059
+ let weights = [];
7060
+ switch (strategyType) {
7061
+ case 6 /* SpotBalanced */:
7062
+ case 7 /* CurveBalanced */:
7063
+ case 8 /* BidAskBalanced */:
7064
+ case 3 /* SpotImBalanced */:
7065
+ case 4 /* CurveImBalanced */:
7066
+ case 5 /* BidAskImBalanced */: {
7067
+ throw "Invalid Strategy Parameters";
7068
+ }
7069
+ case 0 /* SpotOneSide */: {
7070
+ weights = toWeightSpotBalanced(minBinId, maxBinId);
7071
+ break;
7072
+ }
7073
+ case 1 /* CurveOneSide */: {
7074
+ if (depositForY) {
7075
+ weights = toWeightAscendingOrder(minBinId, maxBinId);
7076
+ } else {
7077
+ weights = toWeightDecendingOrder(minBinId, maxBinId);
7078
+ }
7079
+ break;
7080
+ }
7081
+ case 2 /* BidAskOneSide */: {
7082
+ if (depositForY) {
7083
+ weights = toWeightDecendingOrder(minBinId, maxBinId);
7084
+ } else {
7085
+ weights = toWeightAscendingOrder(minBinId, maxBinId);
7086
+ }
7087
+ break;
7088
+ }
7089
+ }
7090
+ if (depositForY) {
7091
+ return toAmountBidSide(activeId, amount, weights);
7092
+ } else {
7093
+ return toAmountAskSide(activeId, binStep, amount, weights);
7094
+ }
7095
+ }
7212
7096
  function toAmountsBothSideByStrategy(activeId, binStep, minBinId, maxBinId, amountX, amountY, amountXInActiveBin, amountYInActiveBin, strategyType) {
7213
7097
  const isSingleSideX = amountY.isZero();
7214
7098
  switch (strategyType) {
7215
- case 0 /* SpotImBalanced */: {
7099
+ case 0 /* SpotOneSide */:
7100
+ case 1 /* CurveOneSide */:
7101
+ case 2 /* BidAskOneSide */: {
7102
+ throw "Invalid Strategy Parameters";
7103
+ }
7104
+ case 3 /* SpotImBalanced */: {
7216
7105
  if (activeId < minBinId || activeId > maxBinId) {
7217
7106
  const weights = toWeightSpotBalanced(minBinId, maxBinId);
7218
7107
  return toAmountBothSide(
@@ -7284,7 +7173,7 @@ function toAmountsBothSideByStrategy(activeId, binStep, minBinId, maxBinId, amou
7284
7173
  }
7285
7174
  return amountsInBin;
7286
7175
  }
7287
- case 1 /* CurveImBalanced */: {
7176
+ case 4 /* CurveImBalanced */: {
7288
7177
  if (activeId < minBinId) {
7289
7178
  let weights = toWeightDecendingOrder(minBinId, maxBinId);
7290
7179
  return toAmountBothSide(
@@ -7368,7 +7257,7 @@ function toAmountsBothSideByStrategy(activeId, binStep, minBinId, maxBinId, amou
7368
7257
  }
7369
7258
  return amountsInBin;
7370
7259
  }
7371
- case 2 /* BidAskImBalanced */: {
7260
+ case 5 /* BidAskImBalanced */: {
7372
7261
  if (activeId < minBinId) {
7373
7262
  const weights = toWeightAscendingOrder(minBinId, maxBinId);
7374
7263
  return toAmountBothSide(
@@ -7452,7 +7341,7 @@ function toAmountsBothSideByStrategy(activeId, binStep, minBinId, maxBinId, amou
7452
7341
  }
7453
7342
  return amountsInBin;
7454
7343
  }
7455
- case 3 /* SpotBalanced */: {
7344
+ case 6 /* SpotBalanced */: {
7456
7345
  let weights = toWeightSpotBalanced(minBinId, maxBinId);
7457
7346
  return toAmountBothSide(
7458
7347
  activeId,
@@ -7464,7 +7353,7 @@ function toAmountsBothSideByStrategy(activeId, binStep, minBinId, maxBinId, amou
7464
7353
  weights
7465
7354
  );
7466
7355
  }
7467
- case 4 /* CurveBalanced */: {
7356
+ case 7 /* CurveBalanced */: {
7468
7357
  let weights = toWeightCurve(minBinId, maxBinId, activeId);
7469
7358
  return toAmountBothSide(
7470
7359
  activeId,
@@ -7476,7 +7365,7 @@ function toAmountsBothSideByStrategy(activeId, binStep, minBinId, maxBinId, amou
7476
7365
  weights
7477
7366
  );
7478
7367
  }
7479
- case 5 /* BidAskBalanced */: {
7368
+ case 8 /* BidAskBalanced */: {
7480
7369
  let weights = toWeightBidAsk(minBinId, maxBinId, activeId);
7481
7370
  return toAmountBothSide(
7482
7371
  activeId,
@@ -7492,12 +7381,15 @@ function toAmountsBothSideByStrategy(activeId, binStep, minBinId, maxBinId, amou
7492
7381
  }
7493
7382
  function autoFillYByStrategy(activeId, binStep, amountX, amountXInActiveBin, amountYInActiveBin, minBinId, maxBinId, strategyType) {
7494
7383
  switch (strategyType) {
7495
- case 0 /* SpotImBalanced */:
7496
- case 1 /* CurveImBalanced */:
7497
- case 2 /* BidAskImBalanced */: {
7384
+ case 0 /* SpotOneSide */:
7385
+ case 1 /* CurveOneSide */:
7386
+ case 2 /* BidAskOneSide */:
7387
+ case 3 /* SpotImBalanced */:
7388
+ case 4 /* CurveImBalanced */:
7389
+ case 5 /* BidAskImBalanced */: {
7498
7390
  throw "Invalid Strategy Parameters";
7499
7391
  }
7500
- case 3 /* SpotBalanced */: {
7392
+ case 6 /* SpotBalanced */: {
7501
7393
  let weights = toWeightSpotBalanced(minBinId, maxBinId);
7502
7394
  return autoFillYByWeight(
7503
7395
  activeId,
@@ -7508,7 +7400,7 @@ function autoFillYByStrategy(activeId, binStep, amountX, amountXInActiveBin, amo
7508
7400
  weights
7509
7401
  );
7510
7402
  }
7511
- case 4 /* CurveBalanced */: {
7403
+ case 7 /* CurveBalanced */: {
7512
7404
  let weights = toWeightCurve(minBinId, maxBinId, activeId);
7513
7405
  return autoFillYByWeight(
7514
7406
  activeId,
@@ -7519,7 +7411,7 @@ function autoFillYByStrategy(activeId, binStep, amountX, amountXInActiveBin, amo
7519
7411
  weights
7520
7412
  );
7521
7413
  }
7522
- case 5 /* BidAskBalanced */: {
7414
+ case 8 /* BidAskBalanced */: {
7523
7415
  let weights = toWeightBidAsk(minBinId, maxBinId, activeId);
7524
7416
  return autoFillYByWeight(
7525
7417
  activeId,
@@ -7534,12 +7426,15 @@ function autoFillYByStrategy(activeId, binStep, amountX, amountXInActiveBin, amo
7534
7426
  }
7535
7427
  function autoFillXByStrategy(activeId, binStep, amountY, amountXInActiveBin, amountYInActiveBin, minBinId, maxBinId, strategyType) {
7536
7428
  switch (strategyType) {
7537
- case 0 /* SpotImBalanced */:
7538
- case 1 /* CurveImBalanced */:
7539
- case 2 /* BidAskImBalanced */: {
7429
+ case 0 /* SpotOneSide */:
7430
+ case 1 /* CurveOneSide */:
7431
+ case 2 /* BidAskOneSide */:
7432
+ case 3 /* SpotImBalanced */:
7433
+ case 4 /* CurveImBalanced */:
7434
+ case 5 /* BidAskImBalanced */: {
7540
7435
  throw "Invalid Strategy Parameters";
7541
7436
  }
7542
- case 3 /* SpotBalanced */: {
7437
+ case 6 /* SpotBalanced */: {
7543
7438
  let weights = toWeightSpotBalanced(minBinId, maxBinId);
7544
7439
  return autoFillXByWeight(
7545
7440
  activeId,
@@ -7550,7 +7445,7 @@ function autoFillXByStrategy(activeId, binStep, amountY, amountXInActiveBin, amo
7550
7445
  weights
7551
7446
  );
7552
7447
  }
7553
- case 4 /* CurveBalanced */: {
7448
+ case 7 /* CurveBalanced */: {
7554
7449
  let weights = toWeightCurve(minBinId, maxBinId, activeId);
7555
7450
  return autoFillXByWeight(
7556
7451
  activeId,
@@ -7561,7 +7456,7 @@ function autoFillXByStrategy(activeId, binStep, amountY, amountXInActiveBin, amo
7561
7456
  weights
7562
7457
  );
7563
7458
  }
7564
- case 5 /* BidAskBalanced */: {
7459
+ case 8 /* BidAskBalanced */: {
7565
7460
  let weights = toWeightBidAsk(minBinId, maxBinId, activeId);
7566
7461
  return autoFillXByWeight(
7567
7462
  activeId,
@@ -7582,7 +7477,31 @@ function toStrategyParameters({
7582
7477
  }) {
7583
7478
  const parameters = [singleSidedX ? 1 : 0, ...new Array(63).fill(0)];
7584
7479
  switch (strategyType) {
7585
- case 3 /* SpotBalanced */: {
7480
+ case 0 /* SpotOneSide */: {
7481
+ return {
7482
+ minBinId,
7483
+ maxBinId,
7484
+ strategyType: { spotOneSide: {} },
7485
+ parameteres: Buffer.from(parameters).toJSON().data
7486
+ };
7487
+ }
7488
+ case 1 /* CurveOneSide */: {
7489
+ return {
7490
+ minBinId,
7491
+ maxBinId,
7492
+ strategyType: { curveOneSide: {} },
7493
+ parameteres: Buffer.from(parameters).toJSON().data
7494
+ };
7495
+ }
7496
+ case 2 /* BidAskOneSide */: {
7497
+ return {
7498
+ minBinId,
7499
+ maxBinId,
7500
+ strategyType: { bidAskOneSide: {} },
7501
+ parameteres: Buffer.from(parameters).toJSON().data
7502
+ };
7503
+ }
7504
+ case 6 /* SpotBalanced */: {
7586
7505
  return {
7587
7506
  minBinId,
7588
7507
  maxBinId,
@@ -7590,7 +7509,7 @@ function toStrategyParameters({
7590
7509
  parameteres: Buffer.from(parameters).toJSON().data
7591
7510
  };
7592
7511
  }
7593
- case 4 /* CurveBalanced */: {
7512
+ case 7 /* CurveBalanced */: {
7594
7513
  return {
7595
7514
  minBinId,
7596
7515
  maxBinId,
@@ -7598,7 +7517,7 @@ function toStrategyParameters({
7598
7517
  parameteres: Buffer.from(parameters).toJSON().data
7599
7518
  };
7600
7519
  }
7601
- case 5 /* BidAskBalanced */: {
7520
+ case 8 /* BidAskBalanced */: {
7602
7521
  return {
7603
7522
  minBinId,
7604
7523
  maxBinId,
@@ -7606,7 +7525,7 @@ function toStrategyParameters({
7606
7525
  parameteres: Buffer.from(parameters).toJSON().data
7607
7526
  };
7608
7527
  }
7609
- case 0 /* SpotImBalanced */: {
7528
+ case 3 /* SpotImBalanced */: {
7610
7529
  return {
7611
7530
  minBinId,
7612
7531
  maxBinId,
@@ -7614,7 +7533,7 @@ function toStrategyParameters({
7614
7533
  parameteres: Buffer.from(parameters).toJSON().data
7615
7534
  };
7616
7535
  }
7617
- case 1 /* CurveImBalanced */: {
7536
+ case 4 /* CurveImBalanced */: {
7618
7537
  return {
7619
7538
  minBinId,
7620
7539
  maxBinId,
@@ -7622,7 +7541,7 @@ function toStrategyParameters({
7622
7541
  parameteres: Buffer.from(parameters).toJSON().data
7623
7542
  };
7624
7543
  }
7625
- case 2 /* BidAskImBalanced */: {
7544
+ case 5 /* BidAskImBalanced */: {
7626
7545
  return {
7627
7546
  minBinId,
7628
7547
  maxBinId,
@@ -7635,7 +7554,7 @@ function toStrategyParameters({
7635
7554
 
7636
7555
  // src/dlmm/helpers/lbPair.ts
7637
7556
  import { AnchorProvider, Program as Program2 } from "@coral-xyz/anchor";
7638
- import { PublicKey as PublicKey5 } from "@solana/web3.js";
7557
+ import { PublicKey as PublicKey4 } from "@solana/web3.js";
7639
7558
  async function getTokensMintFromPoolAddress(connection, poolAddress, opt) {
7640
7559
  const provider = new AnchorProvider(
7641
7560
  connection,
@@ -7648,7 +7567,7 @@ async function getTokensMintFromPoolAddress(connection, poolAddress, opt) {
7648
7567
  provider
7649
7568
  );
7650
7569
  const poolAccount = await program.account.lbPair.fetchNullable(
7651
- new PublicKey5(poolAddress)
7570
+ new PublicKey4(poolAddress)
7652
7571
  );
7653
7572
  if (!poolAccount)
7654
7573
  throw new Error("Pool account not found");
@@ -7702,7 +7621,7 @@ var getOrCreateATAInstruction = async (connection, tokenMint, owner, payer = own
7702
7621
  return { ataPubKey: toAccount, ix: void 0 };
7703
7622
  } catch (e) {
7704
7623
  if (e instanceof TokenAccountNotFoundError || e instanceof TokenInvalidAccountOwnerError) {
7705
- const ix = createAssociatedTokenAccountIdempotentInstruction(
7624
+ const ix = createAssociatedTokenAccountInstruction(
7706
7625
  payer,
7707
7626
  toAccount,
7708
7627
  owner,
@@ -7734,7 +7653,7 @@ var wrapSOLInstruction = (from, to, amount) => {
7734
7653
  toPubkey: to,
7735
7654
  lamports: amount
7736
7655
  }),
7737
- new TransactionInstruction2({
7656
+ new TransactionInstruction({
7738
7657
  keys: [
7739
7658
  {
7740
7659
  pubkey: to,
@@ -7803,7 +7722,7 @@ var getEstimatedComputeUnitIxWithBuffer = async (connection, instructions, feePa
7803
7722
  console.error("Error::getEstimatedComputeUnitUsageWithBuffer", error);
7804
7723
  return 14e5;
7805
7724
  });
7806
- return ComputeBudgetProgram2.setComputeUnitLimit({ units });
7725
+ return ComputeBudgetProgram.setComputeUnitLimit({ units });
7807
7726
  };
7808
7727
 
7809
7728
  // src/dlmm/index.ts
@@ -8147,14 +8066,49 @@ var DLMM = class {
8147
8066
  opt?.programId ?? LBCLMM_PROGRAM_IDS[cluster],
8148
8067
  provider
8149
8068
  );
8150
- const positionsV2 = await program.account.positionV2.all([
8151
- {
8152
- memcmp: {
8153
- bytes: bs58.encode(userPubKey.toBuffer()),
8154
- offset: 8 + 32
8069
+ const [positions, positionsV2] = await Promise.all([
8070
+ program.account.position.all([
8071
+ {
8072
+ memcmp: {
8073
+ bytes: bs58.encode(userPubKey.toBuffer()),
8074
+ offset: 8 + 32
8075
+ }
8155
8076
  }
8156
- }
8077
+ ]),
8078
+ program.account.positionV2.all([
8079
+ {
8080
+ memcmp: {
8081
+ bytes: bs58.encode(userPubKey.toBuffer()),
8082
+ offset: 8 + 32
8083
+ }
8084
+ }
8085
+ ])
8157
8086
  ]);
8087
+ const binArrayPubkeySet = /* @__PURE__ */ new Set();
8088
+ const lbPairSet = /* @__PURE__ */ new Set();
8089
+ positions.forEach(({ account: { upperBinId, lowerBinId, lbPair } }) => {
8090
+ const lowerBinArrayIndex = binIdToBinArrayIndex(new BN10(lowerBinId));
8091
+ const upperBinArrayIndex = binIdToBinArrayIndex(new BN10(upperBinId));
8092
+ const [lowerBinArrayPubKey] = deriveBinArray(
8093
+ lbPair,
8094
+ lowerBinArrayIndex,
8095
+ program.programId
8096
+ );
8097
+ const [upperBinArrayPubKey] = deriveBinArray(
8098
+ lbPair,
8099
+ upperBinArrayIndex,
8100
+ program.programId
8101
+ );
8102
+ binArrayPubkeySet.add(lowerBinArrayPubKey.toBase58());
8103
+ binArrayPubkeySet.add(upperBinArrayPubKey.toBase58());
8104
+ lbPairSet.add(lbPair.toBase58());
8105
+ });
8106
+ const binArrayPubkeyArray = Array.from(binArrayPubkeySet).map(
8107
+ (pubkey) => new PublicKey6(pubkey)
8108
+ );
8109
+ const lbPairArray = Array.from(lbPairSet).map(
8110
+ (pubkey) => new PublicKey6(pubkey)
8111
+ );
8158
8112
  const binArrayPubkeySetV2 = /* @__PURE__ */ new Set();
8159
8113
  const lbPairSetV2 = /* @__PURE__ */ new Set();
8160
8114
  positionsV2.forEach(({ account: { upperBinId, lowerBinId, lbPair } }) => {
@@ -8175,31 +8129,67 @@ var DLMM = class {
8175
8129
  lbPairSetV2.add(lbPair.toBase58());
8176
8130
  });
8177
8131
  const binArrayPubkeyArrayV2 = Array.from(binArrayPubkeySetV2).map(
8178
- (pubkey) => new PublicKey7(pubkey)
8132
+ (pubkey) => new PublicKey6(pubkey)
8179
8133
  );
8180
8134
  const lbPairArrayV2 = Array.from(lbPairSetV2).map(
8181
- (pubkey) => new PublicKey7(pubkey)
8135
+ (pubkey) => new PublicKey6(pubkey)
8182
8136
  );
8183
8137
  const [clockAccInfo, ...binArraysAccInfo] = await chunkedGetMultipleAccountInfos(connection, [
8184
8138
  SYSVAR_CLOCK_PUBKEY,
8139
+ ...binArrayPubkeyArray,
8140
+ ...lbPairArray,
8185
8141
  ...binArrayPubkeyArrayV2,
8186
8142
  ...lbPairArrayV2
8187
8143
  ]);
8144
+ const positionBinArraysMap = /* @__PURE__ */ new Map();
8145
+ for (let i = 0; i < binArrayPubkeyArray.length; i++) {
8146
+ const binArrayPubkey = binArrayPubkeyArray[i];
8147
+ const binArrayAccInfoBuffer = binArraysAccInfo[i];
8148
+ if (!binArrayAccInfoBuffer)
8149
+ throw new Error(
8150
+ `Bin Array account ${binArrayPubkey.toBase58()} not found`
8151
+ );
8152
+ const binArrayAccInfo = program.coder.accounts.decode(
8153
+ "binArray",
8154
+ binArrayAccInfoBuffer.data
8155
+ );
8156
+ positionBinArraysMap.set(binArrayPubkey.toBase58(), binArrayAccInfo);
8157
+ }
8158
+ const lbPairArraysMap = /* @__PURE__ */ new Map();
8159
+ for (let i = binArrayPubkeyArray.length; i < binArrayPubkeyArray.length + lbPairArray.length; i++) {
8160
+ const lbPairPubkey = lbPairArray[i - binArrayPubkeyArray.length];
8161
+ const lbPairAccInfoBuffer = binArraysAccInfo[i];
8162
+ if (!lbPairAccInfoBuffer)
8163
+ throw new Error(`LB Pair account ${lbPairPubkey.toBase58()} not found`);
8164
+ const lbPairAccInfo = program.coder.accounts.decode(
8165
+ "lbPair",
8166
+ lbPairAccInfoBuffer.data
8167
+ );
8168
+ lbPairArraysMap.set(lbPairPubkey.toBase58(), lbPairAccInfo);
8169
+ }
8170
+ const reservePublicKeys = Array.from(lbPairArraysMap.values()).map(({ reserveX, reserveY, tokenXMint, tokenYMint }) => [
8171
+ reserveX,
8172
+ reserveY,
8173
+ tokenXMint,
8174
+ tokenYMint
8175
+ ]).flat();
8188
8176
  const positionBinArraysMapV2 = /* @__PURE__ */ new Map();
8189
- for (let i = 0; i < binArrayPubkeyArrayV2.length; i++) {
8190
- const binArrayPubkey = binArrayPubkeyArrayV2[i];
8177
+ for (let i = binArrayPubkeyArray.length + lbPairArray.length; i < binArrayPubkeyArray.length + lbPairArray.length + binArrayPubkeyArrayV2.length; i++) {
8178
+ const binArrayPubkey = binArrayPubkeyArrayV2[i - (binArrayPubkeyArray.length + lbPairArray.length)];
8191
8179
  const binArrayAccInfoBufferV2 = binArraysAccInfo[i];
8192
- if (binArrayAccInfoBufferV2) {
8193
- const binArrayAccInfo = program.coder.accounts.decode(
8194
- "binArray",
8195
- binArrayAccInfoBufferV2.data
8180
+ if (!binArrayAccInfoBufferV2)
8181
+ throw new Error(
8182
+ `Bin Array account ${binArrayPubkey.toBase58()} not found`
8196
8183
  );
8197
- positionBinArraysMapV2.set(binArrayPubkey.toBase58(), binArrayAccInfo);
8198
- }
8184
+ const binArrayAccInfo = program.coder.accounts.decode(
8185
+ "binArray",
8186
+ binArrayAccInfoBufferV2.data
8187
+ );
8188
+ positionBinArraysMapV2.set(binArrayPubkey.toBase58(), binArrayAccInfo);
8199
8189
  }
8200
8190
  const lbPairArraysMapV2 = /* @__PURE__ */ new Map();
8201
- for (let i = binArrayPubkeyArrayV2.length; i < binArraysAccInfo.length; i++) {
8202
- const lbPairPubkey = lbPairArrayV2[i - binArrayPubkeyArrayV2.length];
8191
+ for (let i = binArrayPubkeyArray.length + lbPairArray.length + binArrayPubkeyArrayV2.length; i < binArraysAccInfo.length; i++) {
8192
+ const lbPairPubkey = lbPairArrayV2[i - (binArrayPubkeyArray.length + lbPairArray.length + binArrayPubkeyArrayV2.length)];
8203
8193
  const lbPairAccInfoBufferV2 = binArraysAccInfo[i];
8204
8194
  if (!lbPairAccInfoBufferV2)
8205
8195
  throw new Error(`LB Pair account ${lbPairPubkey.toBase58()} not found`);
@@ -8217,14 +8207,43 @@ var DLMM = class {
8217
8207
  ]).flat();
8218
8208
  const reserveAccountsInfo = await chunkedGetMultipleAccountInfos(
8219
8209
  program.provider.connection,
8220
- reservePublicKeysV2
8210
+ [...reservePublicKeys, ...reservePublicKeysV2]
8221
8211
  );
8212
+ const lbPairReserveMap = /* @__PURE__ */ new Map();
8213
+ const lbPairMintMap = /* @__PURE__ */ new Map();
8214
+ lbPairArray.forEach((lbPair, idx) => {
8215
+ const index = idx * 4;
8216
+ const reserveAccBufferX = reserveAccountsInfo[index];
8217
+ const reserveAccBufferY = reserveAccountsInfo[index + 1];
8218
+ if (!reserveAccBufferX || !reserveAccBufferY)
8219
+ throw new Error(
8220
+ `Reserve account for LB Pair ${lbPair.toBase58()} not found`
8221
+ );
8222
+ const reserveAccX = AccountLayout.decode(reserveAccBufferX.data);
8223
+ const reserveAccY = AccountLayout.decode(reserveAccBufferY.data);
8224
+ lbPairReserveMap.set(lbPair.toBase58(), {
8225
+ reserveX: reserveAccX.amount,
8226
+ reserveY: reserveAccY.amount
8227
+ });
8228
+ const mintXBuffer = reserveAccountsInfo[index + 2];
8229
+ const mintYBuffer = reserveAccountsInfo[index + 3];
8230
+ if (!mintXBuffer || !mintYBuffer)
8231
+ throw new Error(
8232
+ `Mint account for LB Pair ${lbPair.toBase58()} not found`
8233
+ );
8234
+ const mintX = MintLayout.decode(mintXBuffer.data);
8235
+ const mintY = MintLayout.decode(mintYBuffer.data);
8236
+ lbPairMintMap.set(lbPair.toBase58(), {
8237
+ mintXDecimal: mintX.decimals,
8238
+ mintYDecimal: mintY.decimals
8239
+ });
8240
+ });
8222
8241
  const lbPairReserveMapV2 = /* @__PURE__ */ new Map();
8223
8242
  const lbPairMintMapV2 = /* @__PURE__ */ new Map();
8224
8243
  lbPairArrayV2.forEach((lbPair, idx) => {
8225
8244
  const index = idx * 4;
8226
- const reserveAccBufferXV2 = reserveAccountsInfo[index];
8227
- const reserveAccBufferYV2 = reserveAccountsInfo[index + 1];
8245
+ const reserveAccBufferXV2 = reserveAccountsInfo[reservePublicKeys.length + index];
8246
+ const reserveAccBufferYV2 = reserveAccountsInfo[reservePublicKeys.length + index + 1];
8228
8247
  if (!reserveAccBufferXV2 || !reserveAccBufferYV2)
8229
8248
  throw new Error(
8230
8249
  `Reserve account for LB Pair ${lbPair.toBase58()} not found`
@@ -8235,8 +8254,8 @@ var DLMM = class {
8235
8254
  reserveX: reserveAccX.amount,
8236
8255
  reserveY: reserveAccY.amount
8237
8256
  });
8238
- const mintXBufferV2 = reserveAccountsInfo[index + 2];
8239
- const mintYBufferV2 = reserveAccountsInfo[index + 3];
8257
+ const mintXBufferV2 = reserveAccountsInfo[reservePublicKeys.length + index + 2];
8258
+ const mintYBufferV2 = reserveAccountsInfo[reservePublicKeys.length + index + 3];
8240
8259
  if (!mintXBufferV2 || !mintYBufferV2)
8241
8260
  throw new Error(
8242
8261
  `Mint account for LB Pair ${lbPair.toBase58()} not found`
@@ -8252,6 +8271,74 @@ var DLMM = class {
8252
8271
  clockAccInfo.data.readBigInt64LE(32).toString()
8253
8272
  ).toNumber();
8254
8273
  const positionsMap = /* @__PURE__ */ new Map();
8274
+ for (let position of positions) {
8275
+ const { account, publicKey: positionPubKey } = position;
8276
+ const { upperBinId, lowerBinId, lbPair } = account;
8277
+ const lowerBinArrayIndex = binIdToBinArrayIndex(new BN10(lowerBinId));
8278
+ const upperBinArrayIndex = binIdToBinArrayIndex(new BN10(upperBinId));
8279
+ const [lowerBinArrayPubKey] = deriveBinArray(
8280
+ lbPair,
8281
+ lowerBinArrayIndex,
8282
+ program.programId
8283
+ );
8284
+ const [upperBinArrayPubKey] = deriveBinArray(
8285
+ lbPair,
8286
+ upperBinArrayIndex,
8287
+ program.programId
8288
+ );
8289
+ const lowerBinArray = positionBinArraysMap.get(
8290
+ lowerBinArrayPubKey.toBase58()
8291
+ );
8292
+ const upperBinArray = positionBinArraysMap.get(
8293
+ upperBinArrayPubKey.toBase58()
8294
+ );
8295
+ const lbPairAcc = lbPairArraysMap.get(lbPair.toBase58());
8296
+ const { mintXDecimal, mintYDecimal } = lbPairMintMap.get(
8297
+ lbPair.toBase58()
8298
+ );
8299
+ const reserveXBalance = lbPairReserveMap.get(lbPair.toBase58())?.reserveX ?? BigInt(0);
8300
+ const reserveYBalance = lbPairReserveMap.get(lbPair.toBase58())?.reserveY ?? BigInt(0);
8301
+ const tokenX = {
8302
+ publicKey: lbPairAcc.tokenXMint,
8303
+ reserve: lbPairAcc.reserveX,
8304
+ amount: reserveXBalance,
8305
+ decimal: mintXDecimal
8306
+ };
8307
+ const tokenY = {
8308
+ publicKey: lbPairAcc.tokenYMint,
8309
+ reserve: lbPairAcc.reserveY,
8310
+ amount: reserveYBalance,
8311
+ decimal: mintYDecimal
8312
+ };
8313
+ const positionData = await DLMM.processPosition(
8314
+ program,
8315
+ 0 /* V1 */,
8316
+ lbPairAcc,
8317
+ onChainTimestamp,
8318
+ account,
8319
+ mintXDecimal,
8320
+ mintYDecimal,
8321
+ lowerBinArray,
8322
+ upperBinArray,
8323
+ PublicKey6.default
8324
+ );
8325
+ if (positionData) {
8326
+ positionsMap.set(lbPair.toBase58(), {
8327
+ publicKey: lbPair,
8328
+ lbPair: lbPairAcc,
8329
+ tokenX,
8330
+ tokenY,
8331
+ lbPairPositionsData: [
8332
+ ...positionsMap.get(lbPair.toBase58())?.lbPairPositionsData ?? [],
8333
+ {
8334
+ publicKey: positionPubKey,
8335
+ positionData,
8336
+ version: 0 /* V1 */
8337
+ }
8338
+ ]
8339
+ });
8340
+ }
8341
+ }
8255
8342
  for (let position of positionsV2) {
8256
8343
  const { account, publicKey: positionPubKey } = position;
8257
8344
  const { upperBinId, lowerBinId, lbPair, feeOwner } = account;
@@ -8292,7 +8379,7 @@ var DLMM = class {
8292
8379
  amount: reserveYBalance,
8293
8380
  decimal: quoteTokenDecimal
8294
8381
  };
8295
- const positionData = !!lowerBinArray && !!upperBinArray ? await DLMM.processPosition(
8382
+ const positionData = await DLMM.processPosition(
8296
8383
  program,
8297
8384
  1 /* V2 */,
8298
8385
  lbPairAcc,
@@ -8303,21 +8390,7 @@ var DLMM = class {
8303
8390
  lowerBinArray,
8304
8391
  upperBinArray,
8305
8392
  feeOwner
8306
- ) : {
8307
- totalXAmount: "0",
8308
- totalYAmount: "0",
8309
- positionBinData: [],
8310
- lastUpdatedAt: new BN10(0),
8311
- upperBinId,
8312
- lowerBinId,
8313
- feeX: new BN10(0),
8314
- feeY: new BN10(0),
8315
- rewardOne: new BN10(0),
8316
- rewardTwo: new BN10(0),
8317
- feeOwner,
8318
- totalClaimedFeeXAmount: new BN10(0),
8319
- totalClaimedFeeYAmount: new BN10(0)
8320
- };
8393
+ );
8321
8394
  if (positionData) {
8322
8395
  positionsMap.set(lbPair.toBase58(), {
8323
8396
  publicKey: lbPair,
@@ -8337,6 +8410,56 @@ var DLMM = class {
8337
8410
  }
8338
8411
  return positionsMap;
8339
8412
  }
8413
+ static async migratePosition(connection, positions, newPositions, walletPubkey, opt) {
8414
+ const cluster = opt?.cluster || "mainnet-beta";
8415
+ const provider = new AnchorProvider2(
8416
+ connection,
8417
+ {},
8418
+ AnchorProvider2.defaultOptions()
8419
+ );
8420
+ const program = new Program3(
8421
+ IDL,
8422
+ opt?.programId ?? LBCLMM_PROGRAM_IDS[cluster],
8423
+ provider
8424
+ );
8425
+ const positionsState = await program.account.position.fetchMultiple(
8426
+ positions
8427
+ );
8428
+ const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash("confirmed");
8429
+ return Promise.all(
8430
+ positionsState.map(async ({ lbPair, lowerBinId }, idx) => {
8431
+ const position = positions[idx];
8432
+ const lowerBinArrayIndex = binIdToBinArrayIndex(new BN10(lowerBinId));
8433
+ const upperBinArrayIndex = lowerBinArrayIndex.add(new BN10(1));
8434
+ const [lowerBinArrayPubKey] = deriveBinArray(
8435
+ lbPair,
8436
+ lowerBinArrayIndex,
8437
+ program.programId
8438
+ );
8439
+ const [upperBinArrayPubKey] = deriveBinArray(
8440
+ lbPair,
8441
+ upperBinArrayIndex,
8442
+ program.programId
8443
+ );
8444
+ const migrateTx = await program.methods.migratePosition().accounts({
8445
+ binArrayLower: lowerBinArrayPubKey,
8446
+ binArrayUpper: upperBinArrayPubKey,
8447
+ lbPair,
8448
+ owner: walletPubkey,
8449
+ positionV1: position,
8450
+ positionV2: newPositions[idx],
8451
+ program: program.programId,
8452
+ rentReceiver: walletPubkey,
8453
+ systemProgram: SystemProgram2.programId
8454
+ }).transaction();
8455
+ return new Transaction({
8456
+ blockhash,
8457
+ lastValidBlockHeight,
8458
+ feePayer: walletPubkey
8459
+ }).add(migrateTx);
8460
+ })
8461
+ );
8462
+ }
8340
8463
  static getPricePerLamport(tokenXDecimal, tokenYDecimal, price) {
8341
8464
  return new Decimal5(price).mul(new Decimal5(10 ** (tokenYDecimal - tokenXDecimal))).toString();
8342
8465
  }
@@ -8428,9 +8551,9 @@ var DLMM = class {
8428
8551
  padding: Array(64).fill(0)
8429
8552
  };
8430
8553
  const userTokenX = getAssociatedTokenAddressSync2(tokenX, creatorKey);
8431
- const userTokenY = getAssociatedTokenAddressSync2(tokenY, creatorKey);
8432
8554
  return program.methods.initializeCustomizablePermissionlessLbPair(ixData).accounts({
8433
8555
  lbPair,
8556
+ rent: SYSVAR_RENT_PUBKEY,
8434
8557
  reserveX,
8435
8558
  reserveY,
8436
8559
  binArrayBitmapExtension,
@@ -8440,7 +8563,6 @@ var DLMM = class {
8440
8563
  oracle,
8441
8564
  systemProgram: SystemProgram2.programId,
8442
8565
  userTokenX,
8443
- userTokenY,
8444
8566
  funder: creatorKey
8445
8567
  }).transaction();
8446
8568
  }
@@ -8606,7 +8728,7 @@ var DLMM = class {
8606
8728
  shouldStop = true;
8607
8729
  }
8608
8730
  const accountsToFetch = Array.from(binArraysPubkey).map(
8609
- (pubkey) => new PublicKey7(pubkey)
8731
+ (pubkey) => new PublicKey6(pubkey)
8610
8732
  );
8611
8733
  const binArraysAccInfoBuffer = await chunkedGetMultipleAccountInfos(
8612
8734
  this.program.provider.connection,
@@ -8829,6 +8951,20 @@ var DLMM = class {
8829
8951
  async getPositionsByUserAndLbPair(userPubKey) {
8830
8952
  const promiseResults = await Promise.all([
8831
8953
  this.getActiveBin(),
8954
+ userPubKey && this.program.account.position.all([
8955
+ {
8956
+ memcmp: {
8957
+ bytes: bs58.encode(userPubKey.toBuffer()),
8958
+ offset: 8 + 32
8959
+ }
8960
+ },
8961
+ {
8962
+ memcmp: {
8963
+ bytes: bs58.encode(this.pubkey.toBuffer()),
8964
+ offset: 8
8965
+ }
8966
+ }
8967
+ ]),
8832
8968
  userPubKey && this.program.account.positionV2.all([
8833
8969
  {
8834
8970
  memcmp: {
@@ -8844,7 +8980,7 @@ var DLMM = class {
8844
8980
  }
8845
8981
  ])
8846
8982
  ]);
8847
- const [activeBin, positionsV2] = promiseResults;
8983
+ const [activeBin, positions, positionsV2] = promiseResults;
8848
8984
  if (!activeBin) {
8849
8985
  throw new Error("Error fetching active bin");
8850
8986
  }
@@ -8854,9 +8990,29 @@ var DLMM = class {
8854
8990
  userPositions: []
8855
8991
  };
8856
8992
  }
8857
- if (!positionsV2) {
8993
+ if (!positions || !positionsV2) {
8858
8994
  throw new Error("Error fetching positions");
8859
8995
  }
8996
+ const binArrayPubkeySet = /* @__PURE__ */ new Set();
8997
+ positions.forEach(({ account: { upperBinId, lowerBinId } }) => {
8998
+ const lowerBinArrayIndex = binIdToBinArrayIndex(new BN10(lowerBinId));
8999
+ const upperBinArrayIndex = binIdToBinArrayIndex(new BN10(upperBinId));
9000
+ const [lowerBinArrayPubKey] = deriveBinArray(
9001
+ this.pubkey,
9002
+ lowerBinArrayIndex,
9003
+ this.program.programId
9004
+ );
9005
+ const [upperBinArrayPubKey] = deriveBinArray(
9006
+ this.pubkey,
9007
+ upperBinArrayIndex,
9008
+ this.program.programId
9009
+ );
9010
+ binArrayPubkeySet.add(lowerBinArrayPubKey.toBase58());
9011
+ binArrayPubkeySet.add(upperBinArrayPubKey.toBase58());
9012
+ });
9013
+ const binArrayPubkeyArray = Array.from(binArrayPubkeySet).map(
9014
+ (pubkey) => new PublicKey6(pubkey)
9015
+ );
8860
9016
  const binArrayPubkeySetV2 = /* @__PURE__ */ new Set();
8861
9017
  positionsV2.forEach(({ account: { upperBinId, lowerBinId, lbPair } }) => {
8862
9018
  const lowerBinArrayIndex = binIdToBinArrayIndex(new BN10(lowerBinId));
@@ -8875,20 +9031,35 @@ var DLMM = class {
8875
9031
  binArrayPubkeySetV2.add(upperBinArrayPubKey.toBase58());
8876
9032
  });
8877
9033
  const binArrayPubkeyArrayV2 = Array.from(binArrayPubkeySetV2).map(
8878
- (pubkey) => new PublicKey7(pubkey)
9034
+ (pubkey) => new PublicKey6(pubkey)
8879
9035
  );
8880
9036
  const lbPairAndBinArrays = await chunkedGetMultipleAccountInfos(
8881
9037
  this.program.provider.connection,
8882
9038
  [
8883
9039
  this.pubkey,
8884
9040
  SYSVAR_CLOCK_PUBKEY,
9041
+ ...binArrayPubkeyArray,
8885
9042
  ...binArrayPubkeyArrayV2
8886
9043
  ]
8887
9044
  );
8888
9045
  const [lbPairAccInfo, clockAccInfo, ...binArraysAccInfo] = lbPairAndBinArrays;
9046
+ const positionBinArraysMap = /* @__PURE__ */ new Map();
9047
+ for (let i = 0; i < binArrayPubkeyArray.length; i++) {
9048
+ const binArrayPubkey = binArrayPubkeyArray[i];
9049
+ const binArrayAccBuffer = binArraysAccInfo[i];
9050
+ if (!binArrayAccBuffer)
9051
+ throw new Error(
9052
+ `Bin Array account ${binArrayPubkey.toBase58()} not found`
9053
+ );
9054
+ const binArrayAccInfo = this.program.coder.accounts.decode(
9055
+ "binArray",
9056
+ binArrayAccBuffer.data
9057
+ );
9058
+ positionBinArraysMap.set(binArrayPubkey.toBase58(), binArrayAccInfo);
9059
+ }
8889
9060
  const positionBinArraysMapV2 = /* @__PURE__ */ new Map();
8890
- for (let i = 0; i < binArraysAccInfo.length; i++) {
8891
- const binArrayPubkey = binArrayPubkeyArrayV2[i];
9061
+ for (let i = binArrayPubkeyArray.length; i < binArraysAccInfo.length; i++) {
9062
+ const binArrayPubkey = binArrayPubkeyArrayV2[i - binArrayPubkeyArray.length];
8892
9063
  const binArrayAccBufferV2 = binArraysAccInfo[i];
8893
9064
  if (!binArrayAccBufferV2)
8894
9065
  throw new Error(
@@ -8905,6 +9076,45 @@ var DLMM = class {
8905
9076
  const onChainTimestamp = new BN10(
8906
9077
  clockAccInfo.data.readBigInt64LE(32).toString()
8907
9078
  ).toNumber();
9079
+ const userPositions = await Promise.all(
9080
+ positions.map(async ({ publicKey, account }) => {
9081
+ const { lowerBinId, upperBinId } = account;
9082
+ const lowerBinArrayIndex = binIdToBinArrayIndex(new BN10(lowerBinId));
9083
+ const upperBinArrayIndex = binIdToBinArrayIndex(new BN10(upperBinId));
9084
+ const [lowerBinArrayPubKey] = deriveBinArray(
9085
+ this.pubkey,
9086
+ lowerBinArrayIndex,
9087
+ this.program.programId
9088
+ );
9089
+ const [upperBinArrayPubKey] = deriveBinArray(
9090
+ this.pubkey,
9091
+ upperBinArrayIndex,
9092
+ this.program.programId
9093
+ );
9094
+ const lowerBinArray = positionBinArraysMap.get(
9095
+ lowerBinArrayPubKey.toBase58()
9096
+ );
9097
+ const upperBinArray = positionBinArraysMap.get(
9098
+ upperBinArrayPubKey.toBase58()
9099
+ );
9100
+ return {
9101
+ publicKey,
9102
+ positionData: await DLMM.processPosition(
9103
+ this.program,
9104
+ 0 /* V1 */,
9105
+ this.lbPair,
9106
+ onChainTimestamp,
9107
+ account,
9108
+ this.tokenX.decimal,
9109
+ this.tokenY.decimal,
9110
+ lowerBinArray,
9111
+ upperBinArray,
9112
+ PublicKey6.default
9113
+ ),
9114
+ version: 0 /* V1 */
9115
+ };
9116
+ })
9117
+ );
8908
9118
  const userPositionsV2 = await Promise.all(
8909
9119
  positionsV2.map(async ({ publicKey, account }) => {
8910
9120
  const { lowerBinId, upperBinId, feeOwner } = account;
@@ -8946,7 +9156,7 @@ var DLMM = class {
8946
9156
  );
8947
9157
  return {
8948
9158
  activeBin,
8949
- userPositions: userPositionsV2
9159
+ userPositions: [...userPositions, ...userPositionsV2]
8950
9160
  };
8951
9161
  }
8952
9162
  async quoteCreatePosition({ strategy }) {
@@ -9007,93 +9217,6 @@ var DLMM = class {
9007
9217
  feePayer: user
9008
9218
  }).add(setCUIx, ...instructions);
9009
9219
  }
9010
- /**
9011
- * The function `getPosition` retrieves position information for a given public key and processes it
9012
- * using various data to return a `LbPosition` object.
9013
- * @param {PublicKey} positionPubKey - The `getPosition` function you provided is an asynchronous
9014
- * function that fetches position information based on a given public key. Here's a breakdown of the
9015
- * parameters used in the function:
9016
- * @returns The `getPosition` function returns a Promise that resolves to an object of type
9017
- * `LbPosition`. The object contains the following properties:
9018
- * - `publicKey`: The public key of the position account
9019
- * - `positionData`: Position Object
9020
- * - `version`: The version of the position (in this case, `Position.V2`)
9021
- */
9022
- async getPosition(positionPubKey) {
9023
- const positionAccountInfo = await this.program.account.positionV2.fetch(positionPubKey);
9024
- if (!positionAccountInfo) {
9025
- throw new Error(`Position account ${positionPubKey.toBase58()} not found`);
9026
- }
9027
- const { lowerBinId, upperBinId, feeOwner } = positionAccountInfo;
9028
- const lowerBinArrayIndex = binIdToBinArrayIndex(new BN10(lowerBinId));
9029
- const upperBinArrayIndex = binIdToBinArrayIndex(new BN10(upperBinId));
9030
- const [lowerBinArrayPubKey] = deriveBinArray(
9031
- this.pubkey,
9032
- lowerBinArrayIndex,
9033
- this.program.programId
9034
- );
9035
- const [upperBinArrayPubKey] = deriveBinArray(
9036
- this.pubkey,
9037
- upperBinArrayIndex,
9038
- this.program.programId
9039
- );
9040
- const [clockAccInfo, lowerBinArrayAccInfo, upperBinArrayAccInfo] = await chunkedGetMultipleAccountInfos(
9041
- this.program.provider.connection,
9042
- [
9043
- SYSVAR_CLOCK_PUBKEY,
9044
- lowerBinArrayPubKey,
9045
- upperBinArrayPubKey
9046
- ]
9047
- );
9048
- if (!lowerBinArrayAccInfo || !upperBinArrayAccInfo) {
9049
- return {
9050
- publicKey: positionPubKey,
9051
- positionData: {
9052
- totalXAmount: "0",
9053
- totalYAmount: "0",
9054
- positionBinData: [],
9055
- lastUpdatedAt: new BN10(0),
9056
- upperBinId,
9057
- lowerBinId,
9058
- feeX: new BN10(0),
9059
- feeY: new BN10(0),
9060
- rewardOne: new BN10(0),
9061
- rewardTwo: new BN10(0),
9062
- feeOwner,
9063
- totalClaimedFeeXAmount: new BN10(0),
9064
- totalClaimedFeeYAmount: new BN10(0)
9065
- },
9066
- version: 1 /* V2 */
9067
- };
9068
- }
9069
- const onChainTimestamp = new BN10(
9070
- clockAccInfo.data.readBigInt64LE(32).toString()
9071
- ).toNumber();
9072
- const lowerBinArray = this.program.coder.accounts.decode(
9073
- "binArray",
9074
- lowerBinArrayAccInfo.data
9075
- );
9076
- const upperBinArray = this.program.coder.accounts.decode(
9077
- "binArray",
9078
- upperBinArrayAccInfo.data
9079
- );
9080
- return {
9081
- publicKey: positionPubKey,
9082
- positionData: await DLMM.processPosition(
9083
- this.program,
9084
- 1 /* V2 */,
9085
- this.lbPair,
9086
- onChainTimestamp,
9087
- positionAccountInfo,
9088
- this.tokenX.decimal,
9089
- this.tokenY.decimal,
9090
- lowerBinArray,
9091
- upperBinArray,
9092
- feeOwner
9093
- ),
9094
- version: 1 /* V2 */
9095
- };
9096
- }
9097
9220
  /**
9098
9221
  * The function `initializePositionAndAddLiquidityByStrategy` function is used to initializes a position and adds liquidity
9099
9222
  * @param {TInitializePositionAndAddLiquidityParamsByStrategy}
@@ -9817,13 +9940,9 @@ var DLMM = class {
9817
9940
  bps,
9818
9941
  shouldClaimAndClose = false
9819
9942
  }) {
9820
- const lowerBinIdToRemove = Math.min(...binIds);
9821
- const upperBinIdToRemove = Math.max(...binIds);
9822
- const { lbPair, owner, feeOwner, lowerBinId: positionLowerBinId, liquidityShares } = await this.program.account.positionV2.fetch(position);
9823
- if (liquidityShares.every((share) => share.isZero())) {
9824
- throw new Error("No liquidity to remove");
9825
- }
9826
- const lowerBinArrayIndex = binIdToBinArrayIndex(new BN10(positionLowerBinId));
9943
+ const { lbPair, lowerBinId, owner, feeOwner } = await this.program.account.positionV2.fetch(position);
9944
+ const { reserveX, reserveY, tokenXMint, tokenYMint } = await this.program.account.lbPair.fetch(lbPair);
9945
+ const lowerBinArrayIndex = binIdToBinArrayIndex(new BN10(lowerBinId));
9827
9946
  const upperBinArrayIndex = lowerBinArrayIndex.add(new BN10(1));
9828
9947
  const [binArrayLower] = deriveBinArray(
9829
9948
  lbPair,
@@ -9836,7 +9955,7 @@ var DLMM = class {
9836
9955
  this.program.programId
9837
9956
  );
9838
9957
  const preInstructions = [];
9839
- const walletToReceiveFee = feeOwner.equals(PublicKey7.default) ? user : feeOwner;
9958
+ const walletToReceiveFee = feeOwner.equals(PublicKey6.default) ? user : feeOwner;
9840
9959
  const [
9841
9960
  { ataPubKey: userTokenX, ix: createPayerTokenXIx },
9842
9961
  { ataPubKey: userTokenY, ix: createPayerTokenYIx },
@@ -9883,8 +10002,8 @@ var DLMM = class {
9883
10002
  lbPair: this.pubkey,
9884
10003
  sender: user,
9885
10004
  position,
9886
- reserveX: this.lbPair.reserveX,
9887
- reserveY: this.lbPair.reserveY,
10005
+ reserveX,
10006
+ reserveY,
9888
10007
  tokenProgram: TOKEN_PROGRAM_ID2,
9889
10008
  tokenXMint: this.tokenX.publicKey,
9890
10009
  tokenYMint: this.tokenY.publicKey,
@@ -9894,7 +10013,7 @@ var DLMM = class {
9894
10013
  postInstructions.push(claimSwapFeeIx);
9895
10014
  for (let i = 0; i < 2; i++) {
9896
10015
  const rewardInfo = this.lbPair.rewardInfos[i];
9897
- if (!rewardInfo || rewardInfo.mint.equals(PublicKey7.default))
10016
+ if (!rewardInfo || rewardInfo.mint.equals(PublicKey6.default))
9898
10017
  continue;
9899
10018
  const { ataPubKey, ix: rewardAtaIx } = await getOrCreateATAInstruction(
9900
10019
  this.program.provider.connection,
@@ -9937,19 +10056,21 @@ var DLMM = class {
9937
10056
  const closeWrappedSOLIx = await unwrapSOLInstruction(user);
9938
10057
  closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
9939
10058
  }
9940
- const minBinArrayIndex = binIdToBinArrayIndex(new BN10(lowerBinIdToRemove));
9941
- const maxBinArrayIndex = binIdToBinArrayIndex(new BN10(upperBinIdToRemove));
10059
+ const minBinId = Math.min(...binIds);
10060
+ const maxBinId = Math.max(...binIds);
10061
+ const minBinArrayIndex = binIdToBinArrayIndex(new BN10(minBinId));
10062
+ const maxBinArrayIndex = binIdToBinArrayIndex(new BN10(maxBinId));
9942
10063
  const useExtension = isOverflowDefaultBinArrayBitmap(minBinArrayIndex) || isOverflowDefaultBinArrayBitmap(maxBinArrayIndex);
9943
10064
  const binArrayBitmapExtension = useExtension ? deriveBinArrayBitmapExtension(this.pubkey, this.program.programId)[0] : null;
9944
- const removeLiquidityTx = await this.program.methods.removeLiquidityByRange(lowerBinIdToRemove, upperBinIdToRemove, bps.toNumber()).accounts({
10065
+ const removeLiquidityIx = await this.program.methods.removeLiquidityByRange(minBinId, maxBinId, bps.toNumber()).accounts({
9945
10066
  position,
9946
10067
  lbPair,
9947
10068
  userTokenX,
9948
10069
  userTokenY,
9949
- reserveX: this.lbPair.reserveX,
9950
- reserveY: this.lbPair.reserveY,
9951
- tokenXMint: this.tokenX.publicKey,
9952
- tokenYMint: this.tokenY.publicKey,
10070
+ reserveX,
10071
+ reserveY,
10072
+ tokenXMint,
10073
+ tokenYMint,
9953
10074
  binArrayLower,
9954
10075
  binArrayUpper,
9955
10076
  binArrayBitmapExtension,
@@ -9959,7 +10080,7 @@ var DLMM = class {
9959
10080
  }).instruction();
9960
10081
  const instructions = [
9961
10082
  ...preInstructions,
9962
- removeLiquidityTx,
10083
+ removeLiquidityIx,
9963
10084
  ...postInstructions
9964
10085
  ];
9965
10086
  const setCUIx = await getEstimatedComputeUnitIxWithBuffer(
@@ -10174,7 +10295,6 @@ var DLMM = class {
10174
10295
  let actualOutAmount = new BN10(0);
10175
10296
  let feeAmount = new BN10(0);
10176
10297
  let protocolFeeAmount = new BN10(0);
10177
- let lastFilledActiveBinId = activeId;
10178
10298
  while (!inAmountLeft.isZero()) {
10179
10299
  let binArrayAccountToSwap = findNextBinArrayWithLiquidity(
10180
10300
  swapForY,
@@ -10220,7 +10340,6 @@ var DLMM = class {
10220
10340
  if (!startBin) {
10221
10341
  startBin = bin;
10222
10342
  }
10223
- lastFilledActiveBinId = activeId;
10224
10343
  }
10225
10344
  }
10226
10345
  if (!inAmountLeft.isZero()) {
@@ -10248,7 +10367,7 @@ var DLMM = class {
10248
10367
  const priceImpact = new Decimal5(actualOutAmount.toString()).sub(new Decimal5(outAmountWithoutSlippage.toString())).div(new Decimal5(outAmountWithoutSlippage.toString())).mul(new Decimal5(100));
10249
10368
  const minOutAmount = actualOutAmount.mul(new BN10(BASIS_POINT_MAX).sub(allowedSlippage)).div(new BN10(BASIS_POINT_MAX));
10250
10369
  const endPrice = getPriceOfBinByBinId(
10251
- lastFilledActiveBinId.toNumber(),
10370
+ activeId.toNumber(),
10252
10371
  this.lbPair.binStep
10253
10372
  );
10254
10373
  return {
@@ -10365,6 +10484,7 @@ var DLMM = class {
10365
10484
  priceImpact,
10366
10485
  binArraysPubkey
10367
10486
  }) {
10487
+ const { tokenXMint, tokenYMint, reserveX, reserveY, activeId, oracle } = await this.program.account.lbPair.fetch(lbPair);
10368
10488
  const preInstructions = [];
10369
10489
  const postInstructions = [];
10370
10490
  const [
@@ -10398,6 +10518,9 @@ var DLMM = class {
10398
10518
  const closeWrappedSOLIx = await unwrapSOLInstruction(user);
10399
10519
  closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
10400
10520
  }
10521
+ let swapForY = true;
10522
+ if (outToken.equals(tokenXMint))
10523
+ swapForY = false;
10401
10524
  const binArrays = binArraysPubkey.map((pubkey) => {
10402
10525
  return {
10403
10526
  isSigner: false,
@@ -10411,17 +10534,17 @@ var DLMM = class {
10411
10534
  priceImpact.toNumber()
10412
10535
  ).accounts({
10413
10536
  lbPair,
10414
- reserveX: this.lbPair.reserveX,
10415
- reserveY: this.lbPair.reserveY,
10416
- tokenXMint: this.lbPair.tokenXMint,
10417
- tokenYMint: this.lbPair.tokenYMint,
10537
+ reserveX,
10538
+ reserveY,
10539
+ tokenXMint,
10540
+ tokenYMint,
10418
10541
  tokenXProgram: TOKEN_PROGRAM_ID2,
10419
10542
  tokenYProgram: TOKEN_PROGRAM_ID2,
10420
10543
  user,
10421
10544
  userTokenIn,
10422
10545
  userTokenOut,
10423
10546
  binArrayBitmapExtension: this.binArrayBitmapExtension ? this.binArrayBitmapExtension.publicKey : null,
10424
- oracle: this.lbPair.oracle,
10547
+ oracle,
10425
10548
  hostFeeIn: null
10426
10549
  }).remainingAccounts(binArrays).instruction();
10427
10550
  const instructions = [...preInstructions, swapIx, ...postInstructions];
@@ -10459,6 +10582,7 @@ var DLMM = class {
10459
10582
  user,
10460
10583
  binArraysPubkey
10461
10584
  }) {
10585
+ const { tokenXMint, tokenYMint, reserveX, reserveY, activeId, oracle } = await this.program.account.lbPair.fetch(lbPair);
10462
10586
  const preInstructions = [];
10463
10587
  const postInstructions = [];
10464
10588
  const [
@@ -10492,6 +10616,9 @@ var DLMM = class {
10492
10616
  const closeWrappedSOLIx = await unwrapSOLInstruction(user);
10493
10617
  closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
10494
10618
  }
10619
+ let swapForY = true;
10620
+ if (outToken.equals(tokenXMint))
10621
+ swapForY = false;
10495
10622
  const binArrays = binArraysPubkey.map((pubkey) => {
10496
10623
  return {
10497
10624
  isSigner: false,
@@ -10501,10 +10628,10 @@ var DLMM = class {
10501
10628
  });
10502
10629
  const swapIx = await this.program.methods.swap(inAmount, minOutAmount).accounts({
10503
10630
  lbPair,
10504
- reserveX: this.lbPair.reserveX,
10505
- reserveY: this.lbPair.reserveY,
10506
- tokenXMint: this.lbPair.tokenXMint,
10507
- tokenYMint: this.lbPair.tokenYMint,
10631
+ reserveX,
10632
+ reserveY,
10633
+ tokenXMint,
10634
+ tokenYMint,
10508
10635
  tokenXProgram: TOKEN_PROGRAM_ID2,
10509
10636
  // dont use 2022 first; lack familiarity
10510
10637
  tokenYProgram: TOKEN_PROGRAM_ID2,
@@ -10513,7 +10640,7 @@ var DLMM = class {
10513
10640
  userTokenIn,
10514
10641
  userTokenOut,
10515
10642
  binArrayBitmapExtension: this.binArrayBitmapExtension ? this.binArrayBitmapExtension.publicKey : null,
10516
- oracle: this.lbPair.oracle,
10643
+ oracle,
10517
10644
  hostFeeIn: null
10518
10645
  }).remainingAccounts(binArrays).instruction();
10519
10646
  const instructions = [...preInstructions, swapIx, ...postInstructions];
@@ -10615,21 +10742,6 @@ var DLMM = class {
10615
10742
  lastValidBlockHeight
10616
10743
  }).add(setActivationPointTx);
10617
10744
  }
10618
- async setPairStatus(enabled) {
10619
- const pairStatus = enabled ? 0 : 1;
10620
- const tx = await this.program.methods.setPairStatus(pairStatus).accounts(
10621
- {
10622
- lbPair: this.pubkey,
10623
- admin: this.lbPair.creator
10624
- }
10625
- ).transaction();
10626
- const { blockhash, lastValidBlockHeight } = await this.program.provider.connection.getLatestBlockhash("confirmed");
10627
- return new Transaction({
10628
- feePayer: this.lbPair.creator,
10629
- blockhash,
10630
- lastValidBlockHeight
10631
- }).add(tx);
10632
- }
10633
10745
  /**
10634
10746
  * The function `claimSwapFee` is used to claim swap fees for a specific position owned by a specific owner.
10635
10747
  * @param
@@ -10709,11 +10821,11 @@ var DLMM = class {
10709
10821
  const tokensInvolved = [...pairTokens];
10710
10822
  for (let i = 0; i < 2; i++) {
10711
10823
  const rewardMint = this.lbPair.rewardInfos[i].mint;
10712
- if (!tokensInvolved.some((pubkey) => rewardMint.equals(pubkey)) && !rewardMint.equals(PublicKey7.default)) {
10824
+ if (!tokensInvolved.some((pubkey) => rewardMint.equals(pubkey)) && !rewardMint.equals(PublicKey6.default)) {
10713
10825
  tokensInvolved.push(this.lbPair.rewardInfos[i].mint);
10714
10826
  }
10715
10827
  }
10716
- const feeOwner = position.positionData.feeOwner.equals(PublicKey7.default) ? owner : position.positionData.feeOwner;
10828
+ const feeOwner = position.positionData.feeOwner.equals(PublicKey6.default) ? owner : position.positionData.feeOwner;
10717
10829
  const createATAAccAndIx = await Promise.all(
10718
10830
  tokensInvolved.map((token) => {
10719
10831
  if (pairTokens.some((t) => t.equals(token))) {
@@ -10973,7 +11085,7 @@ var DLMM = class {
10973
11085
  );
10974
11086
  }
10975
11087
  addLiquidityIxs.push([
10976
- ComputeBudgetProgram3.setComputeUnitLimit({
11088
+ ComputeBudgetProgram2.setComputeUnitLimit({
10977
11089
  units: DEFAULT_ADD_LIQUIDITY_CU
10978
11090
  }),
10979
11091
  ...instructions
@@ -11260,7 +11372,7 @@ var DLMM = class {
11260
11372
  const tokensInvolved = [...pairsToken];
11261
11373
  for (let i = 0; i < 2; i++) {
11262
11374
  const rewardMint = this.lbPair.rewardInfos[i].mint;
11263
- if (!tokensInvolved.some((pubkey) => rewardMint.equals(pubkey)) && !rewardMint.equals(PublicKey7.default)) {
11375
+ if (!tokensInvolved.some((pubkey) => rewardMint.equals(pubkey)) && !rewardMint.equals(PublicKey6.default)) {
11264
11376
  tokensInvolved.push(this.lbPair.rewardInfos[i].mint);
11265
11377
  }
11266
11378
  }
@@ -11270,9 +11382,9 @@ var DLMM = class {
11270
11382
  const feeOwners = [
11271
11383
  .../* @__PURE__ */ new Set([
11272
11384
  owner.toBase58(),
11273
- ...positions.filter((p) => !p.positionData.feeOwner.equals(PublicKey7.default)).map((p) => p.positionData.feeOwner.toBase58())
11385
+ ...positions.filter((p) => !p.positionData.feeOwner.equals(PublicKey6.default)).map((p) => p.positionData.feeOwner.toBase58())
11274
11386
  ])
11275
- ].map((pk) => new PublicKey7(pk));
11387
+ ].map((pk) => new PublicKey6(pk));
11276
11388
  const createATAAccAndIx = await Promise.all(
11277
11389
  tokensInvolved.map((token) => {
11278
11390
  if (pairsToken.some((p) => p.equals(token))) {
@@ -11606,7 +11718,7 @@ var DLMM = class {
11606
11718
  const preActivationSwapPoint = this.lbPair.activationPoint.sub(
11607
11719
  this.lbPair.preActivationDuration
11608
11720
  );
11609
- const activationPoint = !this.lbPair.preActivationSwapAddress.equals(PublicKey7.default) && this.lbPair.preActivationSwapAddress.equals(swapInitiator) ? preActivationSwapPoint : this.lbPair.activationPoint;
11721
+ const activationPoint = !this.lbPair.preActivationSwapAddress.equals(PublicKey6.default) && this.lbPair.preActivationSwapAddress.equals(swapInitiator) ? preActivationSwapPoint : this.lbPair.activationPoint;
11610
11722
  if (currentPoint < activationPoint) {
11611
11723
  return true;
11612
11724
  }
@@ -11660,7 +11772,7 @@ var DLMM = class {
11660
11772
  const liquidityShare = positionVersion === 0 /* V1 */ ? position.liquidityShares[binIdxInPosition] : position.liquidityShares[binIdxInPosition].shrn(64);
11661
11773
  for (let j = 0; j < 2; j++) {
11662
11774
  const pairRewardInfo = lbPair.rewardInfos[j];
11663
- if (!pairRewardInfo.mint.equals(PublicKey7.default)) {
11775
+ if (!pairRewardInfo.mint.equals(PublicKey6.default)) {
11664
11776
  let rewardPerTokenStored = binState.rewardPerTokenStored[j];
11665
11777
  if (i == lbPair.activeId && !binState.liquiditySupply.isZero()) {
11666
11778
  const currentTime = new BN10(
@@ -11773,7 +11885,12 @@ var DLMM = class {
11773
11885
  let totalYAmount = new Decimal5(0);
11774
11886
  bins.forEach((bin, idx) => {
11775
11887
  const binSupply = new Decimal5(bin.supply.toString());
11776
- const posShare = new Decimal5(posShares[idx].toString());
11888
+ let posShare;
11889
+ if (bin.version === 1 && version === 0 /* V1 */) {
11890
+ posShare = new Decimal5(posShares[idx].shln(64).toString());
11891
+ } else {
11892
+ posShare = new Decimal5(posShares[idx].toString());
11893
+ }
11777
11894
  const positionXAmount = binSupply.eq(new Decimal5("0")) ? new Decimal5("0") : posShare.mul(bin.xAmount.toString()).div(binSupply);
11778
11895
  const positionYAmount = binSupply.eq(new Decimal5("0")) ? new Decimal5("0") : posShare.mul(bin.yAmount.toString()).div(binSupply);
11779
11896
  totalXAmount = totalXAmount.add(positionXAmount);
@@ -12021,7 +12138,7 @@ var DLMM = class {
12021
12138
  const claimTransactions = [];
12022
12139
  for (let i = 0; i < 2; i++) {
12023
12140
  const rewardInfo = this.lbPair.rewardInfos[i];
12024
- if (!rewardInfo || rewardInfo.mint.equals(PublicKey7.default))
12141
+ if (!rewardInfo || rewardInfo.mint.equals(PublicKey6.default))
12025
12142
  continue;
12026
12143
  const preInstructions = [];
12027
12144
  const { ataPubKey, ix } = await getOrCreateATAInstruction(
@@ -12074,7 +12191,7 @@ var DLMM = class {
12074
12191
  this.pubkey,
12075
12192
  this.program.programId
12076
12193
  );
12077
- const walletToReceiveFee = feeOwner.equals(PublicKey7.default) ? owner : feeOwner;
12194
+ const walletToReceiveFee = feeOwner.equals(PublicKey6.default) ? owner : feeOwner;
12078
12195
  const preInstructions = [];
12079
12196
  const [
12080
12197
  { ataPubKey: userTokenX, ix: createInTokenAccountIx },
@@ -12213,6 +12330,7 @@ export {
12213
12330
  toAmountBidSide,
12214
12331
  toAmountBothSide,
12215
12332
  toAmountsBothSideByStrategy,
12333
+ toAmountsOneSideByStrategy,
12216
12334
  toStrategyParameters,
12217
12335
  toWeightDistribution,
12218
12336
  unwrapSOLInstruction,