@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.js CHANGED
@@ -25,7 +25,7 @@ var _decimaljs = require('decimal.js'); var _decimaljs2 = _interopRequireDefault
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
  };
@@ -6472,42 +6341,13 @@ function generateBinAmount(amount, binStep, binId, tokenXDecimal, tokenYDecimal,
6472
6341
  return new (0, _anchor.BN)(c1.sub(c0).floor().toString());
6473
6342
  }
6474
6343
 
6475
- // src/dlmm/helpers/computeUnit.ts
6344
+ // src/dlmm/helpers/index.ts
6345
+ var _helpers = require('@solana-developers/helpers');
6476
6346
 
6347
+ // src/dlmm/helpers/computeUnit.ts
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
- _web3js.ComputeBudgetProgram.setComputeUnitLimit({ units: 14e5 }),
6486
- ...instructions
6487
- ];
6488
- const testTransaction = new (0, _web3js.VersionedTransaction)(
6489
- new (0, _web3js.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: _web3js.PublicKey.default.toString()
6495
- }).compileToV0Message(lookupTables)
6496
- );
6497
- const rpcResponse = await connection.simulateTransaction(testTransaction, {
6498
- replaceRecentBlockhash: true,
6499
- sigVerify: false,
6500
- commitment
6501
- });
6502
- if (_optionalChain([rpcResponse, 'optionalAccess', _21 => _21.value, 'optionalAccess', _22 => _22.err])) {
6503
- const logs = _optionalChain([rpcResponse, 'access', _23 => _23.value, 'access', _24 => _24.logs, 'optionalAccess', _25 => _25.join, 'call', _26 => _26("\n \u2022 ")]) || "No logs available";
6504
- throw new Error(
6505
- `Transaction simulation failed:
6506
- \u2022${logs}` + JSON.stringify(_optionalChain([rpcResponse, 'optionalAccess', _27 => _27.value, 'optionalAccess', _28 => _28.err]))
6507
- );
6508
- }
6509
- return rpcResponse.value.unitsConsumed || null;
6510
- };
6511
6351
 
6512
6352
  // src/dlmm/helpers/derive.ts
6513
6353
 
@@ -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) => {
@@ -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,
@@ -7644,7 +7563,7 @@ async function getTokensMintFromPoolAddress(connection, poolAddress, opt) {
7644
7563
  );
7645
7564
  const program = new (0, _anchor.Program)(
7646
7565
  IDL,
7647
- LBCLMM_PROGRAM_IDS[_nullishCoalesce(_optionalChain([opt, 'optionalAccess', _29 => _29.cluster]), () => ( "mainnet-beta"))],
7566
+ LBCLMM_PROGRAM_IDS[_nullishCoalesce(_optionalChain([opt, 'optionalAccess', _21 => _21.cluster]), () => ( "mainnet-beta"))],
7648
7567
  provider
7649
7568
  );
7650
7569
  const poolAccount = await program.account.lbPair.fetchNullable(
@@ -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 _spltoken.TokenAccountNotFoundError || e instanceof _spltoken.TokenInvalidAccountOwnerError) {
7705
- const ix = _spltoken.createAssociatedTokenAccountIdempotentInstruction.call(void 0,
7624
+ const ix = _spltoken.createAssociatedTokenAccountInstruction.call(void 0,
7706
7625
  payer,
7707
7626
  toAccount,
7708
7627
  owner,
@@ -7722,7 +7641,7 @@ async function getTokenBalance(conn, tokenAccount) {
7722
7641
  var parseLogs = (eventParser, logs) => {
7723
7642
  if (!logs.length)
7724
7643
  throw new Error("No logs found");
7725
- for (const event of _optionalChain([eventParser, 'optionalAccess', _30 => _30.parseLogs, 'call', _31 => _31(logs)])) {
7644
+ for (const event of _optionalChain([eventParser, 'optionalAccess', _22 => _22.parseLogs, 'call', _23 => _23(logs)])) {
7726
7645
  return event.data;
7727
7646
  }
7728
7647
  throw new Error("No events found");
@@ -7779,7 +7698,7 @@ var getEstimatedComputeUnitUsageWithBuffer = async (connection, instructions, fe
7779
7698
  }
7780
7699
  buffer = Math.max(0, buffer);
7781
7700
  buffer = Math.min(1, buffer);
7782
- const estimatedComputeUnitUsage = await getSimulationComputeUnits(
7701
+ const estimatedComputeUnitUsage = await _helpers.getSimulationComputeUnits.call(void 0,
7783
7702
  connection,
7784
7703
  instructions,
7785
7704
  feePayer,
@@ -7837,13 +7756,13 @@ var DLMM = class {
7837
7756
  );
7838
7757
  const program = new (0, _anchor.Program)(
7839
7758
  IDL,
7840
- _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _32 => _32.programId]), () => ( LBCLMM_PROGRAM_IDS[_nullishCoalesce(_optionalChain([opt, 'optionalAccess', _33 => _33.cluster]), () => ( "mainnet-beta"))])),
7759
+ _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _24 => _24.programId]), () => ( LBCLMM_PROGRAM_IDS[_nullishCoalesce(_optionalChain([opt, 'optionalAccess', _25 => _25.cluster]), () => ( "mainnet-beta"))])),
7841
7760
  provider
7842
7761
  );
7843
7762
  return program.account.lbPair.all();
7844
7763
  }
7845
7764
  static async getPairPubkeyIfExists(connection, tokenX, tokenY, binStep, baseFactor, opt) {
7846
- const cluster = _optionalChain([opt, 'optionalAccess', _34 => _34.cluster]) || "mainnet-beta";
7765
+ const cluster = _optionalChain([opt, 'optionalAccess', _26 => _26.cluster]) || "mainnet-beta";
7847
7766
  const provider = new (0, _anchor.AnchorProvider)(
7848
7767
  connection,
7849
7768
  {},
@@ -7851,7 +7770,7 @@ var DLMM = class {
7851
7770
  );
7852
7771
  const program = new (0, _anchor.Program)(
7853
7772
  IDL,
7854
- _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _35 => _35.programId]), () => ( LBCLMM_PROGRAM_IDS[cluster])),
7773
+ _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _27 => _27.programId]), () => ( LBCLMM_PROGRAM_IDS[cluster])),
7855
7774
  provider
7856
7775
  );
7857
7776
  try {
@@ -7890,7 +7809,7 @@ var DLMM = class {
7890
7809
  * @returns The `create` function returns a `Promise` that resolves to a `DLMM` object.
7891
7810
  */
7892
7811
  static async create(connection, dlmm, opt) {
7893
- const cluster = _optionalChain([opt, 'optionalAccess', _36 => _36.cluster]) || "mainnet-beta";
7812
+ const cluster = _optionalChain([opt, 'optionalAccess', _28 => _28.cluster]) || "mainnet-beta";
7894
7813
  const provider = new (0, _anchor.AnchorProvider)(
7895
7814
  connection,
7896
7815
  {},
@@ -7898,7 +7817,7 @@ var DLMM = class {
7898
7817
  );
7899
7818
  const program = new (0, _anchor.Program)(
7900
7819
  IDL,
7901
- _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _37 => _37.programId]), () => ( LBCLMM_PROGRAM_IDS[cluster])),
7820
+ _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _29 => _29.programId]), () => ( LBCLMM_PROGRAM_IDS[cluster])),
7902
7821
  provider
7903
7822
  );
7904
7823
  const binArrayBitMapExtensionPubkey = deriveBinArrayBitmapExtension(
@@ -7914,14 +7833,14 @@ var DLMM = class {
7914
7833
  connection,
7915
7834
  accountsToFetch
7916
7835
  );
7917
- const lbPairAccountInfoBuffer = _optionalChain([accountsInfo, 'access', _38 => _38[0], 'optionalAccess', _39 => _39.data]);
7836
+ const lbPairAccountInfoBuffer = _optionalChain([accountsInfo, 'access', _30 => _30[0], 'optionalAccess', _31 => _31.data]);
7918
7837
  if (!lbPairAccountInfoBuffer)
7919
7838
  throw new Error(`LB Pair account ${dlmm.toBase58()} not found`);
7920
7839
  const lbPairAccInfo = program.coder.accounts.decode(
7921
7840
  "lbPair",
7922
7841
  lbPairAccountInfoBuffer
7923
7842
  );
7924
- const binArrayBitMapAccountInfoBuffer = _optionalChain([accountsInfo, 'access', _40 => _40[1], 'optionalAccess', _41 => _41.data]);
7843
+ const binArrayBitMapAccountInfoBuffer = _optionalChain([accountsInfo, 'access', _32 => _32[1], 'optionalAccess', _33 => _33.data]);
7925
7844
  let binArrayBitMapExtensionAccInfo = null;
7926
7845
  if (binArrayBitMapAccountInfoBuffer) {
7927
7846
  binArrayBitMapExtensionAccInfo = program.coder.accounts.decode(
@@ -7929,7 +7848,7 @@ var DLMM = class {
7929
7848
  binArrayBitMapAccountInfoBuffer
7930
7849
  );
7931
7850
  }
7932
- const clockAccountInfoBuffer = _optionalChain([accountsInfo, 'access', _42 => _42[2], 'optionalAccess', _43 => _43.data]);
7851
+ const clockAccountInfoBuffer = _optionalChain([accountsInfo, 'access', _34 => _34[2], 'optionalAccess', _35 => _35.data]);
7933
7852
  if (!clockAccountInfoBuffer)
7934
7853
  throw new Error(`Clock account not found`);
7935
7854
  const clock = ClockLayout.decode(clockAccountInfoBuffer);
@@ -7990,7 +7909,7 @@ var DLMM = class {
7990
7909
  * objects.
7991
7910
  */
7992
7911
  static async createMultiple(connection, dlmmList, opt) {
7993
- const cluster = _optionalChain([opt, 'optionalAccess', _44 => _44.cluster]) || "mainnet-beta";
7912
+ const cluster = _optionalChain([opt, 'optionalAccess', _36 => _36.cluster]) || "mainnet-beta";
7994
7913
  const provider = new (0, _anchor.AnchorProvider)(
7995
7914
  connection,
7996
7915
  {},
@@ -7998,7 +7917,7 @@ var DLMM = class {
7998
7917
  );
7999
7918
  const program = new (0, _anchor.Program)(
8000
7919
  IDL,
8001
- _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _45 => _45.programId]), () => ( LBCLMM_PROGRAM_IDS[cluster])),
7920
+ _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _37 => _37.programId]), () => ( LBCLMM_PROGRAM_IDS[cluster])),
8002
7921
  provider
8003
7922
  );
8004
7923
  const binArrayBitMapExtensions = dlmmList.map(
@@ -8014,14 +7933,14 @@ var DLMM = class {
8014
7933
  accountsToFetch
8015
7934
  );
8016
7935
  const clockAccount = accountsInfo.pop();
8017
- const clockAccountInfoBuffer = _optionalChain([clockAccount, 'optionalAccess', _46 => _46.data]);
7936
+ const clockAccountInfoBuffer = _optionalChain([clockAccount, 'optionalAccess', _38 => _38.data]);
8018
7937
  if (!clockAccountInfoBuffer)
8019
7938
  throw new Error(`Clock account not found`);
8020
7939
  const clock = ClockLayout.decode(clockAccountInfoBuffer);
8021
7940
  const lbPairArraysMap = /* @__PURE__ */ new Map();
8022
7941
  for (let i = 0; i < dlmmList.length; i++) {
8023
7942
  const lbPairPubKey = dlmmList[i];
8024
- const lbPairAccountInfoBuffer = _optionalChain([accountsInfo, 'access', _47 => _47[i], 'optionalAccess', _48 => _48.data]);
7943
+ const lbPairAccountInfoBuffer = _optionalChain([accountsInfo, 'access', _39 => _39[i], 'optionalAccess', _40 => _40.data]);
8025
7944
  if (!lbPairAccountInfoBuffer)
8026
7945
  throw new Error(`LB Pair account ${lbPairPubKey.toBase58()} not found`);
8027
7946
  const binArrayAccInfo = program.coder.accounts.decode(
@@ -8034,7 +7953,7 @@ var DLMM = class {
8034
7953
  for (let i = dlmmList.length; i < accountsInfo.length; i++) {
8035
7954
  const index = i - dlmmList.length;
8036
7955
  const lbPairPubkey = dlmmList[index];
8037
- const binArrayBitMapAccountInfoBuffer = _optionalChain([accountsInfo, 'access', _49 => _49[i], 'optionalAccess', _50 => _50.data]);
7956
+ const binArrayBitMapAccountInfoBuffer = _optionalChain([accountsInfo, 'access', _41 => _41[i], 'optionalAccess', _42 => _42.data]);
8038
7957
  if (binArrayBitMapAccountInfoBuffer) {
8039
7958
  const binArrayBitMapExtensionAccInfo = program.coder.accounts.decode(
8040
7959
  "binArrayBitmapExtension",
@@ -8118,7 +8037,7 @@ var DLMM = class {
8118
8037
  );
8119
8038
  const program = new (0, _anchor.Program)(
8120
8039
  IDL,
8121
- _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _51 => _51.programId]), () => ( LBCLMM_PROGRAM_IDS[_nullishCoalesce(_optionalChain([opt, 'optionalAccess', _52 => _52.cluster]), () => ( "mainnet-beta"))])),
8040
+ _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _43 => _43.programId]), () => ( LBCLMM_PROGRAM_IDS[_nullishCoalesce(_optionalChain([opt, 'optionalAccess', _44 => _44.cluster]), () => ( "mainnet-beta"))])),
8122
8041
  provider
8123
8042
  );
8124
8043
  const presetParameter = await program.account.presetParameter.all();
@@ -8136,7 +8055,7 @@ var DLMM = class {
8136
8055
  * Pair account, and the value is an object of PositionInfo
8137
8056
  */
8138
8057
  static async getAllLbPairPositionsByUser(connection, userPubKey, opt) {
8139
- const cluster = _optionalChain([opt, 'optionalAccess', _53 => _53.cluster]) || "mainnet-beta";
8058
+ const cluster = _optionalChain([opt, 'optionalAccess', _45 => _45.cluster]) || "mainnet-beta";
8140
8059
  const provider = new (0, _anchor.AnchorProvider)(
8141
8060
  connection,
8142
8061
  {},
@@ -8144,17 +8063,52 @@ var DLMM = class {
8144
8063
  );
8145
8064
  const program = new (0, _anchor.Program)(
8146
8065
  IDL,
8147
- _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _54 => _54.programId]), () => ( LBCLMM_PROGRAM_IDS[cluster])),
8066
+ _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _46 => _46.programId]), () => ( LBCLMM_PROGRAM_IDS[cluster])),
8148
8067
  provider
8149
8068
  );
8150
- const positionsV2 = await program.account.positionV2.all([
8151
- {
8152
- memcmp: {
8153
- bytes: _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: _bytes.bs58.encode(userPubKey.toBuffer()),
8074
+ offset: 8 + 32
8075
+ }
8155
8076
  }
8156
- }
8077
+ ]),
8078
+ program.account.positionV2.all([
8079
+ {
8080
+ memcmp: {
8081
+ bytes: _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 (0, _anchor.BN)(lowerBinId));
8091
+ const upperBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(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 (0, _web3js.PublicKey)(pubkey)
8108
+ );
8109
+ const lbPairArray = Array.from(lbPairSet).map(
8110
+ (pubkey) => new (0, _web3js.PublicKey)(pubkey)
8111
+ );
8158
8112
  const binArrayPubkeySetV2 = /* @__PURE__ */ new Set();
8159
8113
  const lbPairSetV2 = /* @__PURE__ */ new Set();
8160
8114
  positionsV2.forEach(({ account: { upperBinId, lowerBinId, lbPair } }) => {
@@ -8182,24 +8136,60 @@ var DLMM = class {
8182
8136
  );
8183
8137
  const [clockAccInfo, ...binArraysAccInfo] = await chunkedGetMultipleAccountInfos(connection, [
8184
8138
  _web3js.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 = _spltoken.AccountLayout.decode(reserveAccBufferX.data);
8223
+ const reserveAccY = _spltoken.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 = _spltoken.MintLayout.decode(mintXBuffer.data);
8235
+ const mintY = _spltoken.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 (0, _anchor.BN)(lowerBinId));
8259
8278
  const upperBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(upperBinId));
8260
8279
  const [lowerBinArrayPubKey] = deriveBinArray(
@@ -8267,57 +8286,42 @@ 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)
8280
- ]);
8281
- const reserveXBalance = _nullishCoalesce(_optionalChain([lbPairReserveMapV2, 'access', _55 => _55.get, 'call', _56 => _56(lbPair.toBase58()), 'optionalAccess', _57 => _57.reserveX]), () => ( BigInt(0)));
8282
- const reserveYBalance = _nullishCoalesce(_optionalChain([lbPairReserveMapV2, 'access', _58 => _58.get, 'call', _59 => _59(lbPair.toBase58()), 'optionalAccess', _60 => _60.reserveY]), () => ( BigInt(0)));
8295
+ const lbPairAcc = lbPairArraysMap.get(lbPair.toBase58());
8296
+ const { mintXDecimal, mintYDecimal } = lbPairMintMap.get(
8297
+ lbPair.toBase58()
8298
+ );
8299
+ const reserveXBalance = _nullishCoalesce(_optionalChain([lbPairReserveMap, 'access', _47 => _47.get, 'call', _48 => _48(lbPair.toBase58()), 'optionalAccess', _49 => _49.reserveX]), () => ( BigInt(0)));
8300
+ const reserveYBalance = _nullishCoalesce(_optionalChain([lbPairReserveMap, 'access', _50 => _50.get, 'call', _51 => _51(lbPair.toBase58()), 'optionalAccess', _52 => _52.reserveY]), () => ( BigInt(0)));
8283
8301
  const tokenX = {
8284
8302
  publicKey: lbPairAcc.tokenXMint,
8285
8303
  reserve: lbPairAcc.reserveX,
8286
8304
  amount: reserveXBalance,
8287
- decimal: baseTokenDecimal
8305
+ decimal: mintXDecimal
8288
8306
  };
8289
8307
  const tokenY = {
8290
8308
  publicKey: lbPairAcc.tokenYMint,
8291
8309
  reserve: lbPairAcc.reserveY,
8292
8310
  amount: reserveYBalance,
8293
- decimal: quoteTokenDecimal
8311
+ decimal: mintYDecimal
8294
8312
  };
8295
- const positionData = !!lowerBinArray && !!upperBinArray ? await DLMM.processPosition(
8313
+ const positionData = await DLMM.processPosition(
8296
8314
  program,
8297
- 1 /* V2 */,
8315
+ 0 /* V1 */,
8298
8316
  lbPairAcc,
8299
8317
  onChainTimestamp,
8300
8318
  account,
8301
- baseTokenDecimal,
8302
- quoteTokenDecimal,
8319
+ mintXDecimal,
8320
+ mintYDecimal,
8303
8321
  lowerBinArray,
8304
8322
  upperBinArray,
8305
- feeOwner
8306
- ) : {
8307
- totalXAmount: "0",
8308
- totalYAmount: "0",
8309
- positionBinData: [],
8310
- lastUpdatedAt: new (0, _anchor.BN)(0),
8311
- upperBinId,
8312
- lowerBinId,
8313
- feeX: new (0, _anchor.BN)(0),
8314
- feeY: new (0, _anchor.BN)(0),
8315
- rewardOne: new (0, _anchor.BN)(0),
8316
- rewardTwo: new (0, _anchor.BN)(0),
8317
- feeOwner,
8318
- totalClaimedFeeXAmount: new (0, _anchor.BN)(0),
8319
- totalClaimedFeeYAmount: new (0, _anchor.BN)(0)
8320
- };
8323
+ _web3js.PublicKey.default
8324
+ );
8321
8325
  if (positionData) {
8322
8326
  positionsMap.set(lbPair.toBase58(), {
8323
8327
  publicKey: lbPair,
@@ -8325,136 +8329,144 @@ var DLMM = class {
8325
8329
  tokenX,
8326
8330
  tokenY,
8327
8331
  lbPairPositionsData: [
8328
- ..._nullishCoalesce(_optionalChain([positionsMap, 'access', _61 => _61.get, 'call', _62 => _62(lbPair.toBase58()), 'optionalAccess', _63 => _63.lbPairPositionsData]), () => ( [])),
8332
+ ..._nullishCoalesce(_optionalChain([positionsMap, 'access', _53 => _53.get, 'call', _54 => _54(lbPair.toBase58()), 'optionalAccess', _55 => _55.lbPairPositionsData]), () => ( [])),
8329
8333
  {
8330
8334
  publicKey: positionPubKey,
8331
8335
  positionData,
8332
- version: 1 /* V2 */
8336
+ version: 0 /* V1 */
8333
8337
  }
8334
8338
  ]
8335
8339
  });
8336
8340
  }
8337
8341
  }
8338
- return positionsMap;
8339
- }
8340
- static getPricePerLamport(tokenXDecimal, tokenYDecimal, price) {
8341
- return new (0, _decimaljs2.default)(price).mul(new (0, _decimaljs2.default)(10 ** (tokenYDecimal - tokenXDecimal))).toString();
8342
- }
8343
- static getBinIdFromPrice(price, binStep, min) {
8344
- const binStepNum = new (0, _decimaljs2.default)(binStep).div(new (0, _decimaljs2.default)(BASIS_POINT_MAX));
8345
- const binId = new (0, _decimaljs2.default)(price).log().dividedBy(new (0, _decimaljs2.default)(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: _bytes.bs58.encode(this.pubkey.toBuffer()),
8361
- offset: 8
8362
- }
8363
- }
8364
- ]);
8365
- const clockAccInfo = await this.program.provider.connection.getAccountInfo(_web3js.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 (0, _anchor.BN)(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 } }) => {
8342
+ for (let position of positionsV2) {
8343
+ const { account, publicKey: positionPubKey } = position;
8344
+ const { upperBinId, lowerBinId, lbPair, feeOwner } = account;
8377
8345
  const lowerBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(lowerBinId));
8378
8346
  const upperBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(upperBinId));
8379
8347
  const [lowerBinArrayPubKey] = deriveBinArray(
8380
- this.pubkey,
8348
+ lbPair,
8381
8349
  lowerBinArrayIndex,
8382
- this.program.programId
8350
+ program.programId
8383
8351
  );
8384
8352
  const [upperBinArrayPubKey] = deriveBinArray(
8385
- this.pubkey,
8353
+ lbPair,
8386
8354
  upperBinArrayIndex,
8387
- this.program.programId
8355
+ program.programId
8388
8356
  );
8389
- binArrayPubkeySetV2.add(lowerBinArrayPubKey.toBase58());
8390
- binArrayPubkeySetV2.add(upperBinArrayPubKey.toBase58());
8391
- });
8392
- const binArrayPubkeyArrayV2 = Array.from(binArrayPubkeySetV2).map(
8393
- (pubkey) => new (0, _web3js.PublicKey)(pubkey)
8394
- );
8395
- const binArraysAccInfo = await chunkedGetMultipleAccountInfos(
8396
- this.program.provider.connection,
8397
- binArrayPubkeyArrayV2
8398
- );
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
8357
+ const lowerBinArray = positionBinArraysMapV2.get(
8358
+ lowerBinArrayPubKey.toBase58()
8410
8359
  );
8411
- positionBinArraysMapV2.set(binArrayPubkey.toBase58(), binArrayAccInfo);
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)
8367
+ ]);
8368
+ const reserveXBalance = _nullishCoalesce(_optionalChain([lbPairReserveMapV2, 'access', _56 => _56.get, 'call', _57 => _57(lbPair.toBase58()), 'optionalAccess', _58 => _58.reserveX]), () => ( BigInt(0)));
8369
+ const reserveYBalance = _nullishCoalesce(_optionalChain([lbPairReserveMapV2, 'access', _59 => _59.get, 'call', _60 => _60(lbPair.toBase58()), 'optionalAccess', _61 => _61.reserveY]), () => ( BigInt(0)));
8370
+ const tokenX = {
8371
+ publicKey: lbPairAcc.tokenXMint,
8372
+ reserve: lbPairAcc.reserveX,
8373
+ amount: reserveXBalance,
8374
+ decimal: baseTokenDecimal
8375
+ };
8376
+ const tokenY = {
8377
+ publicKey: lbPairAcc.tokenYMint,
8378
+ reserve: lbPairAcc.reserveY,
8379
+ amount: reserveYBalance,
8380
+ decimal: quoteTokenDecimal
8381
+ };
8382
+ const positionData = await DLMM.processPosition(
8383
+ program,
8384
+ 1 /* V2 */,
8385
+ lbPairAcc,
8386
+ onChainTimestamp,
8387
+ account,
8388
+ baseTokenDecimal,
8389
+ quoteTokenDecimal,
8390
+ lowerBinArray,
8391
+ upperBinArray,
8392
+ feeOwner
8393
+ );
8394
+ if (positionData) {
8395
+ positionsMap.set(lbPair.toBase58(), {
8396
+ publicKey: lbPair,
8397
+ lbPair: lbPairAcc,
8398
+ tokenX,
8399
+ tokenY,
8400
+ lbPairPositionsData: [
8401
+ ..._nullishCoalesce(_optionalChain([positionsMap, 'access', _62 => _62.get, 'call', _63 => _63(lbPair.toBase58()), 'optionalAccess', _64 => _64.lbPairPositionsData]), () => ( [])),
8402
+ {
8403
+ publicKey: positionPubKey,
8404
+ positionData,
8405
+ version: 1 /* V2 */
8406
+ }
8407
+ ]
8408
+ });
8409
+ }
8412
8410
  }
8413
- const positionsLockInfo = await Promise.all(
8414
- positionsWithLock.map(async ({ publicKey, account }) => {
8415
- const { lowerBinId, upperBinId, feeOwner } = account;
8411
+ return positionsMap;
8412
+ }
8413
+ static async migratePosition(connection, positions, newPositions, walletPubkey, opt) {
8414
+ const cluster = _optionalChain([opt, 'optionalAccess', _65 => _65.cluster]) || "mainnet-beta";
8415
+ const provider = new (0, _anchor.AnchorProvider)(
8416
+ connection,
8417
+ {},
8418
+ _anchor.AnchorProvider.defaultOptions()
8419
+ );
8420
+ const program = new (0, _anchor.Program)(
8421
+ IDL,
8422
+ _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _66 => _66.programId]), () => ( LBCLMM_PROGRAM_IDS[cluster])),
8423
+ provider
8424
+ );
8425
+ const positionsState = await program.account.position.fetchMultiple(
8426
+ positions
8427
+ );
8428
+ const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash("confirmed");
8429
+ return Promise.all(
8430
+ positionsState.map(async ({ lbPair, lowerBinId }, idx) => {
8431
+ const position = positions[idx];
8416
8432
  const lowerBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(lowerBinId));
8417
- const upperBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(upperBinId));
8433
+ const upperBinArrayIndex = lowerBinArrayIndex.add(new (0, _anchor.BN)(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
8442
+ program.programId
8427
8443
  );
8428
- const lowerBinArray = positionBinArraysMapV2.get(
8429
- lowerBinArrayPubKey.toBase58()
8430
- );
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: _web3js.SystemProgram.programId
8454
+ }).transaction();
8455
+ return new (0, _web3js.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 (0, _decimaljs2.default)(price).mul(new (0, _decimaljs2.default)(10 ** (tokenYDecimal - tokenXDecimal))).toString();
8465
+ }
8466
+ static getBinIdFromPrice(price, binStep, min) {
8467
+ const binStepNum = new (0, _decimaljs2.default)(binStep).div(new (0, _decimaljs2.default)(BASIS_POINT_MAX));
8468
+ const binId = new (0, _decimaljs2.default)(price).log().dividedBy(new (0, _decimaljs2.default)(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) {
@@ -8465,7 +8477,7 @@ var DLMM = class {
8465
8477
  );
8466
8478
  const program = new (0, _anchor.Program)(
8467
8479
  IDL,
8468
- _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _64 => _64.programId]), () => ( LBCLMM_PROGRAM_IDS[opt.cluster])),
8480
+ _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _67 => _67.programId]), () => ( LBCLMM_PROGRAM_IDS[opt.cluster])),
8469
8481
  provider
8470
8482
  );
8471
8483
  const [lbPair] = derivePermissionLbPair(
@@ -8514,7 +8526,7 @@ var DLMM = class {
8514
8526
  );
8515
8527
  const program = new (0, _anchor.Program)(
8516
8528
  IDL,
8517
- _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _65 => _65.programId]), () => ( LBCLMM_PROGRAM_IDS[opt.cluster])),
8529
+ _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _68 => _68.programId]), () => ( LBCLMM_PROGRAM_IDS[opt.cluster])),
8518
8530
  provider
8519
8531
  );
8520
8532
  const [lbPair] = deriveCustomizablePermissionlessLbPair(
@@ -8539,9 +8551,9 @@ var DLMM = class {
8539
8551
  padding: Array(64).fill(0)
8540
8552
  };
8541
8553
  const userTokenX = _spltoken.getAssociatedTokenAddressSync.call(void 0, tokenX, creatorKey);
8542
- const userTokenY = _spltoken.getAssociatedTokenAddressSync.call(void 0, tokenY, creatorKey);
8543
8554
  return program.methods.initializeCustomizablePermissionlessLbPair(ixData).accounts({
8544
8555
  lbPair,
8556
+ rent: _web3js.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: _web3js.SystemProgram.programId,
8553
8565
  userTokenX,
8554
- userTokenY,
8555
8566
  funder: creatorKey
8556
8567
  }).transaction();
8557
8568
  }
@@ -8563,7 +8574,7 @@ var DLMM = class {
8563
8574
  );
8564
8575
  const program = new (0, _anchor.Program)(
8565
8576
  IDL,
8566
- _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _66 => _66.programId]), () => ( LBCLMM_PROGRAM_IDS[opt.cluster])),
8577
+ _nullishCoalesce(_optionalChain([opt, 'optionalAccess', _69 => _69.programId]), () => ( LBCLMM_PROGRAM_IDS[opt.cluster])),
8567
8578
  provider
8568
8579
  );
8569
8580
  const existsPool = await this.getPairPubkeyIfExists(
@@ -8699,7 +8710,7 @@ var DLMM = class {
8699
8710
  swapForY,
8700
8711
  new (0, _anchor.BN)(activeIdToLoop),
8701
8712
  this.lbPair,
8702
- _nullishCoalesce(_optionalChain([this, 'access', _67 => _67.binArrayBitmapExtension, 'optionalAccess', _68 => _68.account]), () => ( null))
8713
+ _nullishCoalesce(_optionalChain([this, 'access', _70 => _70.binArrayBitmapExtension, 'optionalAccess', _71 => _71.account]), () => ( null))
8703
8714
  );
8704
8715
  if (binArrayIndex === null)
8705
8716
  shouldStop = true;
@@ -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: _bytes.bs58.encode(userPubKey.toBuffer()),
8958
+ offset: 8 + 32
8959
+ }
8960
+ },
8961
+ {
8962
+ memcmp: {
8963
+ bytes: _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 (0, _anchor.BN)(lowerBinId));
8999
+ const upperBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(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 (0, _web3js.PublicKey)(pubkey)
9015
+ );
8971
9016
  const binArrayPubkeySetV2 = /* @__PURE__ */ new Set();
8972
9017
  positionsV2.forEach(({ account: { upperBinId, lowerBinId, lbPair } }) => {
8973
9018
  const lowerBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(lowerBinId));
@@ -8993,13 +9038,28 @@ var DLMM = class {
8993
9038
  [
8994
9039
  this.pubkey,
8995
9040
  _web3js.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 (0, _anchor.BN)(
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 (0, _anchor.BN)(lowerBinId));
9083
+ const upperBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(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
+ _web3js.PublicKey.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 (0, _anchor.BN)(lowerBinId));
9140
- const upperBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(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
- _web3js.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 (0, _anchor.BN)(0),
9167
- upperBinId,
9168
- lowerBinId,
9169
- feeX: new (0, _anchor.BN)(0),
9170
- feeY: new (0, _anchor.BN)(0),
9171
- rewardOne: new (0, _anchor.BN)(0),
9172
- rewardTwo: new (0, _anchor.BN)(0),
9173
- feeOwner,
9174
- totalClaimedFeeXAmount: new (0, _anchor.BN)(0),
9175
- totalClaimedFeeYAmount: new (0, _anchor.BN)(0)
9176
- },
9177
- version: 1 /* V2 */
9178
- };
9179
- }
9180
- const onChainTimestamp = new (0, _anchor.BN)(
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 (0, _anchor.BN)(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 (0, _anchor.BN)(lowerBinId));
9938
9946
  const upperBinArrayIndex = lowerBinArrayIndex.add(new (0, _anchor.BN)(1));
9939
9947
  const [binArrayLower] = deriveBinArray(
9940
9948
  lbPair,
@@ -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: _spltoken.TOKEN_PROGRAM_ID,
10000
10008
  tokenXMint: this.tokenX.publicKey,
10001
10009
  tokenYMint: this.tokenY.publicKey,
@@ -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 (0, _anchor.BN)(lowerBinIdToRemove));
10052
- const maxBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(upperBinIdToRemove));
10059
+ const minBinId = Math.min(...binIds);
10060
+ const maxBinId = Math.max(...binIds);
10061
+ const minBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(minBinId));
10062
+ const maxBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(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(
@@ -10186,7 +10196,7 @@ var DLMM = class {
10186
10196
  swapForY,
10187
10197
  activeId,
10188
10198
  this.lbPair,
10189
- _nullishCoalesce(_optionalChain([this, 'access', _69 => _69.binArrayBitmapExtension, 'optionalAccess', _70 => _70.account]), () => ( null)),
10199
+ _nullishCoalesce(_optionalChain([this, 'access', _72 => _72.binArrayBitmapExtension, 'optionalAccess', _73 => _73.account]), () => ( null)),
10190
10200
  binArrays
10191
10201
  );
10192
10202
  if (binArrayAccountToSwap == null) {
@@ -10285,13 +10295,12 @@ var DLMM = class {
10285
10295
  let actualOutAmount = new (0, _anchor.BN)(0);
10286
10296
  let feeAmount = new (0, _anchor.BN)(0);
10287
10297
  let protocolFeeAmount = new (0, _anchor.BN)(0);
10288
- let lastFilledActiveBinId = activeId;
10289
10298
  while (!inAmountLeft.isZero()) {
10290
10299
  let binArrayAccountToSwap = findNextBinArrayWithLiquidity(
10291
10300
  swapForY,
10292
10301
  activeId,
10293
10302
  this.lbPair,
10294
- _nullishCoalesce(_optionalChain([this, 'access', _71 => _71.binArrayBitmapExtension, 'optionalAccess', _72 => _72.account]), () => ( null)),
10303
+ _nullishCoalesce(_optionalChain([this, 'access', _74 => _74.binArrayBitmapExtension, 'optionalAccess', _75 => _75.account]), () => ( null)),
10295
10304
  binArrays
10296
10305
  );
10297
10306
  if (binArrayAccountToSwap == null) {
@@ -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 (0, _decimaljs2.default)(actualOutAmount.toString()).sub(new (0, _decimaljs2.default)(outAmountWithoutSlippage.toString())).div(new (0, _decimaljs2.default)(outAmountWithoutSlippage.toString())).mul(new (0, _decimaljs2.default)(100));
10360
10368
  const minOutAmount = actualOutAmount.mul(new (0, _anchor.BN)(BASIS_POINT_MAX).sub(allowedSlippage)).div(new (0, _anchor.BN)(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: _spltoken.TOKEN_PROGRAM_ID,
10530
10542
  tokenYProgram: _spltoken.TOKEN_PROGRAM_ID,
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: _spltoken.TOKEN_PROGRAM_ID,
10620
10636
  // dont use 2022 first; lack familiarity
10621
10637
  tokenYProgram: _spltoken.TOKEN_PROGRAM_ID,
@@ -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 (0, _web3js.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
@@ -11485,7 +11486,7 @@ var DLMM = class {
11485
11486
  swapForY,
11486
11487
  new (0, _anchor.BN)(activeBinId),
11487
11488
  this.lbPair,
11488
- _nullishCoalesce(_optionalChain([this, 'access', _73 => _73.binArrayBitmapExtension, 'optionalAccess', _74 => _74.account]), () => ( null))
11489
+ _nullishCoalesce(_optionalChain([this, 'access', _76 => _76.binArrayBitmapExtension, 'optionalAccess', _77 => _77.account]), () => ( null))
11489
11490
  );
11490
11491
  if (toBinArrayIndex === null)
11491
11492
  return true;
@@ -11522,7 +11523,7 @@ var DLMM = class {
11522
11523
  swapForY,
11523
11524
  new (0, _anchor.BN)(activeBinId),
11524
11525
  this.lbPair,
11525
- _nullishCoalesce(_optionalChain([this, 'access', _75 => _75.binArrayBitmapExtension, 'optionalAccess', _76 => _76.account]), () => ( null))
11526
+ _nullishCoalesce(_optionalChain([this, 'access', _78 => _78.binArrayBitmapExtension, 'optionalAccess', _79 => _79.account]), () => ( null))
11526
11527
  );
11527
11528
  const accountsToFetch = [];
11528
11529
  const [binArrayBitMapExtensionPubkey] = deriveBinArrayBitmapExtension(
@@ -11553,13 +11554,13 @@ var DLMM = class {
11553
11554
  let fromBinArray = null;
11554
11555
  let toBinArray = null;
11555
11556
  let binArrayBitmapExtension = null;
11556
- if (!!_optionalChain([binArrayAccounts, 'optionalAccess', _77 => _77[0]])) {
11557
+ if (!!_optionalChain([binArrayAccounts, 'optionalAccess', _80 => _80[0]])) {
11557
11558
  binArrayBitmapExtension = binArrayBitMapExtensionPubkey;
11558
11559
  }
11559
- if (!!_optionalChain([binArrayAccounts, 'optionalAccess', _78 => _78[1]])) {
11560
+ if (!!_optionalChain([binArrayAccounts, 'optionalAccess', _81 => _81[1]])) {
11560
11561
  fromBinArray = fromBinArrayPubkey;
11561
11562
  }
11562
- if (!!_optionalChain([binArrayAccounts, 'optionalAccess', _79 => _79[2]]) && !!toBinArrayIndex) {
11563
+ if (!!_optionalChain([binArrayAccounts, 'optionalAccess', _82 => _82[2]]) && !!toBinArrayIndex) {
11563
11564
  toBinArray = toBinArrayPubkey;
11564
11565
  }
11565
11566
  const { blockhash, lastValidBlockHeight } = await this.program.provider.connection.getLatestBlockhash("confirmed");
@@ -11884,7 +11885,12 @@ var DLMM = class {
11884
11885
  let totalYAmount = new (0, _decimaljs2.default)(0);
11885
11886
  bins.forEach((bin, idx) => {
11886
11887
  const binSupply = new (0, _decimaljs2.default)(bin.supply.toString());
11887
- const posShare = new (0, _decimaljs2.default)(posShares[idx].toString());
11888
+ let posShare;
11889
+ if (bin.version === 1 && version === 0 /* V1 */) {
11890
+ posShare = new (0, _decimaljs2.default)(posShares[idx].shln(64).toString());
11891
+ } else {
11892
+ posShare = new (0, _decimaljs2.default)(posShares[idx].toString());
11893
+ }
11888
11894
  const positionXAmount = binSupply.eq(new (0, _decimaljs2.default)("0")) ? new (0, _decimaljs2.default)("0") : posShare.mul(bin.xAmount.toString()).div(binSupply);
11889
11895
  const positionYAmount = binSupply.eq(new (0, _decimaljs2.default)("0")) ? new (0, _decimaljs2.default)("0") : posShare.mul(bin.yAmount.toString()).div(binSupply);
11890
11896
  totalXAmount = totalXAmount.add(positionXAmount);
@@ -12035,7 +12041,7 @@ var DLMM = class {
12035
12041
  const [lowerBinId2] = getBinArrayLowerUpperBinId(index);
12036
12042
  return bins.map((b, i) => [lowerBinId2.toNumber() + i, b]);
12037
12043
  }));
12038
- const version = _nullishCoalesce(_optionalChain([binArrays, 'access', _80 => _80.find, 'call', _81 => _81((binArray) => binArray != null), 'optionalAccess', _82 => _82.version]), () => ( 1));
12044
+ const version = _nullishCoalesce(_optionalChain([binArrays, 'access', _83 => _83.find, 'call', _84 => _84((binArray) => binArray != null), 'optionalAccess', _85 => _85.version]), () => ( 1));
12039
12045
  return Array.from(enumerateBins(
12040
12046
  binsById,
12041
12047
  lowerBinId,
@@ -12328,5 +12334,6 @@ var src_default = DLMM;
12328
12334
 
12329
12335
 
12330
12336
 
12331
- exports.ADMIN = ADMIN; exports.ActivationType = ActivationType; exports.BASIS_POINT_MAX = BASIS_POINT_MAX; exports.BIN_ARRAY_BITMAP_SIZE = BIN_ARRAY_BITMAP_SIZE; exports.BIN_ARRAY_FEE = BIN_ARRAY_FEE; exports.BinLiquidity = BinLiquidity; exports.BitmapType = BitmapType; exports.ClockLayout = ClockLayout; exports.DLMMError = DLMMError; exports.DlmmSdkError = DlmmSdkError; exports.EXTENSION_BINARRAY_BITMAP_SIZE = EXTENSION_BINARRAY_BITMAP_SIZE; exports.FEE_PRECISION = FEE_PRECISION; exports.IDL = IDL; exports.ILM_BASE = ILM_BASE; exports.LBCLMM_PROGRAM_IDS = LBCLMM_PROGRAM_IDS; exports.MAX_ACTIVE_BIN_SLIPPAGE = MAX_ACTIVE_BIN_SLIPPAGE; exports.MAX_BIN_ARRAY_SIZE = MAX_BIN_ARRAY_SIZE; exports.MAX_BIN_LENGTH_ALLOWED_IN_ONE_TX = MAX_BIN_LENGTH_ALLOWED_IN_ONE_TX; exports.MAX_BIN_PER_POSITION = MAX_BIN_PER_POSITION; exports.MAX_BIN_PER_TX = MAX_BIN_PER_TX; exports.MAX_CLAIM_ALL_ALLOWED = MAX_CLAIM_ALL_ALLOWED; exports.MAX_FEE_RATE = MAX_FEE_RATE; exports.Network = Network; exports.POSITION_FEE = POSITION_FEE; exports.PRECISION = PRECISION; exports.PairStatus = PairStatus; exports.PairType = PairType; exports.PositionVersion = PositionVersion; exports.SCALE = SCALE; exports.SCALE_OFFSET = SCALE_OFFSET; exports.SIMULATION_USER = SIMULATION_USER; exports.Strategy = Strategy; exports.StrategyType = StrategyType; exports.autoFillXByStrategy = autoFillXByStrategy; exports.autoFillXByWeight = autoFillXByWeight; exports.autoFillYByStrategy = autoFillYByStrategy; exports.autoFillYByWeight = autoFillYByWeight; exports.binIdToBinArrayIndex = binIdToBinArrayIndex; exports.calculateBidAskDistribution = calculateBidAskDistribution; exports.calculateNormalDistribution = calculateNormalDistribution; exports.calculateSpotDistribution = calculateSpotDistribution; exports.chunkedFetchMultipleBinArrayBitmapExtensionAccount = chunkedFetchMultipleBinArrayBitmapExtensionAccount; exports.chunkedFetchMultiplePoolAccount = chunkedFetchMultiplePoolAccount; exports.chunkedGetMultipleAccountInfos = chunkedGetMultipleAccountInfos; exports.chunks = chunks; exports.computeFee = computeFee; exports.computeFeeFromAmount = computeFeeFromAmount; exports.computeProtocolFee = computeProtocolFee; exports.default = src_default; exports.deriveBinArray = deriveBinArray; exports.deriveBinArrayBitmapExtension = deriveBinArrayBitmapExtension; exports.deriveCustomizablePermissionlessLbPair = deriveCustomizablePermissionlessLbPair; exports.deriveLbPair = deriveLbPair; exports.deriveLbPair2 = deriveLbPair2; exports.deriveOracle = deriveOracle; exports.derivePermissionLbPair = derivePermissionLbPair; exports.derivePosition = derivePosition; exports.derivePresetParameter = derivePresetParameter; exports.derivePresetParameter2 = derivePresetParameter2; exports.deriveReserve = deriveReserve; exports.enumerateBins = enumerateBins; exports.findNextBinArrayIndexWithLiquidity = findNextBinArrayIndexWithLiquidity; exports.findNextBinArrayWithLiquidity = findNextBinArrayWithLiquidity; exports.fromWeightDistributionToAmount = fromWeightDistributionToAmount; exports.fromWeightDistributionToAmountOneSide = fromWeightDistributionToAmountOneSide; exports.getBaseFee = getBaseFee; exports.getBinArrayLowerUpperBinId = getBinArrayLowerUpperBinId; exports.getBinArraysRequiredByPositionRange = getBinArraysRequiredByPositionRange; exports.getBinFromBinArray = getBinFromBinArray; exports.getEstimatedComputeUnitIxWithBuffer = getEstimatedComputeUnitIxWithBuffer; exports.getEstimatedComputeUnitUsageWithBuffer = getEstimatedComputeUnitUsageWithBuffer; exports.getOrCreateATAInstruction = getOrCreateATAInstruction; exports.getOutAmount = getOutAmount; exports.getPriceOfBinByBinId = getPriceOfBinByBinId; exports.getTokenBalance = getTokenBalance; exports.getTokenDecimals = getTokenDecimals; exports.getTokensMintFromPoolAddress = getTokensMintFromPoolAddress; exports.getTotalFee = getTotalFee; exports.getVariableFee = getVariableFee; exports.isBinIdWithinBinArray = isBinIdWithinBinArray; exports.isOverflowDefaultBinArrayBitmap = isOverflowDefaultBinArrayBitmap; exports.parseLogs = parseLogs; exports.range = range; exports.swapExactInQuoteAtBin = swapExactInQuoteAtBin; exports.swapExactOutQuoteAtBin = swapExactOutQuoteAtBin; exports.toAmountAskSide = toAmountAskSide; exports.toAmountBidSide = toAmountBidSide; exports.toAmountBothSide = toAmountBothSide; exports.toAmountsBothSideByStrategy = toAmountsBothSideByStrategy; exports.toStrategyParameters = toStrategyParameters; exports.toWeightDistribution = toWeightDistribution; exports.unwrapSOLInstruction = unwrapSOLInstruction; exports.wrapSOLInstruction = wrapSOLInstruction;
12337
+
12338
+ exports.ADMIN = ADMIN; exports.ActivationType = ActivationType; exports.BASIS_POINT_MAX = BASIS_POINT_MAX; exports.BIN_ARRAY_BITMAP_SIZE = BIN_ARRAY_BITMAP_SIZE; exports.BIN_ARRAY_FEE = BIN_ARRAY_FEE; exports.BinLiquidity = BinLiquidity; exports.BitmapType = BitmapType; exports.ClockLayout = ClockLayout; exports.DLMMError = DLMMError; exports.DlmmSdkError = DlmmSdkError; exports.EXTENSION_BINARRAY_BITMAP_SIZE = EXTENSION_BINARRAY_BITMAP_SIZE; exports.FEE_PRECISION = FEE_PRECISION; exports.IDL = IDL; exports.ILM_BASE = ILM_BASE; exports.LBCLMM_PROGRAM_IDS = LBCLMM_PROGRAM_IDS; exports.MAX_ACTIVE_BIN_SLIPPAGE = MAX_ACTIVE_BIN_SLIPPAGE; exports.MAX_BIN_ARRAY_SIZE = MAX_BIN_ARRAY_SIZE; exports.MAX_BIN_LENGTH_ALLOWED_IN_ONE_TX = MAX_BIN_LENGTH_ALLOWED_IN_ONE_TX; exports.MAX_BIN_PER_POSITION = MAX_BIN_PER_POSITION; exports.MAX_BIN_PER_TX = MAX_BIN_PER_TX; exports.MAX_CLAIM_ALL_ALLOWED = MAX_CLAIM_ALL_ALLOWED; exports.MAX_FEE_RATE = MAX_FEE_RATE; exports.Network = Network; exports.POSITION_FEE = POSITION_FEE; exports.PRECISION = PRECISION; exports.PairStatus = PairStatus; exports.PairType = PairType; exports.PositionVersion = PositionVersion; exports.SCALE = SCALE; exports.SCALE_OFFSET = SCALE_OFFSET; exports.SIMULATION_USER = SIMULATION_USER; exports.Strategy = Strategy; exports.StrategyType = StrategyType; exports.autoFillXByStrategy = autoFillXByStrategy; exports.autoFillXByWeight = autoFillXByWeight; exports.autoFillYByStrategy = autoFillYByStrategy; exports.autoFillYByWeight = autoFillYByWeight; exports.binIdToBinArrayIndex = binIdToBinArrayIndex; exports.calculateBidAskDistribution = calculateBidAskDistribution; exports.calculateNormalDistribution = calculateNormalDistribution; exports.calculateSpotDistribution = calculateSpotDistribution; exports.chunkedFetchMultipleBinArrayBitmapExtensionAccount = chunkedFetchMultipleBinArrayBitmapExtensionAccount; exports.chunkedFetchMultiplePoolAccount = chunkedFetchMultiplePoolAccount; exports.chunkedGetMultipleAccountInfos = chunkedGetMultipleAccountInfos; exports.chunks = chunks; exports.computeFee = computeFee; exports.computeFeeFromAmount = computeFeeFromAmount; exports.computeProtocolFee = computeProtocolFee; exports.default = src_default; exports.deriveBinArray = deriveBinArray; exports.deriveBinArrayBitmapExtension = deriveBinArrayBitmapExtension; exports.deriveCustomizablePermissionlessLbPair = deriveCustomizablePermissionlessLbPair; exports.deriveLbPair = deriveLbPair; exports.deriveLbPair2 = deriveLbPair2; exports.deriveOracle = deriveOracle; exports.derivePermissionLbPair = derivePermissionLbPair; exports.derivePosition = derivePosition; exports.derivePresetParameter = derivePresetParameter; exports.derivePresetParameter2 = derivePresetParameter2; exports.deriveReserve = deriveReserve; exports.enumerateBins = enumerateBins; exports.findNextBinArrayIndexWithLiquidity = findNextBinArrayIndexWithLiquidity; exports.findNextBinArrayWithLiquidity = findNextBinArrayWithLiquidity; exports.fromWeightDistributionToAmount = fromWeightDistributionToAmount; exports.fromWeightDistributionToAmountOneSide = fromWeightDistributionToAmountOneSide; exports.getBaseFee = getBaseFee; exports.getBinArrayLowerUpperBinId = getBinArrayLowerUpperBinId; exports.getBinArraysRequiredByPositionRange = getBinArraysRequiredByPositionRange; exports.getBinFromBinArray = getBinFromBinArray; exports.getEstimatedComputeUnitIxWithBuffer = getEstimatedComputeUnitIxWithBuffer; exports.getEstimatedComputeUnitUsageWithBuffer = getEstimatedComputeUnitUsageWithBuffer; exports.getOrCreateATAInstruction = getOrCreateATAInstruction; exports.getOutAmount = getOutAmount; exports.getPriceOfBinByBinId = getPriceOfBinByBinId; exports.getTokenBalance = getTokenBalance; exports.getTokenDecimals = getTokenDecimals; exports.getTokensMintFromPoolAddress = getTokensMintFromPoolAddress; exports.getTotalFee = getTotalFee; exports.getVariableFee = getVariableFee; exports.isBinIdWithinBinArray = isBinIdWithinBinArray; exports.isOverflowDefaultBinArrayBitmap = isOverflowDefaultBinArrayBitmap; exports.parseLogs = parseLogs; exports.range = range; exports.swapExactInQuoteAtBin = swapExactInQuoteAtBin; exports.swapExactOutQuoteAtBin = swapExactOutQuoteAtBin; exports.toAmountAskSide = toAmountAskSide; exports.toAmountBidSide = toAmountBidSide; exports.toAmountBothSide = toAmountBothSide; exports.toAmountsBothSideByStrategy = toAmountsBothSideByStrategy; exports.toAmountsOneSideByStrategy = toAmountsOneSideByStrategy; exports.toStrategyParameters = toStrategyParameters; exports.toWeightDistribution = toWeightDistribution; exports.unwrapSOLInstruction = unwrapSOLInstruction; exports.wrapSOLInstruction = wrapSOLInstruction;
12332
12339
  //# sourceMappingURL=index.js.map