@meteora-ag/dlmm 1.3.13-rc.5 → 1.3.14-sam.0
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 +94 -159
- package/dist/index.js +531 -413
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +535 -417
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -25,7 +25,7 @@ var _decimaljs = require('decimal.js'); var _decimaljs2 = _interopRequireDefault
|
|
|
25
25
|
|
|
26
26
|
// src/dlmm/idl.ts
|
|
27
27
|
var IDL = {
|
|
28
|
-
"version": "0.8.
|
|
28
|
+
"version": "0.8.2",
|
|
29
29
|
"name": "lb_clmm",
|
|
30
30
|
"constants": [
|
|
31
31
|
{
|
|
@@ -113,16 +113,6 @@ var IDL = {
|
|
|
113
113
|
},
|
|
114
114
|
"value": "15"
|
|
115
115
|
},
|
|
116
|
-
{
|
|
117
|
-
"name": "ILM_PROTOCOL_SHARE",
|
|
118
|
-
"type": "u16",
|
|
119
|
-
"value": "2000"
|
|
120
|
-
},
|
|
121
|
-
{
|
|
122
|
-
"name": "PROTOCOL_SHARE",
|
|
123
|
-
"type": "u16",
|
|
124
|
-
"value": "500"
|
|
125
|
-
},
|
|
126
116
|
{
|
|
127
117
|
"name": "MAX_BIN_STEP",
|
|
128
118
|
"type": "u16",
|
|
@@ -395,7 +385,7 @@ var IDL = {
|
|
|
395
385
|
"isSigner": false
|
|
396
386
|
},
|
|
397
387
|
{
|
|
398
|
-
"name": "
|
|
388
|
+
"name": "rent",
|
|
399
389
|
"isMut": false,
|
|
400
390
|
"isSigner": false
|
|
401
391
|
},
|
|
@@ -1974,40 +1964,7 @@ var IDL = {
|
|
|
1974
1964
|
"args": []
|
|
1975
1965
|
},
|
|
1976
1966
|
{
|
|
1977
|
-
"name": "
|
|
1978
|
-
"accounts": [
|
|
1979
|
-
{
|
|
1980
|
-
"name": "lbPair",
|
|
1981
|
-
"isMut": true,
|
|
1982
|
-
"isSigner": false
|
|
1983
|
-
},
|
|
1984
|
-
{
|
|
1985
|
-
"name": "admin",
|
|
1986
|
-
"isMut": false,
|
|
1987
|
-
"isSigner": true
|
|
1988
|
-
},
|
|
1989
|
-
{
|
|
1990
|
-
"name": "eventAuthority",
|
|
1991
|
-
"isMut": false,
|
|
1992
|
-
"isSigner": false
|
|
1993
|
-
},
|
|
1994
|
-
{
|
|
1995
|
-
"name": "program",
|
|
1996
|
-
"isMut": false,
|
|
1997
|
-
"isSigner": false
|
|
1998
|
-
}
|
|
1999
|
-
],
|
|
2000
|
-
"args": [
|
|
2001
|
-
{
|
|
2002
|
-
"name": "feeParameter",
|
|
2003
|
-
"type": {
|
|
2004
|
-
"defined": "BaseFeeParameter"
|
|
2005
|
-
}
|
|
2006
|
-
}
|
|
2007
|
-
]
|
|
2008
|
-
},
|
|
2009
|
-
{
|
|
2010
|
-
"name": "updateDynamicFeeParameters",
|
|
1967
|
+
"name": "updateFeeParameters",
|
|
2011
1968
|
"accounts": [
|
|
2012
1969
|
{
|
|
2013
1970
|
"name": "lbPair",
|
|
@@ -2034,7 +1991,7 @@ var IDL = {
|
|
|
2034
1991
|
{
|
|
2035
1992
|
"name": "feeParameter",
|
|
2036
1993
|
"type": {
|
|
2037
|
-
"defined": "
|
|
1994
|
+
"defined": "FeeParameter"
|
|
2038
1995
|
}
|
|
2039
1996
|
}
|
|
2040
1997
|
]
|
|
@@ -2217,7 +2174,7 @@ var IDL = {
|
|
|
2217
2174
|
"args": []
|
|
2218
2175
|
},
|
|
2219
2176
|
{
|
|
2220
|
-
"name": "
|
|
2177
|
+
"name": "togglePairStatus",
|
|
2221
2178
|
"accounts": [
|
|
2222
2179
|
{
|
|
2223
2180
|
"name": "lbPair",
|
|
@@ -2230,12 +2187,7 @@ var IDL = {
|
|
|
2230
2187
|
"isSigner": true
|
|
2231
2188
|
}
|
|
2232
2189
|
],
|
|
2233
|
-
"args": [
|
|
2234
|
-
{
|
|
2235
|
-
"name": "status",
|
|
2236
|
-
"type": "u8"
|
|
2237
|
-
}
|
|
2238
|
-
]
|
|
2190
|
+
"args": []
|
|
2239
2191
|
},
|
|
2240
2192
|
{
|
|
2241
2193
|
"name": "migratePosition",
|
|
@@ -3496,7 +3448,7 @@ var IDL = {
|
|
|
3496
3448
|
}
|
|
3497
3449
|
},
|
|
3498
3450
|
{
|
|
3499
|
-
"name": "
|
|
3451
|
+
"name": "FeeParameter",
|
|
3500
3452
|
"type": {
|
|
3501
3453
|
"kind": "struct",
|
|
3502
3454
|
"fields": [
|
|
@@ -3517,49 +3469,6 @@ var IDL = {
|
|
|
3517
3469
|
]
|
|
3518
3470
|
}
|
|
3519
3471
|
},
|
|
3520
|
-
{
|
|
3521
|
-
"name": "DynamicFeeParameter",
|
|
3522
|
-
"type": {
|
|
3523
|
-
"kind": "struct",
|
|
3524
|
-
"fields": [
|
|
3525
|
-
{
|
|
3526
|
-
"name": "filterPeriod",
|
|
3527
|
-
"docs": [
|
|
3528
|
-
"Filter period determine high frequency trading time window."
|
|
3529
|
-
],
|
|
3530
|
-
"type": "u16"
|
|
3531
|
-
},
|
|
3532
|
-
{
|
|
3533
|
-
"name": "decayPeriod",
|
|
3534
|
-
"docs": [
|
|
3535
|
-
"Decay period determine when the volatile fee start decay / decrease."
|
|
3536
|
-
],
|
|
3537
|
-
"type": "u16"
|
|
3538
|
-
},
|
|
3539
|
-
{
|
|
3540
|
-
"name": "reductionFactor",
|
|
3541
|
-
"docs": [
|
|
3542
|
-
"Reduction factor controls the volatile fee rate decrement rate."
|
|
3543
|
-
],
|
|
3544
|
-
"type": "u16"
|
|
3545
|
-
},
|
|
3546
|
-
{
|
|
3547
|
-
"name": "variableFeeControl",
|
|
3548
|
-
"docs": [
|
|
3549
|
-
"Used to scale the variable fee component depending on the dynamic of the market"
|
|
3550
|
-
],
|
|
3551
|
-
"type": "u32"
|
|
3552
|
-
},
|
|
3553
|
-
{
|
|
3554
|
-
"name": "maxVolatilityAccumulator",
|
|
3555
|
-
"docs": [
|
|
3556
|
-
"Maximum number of bin crossed can be accumulated. Used to cap volatile fee rate."
|
|
3557
|
-
],
|
|
3558
|
-
"type": "u32"
|
|
3559
|
-
}
|
|
3560
|
-
]
|
|
3561
|
-
}
|
|
3562
|
-
},
|
|
3563
3472
|
{
|
|
3564
3473
|
"name": "LiquidityParameterByStrategyOneSide",
|
|
3565
3474
|
"type": {
|
|
@@ -4925,41 +4834,6 @@ var IDL = {
|
|
|
4925
4834
|
}
|
|
4926
4835
|
]
|
|
4927
4836
|
},
|
|
4928
|
-
{
|
|
4929
|
-
"name": "DynamicFeeParameterUpdate",
|
|
4930
|
-
"fields": [
|
|
4931
|
-
{
|
|
4932
|
-
"name": "lbPair",
|
|
4933
|
-
"type": "publicKey",
|
|
4934
|
-
"index": false
|
|
4935
|
-
},
|
|
4936
|
-
{
|
|
4937
|
-
"name": "filterPeriod",
|
|
4938
|
-
"type": "u16",
|
|
4939
|
-
"index": false
|
|
4940
|
-
},
|
|
4941
|
-
{
|
|
4942
|
-
"name": "decayPeriod",
|
|
4943
|
-
"type": "u16",
|
|
4944
|
-
"index": false
|
|
4945
|
-
},
|
|
4946
|
-
{
|
|
4947
|
-
"name": "reductionFactor",
|
|
4948
|
-
"type": "u16",
|
|
4949
|
-
"index": false
|
|
4950
|
-
},
|
|
4951
|
-
{
|
|
4952
|
-
"name": "variableFeeControl",
|
|
4953
|
-
"type": "u32",
|
|
4954
|
-
"index": false
|
|
4955
|
-
},
|
|
4956
|
-
{
|
|
4957
|
-
"name": "maxVolatilityAccumulator",
|
|
4958
|
-
"type": "u32",
|
|
4959
|
-
"index": false
|
|
4960
|
-
}
|
|
4961
|
-
]
|
|
4962
|
-
},
|
|
4963
4837
|
{
|
|
4964
4838
|
"name": "IncreaseObservation",
|
|
4965
4839
|
"fields": [
|
|
@@ -5396,11 +5270,6 @@ var IDL = {
|
|
|
5396
5270
|
"code": 6065,
|
|
5397
5271
|
"name": "AlreadyPassPreActivationSwapPoint",
|
|
5398
5272
|
"msg": "Already pass pre-activation swap point"
|
|
5399
|
-
},
|
|
5400
|
-
{
|
|
5401
|
-
"code": 6066,
|
|
5402
|
-
"name": "InvalidStatus",
|
|
5403
|
-
"msg": "Invalid status"
|
|
5404
5273
|
}
|
|
5405
5274
|
]
|
|
5406
5275
|
};
|
|
@@ -6472,42 +6341,13 @@ function generateBinAmount(amount, binStep, binId, tokenXDecimal, tokenYDecimal,
|
|
|
6472
6341
|
return new (0, _anchor.BN)(c1.sub(c0).floor().toString());
|
|
6473
6342
|
}
|
|
6474
6343
|
|
|
6475
|
-
// src/dlmm/helpers/
|
|
6344
|
+
// src/dlmm/helpers/index.ts
|
|
6345
|
+
var _helpers = require('@solana-developers/helpers');
|
|
6476
6346
|
|
|
6347
|
+
// src/dlmm/helpers/computeUnit.ts
|
|
6477
6348
|
var DEFAULT_ADD_LIQUIDITY_CU = 8e5;
|
|
6478
6349
|
var MIN_CU_BUFFER = 5e4;
|
|
6479
6350
|
var MAX_CU_BUFFER = 2e5;
|
|
6480
|
-
var getSimulationComputeUnits = async (connection, instructions, payer, lookupTables, commitment = "confirmed") => {
|
|
6481
|
-
const testInstructions = [
|
|
6482
|
-
// Set an arbitrarily high number in simulation
|
|
6483
|
-
// so we can be sure the transaction will succeed
|
|
6484
|
-
// and get the real compute units used
|
|
6485
|
-
_web3js.ComputeBudgetProgram.setComputeUnitLimit({ units: 14e5 }),
|
|
6486
|
-
...instructions
|
|
6487
|
-
];
|
|
6488
|
-
const testTransaction = new (0, _web3js.VersionedTransaction)(
|
|
6489
|
-
new (0, _web3js.TransactionMessage)({
|
|
6490
|
-
instructions: testInstructions,
|
|
6491
|
-
payerKey: payer,
|
|
6492
|
-
// RecentBlockhash can by any public key during simulation
|
|
6493
|
-
// since 'replaceRecentBlockhash' is set to 'true' below
|
|
6494
|
-
recentBlockhash: _web3js.PublicKey.default.toString()
|
|
6495
|
-
}).compileToV0Message(lookupTables)
|
|
6496
|
-
);
|
|
6497
|
-
const rpcResponse = await connection.simulateTransaction(testTransaction, {
|
|
6498
|
-
replaceRecentBlockhash: true,
|
|
6499
|
-
sigVerify: false,
|
|
6500
|
-
commitment
|
|
6501
|
-
});
|
|
6502
|
-
if (_optionalChain([rpcResponse, 'optionalAccess', _21 => _21.value, 'optionalAccess', _22 => _22.err])) {
|
|
6503
|
-
const logs = _optionalChain([rpcResponse, 'access', _23 => _23.value, 'access', _24 => _24.logs, 'optionalAccess', _25 => _25.join, 'call', _26 => _26("\n \u2022 ")]) || "No logs available";
|
|
6504
|
-
throw new Error(
|
|
6505
|
-
`Transaction simulation failed:
|
|
6506
|
-
\u2022${logs}` + JSON.stringify(_optionalChain([rpcResponse, 'optionalAccess', _27 => _27.value, 'optionalAccess', _28 => _28.err]))
|
|
6507
|
-
);
|
|
6508
|
-
}
|
|
6509
|
-
return rpcResponse.value.unitsConsumed || null;
|
|
6510
|
-
};
|
|
6511
6351
|
|
|
6512
6352
|
// src/dlmm/helpers/derive.ts
|
|
6513
6353
|
|
|
@@ -6644,6 +6484,9 @@ var PairType = /* @__PURE__ */ ((PairType2) => {
|
|
|
6644
6484
|
return PairType2;
|
|
6645
6485
|
})(PairType || {});
|
|
6646
6486
|
var Strategy = {
|
|
6487
|
+
SpotOneSide: { spotOneSide: {} },
|
|
6488
|
+
CurveOneSide: { curveOneSide: {} },
|
|
6489
|
+
BidAskOneSide: { bidAskOneSide: {} },
|
|
6647
6490
|
SpotBalanced: { spotBalanced: {} },
|
|
6648
6491
|
CurveBalanced: { curveBalanced: {} },
|
|
6649
6492
|
BidAskBalanced: { bidAskBalanced: {} },
|
|
@@ -6652,12 +6495,15 @@ var Strategy = {
|
|
|
6652
6495
|
BidAskImBalanced: { bidAskImBalanced: {} }
|
|
6653
6496
|
};
|
|
6654
6497
|
var StrategyType = /* @__PURE__ */ ((StrategyType2) => {
|
|
6655
|
-
StrategyType2[StrategyType2["
|
|
6656
|
-
StrategyType2[StrategyType2["
|
|
6657
|
-
StrategyType2[StrategyType2["
|
|
6658
|
-
StrategyType2[StrategyType2["
|
|
6659
|
-
StrategyType2[StrategyType2["
|
|
6660
|
-
StrategyType2[StrategyType2["
|
|
6498
|
+
StrategyType2[StrategyType2["SpotOneSide"] = 0] = "SpotOneSide";
|
|
6499
|
+
StrategyType2[StrategyType2["CurveOneSide"] = 1] = "CurveOneSide";
|
|
6500
|
+
StrategyType2[StrategyType2["BidAskOneSide"] = 2] = "BidAskOneSide";
|
|
6501
|
+
StrategyType2[StrategyType2["SpotImBalanced"] = 3] = "SpotImBalanced";
|
|
6502
|
+
StrategyType2[StrategyType2["CurveImBalanced"] = 4] = "CurveImBalanced";
|
|
6503
|
+
StrategyType2[StrategyType2["BidAskImBalanced"] = 5] = "BidAskImBalanced";
|
|
6504
|
+
StrategyType2[StrategyType2["SpotBalanced"] = 6] = "SpotBalanced";
|
|
6505
|
+
StrategyType2[StrategyType2["CurveBalanced"] = 7] = "CurveBalanced";
|
|
6506
|
+
StrategyType2[StrategyType2["BidAskBalanced"] = 8] = "BidAskBalanced";
|
|
6661
6507
|
return StrategyType2;
|
|
6662
6508
|
})(StrategyType || {});
|
|
6663
6509
|
var ActivationType = /* @__PURE__ */ ((ActivationType2) => {
|
|
@@ -7209,10 +7055,53 @@ function toWeightBidAsk(minBinId, maxBinId, activeId) {
|
|
|
7209
7055
|
}
|
|
7210
7056
|
return distributions;
|
|
7211
7057
|
}
|
|
7058
|
+
function toAmountsOneSideByStrategy(activeId, binStep, minBinId, maxBinId, amount, strategyType, depositForY) {
|
|
7059
|
+
let weights = [];
|
|
7060
|
+
switch (strategyType) {
|
|
7061
|
+
case 6 /* SpotBalanced */:
|
|
7062
|
+
case 7 /* CurveBalanced */:
|
|
7063
|
+
case 8 /* BidAskBalanced */:
|
|
7064
|
+
case 3 /* SpotImBalanced */:
|
|
7065
|
+
case 4 /* CurveImBalanced */:
|
|
7066
|
+
case 5 /* BidAskImBalanced */: {
|
|
7067
|
+
throw "Invalid Strategy Parameters";
|
|
7068
|
+
}
|
|
7069
|
+
case 0 /* SpotOneSide */: {
|
|
7070
|
+
weights = toWeightSpotBalanced(minBinId, maxBinId);
|
|
7071
|
+
break;
|
|
7072
|
+
}
|
|
7073
|
+
case 1 /* CurveOneSide */: {
|
|
7074
|
+
if (depositForY) {
|
|
7075
|
+
weights = toWeightAscendingOrder(minBinId, maxBinId);
|
|
7076
|
+
} else {
|
|
7077
|
+
weights = toWeightDecendingOrder(minBinId, maxBinId);
|
|
7078
|
+
}
|
|
7079
|
+
break;
|
|
7080
|
+
}
|
|
7081
|
+
case 2 /* BidAskOneSide */: {
|
|
7082
|
+
if (depositForY) {
|
|
7083
|
+
weights = toWeightDecendingOrder(minBinId, maxBinId);
|
|
7084
|
+
} else {
|
|
7085
|
+
weights = toWeightAscendingOrder(minBinId, maxBinId);
|
|
7086
|
+
}
|
|
7087
|
+
break;
|
|
7088
|
+
}
|
|
7089
|
+
}
|
|
7090
|
+
if (depositForY) {
|
|
7091
|
+
return toAmountBidSide(activeId, amount, weights);
|
|
7092
|
+
} else {
|
|
7093
|
+
return toAmountAskSide(activeId, binStep, amount, weights);
|
|
7094
|
+
}
|
|
7095
|
+
}
|
|
7212
7096
|
function toAmountsBothSideByStrategy(activeId, binStep, minBinId, maxBinId, amountX, amountY, amountXInActiveBin, amountYInActiveBin, strategyType) {
|
|
7213
7097
|
const isSingleSideX = amountY.isZero();
|
|
7214
7098
|
switch (strategyType) {
|
|
7215
|
-
case 0 /*
|
|
7099
|
+
case 0 /* SpotOneSide */:
|
|
7100
|
+
case 1 /* CurveOneSide */:
|
|
7101
|
+
case 2 /* BidAskOneSide */: {
|
|
7102
|
+
throw "Invalid Strategy Parameters";
|
|
7103
|
+
}
|
|
7104
|
+
case 3 /* SpotImBalanced */: {
|
|
7216
7105
|
if (activeId < minBinId || activeId > maxBinId) {
|
|
7217
7106
|
const weights = toWeightSpotBalanced(minBinId, maxBinId);
|
|
7218
7107
|
return toAmountBothSide(
|
|
@@ -7284,7 +7173,7 @@ function toAmountsBothSideByStrategy(activeId, binStep, minBinId, maxBinId, amou
|
|
|
7284
7173
|
}
|
|
7285
7174
|
return amountsInBin;
|
|
7286
7175
|
}
|
|
7287
|
-
case
|
|
7176
|
+
case 4 /* CurveImBalanced */: {
|
|
7288
7177
|
if (activeId < minBinId) {
|
|
7289
7178
|
let weights = toWeightDecendingOrder(minBinId, maxBinId);
|
|
7290
7179
|
return toAmountBothSide(
|
|
@@ -7368,7 +7257,7 @@ function toAmountsBothSideByStrategy(activeId, binStep, minBinId, maxBinId, amou
|
|
|
7368
7257
|
}
|
|
7369
7258
|
return amountsInBin;
|
|
7370
7259
|
}
|
|
7371
|
-
case
|
|
7260
|
+
case 5 /* BidAskImBalanced */: {
|
|
7372
7261
|
if (activeId < minBinId) {
|
|
7373
7262
|
const weights = toWeightAscendingOrder(minBinId, maxBinId);
|
|
7374
7263
|
return toAmountBothSide(
|
|
@@ -7452,7 +7341,7 @@ function toAmountsBothSideByStrategy(activeId, binStep, minBinId, maxBinId, amou
|
|
|
7452
7341
|
}
|
|
7453
7342
|
return amountsInBin;
|
|
7454
7343
|
}
|
|
7455
|
-
case
|
|
7344
|
+
case 6 /* SpotBalanced */: {
|
|
7456
7345
|
let weights = toWeightSpotBalanced(minBinId, maxBinId);
|
|
7457
7346
|
return toAmountBothSide(
|
|
7458
7347
|
activeId,
|
|
@@ -7464,7 +7353,7 @@ function toAmountsBothSideByStrategy(activeId, binStep, minBinId, maxBinId, amou
|
|
|
7464
7353
|
weights
|
|
7465
7354
|
);
|
|
7466
7355
|
}
|
|
7467
|
-
case
|
|
7356
|
+
case 7 /* CurveBalanced */: {
|
|
7468
7357
|
let weights = toWeightCurve(minBinId, maxBinId, activeId);
|
|
7469
7358
|
return toAmountBothSide(
|
|
7470
7359
|
activeId,
|
|
@@ -7476,7 +7365,7 @@ function toAmountsBothSideByStrategy(activeId, binStep, minBinId, maxBinId, amou
|
|
|
7476
7365
|
weights
|
|
7477
7366
|
);
|
|
7478
7367
|
}
|
|
7479
|
-
case
|
|
7368
|
+
case 8 /* BidAskBalanced */: {
|
|
7480
7369
|
let weights = toWeightBidAsk(minBinId, maxBinId, activeId);
|
|
7481
7370
|
return toAmountBothSide(
|
|
7482
7371
|
activeId,
|
|
@@ -7492,12 +7381,15 @@ function toAmountsBothSideByStrategy(activeId, binStep, minBinId, maxBinId, amou
|
|
|
7492
7381
|
}
|
|
7493
7382
|
function autoFillYByStrategy(activeId, binStep, amountX, amountXInActiveBin, amountYInActiveBin, minBinId, maxBinId, strategyType) {
|
|
7494
7383
|
switch (strategyType) {
|
|
7495
|
-
case 0 /*
|
|
7496
|
-
case 1 /*
|
|
7497
|
-
case 2 /*
|
|
7384
|
+
case 0 /* SpotOneSide */:
|
|
7385
|
+
case 1 /* CurveOneSide */:
|
|
7386
|
+
case 2 /* BidAskOneSide */:
|
|
7387
|
+
case 3 /* SpotImBalanced */:
|
|
7388
|
+
case 4 /* CurveImBalanced */:
|
|
7389
|
+
case 5 /* BidAskImBalanced */: {
|
|
7498
7390
|
throw "Invalid Strategy Parameters";
|
|
7499
7391
|
}
|
|
7500
|
-
case
|
|
7392
|
+
case 6 /* SpotBalanced */: {
|
|
7501
7393
|
let weights = toWeightSpotBalanced(minBinId, maxBinId);
|
|
7502
7394
|
return autoFillYByWeight(
|
|
7503
7395
|
activeId,
|
|
@@ -7508,7 +7400,7 @@ function autoFillYByStrategy(activeId, binStep, amountX, amountXInActiveBin, amo
|
|
|
7508
7400
|
weights
|
|
7509
7401
|
);
|
|
7510
7402
|
}
|
|
7511
|
-
case
|
|
7403
|
+
case 7 /* CurveBalanced */: {
|
|
7512
7404
|
let weights = toWeightCurve(minBinId, maxBinId, activeId);
|
|
7513
7405
|
return autoFillYByWeight(
|
|
7514
7406
|
activeId,
|
|
@@ -7519,7 +7411,7 @@ function autoFillYByStrategy(activeId, binStep, amountX, amountXInActiveBin, amo
|
|
|
7519
7411
|
weights
|
|
7520
7412
|
);
|
|
7521
7413
|
}
|
|
7522
|
-
case
|
|
7414
|
+
case 8 /* BidAskBalanced */: {
|
|
7523
7415
|
let weights = toWeightBidAsk(minBinId, maxBinId, activeId);
|
|
7524
7416
|
return autoFillYByWeight(
|
|
7525
7417
|
activeId,
|
|
@@ -7534,12 +7426,15 @@ function autoFillYByStrategy(activeId, binStep, amountX, amountXInActiveBin, amo
|
|
|
7534
7426
|
}
|
|
7535
7427
|
function autoFillXByStrategy(activeId, binStep, amountY, amountXInActiveBin, amountYInActiveBin, minBinId, maxBinId, strategyType) {
|
|
7536
7428
|
switch (strategyType) {
|
|
7537
|
-
case 0 /*
|
|
7538
|
-
case 1 /*
|
|
7539
|
-
case 2 /*
|
|
7429
|
+
case 0 /* SpotOneSide */:
|
|
7430
|
+
case 1 /* CurveOneSide */:
|
|
7431
|
+
case 2 /* BidAskOneSide */:
|
|
7432
|
+
case 3 /* SpotImBalanced */:
|
|
7433
|
+
case 4 /* CurveImBalanced */:
|
|
7434
|
+
case 5 /* BidAskImBalanced */: {
|
|
7540
7435
|
throw "Invalid Strategy Parameters";
|
|
7541
7436
|
}
|
|
7542
|
-
case
|
|
7437
|
+
case 6 /* SpotBalanced */: {
|
|
7543
7438
|
let weights = toWeightSpotBalanced(minBinId, maxBinId);
|
|
7544
7439
|
return autoFillXByWeight(
|
|
7545
7440
|
activeId,
|
|
@@ -7550,7 +7445,7 @@ function autoFillXByStrategy(activeId, binStep, amountY, amountXInActiveBin, amo
|
|
|
7550
7445
|
weights
|
|
7551
7446
|
);
|
|
7552
7447
|
}
|
|
7553
|
-
case
|
|
7448
|
+
case 7 /* CurveBalanced */: {
|
|
7554
7449
|
let weights = toWeightCurve(minBinId, maxBinId, activeId);
|
|
7555
7450
|
return autoFillXByWeight(
|
|
7556
7451
|
activeId,
|
|
@@ -7561,7 +7456,7 @@ function autoFillXByStrategy(activeId, binStep, amountY, amountXInActiveBin, amo
|
|
|
7561
7456
|
weights
|
|
7562
7457
|
);
|
|
7563
7458
|
}
|
|
7564
|
-
case
|
|
7459
|
+
case 8 /* BidAskBalanced */: {
|
|
7565
7460
|
let weights = toWeightBidAsk(minBinId, maxBinId, activeId);
|
|
7566
7461
|
return autoFillXByWeight(
|
|
7567
7462
|
activeId,
|
|
@@ -7582,7 +7477,31 @@ function toStrategyParameters({
|
|
|
7582
7477
|
}) {
|
|
7583
7478
|
const parameters = [singleSidedX ? 1 : 0, ...new Array(63).fill(0)];
|
|
7584
7479
|
switch (strategyType) {
|
|
7585
|
-
case
|
|
7480
|
+
case 0 /* SpotOneSide */: {
|
|
7481
|
+
return {
|
|
7482
|
+
minBinId,
|
|
7483
|
+
maxBinId,
|
|
7484
|
+
strategyType: { spotOneSide: {} },
|
|
7485
|
+
parameteres: Buffer.from(parameters).toJSON().data
|
|
7486
|
+
};
|
|
7487
|
+
}
|
|
7488
|
+
case 1 /* CurveOneSide */: {
|
|
7489
|
+
return {
|
|
7490
|
+
minBinId,
|
|
7491
|
+
maxBinId,
|
|
7492
|
+
strategyType: { curveOneSide: {} },
|
|
7493
|
+
parameteres: Buffer.from(parameters).toJSON().data
|
|
7494
|
+
};
|
|
7495
|
+
}
|
|
7496
|
+
case 2 /* BidAskOneSide */: {
|
|
7497
|
+
return {
|
|
7498
|
+
minBinId,
|
|
7499
|
+
maxBinId,
|
|
7500
|
+
strategyType: { bidAskOneSide: {} },
|
|
7501
|
+
parameteres: Buffer.from(parameters).toJSON().data
|
|
7502
|
+
};
|
|
7503
|
+
}
|
|
7504
|
+
case 6 /* SpotBalanced */: {
|
|
7586
7505
|
return {
|
|
7587
7506
|
minBinId,
|
|
7588
7507
|
maxBinId,
|
|
@@ -7590,7 +7509,7 @@ function toStrategyParameters({
|
|
|
7590
7509
|
parameteres: Buffer.from(parameters).toJSON().data
|
|
7591
7510
|
};
|
|
7592
7511
|
}
|
|
7593
|
-
case
|
|
7512
|
+
case 7 /* CurveBalanced */: {
|
|
7594
7513
|
return {
|
|
7595
7514
|
minBinId,
|
|
7596
7515
|
maxBinId,
|
|
@@ -7598,7 +7517,7 @@ function toStrategyParameters({
|
|
|
7598
7517
|
parameteres: Buffer.from(parameters).toJSON().data
|
|
7599
7518
|
};
|
|
7600
7519
|
}
|
|
7601
|
-
case
|
|
7520
|
+
case 8 /* BidAskBalanced */: {
|
|
7602
7521
|
return {
|
|
7603
7522
|
minBinId,
|
|
7604
7523
|
maxBinId,
|
|
@@ -7606,7 +7525,7 @@ function toStrategyParameters({
|
|
|
7606
7525
|
parameteres: Buffer.from(parameters).toJSON().data
|
|
7607
7526
|
};
|
|
7608
7527
|
}
|
|
7609
|
-
case
|
|
7528
|
+
case 3 /* SpotImBalanced */: {
|
|
7610
7529
|
return {
|
|
7611
7530
|
minBinId,
|
|
7612
7531
|
maxBinId,
|
|
@@ -7614,7 +7533,7 @@ function toStrategyParameters({
|
|
|
7614
7533
|
parameteres: Buffer.from(parameters).toJSON().data
|
|
7615
7534
|
};
|
|
7616
7535
|
}
|
|
7617
|
-
case
|
|
7536
|
+
case 4 /* CurveImBalanced */: {
|
|
7618
7537
|
return {
|
|
7619
7538
|
minBinId,
|
|
7620
7539
|
maxBinId,
|
|
@@ -7622,7 +7541,7 @@ function toStrategyParameters({
|
|
|
7622
7541
|
parameteres: Buffer.from(parameters).toJSON().data
|
|
7623
7542
|
};
|
|
7624
7543
|
}
|
|
7625
|
-
case
|
|
7544
|
+
case 5 /* BidAskImBalanced */: {
|
|
7626
7545
|
return {
|
|
7627
7546
|
minBinId,
|
|
7628
7547
|
maxBinId,
|
|
@@ -7644,7 +7563,7 @@ async function getTokensMintFromPoolAddress(connection, poolAddress, opt) {
|
|
|
7644
7563
|
);
|
|
7645
7564
|
const program = new (0, _anchor.Program)(
|
|
7646
7565
|
IDL,
|
|
7647
|
-
LBCLMM_PROGRAM_IDS[_nullishCoalesce(_optionalChain([opt, 'optionalAccess',
|
|
7566
|
+
LBCLMM_PROGRAM_IDS[_nullishCoalesce(_optionalChain([opt, 'optionalAccess', _21 => _21.cluster]), () => ( "mainnet-beta"))],
|
|
7648
7567
|
provider
|
|
7649
7568
|
);
|
|
7650
7569
|
const poolAccount = await program.account.lbPair.fetchNullable(
|
|
@@ -7702,7 +7621,7 @@ var getOrCreateATAInstruction = async (connection, tokenMint, owner, payer = own
|
|
|
7702
7621
|
return { ataPubKey: toAccount, ix: void 0 };
|
|
7703
7622
|
} catch (e) {
|
|
7704
7623
|
if (e instanceof _spltoken.TokenAccountNotFoundError || e instanceof _spltoken.TokenInvalidAccountOwnerError) {
|
|
7705
|
-
const ix = _spltoken.
|
|
7624
|
+
const ix = _spltoken.createAssociatedTokenAccountInstruction.call(void 0,
|
|
7706
7625
|
payer,
|
|
7707
7626
|
toAccount,
|
|
7708
7627
|
owner,
|
|
@@ -7722,7 +7641,7 @@ async function getTokenBalance(conn, tokenAccount) {
|
|
|
7722
7641
|
var parseLogs = (eventParser, logs) => {
|
|
7723
7642
|
if (!logs.length)
|
|
7724
7643
|
throw new Error("No logs found");
|
|
7725
|
-
for (const event of _optionalChain([eventParser, 'optionalAccess',
|
|
7644
|
+
for (const event of _optionalChain([eventParser, 'optionalAccess', _22 => _22.parseLogs, 'call', _23 => _23(logs)])) {
|
|
7726
7645
|
return event.data;
|
|
7727
7646
|
}
|
|
7728
7647
|
throw new Error("No events found");
|
|
@@ -7779,7 +7698,7 @@ var getEstimatedComputeUnitUsageWithBuffer = async (connection, instructions, fe
|
|
|
7779
7698
|
}
|
|
7780
7699
|
buffer = Math.max(0, buffer);
|
|
7781
7700
|
buffer = Math.min(1, buffer);
|
|
7782
|
-
const estimatedComputeUnitUsage = await getSimulationComputeUnits(
|
|
7701
|
+
const estimatedComputeUnitUsage = await _helpers.getSimulationComputeUnits.call(void 0,
|
|
7783
7702
|
connection,
|
|
7784
7703
|
instructions,
|
|
7785
7704
|
feePayer,
|
|
@@ -7837,13 +7756,13 @@ var DLMM = class {
|
|
|
7837
7756
|
);
|
|
7838
7757
|
const program = new (0, _anchor.Program)(
|
|
7839
7758
|
IDL,
|
|
7840
|
-
_nullishCoalesce(_optionalChain([opt, 'optionalAccess',
|
|
7759
|
+
_nullishCoalesce(_optionalChain([opt, 'optionalAccess', _24 => _24.programId]), () => ( LBCLMM_PROGRAM_IDS[_nullishCoalesce(_optionalChain([opt, 'optionalAccess', _25 => _25.cluster]), () => ( "mainnet-beta"))])),
|
|
7841
7760
|
provider
|
|
7842
7761
|
);
|
|
7843
7762
|
return program.account.lbPair.all();
|
|
7844
7763
|
}
|
|
7845
7764
|
static async getPairPubkeyIfExists(connection, tokenX, tokenY, binStep, baseFactor, opt) {
|
|
7846
|
-
const cluster = _optionalChain([opt, 'optionalAccess',
|
|
7765
|
+
const cluster = _optionalChain([opt, 'optionalAccess', _26 => _26.cluster]) || "mainnet-beta";
|
|
7847
7766
|
const provider = new (0, _anchor.AnchorProvider)(
|
|
7848
7767
|
connection,
|
|
7849
7768
|
{},
|
|
@@ -7851,7 +7770,7 @@ var DLMM = class {
|
|
|
7851
7770
|
);
|
|
7852
7771
|
const program = new (0, _anchor.Program)(
|
|
7853
7772
|
IDL,
|
|
7854
|
-
_nullishCoalesce(_optionalChain([opt, 'optionalAccess',
|
|
7773
|
+
_nullishCoalesce(_optionalChain([opt, 'optionalAccess', _27 => _27.programId]), () => ( LBCLMM_PROGRAM_IDS[cluster])),
|
|
7855
7774
|
provider
|
|
7856
7775
|
);
|
|
7857
7776
|
try {
|
|
@@ -7890,7 +7809,7 @@ var DLMM = class {
|
|
|
7890
7809
|
* @returns The `create` function returns a `Promise` that resolves to a `DLMM` object.
|
|
7891
7810
|
*/
|
|
7892
7811
|
static async create(connection, dlmm, opt) {
|
|
7893
|
-
const cluster = _optionalChain([opt, 'optionalAccess',
|
|
7812
|
+
const cluster = _optionalChain([opt, 'optionalAccess', _28 => _28.cluster]) || "mainnet-beta";
|
|
7894
7813
|
const provider = new (0, _anchor.AnchorProvider)(
|
|
7895
7814
|
connection,
|
|
7896
7815
|
{},
|
|
@@ -7898,7 +7817,7 @@ var DLMM = class {
|
|
|
7898
7817
|
);
|
|
7899
7818
|
const program = new (0, _anchor.Program)(
|
|
7900
7819
|
IDL,
|
|
7901
|
-
_nullishCoalesce(_optionalChain([opt, 'optionalAccess',
|
|
7820
|
+
_nullishCoalesce(_optionalChain([opt, 'optionalAccess', _29 => _29.programId]), () => ( LBCLMM_PROGRAM_IDS[cluster])),
|
|
7902
7821
|
provider
|
|
7903
7822
|
);
|
|
7904
7823
|
const binArrayBitMapExtensionPubkey = deriveBinArrayBitmapExtension(
|
|
@@ -7914,14 +7833,14 @@ var DLMM = class {
|
|
|
7914
7833
|
connection,
|
|
7915
7834
|
accountsToFetch
|
|
7916
7835
|
);
|
|
7917
|
-
const lbPairAccountInfoBuffer = _optionalChain([accountsInfo, 'access',
|
|
7836
|
+
const lbPairAccountInfoBuffer = _optionalChain([accountsInfo, 'access', _30 => _30[0], 'optionalAccess', _31 => _31.data]);
|
|
7918
7837
|
if (!lbPairAccountInfoBuffer)
|
|
7919
7838
|
throw new Error(`LB Pair account ${dlmm.toBase58()} not found`);
|
|
7920
7839
|
const lbPairAccInfo = program.coder.accounts.decode(
|
|
7921
7840
|
"lbPair",
|
|
7922
7841
|
lbPairAccountInfoBuffer
|
|
7923
7842
|
);
|
|
7924
|
-
const binArrayBitMapAccountInfoBuffer = _optionalChain([accountsInfo, 'access',
|
|
7843
|
+
const binArrayBitMapAccountInfoBuffer = _optionalChain([accountsInfo, 'access', _32 => _32[1], 'optionalAccess', _33 => _33.data]);
|
|
7925
7844
|
let binArrayBitMapExtensionAccInfo = null;
|
|
7926
7845
|
if (binArrayBitMapAccountInfoBuffer) {
|
|
7927
7846
|
binArrayBitMapExtensionAccInfo = program.coder.accounts.decode(
|
|
@@ -7929,7 +7848,7 @@ var DLMM = class {
|
|
|
7929
7848
|
binArrayBitMapAccountInfoBuffer
|
|
7930
7849
|
);
|
|
7931
7850
|
}
|
|
7932
|
-
const clockAccountInfoBuffer = _optionalChain([accountsInfo, 'access',
|
|
7851
|
+
const clockAccountInfoBuffer = _optionalChain([accountsInfo, 'access', _34 => _34[2], 'optionalAccess', _35 => _35.data]);
|
|
7933
7852
|
if (!clockAccountInfoBuffer)
|
|
7934
7853
|
throw new Error(`Clock account not found`);
|
|
7935
7854
|
const clock = ClockLayout.decode(clockAccountInfoBuffer);
|
|
@@ -7990,7 +7909,7 @@ var DLMM = class {
|
|
|
7990
7909
|
* objects.
|
|
7991
7910
|
*/
|
|
7992
7911
|
static async createMultiple(connection, dlmmList, opt) {
|
|
7993
|
-
const cluster = _optionalChain([opt, 'optionalAccess',
|
|
7912
|
+
const cluster = _optionalChain([opt, 'optionalAccess', _36 => _36.cluster]) || "mainnet-beta";
|
|
7994
7913
|
const provider = new (0, _anchor.AnchorProvider)(
|
|
7995
7914
|
connection,
|
|
7996
7915
|
{},
|
|
@@ -7998,7 +7917,7 @@ var DLMM = class {
|
|
|
7998
7917
|
);
|
|
7999
7918
|
const program = new (0, _anchor.Program)(
|
|
8000
7919
|
IDL,
|
|
8001
|
-
_nullishCoalesce(_optionalChain([opt, 'optionalAccess',
|
|
7920
|
+
_nullishCoalesce(_optionalChain([opt, 'optionalAccess', _37 => _37.programId]), () => ( LBCLMM_PROGRAM_IDS[cluster])),
|
|
8002
7921
|
provider
|
|
8003
7922
|
);
|
|
8004
7923
|
const binArrayBitMapExtensions = dlmmList.map(
|
|
@@ -8014,14 +7933,14 @@ var DLMM = class {
|
|
|
8014
7933
|
accountsToFetch
|
|
8015
7934
|
);
|
|
8016
7935
|
const clockAccount = accountsInfo.pop();
|
|
8017
|
-
const clockAccountInfoBuffer = _optionalChain([clockAccount, 'optionalAccess',
|
|
7936
|
+
const clockAccountInfoBuffer = _optionalChain([clockAccount, 'optionalAccess', _38 => _38.data]);
|
|
8018
7937
|
if (!clockAccountInfoBuffer)
|
|
8019
7938
|
throw new Error(`Clock account not found`);
|
|
8020
7939
|
const clock = ClockLayout.decode(clockAccountInfoBuffer);
|
|
8021
7940
|
const lbPairArraysMap = /* @__PURE__ */ new Map();
|
|
8022
7941
|
for (let i = 0; i < dlmmList.length; i++) {
|
|
8023
7942
|
const lbPairPubKey = dlmmList[i];
|
|
8024
|
-
const lbPairAccountInfoBuffer = _optionalChain([accountsInfo, 'access',
|
|
7943
|
+
const lbPairAccountInfoBuffer = _optionalChain([accountsInfo, 'access', _39 => _39[i], 'optionalAccess', _40 => _40.data]);
|
|
8025
7944
|
if (!lbPairAccountInfoBuffer)
|
|
8026
7945
|
throw new Error(`LB Pair account ${lbPairPubKey.toBase58()} not found`);
|
|
8027
7946
|
const binArrayAccInfo = program.coder.accounts.decode(
|
|
@@ -8034,7 +7953,7 @@ var DLMM = class {
|
|
|
8034
7953
|
for (let i = dlmmList.length; i < accountsInfo.length; i++) {
|
|
8035
7954
|
const index = i - dlmmList.length;
|
|
8036
7955
|
const lbPairPubkey = dlmmList[index];
|
|
8037
|
-
const binArrayBitMapAccountInfoBuffer = _optionalChain([accountsInfo, 'access',
|
|
7956
|
+
const binArrayBitMapAccountInfoBuffer = _optionalChain([accountsInfo, 'access', _41 => _41[i], 'optionalAccess', _42 => _42.data]);
|
|
8038
7957
|
if (binArrayBitMapAccountInfoBuffer) {
|
|
8039
7958
|
const binArrayBitMapExtensionAccInfo = program.coder.accounts.decode(
|
|
8040
7959
|
"binArrayBitmapExtension",
|
|
@@ -8118,7 +8037,7 @@ var DLMM = class {
|
|
|
8118
8037
|
);
|
|
8119
8038
|
const program = new (0, _anchor.Program)(
|
|
8120
8039
|
IDL,
|
|
8121
|
-
_nullishCoalesce(_optionalChain([opt, 'optionalAccess',
|
|
8040
|
+
_nullishCoalesce(_optionalChain([opt, 'optionalAccess', _43 => _43.programId]), () => ( LBCLMM_PROGRAM_IDS[_nullishCoalesce(_optionalChain([opt, 'optionalAccess', _44 => _44.cluster]), () => ( "mainnet-beta"))])),
|
|
8122
8041
|
provider
|
|
8123
8042
|
);
|
|
8124
8043
|
const presetParameter = await program.account.presetParameter.all();
|
|
@@ -8136,7 +8055,7 @@ var DLMM = class {
|
|
|
8136
8055
|
* Pair account, and the value is an object of PositionInfo
|
|
8137
8056
|
*/
|
|
8138
8057
|
static async getAllLbPairPositionsByUser(connection, userPubKey, opt) {
|
|
8139
|
-
const cluster = _optionalChain([opt, 'optionalAccess',
|
|
8058
|
+
const cluster = _optionalChain([opt, 'optionalAccess', _45 => _45.cluster]) || "mainnet-beta";
|
|
8140
8059
|
const provider = new (0, _anchor.AnchorProvider)(
|
|
8141
8060
|
connection,
|
|
8142
8061
|
{},
|
|
@@ -8144,17 +8063,52 @@ var DLMM = class {
|
|
|
8144
8063
|
);
|
|
8145
8064
|
const program = new (0, _anchor.Program)(
|
|
8146
8065
|
IDL,
|
|
8147
|
-
_nullishCoalesce(_optionalChain([opt, 'optionalAccess',
|
|
8066
|
+
_nullishCoalesce(_optionalChain([opt, 'optionalAccess', _46 => _46.programId]), () => ( LBCLMM_PROGRAM_IDS[cluster])),
|
|
8148
8067
|
provider
|
|
8149
8068
|
);
|
|
8150
|
-
const positionsV2 = await
|
|
8151
|
-
|
|
8152
|
-
|
|
8153
|
-
|
|
8154
|
-
|
|
8069
|
+
const [positions, positionsV2] = await Promise.all([
|
|
8070
|
+
program.account.position.all([
|
|
8071
|
+
{
|
|
8072
|
+
memcmp: {
|
|
8073
|
+
bytes: _bytes.bs58.encode(userPubKey.toBuffer()),
|
|
8074
|
+
offset: 8 + 32
|
|
8075
|
+
}
|
|
8155
8076
|
}
|
|
8156
|
-
|
|
8077
|
+
]),
|
|
8078
|
+
program.account.positionV2.all([
|
|
8079
|
+
{
|
|
8080
|
+
memcmp: {
|
|
8081
|
+
bytes: _bytes.bs58.encode(userPubKey.toBuffer()),
|
|
8082
|
+
offset: 8 + 32
|
|
8083
|
+
}
|
|
8084
|
+
}
|
|
8085
|
+
])
|
|
8157
8086
|
]);
|
|
8087
|
+
const binArrayPubkeySet = /* @__PURE__ */ new Set();
|
|
8088
|
+
const lbPairSet = /* @__PURE__ */ new Set();
|
|
8089
|
+
positions.forEach(({ account: { upperBinId, lowerBinId, lbPair } }) => {
|
|
8090
|
+
const lowerBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(lowerBinId));
|
|
8091
|
+
const upperBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(upperBinId));
|
|
8092
|
+
const [lowerBinArrayPubKey] = deriveBinArray(
|
|
8093
|
+
lbPair,
|
|
8094
|
+
lowerBinArrayIndex,
|
|
8095
|
+
program.programId
|
|
8096
|
+
);
|
|
8097
|
+
const [upperBinArrayPubKey] = deriveBinArray(
|
|
8098
|
+
lbPair,
|
|
8099
|
+
upperBinArrayIndex,
|
|
8100
|
+
program.programId
|
|
8101
|
+
);
|
|
8102
|
+
binArrayPubkeySet.add(lowerBinArrayPubKey.toBase58());
|
|
8103
|
+
binArrayPubkeySet.add(upperBinArrayPubKey.toBase58());
|
|
8104
|
+
lbPairSet.add(lbPair.toBase58());
|
|
8105
|
+
});
|
|
8106
|
+
const binArrayPubkeyArray = Array.from(binArrayPubkeySet).map(
|
|
8107
|
+
(pubkey) => new (0, _web3js.PublicKey)(pubkey)
|
|
8108
|
+
);
|
|
8109
|
+
const lbPairArray = Array.from(lbPairSet).map(
|
|
8110
|
+
(pubkey) => new (0, _web3js.PublicKey)(pubkey)
|
|
8111
|
+
);
|
|
8158
8112
|
const binArrayPubkeySetV2 = /* @__PURE__ */ new Set();
|
|
8159
8113
|
const lbPairSetV2 = /* @__PURE__ */ new Set();
|
|
8160
8114
|
positionsV2.forEach(({ account: { upperBinId, lowerBinId, lbPair } }) => {
|
|
@@ -8182,24 +8136,60 @@ var DLMM = class {
|
|
|
8182
8136
|
);
|
|
8183
8137
|
const [clockAccInfo, ...binArraysAccInfo] = await chunkedGetMultipleAccountInfos(connection, [
|
|
8184
8138
|
_web3js.SYSVAR_CLOCK_PUBKEY,
|
|
8139
|
+
...binArrayPubkeyArray,
|
|
8140
|
+
...lbPairArray,
|
|
8185
8141
|
...binArrayPubkeyArrayV2,
|
|
8186
8142
|
...lbPairArrayV2
|
|
8187
8143
|
]);
|
|
8144
|
+
const positionBinArraysMap = /* @__PURE__ */ new Map();
|
|
8145
|
+
for (let i = 0; i < binArrayPubkeyArray.length; i++) {
|
|
8146
|
+
const binArrayPubkey = binArrayPubkeyArray[i];
|
|
8147
|
+
const binArrayAccInfoBuffer = binArraysAccInfo[i];
|
|
8148
|
+
if (!binArrayAccInfoBuffer)
|
|
8149
|
+
throw new Error(
|
|
8150
|
+
`Bin Array account ${binArrayPubkey.toBase58()} not found`
|
|
8151
|
+
);
|
|
8152
|
+
const binArrayAccInfo = program.coder.accounts.decode(
|
|
8153
|
+
"binArray",
|
|
8154
|
+
binArrayAccInfoBuffer.data
|
|
8155
|
+
);
|
|
8156
|
+
positionBinArraysMap.set(binArrayPubkey.toBase58(), binArrayAccInfo);
|
|
8157
|
+
}
|
|
8158
|
+
const lbPairArraysMap = /* @__PURE__ */ new Map();
|
|
8159
|
+
for (let i = binArrayPubkeyArray.length; i < binArrayPubkeyArray.length + lbPairArray.length; i++) {
|
|
8160
|
+
const lbPairPubkey = lbPairArray[i - binArrayPubkeyArray.length];
|
|
8161
|
+
const lbPairAccInfoBuffer = binArraysAccInfo[i];
|
|
8162
|
+
if (!lbPairAccInfoBuffer)
|
|
8163
|
+
throw new Error(`LB Pair account ${lbPairPubkey.toBase58()} not found`);
|
|
8164
|
+
const lbPairAccInfo = program.coder.accounts.decode(
|
|
8165
|
+
"lbPair",
|
|
8166
|
+
lbPairAccInfoBuffer.data
|
|
8167
|
+
);
|
|
8168
|
+
lbPairArraysMap.set(lbPairPubkey.toBase58(), lbPairAccInfo);
|
|
8169
|
+
}
|
|
8170
|
+
const reservePublicKeys = Array.from(lbPairArraysMap.values()).map(({ reserveX, reserveY, tokenXMint, tokenYMint }) => [
|
|
8171
|
+
reserveX,
|
|
8172
|
+
reserveY,
|
|
8173
|
+
tokenXMint,
|
|
8174
|
+
tokenYMint
|
|
8175
|
+
]).flat();
|
|
8188
8176
|
const positionBinArraysMapV2 = /* @__PURE__ */ new Map();
|
|
8189
|
-
for (let i =
|
|
8190
|
-
const binArrayPubkey = binArrayPubkeyArrayV2[i];
|
|
8177
|
+
for (let i = binArrayPubkeyArray.length + lbPairArray.length; i < binArrayPubkeyArray.length + lbPairArray.length + binArrayPubkeyArrayV2.length; i++) {
|
|
8178
|
+
const binArrayPubkey = binArrayPubkeyArrayV2[i - (binArrayPubkeyArray.length + lbPairArray.length)];
|
|
8191
8179
|
const binArrayAccInfoBufferV2 = binArraysAccInfo[i];
|
|
8192
|
-
if (binArrayAccInfoBufferV2)
|
|
8193
|
-
|
|
8194
|
-
|
|
8195
|
-
binArrayAccInfoBufferV2.data
|
|
8180
|
+
if (!binArrayAccInfoBufferV2)
|
|
8181
|
+
throw new Error(
|
|
8182
|
+
`Bin Array account ${binArrayPubkey.toBase58()} not found`
|
|
8196
8183
|
);
|
|
8197
|
-
|
|
8198
|
-
|
|
8184
|
+
const binArrayAccInfo = program.coder.accounts.decode(
|
|
8185
|
+
"binArray",
|
|
8186
|
+
binArrayAccInfoBufferV2.data
|
|
8187
|
+
);
|
|
8188
|
+
positionBinArraysMapV2.set(binArrayPubkey.toBase58(), binArrayAccInfo);
|
|
8199
8189
|
}
|
|
8200
8190
|
const lbPairArraysMapV2 = /* @__PURE__ */ new Map();
|
|
8201
|
-
for (let i = binArrayPubkeyArrayV2.length; i < binArraysAccInfo.length; i++) {
|
|
8202
|
-
const lbPairPubkey = lbPairArrayV2[i - binArrayPubkeyArrayV2.length];
|
|
8191
|
+
for (let i = binArrayPubkeyArray.length + lbPairArray.length + binArrayPubkeyArrayV2.length; i < binArraysAccInfo.length; i++) {
|
|
8192
|
+
const lbPairPubkey = lbPairArrayV2[i - (binArrayPubkeyArray.length + lbPairArray.length + binArrayPubkeyArrayV2.length)];
|
|
8203
8193
|
const lbPairAccInfoBufferV2 = binArraysAccInfo[i];
|
|
8204
8194
|
if (!lbPairAccInfoBufferV2)
|
|
8205
8195
|
throw new Error(`LB Pair account ${lbPairPubkey.toBase58()} not found`);
|
|
@@ -8217,14 +8207,43 @@ var DLMM = class {
|
|
|
8217
8207
|
]).flat();
|
|
8218
8208
|
const reserveAccountsInfo = await chunkedGetMultipleAccountInfos(
|
|
8219
8209
|
program.provider.connection,
|
|
8220
|
-
reservePublicKeysV2
|
|
8210
|
+
[...reservePublicKeys, ...reservePublicKeysV2]
|
|
8221
8211
|
);
|
|
8212
|
+
const lbPairReserveMap = /* @__PURE__ */ new Map();
|
|
8213
|
+
const lbPairMintMap = /* @__PURE__ */ new Map();
|
|
8214
|
+
lbPairArray.forEach((lbPair, idx) => {
|
|
8215
|
+
const index = idx * 4;
|
|
8216
|
+
const reserveAccBufferX = reserveAccountsInfo[index];
|
|
8217
|
+
const reserveAccBufferY = reserveAccountsInfo[index + 1];
|
|
8218
|
+
if (!reserveAccBufferX || !reserveAccBufferY)
|
|
8219
|
+
throw new Error(
|
|
8220
|
+
`Reserve account for LB Pair ${lbPair.toBase58()} not found`
|
|
8221
|
+
);
|
|
8222
|
+
const reserveAccX = _spltoken.AccountLayout.decode(reserveAccBufferX.data);
|
|
8223
|
+
const reserveAccY = _spltoken.AccountLayout.decode(reserveAccBufferY.data);
|
|
8224
|
+
lbPairReserveMap.set(lbPair.toBase58(), {
|
|
8225
|
+
reserveX: reserveAccX.amount,
|
|
8226
|
+
reserveY: reserveAccY.amount
|
|
8227
|
+
});
|
|
8228
|
+
const mintXBuffer = reserveAccountsInfo[index + 2];
|
|
8229
|
+
const mintYBuffer = reserveAccountsInfo[index + 3];
|
|
8230
|
+
if (!mintXBuffer || !mintYBuffer)
|
|
8231
|
+
throw new Error(
|
|
8232
|
+
`Mint account for LB Pair ${lbPair.toBase58()} not found`
|
|
8233
|
+
);
|
|
8234
|
+
const mintX = _spltoken.MintLayout.decode(mintXBuffer.data);
|
|
8235
|
+
const mintY = _spltoken.MintLayout.decode(mintYBuffer.data);
|
|
8236
|
+
lbPairMintMap.set(lbPair.toBase58(), {
|
|
8237
|
+
mintXDecimal: mintX.decimals,
|
|
8238
|
+
mintYDecimal: mintY.decimals
|
|
8239
|
+
});
|
|
8240
|
+
});
|
|
8222
8241
|
const lbPairReserveMapV2 = /* @__PURE__ */ new Map();
|
|
8223
8242
|
const lbPairMintMapV2 = /* @__PURE__ */ new Map();
|
|
8224
8243
|
lbPairArrayV2.forEach((lbPair, idx) => {
|
|
8225
8244
|
const index = idx * 4;
|
|
8226
|
-
const reserveAccBufferXV2 = reserveAccountsInfo[index];
|
|
8227
|
-
const reserveAccBufferYV2 = reserveAccountsInfo[index + 1];
|
|
8245
|
+
const reserveAccBufferXV2 = reserveAccountsInfo[reservePublicKeys.length + index];
|
|
8246
|
+
const reserveAccBufferYV2 = reserveAccountsInfo[reservePublicKeys.length + index + 1];
|
|
8228
8247
|
if (!reserveAccBufferXV2 || !reserveAccBufferYV2)
|
|
8229
8248
|
throw new Error(
|
|
8230
8249
|
`Reserve account for LB Pair ${lbPair.toBase58()} not found`
|
|
@@ -8235,8 +8254,8 @@ var DLMM = class {
|
|
|
8235
8254
|
reserveX: reserveAccX.amount,
|
|
8236
8255
|
reserveY: reserveAccY.amount
|
|
8237
8256
|
});
|
|
8238
|
-
const mintXBufferV2 = reserveAccountsInfo[index + 2];
|
|
8239
|
-
const mintYBufferV2 = reserveAccountsInfo[index + 3];
|
|
8257
|
+
const mintXBufferV2 = reserveAccountsInfo[reservePublicKeys.length + index + 2];
|
|
8258
|
+
const mintYBufferV2 = reserveAccountsInfo[reservePublicKeys.length + index + 3];
|
|
8240
8259
|
if (!mintXBufferV2 || !mintYBufferV2)
|
|
8241
8260
|
throw new Error(
|
|
8242
8261
|
`Mint account for LB Pair ${lbPair.toBase58()} not found`
|
|
@@ -8252,6 +8271,74 @@ var DLMM = class {
|
|
|
8252
8271
|
clockAccInfo.data.readBigInt64LE(32).toString()
|
|
8253
8272
|
).toNumber();
|
|
8254
8273
|
const positionsMap = /* @__PURE__ */ new Map();
|
|
8274
|
+
for (let position of positions) {
|
|
8275
|
+
const { account, publicKey: positionPubKey } = position;
|
|
8276
|
+
const { upperBinId, lowerBinId, lbPair } = account;
|
|
8277
|
+
const lowerBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(lowerBinId));
|
|
8278
|
+
const upperBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(upperBinId));
|
|
8279
|
+
const [lowerBinArrayPubKey] = deriveBinArray(
|
|
8280
|
+
lbPair,
|
|
8281
|
+
lowerBinArrayIndex,
|
|
8282
|
+
program.programId
|
|
8283
|
+
);
|
|
8284
|
+
const [upperBinArrayPubKey] = deriveBinArray(
|
|
8285
|
+
lbPair,
|
|
8286
|
+
upperBinArrayIndex,
|
|
8287
|
+
program.programId
|
|
8288
|
+
);
|
|
8289
|
+
const lowerBinArray = positionBinArraysMap.get(
|
|
8290
|
+
lowerBinArrayPubKey.toBase58()
|
|
8291
|
+
);
|
|
8292
|
+
const upperBinArray = positionBinArraysMap.get(
|
|
8293
|
+
upperBinArrayPubKey.toBase58()
|
|
8294
|
+
);
|
|
8295
|
+
const lbPairAcc = lbPairArraysMap.get(lbPair.toBase58());
|
|
8296
|
+
const { mintXDecimal, mintYDecimal } = lbPairMintMap.get(
|
|
8297
|
+
lbPair.toBase58()
|
|
8298
|
+
);
|
|
8299
|
+
const reserveXBalance = _nullishCoalesce(_optionalChain([lbPairReserveMap, 'access', _47 => _47.get, 'call', _48 => _48(lbPair.toBase58()), 'optionalAccess', _49 => _49.reserveX]), () => ( BigInt(0)));
|
|
8300
|
+
const reserveYBalance = _nullishCoalesce(_optionalChain([lbPairReserveMap, 'access', _50 => _50.get, 'call', _51 => _51(lbPair.toBase58()), 'optionalAccess', _52 => _52.reserveY]), () => ( BigInt(0)));
|
|
8301
|
+
const tokenX = {
|
|
8302
|
+
publicKey: lbPairAcc.tokenXMint,
|
|
8303
|
+
reserve: lbPairAcc.reserveX,
|
|
8304
|
+
amount: reserveXBalance,
|
|
8305
|
+
decimal: mintXDecimal
|
|
8306
|
+
};
|
|
8307
|
+
const tokenY = {
|
|
8308
|
+
publicKey: lbPairAcc.tokenYMint,
|
|
8309
|
+
reserve: lbPairAcc.reserveY,
|
|
8310
|
+
amount: reserveYBalance,
|
|
8311
|
+
decimal: mintYDecimal
|
|
8312
|
+
};
|
|
8313
|
+
const positionData = await DLMM.processPosition(
|
|
8314
|
+
program,
|
|
8315
|
+
0 /* V1 */,
|
|
8316
|
+
lbPairAcc,
|
|
8317
|
+
onChainTimestamp,
|
|
8318
|
+
account,
|
|
8319
|
+
mintXDecimal,
|
|
8320
|
+
mintYDecimal,
|
|
8321
|
+
lowerBinArray,
|
|
8322
|
+
upperBinArray,
|
|
8323
|
+
_web3js.PublicKey.default
|
|
8324
|
+
);
|
|
8325
|
+
if (positionData) {
|
|
8326
|
+
positionsMap.set(lbPair.toBase58(), {
|
|
8327
|
+
publicKey: lbPair,
|
|
8328
|
+
lbPair: lbPairAcc,
|
|
8329
|
+
tokenX,
|
|
8330
|
+
tokenY,
|
|
8331
|
+
lbPairPositionsData: [
|
|
8332
|
+
..._nullishCoalesce(_optionalChain([positionsMap, 'access', _53 => _53.get, 'call', _54 => _54(lbPair.toBase58()), 'optionalAccess', _55 => _55.lbPairPositionsData]), () => ( [])),
|
|
8333
|
+
{
|
|
8334
|
+
publicKey: positionPubKey,
|
|
8335
|
+
positionData,
|
|
8336
|
+
version: 0 /* V1 */
|
|
8337
|
+
}
|
|
8338
|
+
]
|
|
8339
|
+
});
|
|
8340
|
+
}
|
|
8341
|
+
}
|
|
8255
8342
|
for (let position of positionsV2) {
|
|
8256
8343
|
const { account, publicKey: positionPubKey } = position;
|
|
8257
8344
|
const { upperBinId, lowerBinId, lbPair, feeOwner } = account;
|
|
@@ -8278,8 +8365,8 @@ var DLMM = class {
|
|
|
8278
8365
|
getTokenDecimals(program.provider.connection, lbPairAcc.tokenXMint),
|
|
8279
8366
|
getTokenDecimals(program.provider.connection, lbPairAcc.tokenYMint)
|
|
8280
8367
|
]);
|
|
8281
|
-
const reserveXBalance = _nullishCoalesce(_optionalChain([lbPairReserveMapV2, 'access',
|
|
8282
|
-
const reserveYBalance = _nullishCoalesce(_optionalChain([lbPairReserveMapV2, 'access',
|
|
8368
|
+
const reserveXBalance = _nullishCoalesce(_optionalChain([lbPairReserveMapV2, 'access', _56 => _56.get, 'call', _57 => _57(lbPair.toBase58()), 'optionalAccess', _58 => _58.reserveX]), () => ( BigInt(0)));
|
|
8369
|
+
const reserveYBalance = _nullishCoalesce(_optionalChain([lbPairReserveMapV2, 'access', _59 => _59.get, 'call', _60 => _60(lbPair.toBase58()), 'optionalAccess', _61 => _61.reserveY]), () => ( BigInt(0)));
|
|
8283
8370
|
const tokenX = {
|
|
8284
8371
|
publicKey: lbPairAcc.tokenXMint,
|
|
8285
8372
|
reserve: lbPairAcc.reserveX,
|
|
@@ -8292,7 +8379,7 @@ var DLMM = class {
|
|
|
8292
8379
|
amount: reserveYBalance,
|
|
8293
8380
|
decimal: quoteTokenDecimal
|
|
8294
8381
|
};
|
|
8295
|
-
const positionData =
|
|
8382
|
+
const positionData = await DLMM.processPosition(
|
|
8296
8383
|
program,
|
|
8297
8384
|
1 /* V2 */,
|
|
8298
8385
|
lbPairAcc,
|
|
@@ -8303,21 +8390,7 @@ var DLMM = class {
|
|
|
8303
8390
|
lowerBinArray,
|
|
8304
8391
|
upperBinArray,
|
|
8305
8392
|
feeOwner
|
|
8306
|
-
)
|
|
8307
|
-
totalXAmount: "0",
|
|
8308
|
-
totalYAmount: "0",
|
|
8309
|
-
positionBinData: [],
|
|
8310
|
-
lastUpdatedAt: new (0, _anchor.BN)(0),
|
|
8311
|
-
upperBinId,
|
|
8312
|
-
lowerBinId,
|
|
8313
|
-
feeX: new (0, _anchor.BN)(0),
|
|
8314
|
-
feeY: new (0, _anchor.BN)(0),
|
|
8315
|
-
rewardOne: new (0, _anchor.BN)(0),
|
|
8316
|
-
rewardTwo: new (0, _anchor.BN)(0),
|
|
8317
|
-
feeOwner,
|
|
8318
|
-
totalClaimedFeeXAmount: new (0, _anchor.BN)(0),
|
|
8319
|
-
totalClaimedFeeYAmount: new (0, _anchor.BN)(0)
|
|
8320
|
-
};
|
|
8393
|
+
);
|
|
8321
8394
|
if (positionData) {
|
|
8322
8395
|
positionsMap.set(lbPair.toBase58(), {
|
|
8323
8396
|
publicKey: lbPair,
|
|
@@ -8325,7 +8398,7 @@ var DLMM = class {
|
|
|
8325
8398
|
tokenX,
|
|
8326
8399
|
tokenY,
|
|
8327
8400
|
lbPairPositionsData: [
|
|
8328
|
-
..._nullishCoalesce(_optionalChain([positionsMap, 'access',
|
|
8401
|
+
..._nullishCoalesce(_optionalChain([positionsMap, 'access', _62 => _62.get, 'call', _63 => _63(lbPair.toBase58()), 'optionalAccess', _64 => _64.lbPairPositionsData]), () => ( [])),
|
|
8329
8402
|
{
|
|
8330
8403
|
publicKey: positionPubKey,
|
|
8331
8404
|
positionData,
|
|
@@ -8337,6 +8410,56 @@ var DLMM = class {
|
|
|
8337
8410
|
}
|
|
8338
8411
|
return positionsMap;
|
|
8339
8412
|
}
|
|
8413
|
+
static async migratePosition(connection, positions, newPositions, walletPubkey, opt) {
|
|
8414
|
+
const cluster = _optionalChain([opt, 'optionalAccess', _65 => _65.cluster]) || "mainnet-beta";
|
|
8415
|
+
const provider = new (0, _anchor.AnchorProvider)(
|
|
8416
|
+
connection,
|
|
8417
|
+
{},
|
|
8418
|
+
_anchor.AnchorProvider.defaultOptions()
|
|
8419
|
+
);
|
|
8420
|
+
const program = new (0, _anchor.Program)(
|
|
8421
|
+
IDL,
|
|
8422
|
+
_nullishCoalesce(_optionalChain([opt, 'optionalAccess', _66 => _66.programId]), () => ( LBCLMM_PROGRAM_IDS[cluster])),
|
|
8423
|
+
provider
|
|
8424
|
+
);
|
|
8425
|
+
const positionsState = await program.account.position.fetchMultiple(
|
|
8426
|
+
positions
|
|
8427
|
+
);
|
|
8428
|
+
const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash("confirmed");
|
|
8429
|
+
return Promise.all(
|
|
8430
|
+
positionsState.map(async ({ lbPair, lowerBinId }, idx) => {
|
|
8431
|
+
const position = positions[idx];
|
|
8432
|
+
const lowerBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(lowerBinId));
|
|
8433
|
+
const upperBinArrayIndex = lowerBinArrayIndex.add(new (0, _anchor.BN)(1));
|
|
8434
|
+
const [lowerBinArrayPubKey] = deriveBinArray(
|
|
8435
|
+
lbPair,
|
|
8436
|
+
lowerBinArrayIndex,
|
|
8437
|
+
program.programId
|
|
8438
|
+
);
|
|
8439
|
+
const [upperBinArrayPubKey] = deriveBinArray(
|
|
8440
|
+
lbPair,
|
|
8441
|
+
upperBinArrayIndex,
|
|
8442
|
+
program.programId
|
|
8443
|
+
);
|
|
8444
|
+
const migrateTx = await program.methods.migratePosition().accounts({
|
|
8445
|
+
binArrayLower: lowerBinArrayPubKey,
|
|
8446
|
+
binArrayUpper: upperBinArrayPubKey,
|
|
8447
|
+
lbPair,
|
|
8448
|
+
owner: walletPubkey,
|
|
8449
|
+
positionV1: position,
|
|
8450
|
+
positionV2: newPositions[idx],
|
|
8451
|
+
program: program.programId,
|
|
8452
|
+
rentReceiver: walletPubkey,
|
|
8453
|
+
systemProgram: _web3js.SystemProgram.programId
|
|
8454
|
+
}).transaction();
|
|
8455
|
+
return new (0, _web3js.Transaction)({
|
|
8456
|
+
blockhash,
|
|
8457
|
+
lastValidBlockHeight,
|
|
8458
|
+
feePayer: walletPubkey
|
|
8459
|
+
}).add(migrateTx);
|
|
8460
|
+
})
|
|
8461
|
+
);
|
|
8462
|
+
}
|
|
8340
8463
|
static getPricePerLamport(tokenXDecimal, tokenYDecimal, price) {
|
|
8341
8464
|
return new (0, _decimaljs2.default)(price).mul(new (0, _decimaljs2.default)(10 ** (tokenYDecimal - tokenXDecimal))).toString();
|
|
8342
8465
|
}
|
|
@@ -8354,7 +8477,7 @@ var DLMM = class {
|
|
|
8354
8477
|
);
|
|
8355
8478
|
const program = new (0, _anchor.Program)(
|
|
8356
8479
|
IDL,
|
|
8357
|
-
_nullishCoalesce(_optionalChain([opt, 'optionalAccess',
|
|
8480
|
+
_nullishCoalesce(_optionalChain([opt, 'optionalAccess', _67 => _67.programId]), () => ( LBCLMM_PROGRAM_IDS[opt.cluster])),
|
|
8358
8481
|
provider
|
|
8359
8482
|
);
|
|
8360
8483
|
const [lbPair] = derivePermissionLbPair(
|
|
@@ -8403,7 +8526,7 @@ var DLMM = class {
|
|
|
8403
8526
|
);
|
|
8404
8527
|
const program = new (0, _anchor.Program)(
|
|
8405
8528
|
IDL,
|
|
8406
|
-
_nullishCoalesce(_optionalChain([opt, 'optionalAccess',
|
|
8529
|
+
_nullishCoalesce(_optionalChain([opt, 'optionalAccess', _68 => _68.programId]), () => ( LBCLMM_PROGRAM_IDS[opt.cluster])),
|
|
8407
8530
|
provider
|
|
8408
8531
|
);
|
|
8409
8532
|
const [lbPair] = deriveCustomizablePermissionlessLbPair(
|
|
@@ -8428,9 +8551,9 @@ var DLMM = class {
|
|
|
8428
8551
|
padding: Array(64).fill(0)
|
|
8429
8552
|
};
|
|
8430
8553
|
const userTokenX = _spltoken.getAssociatedTokenAddressSync.call(void 0, tokenX, creatorKey);
|
|
8431
|
-
const userTokenY = _spltoken.getAssociatedTokenAddressSync.call(void 0, tokenY, creatorKey);
|
|
8432
8554
|
return program.methods.initializeCustomizablePermissionlessLbPair(ixData).accounts({
|
|
8433
8555
|
lbPair,
|
|
8556
|
+
rent: _web3js.SYSVAR_RENT_PUBKEY,
|
|
8434
8557
|
reserveX,
|
|
8435
8558
|
reserveY,
|
|
8436
8559
|
binArrayBitmapExtension,
|
|
@@ -8440,7 +8563,6 @@ var DLMM = class {
|
|
|
8440
8563
|
oracle,
|
|
8441
8564
|
systemProgram: _web3js.SystemProgram.programId,
|
|
8442
8565
|
userTokenX,
|
|
8443
|
-
userTokenY,
|
|
8444
8566
|
funder: creatorKey
|
|
8445
8567
|
}).transaction();
|
|
8446
8568
|
}
|
|
@@ -8452,7 +8574,7 @@ var DLMM = class {
|
|
|
8452
8574
|
);
|
|
8453
8575
|
const program = new (0, _anchor.Program)(
|
|
8454
8576
|
IDL,
|
|
8455
|
-
_nullishCoalesce(_optionalChain([opt, 'optionalAccess',
|
|
8577
|
+
_nullishCoalesce(_optionalChain([opt, 'optionalAccess', _69 => _69.programId]), () => ( LBCLMM_PROGRAM_IDS[opt.cluster])),
|
|
8456
8578
|
provider
|
|
8457
8579
|
);
|
|
8458
8580
|
const existsPool = await this.getPairPubkeyIfExists(
|
|
@@ -8588,7 +8710,7 @@ var DLMM = class {
|
|
|
8588
8710
|
swapForY,
|
|
8589
8711
|
new (0, _anchor.BN)(activeIdToLoop),
|
|
8590
8712
|
this.lbPair,
|
|
8591
|
-
_nullishCoalesce(_optionalChain([this, 'access',
|
|
8713
|
+
_nullishCoalesce(_optionalChain([this, 'access', _70 => _70.binArrayBitmapExtension, 'optionalAccess', _71 => _71.account]), () => ( null))
|
|
8592
8714
|
);
|
|
8593
8715
|
if (binArrayIndex === null)
|
|
8594
8716
|
shouldStop = true;
|
|
@@ -8829,6 +8951,20 @@ var DLMM = class {
|
|
|
8829
8951
|
async getPositionsByUserAndLbPair(userPubKey) {
|
|
8830
8952
|
const promiseResults = await Promise.all([
|
|
8831
8953
|
this.getActiveBin(),
|
|
8954
|
+
userPubKey && this.program.account.position.all([
|
|
8955
|
+
{
|
|
8956
|
+
memcmp: {
|
|
8957
|
+
bytes: _bytes.bs58.encode(userPubKey.toBuffer()),
|
|
8958
|
+
offset: 8 + 32
|
|
8959
|
+
}
|
|
8960
|
+
},
|
|
8961
|
+
{
|
|
8962
|
+
memcmp: {
|
|
8963
|
+
bytes: _bytes.bs58.encode(this.pubkey.toBuffer()),
|
|
8964
|
+
offset: 8
|
|
8965
|
+
}
|
|
8966
|
+
}
|
|
8967
|
+
]),
|
|
8832
8968
|
userPubKey && this.program.account.positionV2.all([
|
|
8833
8969
|
{
|
|
8834
8970
|
memcmp: {
|
|
@@ -8844,7 +8980,7 @@ var DLMM = class {
|
|
|
8844
8980
|
}
|
|
8845
8981
|
])
|
|
8846
8982
|
]);
|
|
8847
|
-
const [activeBin, positionsV2] = promiseResults;
|
|
8983
|
+
const [activeBin, positions, positionsV2] = promiseResults;
|
|
8848
8984
|
if (!activeBin) {
|
|
8849
8985
|
throw new Error("Error fetching active bin");
|
|
8850
8986
|
}
|
|
@@ -8854,9 +8990,29 @@ var DLMM = class {
|
|
|
8854
8990
|
userPositions: []
|
|
8855
8991
|
};
|
|
8856
8992
|
}
|
|
8857
|
-
if (!positionsV2) {
|
|
8993
|
+
if (!positions || !positionsV2) {
|
|
8858
8994
|
throw new Error("Error fetching positions");
|
|
8859
8995
|
}
|
|
8996
|
+
const binArrayPubkeySet = /* @__PURE__ */ new Set();
|
|
8997
|
+
positions.forEach(({ account: { upperBinId, lowerBinId } }) => {
|
|
8998
|
+
const lowerBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(lowerBinId));
|
|
8999
|
+
const upperBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(upperBinId));
|
|
9000
|
+
const [lowerBinArrayPubKey] = deriveBinArray(
|
|
9001
|
+
this.pubkey,
|
|
9002
|
+
lowerBinArrayIndex,
|
|
9003
|
+
this.program.programId
|
|
9004
|
+
);
|
|
9005
|
+
const [upperBinArrayPubKey] = deriveBinArray(
|
|
9006
|
+
this.pubkey,
|
|
9007
|
+
upperBinArrayIndex,
|
|
9008
|
+
this.program.programId
|
|
9009
|
+
);
|
|
9010
|
+
binArrayPubkeySet.add(lowerBinArrayPubKey.toBase58());
|
|
9011
|
+
binArrayPubkeySet.add(upperBinArrayPubKey.toBase58());
|
|
9012
|
+
});
|
|
9013
|
+
const binArrayPubkeyArray = Array.from(binArrayPubkeySet).map(
|
|
9014
|
+
(pubkey) => new (0, _web3js.PublicKey)(pubkey)
|
|
9015
|
+
);
|
|
8860
9016
|
const binArrayPubkeySetV2 = /* @__PURE__ */ new Set();
|
|
8861
9017
|
positionsV2.forEach(({ account: { upperBinId, lowerBinId, lbPair } }) => {
|
|
8862
9018
|
const lowerBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(lowerBinId));
|
|
@@ -8882,13 +9038,28 @@ var DLMM = class {
|
|
|
8882
9038
|
[
|
|
8883
9039
|
this.pubkey,
|
|
8884
9040
|
_web3js.SYSVAR_CLOCK_PUBKEY,
|
|
9041
|
+
...binArrayPubkeyArray,
|
|
8885
9042
|
...binArrayPubkeyArrayV2
|
|
8886
9043
|
]
|
|
8887
9044
|
);
|
|
8888
9045
|
const [lbPairAccInfo, clockAccInfo, ...binArraysAccInfo] = lbPairAndBinArrays;
|
|
9046
|
+
const positionBinArraysMap = /* @__PURE__ */ new Map();
|
|
9047
|
+
for (let i = 0; i < binArrayPubkeyArray.length; i++) {
|
|
9048
|
+
const binArrayPubkey = binArrayPubkeyArray[i];
|
|
9049
|
+
const binArrayAccBuffer = binArraysAccInfo[i];
|
|
9050
|
+
if (!binArrayAccBuffer)
|
|
9051
|
+
throw new Error(
|
|
9052
|
+
`Bin Array account ${binArrayPubkey.toBase58()} not found`
|
|
9053
|
+
);
|
|
9054
|
+
const binArrayAccInfo = this.program.coder.accounts.decode(
|
|
9055
|
+
"binArray",
|
|
9056
|
+
binArrayAccBuffer.data
|
|
9057
|
+
);
|
|
9058
|
+
positionBinArraysMap.set(binArrayPubkey.toBase58(), binArrayAccInfo);
|
|
9059
|
+
}
|
|
8889
9060
|
const positionBinArraysMapV2 = /* @__PURE__ */ new Map();
|
|
8890
|
-
for (let i =
|
|
8891
|
-
const binArrayPubkey = binArrayPubkeyArrayV2[i];
|
|
9061
|
+
for (let i = binArrayPubkeyArray.length; i < binArraysAccInfo.length; i++) {
|
|
9062
|
+
const binArrayPubkey = binArrayPubkeyArrayV2[i - binArrayPubkeyArray.length];
|
|
8892
9063
|
const binArrayAccBufferV2 = binArraysAccInfo[i];
|
|
8893
9064
|
if (!binArrayAccBufferV2)
|
|
8894
9065
|
throw new Error(
|
|
@@ -8905,6 +9076,45 @@ var DLMM = class {
|
|
|
8905
9076
|
const onChainTimestamp = new (0, _anchor.BN)(
|
|
8906
9077
|
clockAccInfo.data.readBigInt64LE(32).toString()
|
|
8907
9078
|
).toNumber();
|
|
9079
|
+
const userPositions = await Promise.all(
|
|
9080
|
+
positions.map(async ({ publicKey, account }) => {
|
|
9081
|
+
const { lowerBinId, upperBinId } = account;
|
|
9082
|
+
const lowerBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(lowerBinId));
|
|
9083
|
+
const upperBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(upperBinId));
|
|
9084
|
+
const [lowerBinArrayPubKey] = deriveBinArray(
|
|
9085
|
+
this.pubkey,
|
|
9086
|
+
lowerBinArrayIndex,
|
|
9087
|
+
this.program.programId
|
|
9088
|
+
);
|
|
9089
|
+
const [upperBinArrayPubKey] = deriveBinArray(
|
|
9090
|
+
this.pubkey,
|
|
9091
|
+
upperBinArrayIndex,
|
|
9092
|
+
this.program.programId
|
|
9093
|
+
);
|
|
9094
|
+
const lowerBinArray = positionBinArraysMap.get(
|
|
9095
|
+
lowerBinArrayPubKey.toBase58()
|
|
9096
|
+
);
|
|
9097
|
+
const upperBinArray = positionBinArraysMap.get(
|
|
9098
|
+
upperBinArrayPubKey.toBase58()
|
|
9099
|
+
);
|
|
9100
|
+
return {
|
|
9101
|
+
publicKey,
|
|
9102
|
+
positionData: await DLMM.processPosition(
|
|
9103
|
+
this.program,
|
|
9104
|
+
0 /* V1 */,
|
|
9105
|
+
this.lbPair,
|
|
9106
|
+
onChainTimestamp,
|
|
9107
|
+
account,
|
|
9108
|
+
this.tokenX.decimal,
|
|
9109
|
+
this.tokenY.decimal,
|
|
9110
|
+
lowerBinArray,
|
|
9111
|
+
upperBinArray,
|
|
9112
|
+
_web3js.PublicKey.default
|
|
9113
|
+
),
|
|
9114
|
+
version: 0 /* V1 */
|
|
9115
|
+
};
|
|
9116
|
+
})
|
|
9117
|
+
);
|
|
8908
9118
|
const userPositionsV2 = await Promise.all(
|
|
8909
9119
|
positionsV2.map(async ({ publicKey, account }) => {
|
|
8910
9120
|
const { lowerBinId, upperBinId, feeOwner } = account;
|
|
@@ -8946,7 +9156,7 @@ var DLMM = class {
|
|
|
8946
9156
|
);
|
|
8947
9157
|
return {
|
|
8948
9158
|
activeBin,
|
|
8949
|
-
userPositions: userPositionsV2
|
|
9159
|
+
userPositions: [...userPositions, ...userPositionsV2]
|
|
8950
9160
|
};
|
|
8951
9161
|
}
|
|
8952
9162
|
async quoteCreatePosition({ strategy }) {
|
|
@@ -9007,93 +9217,6 @@ var DLMM = class {
|
|
|
9007
9217
|
feePayer: user
|
|
9008
9218
|
}).add(setCUIx, ...instructions);
|
|
9009
9219
|
}
|
|
9010
|
-
/**
|
|
9011
|
-
* The function `getPosition` retrieves position information for a given public key and processes it
|
|
9012
|
-
* using various data to return a `LbPosition` object.
|
|
9013
|
-
* @param {PublicKey} positionPubKey - The `getPosition` function you provided is an asynchronous
|
|
9014
|
-
* function that fetches position information based on a given public key. Here's a breakdown of the
|
|
9015
|
-
* parameters used in the function:
|
|
9016
|
-
* @returns The `getPosition` function returns a Promise that resolves to an object of type
|
|
9017
|
-
* `LbPosition`. The object contains the following properties:
|
|
9018
|
-
* - `publicKey`: The public key of the position account
|
|
9019
|
-
* - `positionData`: Position Object
|
|
9020
|
-
* - `version`: The version of the position (in this case, `Position.V2`)
|
|
9021
|
-
*/
|
|
9022
|
-
async getPosition(positionPubKey) {
|
|
9023
|
-
const positionAccountInfo = await this.program.account.positionV2.fetch(positionPubKey);
|
|
9024
|
-
if (!positionAccountInfo) {
|
|
9025
|
-
throw new Error(`Position account ${positionPubKey.toBase58()} not found`);
|
|
9026
|
-
}
|
|
9027
|
-
const { lowerBinId, upperBinId, feeOwner } = positionAccountInfo;
|
|
9028
|
-
const lowerBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(lowerBinId));
|
|
9029
|
-
const upperBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(upperBinId));
|
|
9030
|
-
const [lowerBinArrayPubKey] = deriveBinArray(
|
|
9031
|
-
this.pubkey,
|
|
9032
|
-
lowerBinArrayIndex,
|
|
9033
|
-
this.program.programId
|
|
9034
|
-
);
|
|
9035
|
-
const [upperBinArrayPubKey] = deriveBinArray(
|
|
9036
|
-
this.pubkey,
|
|
9037
|
-
upperBinArrayIndex,
|
|
9038
|
-
this.program.programId
|
|
9039
|
-
);
|
|
9040
|
-
const [clockAccInfo, lowerBinArrayAccInfo, upperBinArrayAccInfo] = await chunkedGetMultipleAccountInfos(
|
|
9041
|
-
this.program.provider.connection,
|
|
9042
|
-
[
|
|
9043
|
-
_web3js.SYSVAR_CLOCK_PUBKEY,
|
|
9044
|
-
lowerBinArrayPubKey,
|
|
9045
|
-
upperBinArrayPubKey
|
|
9046
|
-
]
|
|
9047
|
-
);
|
|
9048
|
-
if (!lowerBinArrayAccInfo || !upperBinArrayAccInfo) {
|
|
9049
|
-
return {
|
|
9050
|
-
publicKey: positionPubKey,
|
|
9051
|
-
positionData: {
|
|
9052
|
-
totalXAmount: "0",
|
|
9053
|
-
totalYAmount: "0",
|
|
9054
|
-
positionBinData: [],
|
|
9055
|
-
lastUpdatedAt: new (0, _anchor.BN)(0),
|
|
9056
|
-
upperBinId,
|
|
9057
|
-
lowerBinId,
|
|
9058
|
-
feeX: new (0, _anchor.BN)(0),
|
|
9059
|
-
feeY: new (0, _anchor.BN)(0),
|
|
9060
|
-
rewardOne: new (0, _anchor.BN)(0),
|
|
9061
|
-
rewardTwo: new (0, _anchor.BN)(0),
|
|
9062
|
-
feeOwner,
|
|
9063
|
-
totalClaimedFeeXAmount: new (0, _anchor.BN)(0),
|
|
9064
|
-
totalClaimedFeeYAmount: new (0, _anchor.BN)(0)
|
|
9065
|
-
},
|
|
9066
|
-
version: 1 /* V2 */
|
|
9067
|
-
};
|
|
9068
|
-
}
|
|
9069
|
-
const onChainTimestamp = new (0, _anchor.BN)(
|
|
9070
|
-
clockAccInfo.data.readBigInt64LE(32).toString()
|
|
9071
|
-
).toNumber();
|
|
9072
|
-
const lowerBinArray = this.program.coder.accounts.decode(
|
|
9073
|
-
"binArray",
|
|
9074
|
-
lowerBinArrayAccInfo.data
|
|
9075
|
-
);
|
|
9076
|
-
const upperBinArray = this.program.coder.accounts.decode(
|
|
9077
|
-
"binArray",
|
|
9078
|
-
upperBinArrayAccInfo.data
|
|
9079
|
-
);
|
|
9080
|
-
return {
|
|
9081
|
-
publicKey: positionPubKey,
|
|
9082
|
-
positionData: await DLMM.processPosition(
|
|
9083
|
-
this.program,
|
|
9084
|
-
1 /* V2 */,
|
|
9085
|
-
this.lbPair,
|
|
9086
|
-
onChainTimestamp,
|
|
9087
|
-
positionAccountInfo,
|
|
9088
|
-
this.tokenX.decimal,
|
|
9089
|
-
this.tokenY.decimal,
|
|
9090
|
-
lowerBinArray,
|
|
9091
|
-
upperBinArray,
|
|
9092
|
-
feeOwner
|
|
9093
|
-
),
|
|
9094
|
-
version: 1 /* V2 */
|
|
9095
|
-
};
|
|
9096
|
-
}
|
|
9097
9220
|
/**
|
|
9098
9221
|
* The function `initializePositionAndAddLiquidityByStrategy` function is used to initializes a position and adds liquidity
|
|
9099
9222
|
* @param {TInitializePositionAndAddLiquidityParamsByStrategy}
|
|
@@ -9817,13 +9940,9 @@ var DLMM = class {
|
|
|
9817
9940
|
bps,
|
|
9818
9941
|
shouldClaimAndClose = false
|
|
9819
9942
|
}) {
|
|
9820
|
-
const
|
|
9821
|
-
const
|
|
9822
|
-
const
|
|
9823
|
-
if (liquidityShares.every((share) => share.isZero())) {
|
|
9824
|
-
throw new Error("No liquidity to remove");
|
|
9825
|
-
}
|
|
9826
|
-
const lowerBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(positionLowerBinId));
|
|
9943
|
+
const { lbPair, lowerBinId, owner, feeOwner } = await this.program.account.positionV2.fetch(position);
|
|
9944
|
+
const { reserveX, reserveY, tokenXMint, tokenYMint } = await this.program.account.lbPair.fetch(lbPair);
|
|
9945
|
+
const lowerBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(lowerBinId));
|
|
9827
9946
|
const upperBinArrayIndex = lowerBinArrayIndex.add(new (0, _anchor.BN)(1));
|
|
9828
9947
|
const [binArrayLower] = deriveBinArray(
|
|
9829
9948
|
lbPair,
|
|
@@ -9883,8 +10002,8 @@ var DLMM = class {
|
|
|
9883
10002
|
lbPair: this.pubkey,
|
|
9884
10003
|
sender: user,
|
|
9885
10004
|
position,
|
|
9886
|
-
reserveX
|
|
9887
|
-
reserveY
|
|
10005
|
+
reserveX,
|
|
10006
|
+
reserveY,
|
|
9888
10007
|
tokenProgram: _spltoken.TOKEN_PROGRAM_ID,
|
|
9889
10008
|
tokenXMint: this.tokenX.publicKey,
|
|
9890
10009
|
tokenYMint: this.tokenY.publicKey,
|
|
@@ -9937,19 +10056,21 @@ var DLMM = class {
|
|
|
9937
10056
|
const closeWrappedSOLIx = await unwrapSOLInstruction(user);
|
|
9938
10057
|
closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
|
|
9939
10058
|
}
|
|
9940
|
-
const
|
|
9941
|
-
const
|
|
10059
|
+
const minBinId = Math.min(...binIds);
|
|
10060
|
+
const maxBinId = Math.max(...binIds);
|
|
10061
|
+
const minBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(minBinId));
|
|
10062
|
+
const maxBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(maxBinId));
|
|
9942
10063
|
const useExtension = isOverflowDefaultBinArrayBitmap(minBinArrayIndex) || isOverflowDefaultBinArrayBitmap(maxBinArrayIndex);
|
|
9943
10064
|
const binArrayBitmapExtension = useExtension ? deriveBinArrayBitmapExtension(this.pubkey, this.program.programId)[0] : null;
|
|
9944
|
-
const
|
|
10065
|
+
const removeLiquidityIx = await this.program.methods.removeLiquidityByRange(minBinId, maxBinId, bps.toNumber()).accounts({
|
|
9945
10066
|
position,
|
|
9946
10067
|
lbPair,
|
|
9947
10068
|
userTokenX,
|
|
9948
10069
|
userTokenY,
|
|
9949
|
-
reserveX
|
|
9950
|
-
reserveY
|
|
9951
|
-
tokenXMint
|
|
9952
|
-
tokenYMint
|
|
10070
|
+
reserveX,
|
|
10071
|
+
reserveY,
|
|
10072
|
+
tokenXMint,
|
|
10073
|
+
tokenYMint,
|
|
9953
10074
|
binArrayLower,
|
|
9954
10075
|
binArrayUpper,
|
|
9955
10076
|
binArrayBitmapExtension,
|
|
@@ -9959,7 +10080,7 @@ var DLMM = class {
|
|
|
9959
10080
|
}).instruction();
|
|
9960
10081
|
const instructions = [
|
|
9961
10082
|
...preInstructions,
|
|
9962
|
-
|
|
10083
|
+
removeLiquidityIx,
|
|
9963
10084
|
...postInstructions
|
|
9964
10085
|
];
|
|
9965
10086
|
const setCUIx = await getEstimatedComputeUnitIxWithBuffer(
|
|
@@ -10075,7 +10196,7 @@ var DLMM = class {
|
|
|
10075
10196
|
swapForY,
|
|
10076
10197
|
activeId,
|
|
10077
10198
|
this.lbPair,
|
|
10078
|
-
_nullishCoalesce(_optionalChain([this, 'access',
|
|
10199
|
+
_nullishCoalesce(_optionalChain([this, 'access', _72 => _72.binArrayBitmapExtension, 'optionalAccess', _73 => _73.account]), () => ( null)),
|
|
10079
10200
|
binArrays
|
|
10080
10201
|
);
|
|
10081
10202
|
if (binArrayAccountToSwap == null) {
|
|
@@ -10174,13 +10295,12 @@ var DLMM = class {
|
|
|
10174
10295
|
let actualOutAmount = new (0, _anchor.BN)(0);
|
|
10175
10296
|
let feeAmount = new (0, _anchor.BN)(0);
|
|
10176
10297
|
let protocolFeeAmount = new (0, _anchor.BN)(0);
|
|
10177
|
-
let lastFilledActiveBinId = activeId;
|
|
10178
10298
|
while (!inAmountLeft.isZero()) {
|
|
10179
10299
|
let binArrayAccountToSwap = findNextBinArrayWithLiquidity(
|
|
10180
10300
|
swapForY,
|
|
10181
10301
|
activeId,
|
|
10182
10302
|
this.lbPair,
|
|
10183
|
-
_nullishCoalesce(_optionalChain([this, 'access',
|
|
10303
|
+
_nullishCoalesce(_optionalChain([this, 'access', _74 => _74.binArrayBitmapExtension, 'optionalAccess', _75 => _75.account]), () => ( null)),
|
|
10184
10304
|
binArrays
|
|
10185
10305
|
);
|
|
10186
10306
|
if (binArrayAccountToSwap == null) {
|
|
@@ -10220,7 +10340,6 @@ var DLMM = class {
|
|
|
10220
10340
|
if (!startBin) {
|
|
10221
10341
|
startBin = bin;
|
|
10222
10342
|
}
|
|
10223
|
-
lastFilledActiveBinId = activeId;
|
|
10224
10343
|
}
|
|
10225
10344
|
}
|
|
10226
10345
|
if (!inAmountLeft.isZero()) {
|
|
@@ -10248,7 +10367,7 @@ var DLMM = class {
|
|
|
10248
10367
|
const priceImpact = new (0, _decimaljs2.default)(actualOutAmount.toString()).sub(new (0, _decimaljs2.default)(outAmountWithoutSlippage.toString())).div(new (0, _decimaljs2.default)(outAmountWithoutSlippage.toString())).mul(new (0, _decimaljs2.default)(100));
|
|
10249
10368
|
const minOutAmount = actualOutAmount.mul(new (0, _anchor.BN)(BASIS_POINT_MAX).sub(allowedSlippage)).div(new (0, _anchor.BN)(BASIS_POINT_MAX));
|
|
10250
10369
|
const endPrice = getPriceOfBinByBinId(
|
|
10251
|
-
|
|
10370
|
+
activeId.toNumber(),
|
|
10252
10371
|
this.lbPair.binStep
|
|
10253
10372
|
);
|
|
10254
10373
|
return {
|
|
@@ -10365,6 +10484,7 @@ var DLMM = class {
|
|
|
10365
10484
|
priceImpact,
|
|
10366
10485
|
binArraysPubkey
|
|
10367
10486
|
}) {
|
|
10487
|
+
const { tokenXMint, tokenYMint, reserveX, reserveY, activeId, oracle } = await this.program.account.lbPair.fetch(lbPair);
|
|
10368
10488
|
const preInstructions = [];
|
|
10369
10489
|
const postInstructions = [];
|
|
10370
10490
|
const [
|
|
@@ -10398,6 +10518,9 @@ var DLMM = class {
|
|
|
10398
10518
|
const closeWrappedSOLIx = await unwrapSOLInstruction(user);
|
|
10399
10519
|
closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
|
|
10400
10520
|
}
|
|
10521
|
+
let swapForY = true;
|
|
10522
|
+
if (outToken.equals(tokenXMint))
|
|
10523
|
+
swapForY = false;
|
|
10401
10524
|
const binArrays = binArraysPubkey.map((pubkey) => {
|
|
10402
10525
|
return {
|
|
10403
10526
|
isSigner: false,
|
|
@@ -10411,17 +10534,17 @@ var DLMM = class {
|
|
|
10411
10534
|
priceImpact.toNumber()
|
|
10412
10535
|
).accounts({
|
|
10413
10536
|
lbPair,
|
|
10414
|
-
reserveX
|
|
10415
|
-
reserveY
|
|
10416
|
-
tokenXMint
|
|
10417
|
-
tokenYMint
|
|
10537
|
+
reserveX,
|
|
10538
|
+
reserveY,
|
|
10539
|
+
tokenXMint,
|
|
10540
|
+
tokenYMint,
|
|
10418
10541
|
tokenXProgram: _spltoken.TOKEN_PROGRAM_ID,
|
|
10419
10542
|
tokenYProgram: _spltoken.TOKEN_PROGRAM_ID,
|
|
10420
10543
|
user,
|
|
10421
10544
|
userTokenIn,
|
|
10422
10545
|
userTokenOut,
|
|
10423
10546
|
binArrayBitmapExtension: this.binArrayBitmapExtension ? this.binArrayBitmapExtension.publicKey : null,
|
|
10424
|
-
oracle
|
|
10547
|
+
oracle,
|
|
10425
10548
|
hostFeeIn: null
|
|
10426
10549
|
}).remainingAccounts(binArrays).instruction();
|
|
10427
10550
|
const instructions = [...preInstructions, swapIx, ...postInstructions];
|
|
@@ -10459,6 +10582,7 @@ var DLMM = class {
|
|
|
10459
10582
|
user,
|
|
10460
10583
|
binArraysPubkey
|
|
10461
10584
|
}) {
|
|
10585
|
+
const { tokenXMint, tokenYMint, reserveX, reserveY, activeId, oracle } = await this.program.account.lbPair.fetch(lbPair);
|
|
10462
10586
|
const preInstructions = [];
|
|
10463
10587
|
const postInstructions = [];
|
|
10464
10588
|
const [
|
|
@@ -10492,6 +10616,9 @@ var DLMM = class {
|
|
|
10492
10616
|
const closeWrappedSOLIx = await unwrapSOLInstruction(user);
|
|
10493
10617
|
closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
|
|
10494
10618
|
}
|
|
10619
|
+
let swapForY = true;
|
|
10620
|
+
if (outToken.equals(tokenXMint))
|
|
10621
|
+
swapForY = false;
|
|
10495
10622
|
const binArrays = binArraysPubkey.map((pubkey) => {
|
|
10496
10623
|
return {
|
|
10497
10624
|
isSigner: false,
|
|
@@ -10501,10 +10628,10 @@ var DLMM = class {
|
|
|
10501
10628
|
});
|
|
10502
10629
|
const swapIx = await this.program.methods.swap(inAmount, minOutAmount).accounts({
|
|
10503
10630
|
lbPair,
|
|
10504
|
-
reserveX
|
|
10505
|
-
reserveY
|
|
10506
|
-
tokenXMint
|
|
10507
|
-
tokenYMint
|
|
10631
|
+
reserveX,
|
|
10632
|
+
reserveY,
|
|
10633
|
+
tokenXMint,
|
|
10634
|
+
tokenYMint,
|
|
10508
10635
|
tokenXProgram: _spltoken.TOKEN_PROGRAM_ID,
|
|
10509
10636
|
// dont use 2022 first; lack familiarity
|
|
10510
10637
|
tokenYProgram: _spltoken.TOKEN_PROGRAM_ID,
|
|
@@ -10513,7 +10640,7 @@ var DLMM = class {
|
|
|
10513
10640
|
userTokenIn,
|
|
10514
10641
|
userTokenOut,
|
|
10515
10642
|
binArrayBitmapExtension: this.binArrayBitmapExtension ? this.binArrayBitmapExtension.publicKey : null,
|
|
10516
|
-
oracle
|
|
10643
|
+
oracle,
|
|
10517
10644
|
hostFeeIn: null
|
|
10518
10645
|
}).remainingAccounts(binArrays).instruction();
|
|
10519
10646
|
const instructions = [...preInstructions, swapIx, ...postInstructions];
|
|
@@ -10615,21 +10742,6 @@ var DLMM = class {
|
|
|
10615
10742
|
lastValidBlockHeight
|
|
10616
10743
|
}).add(setActivationPointTx);
|
|
10617
10744
|
}
|
|
10618
|
-
async setPairStatus(enabled) {
|
|
10619
|
-
const pairStatus = enabled ? 0 : 1;
|
|
10620
|
-
const tx = await this.program.methods.setPairStatus(pairStatus).accounts(
|
|
10621
|
-
{
|
|
10622
|
-
lbPair: this.pubkey,
|
|
10623
|
-
admin: this.lbPair.creator
|
|
10624
|
-
}
|
|
10625
|
-
).transaction();
|
|
10626
|
-
const { blockhash, lastValidBlockHeight } = await this.program.provider.connection.getLatestBlockhash("confirmed");
|
|
10627
|
-
return new (0, _web3js.Transaction)({
|
|
10628
|
-
feePayer: this.lbPair.creator,
|
|
10629
|
-
blockhash,
|
|
10630
|
-
lastValidBlockHeight
|
|
10631
|
-
}).add(tx);
|
|
10632
|
-
}
|
|
10633
10745
|
/**
|
|
10634
10746
|
* The function `claimSwapFee` is used to claim swap fees for a specific position owned by a specific owner.
|
|
10635
10747
|
* @param
|
|
@@ -11374,7 +11486,7 @@ var DLMM = class {
|
|
|
11374
11486
|
swapForY,
|
|
11375
11487
|
new (0, _anchor.BN)(activeBinId),
|
|
11376
11488
|
this.lbPair,
|
|
11377
|
-
_nullishCoalesce(_optionalChain([this, 'access',
|
|
11489
|
+
_nullishCoalesce(_optionalChain([this, 'access', _76 => _76.binArrayBitmapExtension, 'optionalAccess', _77 => _77.account]), () => ( null))
|
|
11378
11490
|
);
|
|
11379
11491
|
if (toBinArrayIndex === null)
|
|
11380
11492
|
return true;
|
|
@@ -11411,7 +11523,7 @@ var DLMM = class {
|
|
|
11411
11523
|
swapForY,
|
|
11412
11524
|
new (0, _anchor.BN)(activeBinId),
|
|
11413
11525
|
this.lbPair,
|
|
11414
|
-
_nullishCoalesce(_optionalChain([this, 'access',
|
|
11526
|
+
_nullishCoalesce(_optionalChain([this, 'access', _78 => _78.binArrayBitmapExtension, 'optionalAccess', _79 => _79.account]), () => ( null))
|
|
11415
11527
|
);
|
|
11416
11528
|
const accountsToFetch = [];
|
|
11417
11529
|
const [binArrayBitMapExtensionPubkey] = deriveBinArrayBitmapExtension(
|
|
@@ -11442,13 +11554,13 @@ var DLMM = class {
|
|
|
11442
11554
|
let fromBinArray = null;
|
|
11443
11555
|
let toBinArray = null;
|
|
11444
11556
|
let binArrayBitmapExtension = null;
|
|
11445
|
-
if (!!_optionalChain([binArrayAccounts, 'optionalAccess',
|
|
11557
|
+
if (!!_optionalChain([binArrayAccounts, 'optionalAccess', _80 => _80[0]])) {
|
|
11446
11558
|
binArrayBitmapExtension = binArrayBitMapExtensionPubkey;
|
|
11447
11559
|
}
|
|
11448
|
-
if (!!_optionalChain([binArrayAccounts, 'optionalAccess',
|
|
11560
|
+
if (!!_optionalChain([binArrayAccounts, 'optionalAccess', _81 => _81[1]])) {
|
|
11449
11561
|
fromBinArray = fromBinArrayPubkey;
|
|
11450
11562
|
}
|
|
11451
|
-
if (!!_optionalChain([binArrayAccounts, 'optionalAccess',
|
|
11563
|
+
if (!!_optionalChain([binArrayAccounts, 'optionalAccess', _82 => _82[2]]) && !!toBinArrayIndex) {
|
|
11452
11564
|
toBinArray = toBinArrayPubkey;
|
|
11453
11565
|
}
|
|
11454
11566
|
const { blockhash, lastValidBlockHeight } = await this.program.provider.connection.getLatestBlockhash("confirmed");
|
|
@@ -11773,7 +11885,12 @@ var DLMM = class {
|
|
|
11773
11885
|
let totalYAmount = new (0, _decimaljs2.default)(0);
|
|
11774
11886
|
bins.forEach((bin, idx) => {
|
|
11775
11887
|
const binSupply = new (0, _decimaljs2.default)(bin.supply.toString());
|
|
11776
|
-
|
|
11888
|
+
let posShare;
|
|
11889
|
+
if (bin.version === 1 && version === 0 /* V1 */) {
|
|
11890
|
+
posShare = new (0, _decimaljs2.default)(posShares[idx].shln(64).toString());
|
|
11891
|
+
} else {
|
|
11892
|
+
posShare = new (0, _decimaljs2.default)(posShares[idx].toString());
|
|
11893
|
+
}
|
|
11777
11894
|
const positionXAmount = binSupply.eq(new (0, _decimaljs2.default)("0")) ? new (0, _decimaljs2.default)("0") : posShare.mul(bin.xAmount.toString()).div(binSupply);
|
|
11778
11895
|
const positionYAmount = binSupply.eq(new (0, _decimaljs2.default)("0")) ? new (0, _decimaljs2.default)("0") : posShare.mul(bin.yAmount.toString()).div(binSupply);
|
|
11779
11896
|
totalXAmount = totalXAmount.add(positionXAmount);
|
|
@@ -11924,7 +12041,7 @@ var DLMM = class {
|
|
|
11924
12041
|
const [lowerBinId2] = getBinArrayLowerUpperBinId(index);
|
|
11925
12042
|
return bins.map((b, i) => [lowerBinId2.toNumber() + i, b]);
|
|
11926
12043
|
}));
|
|
11927
|
-
const version = _nullishCoalesce(_optionalChain([binArrays, 'access',
|
|
12044
|
+
const version = _nullishCoalesce(_optionalChain([binArrays, 'access', _83 => _83.find, 'call', _84 => _84((binArray) => binArray != null), 'optionalAccess', _85 => _85.version]), () => ( 1));
|
|
11928
12045
|
return Array.from(enumerateBins(
|
|
11929
12046
|
binsById,
|
|
11930
12047
|
lowerBinId,
|
|
@@ -12217,5 +12334,6 @@ var src_default = DLMM;
|
|
|
12217
12334
|
|
|
12218
12335
|
|
|
12219
12336
|
|
|
12220
|
-
|
|
12337
|
+
|
|
12338
|
+
exports.ADMIN = ADMIN; exports.ActivationType = ActivationType; exports.BASIS_POINT_MAX = BASIS_POINT_MAX; exports.BIN_ARRAY_BITMAP_SIZE = BIN_ARRAY_BITMAP_SIZE; exports.BIN_ARRAY_FEE = BIN_ARRAY_FEE; exports.BinLiquidity = BinLiquidity; exports.BitmapType = BitmapType; exports.ClockLayout = ClockLayout; exports.DLMMError = DLMMError; exports.DlmmSdkError = DlmmSdkError; exports.EXTENSION_BINARRAY_BITMAP_SIZE = EXTENSION_BINARRAY_BITMAP_SIZE; exports.FEE_PRECISION = FEE_PRECISION; exports.IDL = IDL; exports.ILM_BASE = ILM_BASE; 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.PairStatus = PairStatus; 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.computeFee = computeFee; exports.computeFeeFromAmount = computeFeeFromAmount; exports.computeProtocolFee = computeProtocolFee; exports.default = src_default; exports.deriveBinArray = deriveBinArray; exports.deriveBinArrayBitmapExtension = deriveBinArrayBitmapExtension; exports.deriveCustomizablePermissionlessLbPair = deriveCustomizablePermissionlessLbPair; 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.enumerateBins = enumerateBins; 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.getEstimatedComputeUnitIxWithBuffer = getEstimatedComputeUnitIxWithBuffer; exports.getEstimatedComputeUnitUsageWithBuffer = getEstimatedComputeUnitUsageWithBuffer; 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.range = range; 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;
|
|
12221
12339
|
//# sourceMappingURL=index.js.map
|