@meteora-ag/dlmm 1.0.28 → 1.0.29-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,7 @@ declare class DLMM {
5087
5266
  owner: PublicKey;
5088
5267
  positions: LbPosition[];
5089
5268
  }): Promise<Transaction[]>;
5269
+ syncWithMarketPrice(marketPrice: number, owner: PublicKey): Promise<Transaction>;
5090
5270
  /** Private static method */
5091
5271
  private static getBinArrays;
5092
5272
  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
  };
@@ -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;
@@ -9148,6 +9327,48 @@ var DLMM = class {
9148
9327
  })
9149
9328
  );
9150
9329
  }
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
+ }
9151
9372
  /** Private static method */
9152
9373
  static async getBinArrays(program, lbPairPubkey) {
9153
9374
  return program.account.binArray.all([