@meteora-ag/dlmm 1.0.50 → 1.0.52-rc.6
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 +125 -32
- package/dist/index.js +245 -52
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +244 -51
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -2048,6 +2048,73 @@ var IDL = {
|
|
|
2048
2048
|
],
|
|
2049
2049
|
"args": []
|
|
2050
2050
|
},
|
|
2051
|
+
{
|
|
2052
|
+
"name": "removeLiquiditySingleSide",
|
|
2053
|
+
"accounts": [
|
|
2054
|
+
{
|
|
2055
|
+
"name": "position",
|
|
2056
|
+
"isMut": true,
|
|
2057
|
+
"isSigner": false
|
|
2058
|
+
},
|
|
2059
|
+
{
|
|
2060
|
+
"name": "lbPair",
|
|
2061
|
+
"isMut": true,
|
|
2062
|
+
"isSigner": false
|
|
2063
|
+
},
|
|
2064
|
+
{
|
|
2065
|
+
"name": "binArrayBitmapExtension",
|
|
2066
|
+
"isMut": true,
|
|
2067
|
+
"isSigner": false,
|
|
2068
|
+
"isOptional": true
|
|
2069
|
+
},
|
|
2070
|
+
{
|
|
2071
|
+
"name": "userToken",
|
|
2072
|
+
"isMut": true,
|
|
2073
|
+
"isSigner": false
|
|
2074
|
+
},
|
|
2075
|
+
{
|
|
2076
|
+
"name": "reserve",
|
|
2077
|
+
"isMut": true,
|
|
2078
|
+
"isSigner": false
|
|
2079
|
+
},
|
|
2080
|
+
{
|
|
2081
|
+
"name": "tokenMint",
|
|
2082
|
+
"isMut": false,
|
|
2083
|
+
"isSigner": false
|
|
2084
|
+
},
|
|
2085
|
+
{
|
|
2086
|
+
"name": "binArrayLower",
|
|
2087
|
+
"isMut": true,
|
|
2088
|
+
"isSigner": false
|
|
2089
|
+
},
|
|
2090
|
+
{
|
|
2091
|
+
"name": "binArrayUpper",
|
|
2092
|
+
"isMut": true,
|
|
2093
|
+
"isSigner": false
|
|
2094
|
+
},
|
|
2095
|
+
{
|
|
2096
|
+
"name": "sender",
|
|
2097
|
+
"isMut": false,
|
|
2098
|
+
"isSigner": true
|
|
2099
|
+
},
|
|
2100
|
+
{
|
|
2101
|
+
"name": "tokenProgram",
|
|
2102
|
+
"isMut": false,
|
|
2103
|
+
"isSigner": false
|
|
2104
|
+
},
|
|
2105
|
+
{
|
|
2106
|
+
"name": "eventAuthority",
|
|
2107
|
+
"isMut": false,
|
|
2108
|
+
"isSigner": false
|
|
2109
|
+
},
|
|
2110
|
+
{
|
|
2111
|
+
"name": "program",
|
|
2112
|
+
"isMut": false,
|
|
2113
|
+
"isSigner": false
|
|
2114
|
+
}
|
|
2115
|
+
],
|
|
2116
|
+
"args": []
|
|
2117
|
+
},
|
|
2051
2118
|
{
|
|
2052
2119
|
"name": "togglePairStatus",
|
|
2053
2120
|
"accounts": [
|
|
@@ -2559,7 +2626,7 @@ var IDL = {
|
|
|
2559
2626
|
],
|
|
2560
2627
|
"accounts": [
|
|
2561
2628
|
{
|
|
2562
|
-
"name": "
|
|
2629
|
+
"name": "BinArrayBitmapExtension",
|
|
2563
2630
|
"type": {
|
|
2564
2631
|
"kind": "struct",
|
|
2565
2632
|
"fields": [
|
|
@@ -2605,7 +2672,7 @@ var IDL = {
|
|
|
2605
2672
|
}
|
|
2606
2673
|
},
|
|
2607
2674
|
{
|
|
2608
|
-
"name": "
|
|
2675
|
+
"name": "BinArray",
|
|
2609
2676
|
"docs": [
|
|
2610
2677
|
"An account to contain a range of bin. For example: Bin 100 <-> 200.",
|
|
2611
2678
|
"For example:",
|
|
@@ -2654,7 +2721,7 @@ var IDL = {
|
|
|
2654
2721
|
}
|
|
2655
2722
|
},
|
|
2656
2723
|
{
|
|
2657
|
-
"name": "
|
|
2724
|
+
"name": "LbPair",
|
|
2658
2725
|
"type": {
|
|
2659
2726
|
"kind": "struct",
|
|
2660
2727
|
"fields": [
|
|
@@ -2902,7 +2969,7 @@ var IDL = {
|
|
|
2902
2969
|
}
|
|
2903
2970
|
},
|
|
2904
2971
|
{
|
|
2905
|
-
"name": "
|
|
2972
|
+
"name": "Oracle",
|
|
2906
2973
|
"type": {
|
|
2907
2974
|
"kind": "struct",
|
|
2908
2975
|
"fields": [
|
|
@@ -2931,7 +2998,7 @@ var IDL = {
|
|
|
2931
2998
|
}
|
|
2932
2999
|
},
|
|
2933
3000
|
{
|
|
2934
|
-
"name": "
|
|
3001
|
+
"name": "Position",
|
|
2935
3002
|
"type": {
|
|
2936
3003
|
"kind": "struct",
|
|
2937
3004
|
"fields": [
|
|
@@ -3052,7 +3119,7 @@ var IDL = {
|
|
|
3052
3119
|
}
|
|
3053
3120
|
},
|
|
3054
3121
|
{
|
|
3055
|
-
"name": "
|
|
3122
|
+
"name": "PositionV2",
|
|
3056
3123
|
"type": {
|
|
3057
3124
|
"kind": "struct",
|
|
3058
3125
|
"fields": [
|
|
@@ -3201,7 +3268,7 @@ var IDL = {
|
|
|
3201
3268
|
}
|
|
3202
3269
|
},
|
|
3203
3270
|
{
|
|
3204
|
-
"name": "
|
|
3271
|
+
"name": "PresetParameter",
|
|
3205
3272
|
"type": {
|
|
3206
3273
|
"kind": "struct",
|
|
3207
3274
|
"fields": [
|
|
@@ -3724,38 +3791,38 @@ var IDL = {
|
|
|
3724
3791
|
}
|
|
3725
3792
|
},
|
|
3726
3793
|
{
|
|
3727
|
-
"name": "
|
|
3794
|
+
"name": "FeeParameter",
|
|
3728
3795
|
"type": {
|
|
3729
3796
|
"kind": "struct",
|
|
3730
3797
|
"fields": [
|
|
3731
3798
|
{
|
|
3732
|
-
"name": "
|
|
3733
|
-
"
|
|
3799
|
+
"name": "protocolShare",
|
|
3800
|
+
"docs": [
|
|
3801
|
+
"Portion of swap fees retained by the protocol by controlling protocol_share parameter. protocol_swap_fee = protocol_share * total_swap_fee"
|
|
3802
|
+
],
|
|
3803
|
+
"type": "u16"
|
|
3734
3804
|
},
|
|
3735
3805
|
{
|
|
3736
|
-
"name": "
|
|
3806
|
+
"name": "baseFactor",
|
|
3807
|
+
"docs": [
|
|
3808
|
+
"Base factor for base fee rate"
|
|
3809
|
+
],
|
|
3737
3810
|
"type": "u16"
|
|
3738
3811
|
}
|
|
3739
3812
|
]
|
|
3740
3813
|
}
|
|
3741
3814
|
},
|
|
3742
3815
|
{
|
|
3743
|
-
"name": "
|
|
3816
|
+
"name": "BinLiquidityReduction",
|
|
3744
3817
|
"type": {
|
|
3745
3818
|
"kind": "struct",
|
|
3746
3819
|
"fields": [
|
|
3747
3820
|
{
|
|
3748
|
-
"name": "
|
|
3749
|
-
"
|
|
3750
|
-
"Portion of swap fees retained by the protocol by controlling protocol_share parameter. protocol_swap_fee = protocol_share * total_swap_fee"
|
|
3751
|
-
],
|
|
3752
|
-
"type": "u16"
|
|
3821
|
+
"name": "binId",
|
|
3822
|
+
"type": "i32"
|
|
3753
3823
|
},
|
|
3754
3824
|
{
|
|
3755
|
-
"name": "
|
|
3756
|
-
"docs": [
|
|
3757
|
-
"Base factor for base fee rate"
|
|
3758
|
-
],
|
|
3825
|
+
"name": "bpsToRemove",
|
|
3759
3826
|
"type": "u16"
|
|
3760
3827
|
}
|
|
3761
3828
|
]
|
|
@@ -6475,6 +6542,24 @@ function findNextBinArrayWithLiquidity(swapForY, activeBinId, lbPairState, binAr
|
|
|
6475
6542
|
}
|
|
6476
6543
|
return binArrayAccount;
|
|
6477
6544
|
}
|
|
6545
|
+
function getBinArraysRequiredByPositionRange(pair, fromBinId, toBinId, programId) {
|
|
6546
|
+
const [minBinId, maxBinId] = fromBinId.lt(toBinId) ? [fromBinId, toBinId] : [toBinId, fromBinId];
|
|
6547
|
+
const positionCount = getPositionCount(minBinId, maxBinId);
|
|
6548
|
+
const binArrays = /* @__PURE__ */ new Map();
|
|
6549
|
+
for (let i = 0; i < positionCount.toNumber(); i++) {
|
|
6550
|
+
const lowerBinId = minBinId.add(MAX_BIN_PER_POSITION.mul(new (0, _anchor.BN)(i)));
|
|
6551
|
+
const lowerBinArrayIndex = binIdToBinArrayIndex(lowerBinId);
|
|
6552
|
+
const upperBinArrayIndex = lowerBinArrayIndex.add(new (0, _anchor.BN)(1));
|
|
6553
|
+
const [lowerBinArray] = deriveBinArray(pair, lowerBinArrayIndex, programId);
|
|
6554
|
+
const [upperBinArray] = deriveBinArray(pair, upperBinArrayIndex, programId);
|
|
6555
|
+
binArrays.set(lowerBinArray.toBase58(), lowerBinArrayIndex);
|
|
6556
|
+
binArrays.set(upperBinArray.toBase58(), upperBinArrayIndex);
|
|
6557
|
+
}
|
|
6558
|
+
return Array.from(binArrays, ([key, index]) => ({
|
|
6559
|
+
key: new (0, _web3js.PublicKey)(key),
|
|
6560
|
+
index
|
|
6561
|
+
}));
|
|
6562
|
+
}
|
|
6478
6563
|
|
|
6479
6564
|
// src/dlmm/helpers/fee.ts
|
|
6480
6565
|
|
|
@@ -7219,7 +7304,7 @@ async function getTokensMintFromPoolAddress(connection, poolAddress, opt) {
|
|
|
7219
7304
|
LBCLMM_PROGRAM_IDS[_nullishCoalesce(_optionalChain([opt, 'optionalAccess', _18 => _18.cluster]), () => ( "mainnet-beta"))],
|
|
7220
7305
|
provider
|
|
7221
7306
|
);
|
|
7222
|
-
const poolAccount = await program.account.
|
|
7307
|
+
const poolAccount = await program.account.LbPair.fetchNullable(
|
|
7223
7308
|
new (0, _web3js.PublicKey)(poolAddress)
|
|
7224
7309
|
);
|
|
7225
7310
|
if (!poolAccount)
|
|
@@ -7239,7 +7324,7 @@ function chunks(array, size) {
|
|
|
7239
7324
|
async function chunkedFetchMultiplePoolAccount(program, pks, chunkSize = 100) {
|
|
7240
7325
|
const accounts = (await Promise.all(
|
|
7241
7326
|
chunks(pks, chunkSize).map(
|
|
7242
|
-
(chunk) => program.account.
|
|
7327
|
+
(chunk) => program.account.LbPair.fetchMultiple(chunk)
|
|
7243
7328
|
)
|
|
7244
7329
|
)).flat();
|
|
7245
7330
|
return accounts.filter(Boolean);
|
|
@@ -7247,7 +7332,7 @@ async function chunkedFetchMultiplePoolAccount(program, pks, chunkSize = 100) {
|
|
|
7247
7332
|
async function chunkedFetchMultipleBinArrayBitmapExtensionAccount(program, pks, chunkSize = 100) {
|
|
7248
7333
|
const accounts = (await Promise.all(
|
|
7249
7334
|
chunks(pks, chunkSize).map(
|
|
7250
|
-
(chunk) => program.account.
|
|
7335
|
+
(chunk) => program.account.BinArrayBitmapExtension.fetchMultiple(chunk)
|
|
7251
7336
|
)
|
|
7252
7337
|
)).flat();
|
|
7253
7338
|
return accounts;
|
|
@@ -7389,7 +7474,7 @@ var DLMM = class {
|
|
|
7389
7474
|
_nullishCoalesce(_optionalChain([opt, 'optionalAccess', _21 => _21.programId]), () => ( LBCLMM_PROGRAM_IDS[_nullishCoalesce(_optionalChain([opt, 'optionalAccess', _22 => _22.cluster]), () => ( "mainnet-beta"))])),
|
|
7390
7475
|
provider
|
|
7391
7476
|
);
|
|
7392
|
-
return program.account.
|
|
7477
|
+
return program.account.LbPair.all();
|
|
7393
7478
|
}
|
|
7394
7479
|
static async getPairPubkeyIfExists(connection, tokenX, tokenY, binStep, baseFactor, opt) {
|
|
7395
7480
|
const cluster = _optionalChain([opt, 'optionalAccess', _23 => _23.cluster]) || "mainnet-beta";
|
|
@@ -7411,7 +7496,7 @@ var DLMM = class {
|
|
|
7411
7496
|
baseFactor,
|
|
7412
7497
|
program.programId
|
|
7413
7498
|
);
|
|
7414
|
-
const account2 = await program.account.
|
|
7499
|
+
const account2 = await program.account.LbPair.fetchNullable(lbPair2Key);
|
|
7415
7500
|
if (account2)
|
|
7416
7501
|
return lbPair2Key;
|
|
7417
7502
|
const [lbPairKey] = deriveLbPair(
|
|
@@ -7420,7 +7505,7 @@ var DLMM = class {
|
|
|
7420
7505
|
binStep,
|
|
7421
7506
|
program.programId
|
|
7422
7507
|
);
|
|
7423
|
-
const account = await program.account.
|
|
7508
|
+
const account = await program.account.LbPair.fetchNullable(lbPairKey);
|
|
7424
7509
|
if (account && account.parameters.baseFactor === baseFactor.toNumber()) {
|
|
7425
7510
|
return lbPairKey;
|
|
7426
7511
|
}
|
|
@@ -7651,7 +7736,7 @@ var DLMM = class {
|
|
|
7651
7736
|
_nullishCoalesce(_optionalChain([opt, 'optionalAccess', _37 => _37.programId]), () => ( LBCLMM_PROGRAM_IDS[_nullishCoalesce(_optionalChain([opt, 'optionalAccess', _38 => _38.cluster]), () => ( "mainnet-beta"))])),
|
|
7652
7737
|
provider
|
|
7653
7738
|
);
|
|
7654
|
-
const presetParameter = await program.account.
|
|
7739
|
+
const presetParameter = await program.account.PresetParameter.all();
|
|
7655
7740
|
return presetParameter;
|
|
7656
7741
|
}
|
|
7657
7742
|
/**
|
|
@@ -7678,7 +7763,7 @@ var DLMM = class {
|
|
|
7678
7763
|
provider
|
|
7679
7764
|
);
|
|
7680
7765
|
const [positions, positionsV2] = await Promise.all([
|
|
7681
|
-
program.account.
|
|
7766
|
+
program.account.Position.all([
|
|
7682
7767
|
{
|
|
7683
7768
|
memcmp: {
|
|
7684
7769
|
bytes: _bytes.bs58.encode(userPubKey.toBuffer()),
|
|
@@ -7686,7 +7771,7 @@ var DLMM = class {
|
|
|
7686
7771
|
}
|
|
7687
7772
|
}
|
|
7688
7773
|
]),
|
|
7689
|
-
program.account.
|
|
7774
|
+
program.account.PositionV2.all([
|
|
7690
7775
|
{
|
|
7691
7776
|
memcmp: {
|
|
7692
7777
|
bytes: _bytes.bs58.encode(userPubKey.toBuffer()),
|
|
@@ -8033,7 +8118,7 @@ var DLMM = class {
|
|
|
8033
8118
|
_nullishCoalesce(_optionalChain([opt, 'optionalAccess', _60 => _60.programId]), () => ( LBCLMM_PROGRAM_IDS[cluster])),
|
|
8034
8119
|
provider
|
|
8035
8120
|
);
|
|
8036
|
-
const positionsState = await program.account.
|
|
8121
|
+
const positionsState = await program.account.Position.fetchMultiple(
|
|
8037
8122
|
positions
|
|
8038
8123
|
);
|
|
8039
8124
|
const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash("confirmed");
|
|
@@ -8246,7 +8331,7 @@ var DLMM = class {
|
|
|
8246
8331
|
* @returns a Promise that resolves to an array of BinArrayAccount objects.
|
|
8247
8332
|
*/
|
|
8248
8333
|
async getBinArrays() {
|
|
8249
|
-
return this.program.account.
|
|
8334
|
+
return this.program.account.BinArray.all([
|
|
8250
8335
|
{
|
|
8251
8336
|
memcmp: {
|
|
8252
8337
|
bytes: _bytes.bs58.encode(this.pubkey.toBuffer()),
|
|
@@ -8475,7 +8560,7 @@ var DLMM = class {
|
|
|
8475
8560
|
* @returns an object with two properties: "binId" which is a number, and "price" which is a string.
|
|
8476
8561
|
*/
|
|
8477
8562
|
async getActiveBin() {
|
|
8478
|
-
const { activeId } = await this.program.account.
|
|
8563
|
+
const { activeId } = await this.program.account.LbPair.fetch(this.pubkey);
|
|
8479
8564
|
const [activeBinState] = await this.getBins(
|
|
8480
8565
|
this.pubkey,
|
|
8481
8566
|
activeId,
|
|
@@ -8525,7 +8610,7 @@ var DLMM = class {
|
|
|
8525
8610
|
async getPositionsByUserAndLbPair(userPubKey) {
|
|
8526
8611
|
const promiseResults = await Promise.all([
|
|
8527
8612
|
this.getActiveBin(),
|
|
8528
|
-
userPubKey && this.program.account.
|
|
8613
|
+
userPubKey && this.program.account.Position.all([
|
|
8529
8614
|
{
|
|
8530
8615
|
memcmp: {
|
|
8531
8616
|
bytes: _bytes.bs58.encode(userPubKey.toBuffer()),
|
|
@@ -8539,7 +8624,7 @@ var DLMM = class {
|
|
|
8539
8624
|
}
|
|
8540
8625
|
}
|
|
8541
8626
|
]),
|
|
8542
|
-
userPubKey && this.program.account.
|
|
8627
|
+
userPubKey && this.program.account.PositionV2.all([
|
|
8543
8628
|
{
|
|
8544
8629
|
memcmp: {
|
|
8545
8630
|
bytes: _bytes.bs58.encode(userPubKey.toBuffer()),
|
|
@@ -9226,7 +9311,7 @@ var DLMM = class {
|
|
|
9226
9311
|
slippage
|
|
9227
9312
|
}) {
|
|
9228
9313
|
const maxActiveBinSlippage = slippage ? Math.ceil(slippage / (this.lbPair.binStep / 100)) : MAX_ACTIVE_BIN_SLIPPAGE;
|
|
9229
|
-
const positionAccount = await this.program.account.
|
|
9314
|
+
const positionAccount = await this.program.account.PositionV2.fetch(
|
|
9230
9315
|
positionPubKey
|
|
9231
9316
|
);
|
|
9232
9317
|
const { lowerBinId, upperBinId, binIds } = this.processXYAmountDistribution(xYAmountDistribution);
|
|
@@ -9425,8 +9510,8 @@ var DLMM = class {
|
|
|
9425
9510
|
bps,
|
|
9426
9511
|
shouldClaimAndClose = false
|
|
9427
9512
|
}) {
|
|
9428
|
-
const { lbPair, lowerBinId, owner, feeOwner } = await this.program.account.
|
|
9429
|
-
const { reserveX, reserveY, tokenXMint, tokenYMint } = await this.program.account.
|
|
9513
|
+
const { lbPair, lowerBinId, owner, feeOwner } = await this.program.account.PositionV2.fetch(position);
|
|
9514
|
+
const { reserveX, reserveY, tokenXMint, tokenYMint } = await this.program.account.LbPair.fetch(lbPair);
|
|
9430
9515
|
const lowerBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(lowerBinId));
|
|
9431
9516
|
const upperBinArrayIndex = lowerBinArrayIndex.add(new (0, _anchor.BN)(1));
|
|
9432
9517
|
const [binArrayLower] = deriveBinArray(
|
|
@@ -9586,6 +9671,77 @@ var DLMM = class {
|
|
|
9586
9671
|
}).add(removeLiquidityTx);
|
|
9587
9672
|
}
|
|
9588
9673
|
}
|
|
9674
|
+
async removeLiquiditySingleSide({
|
|
9675
|
+
user,
|
|
9676
|
+
position,
|
|
9677
|
+
binIds,
|
|
9678
|
+
removeLiquidityForY = false
|
|
9679
|
+
}) {
|
|
9680
|
+
const { lbPair, lowerBinId, owner, feeOwner } = await this.program.account.PositionV2.fetch(position);
|
|
9681
|
+
console.log("removeLiquidityFor2Y", removeLiquidityForY);
|
|
9682
|
+
const { reserveX, reserveY, tokenXMint, tokenYMint } = await this.program.account.LbPair.fetch(lbPair);
|
|
9683
|
+
const lowerBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(lowerBinId));
|
|
9684
|
+
const upperBinArrayIndex = lowerBinArrayIndex.add(new (0, _anchor.BN)(1));
|
|
9685
|
+
const [binArrayLower] = deriveBinArray(
|
|
9686
|
+
lbPair,
|
|
9687
|
+
lowerBinArrayIndex,
|
|
9688
|
+
this.program.programId
|
|
9689
|
+
);
|
|
9690
|
+
const [binArrayUpper] = deriveBinArray(
|
|
9691
|
+
lbPair,
|
|
9692
|
+
upperBinArrayIndex,
|
|
9693
|
+
this.program.programId
|
|
9694
|
+
);
|
|
9695
|
+
const preInstructions = [];
|
|
9696
|
+
const setComputeUnitLimitIx = computeBudgetIx();
|
|
9697
|
+
preInstructions.push(setComputeUnitLimitIx);
|
|
9698
|
+
const { ataPubKey: userToken, ix: createPayerTokenIx } = removeLiquidityForY ? await getOrCreateATAInstruction(
|
|
9699
|
+
this.program.provider.connection,
|
|
9700
|
+
this.tokenY.publicKey,
|
|
9701
|
+
owner,
|
|
9702
|
+
user
|
|
9703
|
+
) : await getOrCreateATAInstruction(
|
|
9704
|
+
this.program.provider.connection,
|
|
9705
|
+
this.tokenX.publicKey,
|
|
9706
|
+
owner,
|
|
9707
|
+
user
|
|
9708
|
+
);
|
|
9709
|
+
createPayerTokenIx && preInstructions.push(createPayerTokenIx);
|
|
9710
|
+
const postInstructions = [];
|
|
9711
|
+
if ([
|
|
9712
|
+
this.tokenX.publicKey.toBase58(),
|
|
9713
|
+
this.tokenY.publicKey.toBase58()
|
|
9714
|
+
].includes(_spltoken.NATIVE_MINT.toBase58())) {
|
|
9715
|
+
const closeWrappedSOLIx = await unwrapSOLInstruction(user);
|
|
9716
|
+
closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
|
|
9717
|
+
}
|
|
9718
|
+
const minBinId = Math.min(...binIds);
|
|
9719
|
+
const maxBinId = Math.max(...binIds);
|
|
9720
|
+
const minBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(minBinId));
|
|
9721
|
+
const maxBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(maxBinId));
|
|
9722
|
+
const useExtension = isOverflowDefaultBinArrayBitmap(minBinArrayIndex) || isOverflowDefaultBinArrayBitmap(maxBinArrayIndex);
|
|
9723
|
+
const binArrayBitmapExtension = useExtension ? deriveBinArrayBitmapExtension(this.pubkey, this.program.programId)[0] : null;
|
|
9724
|
+
const reserve = removeLiquidityForY ? reserveY : reserveX;
|
|
9725
|
+
const tokenMint = removeLiquidityForY ? tokenYMint : tokenXMint;
|
|
9726
|
+
const removeLiquiditySingleSideTx = await this.program.methods.removeLiquiditySingleSide().accounts({
|
|
9727
|
+
position,
|
|
9728
|
+
lbPair,
|
|
9729
|
+
binArrayBitmapExtension,
|
|
9730
|
+
userToken,
|
|
9731
|
+
reserve,
|
|
9732
|
+
tokenMint,
|
|
9733
|
+
binArrayLower,
|
|
9734
|
+
binArrayUpper,
|
|
9735
|
+
sender: user,
|
|
9736
|
+
tokenProgram: _spltoken.TOKEN_PROGRAM_ID
|
|
9737
|
+
}).preInstructions(preInstructions).transaction();
|
|
9738
|
+
const { blockhash, lastValidBlockHeight } = await this.program.provider.connection.getLatestBlockhash("confirmed");
|
|
9739
|
+
return new (0, _web3js.Transaction)({
|
|
9740
|
+
blockhash,
|
|
9741
|
+
lastValidBlockHeight,
|
|
9742
|
+
feePayer: user
|
|
9743
|
+
}).add(removeLiquiditySingleSideTx);
|
|
9744
|
+
}
|
|
9589
9745
|
/**
|
|
9590
9746
|
* The `closePosition` function closes a position
|
|
9591
9747
|
* @param
|
|
@@ -9597,7 +9753,7 @@ var DLMM = class {
|
|
|
9597
9753
|
owner,
|
|
9598
9754
|
position
|
|
9599
9755
|
}) {
|
|
9600
|
-
const { lowerBinId } = await this.program.account.
|
|
9756
|
+
const { lowerBinId } = await this.program.account.PositionV2.fetch(
|
|
9601
9757
|
position.publicKey
|
|
9602
9758
|
);
|
|
9603
9759
|
const lowerBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(lowerBinId));
|
|
@@ -9836,7 +9992,7 @@ var DLMM = class {
|
|
|
9836
9992
|
user,
|
|
9837
9993
|
binArraysPubkey
|
|
9838
9994
|
}) {
|
|
9839
|
-
const { tokenXMint, tokenYMint, reserveX, reserveY, activeId, oracle } = await this.program.account.
|
|
9995
|
+
const { tokenXMint, tokenYMint, reserveX, reserveY, activeId, oracle } = await this.program.account.LbPair.fetch(lbPair);
|
|
9840
9996
|
const preInstructions = [computeBudgetIx()];
|
|
9841
9997
|
const [
|
|
9842
9998
|
{ ataPubKey: userTokenIn, ix: createInTokenAccountIx },
|
|
@@ -9921,7 +10077,7 @@ var DLMM = class {
|
|
|
9921
10077
|
priceImpact,
|
|
9922
10078
|
binArraysPubkey
|
|
9923
10079
|
}) {
|
|
9924
|
-
const { tokenXMint, tokenYMint, reserveX, reserveY, activeId, oracle } = await this.program.account.
|
|
10080
|
+
const { tokenXMint, tokenYMint, reserveX, reserveY, activeId, oracle } = await this.program.account.LbPair.fetch(lbPair);
|
|
9925
10081
|
const preInstructions = [computeBudgetIx()];
|
|
9926
10082
|
const [
|
|
9927
10083
|
{ ataPubKey: userTokenIn, ix: createInTokenAccountIx },
|
|
@@ -10010,7 +10166,7 @@ var DLMM = class {
|
|
|
10010
10166
|
user,
|
|
10011
10167
|
binArraysPubkey
|
|
10012
10168
|
}) {
|
|
10013
|
-
const { tokenXMint, tokenYMint, reserveX, reserveY, activeId, oracle } = await this.program.account.
|
|
10169
|
+
const { tokenXMint, tokenYMint, reserveX, reserveY, activeId, oracle } = await this.program.account.LbPair.fetch(lbPair);
|
|
10014
10170
|
const preInstructions = [computeBudgetIx()];
|
|
10015
10171
|
const [
|
|
10016
10172
|
{ ataPubKey: userTokenIn, ix: createInTokenAccountIx },
|
|
@@ -10113,7 +10269,9 @@ var DLMM = class {
|
|
|
10113
10269
|
positions
|
|
10114
10270
|
}) {
|
|
10115
10271
|
const claimAllTxs = (await Promise.all(
|
|
10116
|
-
positions.filter(
|
|
10272
|
+
positions.filter(
|
|
10273
|
+
({ positionData: { rewardOne, rewardTwo } }) => !rewardOne.isZero() || !rewardTwo.isZero()
|
|
10274
|
+
).map(async (position, idx) => {
|
|
10117
10275
|
return await this.createClaimBuildMethod({
|
|
10118
10276
|
owner,
|
|
10119
10277
|
position,
|
|
@@ -10197,7 +10355,9 @@ var DLMM = class {
|
|
|
10197
10355
|
positions
|
|
10198
10356
|
}) {
|
|
10199
10357
|
const claimAllTxs = (await Promise.all(
|
|
10200
|
-
positions.filter(
|
|
10358
|
+
positions.filter(
|
|
10359
|
+
({ positionData: { feeX, feeY } }) => !feeX.isZero() || !feeY.isZero()
|
|
10360
|
+
).map(async (position, idx, positions2) => {
|
|
10201
10361
|
return await this.createClaimSwapFeeMethod({
|
|
10202
10362
|
owner,
|
|
10203
10363
|
position,
|
|
@@ -10492,6 +10652,34 @@ var DLMM = class {
|
|
|
10492
10652
|
addLiquidityIxs
|
|
10493
10653
|
};
|
|
10494
10654
|
}
|
|
10655
|
+
/**
|
|
10656
|
+
* Initializes bin arrays for the given bin array indexes if it wasn't initialized.
|
|
10657
|
+
*
|
|
10658
|
+
* @param {BN[]} binArrayIndexes - An array of bin array indexes to initialize.
|
|
10659
|
+
* @param {PublicKey} funder - The public key of the funder.
|
|
10660
|
+
* @return {Promise<TransactionInstruction[]>} An array of transaction instructions to initialize the bin arrays.
|
|
10661
|
+
*/
|
|
10662
|
+
async initializeBinArrays(binArrayIndexes, funder) {
|
|
10663
|
+
const ixs = [];
|
|
10664
|
+
for (const idx of binArrayIndexes) {
|
|
10665
|
+
const [binArray] = deriveBinArray(
|
|
10666
|
+
this.pubkey,
|
|
10667
|
+
idx,
|
|
10668
|
+
this.program.programId
|
|
10669
|
+
);
|
|
10670
|
+
const binArrayAccount = await this.program.provider.connection.getAccountInfo(binArray);
|
|
10671
|
+
if (binArrayAccount === null) {
|
|
10672
|
+
ixs.push(
|
|
10673
|
+
await this.program.methods.initializeBinArray(idx).accounts({
|
|
10674
|
+
binArray,
|
|
10675
|
+
funder,
|
|
10676
|
+
lbPair: this.pubkey
|
|
10677
|
+
}).instruction()
|
|
10678
|
+
);
|
|
10679
|
+
}
|
|
10680
|
+
}
|
|
10681
|
+
return ixs;
|
|
10682
|
+
}
|
|
10495
10683
|
/**
|
|
10496
10684
|
*
|
|
10497
10685
|
* @param
|
|
@@ -10591,7 +10779,9 @@ var DLMM = class {
|
|
|
10591
10779
|
);
|
|
10592
10780
|
createATAAccAndIx.forEach(({ ix }) => ix && preInstructions.push(ix));
|
|
10593
10781
|
const claimAllSwapFeeTxs = (await Promise.all(
|
|
10594
|
-
positions.filter(
|
|
10782
|
+
positions.filter(
|
|
10783
|
+
({ positionData: { feeX, feeY } }) => !feeX.isZero() || !feeY.isZero()
|
|
10784
|
+
).map(async (position) => {
|
|
10595
10785
|
return await this.createClaimSwapFeeMethod({
|
|
10596
10786
|
owner,
|
|
10597
10787
|
position,
|
|
@@ -10601,7 +10791,9 @@ var DLMM = class {
|
|
|
10601
10791
|
})
|
|
10602
10792
|
)).flat();
|
|
10603
10793
|
const claimAllLMTxs = (await Promise.all(
|
|
10604
|
-
positions.filter(
|
|
10794
|
+
positions.filter(
|
|
10795
|
+
({ positionData: { rewardOne, rewardTwo } }) => !rewardOne.isZero() || !rewardTwo.isZero()
|
|
10796
|
+
).map(async (position) => {
|
|
10605
10797
|
return await this.createClaimBuildMethod({
|
|
10606
10798
|
owner,
|
|
10607
10799
|
position,
|
|
@@ -10771,7 +10963,7 @@ var DLMM = class {
|
|
|
10771
10963
|
}
|
|
10772
10964
|
/** Private static method */
|
|
10773
10965
|
static async getBinArrays(program, lbPairPubkey) {
|
|
10774
|
-
return program.account.
|
|
10966
|
+
return program.account.BinArray.all([
|
|
10775
10967
|
{
|
|
10776
10968
|
memcmp: {
|
|
10777
10969
|
bytes: _bytes.bs58.encode(lbPairPubkey.toBuffer()),
|
|
@@ -10800,7 +10992,7 @@ var DLMM = class {
|
|
|
10800
10992
|
upperBinArrayIdx,
|
|
10801
10993
|
program.programId
|
|
10802
10994
|
);
|
|
10803
|
-
[_lowerBinArray, _upperBinArray] = await program.account.
|
|
10995
|
+
[_lowerBinArray, _upperBinArray] = await program.account.BinArray.fetchMultiple([
|
|
10804
10996
|
lowerBinArray2,
|
|
10805
10997
|
upperBinArray2
|
|
10806
10998
|
]);
|
|
@@ -10871,7 +11063,7 @@ var DLMM = class {
|
|
|
10871
11063
|
upperBinArrayIdx,
|
|
10872
11064
|
program.programId
|
|
10873
11065
|
);
|
|
10874
|
-
[_lowerBinArray, _upperBinArray] = await program.account.
|
|
11066
|
+
[_lowerBinArray, _upperBinArray] = await program.account.BinArray.fetchMultiple([
|
|
10875
11067
|
lowerBinArray2,
|
|
10876
11068
|
upperBinArray2
|
|
10877
11069
|
]);
|
|
@@ -11076,7 +11268,7 @@ var DLMM = class {
|
|
|
11076
11268
|
lowerBinArrayIndex,
|
|
11077
11269
|
this.program.programId
|
|
11078
11270
|
);
|
|
11079
|
-
const binArray = await _asyncNullishCoalesce(lowerBinArrays, async () => ( await this.program.account.
|
|
11271
|
+
const binArray = await _asyncNullishCoalesce(lowerBinArrays, async () => ( await this.program.account.BinArray.fetch(binArrayPubKey).catch(() => {
|
|
11080
11272
|
const [lowerBinId2, upperBinId2] = getBinArrayLowerUpperBinId(lowerBinArrayIndex);
|
|
11081
11273
|
const binArrayBins = [];
|
|
11082
11274
|
for (let i = lowerBinId2.toNumber(); i <= upperBinId2.toNumber(); i++) {
|
|
@@ -11131,7 +11323,7 @@ var DLMM = class {
|
|
|
11131
11323
|
);
|
|
11132
11324
|
const binArrays = await (async () => {
|
|
11133
11325
|
if (!lowerBinArrays || !upperBinArrays) {
|
|
11134
|
-
return (await this.program.account.
|
|
11326
|
+
return (await this.program.account.BinArray.fetchMultiple([
|
|
11135
11327
|
lowerBinArrayPubKey,
|
|
11136
11328
|
upperBinArrayPubKey
|
|
11137
11329
|
])).filter((binArray) => binArray !== null);
|
|
@@ -11471,5 +11663,6 @@ var src_default = DLMM;
|
|
|
11471
11663
|
|
|
11472
11664
|
|
|
11473
11665
|
|
|
11474
|
-
|
|
11666
|
+
|
|
11667
|
+
exports.ADMIN = ADMIN; exports.BASIS_POINT_MAX = BASIS_POINT_MAX; exports.BIN_ARRAY_BITMAP_SIZE = BIN_ARRAY_BITMAP_SIZE; exports.BIN_ARRAY_FEE = BIN_ARRAY_FEE; exports.BitmapType = BitmapType; exports.DLMMError = DLMMError; exports.EXTENSION_BINARRAY_BITMAP_SIZE = EXTENSION_BINARRAY_BITMAP_SIZE; exports.FEE_PRECISION = FEE_PRECISION; exports.IDL = IDL; exports.LBCLMM_PROGRAM_IDS = LBCLMM_PROGRAM_IDS; exports.MAX_ACTIVE_BIN_SLIPPAGE = MAX_ACTIVE_BIN_SLIPPAGE; exports.MAX_BIN_ARRAY_SIZE = MAX_BIN_ARRAY_SIZE; exports.MAX_BIN_LENGTH_ALLOWED_IN_ONE_TX = MAX_BIN_LENGTH_ALLOWED_IN_ONE_TX; exports.MAX_BIN_PER_POSITION = MAX_BIN_PER_POSITION; exports.MAX_BIN_PER_TX = MAX_BIN_PER_TX; exports.MAX_CLAIM_ALL_ALLOWED = MAX_CLAIM_ALL_ALLOWED; exports.MAX_FEE_RATE = MAX_FEE_RATE; exports.Network = Network; exports.POSITION_FEE = POSITION_FEE; exports.PRECISION = PRECISION; exports.PairType = PairType; exports.PositionVersion = PositionVersion; exports.SCALE = SCALE; exports.SCALE_OFFSET = SCALE_OFFSET; exports.SIMULATION_USER = SIMULATION_USER; exports.Strategy = Strategy; exports.StrategyType = StrategyType; exports.autoFillXByStrategy = autoFillXByStrategy; exports.autoFillXByWeight = autoFillXByWeight; exports.autoFillYByStrategy = autoFillYByStrategy; exports.autoFillYByWeight = autoFillYByWeight; exports.binIdToBinArrayIndex = binIdToBinArrayIndex; exports.calculateBidAskDistribution = calculateBidAskDistribution; exports.calculateNormalDistribution = calculateNormalDistribution; exports.calculateSpotDistribution = calculateSpotDistribution; exports.chunkedFetchMultipleBinArrayBitmapExtensionAccount = chunkedFetchMultipleBinArrayBitmapExtensionAccount; exports.chunkedFetchMultiplePoolAccount = chunkedFetchMultiplePoolAccount; exports.chunkedGetMultipleAccountInfos = chunkedGetMultipleAccountInfos; exports.chunks = chunks; exports.computeBudgetIx = computeBudgetIx; exports.computeFee = computeFee; exports.computeFeeFromAmount = computeFeeFromAmount; exports.computeProtocolFee = computeProtocolFee; exports.default = src_default; exports.deriveBinArray = deriveBinArray; exports.deriveBinArrayBitmapExtension = deriveBinArrayBitmapExtension; exports.deriveLbPair = deriveLbPair; exports.deriveLbPair2 = deriveLbPair2; exports.deriveOracle = deriveOracle; exports.derivePermissionLbPair = derivePermissionLbPair; exports.derivePosition = derivePosition; exports.derivePresetParameter = derivePresetParameter; exports.derivePresetParameter2 = derivePresetParameter2; exports.deriveReserve = deriveReserve; exports.findNextBinArrayIndexWithLiquidity = findNextBinArrayIndexWithLiquidity; exports.findNextBinArrayWithLiquidity = findNextBinArrayWithLiquidity; exports.fromWeightDistributionToAmount = fromWeightDistributionToAmount; exports.fromWeightDistributionToAmountOneSide = fromWeightDistributionToAmountOneSide; exports.getBaseFee = getBaseFee; exports.getBinArrayLowerUpperBinId = getBinArrayLowerUpperBinId; exports.getBinArraysRequiredByPositionRange = getBinArraysRequiredByPositionRange; exports.getBinFromBinArray = getBinFromBinArray; exports.getOrCreateATAInstruction = getOrCreateATAInstruction; exports.getOutAmount = getOutAmount; exports.getPriceOfBinByBinId = getPriceOfBinByBinId; exports.getTokenBalance = getTokenBalance; exports.getTokenDecimals = getTokenDecimals; exports.getTokensMintFromPoolAddress = getTokensMintFromPoolAddress; exports.getTotalFee = getTotalFee; exports.getVariableFee = getVariableFee; exports.isBinIdWithinBinArray = isBinIdWithinBinArray; exports.isOverflowDefaultBinArrayBitmap = isOverflowDefaultBinArrayBitmap; exports.parseLogs = parseLogs; exports.swapExactInQuoteAtBin = swapExactInQuoteAtBin; exports.swapExactOutQuoteAtBin = swapExactOutQuoteAtBin; exports.toAmountAskSide = toAmountAskSide; exports.toAmountBidSide = toAmountBidSide; exports.toAmountBothSide = toAmountBothSide; exports.toAmountsBothSideByStrategy = toAmountsBothSideByStrategy; exports.toAmountsOneSideByStrategy = toAmountsOneSideByStrategy; exports.toStrategyParameters = toStrategyParameters; exports.toWeightDistribution = toWeightDistribution; exports.unwrapSOLInstruction = unwrapSOLInstruction; exports.wrapSOLInstruction = wrapSOLInstruction;
|
|
11475
11668
|
//# sourceMappingURL=index.js.map
|