@meteora-ag/dlmm 1.5.3 → 1.5.5

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
@@ -9910,6 +9910,131 @@ function getTokenProgramId(lbPairState) {
9910
9910
  };
9911
9911
  }
9912
9912
 
9913
+ // src/dlmm/helpers/positions/index.ts
9914
+ import BN12 from "bn.js";
9915
+
9916
+ // src/dlmm/helpers/positions/wrapper.ts
9917
+ import BN11 from "bn.js";
9918
+ function wrapPosition(program, key, account) {
9919
+ const disc = account.data.subarray(0, 8);
9920
+ if (disc.equals(POSITION_V2_DISC)) {
9921
+ const state = program.coder.accounts.decode(
9922
+ program.account.positionV2.idlAccount.name,
9923
+ account.data
9924
+ );
9925
+ return new PositionV2Wrapper(key, state);
9926
+ } else {
9927
+ throw new Error("Unknown position account");
9928
+ }
9929
+ }
9930
+ var PositionV2Wrapper = class {
9931
+ constructor(positionAddress, inner) {
9932
+ this.positionAddress = positionAddress;
9933
+ this.inner = inner;
9934
+ }
9935
+ address() {
9936
+ return this.positionAddress;
9937
+ }
9938
+ totalClaimedRewards() {
9939
+ return this.inner.totalClaimedRewards;
9940
+ }
9941
+ feeOwner() {
9942
+ return this.inner.feeOwner;
9943
+ }
9944
+ lockReleasePoint() {
9945
+ return this.inner.lockReleasePoint;
9946
+ }
9947
+ operator() {
9948
+ return this.inner.operator;
9949
+ }
9950
+ totalClaimedFeeYAmount() {
9951
+ return this.inner.totalClaimedFeeYAmount;
9952
+ }
9953
+ totalClaimedFeeXAmount() {
9954
+ return this.inner.totalClaimedFeeXAmount;
9955
+ }
9956
+ lbPair() {
9957
+ return this.inner.lbPair;
9958
+ }
9959
+ lowerBinId() {
9960
+ return new BN11(this.inner.lowerBinId);
9961
+ }
9962
+ upperBinId() {
9963
+ return new BN11(this.inner.upperBinId);
9964
+ }
9965
+ liquidityShares() {
9966
+ return this.inner.liquidityShares;
9967
+ }
9968
+ rewardInfos() {
9969
+ return this.inner.rewardInfos;
9970
+ }
9971
+ feeInfos() {
9972
+ return this.inner.feeInfos;
9973
+ }
9974
+ lastUpdatedAt() {
9975
+ return this.inner.lastUpdatedAt;
9976
+ }
9977
+ getBinArrayIndexesCoverage() {
9978
+ const lowerBinArrayIndex = binIdToBinArrayIndex(this.lowerBinId());
9979
+ const upperBinArrayIndex = lowerBinArrayIndex.add(new BN11(1));
9980
+ return [lowerBinArrayIndex, upperBinArrayIndex];
9981
+ }
9982
+ getBinArrayKeysCoverage(programId) {
9983
+ return this.getBinArrayIndexesCoverage().map(
9984
+ (index) => deriveBinArray(this.lbPair(), index, programId)[0]
9985
+ );
9986
+ }
9987
+ version() {
9988
+ return 1 /* V2 */;
9989
+ }
9990
+ owner() {
9991
+ return this.inner.owner;
9992
+ }
9993
+ };
9994
+
9995
+ // src/dlmm/helpers/positions/index.ts
9996
+ function getBinArrayIndexesCoverage(lowerBinId, upperBinId) {
9997
+ const lowerBinArrayIndex = binIdToBinArrayIndex(lowerBinId);
9998
+ const upperBinArrayIndex = binIdToBinArrayIndex(upperBinId);
9999
+ const binArrayIndexes = [];
10000
+ for (let i = lowerBinArrayIndex.toNumber(); i <= upperBinArrayIndex.toNumber(); i++) {
10001
+ binArrayIndexes.push(new BN12(i));
10002
+ }
10003
+ return binArrayIndexes;
10004
+ }
10005
+ function getBinArrayKeysCoverage(lowerBinId, upperBinId, lbPair, programId) {
10006
+ const binArrayIndexes = getBinArrayIndexesCoverage(lowerBinId, upperBinId);
10007
+ return binArrayIndexes.map((index) => {
10008
+ return deriveBinArray(lbPair, index, programId)[0];
10009
+ });
10010
+ }
10011
+ function getBinArrayAccountMetasCoverage(lowerBinId, upperBinId, lbPair, programId) {
10012
+ return getBinArrayKeysCoverage(lowerBinId, upperBinId, lbPair, programId).map(
10013
+ (key) => {
10014
+ return {
10015
+ pubkey: key,
10016
+ isSigner: false,
10017
+ isWritable: true
10018
+ };
10019
+ }
10020
+ );
10021
+ }
10022
+ function getPositionLowerUpperBinIdWithLiquidity(position) {
10023
+ const binWithLiquidity = position.positionBinData.filter(
10024
+ (b) => !new BN12(b.binLiquidity).isZero()
10025
+ );
10026
+ return binWithLiquidity.length > 0 ? {
10027
+ lowerBinId: new BN12(binWithLiquidity[0].binId),
10028
+ upperBinId: new BN12(binWithLiquidity[binWithLiquidity.length - 1].binId)
10029
+ } : null;
10030
+ }
10031
+ function isPositionNoFee(position) {
10032
+ return position.feeX.isZero() && position.feeY.isZero();
10033
+ }
10034
+ function isPositionNoReward(position) {
10035
+ return position.rewardOne.isZero() && position.rewardTwo.isZero();
10036
+ }
10037
+
9913
10038
  // src/dlmm/helpers/index.ts
9914
10039
  function chunks(array, size) {
9915
10040
  return Array.apply(0, new Array(Math.ceil(array.length / size))).map(
@@ -10114,122 +10239,6 @@ var positionLbPairFilter = (lbPair) => {
10114
10239
  };
10115
10240
  };
10116
10241
 
10117
- // src/dlmm/helpers/positions/index.ts
10118
- import BN12 from "bn.js";
10119
-
10120
- // src/dlmm/helpers/positions/wrapper.ts
10121
- import BN11 from "bn.js";
10122
- function wrapPosition(program, key, account) {
10123
- const disc = account.data.subarray(0, 8);
10124
- if (disc.equals(POSITION_V2_DISC)) {
10125
- const state = program.coder.accounts.decode(
10126
- program.account.positionV2.idlAccount.name,
10127
- account.data
10128
- );
10129
- return new PositionV2Wrapper(key, state);
10130
- } else {
10131
- throw new Error("Unknown position account");
10132
- }
10133
- }
10134
- var PositionV2Wrapper = class {
10135
- constructor(positionAddress, inner) {
10136
- this.positionAddress = positionAddress;
10137
- this.inner = inner;
10138
- }
10139
- address() {
10140
- return this.positionAddress;
10141
- }
10142
- totalClaimedRewards() {
10143
- return this.inner.totalClaimedRewards;
10144
- }
10145
- feeOwner() {
10146
- return this.inner.feeOwner;
10147
- }
10148
- lockReleasePoint() {
10149
- return this.inner.lockReleasePoint;
10150
- }
10151
- operator() {
10152
- return this.inner.operator;
10153
- }
10154
- totalClaimedFeeYAmount() {
10155
- return this.inner.totalClaimedFeeYAmount;
10156
- }
10157
- totalClaimedFeeXAmount() {
10158
- return this.inner.totalClaimedFeeXAmount;
10159
- }
10160
- lbPair() {
10161
- return this.inner.lbPair;
10162
- }
10163
- lowerBinId() {
10164
- return new BN11(this.inner.lowerBinId);
10165
- }
10166
- upperBinId() {
10167
- return new BN11(this.inner.upperBinId);
10168
- }
10169
- liquidityShares() {
10170
- return this.inner.liquidityShares;
10171
- }
10172
- rewardInfos() {
10173
- return this.inner.rewardInfos;
10174
- }
10175
- feeInfos() {
10176
- return this.inner.feeInfos;
10177
- }
10178
- lastUpdatedAt() {
10179
- return this.inner.lastUpdatedAt;
10180
- }
10181
- getBinArrayIndexesCoverage() {
10182
- const lowerBinArrayIndex = binIdToBinArrayIndex(this.lowerBinId());
10183
- const upperBinArrayIndex = lowerBinArrayIndex.add(new BN11(1));
10184
- return [lowerBinArrayIndex, upperBinArrayIndex];
10185
- }
10186
- getBinArrayKeysCoverage(programId) {
10187
- return this.getBinArrayIndexesCoverage().map(
10188
- (index) => deriveBinArray(this.lbPair(), index, programId)[0]
10189
- );
10190
- }
10191
- version() {
10192
- return 1 /* V2 */;
10193
- }
10194
- owner() {
10195
- return this.inner.owner;
10196
- }
10197
- };
10198
-
10199
- // src/dlmm/helpers/positions/index.ts
10200
- function getBinArrayIndexesCoverage(lowerBinId, upperBinId) {
10201
- const lowerBinArrayIndex = binIdToBinArrayIndex(lowerBinId);
10202
- const upperBinArrayIndex = binIdToBinArrayIndex(upperBinId);
10203
- const binArrayIndexes = [];
10204
- for (let i = lowerBinArrayIndex.toNumber(); i <= upperBinArrayIndex.toNumber(); i++) {
10205
- binArrayIndexes.push(new BN12(i));
10206
- }
10207
- return binArrayIndexes;
10208
- }
10209
- function getBinArrayKeysCoverage(lowerBinId, upperBinId, lbPair, programId) {
10210
- const binArrayIndexes = getBinArrayIndexesCoverage(lowerBinId, upperBinId);
10211
- return binArrayIndexes.map((index) => {
10212
- return deriveBinArray(lbPair, index, programId)[0];
10213
- });
10214
- }
10215
- function getBinArrayAccountMetasCoverage(lowerBinId, upperBinId, lbPair, programId) {
10216
- return getBinArrayKeysCoverage(lowerBinId, upperBinId, lbPair, programId).map(
10217
- (key) => {
10218
- return {
10219
- pubkey: key,
10220
- isSigner: false,
10221
- isWritable: true
10222
- };
10223
- }
10224
- );
10225
- }
10226
- function isPositionNoFee(position) {
10227
- return position.feeX.isZero() && position.feeY.isZero();
10228
- }
10229
- function isPositionNoReward(position) {
10230
- return position.rewardOne.isZero() && position.rewardTwo.isZero();
10231
- }
10232
-
10233
10242
  // src/dlmm/index.ts
10234
10243
  import { bs58 as bs582 } from "@coral-xyz/anchor/dist/cjs/utils/bytes";
10235
10244
  var DLMM = class {
@@ -13320,7 +13329,7 @@ var DLMM = class {
13320
13329
  ),
13321
13330
  swapForY
13322
13331
  );
13323
- const priceImpact = new Decimal6(totalOutAmount.toString()).sub(new Decimal6(outAmountWithoutSlippage.toString())).div(new Decimal6(outAmountWithoutSlippage.toString())).mul(new Decimal6(100));
13332
+ const priceImpact = new Decimal6(totalOutAmount.toString()).sub(new Decimal6(outAmountWithoutSlippage.toString())).div(new Decimal6(outAmountWithoutSlippage.toString())).mul(new Decimal6(100)).abs();
13324
13333
  const endPrice = getPriceOfBinByBinId(
13325
13334
  lastFilledActiveBinId.toNumber(),
13326
13335
  this.lbPair.binStep
@@ -15338,6 +15347,7 @@ export {
15338
15347
  PRECISION,
15339
15348
  PairStatus,
15340
15349
  PairType,
15350
+ PositionV2Wrapper,
15341
15351
  PositionVersion,
15342
15352
  SCALE,
15343
15353
  SCALE_OFFSET,
@@ -15385,6 +15395,9 @@ export {
15385
15395
  fromWeightDistributionToAmount,
15386
15396
  fromWeightDistributionToAmountOneSide,
15387
15397
  getBaseFee,
15398
+ getBinArrayAccountMetasCoverage,
15399
+ getBinArrayIndexesCoverage,
15400
+ getBinArrayKeysCoverage,
15388
15401
  getBinArrayLowerUpperBinId,
15389
15402
  getBinArraysRequiredByPositionRange,
15390
15403
  getBinFromBinArray,
@@ -15392,6 +15405,7 @@ export {
15392
15405
  getEstimatedComputeUnitUsageWithBuffer,
15393
15406
  getOrCreateATAInstruction,
15394
15407
  getOutAmount,
15408
+ getPositionLowerUpperBinIdWithLiquidity,
15395
15409
  getPriceOfBinByBinId,
15396
15410
  getTokenBalance,
15397
15411
  getTokenDecimals,
@@ -15401,6 +15415,8 @@ export {
15401
15415
  getVariableFee,
15402
15416
  isBinIdWithinBinArray,
15403
15417
  isOverflowDefaultBinArrayBitmap,
15418
+ isPositionNoFee,
15419
+ isPositionNoReward,
15404
15420
  parseLogs,
15405
15421
  range,
15406
15422
  swapExactInQuoteAtBin,
@@ -15412,6 +15428,7 @@ export {
15412
15428
  toStrategyParameters,
15413
15429
  toWeightDistribution,
15414
15430
  unwrapSOLInstruction,
15431
+ wrapPosition,
15415
15432
  wrapSOLInstruction
15416
15433
  };
15417
15434
  //# sourceMappingURL=index.mjs.map