@meteora-ag/dlmm 1.0.0 → 1.0.1

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
@@ -7,7 +7,7 @@
7
7
 
8
8
  ## Getting started
9
9
 
10
- NPM: https://www.npmjs.com/package/@meteora-ag/dlmm-sdk-public
10
+ NPM: https://www.npmjs.com/package/@meteora-ag/dlmm
11
11
 
12
12
  SDK: https://github.com/MeteoraAg/dlmm-sdk
13
13
 
@@ -20,21 +20,19 @@ Discord: https://discord.com/channels/841152225564950528/864859354335412224
20
20
  1. Install deps
21
21
 
22
22
  ```
23
- npm i @meteora-ag/dlmm-sdk-public @coral-xyz/anchor @solana/web3.js
23
+ npm i @meteora-ag/dlmm @coral-xyz/anchor @solana/web3.js
24
24
  ```
25
25
 
26
26
  2. Initialize DLMM instance
27
27
 
28
28
  ```ts
29
+ import DLMM from '@meteora-ag/dlmm'
30
+
29
31
  const USDC_USDT_POOL = new PublicKey('ARwi1S4DaiTG5DX7S4M4ZsrXqpMD1MrTmbu9ue2tpmEq') // You can get your desired pool address from the API https://dlmm-api.meteora.ag/pair/all
30
- const dlmmPool = await DLMM.create(connection, USDC_USDT_POOL, {
31
- cluster: "devnet",
32
- });
32
+ const dlmmPool = await DLMM.create(connection, USDC_USDT_POOL);
33
33
 
34
34
  // If you need to create multiple, can consider using `createMultiple`
35
- const dlmmPool = await DLMM.create(connection, [USDC_USDT_POOL, ...], {
36
- cluster: "devnet",
37
- });
35
+ const dlmmPool = await DLMM.create(connection, [USDC_USDT_POOL, ...]);
38
36
 
39
37
  ```
40
38
 
@@ -168,7 +166,14 @@ try {
168
166
  ```ts
169
167
  const swapAmount = new BN(100);
170
168
  // Swap quote
171
- const swapQuote = await dlmmPool.swapQuote(swapAmount, true, new BN(10));
169
+ const swapYtoX = true;
170
+ const binArrays = await dlmmPool.getBinArrayForSwap(swapYtoX);
171
+ const swapQuote = await dlmmPool.swapQuote(
172
+ swapAmount,
173
+ swapYtoX,
174
+ new BN(10),
175
+ binArrays
176
+ );
172
177
 
173
178
  // Swap
174
179
  const swapTx = await dlmmPool.swap({
@@ -202,6 +207,7 @@ try {
202
207
  | ------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
203
208
  | `refetchStates` | Update onchain state of DLMM instance. It's recommend to call this before interact with the program (Deposit/ Withdraw/ Swap) | `Promise<void>` |
204
209
  | `getBinArrays` | Retrieves List of Bin Arrays | `Promise<BinArrayAccount[]>` |
210
+ | `getBinArrayForSwap` | Retrieves List of Bin Arrays for swap purpose | `Promise<BinArrayAccount[]>` |
205
211
  | `getFeeInfo` | Retrieves LbPair's fee info including `base fee`, `protocol fee` & `max fee` | `FeeInfo` |
206
212
  | `getDynamicFee` | Retrieves LbPair's dynamic fee | `Decimal` |
207
213
  | `getBinsAroundActiveBin` | retrieves a specified number of bins to the left and right of the active bin and returns them along with the active bin ID. | `Promise<{ activeBin: number; bins: BinLiquidity[] }>` |
package/dist/index.d.ts CHANGED
@@ -4642,6 +4642,15 @@ declare class DLMM {
4642
4642
  * @returns a Promise that resolves to an array of BinArrayAccount objects.
4643
4643
  */
4644
4644
  getBinArrays(): Promise<BinArrayAccount[]>;
4645
+ /**
4646
+ * The function `getBinArrayAroundActiveBin` retrieves a specified number of `BinArrayAccount`
4647
+ * objects from the blockchain, based on the active bin and its surrounding bin arrays.
4648
+ * @param
4649
+ * swapForY - The `swapForY` parameter is a boolean value that indicates whether the swap is using quote token as input.
4650
+ * [count=4] - The `count` parameter is the number of bin arrays to retrieve on left and right respectively. By default, it is set to 4.
4651
+ * @returns an array of `BinArrayAccount` objects.
4652
+ */
4653
+ getBinArrayForSwap(swapForY: any, count?: number): Promise<BinArrayAccount[]>;
4645
4654
  /**
4646
4655
  * The function `getFeeInfo` calculates and returns the base fee rate percentage, maximum fee rate
4647
4656
  * percentage, and protocol fee percentage.
package/dist/index.js CHANGED
@@ -6152,6 +6152,63 @@ var DLMM = class {
6152
6152
  }
6153
6153
  ]);
6154
6154
  }
6155
+ /**
6156
+ * The function `getBinArrayAroundActiveBin` retrieves a specified number of `BinArrayAccount`
6157
+ * objects from the blockchain, based on the active bin and its surrounding bin arrays.
6158
+ * @param
6159
+ * swapForY - The `swapForY` parameter is a boolean value that indicates whether the swap is using quote token as input.
6160
+ * [count=4] - The `count` parameter is the number of bin arrays to retrieve on left and right respectively. By default, it is set to 4.
6161
+ * @returns an array of `BinArrayAccount` objects.
6162
+ */
6163
+ async getBinArrayForSwap(swapForY, count = 4) {
6164
+ await this.refetchStates();
6165
+ const binArraysPubkey = /* @__PURE__ */ new Set();
6166
+ let shouldStop = false;
6167
+ let activeIdToLoop = this.lbPair.activeId;
6168
+ while (!shouldStop) {
6169
+ const binArrayIndex = findNextBinArrayIndexWithLiquidity(
6170
+ swapForY,
6171
+ new (0, _anchor.BN)(activeIdToLoop),
6172
+ this.lbPair,
6173
+ _nullishCoalesce(_optionalChain([this, 'access', _51 => _51.binArrayBitmapExtension, 'optionalAccess', _52 => _52.account]), () => ( null))
6174
+ );
6175
+ if (binArrayIndex === null)
6176
+ shouldStop = true;
6177
+ else {
6178
+ const [binArrayPubKey] = deriveBinArray(
6179
+ this.pubkey,
6180
+ binArrayIndex,
6181
+ this.program.programId
6182
+ );
6183
+ binArraysPubkey.add(binArrayPubKey.toBase58());
6184
+ const [lowerBinId, upperBinId] = getBinArrayLowerUpperBinId(binArrayIndex);
6185
+ activeIdToLoop = swapForY ? lowerBinId.toNumber() - 1 : upperBinId.toNumber() + 1;
6186
+ }
6187
+ if (binArraysPubkey.size === count)
6188
+ shouldStop = true;
6189
+ }
6190
+ const accountsToFetch = Array.from(binArraysPubkey).map(
6191
+ (pubkey) => new (0, _web3js.PublicKey)(pubkey)
6192
+ );
6193
+ const binArraysAccInfoBuffer = await chunkedGetMultipleAccountInfos(
6194
+ this.program.provider.connection,
6195
+ accountsToFetch
6196
+ );
6197
+ const binArrays = await Promise.all(
6198
+ binArraysAccInfoBuffer.map(async (accInfo, idx) => {
6199
+ const account = this.program.coder.accounts.decode(
6200
+ "binArray",
6201
+ accInfo.data
6202
+ );
6203
+ const publicKey = accountsToFetch[idx];
6204
+ return {
6205
+ account,
6206
+ publicKey
6207
+ };
6208
+ })
6209
+ );
6210
+ return binArrays;
6211
+ }
6155
6212
  /**
6156
6213
  * The function `getFeeInfo` calculates and returns the base fee rate percentage, maximum fee rate
6157
6214
  * percentage, and protocol fee percentage.
@@ -7203,7 +7260,7 @@ var DLMM = class {
7203
7260
  swapForY,
7204
7261
  activeId,
7205
7262
  this.lbPair,
7206
- _optionalChain([this, 'access', _51 => _51.binArrayBitmapExtension, 'optionalAccess', _52 => _52.account]),
7263
+ _optionalChain([this, 'access', _53 => _53.binArrayBitmapExtension, 'optionalAccess', _54 => _54.account]),
7207
7264
  binArrays
7208
7265
  );
7209
7266
  if (binArrayAccountToSwap == null) {