@meteora-ag/dlmm 1.0.28-rc.0 → 1.0.28

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/README.md CHANGED
@@ -231,7 +231,6 @@ try {
231
231
  | `claimSwapFee` | Claim swap fees for a specific position owned by a specific owner | `Promise<Transaction>` |
232
232
  | `claimAllSwapFee` | Claim swap fees for multiple positions owned by a specific owner | `Promise<Transaction>` |
233
233
  | `claimAllRewards` | Claim swap fees and LM rewards for multiple positions owned by a specific owner | `Promise<Transaction[]>` |
234
- | `syncWithMarketPrice` | Sync the pool current active bin to match nearest market price bin | `Promise<Transaction>` |
235
234
 
236
235
  ```
237
236
 
package/dist/index.d.ts CHANGED
@@ -5,7 +5,7 @@ import { PublicKey, TransactionInstruction, Connection, Transaction, Cluster } f
5
5
  import Decimal from 'decimal.js';
6
6
 
7
7
  type LbClmm = {
8
- version: "0.5.1";
8
+ version: "0.5.0";
9
9
  name: "lb_clmm";
10
10
  constants: [
11
11
  {
@@ -2285,124 +2285,6 @@ type LbClmm = {
2285
2285
  type: "u16";
2286
2286
  }
2287
2287
  ];
2288
- },
2289
- {
2290
- name: "addLiquidityOneSidePrecise";
2291
- accounts: [
2292
- {
2293
- name: "position";
2294
- isMut: true;
2295
- isSigner: false;
2296
- },
2297
- {
2298
- name: "lbPair";
2299
- isMut: true;
2300
- isSigner: false;
2301
- },
2302
- {
2303
- name: "binArrayBitmapExtension";
2304
- isMut: true;
2305
- isSigner: false;
2306
- isOptional: true;
2307
- },
2308
- {
2309
- name: "userToken";
2310
- isMut: true;
2311
- isSigner: false;
2312
- },
2313
- {
2314
- name: "reserve";
2315
- isMut: true;
2316
- isSigner: false;
2317
- },
2318
- {
2319
- name: "tokenMint";
2320
- isMut: false;
2321
- isSigner: false;
2322
- },
2323
- {
2324
- name: "binArrayLower";
2325
- isMut: true;
2326
- isSigner: false;
2327
- },
2328
- {
2329
- name: "binArrayUpper";
2330
- isMut: true;
2331
- isSigner: false;
2332
- },
2333
- {
2334
- name: "sender";
2335
- isMut: false;
2336
- isSigner: true;
2337
- },
2338
- {
2339
- name: "tokenProgram";
2340
- isMut: false;
2341
- isSigner: false;
2342
- },
2343
- {
2344
- name: "eventAuthority";
2345
- isMut: false;
2346
- isSigner: false;
2347
- },
2348
- {
2349
- name: "program";
2350
- isMut: false;
2351
- isSigner: false;
2352
- }
2353
- ];
2354
- args: [
2355
- {
2356
- name: "parameter";
2357
- type: {
2358
- defined: "AddLiquiditySingleSidePreciseParameter";
2359
- };
2360
- }
2361
- ];
2362
- },
2363
- {
2364
- name: "goToABin";
2365
- accounts: [
2366
- {
2367
- name: "lbPair";
2368
- isMut: true;
2369
- isSigner: false;
2370
- },
2371
- {
2372
- name: "binArrayBitmapExtension";
2373
- isMut: false;
2374
- isSigner: false;
2375
- isOptional: true;
2376
- },
2377
- {
2378
- name: "fromBinArray";
2379
- isMut: false;
2380
- isSigner: false;
2381
- isOptional: true;
2382
- },
2383
- {
2384
- name: "toBinArray";
2385
- isMut: false;
2386
- isSigner: false;
2387
- isOptional: true;
2388
- },
2389
- {
2390
- name: "eventAuthority";
2391
- isMut: false;
2392
- isSigner: false;
2393
- },
2394
- {
2395
- name: "program";
2396
- isMut: false;
2397
- isSigner: false;
2398
- }
2399
- ];
2400
- args: [
2401
- {
2402
- name: "binId";
2403
- type: "i32";
2404
- }
2405
- ];
2406
2288
  }
2407
2289
  ];
2408
2290
  accounts: [
@@ -3155,42 +3037,6 @@ type LbClmm = {
3155
3037
  ];
3156
3038
  };
3157
3039
  },
3158
- {
3159
- name: "AddLiquiditySingleSidePreciseParameter";
3160
- type: {
3161
- kind: "struct";
3162
- fields: [
3163
- {
3164
- name: "bins";
3165
- type: {
3166
- vec: {
3167
- defined: "CompressedBinDepositAmount";
3168
- };
3169
- };
3170
- },
3171
- {
3172
- name: "decompressMultiplier";
3173
- type: "u64";
3174
- }
3175
- ];
3176
- };
3177
- },
3178
- {
3179
- name: "CompressedBinDepositAmount";
3180
- type: {
3181
- kind: "struct";
3182
- fields: [
3183
- {
3184
- name: "binId";
3185
- type: "i32";
3186
- },
3187
- {
3188
- name: "amount";
3189
- type: "u32";
3190
- }
3191
- ];
3192
- };
3193
- },
3194
3040
  {
3195
3041
  name: "BinLiquidityDistribution";
3196
3042
  type: {
@@ -4303,26 +4149,6 @@ type LbClmm = {
4303
4149
  index: false;
4304
4150
  }
4305
4151
  ];
4306
- },
4307
- {
4308
- name: "GoToABin";
4309
- fields: [
4310
- {
4311
- name: "lbPair";
4312
- type: "publicKey";
4313
- index: false;
4314
- },
4315
- {
4316
- name: "fromBinId";
4317
- type: "i32";
4318
- index: false;
4319
- },
4320
- {
4321
- name: "toBinId";
4322
- type: "i32";
4323
- index: false;
4324
- }
4325
- ];
4326
4152
  }
4327
4153
  ];
4328
4154
  errors: [
@@ -4615,11 +4441,6 @@ type LbClmm = {
4615
4441
  code: 6057;
4616
4442
  name: "InvalidLockReleaseSlot";
4617
4443
  msg: "Invalid lock release slot";
4618
- },
4619
- {
4620
- code: 6058;
4621
- name: "BinRangeIsNotEmpty";
4622
- msg: "Bin range is not empty";
4623
4444
  }
4624
4445
  ];
4625
4446
  };
@@ -5266,7 +5087,6 @@ declare class DLMM {
5266
5087
  owner: PublicKey;
5267
5088
  positions: LbPosition[];
5268
5089
  }): Promise<Transaction[]>;
5269
- syncWithMarketPrice(marketPrice: number, owner: PublicKey): Promise<Transaction>;
5270
5090
  /** Private static method */
5271
5091
  private static getBinArrays;
5272
5092
  private static getClaimableLMReward;
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ var _web3js = require('@solana/web3.js');
9
9
 
10
10
  // src/dlmm/idl.ts
11
11
  var IDL = {
12
- version: "0.5.1",
12
+ version: "0.5.0",
13
13
  name: "lb_clmm",
14
14
  constants: [
15
15
  {
@@ -2289,124 +2289,6 @@ var IDL = {
2289
2289
  type: "u16"
2290
2290
  }
2291
2291
  ]
2292
- },
2293
- {
2294
- name: "addLiquidityOneSidePrecise",
2295
- accounts: [
2296
- {
2297
- name: "position",
2298
- isMut: true,
2299
- isSigner: false
2300
- },
2301
- {
2302
- name: "lbPair",
2303
- isMut: true,
2304
- isSigner: false
2305
- },
2306
- {
2307
- name: "binArrayBitmapExtension",
2308
- isMut: true,
2309
- isSigner: false,
2310
- isOptional: true
2311
- },
2312
- {
2313
- name: "userToken",
2314
- isMut: true,
2315
- isSigner: false
2316
- },
2317
- {
2318
- name: "reserve",
2319
- isMut: true,
2320
- isSigner: false
2321
- },
2322
- {
2323
- name: "tokenMint",
2324
- isMut: false,
2325
- isSigner: false
2326
- },
2327
- {
2328
- name: "binArrayLower",
2329
- isMut: true,
2330
- isSigner: false
2331
- },
2332
- {
2333
- name: "binArrayUpper",
2334
- isMut: true,
2335
- isSigner: false
2336
- },
2337
- {
2338
- name: "sender",
2339
- isMut: false,
2340
- isSigner: true
2341
- },
2342
- {
2343
- name: "tokenProgram",
2344
- isMut: false,
2345
- isSigner: false
2346
- },
2347
- {
2348
- name: "eventAuthority",
2349
- isMut: false,
2350
- isSigner: false
2351
- },
2352
- {
2353
- name: "program",
2354
- isMut: false,
2355
- isSigner: false
2356
- }
2357
- ],
2358
- args: [
2359
- {
2360
- name: "parameter",
2361
- type: {
2362
- defined: "AddLiquiditySingleSidePreciseParameter"
2363
- }
2364
- }
2365
- ]
2366
- },
2367
- {
2368
- name: "goToABin",
2369
- accounts: [
2370
- {
2371
- name: "lbPair",
2372
- isMut: true,
2373
- isSigner: false
2374
- },
2375
- {
2376
- name: "binArrayBitmapExtension",
2377
- isMut: false,
2378
- isSigner: false,
2379
- isOptional: true
2380
- },
2381
- {
2382
- name: "fromBinArray",
2383
- isMut: false,
2384
- isSigner: false,
2385
- isOptional: true
2386
- },
2387
- {
2388
- name: "toBinArray",
2389
- isMut: false,
2390
- isSigner: false,
2391
- isOptional: true
2392
- },
2393
- {
2394
- name: "eventAuthority",
2395
- isMut: false,
2396
- isSigner: false
2397
- },
2398
- {
2399
- name: "program",
2400
- isMut: false,
2401
- isSigner: false
2402
- }
2403
- ],
2404
- args: [
2405
- {
2406
- name: "binId",
2407
- type: "i32"
2408
- }
2409
- ]
2410
2292
  }
2411
2293
  ],
2412
2294
  accounts: [
@@ -3159,42 +3041,6 @@ var IDL = {
3159
3041
  ]
3160
3042
  }
3161
3043
  },
3162
- {
3163
- name: "AddLiquiditySingleSidePreciseParameter",
3164
- type: {
3165
- kind: "struct",
3166
- fields: [
3167
- {
3168
- name: "bins",
3169
- type: {
3170
- vec: {
3171
- defined: "CompressedBinDepositAmount"
3172
- }
3173
- }
3174
- },
3175
- {
3176
- name: "decompressMultiplier",
3177
- type: "u64"
3178
- }
3179
- ]
3180
- }
3181
- },
3182
- {
3183
- name: "CompressedBinDepositAmount",
3184
- type: {
3185
- kind: "struct",
3186
- fields: [
3187
- {
3188
- name: "binId",
3189
- type: "i32"
3190
- },
3191
- {
3192
- name: "amount",
3193
- type: "u32"
3194
- }
3195
- ]
3196
- }
3197
- },
3198
3044
  {
3199
3045
  name: "BinLiquidityDistribution",
3200
3046
  type: {
@@ -4307,26 +4153,6 @@ var IDL = {
4307
4153
  index: false
4308
4154
  }
4309
4155
  ]
4310
- },
4311
- {
4312
- name: "GoToABin",
4313
- fields: [
4314
- {
4315
- name: "lbPair",
4316
- type: "publicKey",
4317
- index: false
4318
- },
4319
- {
4320
- name: "fromBinId",
4321
- type: "i32",
4322
- index: false
4323
- },
4324
- {
4325
- name: "toBinId",
4326
- type: "i32",
4327
- index: false
4328
- }
4329
- ]
4330
4156
  }
4331
4157
  ],
4332
4158
  errors: [
@@ -4619,11 +4445,6 @@ var IDL = {
4619
4445
  code: 6057,
4620
4446
  name: "InvalidLockReleaseSlot",
4621
4447
  msg: "Invalid lock release slot"
4622
- },
4623
- {
4624
- code: 6058,
4625
- name: "BinRangeIsNotEmpty",
4626
- msg: "Bin range is not empty"
4627
4448
  }
4628
4449
  ]
4629
4450
  };
@@ -5165,7 +4986,7 @@ function findNextBinArrayIndexWithLiquidity(swapForY, activeId, lbPairState, bin
5165
4986
  maxBinArrayIndex.toNumber(),
5166
4987
  binArrayBitmapExtension
5167
4988
  );
5168
- if (binArrayIndex !== null) {
4989
+ if (binArrayIndex != null) {
5169
4990
  return new (0, _anchor.BN)(binArrayIndex);
5170
4991
  } else {
5171
4992
  return null;
@@ -7794,7 +7615,7 @@ var DLMM = class {
7794
7615
  { length: upperBinArrayIndex.sub(lowerBinArrayIndex).toNumber() + 1 },
7795
7616
  (_, index) => index + lowerBinArrayIndex.toNumber()
7796
7617
  ).map((idx) => new (0, _anchor.BN)(idx));
7797
- const binArraysCount = (await this.binArraysToBeCreate(binArraysNeeded)).length;
7618
+ const binArraysCount = (await this.binArraysToBeCreate(lowerBinArrayIndex, upperBinArrayIndex)).length;
7798
7619
  const positionCount = Math.ceil((maxBinId - minBinId) / MAX_BIN_PER_TX);
7799
7620
  const binArrayCost = binArraysCount * BIN_ARRAY_FEE;
7800
7621
  const positionCost = positionCount * POSITION_FEE;
@@ -7842,18 +7663,18 @@ var DLMM = class {
7842
7663
  lowerBinArrayIndex,
7843
7664
  this.program.programId
7844
7665
  );
7845
- const upperBinArrayIndex = lowerBinArrayIndex.add(new (0, _anchor.BN)(1));
7666
+ const upperBinArrayIndex = _anchor.BN.max(
7667
+ lowerBinArrayIndex.add(new (0, _anchor.BN)(1)),
7668
+ binIdToBinArrayIndex(new (0, _anchor.BN)(maxBinId))
7669
+ );
7846
7670
  const [binArrayUpper] = deriveBinArray(
7847
7671
  this.pubkey,
7848
7672
  upperBinArrayIndex,
7849
7673
  this.program.programId
7850
7674
  );
7851
- const binArraysNeeded = Array.from(
7852
- { length: upperBinArrayIndex.sub(lowerBinArrayIndex).toNumber() + 4 },
7853
- (_, index) => index - 2 + lowerBinArrayIndex.toNumber()
7854
- ).map((idx) => new (0, _anchor.BN)(idx));
7855
7675
  const createBinArrayIxs = await this.createBinArraysIfNeeded(
7856
- binArraysNeeded,
7676
+ upperBinArrayIndex,
7677
+ lowerBinArrayIndex,
7857
7678
  user
7858
7679
  );
7859
7680
  preInstructions.push(...createBinArrayIxs);
@@ -8000,18 +7821,18 @@ var DLMM = class {
8000
7821
  lowerBinArrayIndex,
8001
7822
  this.program.programId
8002
7823
  );
8003
- const upperBinArrayIndex = lowerBinArrayIndex.add(new (0, _anchor.BN)(1));
7824
+ const upperBinArrayIndex = _anchor.BN.max(
7825
+ lowerBinArrayIndex.add(new (0, _anchor.BN)(1)),
7826
+ binIdToBinArrayIndex(new (0, _anchor.BN)(upperBinId))
7827
+ );
8004
7828
  const [binArrayUpper] = deriveBinArray(
8005
7829
  this.pubkey,
8006
7830
  upperBinArrayIndex,
8007
7831
  this.program.programId
8008
7832
  );
8009
- const binArraysNeeded = Array.from(
8010
- { length: upperBinArrayIndex.sub(lowerBinArrayIndex).toNumber() + 4 },
8011
- (_, index) => index - 2 + lowerBinArrayIndex.toNumber()
8012
- ).map((idx) => new (0, _anchor.BN)(idx));
8013
7833
  const createBinArrayIxs = await this.createBinArraysIfNeeded(
8014
- binArraysNeeded,
7834
+ upperBinArrayIndex,
7835
+ lowerBinArrayIndex,
8015
7836
  user
8016
7837
  );
8017
7838
  preInstructions.push(...createBinArrayIxs);
@@ -8197,18 +8018,18 @@ var DLMM = class {
8197
8018
  lowerBinArrayIndex,
8198
8019
  this.program.programId
8199
8020
  );
8200
- const upperBinArrayIndex = lowerBinArrayIndex.add(new (0, _anchor.BN)(1));
8021
+ const upperBinArrayIndex = _anchor.BN.max(
8022
+ lowerBinArrayIndex.add(new (0, _anchor.BN)(1)),
8023
+ binIdToBinArrayIndex(new (0, _anchor.BN)(maxBinId))
8024
+ );
8201
8025
  const [binArrayUpper] = deriveBinArray(
8202
8026
  this.pubkey,
8203
8027
  upperBinArrayIndex,
8204
8028
  this.program.programId
8205
8029
  );
8206
- const binArraysNeeded = Array.from(
8207
- { length: upperBinArrayIndex.sub(lowerBinArrayIndex).toNumber() + 4 },
8208
- (_, index) => index - 2 + lowerBinArrayIndex.toNumber()
8209
- ).map((idx) => new (0, _anchor.BN)(idx));
8210
8030
  const createBinArrayIxs = await this.createBinArraysIfNeeded(
8211
- binArraysNeeded,
8031
+ upperBinArrayIndex,
8032
+ lowerBinArrayIndex,
8212
8033
  user
8213
8034
  );
8214
8035
  preInstructions.push(...createBinArrayIxs);
@@ -8369,19 +8190,19 @@ var DLMM = class {
8369
8190
  lowerBinArrayIndex,
8370
8191
  this.program.programId
8371
8192
  );
8372
- const upperBinArrayIndex = lowerBinArrayIndex.add(new (0, _anchor.BN)(1));
8193
+ const upperBinArrayIndex = _anchor.BN.max(
8194
+ lowerBinArrayIndex.add(new (0, _anchor.BN)(1)),
8195
+ binIdToBinArrayIndex(new (0, _anchor.BN)(positionAccount.upperBinId))
8196
+ );
8373
8197
  const [binArrayUpper] = deriveBinArray(
8374
8198
  this.pubkey,
8375
8199
  upperBinArrayIndex,
8376
8200
  this.program.programId
8377
8201
  );
8378
- const binArraysNeeded = Array.from(
8379
- { length: upperBinArrayIndex.sub(lowerBinArrayIndex).toNumber() + 4 },
8380
- (_, index) => index - 2 + lowerBinArrayIndex.toNumber()
8381
- ).map((idx) => new (0, _anchor.BN)(idx));
8382
8202
  const preInstructions = [];
8383
8203
  const createBinArrayIxs = await this.createBinArraysIfNeeded(
8384
- binArraysNeeded,
8204
+ upperBinArrayIndex,
8205
+ lowerBinArrayIndex,
8385
8206
  user
8386
8207
  );
8387
8208
  preInstructions.push(...createBinArrayIxs);
@@ -9327,48 +9148,6 @@ var DLMM = class {
9327
9148
  })
9328
9149
  );
9329
9150
  }
9330
- async syncWithMarketPrice(marketPrice, owner) {
9331
- const marketPriceBinId = this.getBinIdFromPrice(marketPrice, false);
9332
- const activeBin = await this.getActiveBin();
9333
- const activeBinId = activeBin.binId;
9334
- const fromBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(activeBinId));
9335
- const swapForY = marketPriceBinId < activeBinId;
9336
- const toBinArrayIndex = findNextBinArrayIndexWithLiquidity(
9337
- swapForY,
9338
- new (0, _anchor.BN)(activeBinId),
9339
- this.lbPair,
9340
- this.binArrayBitmapExtension.account
9341
- );
9342
- const [lowerBinId, upperBinId] = getBinArrayLowerUpperBinId(toBinArrayIndex);
9343
- const toBinArrayBins = await this.getBins(
9344
- this.pubkey,
9345
- lowerBinId.toNumber(),
9346
- upperBinId.toNumber(),
9347
- this.tokenX.decimal,
9348
- this.tokenY.decimal
9349
- );
9350
- const toBinId = swapForY ? toBinArrayBins.findLast(({ yAmount }) => !yAmount.isZero()) : toBinArrayBins.find(({ xAmount }) => !xAmount.isZero());
9351
- const { blockhash, lastValidBlockHeight } = await this.program.provider.connection.getLatestBlockhash("confirmed");
9352
- const syncWithMarketPriceTx = await this.program.methods.goToABin(toBinId.binId).accounts({
9353
- lbPair: this.pubkey,
9354
- binArrayBitmapExtension: this.binArrayBitmapExtension.publicKey,
9355
- fromBinArray: deriveBinArray(
9356
- this.pubkey,
9357
- fromBinArrayIndex,
9358
- this.program.programId
9359
- )[0],
9360
- toBinArray: deriveBinArray(
9361
- this.pubkey,
9362
- toBinArrayIndex,
9363
- this.program.programId
9364
- )[0]
9365
- }).transaction();
9366
- return new (0, _web3js.Transaction)({
9367
- feePayer: owner,
9368
- blockhash,
9369
- lastValidBlockHeight
9370
- }).add(syncWithMarketPriceTx);
9371
- }
9372
9151
  /** Private static method */
9373
9152
  static async getBinArrays(program, lbPairPubkey) {
9374
9153
  return program.account.binArray.all([
@@ -9763,7 +9542,11 @@ var DLMM = class {
9763
9542
  }
9764
9543
  return bins;
9765
9544
  }
9766
- async binArraysToBeCreate(binArrayIndexes) {
9545
+ async binArraysToBeCreate(lowerBinArrayIndex, upperBinArrayIndex) {
9546
+ const binArrayIndexes = Array.from(
9547
+ { length: upperBinArrayIndex.sub(lowerBinArrayIndex).toNumber() + 1 },
9548
+ (_, index) => index + lowerBinArrayIndex.toNumber()
9549
+ ).map((idx) => new (0, _anchor.BN)(idx));
9767
9550
  const binArrays = [];
9768
9551
  for (const idx of binArrayIndexes) {
9769
9552
  const [binArray] = deriveBinArray(
@@ -9778,8 +9561,12 @@ var DLMM = class {
9778
9561
  }
9779
9562
  return binArrays;
9780
9563
  }
9781
- async createBinArraysIfNeeded(binArrayIndexes, funder) {
9564
+ async createBinArraysIfNeeded(upperBinArrayIndex, lowerBinArrayIndex, funder) {
9782
9565
  const ixs = [];
9566
+ const binArrayIndexes = Array.from(
9567
+ { length: upperBinArrayIndex.sub(lowerBinArrayIndex).toNumber() + 1 },
9568
+ (_, index) => index + lowerBinArrayIndex.toNumber()
9569
+ ).map((idx) => new (0, _anchor.BN)(idx));
9783
9570
  for (const idx of binArrayIndexes) {
9784
9571
  const [binArray] = deriveBinArray(
9785
9572
  this.pubkey,