@meteora-ag/dlmm 1.0.30 → 1.0.32-rc.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/README.md CHANGED
@@ -231,6 +231,7 @@ 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>` |
234
235
 
235
236
  ```
236
237
 
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.0";
8
+ version: "0.5.1";
9
9
  name: "lb_clmm";
10
10
  constants: [
11
11
  {
@@ -2285,6 +2285,124 @@ 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
+ ];
2288
2406
  }
2289
2407
  ];
2290
2408
  accounts: [
@@ -3037,6 +3155,42 @@ type LbClmm = {
3037
3155
  ];
3038
3156
  };
3039
3157
  },
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
+ },
3040
3194
  {
3041
3195
  name: "BinLiquidityDistribution";
3042
3196
  type: {
@@ -4149,6 +4303,26 @@ type LbClmm = {
4149
4303
  index: false;
4150
4304
  }
4151
4305
  ];
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
+ ];
4152
4326
  }
4153
4327
  ];
4154
4328
  errors: [
@@ -4441,6 +4615,11 @@ type LbClmm = {
4441
4615
  code: 6057;
4442
4616
  name: "InvalidLockReleaseSlot";
4443
4617
  msg: "Invalid lock release slot";
4618
+ },
4619
+ {
4620
+ code: 6058;
4621
+ name: "BinRangeIsNotEmpty";
4622
+ msg: "Bin range is not empty";
4444
4623
  }
4445
4624
  ];
4446
4625
  };
@@ -5087,6 +5266,15 @@ declare class DLMM {
5087
5266
  owner: PublicKey;
5088
5267
  positions: LbPosition[];
5089
5268
  }): Promise<Transaction[]>;
5269
+ canSyncWithMarketPrice(marketPrice: number, activeBinId: number): boolean;
5270
+ /**
5271
+ * The `syncWithMarketPrice` function is used to sync the liquidity pool with the market price.
5272
+ * @param
5273
+ * - `marketPrice`: The market price to sync with.
5274
+ * - `owner`: The public key of the owner of the liquidity pool.
5275
+ * @returns {Promise<Transaction>}
5276
+ */
5277
+ syncWithMarketPrice(marketPrice: number, owner: PublicKey): Promise<Transaction>;
5090
5278
  /** Private static method */
5091
5279
  private static getBinArrays;
5092
5280
  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.0",
12
+ version: "0.5.1",
13
13
  name: "lb_clmm",
14
14
  constants: [
15
15
  {
@@ -2289,6 +2289,124 @@ 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
+ ]
2292
2410
  }
2293
2411
  ],
2294
2412
  accounts: [
@@ -3041,6 +3159,42 @@ var IDL = {
3041
3159
  ]
3042
3160
  }
3043
3161
  },
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
+ },
3044
3198
  {
3045
3199
  name: "BinLiquidityDistribution",
3046
3200
  type: {
@@ -4153,6 +4307,26 @@ var IDL = {
4153
4307
  index: false
4154
4308
  }
4155
4309
  ]
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
+ ]
4156
4330
  }
4157
4331
  ],
4158
4332
  errors: [
@@ -4445,6 +4619,11 @@ var IDL = {
4445
4619
  code: 6057,
4446
4620
  name: "InvalidLockReleaseSlot",
4447
4621
  msg: "Invalid lock release slot"
4622
+ },
4623
+ {
4624
+ code: 6058,
4625
+ name: "BinRangeIsNotEmpty",
4626
+ msg: "Bin range is not empty"
4448
4627
  }
4449
4628
  ]
4450
4629
  };
@@ -4940,7 +5119,7 @@ function findNextBinArrayIndexWithLiquidity(swapForY, activeId, lbPairState, bin
4940
5119
  let startBinArrayIndex = binIdToBinArrayIndex(activeId);
4941
5120
  while (true) {
4942
5121
  if (isOverflowDefaultBinArrayBitmap(startBinArrayIndex)) {
4943
- if (binArrayBitmapExtension == null) {
5122
+ if (binArrayBitmapExtension === null) {
4944
5123
  return null;
4945
5124
  }
4946
5125
  const [minBinArrayIndex, maxBinArrayIndex] = extensionBitmapRange();
@@ -4951,7 +5130,7 @@ function findNextBinArrayIndexWithLiquidity(swapForY, activeId, lbPairState, bin
4951
5130
  minBinArrayIndex.toNumber(),
4952
5131
  binArrayBitmapExtension
4953
5132
  );
4954
- if (binArrayIndex != null) {
5133
+ if (binArrayIndex !== null) {
4955
5134
  return new (0, _anchor.BN)(binArrayIndex);
4956
5135
  } else {
4957
5136
  return null;
@@ -4962,7 +5141,7 @@ function findNextBinArrayIndexWithLiquidity(swapForY, activeId, lbPairState, bin
4962
5141
  BIN_ARRAY_BITMAP_SIZE.neg().sub(new (0, _anchor.BN)(1)).toNumber(),
4963
5142
  binArrayBitmapExtension
4964
5143
  );
4965
- if (binArrayIndex != null) {
5144
+ if (binArrayIndex !== null) {
4966
5145
  return new (0, _anchor.BN)(binArrayIndex);
4967
5146
  } else {
4968
5147
  startBinArrayIndex = BIN_ARRAY_BITMAP_SIZE.neg();
@@ -4975,7 +5154,7 @@ function findNextBinArrayIndexWithLiquidity(swapForY, activeId, lbPairState, bin
4975
5154
  BIN_ARRAY_BITMAP_SIZE.toNumber(),
4976
5155
  binArrayBitmapExtension
4977
5156
  );
4978
- if (binArrayIndex != null) {
5157
+ if (binArrayIndex !== null) {
4979
5158
  return new (0, _anchor.BN)(binArrayIndex);
4980
5159
  } else {
4981
5160
  startBinArrayIndex = BIN_ARRAY_BITMAP_SIZE;
@@ -4986,7 +5165,7 @@ function findNextBinArrayIndexWithLiquidity(swapForY, activeId, lbPairState, bin
4986
5165
  maxBinArrayIndex.toNumber(),
4987
5166
  binArrayBitmapExtension
4988
5167
  );
4989
- if (binArrayIndex != null) {
5168
+ if (binArrayIndex !== null) {
4990
5169
  return new (0, _anchor.BN)(binArrayIndex);
4991
5170
  } else {
4992
5171
  return null;
@@ -5005,7 +5184,7 @@ function findNextBinArrayIndexWithLiquidity(swapForY, activeId, lbPairState, bin
5005
5184
  const upperBitRange = new (0, _anchor.BN)(bitmapDetail.bits - 1).sub(offset);
5006
5185
  const croppedBitmap = bitmap.shln(upperBitRange.toNumber());
5007
5186
  const msb = mostSignificantBit(croppedBitmap, bitmapDetail.bits);
5008
- if (msb != null) {
5187
+ if (msb !== null) {
5009
5188
  return startBinArrayIndex.sub(new (0, _anchor.BN)(msb));
5010
5189
  } else {
5011
5190
  startBinArrayIndex = lowerBinArrayIndex.sub(new (0, _anchor.BN)(1));
@@ -5014,7 +5193,7 @@ function findNextBinArrayIndexWithLiquidity(swapForY, activeId, lbPairState, bin
5014
5193
  const lowerBitRange = offset;
5015
5194
  const croppedBitmap = bitmap.shrn(lowerBitRange.toNumber());
5016
5195
  const lsb = leastSignificantBit(croppedBitmap, bitmapDetail.bits);
5017
- if (lsb != null) {
5196
+ if (lsb !== null) {
5018
5197
  return startBinArrayIndex.add(new (0, _anchor.BN)(lsb));
5019
5198
  } else {
5020
5199
  startBinArrayIndex = upperBinArrayIndex.add(new (0, _anchor.BN)(1));
@@ -9144,6 +9323,115 @@ var DLMM = class {
9144
9323
  })
9145
9324
  );
9146
9325
  }
9326
+ canSyncWithMarketPrice(marketPrice, activeBinId) {
9327
+ const marketPriceBinId = this.getBinIdFromPrice(
9328
+ Number(
9329
+ DLMM.getPricePerLamport(
9330
+ this.tokenX.decimal,
9331
+ this.tokenY.decimal,
9332
+ marketPrice
9333
+ )
9334
+ ),
9335
+ false
9336
+ );
9337
+ const marketPriceBinArrayIndex = binIdToBinArrayIndex(
9338
+ new (0, _anchor.BN)(marketPriceBinId)
9339
+ );
9340
+ const swapForY = marketPriceBinId < activeBinId;
9341
+ const toBinArrayIndex = findNextBinArrayIndexWithLiquidity(
9342
+ swapForY,
9343
+ new (0, _anchor.BN)(activeBinId),
9344
+ this.lbPair,
9345
+ _nullishCoalesce(_optionalChain([this, 'access', _58 => _58.binArrayBitmapExtension, 'optionalAccess', _59 => _59.account]), () => ( null))
9346
+ );
9347
+ if (toBinArrayIndex === null)
9348
+ return true;
9349
+ return swapForY ? marketPriceBinArrayIndex.gt(toBinArrayIndex) : marketPriceBinArrayIndex.lt(toBinArrayIndex);
9350
+ }
9351
+ /**
9352
+ * The `syncWithMarketPrice` function is used to sync the liquidity pool with the market price.
9353
+ * @param
9354
+ * - `marketPrice`: The market price to sync with.
9355
+ * - `owner`: The public key of the owner of the liquidity pool.
9356
+ * @returns {Promise<Transaction>}
9357
+ */
9358
+ async syncWithMarketPrice(marketPrice, owner) {
9359
+ const marketPriceBinId = this.getBinIdFromPrice(
9360
+ Number(
9361
+ DLMM.getPricePerLamport(
9362
+ this.tokenX.decimal,
9363
+ this.tokenY.decimal,
9364
+ marketPrice
9365
+ )
9366
+ ),
9367
+ false
9368
+ );
9369
+ const activeBin = await this.getActiveBin();
9370
+ const activeBinId = activeBin.binId;
9371
+ const fromBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(activeBinId));
9372
+ const swapForY = marketPriceBinId < activeBinId;
9373
+ const toBinArrayIndex = findNextBinArrayIndexWithLiquidity(
9374
+ swapForY,
9375
+ new (0, _anchor.BN)(activeBinId),
9376
+ this.lbPair,
9377
+ _nullishCoalesce(_optionalChain([this, 'access', _60 => _60.binArrayBitmapExtension, 'optionalAccess', _61 => _61.account]), () => ( null))
9378
+ );
9379
+ if (!this.canSyncWithMarketPrice(marketPrice, activeBinId)) {
9380
+ throw new Error(
9381
+ "Unable to sync with market price due to bin with liquidity between current and market price bin"
9382
+ );
9383
+ }
9384
+ const accountsToFetch = [];
9385
+ const [binArrayBitMapExtensionPubkey] = deriveBinArrayBitmapExtension(
9386
+ this.pubkey,
9387
+ this.program.programId
9388
+ );
9389
+ accountsToFetch.push(binArrayBitMapExtensionPubkey);
9390
+ const [fromBinArrayPubkey] = deriveBinArray(
9391
+ this.pubkey,
9392
+ fromBinArrayIndex,
9393
+ this.program.programId
9394
+ );
9395
+ accountsToFetch.push(fromBinArrayPubkey);
9396
+ const toBinArrayPubkey = (() => {
9397
+ if (!toBinArrayIndex)
9398
+ return null;
9399
+ const [toBinArrayPubkey2] = deriveBinArray(
9400
+ this.pubkey,
9401
+ toBinArrayIndex,
9402
+ this.program.programId
9403
+ );
9404
+ accountsToFetch.push(toBinArrayPubkey2);
9405
+ return toBinArrayPubkey2;
9406
+ })();
9407
+ const binArrayAccounts = await this.program.provider.connection.getMultipleAccountsInfo(
9408
+ accountsToFetch
9409
+ );
9410
+ let fromBinArray = null;
9411
+ let toBinArray = null;
9412
+ let binArrayBitmapExtension = null;
9413
+ if (!!_optionalChain([binArrayAccounts, 'optionalAccess', _62 => _62[0]])) {
9414
+ binArrayBitmapExtension = binArrayBitMapExtensionPubkey;
9415
+ }
9416
+ if (!!_optionalChain([binArrayAccounts, 'optionalAccess', _63 => _63[1]])) {
9417
+ fromBinArray = fromBinArrayPubkey;
9418
+ }
9419
+ if (!!_optionalChain([binArrayAccounts, 'optionalAccess', _64 => _64[2]]) && !!toBinArrayIndex) {
9420
+ toBinArray = toBinArrayPubkey;
9421
+ }
9422
+ const { blockhash, lastValidBlockHeight } = await this.program.provider.connection.getLatestBlockhash("confirmed");
9423
+ const syncWithMarketPriceTx = await this.program.methods.goToABin(marketPriceBinId).accounts({
9424
+ lbPair: this.pubkey,
9425
+ binArrayBitmapExtension,
9426
+ fromBinArray,
9427
+ toBinArray
9428
+ }).transaction();
9429
+ return new (0, _web3js.Transaction)({
9430
+ feePayer: owner,
9431
+ blockhash,
9432
+ lastValidBlockHeight
9433
+ }).add(syncWithMarketPriceTx);
9434
+ }
9147
9435
  /** Private static method */
9148
9436
  static async getBinArrays(program, lbPairPubkey) {
9149
9437
  return program.account.binArray.all([
@@ -9740,7 +10028,7 @@ var DLMMError = class extends Error {
9740
10028
  const anchorError = _anchor.AnchorError.parse(
9741
10029
  JSON.parse(JSON.stringify(error)).logs
9742
10030
  );
9743
- if (_optionalChain([anchorError, 'optionalAccess', _58 => _58.program, 'access', _59 => _59.toBase58, 'call', _60 => _60()]) === LBCLMM_PROGRAM_IDS["mainnet-beta"]) {
10031
+ if (_optionalChain([anchorError, 'optionalAccess', _65 => _65.program, 'access', _66 => _66.toBase58, 'call', _67 => _67()]) === LBCLMM_PROGRAM_IDS["mainnet-beta"]) {
9744
10032
  _errorCode = anchorError.error.errorCode.number;
9745
10033
  _errorName = anchorError.error.errorCode.code;
9746
10034
  _errorMessage = anchorError.error.errorMessage;