@meteora-ag/dlmm 1.1.3-rc.1 → 1.1.3
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 +106 -78
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +71 -43
- 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,11 @@ 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
|
-
if (
|
|
9815
|
+
if ([
|
|
9816
|
+
this.tokenX.publicKey.toBase58(),
|
|
9817
|
+
this.tokenY.publicKey.toBase58()
|
|
9818
|
+
].includes(NATIVE_MINT2.toBase58())) {
|
|
9773
9819
|
const closeWrappedSOLIx = await unwrapSOLInstruction(user);
|
|
9774
9820
|
closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
|
|
9775
9821
|
}
|
|
@@ -9779,6 +9825,8 @@ var DLMM = class {
|
|
|
9779
9825
|
const maxBinArrayIndex = binIdToBinArrayIndex(new BN9(maxBinId));
|
|
9780
9826
|
const useExtension = isOverflowDefaultBinArrayBitmap(minBinArrayIndex) || isOverflowDefaultBinArrayBitmap(maxBinArrayIndex);
|
|
9781
9827
|
const binArrayBitmapExtension = useExtension ? deriveBinArrayBitmapExtension(this.pubkey, this.program.programId)[0] : null;
|
|
9828
|
+
const reserve = removeLiquidityForY ? reserveY : reserveX;
|
|
9829
|
+
const tokenMint = removeLiquidityForY ? tokenYMint : tokenXMint;
|
|
9782
9830
|
const removeLiquiditySingleSideTx = await this.program.methods.removeLiquiditySingleSide().accounts({
|
|
9783
9831
|
position,
|
|
9784
9832
|
lbPair,
|
|
@@ -9790,7 +9838,7 @@ var DLMM = class {
|
|
|
9790
9838
|
binArrayUpper,
|
|
9791
9839
|
sender: user,
|
|
9792
9840
|
tokenProgram: TOKEN_PROGRAM_ID2
|
|
9793
|
-
}).preInstructions(preInstructions).
|
|
9841
|
+
}).preInstructions(preInstructions).transaction();
|
|
9794
9842
|
const { blockhash, lastValidBlockHeight } = await this.program.provider.connection.getLatestBlockhash("confirmed");
|
|
9795
9843
|
return new Transaction({
|
|
9796
9844
|
blockhash,
|
|
@@ -9852,6 +9900,8 @@ var DLMM = class {
|
|
|
9852
9900
|
* - `protocolFee`: Protocol fee amount
|
|
9853
9901
|
* - `maxInAmount`: Maximum amount of lamport to swap in
|
|
9854
9902
|
* - `binArraysPubkey`: Array of bin arrays involved in the swap
|
|
9903
|
+
* @throws {DlmmSdkError}
|
|
9904
|
+
*
|
|
9855
9905
|
*/
|
|
9856
9906
|
swapQuoteExactOut(outAmount, swapForY, allowedSlippage, binArrays) {
|
|
9857
9907
|
const currentTimestamp = Date.now() / 1e3;
|
|
@@ -9880,7 +9930,10 @@ var DLMM = class {
|
|
|
9880
9930
|
binArrays
|
|
9881
9931
|
);
|
|
9882
9932
|
if (binArrayAccountToSwap == null) {
|
|
9883
|
-
throw new
|
|
9933
|
+
throw new DlmmSdkError(
|
|
9934
|
+
"SWAP_QUOTE_INSUFFICIENT_LIQUIDITY",
|
|
9935
|
+
"Insufficient liquidity in binArrays"
|
|
9936
|
+
);
|
|
9884
9937
|
}
|
|
9885
9938
|
binArraysForSwap.set(binArrayAccountToSwap.publicKey, true);
|
|
9886
9939
|
this.updateVolatilityAccumulator(
|
|
@@ -9952,6 +10005,7 @@ var DLMM = class {
|
|
|
9952
10005
|
* - `minOutAmount`: Minimum amount of lamport to swap out
|
|
9953
10006
|
* - `priceImpact`: Price impact of the swap
|
|
9954
10007
|
* - `binArraysPubkey`: Array of bin arrays involved in the swap
|
|
10008
|
+
* @throws {DlmmSdkError}
|
|
9955
10009
|
*/
|
|
9956
10010
|
swapQuote(inAmount, swapForY, allowedSlippage, binArrays, isPartialFill) {
|
|
9957
10011
|
const currentTimestamp = Date.now() / 1e3;
|
|
@@ -9983,7 +10037,10 @@ var DLMM = class {
|
|
|
9983
10037
|
if (isPartialFill) {
|
|
9984
10038
|
break;
|
|
9985
10039
|
} else {
|
|
9986
|
-
throw new
|
|
10040
|
+
throw new DlmmSdkError(
|
|
10041
|
+
"SWAP_QUOTE_INSUFFICIENT_LIQUIDITY",
|
|
10042
|
+
"Insufficient liquidity in binArrays for swapQuote"
|
|
10043
|
+
);
|
|
9987
10044
|
}
|
|
9988
10045
|
}
|
|
9989
10046
|
binArraysForSwap.set(binArrayAccountToSwap.publicKey, true);
|
|
@@ -10023,8 +10080,12 @@ var DLMM = class {
|
|
|
10023
10080
|
}
|
|
10024
10081
|
}
|
|
10025
10082
|
}
|
|
10026
|
-
if (!startBin)
|
|
10027
|
-
throw new
|
|
10083
|
+
if (!startBin) {
|
|
10084
|
+
throw new DlmmSdkError(
|
|
10085
|
+
"SWAP_QUOTE_INSUFFICIENT_LIQUIDITY",
|
|
10086
|
+
"Insufficient liquidity"
|
|
10087
|
+
);
|
|
10088
|
+
}
|
|
10028
10089
|
inAmount = inAmount.sub(inAmountLeft);
|
|
10029
10090
|
const outAmountWithoutSlippage = getOutAmount(
|
|
10030
10091
|
startBin,
|
|
@@ -11734,40 +11795,6 @@ var DLMM = class {
|
|
|
11734
11795
|
}
|
|
11735
11796
|
};
|
|
11736
11797
|
|
|
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
11798
|
// src/index.ts
|
|
11772
11799
|
var src_default = DLMM;
|
|
11773
11800
|
export {
|
|
@@ -11779,6 +11806,7 @@ export {
|
|
|
11779
11806
|
BitmapType,
|
|
11780
11807
|
ClockLayout,
|
|
11781
11808
|
DLMMError,
|
|
11809
|
+
DlmmSdkError,
|
|
11782
11810
|
EXTENSION_BINARRAY_BITMAP_SIZE,
|
|
11783
11811
|
FEE_PRECISION,
|
|
11784
11812
|
IDL,
|