@meteora-ag/dlmm 1.3.13 → 1.3.15
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.d.ts +65 -10
- package/dist/index.js +162 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +154 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -25,7 +25,7 @@ import { PublicKey } from "@solana/web3.js";
|
|
|
25
25
|
|
|
26
26
|
// src/dlmm/idl.ts
|
|
27
27
|
var IDL = {
|
|
28
|
-
"version": "0.8.
|
|
28
|
+
"version": "0.8.6",
|
|
29
29
|
"name": "lb_clmm",
|
|
30
30
|
"constants": [
|
|
31
31
|
{
|
|
@@ -138,6 +138,11 @@ var IDL = {
|
|
|
138
138
|
"type": "u128",
|
|
139
139
|
"value": "100_000"
|
|
140
140
|
},
|
|
141
|
+
{
|
|
142
|
+
"name": "MINIMUM_LIQUIDITY",
|
|
143
|
+
"type": "u128",
|
|
144
|
+
"value": "1_000_000"
|
|
145
|
+
},
|
|
141
146
|
{
|
|
142
147
|
"name": "BIN_ARRAY",
|
|
143
148
|
"type": "bytes",
|
|
@@ -2671,6 +2676,27 @@ var IDL = {
|
|
|
2671
2676
|
"type": "publicKey"
|
|
2672
2677
|
}
|
|
2673
2678
|
]
|
|
2679
|
+
},
|
|
2680
|
+
{
|
|
2681
|
+
"name": "setPairStatusPermissionless",
|
|
2682
|
+
"accounts": [
|
|
2683
|
+
{
|
|
2684
|
+
"name": "lbPair",
|
|
2685
|
+
"isMut": true,
|
|
2686
|
+
"isSigner": false
|
|
2687
|
+
},
|
|
2688
|
+
{
|
|
2689
|
+
"name": "creator",
|
|
2690
|
+
"isMut": false,
|
|
2691
|
+
"isSigner": true
|
|
2692
|
+
}
|
|
2693
|
+
],
|
|
2694
|
+
"args": [
|
|
2695
|
+
{
|
|
2696
|
+
"name": "status",
|
|
2697
|
+
"type": "u8"
|
|
2698
|
+
}
|
|
2699
|
+
]
|
|
2674
2700
|
}
|
|
2675
2701
|
],
|
|
2676
2702
|
"accounts": [
|
|
@@ -2862,9 +2888,9 @@ var IDL = {
|
|
|
2862
2888
|
"type": "u8"
|
|
2863
2889
|
},
|
|
2864
2890
|
{
|
|
2865
|
-
"name": "
|
|
2891
|
+
"name": "creatorPoolOnOffControl",
|
|
2866
2892
|
"docs": [
|
|
2867
|
-
"
|
|
2893
|
+
"Allow pool creator to enable/disable pool with restricted validation. Only applicable for customizable permissionless pair type."
|
|
2868
2894
|
],
|
|
2869
2895
|
"type": "u8"
|
|
2870
2896
|
},
|
|
@@ -3942,6 +3968,13 @@ var IDL = {
|
|
|
3942
3968
|
"option": "u64"
|
|
3943
3969
|
}
|
|
3944
3970
|
},
|
|
3971
|
+
{
|
|
3972
|
+
"name": "creatorPoolOnOffControl",
|
|
3973
|
+
"docs": [
|
|
3974
|
+
"Pool creator have permission to enable/disable pool with restricted program validation. Only applicable for customizable permissionless pool."
|
|
3975
|
+
],
|
|
3976
|
+
"type": "bool"
|
|
3977
|
+
},
|
|
3945
3978
|
{
|
|
3946
3979
|
"name": "padding",
|
|
3947
3980
|
"docs": [
|
|
@@ -3950,7 +3983,7 @@ var IDL = {
|
|
|
3950
3983
|
"type": {
|
|
3951
3984
|
"array": [
|
|
3952
3985
|
"u8",
|
|
3953
|
-
|
|
3986
|
+
63
|
|
3954
3987
|
]
|
|
3955
3988
|
}
|
|
3956
3989
|
}
|
|
@@ -5401,6 +5434,16 @@ var IDL = {
|
|
|
5401
5434
|
"code": 6066,
|
|
5402
5435
|
"name": "InvalidStatus",
|
|
5403
5436
|
"msg": "Invalid status"
|
|
5437
|
+
},
|
|
5438
|
+
{
|
|
5439
|
+
"code": 6067,
|
|
5440
|
+
"name": "ExceededMaxOracleLength",
|
|
5441
|
+
"msg": "Exceed max oracle length"
|
|
5442
|
+
},
|
|
5443
|
+
{
|
|
5444
|
+
"code": 6068,
|
|
5445
|
+
"name": "InvalidMinimumLiquidity",
|
|
5446
|
+
"msg": "Invalid minimum liquidity"
|
|
5404
5447
|
}
|
|
5405
5448
|
]
|
|
5406
5449
|
};
|
|
@@ -5454,6 +5497,7 @@ var MAX_ACTIVE_BIN_SLIPPAGE = 3;
|
|
|
5454
5497
|
var ILM_BASE = new PublicKey(
|
|
5455
5498
|
"MFGQxwAmB91SwuYX36okv2Qmdc9aMuHTwWGUrp4AtB1"
|
|
5456
5499
|
);
|
|
5500
|
+
var MAX_EXTRA_BIN_ARRAYS = 3;
|
|
5457
5501
|
|
|
5458
5502
|
// src/dlmm/error.ts
|
|
5459
5503
|
import { AnchorError } from "@coral-xyz/anchor";
|
|
@@ -8506,7 +8550,7 @@ var DLMM = class {
|
|
|
8506
8550
|
base: baseKey
|
|
8507
8551
|
}).transaction();
|
|
8508
8552
|
}
|
|
8509
|
-
static async createCustomizablePermissionlessLbPair(connection, binStep, tokenX, tokenY, activeId, feeBps, activationType, hasAlphaVault, creatorKey, activationPoint, opt) {
|
|
8553
|
+
static async createCustomizablePermissionlessLbPair(connection, binStep, tokenX, tokenY, activeId, feeBps, activationType, hasAlphaVault, creatorKey, activationPoint, creatorPoolOnOffControl, opt) {
|
|
8510
8554
|
const provider = new AnchorProvider2(
|
|
8511
8555
|
connection,
|
|
8512
8556
|
{},
|
|
@@ -8536,7 +8580,8 @@ var DLMM = class {
|
|
|
8536
8580
|
activationType,
|
|
8537
8581
|
activationPoint: activationPoint ? activationPoint : null,
|
|
8538
8582
|
hasAlphaVault,
|
|
8539
|
-
|
|
8583
|
+
creatorPoolOnOffControl: creatorPoolOnOffControl ? creatorPoolOnOffControl : false,
|
|
8584
|
+
padding: Array(63).fill(0)
|
|
8540
8585
|
};
|
|
8541
8586
|
const userTokenX = getAssociatedTokenAddressSync2(tokenX, creatorKey);
|
|
8542
8587
|
const userTokenY = getAssociatedTokenAddressSync2(tokenY, creatorKey);
|
|
@@ -8667,6 +8712,26 @@ var DLMM = class {
|
|
|
8667
8712
|
};
|
|
8668
8713
|
this.lbPair = lbPairState;
|
|
8669
8714
|
}
|
|
8715
|
+
/**
|
|
8716
|
+
* Set the status of a permissionless LB pair to either enabled or disabled. This require pool field `creator_pool_on_off_control` to be true and type `CustomizablePermissionless`.
|
|
8717
|
+
* Pool creator can enable/disable the pair anytime before the pool is opened / activated. Once the pool activation time is passed, the pool creator can only enable the pair.
|
|
8718
|
+
* Useful for token launches which do not have fixed activation time.
|
|
8719
|
+
* @param enable If true, the pair will be enabled. If false, the pair will be disabled.
|
|
8720
|
+
* @param creator The public key of the pool creator.
|
|
8721
|
+
* @returns a Promise that resolves to the transaction.
|
|
8722
|
+
*/
|
|
8723
|
+
async setPairStatusPermissionless(enable, creator) {
|
|
8724
|
+
const tx = await this.program.methods.setPairStatusPermissionless(Number(enable)).accounts({
|
|
8725
|
+
lbPair: this.pubkey,
|
|
8726
|
+
creator
|
|
8727
|
+
}).transaction();
|
|
8728
|
+
const { blockhash, lastValidBlockHeight } = await this.program.provider.connection.getLatestBlockhash("confirmed");
|
|
8729
|
+
return new Transaction({
|
|
8730
|
+
feePayer: this.lbPair.creator,
|
|
8731
|
+
blockhash,
|
|
8732
|
+
lastValidBlockHeight
|
|
8733
|
+
}).add(tx);
|
|
8734
|
+
}
|
|
8670
8735
|
/**
|
|
8671
8736
|
* The function `getBinArrays` returns an array of `BinArrayAccount` objects
|
|
8672
8737
|
* @returns a Promise that resolves to an array of BinArrayAccount objects.
|
|
@@ -10153,6 +10218,7 @@ var DLMM = class {
|
|
|
10153
10218
|
* - `outAmount`: Amount of lamport to swap out
|
|
10154
10219
|
* - `swapForY`: Swap token X to Y when it is true, else reversed.
|
|
10155
10220
|
* - `allowedSlippage`: Allowed slippage for the swap. Expressed in BPS. To convert from slippage percentage to BPS unit: SLIPPAGE_PERCENTAGE * 100
|
|
10221
|
+
* - `maxExtraBinArrays`: Maximum number of extra binArrays to return
|
|
10156
10222
|
* @returns {SwapQuote}
|
|
10157
10223
|
* - `inAmount`: Amount of lamport to swap in
|
|
10158
10224
|
* - `outAmount`: Amount of lamport to swap out
|
|
@@ -10163,9 +10229,12 @@ var DLMM = class {
|
|
|
10163
10229
|
* @throws {DlmmSdkError}
|
|
10164
10230
|
*
|
|
10165
10231
|
*/
|
|
10166
|
-
swapQuoteExactOut(outAmount, swapForY, allowedSlippage, binArrays) {
|
|
10232
|
+
swapQuoteExactOut(outAmount, swapForY, allowedSlippage, binArrays, maxExtraBinArrays = 0) {
|
|
10167
10233
|
const currentTimestamp = Date.now() / 1e3;
|
|
10168
10234
|
let outAmountLeft = outAmount;
|
|
10235
|
+
if (maxExtraBinArrays < 0 || maxExtraBinArrays > MAX_EXTRA_BIN_ARRAYS) {
|
|
10236
|
+
throw new DlmmSdkError("INVALID_MAX_EXTRA_BIN_ARRAYS", `maxExtraBinArrays must be a value between 0 and ${MAX_EXTRA_BIN_ARRAYS}`);
|
|
10237
|
+
}
|
|
10169
10238
|
let vParameterClone = Object.assign({}, this.lbPair.vParameters);
|
|
10170
10239
|
let activeId = new BN10(this.lbPair.activeId);
|
|
10171
10240
|
const binStep = this.lbPair.binStep;
|
|
@@ -10239,6 +10308,41 @@ var DLMM = class {
|
|
|
10239
10308
|
);
|
|
10240
10309
|
const priceImpact = startPrice.sub(endPrice).abs().div(startPrice).mul(new Decimal5(100));
|
|
10241
10310
|
const maxInAmount = actualInAmount.mul(new BN10(BASIS_POINT_MAX).add(allowedSlippage)).div(new BN10(BASIS_POINT_MAX));
|
|
10311
|
+
if (maxExtraBinArrays > 0 && maxExtraBinArrays <= MAX_EXTRA_BIN_ARRAYS) {
|
|
10312
|
+
const extraBinArrays = new Array();
|
|
10313
|
+
while (extraBinArrays.length < maxExtraBinArrays) {
|
|
10314
|
+
let binArrayAccountToSwap = findNextBinArrayWithLiquidity(
|
|
10315
|
+
swapForY,
|
|
10316
|
+
activeId,
|
|
10317
|
+
this.lbPair,
|
|
10318
|
+
this.binArrayBitmapExtension?.account ?? null,
|
|
10319
|
+
binArrays
|
|
10320
|
+
);
|
|
10321
|
+
if (binArrayAccountToSwap == null) {
|
|
10322
|
+
break;
|
|
10323
|
+
}
|
|
10324
|
+
const binArrayAccountToSwapExisted = binArraysForSwap.has(binArrayAccountToSwap.publicKey);
|
|
10325
|
+
if (binArrayAccountToSwapExisted) {
|
|
10326
|
+
if (swapForY) {
|
|
10327
|
+
activeId = activeId.sub(new BN10(1));
|
|
10328
|
+
} else {
|
|
10329
|
+
activeId = activeId.add(new BN10(1));
|
|
10330
|
+
}
|
|
10331
|
+
} else {
|
|
10332
|
+
extraBinArrays.push(binArrayAccountToSwap.publicKey);
|
|
10333
|
+
const [lowerBinId, upperBinId] = getBinArrayLowerUpperBinId(binArrayAccountToSwap.account.index);
|
|
10334
|
+
if (swapForY) {
|
|
10335
|
+
activeId = lowerBinId.sub(new BN10(1));
|
|
10336
|
+
} else {
|
|
10337
|
+
activeId = upperBinId.add(new BN10(1));
|
|
10338
|
+
}
|
|
10339
|
+
}
|
|
10340
|
+
}
|
|
10341
|
+
extraBinArrays.forEach((binArrayPubkey) => {
|
|
10342
|
+
binArraysForSwap.set(binArrayPubkey, true);
|
|
10343
|
+
});
|
|
10344
|
+
}
|
|
10345
|
+
const binArraysPubkey = Array.from(binArraysForSwap.keys());
|
|
10242
10346
|
return {
|
|
10243
10347
|
inAmount: actualInAmount,
|
|
10244
10348
|
maxInAmount,
|
|
@@ -10246,7 +10350,7 @@ var DLMM = class {
|
|
|
10246
10350
|
priceImpact,
|
|
10247
10351
|
fee: feeAmount,
|
|
10248
10352
|
protocolFee: protocolFeeAmount,
|
|
10249
|
-
binArraysPubkey
|
|
10353
|
+
binArraysPubkey
|
|
10250
10354
|
};
|
|
10251
10355
|
}
|
|
10252
10356
|
/**
|
|
@@ -10257,6 +10361,7 @@ var DLMM = class {
|
|
|
10257
10361
|
* - `allowedSlippage`: Allowed slippage for the swap. Expressed in BPS. To convert from slippage percentage to BPS unit: SLIPPAGE_PERCENTAGE * 100
|
|
10258
10362
|
* - `binArrays`: binArrays for swapQuote.
|
|
10259
10363
|
* - `isPartialFill`: Flag to check whether the the swapQuote is partial fill, default = false.
|
|
10364
|
+
* - `maxExtraBinArrays`: Maximum number of extra binArrays to return
|
|
10260
10365
|
* @returns {SwapQuote}
|
|
10261
10366
|
* - `consumedInAmount`: Amount of lamport to swap in
|
|
10262
10367
|
* - `outAmount`: Amount of lamport to swap out
|
|
@@ -10267,9 +10372,12 @@ var DLMM = class {
|
|
|
10267
10372
|
* - `binArraysPubkey`: Array of bin arrays involved in the swap
|
|
10268
10373
|
* @throws {DlmmSdkError}
|
|
10269
10374
|
*/
|
|
10270
|
-
swapQuote(inAmount, swapForY, allowedSlippage, binArrays, isPartialFill) {
|
|
10375
|
+
swapQuote(inAmount, swapForY, allowedSlippage, binArrays, isPartialFill, maxExtraBinArrays = 0) {
|
|
10271
10376
|
const currentTimestamp = Date.now() / 1e3;
|
|
10272
10377
|
let inAmountLeft = inAmount;
|
|
10378
|
+
if (maxExtraBinArrays < 0 || maxExtraBinArrays > MAX_EXTRA_BIN_ARRAYS) {
|
|
10379
|
+
throw new DlmmSdkError("INVALID_MAX_EXTRA_BIN_ARRAYS", `maxExtraBinArrays must be a value between 0 and ${MAX_EXTRA_BIN_ARRAYS}`);
|
|
10380
|
+
}
|
|
10273
10381
|
let vParameterClone = Object.assign({}, this.lbPair.vParameters);
|
|
10274
10382
|
let activeId = new BN10(this.lbPair.activeId);
|
|
10275
10383
|
const binStep = this.lbPair.binStep;
|
|
@@ -10362,6 +10470,41 @@ var DLMM = class {
|
|
|
10362
10470
|
lastFilledActiveBinId.toNumber(),
|
|
10363
10471
|
this.lbPair.binStep
|
|
10364
10472
|
);
|
|
10473
|
+
if (maxExtraBinArrays > 0 && maxExtraBinArrays <= MAX_EXTRA_BIN_ARRAYS) {
|
|
10474
|
+
const extraBinArrays = new Array();
|
|
10475
|
+
while (extraBinArrays.length < maxExtraBinArrays) {
|
|
10476
|
+
let binArrayAccountToSwap = findNextBinArrayWithLiquidity(
|
|
10477
|
+
swapForY,
|
|
10478
|
+
activeId,
|
|
10479
|
+
this.lbPair,
|
|
10480
|
+
this.binArrayBitmapExtension?.account ?? null,
|
|
10481
|
+
binArrays
|
|
10482
|
+
);
|
|
10483
|
+
if (binArrayAccountToSwap == null) {
|
|
10484
|
+
break;
|
|
10485
|
+
}
|
|
10486
|
+
const binArrayAccountToSwapExisted = binArraysForSwap.has(binArrayAccountToSwap.publicKey);
|
|
10487
|
+
if (binArrayAccountToSwapExisted) {
|
|
10488
|
+
if (swapForY) {
|
|
10489
|
+
activeId = activeId.sub(new BN10(1));
|
|
10490
|
+
} else {
|
|
10491
|
+
activeId = activeId.add(new BN10(1));
|
|
10492
|
+
}
|
|
10493
|
+
} else {
|
|
10494
|
+
extraBinArrays.push(binArrayAccountToSwap.publicKey);
|
|
10495
|
+
const [lowerBinId, upperBinId] = getBinArrayLowerUpperBinId(binArrayAccountToSwap.account.index);
|
|
10496
|
+
if (swapForY) {
|
|
10497
|
+
activeId = lowerBinId.sub(new BN10(1));
|
|
10498
|
+
} else {
|
|
10499
|
+
activeId = upperBinId.add(new BN10(1));
|
|
10500
|
+
}
|
|
10501
|
+
}
|
|
10502
|
+
}
|
|
10503
|
+
extraBinArrays.forEach((binArrayPubkey) => {
|
|
10504
|
+
binArraysForSwap.set(binArrayPubkey, true);
|
|
10505
|
+
});
|
|
10506
|
+
}
|
|
10507
|
+
const binArraysPubkey = Array.from(binArraysForSwap.keys());
|
|
10365
10508
|
return {
|
|
10366
10509
|
consumedInAmount: inAmount,
|
|
10367
10510
|
outAmount: actualOutAmount,
|
|
@@ -10369,7 +10512,7 @@ var DLMM = class {
|
|
|
10369
10512
|
protocolFee: protocolFeeAmount,
|
|
10370
10513
|
minOutAmount,
|
|
10371
10514
|
priceImpact,
|
|
10372
|
-
binArraysPubkey
|
|
10515
|
+
binArraysPubkey,
|
|
10373
10516
|
endPrice
|
|
10374
10517
|
};
|
|
10375
10518
|
}
|
|
@@ -12256,6 +12399,7 @@ export {
|
|
|
12256
12399
|
MAX_BIN_PER_POSITION,
|
|
12257
12400
|
MAX_BIN_PER_TX,
|
|
12258
12401
|
MAX_CLAIM_ALL_ALLOWED,
|
|
12402
|
+
MAX_EXTRA_BIN_ARRAYS,
|
|
12259
12403
|
MAX_FEE_RATE,
|
|
12260
12404
|
Network,
|
|
12261
12405
|
POSITION_FEE,
|