@meteora-ag/dlmm 1.1.3-rc.1 → 1.1.4
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 +10 -1
- package/dist/index.js +103 -77
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +68 -42
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -6588,7 +6588,7 @@ function findNextBinArrayWithLiquidity(swapForY, activeBinId, lbPairState, binAr
|
|
|
6588
6588
|
(ba) => ba.account.index.eq(nearestBinArrayIndexWithLiquidity)
|
|
6589
6589
|
);
|
|
6590
6590
|
if (!binArrayAccount) {
|
|
6591
|
-
|
|
6591
|
+
return null;
|
|
6592
6592
|
}
|
|
6593
6593
|
return binArrayAccount;
|
|
6594
6594
|
}
|
|
@@ -7492,6 +7492,51 @@ import {
|
|
|
7492
7492
|
TOKEN_PROGRAM_ID as TOKEN_PROGRAM_ID2,
|
|
7493
7493
|
getAssociatedTokenAddressSync as getAssociatedTokenAddressSync2
|
|
7494
7494
|
} from "@solana/spl-token";
|
|
7495
|
+
|
|
7496
|
+
// src/dlmm/error.ts
|
|
7497
|
+
import { AnchorError } from "@coral-xyz/anchor";
|
|
7498
|
+
var DLMMError = class extends Error {
|
|
7499
|
+
errorCode;
|
|
7500
|
+
errorName;
|
|
7501
|
+
errorMessage;
|
|
7502
|
+
constructor(error) {
|
|
7503
|
+
let _errorCode = 0;
|
|
7504
|
+
let _errorName = "Something went wrong";
|
|
7505
|
+
let _errorMessage = "Something went wrong";
|
|
7506
|
+
if (error instanceof Error) {
|
|
7507
|
+
const anchorError = AnchorError.parse(
|
|
7508
|
+
JSON.parse(JSON.stringify(error)).logs
|
|
7509
|
+
);
|
|
7510
|
+
if (anchorError?.program.toBase58() === LBCLMM_PROGRAM_IDS["mainnet-beta"]) {
|
|
7511
|
+
_errorCode = anchorError.error.errorCode.number;
|
|
7512
|
+
_errorName = anchorError.error.errorCode.code;
|
|
7513
|
+
_errorMessage = anchorError.error.errorMessage;
|
|
7514
|
+
}
|
|
7515
|
+
} else {
|
|
7516
|
+
const idlError = IDL.errors.find((err) => err.code === error);
|
|
7517
|
+
if (idlError) {
|
|
7518
|
+
_errorCode = idlError.code;
|
|
7519
|
+
_errorName = idlError.name;
|
|
7520
|
+
_errorMessage = idlError.msg;
|
|
7521
|
+
}
|
|
7522
|
+
}
|
|
7523
|
+
super(_errorMessage);
|
|
7524
|
+
this.errorCode = _errorCode;
|
|
7525
|
+
this.errorName = _errorName;
|
|
7526
|
+
this.errorMessage = _errorMessage;
|
|
7527
|
+
}
|
|
7528
|
+
};
|
|
7529
|
+
var DlmmSdkError = class extends Error {
|
|
7530
|
+
name;
|
|
7531
|
+
message;
|
|
7532
|
+
constructor(name, message) {
|
|
7533
|
+
super();
|
|
7534
|
+
this.name = name;
|
|
7535
|
+
this.message = message;
|
|
7536
|
+
}
|
|
7537
|
+
};
|
|
7538
|
+
|
|
7539
|
+
// src/dlmm/index.ts
|
|
7495
7540
|
var DLMM = class {
|
|
7496
7541
|
constructor(pubkey, program, lbPair, binArrayBitmapExtension, tokenX, tokenY, clock, opt) {
|
|
7497
7542
|
this.pubkey = pubkey;
|
|
@@ -9766,10 +9811,9 @@ var DLMM = class {
|
|
|
9766
9811
|
user
|
|
9767
9812
|
);
|
|
9768
9813
|
createPayerTokenIx && preInstructions.push(createPayerTokenIx);
|
|
9769
|
-
const reserve = removeLiquidityForY ? reserveY : reserveX;
|
|
9770
|
-
const tokenMint = removeLiquidityForY ? tokenYMint : tokenXMint;
|
|
9771
9814
|
const postInstructions = [];
|
|
9772
|
-
|
|
9815
|
+
const shouldUnwrapSOL = removeLiquidityForY && this.tokenY.publicKey.equals(NATIVE_MINT2) || !removeLiquidityForY && this.tokenX.publicKey.equals(NATIVE_MINT2);
|
|
9816
|
+
if (shouldUnwrapSOL) {
|
|
9773
9817
|
const closeWrappedSOLIx = await unwrapSOLInstruction(user);
|
|
9774
9818
|
closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
|
|
9775
9819
|
}
|
|
@@ -9779,6 +9823,8 @@ var DLMM = class {
|
|
|
9779
9823
|
const maxBinArrayIndex = binIdToBinArrayIndex(new BN9(maxBinId));
|
|
9780
9824
|
const useExtension = isOverflowDefaultBinArrayBitmap(minBinArrayIndex) || isOverflowDefaultBinArrayBitmap(maxBinArrayIndex);
|
|
9781
9825
|
const binArrayBitmapExtension = useExtension ? deriveBinArrayBitmapExtension(this.pubkey, this.program.programId)[0] : null;
|
|
9826
|
+
const reserve = removeLiquidityForY ? reserveY : reserveX;
|
|
9827
|
+
const tokenMint = removeLiquidityForY ? tokenYMint : tokenXMint;
|
|
9782
9828
|
const removeLiquiditySingleSideTx = await this.program.methods.removeLiquiditySingleSide().accounts({
|
|
9783
9829
|
position,
|
|
9784
9830
|
lbPair,
|
|
@@ -9852,6 +9898,8 @@ var DLMM = class {
|
|
|
9852
9898
|
* - `protocolFee`: Protocol fee amount
|
|
9853
9899
|
* - `maxInAmount`: Maximum amount of lamport to swap in
|
|
9854
9900
|
* - `binArraysPubkey`: Array of bin arrays involved in the swap
|
|
9901
|
+
* @throws {DlmmSdkError}
|
|
9902
|
+
*
|
|
9855
9903
|
*/
|
|
9856
9904
|
swapQuoteExactOut(outAmount, swapForY, allowedSlippage, binArrays) {
|
|
9857
9905
|
const currentTimestamp = Date.now() / 1e3;
|
|
@@ -9880,7 +9928,10 @@ var DLMM = class {
|
|
|
9880
9928
|
binArrays
|
|
9881
9929
|
);
|
|
9882
9930
|
if (binArrayAccountToSwap == null) {
|
|
9883
|
-
throw new
|
|
9931
|
+
throw new DlmmSdkError(
|
|
9932
|
+
"SWAP_QUOTE_INSUFFICIENT_LIQUIDITY",
|
|
9933
|
+
"Insufficient liquidity in binArrays"
|
|
9934
|
+
);
|
|
9884
9935
|
}
|
|
9885
9936
|
binArraysForSwap.set(binArrayAccountToSwap.publicKey, true);
|
|
9886
9937
|
this.updateVolatilityAccumulator(
|
|
@@ -9952,6 +10003,7 @@ var DLMM = class {
|
|
|
9952
10003
|
* - `minOutAmount`: Minimum amount of lamport to swap out
|
|
9953
10004
|
* - `priceImpact`: Price impact of the swap
|
|
9954
10005
|
* - `binArraysPubkey`: Array of bin arrays involved in the swap
|
|
10006
|
+
* @throws {DlmmSdkError}
|
|
9955
10007
|
*/
|
|
9956
10008
|
swapQuote(inAmount, swapForY, allowedSlippage, binArrays, isPartialFill) {
|
|
9957
10009
|
const currentTimestamp = Date.now() / 1e3;
|
|
@@ -9983,7 +10035,10 @@ var DLMM = class {
|
|
|
9983
10035
|
if (isPartialFill) {
|
|
9984
10036
|
break;
|
|
9985
10037
|
} else {
|
|
9986
|
-
throw new
|
|
10038
|
+
throw new DlmmSdkError(
|
|
10039
|
+
"SWAP_QUOTE_INSUFFICIENT_LIQUIDITY",
|
|
10040
|
+
"Insufficient liquidity in binArrays for swapQuote"
|
|
10041
|
+
);
|
|
9987
10042
|
}
|
|
9988
10043
|
}
|
|
9989
10044
|
binArraysForSwap.set(binArrayAccountToSwap.publicKey, true);
|
|
@@ -10023,8 +10078,12 @@ var DLMM = class {
|
|
|
10023
10078
|
}
|
|
10024
10079
|
}
|
|
10025
10080
|
}
|
|
10026
|
-
if (!startBin)
|
|
10027
|
-
throw new
|
|
10081
|
+
if (!startBin) {
|
|
10082
|
+
throw new DlmmSdkError(
|
|
10083
|
+
"SWAP_QUOTE_INSUFFICIENT_LIQUIDITY",
|
|
10084
|
+
"Insufficient liquidity"
|
|
10085
|
+
);
|
|
10086
|
+
}
|
|
10028
10087
|
inAmount = inAmount.sub(inAmountLeft);
|
|
10029
10088
|
const outAmountWithoutSlippage = getOutAmount(
|
|
10030
10089
|
startBin,
|
|
@@ -11734,40 +11793,6 @@ var DLMM = class {
|
|
|
11734
11793
|
}
|
|
11735
11794
|
};
|
|
11736
11795
|
|
|
11737
|
-
// src/dlmm/error.ts
|
|
11738
|
-
import { AnchorError } from "@coral-xyz/anchor";
|
|
11739
|
-
var DLMMError = class extends Error {
|
|
11740
|
-
errorCode;
|
|
11741
|
-
errorName;
|
|
11742
|
-
errorMessage;
|
|
11743
|
-
constructor(error) {
|
|
11744
|
-
let _errorCode = 0;
|
|
11745
|
-
let _errorName = "Something went wrong";
|
|
11746
|
-
let _errorMessage = "Something went wrong";
|
|
11747
|
-
if (error instanceof Error) {
|
|
11748
|
-
const anchorError = AnchorError.parse(
|
|
11749
|
-
JSON.parse(JSON.stringify(error)).logs
|
|
11750
|
-
);
|
|
11751
|
-
if (anchorError?.program.toBase58() === LBCLMM_PROGRAM_IDS["mainnet-beta"]) {
|
|
11752
|
-
_errorCode = anchorError.error.errorCode.number;
|
|
11753
|
-
_errorName = anchorError.error.errorCode.code;
|
|
11754
|
-
_errorMessage = anchorError.error.errorMessage;
|
|
11755
|
-
}
|
|
11756
|
-
} else {
|
|
11757
|
-
const idlError = IDL.errors.find((err) => err.code === error);
|
|
11758
|
-
if (idlError) {
|
|
11759
|
-
_errorCode = idlError.code;
|
|
11760
|
-
_errorName = idlError.name;
|
|
11761
|
-
_errorMessage = idlError.msg;
|
|
11762
|
-
}
|
|
11763
|
-
}
|
|
11764
|
-
super(_errorMessage);
|
|
11765
|
-
this.errorCode = _errorCode;
|
|
11766
|
-
this.errorName = _errorName;
|
|
11767
|
-
this.errorMessage = _errorMessage;
|
|
11768
|
-
}
|
|
11769
|
-
};
|
|
11770
|
-
|
|
11771
11796
|
// src/index.ts
|
|
11772
11797
|
var src_default = DLMM;
|
|
11773
11798
|
export {
|
|
@@ -11779,6 +11804,7 @@ export {
|
|
|
11779
11804
|
BitmapType,
|
|
11780
11805
|
ClockLayout,
|
|
11781
11806
|
DLMMError,
|
|
11807
|
+
DlmmSdkError,
|
|
11782
11808
|
EXTENSION_BINARRAY_BITMAP_SIZE,
|
|
11783
11809
|
FEE_PRECISION,
|
|
11784
11810
|
IDL,
|