@meteora-ag/dlmm 1.3.13 → 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,40 +1964,7 @@ var IDL = {
1974
1964
  "args": []
1975
1965
  },
1976
1966
  {
1977
- "name": "updateBaseFeeParameters",
1978
- "accounts": [
1979
- {
1980
- "name": "lbPair",
1981
- "isMut": true,
1982
- "isSigner": false
1983
- },
1984
- {
1985
- "name": "admin",
1986
- "isMut": false,
1987
- "isSigner": true
1988
- },
1989
- {
1990
- "name": "eventAuthority",
1991
- "isMut": false,
1992
- "isSigner": false
1993
- },
1994
- {
1995
- "name": "program",
1996
- "isMut": false,
1997
- "isSigner": false
1998
- }
1999
- ],
2000
- "args": [
2001
- {
2002
- "name": "feeParameter",
2003
- "type": {
2004
- "defined": "BaseFeeParameter"
2005
- }
2006
- }
2007
- ]
2008
- },
2009
- {
2010
- "name": "updateDynamicFeeParameters",
1967
+ "name": "updateFeeParameters",
2011
1968
  "accounts": [
2012
1969
  {
2013
1970
  "name": "lbPair",
@@ -2034,7 +1991,7 @@ var IDL = {
2034
1991
  {
2035
1992
  "name": "feeParameter",
2036
1993
  "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,9 +8271,9 @@ var DLMM = class {
8252
8271
  clockAccInfo.data.readBigInt64LE(32).toString()
8253
8272
  ).toNumber();
8254
8273
  const positionsMap = /* @__PURE__ */ new Map();
8255
- for (let position of positionsV2) {
8274
+ for (let position of positions) {
8256
8275
  const { account, publicKey: positionPubKey } = position;
8257
- const { upperBinId, lowerBinId, lbPair, feeOwner } = account;
8276
+ const { upperBinId, lowerBinId, lbPair } = account;
8258
8277
  const lowerBinArrayIndex = binIdToBinArrayIndex(new BN10(lowerBinId));
8259
8278
  const upperBinArrayIndex = binIdToBinArrayIndex(new BN10(upperBinId));
8260
8279
  const [lowerBinArrayPubKey] = deriveBinArray(
@@ -8267,16 +8286,84 @@ var DLMM = class {
8267
8286
  upperBinArrayIndex,
8268
8287
  program.programId
8269
8288
  );
8270
- const lowerBinArray = positionBinArraysMapV2.get(
8289
+ const lowerBinArray = positionBinArraysMap.get(
8271
8290
  lowerBinArrayPubKey.toBase58()
8272
8291
  );
8273
- const upperBinArray = positionBinArraysMapV2.get(
8292
+ const upperBinArray = positionBinArraysMap.get(
8274
8293
  upperBinArrayPubKey.toBase58()
8275
8294
  );
8276
- const lbPairAcc = lbPairArraysMapV2.get(lbPair.toBase58());
8277
- const [baseTokenDecimal, quoteTokenDecimal] = await Promise.all([
8278
- getTokenDecimals(program.provider.connection, lbPairAcc.tokenXMint),
8279
- getTokenDecimals(program.provider.connection, lbPairAcc.tokenYMint)
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
+ }
8342
+ for (let position of positionsV2) {
8343
+ const { account, publicKey: positionPubKey } = position;
8344
+ const { upperBinId, lowerBinId, lbPair, feeOwner } = account;
8345
+ const lowerBinArrayIndex = binIdToBinArrayIndex(new BN10(lowerBinId));
8346
+ const upperBinArrayIndex = binIdToBinArrayIndex(new BN10(upperBinId));
8347
+ const [lowerBinArrayPubKey] = deriveBinArray(
8348
+ lbPair,
8349
+ lowerBinArrayIndex,
8350
+ program.programId
8351
+ );
8352
+ const [upperBinArrayPubKey] = deriveBinArray(
8353
+ lbPair,
8354
+ upperBinArrayIndex,
8355
+ program.programId
8356
+ );
8357
+ const lowerBinArray = positionBinArraysMapV2.get(
8358
+ lowerBinArrayPubKey.toBase58()
8359
+ );
8360
+ const upperBinArray = positionBinArraysMapV2.get(
8361
+ upperBinArrayPubKey.toBase58()
8362
+ );
8363
+ const lbPairAcc = lbPairArraysMapV2.get(lbPair.toBase58());
8364
+ const [baseTokenDecimal, quoteTokenDecimal] = await Promise.all([
8365
+ getTokenDecimals(program.provider.connection, lbPairAcc.tokenXMint),
8366
+ getTokenDecimals(program.provider.connection, lbPairAcc.tokenYMint)
8280
8367
  ]);
8281
8368
  const reserveXBalance = lbPairReserveMapV2.get(lbPair.toBase58())?.reserveX ?? BigInt(0);
8282
8369
  const reserveYBalance = lbPairReserveMapV2.get(lbPair.toBase58())?.reserveY ?? BigInt(0);
@@ -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,124 +8410,63 @@ var DLMM = class {
8337
8410
  }
8338
8411
  return positionsMap;
8339
8412
  }
8340
- static getPricePerLamport(tokenXDecimal, tokenYDecimal, price) {
8341
- return new Decimal5(price).mul(new Decimal5(10 ** (tokenYDecimal - tokenXDecimal))).toString();
8342
- }
8343
- static getBinIdFromPrice(price, binStep, min) {
8344
- const binStepNum = new Decimal5(binStep).div(new Decimal5(BASIS_POINT_MAX));
8345
- const binId = new Decimal5(price).log().dividedBy(new Decimal5(1).add(binStepNum).log());
8346
- return (min ? binId.floor() : binId.ceil()).toNumber();
8347
- }
8348
- /**
8349
- * The function `getLbPairLockInfo` retrieves all pair positions that has locked liquidity.
8350
- * @param {number} [lockDurationOpt] - An optional value indicating the minimum position lock duration that the function should return.
8351
- * Depending on the lbPair activationType, the param should be a number of seconds or a number of slots.
8352
- * @returns The function `getLbPairLockInfo` returns a `Promise` that resolves to a `PairLockInfo`
8353
- * object. The `PairLockInfo` object contains an array of `PositionLockInfo` objects.
8354
- */
8355
- async getLbPairLockInfo(lockDurationOpt) {
8356
- const lockDuration = lockDurationOpt | 0;
8357
- const lbPairPositions = await this.program.account.positionV2.all([
8358
- {
8359
- memcmp: {
8360
- bytes: bs58.encode(this.pubkey.toBuffer()),
8361
- offset: 8
8362
- }
8363
- }
8364
- ]);
8365
- const clockAccInfo = await this.program.provider.connection.getAccountInfo(SYSVAR_CLOCK_PUBKEY);
8366
- const clock = ClockLayout.decode(clockAccInfo.data);
8367
- const currentPoint = this.lbPair.activationType == 0 /* Slot */ ? clock.slot : clock.unixTimestamp;
8368
- const minLockReleasePoint = currentPoint.add(new BN10(lockDuration));
8369
- const positionsWithLock = lbPairPositions.filter((p) => p.account.lockReleasePoint.gt(minLockReleasePoint));
8370
- if (positionsWithLock.length == 0) {
8371
- return {
8372
- positions: []
8373
- };
8374
- }
8375
- const binArrayPubkeySetV2 = /* @__PURE__ */ new Set();
8376
- positionsWithLock.forEach(({ account: { upperBinId, lowerBinId, lbPair } }) => {
8377
- const lowerBinArrayIndex = binIdToBinArrayIndex(new BN10(lowerBinId));
8378
- const upperBinArrayIndex = binIdToBinArrayIndex(new BN10(upperBinId));
8379
- const [lowerBinArrayPubKey] = deriveBinArray(
8380
- this.pubkey,
8381
- lowerBinArrayIndex,
8382
- this.program.programId
8383
- );
8384
- const [upperBinArrayPubKey] = deriveBinArray(
8385
- this.pubkey,
8386
- upperBinArrayIndex,
8387
- this.program.programId
8388
- );
8389
- binArrayPubkeySetV2.add(lowerBinArrayPubKey.toBase58());
8390
- binArrayPubkeySetV2.add(upperBinArrayPubKey.toBase58());
8391
- });
8392
- const binArrayPubkeyArrayV2 = Array.from(binArrayPubkeySetV2).map(
8393
- (pubkey) => new PublicKey7(pubkey)
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()
8394
8419
  );
8395
- const binArraysAccInfo = await chunkedGetMultipleAccountInfos(
8396
- this.program.provider.connection,
8397
- binArrayPubkeyArrayV2
8420
+ const program = new Program3(
8421
+ IDL,
8422
+ opt?.programId ?? LBCLMM_PROGRAM_IDS[cluster],
8423
+ provider
8398
8424
  );
8399
- const positionBinArraysMapV2 = /* @__PURE__ */ new Map();
8400
- for (let i = 0; i < binArraysAccInfo.length; i++) {
8401
- const binArrayPubkey = binArrayPubkeyArrayV2[i];
8402
- const binArrayAccBufferV2 = binArraysAccInfo[i];
8403
- if (!binArrayAccBufferV2)
8404
- throw new Error(
8405
- `Bin Array account ${binArrayPubkey.toBase58()} not found`
8406
- );
8407
- const binArrayAccInfo = this.program.coder.accounts.decode(
8408
- "binArray",
8409
- binArrayAccBufferV2.data
8410
- );
8411
- positionBinArraysMapV2.set(binArrayPubkey.toBase58(), binArrayAccInfo);
8412
- }
8413
- const positionsLockInfo = await Promise.all(
8414
- positionsWithLock.map(async ({ publicKey, account }) => {
8415
- const { lowerBinId, upperBinId, feeOwner } = account;
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];
8416
8432
  const lowerBinArrayIndex = binIdToBinArrayIndex(new BN10(lowerBinId));
8417
- const upperBinArrayIndex = binIdToBinArrayIndex(new BN10(upperBinId));
8433
+ const upperBinArrayIndex = lowerBinArrayIndex.add(new BN10(1));
8418
8434
  const [lowerBinArrayPubKey] = deriveBinArray(
8419
- this.pubkey,
8435
+ lbPair,
8420
8436
  lowerBinArrayIndex,
8421
- this.program.programId
8437
+ program.programId
8422
8438
  );
8423
8439
  const [upperBinArrayPubKey] = deriveBinArray(
8424
- this.pubkey,
8440
+ lbPair,
8425
8441
  upperBinArrayIndex,
8426
- this.program.programId
8427
- );
8428
- const lowerBinArray = positionBinArraysMapV2.get(
8429
- lowerBinArrayPubKey.toBase58()
8442
+ program.programId
8430
8443
  );
8431
- const upperBinArray = positionBinArraysMapV2.get(
8432
- upperBinArrayPubKey.toBase58()
8433
- );
8434
- const positionData = await DLMM.processPosition(
8435
- this.program,
8436
- 1 /* V2 */,
8437
- this.lbPair,
8438
- clock.unixTimestamp.toNumber(),
8439
- account,
8440
- this.tokenX.decimal,
8441
- this.tokenY.decimal,
8442
- lowerBinArray,
8443
- upperBinArray,
8444
- feeOwner
8445
- );
8446
- return {
8447
- positionAddress: publicKey,
8448
- owner: account.owner,
8449
- lockReleasePoint: account.lockReleasePoint.toNumber(),
8450
- tokenXAmount: positionData.totalXAmount,
8451
- tokenYAmount: positionData.totalYAmount
8452
- };
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);
8453
8460
  })
8454
8461
  );
8455
- return {
8456
- positions: positionsLockInfo
8457
- };
8462
+ }
8463
+ static getPricePerLamport(tokenXDecimal, tokenYDecimal, price) {
8464
+ return new Decimal5(price).mul(new Decimal5(10 ** (tokenYDecimal - tokenXDecimal))).toString();
8465
+ }
8466
+ static getBinIdFromPrice(price, binStep, min) {
8467
+ const binStepNum = new Decimal5(binStep).div(new Decimal5(BASIS_POINT_MAX));
8468
+ const binId = new Decimal5(price).log().dividedBy(new Decimal5(1).add(binStepNum).log());
8469
+ return (min ? binId.floor() : binId.ceil()).toNumber();
8458
8470
  }
8459
8471
  /** Public methods */
8460
8472
  static async createPermissionLbPair(connection, binStep, tokenX, tokenY, activeId, baseKey, creatorKey, feeBps, activationType, opt) {
@@ -8539,9 +8551,9 @@ var DLMM = class {
8539
8551
  padding: Array(64).fill(0)
8540
8552
  };
8541
8553
  const userTokenX = getAssociatedTokenAddressSync2(tokenX, creatorKey);
8542
- const userTokenY = getAssociatedTokenAddressSync2(tokenY, creatorKey);
8543
8554
  return program.methods.initializeCustomizablePermissionlessLbPair(ixData).accounts({
8544
8555
  lbPair,
8556
+ rent: SYSVAR_RENT_PUBKEY,
8545
8557
  reserveX,
8546
8558
  reserveY,
8547
8559
  binArrayBitmapExtension,
@@ -8551,7 +8563,6 @@ var DLMM = class {
8551
8563
  oracle,
8552
8564
  systemProgram: SystemProgram2.programId,
8553
8565
  userTokenX,
8554
- userTokenY,
8555
8566
  funder: creatorKey
8556
8567
  }).transaction();
8557
8568
  }
@@ -8717,7 +8728,7 @@ var DLMM = class {
8717
8728
  shouldStop = true;
8718
8729
  }
8719
8730
  const accountsToFetch = Array.from(binArraysPubkey).map(
8720
- (pubkey) => new PublicKey7(pubkey)
8731
+ (pubkey) => new PublicKey6(pubkey)
8721
8732
  );
8722
8733
  const binArraysAccInfoBuffer = await chunkedGetMultipleAccountInfos(
8723
8734
  this.program.provider.connection,
@@ -8940,6 +8951,20 @@ var DLMM = class {
8940
8951
  async getPositionsByUserAndLbPair(userPubKey) {
8941
8952
  const promiseResults = await Promise.all([
8942
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
+ ]),
8943
8968
  userPubKey && this.program.account.positionV2.all([
8944
8969
  {
8945
8970
  memcmp: {
@@ -8955,7 +8980,7 @@ var DLMM = class {
8955
8980
  }
8956
8981
  ])
8957
8982
  ]);
8958
- const [activeBin, positionsV2] = promiseResults;
8983
+ const [activeBin, positions, positionsV2] = promiseResults;
8959
8984
  if (!activeBin) {
8960
8985
  throw new Error("Error fetching active bin");
8961
8986
  }
@@ -8965,9 +8990,29 @@ var DLMM = class {
8965
8990
  userPositions: []
8966
8991
  };
8967
8992
  }
8968
- if (!positionsV2) {
8993
+ if (!positions || !positionsV2) {
8969
8994
  throw new Error("Error fetching positions");
8970
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
+ );
8971
9016
  const binArrayPubkeySetV2 = /* @__PURE__ */ new Set();
8972
9017
  positionsV2.forEach(({ account: { upperBinId, lowerBinId, lbPair } }) => {
8973
9018
  const lowerBinArrayIndex = binIdToBinArrayIndex(new BN10(lowerBinId));
@@ -8986,20 +9031,35 @@ var DLMM = class {
8986
9031
  binArrayPubkeySetV2.add(upperBinArrayPubKey.toBase58());
8987
9032
  });
8988
9033
  const binArrayPubkeyArrayV2 = Array.from(binArrayPubkeySetV2).map(
8989
- (pubkey) => new PublicKey7(pubkey)
9034
+ (pubkey) => new PublicKey6(pubkey)
8990
9035
  );
8991
9036
  const lbPairAndBinArrays = await chunkedGetMultipleAccountInfos(
8992
9037
  this.program.provider.connection,
8993
9038
  [
8994
9039
  this.pubkey,
8995
9040
  SYSVAR_CLOCK_PUBKEY,
9041
+ ...binArrayPubkeyArray,
8996
9042
  ...binArrayPubkeyArrayV2
8997
9043
  ]
8998
9044
  );
8999
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
+ }
9000
9060
  const positionBinArraysMapV2 = /* @__PURE__ */ new Map();
9001
- for (let i = 0; i < binArraysAccInfo.length; i++) {
9002
- const binArrayPubkey = binArrayPubkeyArrayV2[i];
9061
+ for (let i = binArrayPubkeyArray.length; i < binArraysAccInfo.length; i++) {
9062
+ const binArrayPubkey = binArrayPubkeyArrayV2[i - binArrayPubkeyArray.length];
9003
9063
  const binArrayAccBufferV2 = binArraysAccInfo[i];
9004
9064
  if (!binArrayAccBufferV2)
9005
9065
  throw new Error(
@@ -9016,6 +9076,45 @@ var DLMM = class {
9016
9076
  const onChainTimestamp = new BN10(
9017
9077
  clockAccInfo.data.readBigInt64LE(32).toString()
9018
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
+ );
9019
9118
  const userPositionsV2 = await Promise.all(
9020
9119
  positionsV2.map(async ({ publicKey, account }) => {
9021
9120
  const { lowerBinId, upperBinId, feeOwner } = account;
@@ -9057,7 +9156,7 @@ var DLMM = class {
9057
9156
  );
9058
9157
  return {
9059
9158
  activeBin,
9060
- userPositions: userPositionsV2
9159
+ userPositions: [...userPositions, ...userPositionsV2]
9061
9160
  };
9062
9161
  }
9063
9162
  async quoteCreatePosition({ strategy }) {
@@ -9118,93 +9217,6 @@ var DLMM = class {
9118
9217
  feePayer: user
9119
9218
  }).add(setCUIx, ...instructions);
9120
9219
  }
9121
- /**
9122
- * The function `getPosition` retrieves position information for a given public key and processes it
9123
- * using various data to return a `LbPosition` object.
9124
- * @param {PublicKey} positionPubKey - The `getPosition` function you provided is an asynchronous
9125
- * function that fetches position information based on a given public key. Here's a breakdown of the
9126
- * parameters used in the function:
9127
- * @returns The `getPosition` function returns a Promise that resolves to an object of type
9128
- * `LbPosition`. The object contains the following properties:
9129
- * - `publicKey`: The public key of the position account
9130
- * - `positionData`: Position Object
9131
- * - `version`: The version of the position (in this case, `Position.V2`)
9132
- */
9133
- async getPosition(positionPubKey) {
9134
- const positionAccountInfo = await this.program.account.positionV2.fetch(positionPubKey);
9135
- if (!positionAccountInfo) {
9136
- throw new Error(`Position account ${positionPubKey.toBase58()} not found`);
9137
- }
9138
- const { lowerBinId, upperBinId, feeOwner } = positionAccountInfo;
9139
- const lowerBinArrayIndex = binIdToBinArrayIndex(new BN10(lowerBinId));
9140
- const upperBinArrayIndex = binIdToBinArrayIndex(new BN10(upperBinId));
9141
- const [lowerBinArrayPubKey] = deriveBinArray(
9142
- this.pubkey,
9143
- lowerBinArrayIndex,
9144
- this.program.programId
9145
- );
9146
- const [upperBinArrayPubKey] = deriveBinArray(
9147
- this.pubkey,
9148
- upperBinArrayIndex,
9149
- this.program.programId
9150
- );
9151
- const [clockAccInfo, lowerBinArrayAccInfo, upperBinArrayAccInfo] = await chunkedGetMultipleAccountInfos(
9152
- this.program.provider.connection,
9153
- [
9154
- SYSVAR_CLOCK_PUBKEY,
9155
- lowerBinArrayPubKey,
9156
- upperBinArrayPubKey
9157
- ]
9158
- );
9159
- if (!lowerBinArrayAccInfo || !upperBinArrayAccInfo) {
9160
- return {
9161
- publicKey: positionPubKey,
9162
- positionData: {
9163
- totalXAmount: "0",
9164
- totalYAmount: "0",
9165
- positionBinData: [],
9166
- lastUpdatedAt: new BN10(0),
9167
- upperBinId,
9168
- lowerBinId,
9169
- feeX: new BN10(0),
9170
- feeY: new BN10(0),
9171
- rewardOne: new BN10(0),
9172
- rewardTwo: new BN10(0),
9173
- feeOwner,
9174
- totalClaimedFeeXAmount: new BN10(0),
9175
- totalClaimedFeeYAmount: new BN10(0)
9176
- },
9177
- version: 1 /* V2 */
9178
- };
9179
- }
9180
- const onChainTimestamp = new BN10(
9181
- clockAccInfo.data.readBigInt64LE(32).toString()
9182
- ).toNumber();
9183
- const lowerBinArray = this.program.coder.accounts.decode(
9184
- "binArray",
9185
- lowerBinArrayAccInfo.data
9186
- );
9187
- const upperBinArray = this.program.coder.accounts.decode(
9188
- "binArray",
9189
- upperBinArrayAccInfo.data
9190
- );
9191
- return {
9192
- publicKey: positionPubKey,
9193
- positionData: await DLMM.processPosition(
9194
- this.program,
9195
- 1 /* V2 */,
9196
- this.lbPair,
9197
- onChainTimestamp,
9198
- positionAccountInfo,
9199
- this.tokenX.decimal,
9200
- this.tokenY.decimal,
9201
- lowerBinArray,
9202
- upperBinArray,
9203
- feeOwner
9204
- ),
9205
- version: 1 /* V2 */
9206
- };
9207
- }
9208
9220
  /**
9209
9221
  * The function `initializePositionAndAddLiquidityByStrategy` function is used to initializes a position and adds liquidity
9210
9222
  * @param {TInitializePositionAndAddLiquidityParamsByStrategy}
@@ -9928,13 +9940,9 @@ var DLMM = class {
9928
9940
  bps,
9929
9941
  shouldClaimAndClose = false
9930
9942
  }) {
9931
- const lowerBinIdToRemove = Math.min(...binIds);
9932
- const upperBinIdToRemove = Math.max(...binIds);
9933
- const { lbPair, owner, feeOwner, lowerBinId: positionLowerBinId, liquidityShares } = await this.program.account.positionV2.fetch(position);
9934
- if (liquidityShares.every((share) => share.isZero())) {
9935
- throw new Error("No liquidity to remove");
9936
- }
9937
- 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));
9938
9946
  const upperBinArrayIndex = lowerBinArrayIndex.add(new BN10(1));
9939
9947
  const [binArrayLower] = deriveBinArray(
9940
9948
  lbPair,
@@ -9947,7 +9955,7 @@ var DLMM = class {
9947
9955
  this.program.programId
9948
9956
  );
9949
9957
  const preInstructions = [];
9950
- const walletToReceiveFee = feeOwner.equals(PublicKey7.default) ? user : feeOwner;
9958
+ const walletToReceiveFee = feeOwner.equals(PublicKey6.default) ? user : feeOwner;
9951
9959
  const [
9952
9960
  { ataPubKey: userTokenX, ix: createPayerTokenXIx },
9953
9961
  { ataPubKey: userTokenY, ix: createPayerTokenYIx },
@@ -9994,8 +10002,8 @@ var DLMM = class {
9994
10002
  lbPair: this.pubkey,
9995
10003
  sender: user,
9996
10004
  position,
9997
- reserveX: this.lbPair.reserveX,
9998
- reserveY: this.lbPair.reserveY,
10005
+ reserveX,
10006
+ reserveY,
9999
10007
  tokenProgram: TOKEN_PROGRAM_ID2,
10000
10008
  tokenXMint: this.tokenX.publicKey,
10001
10009
  tokenYMint: this.tokenY.publicKey,
@@ -10005,7 +10013,7 @@ var DLMM = class {
10005
10013
  postInstructions.push(claimSwapFeeIx);
10006
10014
  for (let i = 0; i < 2; i++) {
10007
10015
  const rewardInfo = this.lbPair.rewardInfos[i];
10008
- if (!rewardInfo || rewardInfo.mint.equals(PublicKey7.default))
10016
+ if (!rewardInfo || rewardInfo.mint.equals(PublicKey6.default))
10009
10017
  continue;
10010
10018
  const { ataPubKey, ix: rewardAtaIx } = await getOrCreateATAInstruction(
10011
10019
  this.program.provider.connection,
@@ -10048,19 +10056,21 @@ var DLMM = class {
10048
10056
  const closeWrappedSOLIx = await unwrapSOLInstruction(user);
10049
10057
  closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
10050
10058
  }
10051
- const minBinArrayIndex = binIdToBinArrayIndex(new BN10(lowerBinIdToRemove));
10052
- 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));
10053
10063
  const useExtension = isOverflowDefaultBinArrayBitmap(minBinArrayIndex) || isOverflowDefaultBinArrayBitmap(maxBinArrayIndex);
10054
10064
  const binArrayBitmapExtension = useExtension ? deriveBinArrayBitmapExtension(this.pubkey, this.program.programId)[0] : null;
10055
- 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({
10056
10066
  position,
10057
10067
  lbPair,
10058
10068
  userTokenX,
10059
10069
  userTokenY,
10060
- reserveX: this.lbPair.reserveX,
10061
- reserveY: this.lbPair.reserveY,
10062
- tokenXMint: this.tokenX.publicKey,
10063
- tokenYMint: this.tokenY.publicKey,
10070
+ reserveX,
10071
+ reserveY,
10072
+ tokenXMint,
10073
+ tokenYMint,
10064
10074
  binArrayLower,
10065
10075
  binArrayUpper,
10066
10076
  binArrayBitmapExtension,
@@ -10070,7 +10080,7 @@ var DLMM = class {
10070
10080
  }).instruction();
10071
10081
  const instructions = [
10072
10082
  ...preInstructions,
10073
- removeLiquidityTx,
10083
+ removeLiquidityIx,
10074
10084
  ...postInstructions
10075
10085
  ];
10076
10086
  const setCUIx = await getEstimatedComputeUnitIxWithBuffer(
@@ -10285,7 +10295,6 @@ var DLMM = class {
10285
10295
  let actualOutAmount = new BN10(0);
10286
10296
  let feeAmount = new BN10(0);
10287
10297
  let protocolFeeAmount = new BN10(0);
10288
- let lastFilledActiveBinId = activeId;
10289
10298
  while (!inAmountLeft.isZero()) {
10290
10299
  let binArrayAccountToSwap = findNextBinArrayWithLiquidity(
10291
10300
  swapForY,
@@ -10331,7 +10340,6 @@ var DLMM = class {
10331
10340
  if (!startBin) {
10332
10341
  startBin = bin;
10333
10342
  }
10334
- lastFilledActiveBinId = activeId;
10335
10343
  }
10336
10344
  }
10337
10345
  if (!inAmountLeft.isZero()) {
@@ -10359,7 +10367,7 @@ var DLMM = class {
10359
10367
  const priceImpact = new Decimal5(actualOutAmount.toString()).sub(new Decimal5(outAmountWithoutSlippage.toString())).div(new Decimal5(outAmountWithoutSlippage.toString())).mul(new Decimal5(100));
10360
10368
  const minOutAmount = actualOutAmount.mul(new BN10(BASIS_POINT_MAX).sub(allowedSlippage)).div(new BN10(BASIS_POINT_MAX));
10361
10369
  const endPrice = getPriceOfBinByBinId(
10362
- lastFilledActiveBinId.toNumber(),
10370
+ activeId.toNumber(),
10363
10371
  this.lbPair.binStep
10364
10372
  );
10365
10373
  return {
@@ -10476,6 +10484,7 @@ var DLMM = class {
10476
10484
  priceImpact,
10477
10485
  binArraysPubkey
10478
10486
  }) {
10487
+ const { tokenXMint, tokenYMint, reserveX, reserveY, activeId, oracle } = await this.program.account.lbPair.fetch(lbPair);
10479
10488
  const preInstructions = [];
10480
10489
  const postInstructions = [];
10481
10490
  const [
@@ -10509,6 +10518,9 @@ var DLMM = class {
10509
10518
  const closeWrappedSOLIx = await unwrapSOLInstruction(user);
10510
10519
  closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
10511
10520
  }
10521
+ let swapForY = true;
10522
+ if (outToken.equals(tokenXMint))
10523
+ swapForY = false;
10512
10524
  const binArrays = binArraysPubkey.map((pubkey) => {
10513
10525
  return {
10514
10526
  isSigner: false,
@@ -10522,17 +10534,17 @@ var DLMM = class {
10522
10534
  priceImpact.toNumber()
10523
10535
  ).accounts({
10524
10536
  lbPair,
10525
- reserveX: this.lbPair.reserveX,
10526
- reserveY: this.lbPair.reserveY,
10527
- tokenXMint: this.lbPair.tokenXMint,
10528
- tokenYMint: this.lbPair.tokenYMint,
10537
+ reserveX,
10538
+ reserveY,
10539
+ tokenXMint,
10540
+ tokenYMint,
10529
10541
  tokenXProgram: TOKEN_PROGRAM_ID2,
10530
10542
  tokenYProgram: TOKEN_PROGRAM_ID2,
10531
10543
  user,
10532
10544
  userTokenIn,
10533
10545
  userTokenOut,
10534
10546
  binArrayBitmapExtension: this.binArrayBitmapExtension ? this.binArrayBitmapExtension.publicKey : null,
10535
- oracle: this.lbPair.oracle,
10547
+ oracle,
10536
10548
  hostFeeIn: null
10537
10549
  }).remainingAccounts(binArrays).instruction();
10538
10550
  const instructions = [...preInstructions, swapIx, ...postInstructions];
@@ -10570,6 +10582,7 @@ var DLMM = class {
10570
10582
  user,
10571
10583
  binArraysPubkey
10572
10584
  }) {
10585
+ const { tokenXMint, tokenYMint, reserveX, reserveY, activeId, oracle } = await this.program.account.lbPair.fetch(lbPair);
10573
10586
  const preInstructions = [];
10574
10587
  const postInstructions = [];
10575
10588
  const [
@@ -10603,6 +10616,9 @@ var DLMM = class {
10603
10616
  const closeWrappedSOLIx = await unwrapSOLInstruction(user);
10604
10617
  closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
10605
10618
  }
10619
+ let swapForY = true;
10620
+ if (outToken.equals(tokenXMint))
10621
+ swapForY = false;
10606
10622
  const binArrays = binArraysPubkey.map((pubkey) => {
10607
10623
  return {
10608
10624
  isSigner: false,
@@ -10612,10 +10628,10 @@ var DLMM = class {
10612
10628
  });
10613
10629
  const swapIx = await this.program.methods.swap(inAmount, minOutAmount).accounts({
10614
10630
  lbPair,
10615
- reserveX: this.lbPair.reserveX,
10616
- reserveY: this.lbPair.reserveY,
10617
- tokenXMint: this.lbPair.tokenXMint,
10618
- tokenYMint: this.lbPair.tokenYMint,
10631
+ reserveX,
10632
+ reserveY,
10633
+ tokenXMint,
10634
+ tokenYMint,
10619
10635
  tokenXProgram: TOKEN_PROGRAM_ID2,
10620
10636
  // dont use 2022 first; lack familiarity
10621
10637
  tokenYProgram: TOKEN_PROGRAM_ID2,
@@ -10624,7 +10640,7 @@ var DLMM = class {
10624
10640
  userTokenIn,
10625
10641
  userTokenOut,
10626
10642
  binArrayBitmapExtension: this.binArrayBitmapExtension ? this.binArrayBitmapExtension.publicKey : null,
10627
- oracle: this.lbPair.oracle,
10643
+ oracle,
10628
10644
  hostFeeIn: null
10629
10645
  }).remainingAccounts(binArrays).instruction();
10630
10646
  const instructions = [...preInstructions, swapIx, ...postInstructions];
@@ -10726,21 +10742,6 @@ var DLMM = class {
10726
10742
  lastValidBlockHeight
10727
10743
  }).add(setActivationPointTx);
10728
10744
  }
10729
- async setPairStatus(enabled) {
10730
- const pairStatus = enabled ? 0 : 1;
10731
- const tx = await this.program.methods.setPairStatus(pairStatus).accounts(
10732
- {
10733
- lbPair: this.pubkey,
10734
- admin: this.lbPair.creator
10735
- }
10736
- ).transaction();
10737
- const { blockhash, lastValidBlockHeight } = await this.program.provider.connection.getLatestBlockhash("confirmed");
10738
- return new Transaction({
10739
- feePayer: this.lbPair.creator,
10740
- blockhash,
10741
- lastValidBlockHeight
10742
- }).add(tx);
10743
- }
10744
10745
  /**
10745
10746
  * The function `claimSwapFee` is used to claim swap fees for a specific position owned by a specific owner.
10746
10747
  * @param
@@ -10820,11 +10821,11 @@ var DLMM = class {
10820
10821
  const tokensInvolved = [...pairTokens];
10821
10822
  for (let i = 0; i < 2; i++) {
10822
10823
  const rewardMint = this.lbPair.rewardInfos[i].mint;
10823
- if (!tokensInvolved.some((pubkey) => rewardMint.equals(pubkey)) && !rewardMint.equals(PublicKey7.default)) {
10824
+ if (!tokensInvolved.some((pubkey) => rewardMint.equals(pubkey)) && !rewardMint.equals(PublicKey6.default)) {
10824
10825
  tokensInvolved.push(this.lbPair.rewardInfos[i].mint);
10825
10826
  }
10826
10827
  }
10827
- 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;
10828
10829
  const createATAAccAndIx = await Promise.all(
10829
10830
  tokensInvolved.map((token) => {
10830
10831
  if (pairTokens.some((t) => t.equals(token))) {
@@ -11084,7 +11085,7 @@ var DLMM = class {
11084
11085
  );
11085
11086
  }
11086
11087
  addLiquidityIxs.push([
11087
- ComputeBudgetProgram3.setComputeUnitLimit({
11088
+ ComputeBudgetProgram2.setComputeUnitLimit({
11088
11089
  units: DEFAULT_ADD_LIQUIDITY_CU
11089
11090
  }),
11090
11091
  ...instructions
@@ -11371,7 +11372,7 @@ var DLMM = class {
11371
11372
  const tokensInvolved = [...pairsToken];
11372
11373
  for (let i = 0; i < 2; i++) {
11373
11374
  const rewardMint = this.lbPair.rewardInfos[i].mint;
11374
- if (!tokensInvolved.some((pubkey) => rewardMint.equals(pubkey)) && !rewardMint.equals(PublicKey7.default)) {
11375
+ if (!tokensInvolved.some((pubkey) => rewardMint.equals(pubkey)) && !rewardMint.equals(PublicKey6.default)) {
11375
11376
  tokensInvolved.push(this.lbPair.rewardInfos[i].mint);
11376
11377
  }
11377
11378
  }
@@ -11381,9 +11382,9 @@ var DLMM = class {
11381
11382
  const feeOwners = [
11382
11383
  .../* @__PURE__ */ new Set([
11383
11384
  owner.toBase58(),
11384
- ...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())
11385
11386
  ])
11386
- ].map((pk) => new PublicKey7(pk));
11387
+ ].map((pk) => new PublicKey6(pk));
11387
11388
  const createATAAccAndIx = await Promise.all(
11388
11389
  tokensInvolved.map((token) => {
11389
11390
  if (pairsToken.some((p) => p.equals(token))) {
@@ -11717,7 +11718,7 @@ var DLMM = class {
11717
11718
  const preActivationSwapPoint = this.lbPair.activationPoint.sub(
11718
11719
  this.lbPair.preActivationDuration
11719
11720
  );
11720
- 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;
11721
11722
  if (currentPoint < activationPoint) {
11722
11723
  return true;
11723
11724
  }
@@ -11771,7 +11772,7 @@ var DLMM = class {
11771
11772
  const liquidityShare = positionVersion === 0 /* V1 */ ? position.liquidityShares[binIdxInPosition] : position.liquidityShares[binIdxInPosition].shrn(64);
11772
11773
  for (let j = 0; j < 2; j++) {
11773
11774
  const pairRewardInfo = lbPair.rewardInfos[j];
11774
- if (!pairRewardInfo.mint.equals(PublicKey7.default)) {
11775
+ if (!pairRewardInfo.mint.equals(PublicKey6.default)) {
11775
11776
  let rewardPerTokenStored = binState.rewardPerTokenStored[j];
11776
11777
  if (i == lbPair.activeId && !binState.liquiditySupply.isZero()) {
11777
11778
  const currentTime = new BN10(
@@ -11884,7 +11885,12 @@ var DLMM = class {
11884
11885
  let totalYAmount = new Decimal5(0);
11885
11886
  bins.forEach((bin, idx) => {
11886
11887
  const binSupply = new Decimal5(bin.supply.toString());
11887
- 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
+ }
11888
11894
  const positionXAmount = binSupply.eq(new Decimal5("0")) ? new Decimal5("0") : posShare.mul(bin.xAmount.toString()).div(binSupply);
11889
11895
  const positionYAmount = binSupply.eq(new Decimal5("0")) ? new Decimal5("0") : posShare.mul(bin.yAmount.toString()).div(binSupply);
11890
11896
  totalXAmount = totalXAmount.add(positionXAmount);
@@ -12132,7 +12138,7 @@ var DLMM = class {
12132
12138
  const claimTransactions = [];
12133
12139
  for (let i = 0; i < 2; i++) {
12134
12140
  const rewardInfo = this.lbPair.rewardInfos[i];
12135
- if (!rewardInfo || rewardInfo.mint.equals(PublicKey7.default))
12141
+ if (!rewardInfo || rewardInfo.mint.equals(PublicKey6.default))
12136
12142
  continue;
12137
12143
  const preInstructions = [];
12138
12144
  const { ataPubKey, ix } = await getOrCreateATAInstruction(
@@ -12185,7 +12191,7 @@ var DLMM = class {
12185
12191
  this.pubkey,
12186
12192
  this.program.programId
12187
12193
  );
12188
- const walletToReceiveFee = feeOwner.equals(PublicKey7.default) ? owner : feeOwner;
12194
+ const walletToReceiveFee = feeOwner.equals(PublicKey6.default) ? owner : feeOwner;
12189
12195
  const preInstructions = [];
12190
12196
  const [
12191
12197
  { ataPubKey: userTokenX, ix: createInTokenAccountIx },
@@ -12324,6 +12330,7 @@ export {
12324
12330
  toAmountBidSide,
12325
12331
  toAmountBothSide,
12326
12332
  toAmountsBothSideByStrategy,
12333
+ toAmountsOneSideByStrategy,
12327
12334
  toStrategyParameters,
12328
12335
  toWeightDistribution,
12329
12336
  unwrapSOLInstruction,