@meteora-ag/dlmm 1.3.14-sam.0 → 1.3.15

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 ComputeBudgetProgram2,
15
- PublicKey as PublicKey6,
14
+ ComputeBudgetProgram as ComputeBudgetProgram3,
15
+ PublicKey as PublicKey7,
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.2",
28
+ "version": "0.8.6",
29
29
  "name": "lb_clmm",
30
30
  "constants": [
31
31
  {
@@ -113,6 +113,16 @@ 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
+ },
116
126
  {
117
127
  "name": "MAX_BIN_STEP",
118
128
  "type": "u16",
@@ -128,6 +138,11 @@ var IDL = {
128
138
  "type": "u128",
129
139
  "value": "100_000"
130
140
  },
141
+ {
142
+ "name": "MINIMUM_LIQUIDITY",
143
+ "type": "u128",
144
+ "value": "1_000_000"
145
+ },
131
146
  {
132
147
  "name": "BIN_ARRAY",
133
148
  "type": "bytes",
@@ -385,7 +400,7 @@ var IDL = {
385
400
  "isSigner": false
386
401
  },
387
402
  {
388
- "name": "rent",
403
+ "name": "userTokenY",
389
404
  "isMut": false,
390
405
  "isSigner": false
391
406
  },
@@ -1964,7 +1979,40 @@ var IDL = {
1964
1979
  "args": []
1965
1980
  },
1966
1981
  {
1967
- "name": "updateFeeParameters",
1982
+ "name": "updateBaseFeeParameters",
1983
+ "accounts": [
1984
+ {
1985
+ "name": "lbPair",
1986
+ "isMut": true,
1987
+ "isSigner": false
1988
+ },
1989
+ {
1990
+ "name": "admin",
1991
+ "isMut": false,
1992
+ "isSigner": true
1993
+ },
1994
+ {
1995
+ "name": "eventAuthority",
1996
+ "isMut": false,
1997
+ "isSigner": false
1998
+ },
1999
+ {
2000
+ "name": "program",
2001
+ "isMut": false,
2002
+ "isSigner": false
2003
+ }
2004
+ ],
2005
+ "args": [
2006
+ {
2007
+ "name": "feeParameter",
2008
+ "type": {
2009
+ "defined": "BaseFeeParameter"
2010
+ }
2011
+ }
2012
+ ]
2013
+ },
2014
+ {
2015
+ "name": "updateDynamicFeeParameters",
1968
2016
  "accounts": [
1969
2017
  {
1970
2018
  "name": "lbPair",
@@ -1991,7 +2039,7 @@ var IDL = {
1991
2039
  {
1992
2040
  "name": "feeParameter",
1993
2041
  "type": {
1994
- "defined": "FeeParameter"
2042
+ "defined": "DynamicFeeParameter"
1995
2043
  }
1996
2044
  }
1997
2045
  ]
@@ -2174,7 +2222,7 @@ var IDL = {
2174
2222
  "args": []
2175
2223
  },
2176
2224
  {
2177
- "name": "togglePairStatus",
2225
+ "name": "setPairStatus",
2178
2226
  "accounts": [
2179
2227
  {
2180
2228
  "name": "lbPair",
@@ -2187,7 +2235,12 @@ var IDL = {
2187
2235
  "isSigner": true
2188
2236
  }
2189
2237
  ],
2190
- "args": []
2238
+ "args": [
2239
+ {
2240
+ "name": "status",
2241
+ "type": "u8"
2242
+ }
2243
+ ]
2191
2244
  },
2192
2245
  {
2193
2246
  "name": "migratePosition",
@@ -2623,6 +2676,27 @@ var IDL = {
2623
2676
  "type": "publicKey"
2624
2677
  }
2625
2678
  ]
2679
+ },
2680
+ {
2681
+ "name": "setPairStatusPermissionless",
2682
+ "accounts": [
2683
+ {
2684
+ "name": "lbPair",
2685
+ "isMut": true,
2686
+ "isSigner": false
2687
+ },
2688
+ {
2689
+ "name": "creator",
2690
+ "isMut": false,
2691
+ "isSigner": true
2692
+ }
2693
+ ],
2694
+ "args": [
2695
+ {
2696
+ "name": "status",
2697
+ "type": "u8"
2698
+ }
2699
+ ]
2626
2700
  }
2627
2701
  ],
2628
2702
  "accounts": [
@@ -2814,9 +2888,9 @@ var IDL = {
2814
2888
  "type": "u8"
2815
2889
  },
2816
2890
  {
2817
- "name": "padding0",
2891
+ "name": "creatorPoolOnOffControl",
2818
2892
  "docs": [
2819
- "padding 0"
2893
+ "Allow pool creator to enable/disable pool with restricted validation. Only applicable for customizable permissionless pair type."
2820
2894
  ],
2821
2895
  "type": "u8"
2822
2896
  },
@@ -3448,7 +3522,7 @@ var IDL = {
3448
3522
  }
3449
3523
  },
3450
3524
  {
3451
- "name": "FeeParameter",
3525
+ "name": "BaseFeeParameter",
3452
3526
  "type": {
3453
3527
  "kind": "struct",
3454
3528
  "fields": [
@@ -3469,6 +3543,49 @@ var IDL = {
3469
3543
  ]
3470
3544
  }
3471
3545
  },
3546
+ {
3547
+ "name": "DynamicFeeParameter",
3548
+ "type": {
3549
+ "kind": "struct",
3550
+ "fields": [
3551
+ {
3552
+ "name": "filterPeriod",
3553
+ "docs": [
3554
+ "Filter period determine high frequency trading time window."
3555
+ ],
3556
+ "type": "u16"
3557
+ },
3558
+ {
3559
+ "name": "decayPeriod",
3560
+ "docs": [
3561
+ "Decay period determine when the volatile fee start decay / decrease."
3562
+ ],
3563
+ "type": "u16"
3564
+ },
3565
+ {
3566
+ "name": "reductionFactor",
3567
+ "docs": [
3568
+ "Reduction factor controls the volatile fee rate decrement rate."
3569
+ ],
3570
+ "type": "u16"
3571
+ },
3572
+ {
3573
+ "name": "variableFeeControl",
3574
+ "docs": [
3575
+ "Used to scale the variable fee component depending on the dynamic of the market"
3576
+ ],
3577
+ "type": "u32"
3578
+ },
3579
+ {
3580
+ "name": "maxVolatilityAccumulator",
3581
+ "docs": [
3582
+ "Maximum number of bin crossed can be accumulated. Used to cap volatile fee rate."
3583
+ ],
3584
+ "type": "u32"
3585
+ }
3586
+ ]
3587
+ }
3588
+ },
3472
3589
  {
3473
3590
  "name": "LiquidityParameterByStrategyOneSide",
3474
3591
  "type": {
@@ -3851,6 +3968,13 @@ var IDL = {
3851
3968
  "option": "u64"
3852
3969
  }
3853
3970
  },
3971
+ {
3972
+ "name": "creatorPoolOnOffControl",
3973
+ "docs": [
3974
+ "Pool creator have permission to enable/disable pool with restricted program validation. Only applicable for customizable permissionless pool."
3975
+ ],
3976
+ "type": "bool"
3977
+ },
3854
3978
  {
3855
3979
  "name": "padding",
3856
3980
  "docs": [
@@ -3859,7 +3983,7 @@ var IDL = {
3859
3983
  "type": {
3860
3984
  "array": [
3861
3985
  "u8",
3862
- 64
3986
+ 63
3863
3987
  ]
3864
3988
  }
3865
3989
  }
@@ -4834,6 +4958,41 @@ var IDL = {
4834
4958
  }
4835
4959
  ]
4836
4960
  },
4961
+ {
4962
+ "name": "DynamicFeeParameterUpdate",
4963
+ "fields": [
4964
+ {
4965
+ "name": "lbPair",
4966
+ "type": "publicKey",
4967
+ "index": false
4968
+ },
4969
+ {
4970
+ "name": "filterPeriod",
4971
+ "type": "u16",
4972
+ "index": false
4973
+ },
4974
+ {
4975
+ "name": "decayPeriod",
4976
+ "type": "u16",
4977
+ "index": false
4978
+ },
4979
+ {
4980
+ "name": "reductionFactor",
4981
+ "type": "u16",
4982
+ "index": false
4983
+ },
4984
+ {
4985
+ "name": "variableFeeControl",
4986
+ "type": "u32",
4987
+ "index": false
4988
+ },
4989
+ {
4990
+ "name": "maxVolatilityAccumulator",
4991
+ "type": "u32",
4992
+ "index": false
4993
+ }
4994
+ ]
4995
+ },
4837
4996
  {
4838
4997
  "name": "IncreaseObservation",
4839
4998
  "fields": [
@@ -5270,6 +5429,21 @@ var IDL = {
5270
5429
  "code": 6065,
5271
5430
  "name": "AlreadyPassPreActivationSwapPoint",
5272
5431
  "msg": "Already pass pre-activation swap point"
5432
+ },
5433
+ {
5434
+ "code": 6066,
5435
+ "name": "InvalidStatus",
5436
+ "msg": "Invalid status"
5437
+ },
5438
+ {
5439
+ "code": 6067,
5440
+ "name": "ExceededMaxOracleLength",
5441
+ "msg": "Exceed max oracle length"
5442
+ },
5443
+ {
5444
+ "code": 6068,
5445
+ "name": "InvalidMinimumLiquidity",
5446
+ "msg": "Invalid minimum liquidity"
5273
5447
  }
5274
5448
  ]
5275
5449
  };
@@ -5323,6 +5497,7 @@ var MAX_ACTIVE_BIN_SLIPPAGE = 3;
5323
5497
  var ILM_BASE = new PublicKey(
5324
5498
  "MFGQxwAmB91SwuYX36okv2Qmdc9aMuHTwWGUrp4AtB1"
5325
5499
  );
5500
+ var MAX_EXTRA_BIN_ARRAYS = 3;
5326
5501
 
5327
5502
  // src/dlmm/error.ts
5328
5503
  import { AnchorError } from "@coral-xyz/anchor";
@@ -5373,16 +5548,16 @@ import {
5373
5548
  TOKEN_PROGRAM_ID,
5374
5549
  TokenAccountNotFoundError,
5375
5550
  TokenInvalidAccountOwnerError,
5376
- createAssociatedTokenAccountInstruction,
5551
+ createAssociatedTokenAccountIdempotentInstruction,
5377
5552
  createCloseAccountInstruction,
5378
5553
  getAccount,
5379
5554
  getAssociatedTokenAddressSync,
5380
5555
  getMint
5381
5556
  } from "@solana/spl-token";
5382
5557
  import {
5383
- ComputeBudgetProgram,
5558
+ ComputeBudgetProgram as ComputeBudgetProgram2,
5384
5559
  SystemProgram,
5385
- TransactionInstruction
5560
+ TransactionInstruction as TransactionInstruction2
5386
5561
  } from "@solana/web3.js";
5387
5562
 
5388
5563
  // src/dlmm/helpers/math.ts
@@ -6341,22 +6516,51 @@ function generateBinAmount(amount, binStep, binId, tokenXDecimal, tokenYDecimal,
6341
6516
  return new BN5(c1.sub(c0).floor().toString());
6342
6517
  }
6343
6518
 
6344
- // src/dlmm/helpers/index.ts
6345
- import { getSimulationComputeUnits } from "@solana-developers/helpers";
6346
-
6347
6519
  // src/dlmm/helpers/computeUnit.ts
6520
+ import { ComputeBudgetProgram, PublicKey as PublicKey2, TransactionMessage, VersionedTransaction } from "@solana/web3.js";
6348
6521
  var DEFAULT_ADD_LIQUIDITY_CU = 8e5;
6349
6522
  var MIN_CU_BUFFER = 5e4;
6350
6523
  var MAX_CU_BUFFER = 2e5;
6524
+ var getSimulationComputeUnits = async (connection, instructions, payer, lookupTables, commitment = "confirmed") => {
6525
+ const testInstructions = [
6526
+ // Set an arbitrarily high number in simulation
6527
+ // so we can be sure the transaction will succeed
6528
+ // and get the real compute units used
6529
+ ComputeBudgetProgram.setComputeUnitLimit({ units: 14e5 }),
6530
+ ...instructions
6531
+ ];
6532
+ const testTransaction = new VersionedTransaction(
6533
+ new TransactionMessage({
6534
+ instructions: testInstructions,
6535
+ payerKey: payer,
6536
+ // RecentBlockhash can by any public key during simulation
6537
+ // since 'replaceRecentBlockhash' is set to 'true' below
6538
+ recentBlockhash: PublicKey2.default.toString()
6539
+ }).compileToV0Message(lookupTables)
6540
+ );
6541
+ const rpcResponse = await connection.simulateTransaction(testTransaction, {
6542
+ replaceRecentBlockhash: true,
6543
+ sigVerify: false,
6544
+ commitment
6545
+ });
6546
+ if (rpcResponse?.value?.err) {
6547
+ const logs = rpcResponse.value.logs?.join("\n \u2022 ") || "No logs available";
6548
+ throw new Error(
6549
+ `Transaction simulation failed:
6550
+ \u2022${logs}` + JSON.stringify(rpcResponse?.value?.err)
6551
+ );
6552
+ }
6553
+ return rpcResponse.value.unitsConsumed || null;
6554
+ };
6351
6555
 
6352
6556
  // src/dlmm/helpers/derive.ts
6353
- import { PublicKey as PublicKey2 } from "@solana/web3.js";
6557
+ import { PublicKey as PublicKey3 } from "@solana/web3.js";
6354
6558
  function sortTokenMints(tokenX, tokenY) {
6355
6559
  const [minKey, maxKey] = tokenX.toBuffer().compare(tokenY.toBuffer()) == 1 ? [tokenY, tokenX] : [tokenX, tokenY];
6356
6560
  return [minKey, maxKey];
6357
6561
  }
6358
6562
  function derivePresetParameter(binStep, programId) {
6359
- return PublicKey2.findProgramAddressSync(
6563
+ return PublicKey3.findProgramAddressSync(
6360
6564
  [
6361
6565
  Buffer.from("preset_parameter"),
6362
6566
  new Uint8Array(binStep.toArrayLike(Buffer, "le", 2))
@@ -6365,7 +6569,7 @@ function derivePresetParameter(binStep, programId) {
6365
6569
  );
6366
6570
  }
6367
6571
  function derivePresetParameter2(binStep, baseFactor, programId) {
6368
- return PublicKey2.findProgramAddressSync(
6572
+ return PublicKey3.findProgramAddressSync(
6369
6573
  [
6370
6574
  Buffer.from("preset_parameter"),
6371
6575
  new Uint8Array(binStep.toArrayLike(Buffer, "le", 2)),
@@ -6376,7 +6580,7 @@ function derivePresetParameter2(binStep, baseFactor, programId) {
6376
6580
  }
6377
6581
  function deriveLbPair2(tokenX, tokenY, binStep, baseFactor, programId) {
6378
6582
  const [minKey, maxKey] = sortTokenMints(tokenX, tokenY);
6379
- return PublicKey2.findProgramAddressSync(
6583
+ return PublicKey3.findProgramAddressSync(
6380
6584
  [
6381
6585
  minKey.toBuffer(),
6382
6586
  maxKey.toBuffer(),
@@ -6388,7 +6592,7 @@ function deriveLbPair2(tokenX, tokenY, binStep, baseFactor, programId) {
6388
6592
  }
6389
6593
  function deriveLbPair(tokenX, tokenY, binStep, programId) {
6390
6594
  const [minKey, maxKey] = sortTokenMints(tokenX, tokenY);
6391
- return PublicKey2.findProgramAddressSync(
6595
+ return PublicKey3.findProgramAddressSync(
6392
6596
  [
6393
6597
  minKey.toBuffer(),
6394
6598
  maxKey.toBuffer(),
@@ -6399,14 +6603,14 @@ function deriveLbPair(tokenX, tokenY, binStep, programId) {
6399
6603
  }
6400
6604
  function deriveCustomizablePermissionlessLbPair(tokenX, tokenY, programId) {
6401
6605
  const [minKey, maxKey] = sortTokenMints(tokenX, tokenY);
6402
- return PublicKey2.findProgramAddressSync(
6606
+ return PublicKey3.findProgramAddressSync(
6403
6607
  [ILM_BASE.toBuffer(), minKey.toBuffer(), maxKey.toBuffer()],
6404
6608
  programId
6405
6609
  );
6406
6610
  }
6407
6611
  function derivePermissionLbPair(baseKey, tokenX, tokenY, binStep, programId) {
6408
6612
  const [minKey, maxKey] = sortTokenMints(tokenX, tokenY);
6409
- return PublicKey2.findProgramAddressSync(
6613
+ return PublicKey3.findProgramAddressSync(
6410
6614
  [
6411
6615
  baseKey.toBuffer(),
6412
6616
  minKey.toBuffer(),
@@ -6417,7 +6621,7 @@ function derivePermissionLbPair(baseKey, tokenX, tokenY, binStep, programId) {
6417
6621
  );
6418
6622
  }
6419
6623
  function deriveOracle(lbPair, programId) {
6420
- return PublicKey2.findProgramAddressSync(
6624
+ return PublicKey3.findProgramAddressSync(
6421
6625
  [Buffer.from("oracle"), lbPair.toBytes()],
6422
6626
  programId
6423
6627
  );
@@ -6431,7 +6635,7 @@ function derivePosition(lbPair, base, lowerBinId, width, programId) {
6431
6635
  } else {
6432
6636
  lowerBinIdBytes = new Uint8Array(lowerBinId.toArrayLike(Buffer, "le", 4));
6433
6637
  }
6434
- return PublicKey2.findProgramAddressSync(
6638
+ return PublicKey3.findProgramAddressSync(
6435
6639
  [
6436
6640
  Buffer.from("position"),
6437
6641
  lbPair.toBuffer(),
@@ -6451,13 +6655,13 @@ function deriveBinArray(lbPair, index, programId) {
6451
6655
  } else {
6452
6656
  binArrayBytes = new Uint8Array(index.toArrayLike(Buffer, "le", 8));
6453
6657
  }
6454
- return PublicKey2.findProgramAddressSync(
6658
+ return PublicKey3.findProgramAddressSync(
6455
6659
  [Buffer.from("bin_array"), lbPair.toBytes(), binArrayBytes],
6456
6660
  programId
6457
6661
  );
6458
6662
  }
6459
6663
  function deriveReserve(token, lbPair, programId) {
6460
- return PublicKey2.findProgramAddressSync(
6664
+ return PublicKey3.findProgramAddressSync(
6461
6665
  [lbPair.toBuffer(), token.toBuffer()],
6462
6666
  programId
6463
6667
  );
@@ -6465,7 +6669,7 @@ function deriveReserve(token, lbPair, programId) {
6465
6669
 
6466
6670
  // src/dlmm/helpers/binArray.ts
6467
6671
  import { BN as BN7 } from "@coral-xyz/anchor";
6468
- import { PublicKey as PublicKey3 } from "@solana/web3.js";
6672
+ import { PublicKey as PublicKey4 } from "@solana/web3.js";
6469
6673
 
6470
6674
  // src/dlmm/types/index.ts
6471
6675
  import {
@@ -6484,9 +6688,6 @@ var PairType = /* @__PURE__ */ ((PairType2) => {
6484
6688
  return PairType2;
6485
6689
  })(PairType || {});
6486
6690
  var Strategy = {
6487
- SpotOneSide: { spotOneSide: {} },
6488
- CurveOneSide: { curveOneSide: {} },
6489
- BidAskOneSide: { bidAskOneSide: {} },
6490
6691
  SpotBalanced: { spotBalanced: {} },
6491
6692
  CurveBalanced: { curveBalanced: {} },
6492
6693
  BidAskBalanced: { bidAskBalanced: {} },
@@ -6495,15 +6696,12 @@ var Strategy = {
6495
6696
  BidAskImBalanced: { bidAskImBalanced: {} }
6496
6697
  };
6497
6698
  var StrategyType = /* @__PURE__ */ ((StrategyType2) => {
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";
6699
+ StrategyType2[StrategyType2["SpotImBalanced"] = 0] = "SpotImBalanced";
6700
+ StrategyType2[StrategyType2["CurveImBalanced"] = 1] = "CurveImBalanced";
6701
+ StrategyType2[StrategyType2["BidAskImBalanced"] = 2] = "BidAskImBalanced";
6702
+ StrategyType2[StrategyType2["SpotBalanced"] = 3] = "SpotBalanced";
6703
+ StrategyType2[StrategyType2["CurveBalanced"] = 4] = "CurveBalanced";
6704
+ StrategyType2[StrategyType2["BidAskBalanced"] = 5] = "BidAskBalanced";
6507
6705
  return StrategyType2;
6508
6706
  })(StrategyType || {});
6509
6707
  var ActivationType = /* @__PURE__ */ ((ActivationType2) => {
@@ -6659,7 +6857,7 @@ function isOverflowDefaultBinArrayBitmap(binArrayIndex) {
6659
6857
  return binArrayIndex.gt(maxBinArrayIndex) || binArrayIndex.lt(minBinArrayIndex);
6660
6858
  }
6661
6859
  function deriveBinArrayBitmapExtension(lbPair, programId) {
6662
- return PublicKey3.findProgramAddressSync(
6860
+ return PublicKey4.findProgramAddressSync(
6663
6861
  [Buffer.from("bitmap"), lbPair.toBytes()],
6664
6862
  programId
6665
6863
  );
@@ -6808,7 +7006,7 @@ function getBinArraysRequiredByPositionRange(pair, fromBinId, toBinId, programId
6808
7006
  binArrays.set(upperBinArray.toBase58(), upperBinArrayIndex);
6809
7007
  }
6810
7008
  return Array.from(binArrays, ([key, index]) => ({
6811
- key: new PublicKey3(key),
7009
+ key: new PublicKey4(key),
6812
7010
  index
6813
7011
  }));
6814
7012
  }
@@ -7055,53 +7253,10 @@ function toWeightBidAsk(minBinId, maxBinId, activeId) {
7055
7253
  }
7056
7254
  return distributions;
7057
7255
  }
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
- }
7096
7256
  function toAmountsBothSideByStrategy(activeId, binStep, minBinId, maxBinId, amountX, amountY, amountXInActiveBin, amountYInActiveBin, strategyType) {
7097
7257
  const isSingleSideX = amountY.isZero();
7098
7258
  switch (strategyType) {
7099
- case 0 /* SpotOneSide */:
7100
- case 1 /* CurveOneSide */:
7101
- case 2 /* BidAskOneSide */: {
7102
- throw "Invalid Strategy Parameters";
7103
- }
7104
- case 3 /* SpotImBalanced */: {
7259
+ case 0 /* SpotImBalanced */: {
7105
7260
  if (activeId < minBinId || activeId > maxBinId) {
7106
7261
  const weights = toWeightSpotBalanced(minBinId, maxBinId);
7107
7262
  return toAmountBothSide(
@@ -7173,7 +7328,7 @@ function toAmountsBothSideByStrategy(activeId, binStep, minBinId, maxBinId, amou
7173
7328
  }
7174
7329
  return amountsInBin;
7175
7330
  }
7176
- case 4 /* CurveImBalanced */: {
7331
+ case 1 /* CurveImBalanced */: {
7177
7332
  if (activeId < minBinId) {
7178
7333
  let weights = toWeightDecendingOrder(minBinId, maxBinId);
7179
7334
  return toAmountBothSide(
@@ -7257,7 +7412,7 @@ function toAmountsBothSideByStrategy(activeId, binStep, minBinId, maxBinId, amou
7257
7412
  }
7258
7413
  return amountsInBin;
7259
7414
  }
7260
- case 5 /* BidAskImBalanced */: {
7415
+ case 2 /* BidAskImBalanced */: {
7261
7416
  if (activeId < minBinId) {
7262
7417
  const weights = toWeightAscendingOrder(minBinId, maxBinId);
7263
7418
  return toAmountBothSide(
@@ -7341,7 +7496,7 @@ function toAmountsBothSideByStrategy(activeId, binStep, minBinId, maxBinId, amou
7341
7496
  }
7342
7497
  return amountsInBin;
7343
7498
  }
7344
- case 6 /* SpotBalanced */: {
7499
+ case 3 /* SpotBalanced */: {
7345
7500
  let weights = toWeightSpotBalanced(minBinId, maxBinId);
7346
7501
  return toAmountBothSide(
7347
7502
  activeId,
@@ -7353,7 +7508,7 @@ function toAmountsBothSideByStrategy(activeId, binStep, minBinId, maxBinId, amou
7353
7508
  weights
7354
7509
  );
7355
7510
  }
7356
- case 7 /* CurveBalanced */: {
7511
+ case 4 /* CurveBalanced */: {
7357
7512
  let weights = toWeightCurve(minBinId, maxBinId, activeId);
7358
7513
  return toAmountBothSide(
7359
7514
  activeId,
@@ -7365,7 +7520,7 @@ function toAmountsBothSideByStrategy(activeId, binStep, minBinId, maxBinId, amou
7365
7520
  weights
7366
7521
  );
7367
7522
  }
7368
- case 8 /* BidAskBalanced */: {
7523
+ case 5 /* BidAskBalanced */: {
7369
7524
  let weights = toWeightBidAsk(minBinId, maxBinId, activeId);
7370
7525
  return toAmountBothSide(
7371
7526
  activeId,
@@ -7381,15 +7536,12 @@ function toAmountsBothSideByStrategy(activeId, binStep, minBinId, maxBinId, amou
7381
7536
  }
7382
7537
  function autoFillYByStrategy(activeId, binStep, amountX, amountXInActiveBin, amountYInActiveBin, minBinId, maxBinId, strategyType) {
7383
7538
  switch (strategyType) {
7384
- case 0 /* SpotOneSide */:
7385
- case 1 /* CurveOneSide */:
7386
- case 2 /* BidAskOneSide */:
7387
- case 3 /* SpotImBalanced */:
7388
- case 4 /* CurveImBalanced */:
7389
- case 5 /* BidAskImBalanced */: {
7539
+ case 0 /* SpotImBalanced */:
7540
+ case 1 /* CurveImBalanced */:
7541
+ case 2 /* BidAskImBalanced */: {
7390
7542
  throw "Invalid Strategy Parameters";
7391
7543
  }
7392
- case 6 /* SpotBalanced */: {
7544
+ case 3 /* SpotBalanced */: {
7393
7545
  let weights = toWeightSpotBalanced(minBinId, maxBinId);
7394
7546
  return autoFillYByWeight(
7395
7547
  activeId,
@@ -7400,7 +7552,7 @@ function autoFillYByStrategy(activeId, binStep, amountX, amountXInActiveBin, amo
7400
7552
  weights
7401
7553
  );
7402
7554
  }
7403
- case 7 /* CurveBalanced */: {
7555
+ case 4 /* CurveBalanced */: {
7404
7556
  let weights = toWeightCurve(minBinId, maxBinId, activeId);
7405
7557
  return autoFillYByWeight(
7406
7558
  activeId,
@@ -7411,7 +7563,7 @@ function autoFillYByStrategy(activeId, binStep, amountX, amountXInActiveBin, amo
7411
7563
  weights
7412
7564
  );
7413
7565
  }
7414
- case 8 /* BidAskBalanced */: {
7566
+ case 5 /* BidAskBalanced */: {
7415
7567
  let weights = toWeightBidAsk(minBinId, maxBinId, activeId);
7416
7568
  return autoFillYByWeight(
7417
7569
  activeId,
@@ -7426,15 +7578,12 @@ function autoFillYByStrategy(activeId, binStep, amountX, amountXInActiveBin, amo
7426
7578
  }
7427
7579
  function autoFillXByStrategy(activeId, binStep, amountY, amountXInActiveBin, amountYInActiveBin, minBinId, maxBinId, strategyType) {
7428
7580
  switch (strategyType) {
7429
- case 0 /* SpotOneSide */:
7430
- case 1 /* CurveOneSide */:
7431
- case 2 /* BidAskOneSide */:
7432
- case 3 /* SpotImBalanced */:
7433
- case 4 /* CurveImBalanced */:
7434
- case 5 /* BidAskImBalanced */: {
7581
+ case 0 /* SpotImBalanced */:
7582
+ case 1 /* CurveImBalanced */:
7583
+ case 2 /* BidAskImBalanced */: {
7435
7584
  throw "Invalid Strategy Parameters";
7436
7585
  }
7437
- case 6 /* SpotBalanced */: {
7586
+ case 3 /* SpotBalanced */: {
7438
7587
  let weights = toWeightSpotBalanced(minBinId, maxBinId);
7439
7588
  return autoFillXByWeight(
7440
7589
  activeId,
@@ -7445,7 +7594,7 @@ function autoFillXByStrategy(activeId, binStep, amountY, amountXInActiveBin, amo
7445
7594
  weights
7446
7595
  );
7447
7596
  }
7448
- case 7 /* CurveBalanced */: {
7597
+ case 4 /* CurveBalanced */: {
7449
7598
  let weights = toWeightCurve(minBinId, maxBinId, activeId);
7450
7599
  return autoFillXByWeight(
7451
7600
  activeId,
@@ -7456,7 +7605,7 @@ function autoFillXByStrategy(activeId, binStep, amountY, amountXInActiveBin, amo
7456
7605
  weights
7457
7606
  );
7458
7607
  }
7459
- case 8 /* BidAskBalanced */: {
7608
+ case 5 /* BidAskBalanced */: {
7460
7609
  let weights = toWeightBidAsk(minBinId, maxBinId, activeId);
7461
7610
  return autoFillXByWeight(
7462
7611
  activeId,
@@ -7477,31 +7626,7 @@ function toStrategyParameters({
7477
7626
  }) {
7478
7627
  const parameters = [singleSidedX ? 1 : 0, ...new Array(63).fill(0)];
7479
7628
  switch (strategyType) {
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 */: {
7629
+ case 3 /* SpotBalanced */: {
7505
7630
  return {
7506
7631
  minBinId,
7507
7632
  maxBinId,
@@ -7509,7 +7634,7 @@ function toStrategyParameters({
7509
7634
  parameteres: Buffer.from(parameters).toJSON().data
7510
7635
  };
7511
7636
  }
7512
- case 7 /* CurveBalanced */: {
7637
+ case 4 /* CurveBalanced */: {
7513
7638
  return {
7514
7639
  minBinId,
7515
7640
  maxBinId,
@@ -7517,7 +7642,7 @@ function toStrategyParameters({
7517
7642
  parameteres: Buffer.from(parameters).toJSON().data
7518
7643
  };
7519
7644
  }
7520
- case 8 /* BidAskBalanced */: {
7645
+ case 5 /* BidAskBalanced */: {
7521
7646
  return {
7522
7647
  minBinId,
7523
7648
  maxBinId,
@@ -7525,7 +7650,7 @@ function toStrategyParameters({
7525
7650
  parameteres: Buffer.from(parameters).toJSON().data
7526
7651
  };
7527
7652
  }
7528
- case 3 /* SpotImBalanced */: {
7653
+ case 0 /* SpotImBalanced */: {
7529
7654
  return {
7530
7655
  minBinId,
7531
7656
  maxBinId,
@@ -7533,7 +7658,7 @@ function toStrategyParameters({
7533
7658
  parameteres: Buffer.from(parameters).toJSON().data
7534
7659
  };
7535
7660
  }
7536
- case 4 /* CurveImBalanced */: {
7661
+ case 1 /* CurveImBalanced */: {
7537
7662
  return {
7538
7663
  minBinId,
7539
7664
  maxBinId,
@@ -7541,7 +7666,7 @@ function toStrategyParameters({
7541
7666
  parameteres: Buffer.from(parameters).toJSON().data
7542
7667
  };
7543
7668
  }
7544
- case 5 /* BidAskImBalanced */: {
7669
+ case 2 /* BidAskImBalanced */: {
7545
7670
  return {
7546
7671
  minBinId,
7547
7672
  maxBinId,
@@ -7554,7 +7679,7 @@ function toStrategyParameters({
7554
7679
 
7555
7680
  // src/dlmm/helpers/lbPair.ts
7556
7681
  import { AnchorProvider, Program as Program2 } from "@coral-xyz/anchor";
7557
- import { PublicKey as PublicKey4 } from "@solana/web3.js";
7682
+ import { PublicKey as PublicKey5 } from "@solana/web3.js";
7558
7683
  async function getTokensMintFromPoolAddress(connection, poolAddress, opt) {
7559
7684
  const provider = new AnchorProvider(
7560
7685
  connection,
@@ -7567,7 +7692,7 @@ async function getTokensMintFromPoolAddress(connection, poolAddress, opt) {
7567
7692
  provider
7568
7693
  );
7569
7694
  const poolAccount = await program.account.lbPair.fetchNullable(
7570
- new PublicKey4(poolAddress)
7695
+ new PublicKey5(poolAddress)
7571
7696
  );
7572
7697
  if (!poolAccount)
7573
7698
  throw new Error("Pool account not found");
@@ -7621,7 +7746,7 @@ var getOrCreateATAInstruction = async (connection, tokenMint, owner, payer = own
7621
7746
  return { ataPubKey: toAccount, ix: void 0 };
7622
7747
  } catch (e) {
7623
7748
  if (e instanceof TokenAccountNotFoundError || e instanceof TokenInvalidAccountOwnerError) {
7624
- const ix = createAssociatedTokenAccountInstruction(
7749
+ const ix = createAssociatedTokenAccountIdempotentInstruction(
7625
7750
  payer,
7626
7751
  toAccount,
7627
7752
  owner,
@@ -7653,7 +7778,7 @@ var wrapSOLInstruction = (from, to, amount) => {
7653
7778
  toPubkey: to,
7654
7779
  lamports: amount
7655
7780
  }),
7656
- new TransactionInstruction({
7781
+ new TransactionInstruction2({
7657
7782
  keys: [
7658
7783
  {
7659
7784
  pubkey: to,
@@ -7722,7 +7847,7 @@ var getEstimatedComputeUnitIxWithBuffer = async (connection, instructions, feePa
7722
7847
  console.error("Error::getEstimatedComputeUnitUsageWithBuffer", error);
7723
7848
  return 14e5;
7724
7849
  });
7725
- return ComputeBudgetProgram.setComputeUnitLimit({ units });
7850
+ return ComputeBudgetProgram2.setComputeUnitLimit({ units });
7726
7851
  };
7727
7852
 
7728
7853
  // src/dlmm/index.ts
@@ -8066,49 +8191,14 @@ var DLMM = class {
8066
8191
  opt?.programId ?? LBCLMM_PROGRAM_IDS[cluster],
8067
8192
  provider
8068
8193
  );
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
- }
8076
- }
8077
- ]),
8078
- program.account.positionV2.all([
8079
- {
8080
- memcmp: {
8081
- bytes: bs58.encode(userPubKey.toBuffer()),
8082
- offset: 8 + 32
8083
- }
8194
+ const positionsV2 = await program.account.positionV2.all([
8195
+ {
8196
+ memcmp: {
8197
+ bytes: bs58.encode(userPubKey.toBuffer()),
8198
+ offset: 8 + 32
8084
8199
  }
8085
- ])
8200
+ }
8086
8201
  ]);
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
- );
8112
8202
  const binArrayPubkeySetV2 = /* @__PURE__ */ new Set();
8113
8203
  const lbPairSetV2 = /* @__PURE__ */ new Set();
8114
8204
  positionsV2.forEach(({ account: { upperBinId, lowerBinId, lbPair } }) => {
@@ -8129,77 +8219,41 @@ var DLMM = class {
8129
8219
  lbPairSetV2.add(lbPair.toBase58());
8130
8220
  });
8131
8221
  const binArrayPubkeyArrayV2 = Array.from(binArrayPubkeySetV2).map(
8132
- (pubkey) => new PublicKey6(pubkey)
8222
+ (pubkey) => new PublicKey7(pubkey)
8133
8223
  );
8134
8224
  const lbPairArrayV2 = Array.from(lbPairSetV2).map(
8135
- (pubkey) => new PublicKey6(pubkey)
8225
+ (pubkey) => new PublicKey7(pubkey)
8136
8226
  );
8137
8227
  const [clockAccInfo, ...binArraysAccInfo] = await chunkedGetMultipleAccountInfos(connection, [
8138
8228
  SYSVAR_CLOCK_PUBKEY,
8139
- ...binArrayPubkeyArray,
8140
- ...lbPairArray,
8141
8229
  ...binArrayPubkeyArrayV2,
8142
8230
  ...lbPairArrayV2
8143
8231
  ]);
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`
8232
+ const positionBinArraysMapV2 = /* @__PURE__ */ new Map();
8233
+ for (let i = 0; i < binArrayPubkeyArrayV2.length; i++) {
8234
+ const binArrayPubkey = binArrayPubkeyArrayV2[i];
8235
+ const binArrayAccInfoBufferV2 = binArraysAccInfo[i];
8236
+ if (binArrayAccInfoBufferV2) {
8237
+ const binArrayAccInfo = program.coder.accounts.decode(
8238
+ "binArray",
8239
+ binArrayAccInfoBufferV2.data
8151
8240
  );
8152
- const binArrayAccInfo = program.coder.accounts.decode(
8153
- "binArray",
8154
- binArrayAccInfoBuffer.data
8155
- );
8156
- positionBinArraysMap.set(binArrayPubkey.toBase58(), binArrayAccInfo);
8241
+ positionBinArraysMapV2.set(binArrayPubkey.toBase58(), binArrayAccInfo);
8242
+ }
8157
8243
  }
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)
8244
+ const lbPairArraysMapV2 = /* @__PURE__ */ new Map();
8245
+ for (let i = binArrayPubkeyArrayV2.length; i < binArraysAccInfo.length; i++) {
8246
+ const lbPairPubkey = lbPairArrayV2[i - binArrayPubkeyArrayV2.length];
8247
+ const lbPairAccInfoBufferV2 = binArraysAccInfo[i];
8248
+ if (!lbPairAccInfoBufferV2)
8163
8249
  throw new Error(`LB Pair account ${lbPairPubkey.toBase58()} not found`);
8164
8250
  const lbPairAccInfo = program.coder.accounts.decode(
8165
8251
  "lbPair",
8166
- lbPairAccInfoBuffer.data
8252
+ lbPairAccInfoBufferV2.data
8167
8253
  );
8168
- lbPairArraysMap.set(lbPairPubkey.toBase58(), lbPairAccInfo);
8254
+ lbPairArraysMapV2.set(lbPairPubkey.toBase58(), lbPairAccInfo);
8169
8255
  }
8170
- const reservePublicKeys = Array.from(lbPairArraysMap.values()).map(({ reserveX, reserveY, tokenXMint, tokenYMint }) => [
8171
- reserveX,
8172
- reserveY,
8173
- tokenXMint,
8174
- tokenYMint
8175
- ]).flat();
8176
- const positionBinArraysMapV2 = /* @__PURE__ */ new Map();
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)];
8179
- const binArrayAccInfoBufferV2 = binArraysAccInfo[i];
8180
- if (!binArrayAccInfoBufferV2)
8181
- throw new Error(
8182
- `Bin Array account ${binArrayPubkey.toBase58()} not found`
8183
- );
8184
- const binArrayAccInfo = program.coder.accounts.decode(
8185
- "binArray",
8186
- binArrayAccInfoBufferV2.data
8187
- );
8188
- positionBinArraysMapV2.set(binArrayPubkey.toBase58(), binArrayAccInfo);
8189
- }
8190
- const lbPairArraysMapV2 = /* @__PURE__ */ new Map();
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)];
8193
- const lbPairAccInfoBufferV2 = binArraysAccInfo[i];
8194
- if (!lbPairAccInfoBufferV2)
8195
- throw new Error(`LB Pair account ${lbPairPubkey.toBase58()} not found`);
8196
- const lbPairAccInfo = program.coder.accounts.decode(
8197
- "lbPair",
8198
- lbPairAccInfoBufferV2.data
8199
- );
8200
- lbPairArraysMapV2.set(lbPairPubkey.toBase58(), lbPairAccInfo);
8201
- }
8202
- const reservePublicKeysV2 = Array.from(lbPairArraysMapV2.values()).map(({ reserveX, reserveY, tokenXMint, tokenYMint }) => [
8256
+ const reservePublicKeysV2 = Array.from(lbPairArraysMapV2.values()).map(({ reserveX, reserveY, tokenXMint, tokenYMint }) => [
8203
8257
  reserveX,
8204
8258
  reserveY,
8205
8259
  tokenXMint,
@@ -8207,43 +8261,14 @@ var DLMM = class {
8207
8261
  ]).flat();
8208
8262
  const reserveAccountsInfo = await chunkedGetMultipleAccountInfos(
8209
8263
  program.provider.connection,
8210
- [...reservePublicKeys, ...reservePublicKeysV2]
8264
+ reservePublicKeysV2
8211
8265
  );
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
- });
8241
8266
  const lbPairReserveMapV2 = /* @__PURE__ */ new Map();
8242
8267
  const lbPairMintMapV2 = /* @__PURE__ */ new Map();
8243
8268
  lbPairArrayV2.forEach((lbPair, idx) => {
8244
8269
  const index = idx * 4;
8245
- const reserveAccBufferXV2 = reserveAccountsInfo[reservePublicKeys.length + index];
8246
- const reserveAccBufferYV2 = reserveAccountsInfo[reservePublicKeys.length + index + 1];
8270
+ const reserveAccBufferXV2 = reserveAccountsInfo[index];
8271
+ const reserveAccBufferYV2 = reserveAccountsInfo[index + 1];
8247
8272
  if (!reserveAccBufferXV2 || !reserveAccBufferYV2)
8248
8273
  throw new Error(
8249
8274
  `Reserve account for LB Pair ${lbPair.toBase58()} not found`
@@ -8254,8 +8279,8 @@ var DLMM = class {
8254
8279
  reserveX: reserveAccX.amount,
8255
8280
  reserveY: reserveAccY.amount
8256
8281
  });
8257
- const mintXBufferV2 = reserveAccountsInfo[reservePublicKeys.length + index + 2];
8258
- const mintYBufferV2 = reserveAccountsInfo[reservePublicKeys.length + index + 3];
8282
+ const mintXBufferV2 = reserveAccountsInfo[index + 2];
8283
+ const mintYBufferV2 = reserveAccountsInfo[index + 3];
8259
8284
  if (!mintXBufferV2 || !mintYBufferV2)
8260
8285
  throw new Error(
8261
8286
  `Mint account for LB Pair ${lbPair.toBase58()} not found`
@@ -8271,74 +8296,6 @@ var DLMM = class {
8271
8296
  clockAccInfo.data.readBigInt64LE(32).toString()
8272
8297
  ).toNumber();
8273
8298
  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
- }
8342
8299
  for (let position of positionsV2) {
8343
8300
  const { account, publicKey: positionPubKey } = position;
8344
8301
  const { upperBinId, lowerBinId, lbPair, feeOwner } = account;
@@ -8379,7 +8336,7 @@ var DLMM = class {
8379
8336
  amount: reserveYBalance,
8380
8337
  decimal: quoteTokenDecimal
8381
8338
  };
8382
- const positionData = await DLMM.processPosition(
8339
+ const positionData = !!lowerBinArray && !!upperBinArray ? await DLMM.processPosition(
8383
8340
  program,
8384
8341
  1 /* V2 */,
8385
8342
  lbPairAcc,
@@ -8390,7 +8347,21 @@ var DLMM = class {
8390
8347
  lowerBinArray,
8391
8348
  upperBinArray,
8392
8349
  feeOwner
8393
- );
8350
+ ) : {
8351
+ totalXAmount: "0",
8352
+ totalYAmount: "0",
8353
+ positionBinData: [],
8354
+ lastUpdatedAt: new BN10(0),
8355
+ upperBinId,
8356
+ lowerBinId,
8357
+ feeX: new BN10(0),
8358
+ feeY: new BN10(0),
8359
+ rewardOne: new BN10(0),
8360
+ rewardTwo: new BN10(0),
8361
+ feeOwner,
8362
+ totalClaimedFeeXAmount: new BN10(0),
8363
+ totalClaimedFeeYAmount: new BN10(0)
8364
+ };
8394
8365
  if (positionData) {
8395
8366
  positionsMap.set(lbPair.toBase58(), {
8396
8367
  publicKey: lbPair,
@@ -8410,63 +8381,124 @@ var DLMM = class {
8410
8381
  }
8411
8382
  return positionsMap;
8412
8383
  }
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
8384
+ static getPricePerLamport(tokenXDecimal, tokenYDecimal, price) {
8385
+ return new Decimal5(price).mul(new Decimal5(10 ** (tokenYDecimal - tokenXDecimal))).toString();
8386
+ }
8387
+ static getBinIdFromPrice(price, binStep, min) {
8388
+ const binStepNum = new Decimal5(binStep).div(new Decimal5(BASIS_POINT_MAX));
8389
+ const binId = new Decimal5(price).log().dividedBy(new Decimal5(1).add(binStepNum).log());
8390
+ return (min ? binId.floor() : binId.ceil()).toNumber();
8391
+ }
8392
+ /**
8393
+ * The function `getLbPairLockInfo` retrieves all pair positions that has locked liquidity.
8394
+ * @param {number} [lockDurationOpt] - An optional value indicating the minimum position lock duration that the function should return.
8395
+ * Depending on the lbPair activationType, the param should be a number of seconds or a number of slots.
8396
+ * @returns The function `getLbPairLockInfo` returns a `Promise` that resolves to a `PairLockInfo`
8397
+ * object. The `PairLockInfo` object contains an array of `PositionLockInfo` objects.
8398
+ */
8399
+ async getLbPairLockInfo(lockDurationOpt) {
8400
+ const lockDuration = lockDurationOpt | 0;
8401
+ const lbPairPositions = await this.program.account.positionV2.all([
8402
+ {
8403
+ memcmp: {
8404
+ bytes: bs58.encode(this.pubkey.toBuffer()),
8405
+ offset: 8
8406
+ }
8407
+ }
8408
+ ]);
8409
+ const clockAccInfo = await this.program.provider.connection.getAccountInfo(SYSVAR_CLOCK_PUBKEY);
8410
+ const clock = ClockLayout.decode(clockAccInfo.data);
8411
+ const currentPoint = this.lbPair.activationType == 0 /* Slot */ ? clock.slot : clock.unixTimestamp;
8412
+ const minLockReleasePoint = currentPoint.add(new BN10(lockDuration));
8413
+ const positionsWithLock = lbPairPositions.filter((p) => p.account.lockReleasePoint.gt(minLockReleasePoint));
8414
+ if (positionsWithLock.length == 0) {
8415
+ return {
8416
+ positions: []
8417
+ };
8418
+ }
8419
+ const binArrayPubkeySetV2 = /* @__PURE__ */ new Set();
8420
+ positionsWithLock.forEach(({ account: { upperBinId, lowerBinId, lbPair } }) => {
8421
+ const lowerBinArrayIndex = binIdToBinArrayIndex(new BN10(lowerBinId));
8422
+ const upperBinArrayIndex = binIdToBinArrayIndex(new BN10(upperBinId));
8423
+ const [lowerBinArrayPubKey] = deriveBinArray(
8424
+ this.pubkey,
8425
+ lowerBinArrayIndex,
8426
+ this.program.programId
8427
+ );
8428
+ const [upperBinArrayPubKey] = deriveBinArray(
8429
+ this.pubkey,
8430
+ upperBinArrayIndex,
8431
+ this.program.programId
8432
+ );
8433
+ binArrayPubkeySetV2.add(lowerBinArrayPubKey.toBase58());
8434
+ binArrayPubkeySetV2.add(upperBinArrayPubKey.toBase58());
8435
+ });
8436
+ const binArrayPubkeyArrayV2 = Array.from(binArrayPubkeySetV2).map(
8437
+ (pubkey) => new PublicKey7(pubkey)
8424
8438
  );
8425
- const positionsState = await program.account.position.fetchMultiple(
8426
- positions
8439
+ const binArraysAccInfo = await chunkedGetMultipleAccountInfos(
8440
+ this.program.provider.connection,
8441
+ binArrayPubkeyArrayV2
8427
8442
  );
8428
- const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash("confirmed");
8429
- return Promise.all(
8430
- positionsState.map(async ({ lbPair, lowerBinId }, idx) => {
8431
- const position = positions[idx];
8443
+ const positionBinArraysMapV2 = /* @__PURE__ */ new Map();
8444
+ for (let i = 0; i < binArraysAccInfo.length; i++) {
8445
+ const binArrayPubkey = binArrayPubkeyArrayV2[i];
8446
+ const binArrayAccBufferV2 = binArraysAccInfo[i];
8447
+ if (!binArrayAccBufferV2)
8448
+ throw new Error(
8449
+ `Bin Array account ${binArrayPubkey.toBase58()} not found`
8450
+ );
8451
+ const binArrayAccInfo = this.program.coder.accounts.decode(
8452
+ "binArray",
8453
+ binArrayAccBufferV2.data
8454
+ );
8455
+ positionBinArraysMapV2.set(binArrayPubkey.toBase58(), binArrayAccInfo);
8456
+ }
8457
+ const positionsLockInfo = await Promise.all(
8458
+ positionsWithLock.map(async ({ publicKey, account }) => {
8459
+ const { lowerBinId, upperBinId, feeOwner } = account;
8432
8460
  const lowerBinArrayIndex = binIdToBinArrayIndex(new BN10(lowerBinId));
8433
- const upperBinArrayIndex = lowerBinArrayIndex.add(new BN10(1));
8461
+ const upperBinArrayIndex = binIdToBinArrayIndex(new BN10(upperBinId));
8434
8462
  const [lowerBinArrayPubKey] = deriveBinArray(
8435
- lbPair,
8463
+ this.pubkey,
8436
8464
  lowerBinArrayIndex,
8437
- program.programId
8465
+ this.program.programId
8438
8466
  );
8439
8467
  const [upperBinArrayPubKey] = deriveBinArray(
8440
- lbPair,
8468
+ this.pubkey,
8441
8469
  upperBinArrayIndex,
8442
- program.programId
8470
+ this.program.programId
8443
8471
  );
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);
8472
+ const lowerBinArray = positionBinArraysMapV2.get(
8473
+ lowerBinArrayPubKey.toBase58()
8474
+ );
8475
+ const upperBinArray = positionBinArraysMapV2.get(
8476
+ upperBinArrayPubKey.toBase58()
8477
+ );
8478
+ const positionData = await DLMM.processPosition(
8479
+ this.program,
8480
+ 1 /* V2 */,
8481
+ this.lbPair,
8482
+ clock.unixTimestamp.toNumber(),
8483
+ account,
8484
+ this.tokenX.decimal,
8485
+ this.tokenY.decimal,
8486
+ lowerBinArray,
8487
+ upperBinArray,
8488
+ feeOwner
8489
+ );
8490
+ return {
8491
+ positionAddress: publicKey,
8492
+ owner: account.owner,
8493
+ lockReleasePoint: account.lockReleasePoint.toNumber(),
8494
+ tokenXAmount: positionData.totalXAmount,
8495
+ tokenYAmount: positionData.totalYAmount
8496
+ };
8460
8497
  })
8461
8498
  );
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();
8499
+ return {
8500
+ positions: positionsLockInfo
8501
+ };
8470
8502
  }
8471
8503
  /** Public methods */
8472
8504
  static async createPermissionLbPair(connection, binStep, tokenX, tokenY, activeId, baseKey, creatorKey, feeBps, activationType, opt) {
@@ -8518,7 +8550,7 @@ var DLMM = class {
8518
8550
  base: baseKey
8519
8551
  }).transaction();
8520
8552
  }
8521
- static async createCustomizablePermissionlessLbPair(connection, binStep, tokenX, tokenY, activeId, feeBps, activationType, hasAlphaVault, creatorKey, activationPoint, opt) {
8553
+ static async createCustomizablePermissionlessLbPair(connection, binStep, tokenX, tokenY, activeId, feeBps, activationType, hasAlphaVault, creatorKey, activationPoint, creatorPoolOnOffControl, opt) {
8522
8554
  const provider = new AnchorProvider2(
8523
8555
  connection,
8524
8556
  {},
@@ -8548,12 +8580,13 @@ var DLMM = class {
8548
8580
  activationType,
8549
8581
  activationPoint: activationPoint ? activationPoint : null,
8550
8582
  hasAlphaVault,
8551
- padding: Array(64).fill(0)
8583
+ creatorPoolOnOffControl: creatorPoolOnOffControl ? creatorPoolOnOffControl : false,
8584
+ padding: Array(63).fill(0)
8552
8585
  };
8553
8586
  const userTokenX = getAssociatedTokenAddressSync2(tokenX, creatorKey);
8587
+ const userTokenY = getAssociatedTokenAddressSync2(tokenY, creatorKey);
8554
8588
  return program.methods.initializeCustomizablePermissionlessLbPair(ixData).accounts({
8555
8589
  lbPair,
8556
- rent: SYSVAR_RENT_PUBKEY,
8557
8590
  reserveX,
8558
8591
  reserveY,
8559
8592
  binArrayBitmapExtension,
@@ -8563,6 +8596,7 @@ var DLMM = class {
8563
8596
  oracle,
8564
8597
  systemProgram: SystemProgram2.programId,
8565
8598
  userTokenX,
8599
+ userTokenY,
8566
8600
  funder: creatorKey
8567
8601
  }).transaction();
8568
8602
  }
@@ -8678,6 +8712,26 @@ var DLMM = class {
8678
8712
  };
8679
8713
  this.lbPair = lbPairState;
8680
8714
  }
8715
+ /**
8716
+ * Set the status of a permissionless LB pair to either enabled or disabled. This require pool field `creator_pool_on_off_control` to be true and type `CustomizablePermissionless`.
8717
+ * Pool creator can enable/disable the pair anytime before the pool is opened / activated. Once the pool activation time is passed, the pool creator can only enable the pair.
8718
+ * Useful for token launches which do not have fixed activation time.
8719
+ * @param enable If true, the pair will be enabled. If false, the pair will be disabled.
8720
+ * @param creator The public key of the pool creator.
8721
+ * @returns a Promise that resolves to the transaction.
8722
+ */
8723
+ async setPairStatusPermissionless(enable, creator) {
8724
+ const tx = await this.program.methods.setPairStatusPermissionless(Number(enable)).accounts({
8725
+ lbPair: this.pubkey,
8726
+ creator
8727
+ }).transaction();
8728
+ const { blockhash, lastValidBlockHeight } = await this.program.provider.connection.getLatestBlockhash("confirmed");
8729
+ return new Transaction({
8730
+ feePayer: this.lbPair.creator,
8731
+ blockhash,
8732
+ lastValidBlockHeight
8733
+ }).add(tx);
8734
+ }
8681
8735
  /**
8682
8736
  * The function `getBinArrays` returns an array of `BinArrayAccount` objects
8683
8737
  * @returns a Promise that resolves to an array of BinArrayAccount objects.
@@ -8728,7 +8782,7 @@ var DLMM = class {
8728
8782
  shouldStop = true;
8729
8783
  }
8730
8784
  const accountsToFetch = Array.from(binArraysPubkey).map(
8731
- (pubkey) => new PublicKey6(pubkey)
8785
+ (pubkey) => new PublicKey7(pubkey)
8732
8786
  );
8733
8787
  const binArraysAccInfoBuffer = await chunkedGetMultipleAccountInfos(
8734
8788
  this.program.provider.connection,
@@ -8951,20 +9005,6 @@ var DLMM = class {
8951
9005
  async getPositionsByUserAndLbPair(userPubKey) {
8952
9006
  const promiseResults = await Promise.all([
8953
9007
  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
- ]),
8968
9008
  userPubKey && this.program.account.positionV2.all([
8969
9009
  {
8970
9010
  memcmp: {
@@ -8980,7 +9020,7 @@ var DLMM = class {
8980
9020
  }
8981
9021
  ])
8982
9022
  ]);
8983
- const [activeBin, positions, positionsV2] = promiseResults;
9023
+ const [activeBin, positionsV2] = promiseResults;
8984
9024
  if (!activeBin) {
8985
9025
  throw new Error("Error fetching active bin");
8986
9026
  }
@@ -8990,29 +9030,9 @@ var DLMM = class {
8990
9030
  userPositions: []
8991
9031
  };
8992
9032
  }
8993
- if (!positions || !positionsV2) {
9033
+ if (!positionsV2) {
8994
9034
  throw new Error("Error fetching positions");
8995
9035
  }
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
- );
9016
9036
  const binArrayPubkeySetV2 = /* @__PURE__ */ new Set();
9017
9037
  positionsV2.forEach(({ account: { upperBinId, lowerBinId, lbPair } }) => {
9018
9038
  const lowerBinArrayIndex = binIdToBinArrayIndex(new BN10(lowerBinId));
@@ -9031,35 +9051,20 @@ var DLMM = class {
9031
9051
  binArrayPubkeySetV2.add(upperBinArrayPubKey.toBase58());
9032
9052
  });
9033
9053
  const binArrayPubkeyArrayV2 = Array.from(binArrayPubkeySetV2).map(
9034
- (pubkey) => new PublicKey6(pubkey)
9054
+ (pubkey) => new PublicKey7(pubkey)
9035
9055
  );
9036
9056
  const lbPairAndBinArrays = await chunkedGetMultipleAccountInfos(
9037
9057
  this.program.provider.connection,
9038
9058
  [
9039
9059
  this.pubkey,
9040
9060
  SYSVAR_CLOCK_PUBKEY,
9041
- ...binArrayPubkeyArray,
9042
9061
  ...binArrayPubkeyArrayV2
9043
9062
  ]
9044
9063
  );
9045
9064
  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
- }
9060
9065
  const positionBinArraysMapV2 = /* @__PURE__ */ new Map();
9061
- for (let i = binArrayPubkeyArray.length; i < binArraysAccInfo.length; i++) {
9062
- const binArrayPubkey = binArrayPubkeyArrayV2[i - binArrayPubkeyArray.length];
9066
+ for (let i = 0; i < binArraysAccInfo.length; i++) {
9067
+ const binArrayPubkey = binArrayPubkeyArrayV2[i];
9063
9068
  const binArrayAccBufferV2 = binArraysAccInfo[i];
9064
9069
  if (!binArrayAccBufferV2)
9065
9070
  throw new Error(
@@ -9076,45 +9081,6 @@ var DLMM = class {
9076
9081
  const onChainTimestamp = new BN10(
9077
9082
  clockAccInfo.data.readBigInt64LE(32).toString()
9078
9083
  ).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
- );
9118
9084
  const userPositionsV2 = await Promise.all(
9119
9085
  positionsV2.map(async ({ publicKey, account }) => {
9120
9086
  const { lowerBinId, upperBinId, feeOwner } = account;
@@ -9156,7 +9122,7 @@ var DLMM = class {
9156
9122
  );
9157
9123
  return {
9158
9124
  activeBin,
9159
- userPositions: [...userPositions, ...userPositionsV2]
9125
+ userPositions: userPositionsV2
9160
9126
  };
9161
9127
  }
9162
9128
  async quoteCreatePosition({ strategy }) {
@@ -9217,6 +9183,93 @@ var DLMM = class {
9217
9183
  feePayer: user
9218
9184
  }).add(setCUIx, ...instructions);
9219
9185
  }
9186
+ /**
9187
+ * The function `getPosition` retrieves position information for a given public key and processes it
9188
+ * using various data to return a `LbPosition` object.
9189
+ * @param {PublicKey} positionPubKey - The `getPosition` function you provided is an asynchronous
9190
+ * function that fetches position information based on a given public key. Here's a breakdown of the
9191
+ * parameters used in the function:
9192
+ * @returns The `getPosition` function returns a Promise that resolves to an object of type
9193
+ * `LbPosition`. The object contains the following properties:
9194
+ * - `publicKey`: The public key of the position account
9195
+ * - `positionData`: Position Object
9196
+ * - `version`: The version of the position (in this case, `Position.V2`)
9197
+ */
9198
+ async getPosition(positionPubKey) {
9199
+ const positionAccountInfo = await this.program.account.positionV2.fetch(positionPubKey);
9200
+ if (!positionAccountInfo) {
9201
+ throw new Error(`Position account ${positionPubKey.toBase58()} not found`);
9202
+ }
9203
+ const { lowerBinId, upperBinId, feeOwner } = positionAccountInfo;
9204
+ const lowerBinArrayIndex = binIdToBinArrayIndex(new BN10(lowerBinId));
9205
+ const upperBinArrayIndex = binIdToBinArrayIndex(new BN10(upperBinId));
9206
+ const [lowerBinArrayPubKey] = deriveBinArray(
9207
+ this.pubkey,
9208
+ lowerBinArrayIndex,
9209
+ this.program.programId
9210
+ );
9211
+ const [upperBinArrayPubKey] = deriveBinArray(
9212
+ this.pubkey,
9213
+ upperBinArrayIndex,
9214
+ this.program.programId
9215
+ );
9216
+ const [clockAccInfo, lowerBinArrayAccInfo, upperBinArrayAccInfo] = await chunkedGetMultipleAccountInfos(
9217
+ this.program.provider.connection,
9218
+ [
9219
+ SYSVAR_CLOCK_PUBKEY,
9220
+ lowerBinArrayPubKey,
9221
+ upperBinArrayPubKey
9222
+ ]
9223
+ );
9224
+ if (!lowerBinArrayAccInfo || !upperBinArrayAccInfo) {
9225
+ return {
9226
+ publicKey: positionPubKey,
9227
+ positionData: {
9228
+ totalXAmount: "0",
9229
+ totalYAmount: "0",
9230
+ positionBinData: [],
9231
+ lastUpdatedAt: new BN10(0),
9232
+ upperBinId,
9233
+ lowerBinId,
9234
+ feeX: new BN10(0),
9235
+ feeY: new BN10(0),
9236
+ rewardOne: new BN10(0),
9237
+ rewardTwo: new BN10(0),
9238
+ feeOwner,
9239
+ totalClaimedFeeXAmount: new BN10(0),
9240
+ totalClaimedFeeYAmount: new BN10(0)
9241
+ },
9242
+ version: 1 /* V2 */
9243
+ };
9244
+ }
9245
+ const onChainTimestamp = new BN10(
9246
+ clockAccInfo.data.readBigInt64LE(32).toString()
9247
+ ).toNumber();
9248
+ const lowerBinArray = this.program.coder.accounts.decode(
9249
+ "binArray",
9250
+ lowerBinArrayAccInfo.data
9251
+ );
9252
+ const upperBinArray = this.program.coder.accounts.decode(
9253
+ "binArray",
9254
+ upperBinArrayAccInfo.data
9255
+ );
9256
+ return {
9257
+ publicKey: positionPubKey,
9258
+ positionData: await DLMM.processPosition(
9259
+ this.program,
9260
+ 1 /* V2 */,
9261
+ this.lbPair,
9262
+ onChainTimestamp,
9263
+ positionAccountInfo,
9264
+ this.tokenX.decimal,
9265
+ this.tokenY.decimal,
9266
+ lowerBinArray,
9267
+ upperBinArray,
9268
+ feeOwner
9269
+ ),
9270
+ version: 1 /* V2 */
9271
+ };
9272
+ }
9220
9273
  /**
9221
9274
  * The function `initializePositionAndAddLiquidityByStrategy` function is used to initializes a position and adds liquidity
9222
9275
  * @param {TInitializePositionAndAddLiquidityParamsByStrategy}
@@ -9940,9 +9993,13 @@ var DLMM = class {
9940
9993
  bps,
9941
9994
  shouldClaimAndClose = false
9942
9995
  }) {
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));
9996
+ const lowerBinIdToRemove = Math.min(...binIds);
9997
+ const upperBinIdToRemove = Math.max(...binIds);
9998
+ const { lbPair, owner, feeOwner, lowerBinId: positionLowerBinId, liquidityShares } = await this.program.account.positionV2.fetch(position);
9999
+ if (liquidityShares.every((share) => share.isZero())) {
10000
+ throw new Error("No liquidity to remove");
10001
+ }
10002
+ const lowerBinArrayIndex = binIdToBinArrayIndex(new BN10(positionLowerBinId));
9946
10003
  const upperBinArrayIndex = lowerBinArrayIndex.add(new BN10(1));
9947
10004
  const [binArrayLower] = deriveBinArray(
9948
10005
  lbPair,
@@ -9955,7 +10012,7 @@ var DLMM = class {
9955
10012
  this.program.programId
9956
10013
  );
9957
10014
  const preInstructions = [];
9958
- const walletToReceiveFee = feeOwner.equals(PublicKey6.default) ? user : feeOwner;
10015
+ const walletToReceiveFee = feeOwner.equals(PublicKey7.default) ? user : feeOwner;
9959
10016
  const [
9960
10017
  { ataPubKey: userTokenX, ix: createPayerTokenXIx },
9961
10018
  { ataPubKey: userTokenY, ix: createPayerTokenYIx },
@@ -10002,8 +10059,8 @@ var DLMM = class {
10002
10059
  lbPair: this.pubkey,
10003
10060
  sender: user,
10004
10061
  position,
10005
- reserveX,
10006
- reserveY,
10062
+ reserveX: this.lbPair.reserveX,
10063
+ reserveY: this.lbPair.reserveY,
10007
10064
  tokenProgram: TOKEN_PROGRAM_ID2,
10008
10065
  tokenXMint: this.tokenX.publicKey,
10009
10066
  tokenYMint: this.tokenY.publicKey,
@@ -10013,7 +10070,7 @@ var DLMM = class {
10013
10070
  postInstructions.push(claimSwapFeeIx);
10014
10071
  for (let i = 0; i < 2; i++) {
10015
10072
  const rewardInfo = this.lbPair.rewardInfos[i];
10016
- if (!rewardInfo || rewardInfo.mint.equals(PublicKey6.default))
10073
+ if (!rewardInfo || rewardInfo.mint.equals(PublicKey7.default))
10017
10074
  continue;
10018
10075
  const { ataPubKey, ix: rewardAtaIx } = await getOrCreateATAInstruction(
10019
10076
  this.program.provider.connection,
@@ -10056,21 +10113,19 @@ var DLMM = class {
10056
10113
  const closeWrappedSOLIx = await unwrapSOLInstruction(user);
10057
10114
  closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
10058
10115
  }
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));
10116
+ const minBinArrayIndex = binIdToBinArrayIndex(new BN10(lowerBinIdToRemove));
10117
+ const maxBinArrayIndex = binIdToBinArrayIndex(new BN10(upperBinIdToRemove));
10063
10118
  const useExtension = isOverflowDefaultBinArrayBitmap(minBinArrayIndex) || isOverflowDefaultBinArrayBitmap(maxBinArrayIndex);
10064
10119
  const binArrayBitmapExtension = useExtension ? deriveBinArrayBitmapExtension(this.pubkey, this.program.programId)[0] : null;
10065
- const removeLiquidityIx = await this.program.methods.removeLiquidityByRange(minBinId, maxBinId, bps.toNumber()).accounts({
10120
+ const removeLiquidityTx = await this.program.methods.removeLiquidityByRange(lowerBinIdToRemove, upperBinIdToRemove, bps.toNumber()).accounts({
10066
10121
  position,
10067
10122
  lbPair,
10068
10123
  userTokenX,
10069
10124
  userTokenY,
10070
- reserveX,
10071
- reserveY,
10072
- tokenXMint,
10073
- tokenYMint,
10125
+ reserveX: this.lbPair.reserveX,
10126
+ reserveY: this.lbPair.reserveY,
10127
+ tokenXMint: this.tokenX.publicKey,
10128
+ tokenYMint: this.tokenY.publicKey,
10074
10129
  binArrayLower,
10075
10130
  binArrayUpper,
10076
10131
  binArrayBitmapExtension,
@@ -10080,7 +10135,7 @@ var DLMM = class {
10080
10135
  }).instruction();
10081
10136
  const instructions = [
10082
10137
  ...preInstructions,
10083
- removeLiquidityIx,
10138
+ removeLiquidityTx,
10084
10139
  ...postInstructions
10085
10140
  ];
10086
10141
  const setCUIx = await getEstimatedComputeUnitIxWithBuffer(
@@ -10163,6 +10218,7 @@ var DLMM = class {
10163
10218
  * - `outAmount`: Amount of lamport to swap out
10164
10219
  * - `swapForY`: Swap token X to Y when it is true, else reversed.
10165
10220
  * - `allowedSlippage`: Allowed slippage for the swap. Expressed in BPS. To convert from slippage percentage to BPS unit: SLIPPAGE_PERCENTAGE * 100
10221
+ * - `maxExtraBinArrays`: Maximum number of extra binArrays to return
10166
10222
  * @returns {SwapQuote}
10167
10223
  * - `inAmount`: Amount of lamport to swap in
10168
10224
  * - `outAmount`: Amount of lamport to swap out
@@ -10173,9 +10229,12 @@ var DLMM = class {
10173
10229
  * @throws {DlmmSdkError}
10174
10230
  *
10175
10231
  */
10176
- swapQuoteExactOut(outAmount, swapForY, allowedSlippage, binArrays) {
10232
+ swapQuoteExactOut(outAmount, swapForY, allowedSlippage, binArrays, maxExtraBinArrays = 0) {
10177
10233
  const currentTimestamp = Date.now() / 1e3;
10178
10234
  let outAmountLeft = outAmount;
10235
+ if (maxExtraBinArrays < 0 || maxExtraBinArrays > MAX_EXTRA_BIN_ARRAYS) {
10236
+ throw new DlmmSdkError("INVALID_MAX_EXTRA_BIN_ARRAYS", `maxExtraBinArrays must be a value between 0 and ${MAX_EXTRA_BIN_ARRAYS}`);
10237
+ }
10179
10238
  let vParameterClone = Object.assign({}, this.lbPair.vParameters);
10180
10239
  let activeId = new BN10(this.lbPair.activeId);
10181
10240
  const binStep = this.lbPair.binStep;
@@ -10249,6 +10308,41 @@ var DLMM = class {
10249
10308
  );
10250
10309
  const priceImpact = startPrice.sub(endPrice).abs().div(startPrice).mul(new Decimal5(100));
10251
10310
  const maxInAmount = actualInAmount.mul(new BN10(BASIS_POINT_MAX).add(allowedSlippage)).div(new BN10(BASIS_POINT_MAX));
10311
+ if (maxExtraBinArrays > 0 && maxExtraBinArrays <= MAX_EXTRA_BIN_ARRAYS) {
10312
+ const extraBinArrays = new Array();
10313
+ while (extraBinArrays.length < maxExtraBinArrays) {
10314
+ let binArrayAccountToSwap = findNextBinArrayWithLiquidity(
10315
+ swapForY,
10316
+ activeId,
10317
+ this.lbPair,
10318
+ this.binArrayBitmapExtension?.account ?? null,
10319
+ binArrays
10320
+ );
10321
+ if (binArrayAccountToSwap == null) {
10322
+ break;
10323
+ }
10324
+ const binArrayAccountToSwapExisted = binArraysForSwap.has(binArrayAccountToSwap.publicKey);
10325
+ if (binArrayAccountToSwapExisted) {
10326
+ if (swapForY) {
10327
+ activeId = activeId.sub(new BN10(1));
10328
+ } else {
10329
+ activeId = activeId.add(new BN10(1));
10330
+ }
10331
+ } else {
10332
+ extraBinArrays.push(binArrayAccountToSwap.publicKey);
10333
+ const [lowerBinId, upperBinId] = getBinArrayLowerUpperBinId(binArrayAccountToSwap.account.index);
10334
+ if (swapForY) {
10335
+ activeId = lowerBinId.sub(new BN10(1));
10336
+ } else {
10337
+ activeId = upperBinId.add(new BN10(1));
10338
+ }
10339
+ }
10340
+ }
10341
+ extraBinArrays.forEach((binArrayPubkey) => {
10342
+ binArraysForSwap.set(binArrayPubkey, true);
10343
+ });
10344
+ }
10345
+ const binArraysPubkey = Array.from(binArraysForSwap.keys());
10252
10346
  return {
10253
10347
  inAmount: actualInAmount,
10254
10348
  maxInAmount,
@@ -10256,7 +10350,7 @@ var DLMM = class {
10256
10350
  priceImpact,
10257
10351
  fee: feeAmount,
10258
10352
  protocolFee: protocolFeeAmount,
10259
- binArraysPubkey: [...binArraysForSwap.keys()]
10353
+ binArraysPubkey
10260
10354
  };
10261
10355
  }
10262
10356
  /**
@@ -10267,6 +10361,7 @@ var DLMM = class {
10267
10361
  * - `allowedSlippage`: Allowed slippage for the swap. Expressed in BPS. To convert from slippage percentage to BPS unit: SLIPPAGE_PERCENTAGE * 100
10268
10362
  * - `binArrays`: binArrays for swapQuote.
10269
10363
  * - `isPartialFill`: Flag to check whether the the swapQuote is partial fill, default = false.
10364
+ * - `maxExtraBinArrays`: Maximum number of extra binArrays to return
10270
10365
  * @returns {SwapQuote}
10271
10366
  * - `consumedInAmount`: Amount of lamport to swap in
10272
10367
  * - `outAmount`: Amount of lamport to swap out
@@ -10277,9 +10372,12 @@ var DLMM = class {
10277
10372
  * - `binArraysPubkey`: Array of bin arrays involved in the swap
10278
10373
  * @throws {DlmmSdkError}
10279
10374
  */
10280
- swapQuote(inAmount, swapForY, allowedSlippage, binArrays, isPartialFill) {
10375
+ swapQuote(inAmount, swapForY, allowedSlippage, binArrays, isPartialFill, maxExtraBinArrays = 0) {
10281
10376
  const currentTimestamp = Date.now() / 1e3;
10282
10377
  let inAmountLeft = inAmount;
10378
+ if (maxExtraBinArrays < 0 || maxExtraBinArrays > MAX_EXTRA_BIN_ARRAYS) {
10379
+ throw new DlmmSdkError("INVALID_MAX_EXTRA_BIN_ARRAYS", `maxExtraBinArrays must be a value between 0 and ${MAX_EXTRA_BIN_ARRAYS}`);
10380
+ }
10283
10381
  let vParameterClone = Object.assign({}, this.lbPair.vParameters);
10284
10382
  let activeId = new BN10(this.lbPair.activeId);
10285
10383
  const binStep = this.lbPair.binStep;
@@ -10295,6 +10393,7 @@ var DLMM = class {
10295
10393
  let actualOutAmount = new BN10(0);
10296
10394
  let feeAmount = new BN10(0);
10297
10395
  let protocolFeeAmount = new BN10(0);
10396
+ let lastFilledActiveBinId = activeId;
10298
10397
  while (!inAmountLeft.isZero()) {
10299
10398
  let binArrayAccountToSwap = findNextBinArrayWithLiquidity(
10300
10399
  swapForY,
@@ -10340,6 +10439,7 @@ var DLMM = class {
10340
10439
  if (!startBin) {
10341
10440
  startBin = bin;
10342
10441
  }
10442
+ lastFilledActiveBinId = activeId;
10343
10443
  }
10344
10444
  }
10345
10445
  if (!inAmountLeft.isZero()) {
@@ -10367,9 +10467,44 @@ var DLMM = class {
10367
10467
  const priceImpact = new Decimal5(actualOutAmount.toString()).sub(new Decimal5(outAmountWithoutSlippage.toString())).div(new Decimal5(outAmountWithoutSlippage.toString())).mul(new Decimal5(100));
10368
10468
  const minOutAmount = actualOutAmount.mul(new BN10(BASIS_POINT_MAX).sub(allowedSlippage)).div(new BN10(BASIS_POINT_MAX));
10369
10469
  const endPrice = getPriceOfBinByBinId(
10370
- activeId.toNumber(),
10470
+ lastFilledActiveBinId.toNumber(),
10371
10471
  this.lbPair.binStep
10372
10472
  );
10473
+ if (maxExtraBinArrays > 0 && maxExtraBinArrays <= MAX_EXTRA_BIN_ARRAYS) {
10474
+ const extraBinArrays = new Array();
10475
+ while (extraBinArrays.length < maxExtraBinArrays) {
10476
+ let binArrayAccountToSwap = findNextBinArrayWithLiquidity(
10477
+ swapForY,
10478
+ activeId,
10479
+ this.lbPair,
10480
+ this.binArrayBitmapExtension?.account ?? null,
10481
+ binArrays
10482
+ );
10483
+ if (binArrayAccountToSwap == null) {
10484
+ break;
10485
+ }
10486
+ const binArrayAccountToSwapExisted = binArraysForSwap.has(binArrayAccountToSwap.publicKey);
10487
+ if (binArrayAccountToSwapExisted) {
10488
+ if (swapForY) {
10489
+ activeId = activeId.sub(new BN10(1));
10490
+ } else {
10491
+ activeId = activeId.add(new BN10(1));
10492
+ }
10493
+ } else {
10494
+ extraBinArrays.push(binArrayAccountToSwap.publicKey);
10495
+ const [lowerBinId, upperBinId] = getBinArrayLowerUpperBinId(binArrayAccountToSwap.account.index);
10496
+ if (swapForY) {
10497
+ activeId = lowerBinId.sub(new BN10(1));
10498
+ } else {
10499
+ activeId = upperBinId.add(new BN10(1));
10500
+ }
10501
+ }
10502
+ }
10503
+ extraBinArrays.forEach((binArrayPubkey) => {
10504
+ binArraysForSwap.set(binArrayPubkey, true);
10505
+ });
10506
+ }
10507
+ const binArraysPubkey = Array.from(binArraysForSwap.keys());
10373
10508
  return {
10374
10509
  consumedInAmount: inAmount,
10375
10510
  outAmount: actualOutAmount,
@@ -10377,7 +10512,7 @@ var DLMM = class {
10377
10512
  protocolFee: protocolFeeAmount,
10378
10513
  minOutAmount,
10379
10514
  priceImpact,
10380
- binArraysPubkey: [...binArraysForSwap.keys()],
10515
+ binArraysPubkey,
10381
10516
  endPrice
10382
10517
  };
10383
10518
  }
@@ -10484,7 +10619,6 @@ var DLMM = class {
10484
10619
  priceImpact,
10485
10620
  binArraysPubkey
10486
10621
  }) {
10487
- const { tokenXMint, tokenYMint, reserveX, reserveY, activeId, oracle } = await this.program.account.lbPair.fetch(lbPair);
10488
10622
  const preInstructions = [];
10489
10623
  const postInstructions = [];
10490
10624
  const [
@@ -10518,9 +10652,6 @@ var DLMM = class {
10518
10652
  const closeWrappedSOLIx = await unwrapSOLInstruction(user);
10519
10653
  closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
10520
10654
  }
10521
- let swapForY = true;
10522
- if (outToken.equals(tokenXMint))
10523
- swapForY = false;
10524
10655
  const binArrays = binArraysPubkey.map((pubkey) => {
10525
10656
  return {
10526
10657
  isSigner: false,
@@ -10534,17 +10665,17 @@ var DLMM = class {
10534
10665
  priceImpact.toNumber()
10535
10666
  ).accounts({
10536
10667
  lbPair,
10537
- reserveX,
10538
- reserveY,
10539
- tokenXMint,
10540
- tokenYMint,
10668
+ reserveX: this.lbPair.reserveX,
10669
+ reserveY: this.lbPair.reserveY,
10670
+ tokenXMint: this.lbPair.tokenXMint,
10671
+ tokenYMint: this.lbPair.tokenYMint,
10541
10672
  tokenXProgram: TOKEN_PROGRAM_ID2,
10542
10673
  tokenYProgram: TOKEN_PROGRAM_ID2,
10543
10674
  user,
10544
10675
  userTokenIn,
10545
10676
  userTokenOut,
10546
10677
  binArrayBitmapExtension: this.binArrayBitmapExtension ? this.binArrayBitmapExtension.publicKey : null,
10547
- oracle,
10678
+ oracle: this.lbPair.oracle,
10548
10679
  hostFeeIn: null
10549
10680
  }).remainingAccounts(binArrays).instruction();
10550
10681
  const instructions = [...preInstructions, swapIx, ...postInstructions];
@@ -10582,7 +10713,6 @@ var DLMM = class {
10582
10713
  user,
10583
10714
  binArraysPubkey
10584
10715
  }) {
10585
- const { tokenXMint, tokenYMint, reserveX, reserveY, activeId, oracle } = await this.program.account.lbPair.fetch(lbPair);
10586
10716
  const preInstructions = [];
10587
10717
  const postInstructions = [];
10588
10718
  const [
@@ -10616,9 +10746,6 @@ var DLMM = class {
10616
10746
  const closeWrappedSOLIx = await unwrapSOLInstruction(user);
10617
10747
  closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
10618
10748
  }
10619
- let swapForY = true;
10620
- if (outToken.equals(tokenXMint))
10621
- swapForY = false;
10622
10749
  const binArrays = binArraysPubkey.map((pubkey) => {
10623
10750
  return {
10624
10751
  isSigner: false,
@@ -10628,10 +10755,10 @@ var DLMM = class {
10628
10755
  });
10629
10756
  const swapIx = await this.program.methods.swap(inAmount, minOutAmount).accounts({
10630
10757
  lbPair,
10631
- reserveX,
10632
- reserveY,
10633
- tokenXMint,
10634
- tokenYMint,
10758
+ reserveX: this.lbPair.reserveX,
10759
+ reserveY: this.lbPair.reserveY,
10760
+ tokenXMint: this.lbPair.tokenXMint,
10761
+ tokenYMint: this.lbPair.tokenYMint,
10635
10762
  tokenXProgram: TOKEN_PROGRAM_ID2,
10636
10763
  // dont use 2022 first; lack familiarity
10637
10764
  tokenYProgram: TOKEN_PROGRAM_ID2,
@@ -10640,7 +10767,7 @@ var DLMM = class {
10640
10767
  userTokenIn,
10641
10768
  userTokenOut,
10642
10769
  binArrayBitmapExtension: this.binArrayBitmapExtension ? this.binArrayBitmapExtension.publicKey : null,
10643
- oracle,
10770
+ oracle: this.lbPair.oracle,
10644
10771
  hostFeeIn: null
10645
10772
  }).remainingAccounts(binArrays).instruction();
10646
10773
  const instructions = [...preInstructions, swapIx, ...postInstructions];
@@ -10742,6 +10869,21 @@ var DLMM = class {
10742
10869
  lastValidBlockHeight
10743
10870
  }).add(setActivationPointTx);
10744
10871
  }
10872
+ async setPairStatus(enabled) {
10873
+ const pairStatus = enabled ? 0 : 1;
10874
+ const tx = await this.program.methods.setPairStatus(pairStatus).accounts(
10875
+ {
10876
+ lbPair: this.pubkey,
10877
+ admin: this.lbPair.creator
10878
+ }
10879
+ ).transaction();
10880
+ const { blockhash, lastValidBlockHeight } = await this.program.provider.connection.getLatestBlockhash("confirmed");
10881
+ return new Transaction({
10882
+ feePayer: this.lbPair.creator,
10883
+ blockhash,
10884
+ lastValidBlockHeight
10885
+ }).add(tx);
10886
+ }
10745
10887
  /**
10746
10888
  * The function `claimSwapFee` is used to claim swap fees for a specific position owned by a specific owner.
10747
10889
  * @param
@@ -10821,11 +10963,11 @@ var DLMM = class {
10821
10963
  const tokensInvolved = [...pairTokens];
10822
10964
  for (let i = 0; i < 2; i++) {
10823
10965
  const rewardMint = this.lbPair.rewardInfos[i].mint;
10824
- if (!tokensInvolved.some((pubkey) => rewardMint.equals(pubkey)) && !rewardMint.equals(PublicKey6.default)) {
10966
+ if (!tokensInvolved.some((pubkey) => rewardMint.equals(pubkey)) && !rewardMint.equals(PublicKey7.default)) {
10825
10967
  tokensInvolved.push(this.lbPair.rewardInfos[i].mint);
10826
10968
  }
10827
10969
  }
10828
- const feeOwner = position.positionData.feeOwner.equals(PublicKey6.default) ? owner : position.positionData.feeOwner;
10970
+ const feeOwner = position.positionData.feeOwner.equals(PublicKey7.default) ? owner : position.positionData.feeOwner;
10829
10971
  const createATAAccAndIx = await Promise.all(
10830
10972
  tokensInvolved.map((token) => {
10831
10973
  if (pairTokens.some((t) => t.equals(token))) {
@@ -11085,7 +11227,7 @@ var DLMM = class {
11085
11227
  );
11086
11228
  }
11087
11229
  addLiquidityIxs.push([
11088
- ComputeBudgetProgram2.setComputeUnitLimit({
11230
+ ComputeBudgetProgram3.setComputeUnitLimit({
11089
11231
  units: DEFAULT_ADD_LIQUIDITY_CU
11090
11232
  }),
11091
11233
  ...instructions
@@ -11372,7 +11514,7 @@ var DLMM = class {
11372
11514
  const tokensInvolved = [...pairsToken];
11373
11515
  for (let i = 0; i < 2; i++) {
11374
11516
  const rewardMint = this.lbPair.rewardInfos[i].mint;
11375
- if (!tokensInvolved.some((pubkey) => rewardMint.equals(pubkey)) && !rewardMint.equals(PublicKey6.default)) {
11517
+ if (!tokensInvolved.some((pubkey) => rewardMint.equals(pubkey)) && !rewardMint.equals(PublicKey7.default)) {
11376
11518
  tokensInvolved.push(this.lbPair.rewardInfos[i].mint);
11377
11519
  }
11378
11520
  }
@@ -11382,9 +11524,9 @@ var DLMM = class {
11382
11524
  const feeOwners = [
11383
11525
  .../* @__PURE__ */ new Set([
11384
11526
  owner.toBase58(),
11385
- ...positions.filter((p) => !p.positionData.feeOwner.equals(PublicKey6.default)).map((p) => p.positionData.feeOwner.toBase58())
11527
+ ...positions.filter((p) => !p.positionData.feeOwner.equals(PublicKey7.default)).map((p) => p.positionData.feeOwner.toBase58())
11386
11528
  ])
11387
- ].map((pk) => new PublicKey6(pk));
11529
+ ].map((pk) => new PublicKey7(pk));
11388
11530
  const createATAAccAndIx = await Promise.all(
11389
11531
  tokensInvolved.map((token) => {
11390
11532
  if (pairsToken.some((p) => p.equals(token))) {
@@ -11718,7 +11860,7 @@ var DLMM = class {
11718
11860
  const preActivationSwapPoint = this.lbPair.activationPoint.sub(
11719
11861
  this.lbPair.preActivationDuration
11720
11862
  );
11721
- const activationPoint = !this.lbPair.preActivationSwapAddress.equals(PublicKey6.default) && this.lbPair.preActivationSwapAddress.equals(swapInitiator) ? preActivationSwapPoint : this.lbPair.activationPoint;
11863
+ const activationPoint = !this.lbPair.preActivationSwapAddress.equals(PublicKey7.default) && this.lbPair.preActivationSwapAddress.equals(swapInitiator) ? preActivationSwapPoint : this.lbPair.activationPoint;
11722
11864
  if (currentPoint < activationPoint) {
11723
11865
  return true;
11724
11866
  }
@@ -11772,7 +11914,7 @@ var DLMM = class {
11772
11914
  const liquidityShare = positionVersion === 0 /* V1 */ ? position.liquidityShares[binIdxInPosition] : position.liquidityShares[binIdxInPosition].shrn(64);
11773
11915
  for (let j = 0; j < 2; j++) {
11774
11916
  const pairRewardInfo = lbPair.rewardInfos[j];
11775
- if (!pairRewardInfo.mint.equals(PublicKey6.default)) {
11917
+ if (!pairRewardInfo.mint.equals(PublicKey7.default)) {
11776
11918
  let rewardPerTokenStored = binState.rewardPerTokenStored[j];
11777
11919
  if (i == lbPair.activeId && !binState.liquiditySupply.isZero()) {
11778
11920
  const currentTime = new BN10(
@@ -11885,12 +12027,7 @@ var DLMM = class {
11885
12027
  let totalYAmount = new Decimal5(0);
11886
12028
  bins.forEach((bin, idx) => {
11887
12029
  const binSupply = new Decimal5(bin.supply.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
- }
12030
+ const posShare = new Decimal5(posShares[idx].toString());
11894
12031
  const positionXAmount = binSupply.eq(new Decimal5("0")) ? new Decimal5("0") : posShare.mul(bin.xAmount.toString()).div(binSupply);
11895
12032
  const positionYAmount = binSupply.eq(new Decimal5("0")) ? new Decimal5("0") : posShare.mul(bin.yAmount.toString()).div(binSupply);
11896
12033
  totalXAmount = totalXAmount.add(positionXAmount);
@@ -12138,7 +12275,7 @@ var DLMM = class {
12138
12275
  const claimTransactions = [];
12139
12276
  for (let i = 0; i < 2; i++) {
12140
12277
  const rewardInfo = this.lbPair.rewardInfos[i];
12141
- if (!rewardInfo || rewardInfo.mint.equals(PublicKey6.default))
12278
+ if (!rewardInfo || rewardInfo.mint.equals(PublicKey7.default))
12142
12279
  continue;
12143
12280
  const preInstructions = [];
12144
12281
  const { ataPubKey, ix } = await getOrCreateATAInstruction(
@@ -12191,7 +12328,7 @@ var DLMM = class {
12191
12328
  this.pubkey,
12192
12329
  this.program.programId
12193
12330
  );
12194
- const walletToReceiveFee = feeOwner.equals(PublicKey6.default) ? owner : feeOwner;
12331
+ const walletToReceiveFee = feeOwner.equals(PublicKey7.default) ? owner : feeOwner;
12195
12332
  const preInstructions = [];
12196
12333
  const [
12197
12334
  { ataPubKey: userTokenX, ix: createInTokenAccountIx },
@@ -12262,6 +12399,7 @@ export {
12262
12399
  MAX_BIN_PER_POSITION,
12263
12400
  MAX_BIN_PER_TX,
12264
12401
  MAX_CLAIM_ALL_ALLOWED,
12402
+ MAX_EXTRA_BIN_ARRAYS,
12265
12403
  MAX_FEE_RATE,
12266
12404
  Network,
12267
12405
  POSITION_FEE,
@@ -12330,7 +12468,6 @@ export {
12330
12468
  toAmountBidSide,
12331
12469
  toAmountBothSide,
12332
12470
  toAmountsBothSideByStrategy,
12333
- toAmountsOneSideByStrategy,
12334
12471
  toStrategyParameters,
12335
12472
  toWeightDistribution,
12336
12473
  unwrapSOLInstruction,