@meteora-ag/dlmm 1.3.14-sam.0 → 1.3.17-rc.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 +247 -103
- package/dist/index.js +748 -559
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +754 -565
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -3
package/dist/index.mjs
CHANGED
|
@@ -6,13 +6,15 @@ import {
|
|
|
6
6
|
MintLayout,
|
|
7
7
|
NATIVE_MINT as NATIVE_MINT2,
|
|
8
8
|
TOKEN_PROGRAM_ID as TOKEN_PROGRAM_ID2,
|
|
9
|
+
createAssociatedTokenAccountIdempotentInstruction as createAssociatedTokenAccountIdempotentInstruction2,
|
|
9
10
|
createAssociatedTokenAccountInstruction as createAssociatedTokenAccountInstruction2,
|
|
10
11
|
createTransferInstruction,
|
|
11
|
-
getAssociatedTokenAddressSync as getAssociatedTokenAddressSync2
|
|
12
|
+
getAssociatedTokenAddressSync as getAssociatedTokenAddressSync2,
|
|
13
|
+
unpackAccount
|
|
12
14
|
} from "@solana/spl-token";
|
|
13
15
|
import {
|
|
14
|
-
ComputeBudgetProgram as
|
|
15
|
-
PublicKey as
|
|
16
|
+
ComputeBudgetProgram as ComputeBudgetProgram3,
|
|
17
|
+
PublicKey as PublicKey7,
|
|
16
18
|
SYSVAR_CLOCK_PUBKEY,
|
|
17
19
|
SYSVAR_RENT_PUBKEY,
|
|
18
20
|
SystemProgram as SystemProgram2,
|
|
@@ -25,7 +27,7 @@ import { PublicKey } from "@solana/web3.js";
|
|
|
25
27
|
|
|
26
28
|
// src/dlmm/idl.ts
|
|
27
29
|
var IDL = {
|
|
28
|
-
"version": "0.8.
|
|
30
|
+
"version": "0.8.6",
|
|
29
31
|
"name": "lb_clmm",
|
|
30
32
|
"constants": [
|
|
31
33
|
{
|
|
@@ -113,6 +115,16 @@ var IDL = {
|
|
|
113
115
|
},
|
|
114
116
|
"value": "15"
|
|
115
117
|
},
|
|
118
|
+
{
|
|
119
|
+
"name": "ILM_PROTOCOL_SHARE",
|
|
120
|
+
"type": "u16",
|
|
121
|
+
"value": "2000"
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
"name": "PROTOCOL_SHARE",
|
|
125
|
+
"type": "u16",
|
|
126
|
+
"value": "500"
|
|
127
|
+
},
|
|
116
128
|
{
|
|
117
129
|
"name": "MAX_BIN_STEP",
|
|
118
130
|
"type": "u16",
|
|
@@ -128,6 +140,11 @@ var IDL = {
|
|
|
128
140
|
"type": "u128",
|
|
129
141
|
"value": "100_000"
|
|
130
142
|
},
|
|
143
|
+
{
|
|
144
|
+
"name": "MINIMUM_LIQUIDITY",
|
|
145
|
+
"type": "u128",
|
|
146
|
+
"value": "1_000_000"
|
|
147
|
+
},
|
|
131
148
|
{
|
|
132
149
|
"name": "BIN_ARRAY",
|
|
133
150
|
"type": "bytes",
|
|
@@ -385,7 +402,7 @@ var IDL = {
|
|
|
385
402
|
"isSigner": false
|
|
386
403
|
},
|
|
387
404
|
{
|
|
388
|
-
"name": "
|
|
405
|
+
"name": "userTokenY",
|
|
389
406
|
"isMut": false,
|
|
390
407
|
"isSigner": false
|
|
391
408
|
},
|
|
@@ -1964,7 +1981,40 @@ var IDL = {
|
|
|
1964
1981
|
"args": []
|
|
1965
1982
|
},
|
|
1966
1983
|
{
|
|
1967
|
-
"name": "
|
|
1984
|
+
"name": "updateBaseFeeParameters",
|
|
1985
|
+
"accounts": [
|
|
1986
|
+
{
|
|
1987
|
+
"name": "lbPair",
|
|
1988
|
+
"isMut": true,
|
|
1989
|
+
"isSigner": false
|
|
1990
|
+
},
|
|
1991
|
+
{
|
|
1992
|
+
"name": "admin",
|
|
1993
|
+
"isMut": false,
|
|
1994
|
+
"isSigner": true
|
|
1995
|
+
},
|
|
1996
|
+
{
|
|
1997
|
+
"name": "eventAuthority",
|
|
1998
|
+
"isMut": false,
|
|
1999
|
+
"isSigner": false
|
|
2000
|
+
},
|
|
2001
|
+
{
|
|
2002
|
+
"name": "program",
|
|
2003
|
+
"isMut": false,
|
|
2004
|
+
"isSigner": false
|
|
2005
|
+
}
|
|
2006
|
+
],
|
|
2007
|
+
"args": [
|
|
2008
|
+
{
|
|
2009
|
+
"name": "feeParameter",
|
|
2010
|
+
"type": {
|
|
2011
|
+
"defined": "BaseFeeParameter"
|
|
2012
|
+
}
|
|
2013
|
+
}
|
|
2014
|
+
]
|
|
2015
|
+
},
|
|
2016
|
+
{
|
|
2017
|
+
"name": "updateDynamicFeeParameters",
|
|
1968
2018
|
"accounts": [
|
|
1969
2019
|
{
|
|
1970
2020
|
"name": "lbPair",
|
|
@@ -1991,7 +2041,7 @@ var IDL = {
|
|
|
1991
2041
|
{
|
|
1992
2042
|
"name": "feeParameter",
|
|
1993
2043
|
"type": {
|
|
1994
|
-
"defined": "
|
|
2044
|
+
"defined": "DynamicFeeParameter"
|
|
1995
2045
|
}
|
|
1996
2046
|
}
|
|
1997
2047
|
]
|
|
@@ -2174,7 +2224,7 @@ var IDL = {
|
|
|
2174
2224
|
"args": []
|
|
2175
2225
|
},
|
|
2176
2226
|
{
|
|
2177
|
-
"name": "
|
|
2227
|
+
"name": "setPairStatus",
|
|
2178
2228
|
"accounts": [
|
|
2179
2229
|
{
|
|
2180
2230
|
"name": "lbPair",
|
|
@@ -2187,7 +2237,12 @@ var IDL = {
|
|
|
2187
2237
|
"isSigner": true
|
|
2188
2238
|
}
|
|
2189
2239
|
],
|
|
2190
|
-
"args": [
|
|
2240
|
+
"args": [
|
|
2241
|
+
{
|
|
2242
|
+
"name": "status",
|
|
2243
|
+
"type": "u8"
|
|
2244
|
+
}
|
|
2245
|
+
]
|
|
2191
2246
|
},
|
|
2192
2247
|
{
|
|
2193
2248
|
"name": "migratePosition",
|
|
@@ -2623,6 +2678,27 @@ var IDL = {
|
|
|
2623
2678
|
"type": "publicKey"
|
|
2624
2679
|
}
|
|
2625
2680
|
]
|
|
2681
|
+
},
|
|
2682
|
+
{
|
|
2683
|
+
"name": "setPairStatusPermissionless",
|
|
2684
|
+
"accounts": [
|
|
2685
|
+
{
|
|
2686
|
+
"name": "lbPair",
|
|
2687
|
+
"isMut": true,
|
|
2688
|
+
"isSigner": false
|
|
2689
|
+
},
|
|
2690
|
+
{
|
|
2691
|
+
"name": "creator",
|
|
2692
|
+
"isMut": false,
|
|
2693
|
+
"isSigner": true
|
|
2694
|
+
}
|
|
2695
|
+
],
|
|
2696
|
+
"args": [
|
|
2697
|
+
{
|
|
2698
|
+
"name": "status",
|
|
2699
|
+
"type": "u8"
|
|
2700
|
+
}
|
|
2701
|
+
]
|
|
2626
2702
|
}
|
|
2627
2703
|
],
|
|
2628
2704
|
"accounts": [
|
|
@@ -2814,9 +2890,9 @@ var IDL = {
|
|
|
2814
2890
|
"type": "u8"
|
|
2815
2891
|
},
|
|
2816
2892
|
{
|
|
2817
|
-
"name": "
|
|
2893
|
+
"name": "creatorPoolOnOffControl",
|
|
2818
2894
|
"docs": [
|
|
2819
|
-
"
|
|
2895
|
+
"Allow pool creator to enable/disable pool with restricted validation. Only applicable for customizable permissionless pair type."
|
|
2820
2896
|
],
|
|
2821
2897
|
"type": "u8"
|
|
2822
2898
|
},
|
|
@@ -3448,7 +3524,7 @@ var IDL = {
|
|
|
3448
3524
|
}
|
|
3449
3525
|
},
|
|
3450
3526
|
{
|
|
3451
|
-
"name": "
|
|
3527
|
+
"name": "BaseFeeParameter",
|
|
3452
3528
|
"type": {
|
|
3453
3529
|
"kind": "struct",
|
|
3454
3530
|
"fields": [
|
|
@@ -3469,6 +3545,49 @@ var IDL = {
|
|
|
3469
3545
|
]
|
|
3470
3546
|
}
|
|
3471
3547
|
},
|
|
3548
|
+
{
|
|
3549
|
+
"name": "DynamicFeeParameter",
|
|
3550
|
+
"type": {
|
|
3551
|
+
"kind": "struct",
|
|
3552
|
+
"fields": [
|
|
3553
|
+
{
|
|
3554
|
+
"name": "filterPeriod",
|
|
3555
|
+
"docs": [
|
|
3556
|
+
"Filter period determine high frequency trading time window."
|
|
3557
|
+
],
|
|
3558
|
+
"type": "u16"
|
|
3559
|
+
},
|
|
3560
|
+
{
|
|
3561
|
+
"name": "decayPeriod",
|
|
3562
|
+
"docs": [
|
|
3563
|
+
"Decay period determine when the volatile fee start decay / decrease."
|
|
3564
|
+
],
|
|
3565
|
+
"type": "u16"
|
|
3566
|
+
},
|
|
3567
|
+
{
|
|
3568
|
+
"name": "reductionFactor",
|
|
3569
|
+
"docs": [
|
|
3570
|
+
"Reduction factor controls the volatile fee rate decrement rate."
|
|
3571
|
+
],
|
|
3572
|
+
"type": "u16"
|
|
3573
|
+
},
|
|
3574
|
+
{
|
|
3575
|
+
"name": "variableFeeControl",
|
|
3576
|
+
"docs": [
|
|
3577
|
+
"Used to scale the variable fee component depending on the dynamic of the market"
|
|
3578
|
+
],
|
|
3579
|
+
"type": "u32"
|
|
3580
|
+
},
|
|
3581
|
+
{
|
|
3582
|
+
"name": "maxVolatilityAccumulator",
|
|
3583
|
+
"docs": [
|
|
3584
|
+
"Maximum number of bin crossed can be accumulated. Used to cap volatile fee rate."
|
|
3585
|
+
],
|
|
3586
|
+
"type": "u32"
|
|
3587
|
+
}
|
|
3588
|
+
]
|
|
3589
|
+
}
|
|
3590
|
+
},
|
|
3472
3591
|
{
|
|
3473
3592
|
"name": "LiquidityParameterByStrategyOneSide",
|
|
3474
3593
|
"type": {
|
|
@@ -3851,6 +3970,13 @@ var IDL = {
|
|
|
3851
3970
|
"option": "u64"
|
|
3852
3971
|
}
|
|
3853
3972
|
},
|
|
3973
|
+
{
|
|
3974
|
+
"name": "creatorPoolOnOffControl",
|
|
3975
|
+
"docs": [
|
|
3976
|
+
"Pool creator have permission to enable/disable pool with restricted program validation. Only applicable for customizable permissionless pool."
|
|
3977
|
+
],
|
|
3978
|
+
"type": "bool"
|
|
3979
|
+
},
|
|
3854
3980
|
{
|
|
3855
3981
|
"name": "padding",
|
|
3856
3982
|
"docs": [
|
|
@@ -3859,7 +3985,7 @@ var IDL = {
|
|
|
3859
3985
|
"type": {
|
|
3860
3986
|
"array": [
|
|
3861
3987
|
"u8",
|
|
3862
|
-
|
|
3988
|
+
63
|
|
3863
3989
|
]
|
|
3864
3990
|
}
|
|
3865
3991
|
}
|
|
@@ -4834,6 +4960,41 @@ var IDL = {
|
|
|
4834
4960
|
}
|
|
4835
4961
|
]
|
|
4836
4962
|
},
|
|
4963
|
+
{
|
|
4964
|
+
"name": "DynamicFeeParameterUpdate",
|
|
4965
|
+
"fields": [
|
|
4966
|
+
{
|
|
4967
|
+
"name": "lbPair",
|
|
4968
|
+
"type": "publicKey",
|
|
4969
|
+
"index": false
|
|
4970
|
+
},
|
|
4971
|
+
{
|
|
4972
|
+
"name": "filterPeriod",
|
|
4973
|
+
"type": "u16",
|
|
4974
|
+
"index": false
|
|
4975
|
+
},
|
|
4976
|
+
{
|
|
4977
|
+
"name": "decayPeriod",
|
|
4978
|
+
"type": "u16",
|
|
4979
|
+
"index": false
|
|
4980
|
+
},
|
|
4981
|
+
{
|
|
4982
|
+
"name": "reductionFactor",
|
|
4983
|
+
"type": "u16",
|
|
4984
|
+
"index": false
|
|
4985
|
+
},
|
|
4986
|
+
{
|
|
4987
|
+
"name": "variableFeeControl",
|
|
4988
|
+
"type": "u32",
|
|
4989
|
+
"index": false
|
|
4990
|
+
},
|
|
4991
|
+
{
|
|
4992
|
+
"name": "maxVolatilityAccumulator",
|
|
4993
|
+
"type": "u32",
|
|
4994
|
+
"index": false
|
|
4995
|
+
}
|
|
4996
|
+
]
|
|
4997
|
+
},
|
|
4837
4998
|
{
|
|
4838
4999
|
"name": "IncreaseObservation",
|
|
4839
5000
|
"fields": [
|
|
@@ -5270,6 +5431,21 @@ var IDL = {
|
|
|
5270
5431
|
"code": 6065,
|
|
5271
5432
|
"name": "AlreadyPassPreActivationSwapPoint",
|
|
5272
5433
|
"msg": "Already pass pre-activation swap point"
|
|
5434
|
+
},
|
|
5435
|
+
{
|
|
5436
|
+
"code": 6066,
|
|
5437
|
+
"name": "InvalidStatus",
|
|
5438
|
+
"msg": "Invalid status"
|
|
5439
|
+
},
|
|
5440
|
+
{
|
|
5441
|
+
"code": 6067,
|
|
5442
|
+
"name": "ExceededMaxOracleLength",
|
|
5443
|
+
"msg": "Exceed max oracle length"
|
|
5444
|
+
},
|
|
5445
|
+
{
|
|
5446
|
+
"code": 6068,
|
|
5447
|
+
"name": "InvalidMinimumLiquidity",
|
|
5448
|
+
"msg": "Invalid minimum liquidity"
|
|
5273
5449
|
}
|
|
5274
5450
|
]
|
|
5275
5451
|
};
|
|
@@ -5303,6 +5479,7 @@ var CONSTANTS = Object.entries(IDL.constants);
|
|
|
5303
5479
|
var MAX_BIN_ARRAY_SIZE = new BN(
|
|
5304
5480
|
CONSTANTS.find(([k, v]) => v.name == "MAX_BIN_PER_ARRAY")?.[1].value ?? 0
|
|
5305
5481
|
);
|
|
5482
|
+
console.log("CONSTANTS", CONSTANTS);
|
|
5306
5483
|
var MAX_BIN_PER_POSITION = new BN(
|
|
5307
5484
|
CONSTANTS.find(([k, v]) => v.name == "MAX_BIN_PER_POSITION")?.[1].value ?? 0
|
|
5308
5485
|
);
|
|
@@ -5323,6 +5500,7 @@ var MAX_ACTIVE_BIN_SLIPPAGE = 3;
|
|
|
5323
5500
|
var ILM_BASE = new PublicKey(
|
|
5324
5501
|
"MFGQxwAmB91SwuYX36okv2Qmdc9aMuHTwWGUrp4AtB1"
|
|
5325
5502
|
);
|
|
5503
|
+
var MAX_EXTRA_BIN_ARRAYS = 3;
|
|
5326
5504
|
|
|
5327
5505
|
// src/dlmm/error.ts
|
|
5328
5506
|
import { AnchorError } from "@coral-xyz/anchor";
|
|
@@ -5373,16 +5551,16 @@ import {
|
|
|
5373
5551
|
TOKEN_PROGRAM_ID,
|
|
5374
5552
|
TokenAccountNotFoundError,
|
|
5375
5553
|
TokenInvalidAccountOwnerError,
|
|
5376
|
-
|
|
5554
|
+
createAssociatedTokenAccountIdempotentInstruction,
|
|
5377
5555
|
createCloseAccountInstruction,
|
|
5378
5556
|
getAccount,
|
|
5379
5557
|
getAssociatedTokenAddressSync,
|
|
5380
5558
|
getMint
|
|
5381
5559
|
} from "@solana/spl-token";
|
|
5382
5560
|
import {
|
|
5383
|
-
ComputeBudgetProgram,
|
|
5561
|
+
ComputeBudgetProgram as ComputeBudgetProgram2,
|
|
5384
5562
|
SystemProgram,
|
|
5385
|
-
TransactionInstruction
|
|
5563
|
+
TransactionInstruction as TransactionInstruction2
|
|
5386
5564
|
} from "@solana/web3.js";
|
|
5387
5565
|
|
|
5388
5566
|
// src/dlmm/helpers/math.ts
|
|
@@ -6341,22 +6519,51 @@ function generateBinAmount(amount, binStep, binId, tokenXDecimal, tokenYDecimal,
|
|
|
6341
6519
|
return new BN5(c1.sub(c0).floor().toString());
|
|
6342
6520
|
}
|
|
6343
6521
|
|
|
6344
|
-
// src/dlmm/helpers/index.ts
|
|
6345
|
-
import { getSimulationComputeUnits } from "@solana-developers/helpers";
|
|
6346
|
-
|
|
6347
6522
|
// src/dlmm/helpers/computeUnit.ts
|
|
6523
|
+
import { ComputeBudgetProgram, PublicKey as PublicKey2, TransactionMessage, VersionedTransaction } from "@solana/web3.js";
|
|
6348
6524
|
var DEFAULT_ADD_LIQUIDITY_CU = 8e5;
|
|
6349
6525
|
var MIN_CU_BUFFER = 5e4;
|
|
6350
6526
|
var MAX_CU_BUFFER = 2e5;
|
|
6527
|
+
var getSimulationComputeUnits = async (connection, instructions, payer, lookupTables, commitment = "confirmed") => {
|
|
6528
|
+
const testInstructions = [
|
|
6529
|
+
// Set an arbitrarily high number in simulation
|
|
6530
|
+
// so we can be sure the transaction will succeed
|
|
6531
|
+
// and get the real compute units used
|
|
6532
|
+
ComputeBudgetProgram.setComputeUnitLimit({ units: 14e5 }),
|
|
6533
|
+
...instructions
|
|
6534
|
+
];
|
|
6535
|
+
const testTransaction = new VersionedTransaction(
|
|
6536
|
+
new TransactionMessage({
|
|
6537
|
+
instructions: testInstructions,
|
|
6538
|
+
payerKey: payer,
|
|
6539
|
+
// RecentBlockhash can by any public key during simulation
|
|
6540
|
+
// since 'replaceRecentBlockhash' is set to 'true' below
|
|
6541
|
+
recentBlockhash: PublicKey2.default.toString()
|
|
6542
|
+
}).compileToV0Message(lookupTables)
|
|
6543
|
+
);
|
|
6544
|
+
const rpcResponse = await connection.simulateTransaction(testTransaction, {
|
|
6545
|
+
replaceRecentBlockhash: true,
|
|
6546
|
+
sigVerify: false,
|
|
6547
|
+
commitment
|
|
6548
|
+
});
|
|
6549
|
+
if (rpcResponse?.value?.err) {
|
|
6550
|
+
const logs = rpcResponse.value.logs?.join("\n \u2022 ") || "No logs available";
|
|
6551
|
+
throw new Error(
|
|
6552
|
+
`Transaction simulation failed:
|
|
6553
|
+
\u2022${logs}` + JSON.stringify(rpcResponse?.value?.err)
|
|
6554
|
+
);
|
|
6555
|
+
}
|
|
6556
|
+
return rpcResponse.value.unitsConsumed || null;
|
|
6557
|
+
};
|
|
6351
6558
|
|
|
6352
6559
|
// src/dlmm/helpers/derive.ts
|
|
6353
|
-
import { PublicKey as
|
|
6560
|
+
import { PublicKey as PublicKey3 } from "@solana/web3.js";
|
|
6354
6561
|
function sortTokenMints(tokenX, tokenY) {
|
|
6355
6562
|
const [minKey, maxKey] = tokenX.toBuffer().compare(tokenY.toBuffer()) == 1 ? [tokenY, tokenX] : [tokenX, tokenY];
|
|
6356
6563
|
return [minKey, maxKey];
|
|
6357
6564
|
}
|
|
6358
6565
|
function derivePresetParameter(binStep, programId) {
|
|
6359
|
-
return
|
|
6566
|
+
return PublicKey3.findProgramAddressSync(
|
|
6360
6567
|
[
|
|
6361
6568
|
Buffer.from("preset_parameter"),
|
|
6362
6569
|
new Uint8Array(binStep.toArrayLike(Buffer, "le", 2))
|
|
@@ -6365,7 +6572,7 @@ function derivePresetParameter(binStep, programId) {
|
|
|
6365
6572
|
);
|
|
6366
6573
|
}
|
|
6367
6574
|
function derivePresetParameter2(binStep, baseFactor, programId) {
|
|
6368
|
-
return
|
|
6575
|
+
return PublicKey3.findProgramAddressSync(
|
|
6369
6576
|
[
|
|
6370
6577
|
Buffer.from("preset_parameter"),
|
|
6371
6578
|
new Uint8Array(binStep.toArrayLike(Buffer, "le", 2)),
|
|
@@ -6376,7 +6583,7 @@ function derivePresetParameter2(binStep, baseFactor, programId) {
|
|
|
6376
6583
|
}
|
|
6377
6584
|
function deriveLbPair2(tokenX, tokenY, binStep, baseFactor, programId) {
|
|
6378
6585
|
const [minKey, maxKey] = sortTokenMints(tokenX, tokenY);
|
|
6379
|
-
return
|
|
6586
|
+
return PublicKey3.findProgramAddressSync(
|
|
6380
6587
|
[
|
|
6381
6588
|
minKey.toBuffer(),
|
|
6382
6589
|
maxKey.toBuffer(),
|
|
@@ -6388,7 +6595,7 @@ function deriveLbPair2(tokenX, tokenY, binStep, baseFactor, programId) {
|
|
|
6388
6595
|
}
|
|
6389
6596
|
function deriveLbPair(tokenX, tokenY, binStep, programId) {
|
|
6390
6597
|
const [minKey, maxKey] = sortTokenMints(tokenX, tokenY);
|
|
6391
|
-
return
|
|
6598
|
+
return PublicKey3.findProgramAddressSync(
|
|
6392
6599
|
[
|
|
6393
6600
|
minKey.toBuffer(),
|
|
6394
6601
|
maxKey.toBuffer(),
|
|
@@ -6399,14 +6606,14 @@ function deriveLbPair(tokenX, tokenY, binStep, programId) {
|
|
|
6399
6606
|
}
|
|
6400
6607
|
function deriveCustomizablePermissionlessLbPair(tokenX, tokenY, programId) {
|
|
6401
6608
|
const [minKey, maxKey] = sortTokenMints(tokenX, tokenY);
|
|
6402
|
-
return
|
|
6609
|
+
return PublicKey3.findProgramAddressSync(
|
|
6403
6610
|
[ILM_BASE.toBuffer(), minKey.toBuffer(), maxKey.toBuffer()],
|
|
6404
6611
|
programId
|
|
6405
6612
|
);
|
|
6406
6613
|
}
|
|
6407
6614
|
function derivePermissionLbPair(baseKey, tokenX, tokenY, binStep, programId) {
|
|
6408
6615
|
const [minKey, maxKey] = sortTokenMints(tokenX, tokenY);
|
|
6409
|
-
return
|
|
6616
|
+
return PublicKey3.findProgramAddressSync(
|
|
6410
6617
|
[
|
|
6411
6618
|
baseKey.toBuffer(),
|
|
6412
6619
|
minKey.toBuffer(),
|
|
@@ -6417,7 +6624,7 @@ function derivePermissionLbPair(baseKey, tokenX, tokenY, binStep, programId) {
|
|
|
6417
6624
|
);
|
|
6418
6625
|
}
|
|
6419
6626
|
function deriveOracle(lbPair, programId) {
|
|
6420
|
-
return
|
|
6627
|
+
return PublicKey3.findProgramAddressSync(
|
|
6421
6628
|
[Buffer.from("oracle"), lbPair.toBytes()],
|
|
6422
6629
|
programId
|
|
6423
6630
|
);
|
|
@@ -6431,13 +6638,13 @@ function derivePosition(lbPair, base, lowerBinId, width, programId) {
|
|
|
6431
6638
|
} else {
|
|
6432
6639
|
lowerBinIdBytes = new Uint8Array(lowerBinId.toArrayLike(Buffer, "le", 4));
|
|
6433
6640
|
}
|
|
6434
|
-
return
|
|
6641
|
+
return PublicKey3.findProgramAddressSync(
|
|
6435
6642
|
[
|
|
6436
6643
|
Buffer.from("position"),
|
|
6437
6644
|
lbPair.toBuffer(),
|
|
6438
6645
|
base.toBuffer(),
|
|
6439
6646
|
lowerBinIdBytes,
|
|
6440
|
-
new Uint8Array(width.
|
|
6647
|
+
new Uint8Array(width.toArrayLike(Buffer, "le", 4))
|
|
6441
6648
|
],
|
|
6442
6649
|
programId
|
|
6443
6650
|
);
|
|
@@ -6451,13 +6658,13 @@ function deriveBinArray(lbPair, index, programId) {
|
|
|
6451
6658
|
} else {
|
|
6452
6659
|
binArrayBytes = new Uint8Array(index.toArrayLike(Buffer, "le", 8));
|
|
6453
6660
|
}
|
|
6454
|
-
return
|
|
6661
|
+
return PublicKey3.findProgramAddressSync(
|
|
6455
6662
|
[Buffer.from("bin_array"), lbPair.toBytes(), binArrayBytes],
|
|
6456
6663
|
programId
|
|
6457
6664
|
);
|
|
6458
6665
|
}
|
|
6459
6666
|
function deriveReserve(token, lbPair, programId) {
|
|
6460
|
-
return
|
|
6667
|
+
return PublicKey3.findProgramAddressSync(
|
|
6461
6668
|
[lbPair.toBuffer(), token.toBuffer()],
|
|
6462
6669
|
programId
|
|
6463
6670
|
);
|
|
@@ -6465,7 +6672,7 @@ function deriveReserve(token, lbPair, programId) {
|
|
|
6465
6672
|
|
|
6466
6673
|
// src/dlmm/helpers/binArray.ts
|
|
6467
6674
|
import { BN as BN7 } from "@coral-xyz/anchor";
|
|
6468
|
-
import { PublicKey as
|
|
6675
|
+
import { PublicKey as PublicKey4 } from "@solana/web3.js";
|
|
6469
6676
|
|
|
6470
6677
|
// src/dlmm/types/index.ts
|
|
6471
6678
|
import {
|
|
@@ -6484,9 +6691,6 @@ var PairType = /* @__PURE__ */ ((PairType2) => {
|
|
|
6484
6691
|
return PairType2;
|
|
6485
6692
|
})(PairType || {});
|
|
6486
6693
|
var Strategy = {
|
|
6487
|
-
SpotOneSide: { spotOneSide: {} },
|
|
6488
|
-
CurveOneSide: { curveOneSide: {} },
|
|
6489
|
-
BidAskOneSide: { bidAskOneSide: {} },
|
|
6490
6694
|
SpotBalanced: { spotBalanced: {} },
|
|
6491
6695
|
CurveBalanced: { curveBalanced: {} },
|
|
6492
6696
|
BidAskBalanced: { bidAskBalanced: {} },
|
|
@@ -6495,15 +6699,12 @@ var Strategy = {
|
|
|
6495
6699
|
BidAskImBalanced: { bidAskImBalanced: {} }
|
|
6496
6700
|
};
|
|
6497
6701
|
var StrategyType = /* @__PURE__ */ ((StrategyType2) => {
|
|
6498
|
-
StrategyType2[StrategyType2["
|
|
6499
|
-
StrategyType2[StrategyType2["
|
|
6500
|
-
StrategyType2[StrategyType2["
|
|
6501
|
-
StrategyType2[StrategyType2["
|
|
6502
|
-
StrategyType2[StrategyType2["
|
|
6503
|
-
StrategyType2[StrategyType2["
|
|
6504
|
-
StrategyType2[StrategyType2["SpotBalanced"] = 6] = "SpotBalanced";
|
|
6505
|
-
StrategyType2[StrategyType2["CurveBalanced"] = 7] = "CurveBalanced";
|
|
6506
|
-
StrategyType2[StrategyType2["BidAskBalanced"] = 8] = "BidAskBalanced";
|
|
6702
|
+
StrategyType2[StrategyType2["SpotImBalanced"] = 0] = "SpotImBalanced";
|
|
6703
|
+
StrategyType2[StrategyType2["CurveImBalanced"] = 1] = "CurveImBalanced";
|
|
6704
|
+
StrategyType2[StrategyType2["BidAskImBalanced"] = 2] = "BidAskImBalanced";
|
|
6705
|
+
StrategyType2[StrategyType2["SpotBalanced"] = 3] = "SpotBalanced";
|
|
6706
|
+
StrategyType2[StrategyType2["CurveBalanced"] = 4] = "CurveBalanced";
|
|
6707
|
+
StrategyType2[StrategyType2["BidAskBalanced"] = 5] = "BidAskBalanced";
|
|
6507
6708
|
return StrategyType2;
|
|
6508
6709
|
})(StrategyType || {});
|
|
6509
6710
|
var ActivationType = /* @__PURE__ */ ((ActivationType2) => {
|
|
@@ -6659,7 +6860,7 @@ function isOverflowDefaultBinArrayBitmap(binArrayIndex) {
|
|
|
6659
6860
|
return binArrayIndex.gt(maxBinArrayIndex) || binArrayIndex.lt(minBinArrayIndex);
|
|
6660
6861
|
}
|
|
6661
6862
|
function deriveBinArrayBitmapExtension(lbPair, programId) {
|
|
6662
|
-
return
|
|
6863
|
+
return PublicKey4.findProgramAddressSync(
|
|
6663
6864
|
[Buffer.from("bitmap"), lbPair.toBytes()],
|
|
6664
6865
|
programId
|
|
6665
6866
|
);
|
|
@@ -6808,7 +7009,7 @@ function getBinArraysRequiredByPositionRange(pair, fromBinId, toBinId, programId
|
|
|
6808
7009
|
binArrays.set(upperBinArray.toBase58(), upperBinArrayIndex);
|
|
6809
7010
|
}
|
|
6810
7011
|
return Array.from(binArrays, ([key, index]) => ({
|
|
6811
|
-
key: new
|
|
7012
|
+
key: new PublicKey4(key),
|
|
6812
7013
|
index
|
|
6813
7014
|
}));
|
|
6814
7015
|
}
|
|
@@ -7055,53 +7256,10 @@ function toWeightBidAsk(minBinId, maxBinId, activeId) {
|
|
|
7055
7256
|
}
|
|
7056
7257
|
return distributions;
|
|
7057
7258
|
}
|
|
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
|
-
}
|
|
7096
7259
|
function toAmountsBothSideByStrategy(activeId, binStep, minBinId, maxBinId, amountX, amountY, amountXInActiveBin, amountYInActiveBin, strategyType) {
|
|
7097
7260
|
const isSingleSideX = amountY.isZero();
|
|
7098
7261
|
switch (strategyType) {
|
|
7099
|
-
case 0 /*
|
|
7100
|
-
case 1 /* CurveOneSide */:
|
|
7101
|
-
case 2 /* BidAskOneSide */: {
|
|
7102
|
-
throw "Invalid Strategy Parameters";
|
|
7103
|
-
}
|
|
7104
|
-
case 3 /* SpotImBalanced */: {
|
|
7262
|
+
case 0 /* SpotImBalanced */: {
|
|
7105
7263
|
if (activeId < minBinId || activeId > maxBinId) {
|
|
7106
7264
|
const weights = toWeightSpotBalanced(minBinId, maxBinId);
|
|
7107
7265
|
return toAmountBothSide(
|
|
@@ -7173,7 +7331,7 @@ function toAmountsBothSideByStrategy(activeId, binStep, minBinId, maxBinId, amou
|
|
|
7173
7331
|
}
|
|
7174
7332
|
return amountsInBin;
|
|
7175
7333
|
}
|
|
7176
|
-
case
|
|
7334
|
+
case 1 /* CurveImBalanced */: {
|
|
7177
7335
|
if (activeId < minBinId) {
|
|
7178
7336
|
let weights = toWeightDecendingOrder(minBinId, maxBinId);
|
|
7179
7337
|
return toAmountBothSide(
|
|
@@ -7257,7 +7415,7 @@ function toAmountsBothSideByStrategy(activeId, binStep, minBinId, maxBinId, amou
|
|
|
7257
7415
|
}
|
|
7258
7416
|
return amountsInBin;
|
|
7259
7417
|
}
|
|
7260
|
-
case
|
|
7418
|
+
case 2 /* BidAskImBalanced */: {
|
|
7261
7419
|
if (activeId < minBinId) {
|
|
7262
7420
|
const weights = toWeightAscendingOrder(minBinId, maxBinId);
|
|
7263
7421
|
return toAmountBothSide(
|
|
@@ -7341,7 +7499,7 @@ function toAmountsBothSideByStrategy(activeId, binStep, minBinId, maxBinId, amou
|
|
|
7341
7499
|
}
|
|
7342
7500
|
return amountsInBin;
|
|
7343
7501
|
}
|
|
7344
|
-
case
|
|
7502
|
+
case 3 /* SpotBalanced */: {
|
|
7345
7503
|
let weights = toWeightSpotBalanced(minBinId, maxBinId);
|
|
7346
7504
|
return toAmountBothSide(
|
|
7347
7505
|
activeId,
|
|
@@ -7353,7 +7511,7 @@ function toAmountsBothSideByStrategy(activeId, binStep, minBinId, maxBinId, amou
|
|
|
7353
7511
|
weights
|
|
7354
7512
|
);
|
|
7355
7513
|
}
|
|
7356
|
-
case
|
|
7514
|
+
case 4 /* CurveBalanced */: {
|
|
7357
7515
|
let weights = toWeightCurve(minBinId, maxBinId, activeId);
|
|
7358
7516
|
return toAmountBothSide(
|
|
7359
7517
|
activeId,
|
|
@@ -7365,7 +7523,7 @@ function toAmountsBothSideByStrategy(activeId, binStep, minBinId, maxBinId, amou
|
|
|
7365
7523
|
weights
|
|
7366
7524
|
);
|
|
7367
7525
|
}
|
|
7368
|
-
case
|
|
7526
|
+
case 5 /* BidAskBalanced */: {
|
|
7369
7527
|
let weights = toWeightBidAsk(minBinId, maxBinId, activeId);
|
|
7370
7528
|
return toAmountBothSide(
|
|
7371
7529
|
activeId,
|
|
@@ -7381,15 +7539,12 @@ function toAmountsBothSideByStrategy(activeId, binStep, minBinId, maxBinId, amou
|
|
|
7381
7539
|
}
|
|
7382
7540
|
function autoFillYByStrategy(activeId, binStep, amountX, amountXInActiveBin, amountYInActiveBin, minBinId, maxBinId, strategyType) {
|
|
7383
7541
|
switch (strategyType) {
|
|
7384
|
-
case 0 /*
|
|
7385
|
-
case 1 /*
|
|
7386
|
-
case 2 /*
|
|
7387
|
-
case 3 /* SpotImBalanced */:
|
|
7388
|
-
case 4 /* CurveImBalanced */:
|
|
7389
|
-
case 5 /* BidAskImBalanced */: {
|
|
7542
|
+
case 0 /* SpotImBalanced */:
|
|
7543
|
+
case 1 /* CurveImBalanced */:
|
|
7544
|
+
case 2 /* BidAskImBalanced */: {
|
|
7390
7545
|
throw "Invalid Strategy Parameters";
|
|
7391
7546
|
}
|
|
7392
|
-
case
|
|
7547
|
+
case 3 /* SpotBalanced */: {
|
|
7393
7548
|
let weights = toWeightSpotBalanced(minBinId, maxBinId);
|
|
7394
7549
|
return autoFillYByWeight(
|
|
7395
7550
|
activeId,
|
|
@@ -7400,7 +7555,7 @@ function autoFillYByStrategy(activeId, binStep, amountX, amountXInActiveBin, amo
|
|
|
7400
7555
|
weights
|
|
7401
7556
|
);
|
|
7402
7557
|
}
|
|
7403
|
-
case
|
|
7558
|
+
case 4 /* CurveBalanced */: {
|
|
7404
7559
|
let weights = toWeightCurve(minBinId, maxBinId, activeId);
|
|
7405
7560
|
return autoFillYByWeight(
|
|
7406
7561
|
activeId,
|
|
@@ -7411,7 +7566,7 @@ function autoFillYByStrategy(activeId, binStep, amountX, amountXInActiveBin, amo
|
|
|
7411
7566
|
weights
|
|
7412
7567
|
);
|
|
7413
7568
|
}
|
|
7414
|
-
case
|
|
7569
|
+
case 5 /* BidAskBalanced */: {
|
|
7415
7570
|
let weights = toWeightBidAsk(minBinId, maxBinId, activeId);
|
|
7416
7571
|
return autoFillYByWeight(
|
|
7417
7572
|
activeId,
|
|
@@ -7426,15 +7581,12 @@ function autoFillYByStrategy(activeId, binStep, amountX, amountXInActiveBin, amo
|
|
|
7426
7581
|
}
|
|
7427
7582
|
function autoFillXByStrategy(activeId, binStep, amountY, amountXInActiveBin, amountYInActiveBin, minBinId, maxBinId, strategyType) {
|
|
7428
7583
|
switch (strategyType) {
|
|
7429
|
-
case 0 /*
|
|
7430
|
-
case 1 /*
|
|
7431
|
-
case 2 /*
|
|
7432
|
-
case 3 /* SpotImBalanced */:
|
|
7433
|
-
case 4 /* CurveImBalanced */:
|
|
7434
|
-
case 5 /* BidAskImBalanced */: {
|
|
7584
|
+
case 0 /* SpotImBalanced */:
|
|
7585
|
+
case 1 /* CurveImBalanced */:
|
|
7586
|
+
case 2 /* BidAskImBalanced */: {
|
|
7435
7587
|
throw "Invalid Strategy Parameters";
|
|
7436
7588
|
}
|
|
7437
|
-
case
|
|
7589
|
+
case 3 /* SpotBalanced */: {
|
|
7438
7590
|
let weights = toWeightSpotBalanced(minBinId, maxBinId);
|
|
7439
7591
|
return autoFillXByWeight(
|
|
7440
7592
|
activeId,
|
|
@@ -7445,7 +7597,7 @@ function autoFillXByStrategy(activeId, binStep, amountY, amountXInActiveBin, amo
|
|
|
7445
7597
|
weights
|
|
7446
7598
|
);
|
|
7447
7599
|
}
|
|
7448
|
-
case
|
|
7600
|
+
case 4 /* CurveBalanced */: {
|
|
7449
7601
|
let weights = toWeightCurve(minBinId, maxBinId, activeId);
|
|
7450
7602
|
return autoFillXByWeight(
|
|
7451
7603
|
activeId,
|
|
@@ -7456,7 +7608,7 @@ function autoFillXByStrategy(activeId, binStep, amountY, amountXInActiveBin, amo
|
|
|
7456
7608
|
weights
|
|
7457
7609
|
);
|
|
7458
7610
|
}
|
|
7459
|
-
case
|
|
7611
|
+
case 5 /* BidAskBalanced */: {
|
|
7460
7612
|
let weights = toWeightBidAsk(minBinId, maxBinId, activeId);
|
|
7461
7613
|
return autoFillXByWeight(
|
|
7462
7614
|
activeId,
|
|
@@ -7477,31 +7629,7 @@ function toStrategyParameters({
|
|
|
7477
7629
|
}) {
|
|
7478
7630
|
const parameters = [singleSidedX ? 1 : 0, ...new Array(63).fill(0)];
|
|
7479
7631
|
switch (strategyType) {
|
|
7480
|
-
case
|
|
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 */: {
|
|
7632
|
+
case 3 /* SpotBalanced */: {
|
|
7505
7633
|
return {
|
|
7506
7634
|
minBinId,
|
|
7507
7635
|
maxBinId,
|
|
@@ -7509,7 +7637,7 @@ function toStrategyParameters({
|
|
|
7509
7637
|
parameteres: Buffer.from(parameters).toJSON().data
|
|
7510
7638
|
};
|
|
7511
7639
|
}
|
|
7512
|
-
case
|
|
7640
|
+
case 4 /* CurveBalanced */: {
|
|
7513
7641
|
return {
|
|
7514
7642
|
minBinId,
|
|
7515
7643
|
maxBinId,
|
|
@@ -7517,7 +7645,7 @@ function toStrategyParameters({
|
|
|
7517
7645
|
parameteres: Buffer.from(parameters).toJSON().data
|
|
7518
7646
|
};
|
|
7519
7647
|
}
|
|
7520
|
-
case
|
|
7648
|
+
case 5 /* BidAskBalanced */: {
|
|
7521
7649
|
return {
|
|
7522
7650
|
minBinId,
|
|
7523
7651
|
maxBinId,
|
|
@@ -7525,7 +7653,7 @@ function toStrategyParameters({
|
|
|
7525
7653
|
parameteres: Buffer.from(parameters).toJSON().data
|
|
7526
7654
|
};
|
|
7527
7655
|
}
|
|
7528
|
-
case
|
|
7656
|
+
case 0 /* SpotImBalanced */: {
|
|
7529
7657
|
return {
|
|
7530
7658
|
minBinId,
|
|
7531
7659
|
maxBinId,
|
|
@@ -7533,7 +7661,7 @@ function toStrategyParameters({
|
|
|
7533
7661
|
parameteres: Buffer.from(parameters).toJSON().data
|
|
7534
7662
|
};
|
|
7535
7663
|
}
|
|
7536
|
-
case
|
|
7664
|
+
case 1 /* CurveImBalanced */: {
|
|
7537
7665
|
return {
|
|
7538
7666
|
minBinId,
|
|
7539
7667
|
maxBinId,
|
|
@@ -7541,7 +7669,7 @@ function toStrategyParameters({
|
|
|
7541
7669
|
parameteres: Buffer.from(parameters).toJSON().data
|
|
7542
7670
|
};
|
|
7543
7671
|
}
|
|
7544
|
-
case
|
|
7672
|
+
case 2 /* BidAskImBalanced */: {
|
|
7545
7673
|
return {
|
|
7546
7674
|
minBinId,
|
|
7547
7675
|
maxBinId,
|
|
@@ -7554,7 +7682,7 @@ function toStrategyParameters({
|
|
|
7554
7682
|
|
|
7555
7683
|
// src/dlmm/helpers/lbPair.ts
|
|
7556
7684
|
import { AnchorProvider, Program as Program2 } from "@coral-xyz/anchor";
|
|
7557
|
-
import { PublicKey as
|
|
7685
|
+
import { PublicKey as PublicKey5 } from "@solana/web3.js";
|
|
7558
7686
|
async function getTokensMintFromPoolAddress(connection, poolAddress, opt) {
|
|
7559
7687
|
const provider = new AnchorProvider(
|
|
7560
7688
|
connection,
|
|
@@ -7567,7 +7695,7 @@ async function getTokensMintFromPoolAddress(connection, poolAddress, opt) {
|
|
|
7567
7695
|
provider
|
|
7568
7696
|
);
|
|
7569
7697
|
const poolAccount = await program.account.lbPair.fetchNullable(
|
|
7570
|
-
new
|
|
7698
|
+
new PublicKey5(poolAddress)
|
|
7571
7699
|
);
|
|
7572
7700
|
if (!poolAccount)
|
|
7573
7701
|
throw new Error("Pool account not found");
|
|
@@ -7621,7 +7749,7 @@ var getOrCreateATAInstruction = async (connection, tokenMint, owner, payer = own
|
|
|
7621
7749
|
return { ataPubKey: toAccount, ix: void 0 };
|
|
7622
7750
|
} catch (e) {
|
|
7623
7751
|
if (e instanceof TokenAccountNotFoundError || e instanceof TokenInvalidAccountOwnerError) {
|
|
7624
|
-
const ix =
|
|
7752
|
+
const ix = createAssociatedTokenAccountIdempotentInstruction(
|
|
7625
7753
|
payer,
|
|
7626
7754
|
toAccount,
|
|
7627
7755
|
owner,
|
|
@@ -7653,7 +7781,7 @@ var wrapSOLInstruction = (from, to, amount) => {
|
|
|
7653
7781
|
toPubkey: to,
|
|
7654
7782
|
lamports: amount
|
|
7655
7783
|
}),
|
|
7656
|
-
new
|
|
7784
|
+
new TransactionInstruction2({
|
|
7657
7785
|
keys: [
|
|
7658
7786
|
{
|
|
7659
7787
|
pubkey: to,
|
|
@@ -7722,7 +7850,7 @@ var getEstimatedComputeUnitIxWithBuffer = async (connection, instructions, feePa
|
|
|
7722
7850
|
console.error("Error::getEstimatedComputeUnitUsageWithBuffer", error);
|
|
7723
7851
|
return 14e5;
|
|
7724
7852
|
});
|
|
7725
|
-
return
|
|
7853
|
+
return ComputeBudgetProgram2.setComputeUnitLimit({ units });
|
|
7726
7854
|
};
|
|
7727
7855
|
|
|
7728
7856
|
// src/dlmm/index.ts
|
|
@@ -8066,49 +8194,14 @@ var DLMM = class {
|
|
|
8066
8194
|
opt?.programId ?? LBCLMM_PROGRAM_IDS[cluster],
|
|
8067
8195
|
provider
|
|
8068
8196
|
);
|
|
8069
|
-
const
|
|
8070
|
-
|
|
8071
|
-
{
|
|
8072
|
-
|
|
8073
|
-
|
|
8074
|
-
offset: 8 + 32
|
|
8075
|
-
}
|
|
8076
|
-
}
|
|
8077
|
-
]),
|
|
8078
|
-
program.account.positionV2.all([
|
|
8079
|
-
{
|
|
8080
|
-
memcmp: {
|
|
8081
|
-
bytes: bs58.encode(userPubKey.toBuffer()),
|
|
8082
|
-
offset: 8 + 32
|
|
8083
|
-
}
|
|
8197
|
+
const positionsV2 = await program.account.positionV2.all([
|
|
8198
|
+
{
|
|
8199
|
+
memcmp: {
|
|
8200
|
+
bytes: bs58.encode(userPubKey.toBuffer()),
|
|
8201
|
+
offset: 8 + 32
|
|
8084
8202
|
}
|
|
8085
|
-
|
|
8203
|
+
}
|
|
8086
8204
|
]);
|
|
8087
|
-
const binArrayPubkeySet = /* @__PURE__ */ new Set();
|
|
8088
|
-
const lbPairSet = /* @__PURE__ */ new Set();
|
|
8089
|
-
positions.forEach(({ account: { upperBinId, lowerBinId, lbPair } }) => {
|
|
8090
|
-
const lowerBinArrayIndex = binIdToBinArrayIndex(new BN10(lowerBinId));
|
|
8091
|
-
const upperBinArrayIndex = binIdToBinArrayIndex(new BN10(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 PublicKey6(pubkey)
|
|
8108
|
-
);
|
|
8109
|
-
const lbPairArray = Array.from(lbPairSet).map(
|
|
8110
|
-
(pubkey) => new PublicKey6(pubkey)
|
|
8111
|
-
);
|
|
8112
8205
|
const binArrayPubkeySetV2 = /* @__PURE__ */ new Set();
|
|
8113
8206
|
const lbPairSetV2 = /* @__PURE__ */ new Set();
|
|
8114
8207
|
positionsV2.forEach(({ account: { upperBinId, lowerBinId, lbPair } }) => {
|
|
@@ -8129,77 +8222,41 @@ var DLMM = class {
|
|
|
8129
8222
|
lbPairSetV2.add(lbPair.toBase58());
|
|
8130
8223
|
});
|
|
8131
8224
|
const binArrayPubkeyArrayV2 = Array.from(binArrayPubkeySetV2).map(
|
|
8132
|
-
(pubkey) => new
|
|
8225
|
+
(pubkey) => new PublicKey7(pubkey)
|
|
8133
8226
|
);
|
|
8134
8227
|
const lbPairArrayV2 = Array.from(lbPairSetV2).map(
|
|
8135
|
-
(pubkey) => new
|
|
8228
|
+
(pubkey) => new PublicKey7(pubkey)
|
|
8136
8229
|
);
|
|
8137
8230
|
const [clockAccInfo, ...binArraysAccInfo] = await chunkedGetMultipleAccountInfos(connection, [
|
|
8138
8231
|
SYSVAR_CLOCK_PUBKEY,
|
|
8139
|
-
...binArrayPubkeyArray,
|
|
8140
|
-
...lbPairArray,
|
|
8141
8232
|
...binArrayPubkeyArrayV2,
|
|
8142
8233
|
...lbPairArrayV2
|
|
8143
8234
|
]);
|
|
8144
|
-
const
|
|
8145
|
-
for (let i = 0; i <
|
|
8146
|
-
const binArrayPubkey =
|
|
8147
|
-
const
|
|
8148
|
-
if (
|
|
8149
|
-
|
|
8150
|
-
|
|
8235
|
+
const positionBinArraysMapV2 = /* @__PURE__ */ new Map();
|
|
8236
|
+
for (let i = 0; i < binArrayPubkeyArrayV2.length; i++) {
|
|
8237
|
+
const binArrayPubkey = binArrayPubkeyArrayV2[i];
|
|
8238
|
+
const binArrayAccInfoBufferV2 = binArraysAccInfo[i];
|
|
8239
|
+
if (binArrayAccInfoBufferV2) {
|
|
8240
|
+
const binArrayAccInfo = program.coder.accounts.decode(
|
|
8241
|
+
"binArray",
|
|
8242
|
+
binArrayAccInfoBufferV2.data
|
|
8151
8243
|
);
|
|
8152
|
-
|
|
8153
|
-
|
|
8154
|
-
binArrayAccInfoBuffer.data
|
|
8155
|
-
);
|
|
8156
|
-
positionBinArraysMap.set(binArrayPubkey.toBase58(), binArrayAccInfo);
|
|
8244
|
+
positionBinArraysMapV2.set(binArrayPubkey.toBase58(), binArrayAccInfo);
|
|
8245
|
+
}
|
|
8157
8246
|
}
|
|
8158
|
-
const
|
|
8159
|
-
for (let i =
|
|
8160
|
-
const lbPairPubkey =
|
|
8161
|
-
const
|
|
8162
|
-
if (!
|
|
8247
|
+
const lbPairArraysMapV2 = /* @__PURE__ */ new Map();
|
|
8248
|
+
for (let i = binArrayPubkeyArrayV2.length; i < binArraysAccInfo.length; i++) {
|
|
8249
|
+
const lbPairPubkey = lbPairArrayV2[i - binArrayPubkeyArrayV2.length];
|
|
8250
|
+
const lbPairAccInfoBufferV2 = binArraysAccInfo[i];
|
|
8251
|
+
if (!lbPairAccInfoBufferV2)
|
|
8163
8252
|
throw new Error(`LB Pair account ${lbPairPubkey.toBase58()} not found`);
|
|
8164
8253
|
const lbPairAccInfo = program.coder.accounts.decode(
|
|
8165
8254
|
"lbPair",
|
|
8166
|
-
|
|
8255
|
+
lbPairAccInfoBufferV2.data
|
|
8167
8256
|
);
|
|
8168
|
-
|
|
8257
|
+
lbPairArraysMapV2.set(lbPairPubkey.toBase58(), lbPairAccInfo);
|
|
8169
8258
|
}
|
|
8170
|
-
const
|
|
8171
|
-
reserveX,
|
|
8172
|
-
reserveY,
|
|
8173
|
-
tokenXMint,
|
|
8174
|
-
tokenYMint
|
|
8175
|
-
]).flat();
|
|
8176
|
-
const positionBinArraysMapV2 = /* @__PURE__ */ new Map();
|
|
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)];
|
|
8179
|
-
const binArrayAccInfoBufferV2 = binArraysAccInfo[i];
|
|
8180
|
-
if (!binArrayAccInfoBufferV2)
|
|
8181
|
-
throw new Error(
|
|
8182
|
-
`Bin Array account ${binArrayPubkey.toBase58()} not found`
|
|
8183
|
-
);
|
|
8184
|
-
const binArrayAccInfo = program.coder.accounts.decode(
|
|
8185
|
-
"binArray",
|
|
8186
|
-
binArrayAccInfoBufferV2.data
|
|
8187
|
-
);
|
|
8188
|
-
positionBinArraysMapV2.set(binArrayPubkey.toBase58(), binArrayAccInfo);
|
|
8189
|
-
}
|
|
8190
|
-
const lbPairArraysMapV2 = /* @__PURE__ */ new Map();
|
|
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)];
|
|
8193
|
-
const lbPairAccInfoBufferV2 = binArraysAccInfo[i];
|
|
8194
|
-
if (!lbPairAccInfoBufferV2)
|
|
8195
|
-
throw new Error(`LB Pair account ${lbPairPubkey.toBase58()} not found`);
|
|
8196
|
-
const lbPairAccInfo = program.coder.accounts.decode(
|
|
8197
|
-
"lbPair",
|
|
8198
|
-
lbPairAccInfoBufferV2.data
|
|
8199
|
-
);
|
|
8200
|
-
lbPairArraysMapV2.set(lbPairPubkey.toBase58(), lbPairAccInfo);
|
|
8201
|
-
}
|
|
8202
|
-
const reservePublicKeysV2 = Array.from(lbPairArraysMapV2.values()).map(({ reserveX, reserveY, tokenXMint, tokenYMint }) => [
|
|
8259
|
+
const reservePublicKeysV2 = Array.from(lbPairArraysMapV2.values()).map(({ reserveX, reserveY, tokenXMint, tokenYMint }) => [
|
|
8203
8260
|
reserveX,
|
|
8204
8261
|
reserveY,
|
|
8205
8262
|
tokenXMint,
|
|
@@ -8207,43 +8264,14 @@ var DLMM = class {
|
|
|
8207
8264
|
]).flat();
|
|
8208
8265
|
const reserveAccountsInfo = await chunkedGetMultipleAccountInfos(
|
|
8209
8266
|
program.provider.connection,
|
|
8210
|
-
|
|
8267
|
+
reservePublicKeysV2
|
|
8211
8268
|
);
|
|
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 = AccountLayout.decode(reserveAccBufferX.data);
|
|
8223
|
-
const reserveAccY = 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 = MintLayout.decode(mintXBuffer.data);
|
|
8235
|
-
const mintY = MintLayout.decode(mintYBuffer.data);
|
|
8236
|
-
lbPairMintMap.set(lbPair.toBase58(), {
|
|
8237
|
-
mintXDecimal: mintX.decimals,
|
|
8238
|
-
mintYDecimal: mintY.decimals
|
|
8239
|
-
});
|
|
8240
|
-
});
|
|
8241
8269
|
const lbPairReserveMapV2 = /* @__PURE__ */ new Map();
|
|
8242
8270
|
const lbPairMintMapV2 = /* @__PURE__ */ new Map();
|
|
8243
8271
|
lbPairArrayV2.forEach((lbPair, idx) => {
|
|
8244
8272
|
const index = idx * 4;
|
|
8245
|
-
const reserveAccBufferXV2 = reserveAccountsInfo[
|
|
8246
|
-
const reserveAccBufferYV2 = reserveAccountsInfo[
|
|
8273
|
+
const reserveAccBufferXV2 = reserveAccountsInfo[index];
|
|
8274
|
+
const reserveAccBufferYV2 = reserveAccountsInfo[index + 1];
|
|
8247
8275
|
if (!reserveAccBufferXV2 || !reserveAccBufferYV2)
|
|
8248
8276
|
throw new Error(
|
|
8249
8277
|
`Reserve account for LB Pair ${lbPair.toBase58()} not found`
|
|
@@ -8254,8 +8282,8 @@ var DLMM = class {
|
|
|
8254
8282
|
reserveX: reserveAccX.amount,
|
|
8255
8283
|
reserveY: reserveAccY.amount
|
|
8256
8284
|
});
|
|
8257
|
-
const mintXBufferV2 = reserveAccountsInfo[
|
|
8258
|
-
const mintYBufferV2 = reserveAccountsInfo[
|
|
8285
|
+
const mintXBufferV2 = reserveAccountsInfo[index + 2];
|
|
8286
|
+
const mintYBufferV2 = reserveAccountsInfo[index + 3];
|
|
8259
8287
|
if (!mintXBufferV2 || !mintYBufferV2)
|
|
8260
8288
|
throw new Error(
|
|
8261
8289
|
`Mint account for LB Pair ${lbPair.toBase58()} not found`
|
|
@@ -8271,74 +8299,6 @@ var DLMM = class {
|
|
|
8271
8299
|
clockAccInfo.data.readBigInt64LE(32).toString()
|
|
8272
8300
|
).toNumber();
|
|
8273
8301
|
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 BN10(lowerBinId));
|
|
8278
|
-
const upperBinArrayIndex = binIdToBinArrayIndex(new BN10(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 = lbPairReserveMap.get(lbPair.toBase58())?.reserveX ?? BigInt(0);
|
|
8300
|
-
const reserveYBalance = lbPairReserveMap.get(lbPair.toBase58())?.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
|
-
PublicKey6.default
|
|
8324
|
-
);
|
|
8325
|
-
if (positionData) {
|
|
8326
|
-
positionsMap.set(lbPair.toBase58(), {
|
|
8327
|
-
publicKey: lbPair,
|
|
8328
|
-
lbPair: lbPairAcc,
|
|
8329
|
-
tokenX,
|
|
8330
|
-
tokenY,
|
|
8331
|
-
lbPairPositionsData: [
|
|
8332
|
-
...positionsMap.get(lbPair.toBase58())?.lbPairPositionsData ?? [],
|
|
8333
|
-
{
|
|
8334
|
-
publicKey: positionPubKey,
|
|
8335
|
-
positionData,
|
|
8336
|
-
version: 0 /* V1 */
|
|
8337
|
-
}
|
|
8338
|
-
]
|
|
8339
|
-
});
|
|
8340
|
-
}
|
|
8341
|
-
}
|
|
8342
8302
|
for (let position of positionsV2) {
|
|
8343
8303
|
const { account, publicKey: positionPubKey } = position;
|
|
8344
8304
|
const { upperBinId, lowerBinId, lbPair, feeOwner } = account;
|
|
@@ -8379,7 +8339,7 @@ var DLMM = class {
|
|
|
8379
8339
|
amount: reserveYBalance,
|
|
8380
8340
|
decimal: quoteTokenDecimal
|
|
8381
8341
|
};
|
|
8382
|
-
const positionData = await DLMM.processPosition(
|
|
8342
|
+
const positionData = !!lowerBinArray && !!upperBinArray ? await DLMM.processPosition(
|
|
8383
8343
|
program,
|
|
8384
8344
|
1 /* V2 */,
|
|
8385
8345
|
lbPairAcc,
|
|
@@ -8390,7 +8350,21 @@ var DLMM = class {
|
|
|
8390
8350
|
lowerBinArray,
|
|
8391
8351
|
upperBinArray,
|
|
8392
8352
|
feeOwner
|
|
8393
|
-
)
|
|
8353
|
+
) : {
|
|
8354
|
+
totalXAmount: "0",
|
|
8355
|
+
totalYAmount: "0",
|
|
8356
|
+
positionBinData: [],
|
|
8357
|
+
lastUpdatedAt: new BN10(0),
|
|
8358
|
+
upperBinId,
|
|
8359
|
+
lowerBinId,
|
|
8360
|
+
feeX: new BN10(0),
|
|
8361
|
+
feeY: new BN10(0),
|
|
8362
|
+
rewardOne: new BN10(0),
|
|
8363
|
+
rewardTwo: new BN10(0),
|
|
8364
|
+
feeOwner,
|
|
8365
|
+
totalClaimedFeeXAmount: new BN10(0),
|
|
8366
|
+
totalClaimedFeeYAmount: new BN10(0)
|
|
8367
|
+
};
|
|
8394
8368
|
if (positionData) {
|
|
8395
8369
|
positionsMap.set(lbPair.toBase58(), {
|
|
8396
8370
|
publicKey: lbPair,
|
|
@@ -8410,63 +8384,124 @@ var DLMM = class {
|
|
|
8410
8384
|
}
|
|
8411
8385
|
return positionsMap;
|
|
8412
8386
|
}
|
|
8413
|
-
static
|
|
8414
|
-
|
|
8415
|
-
|
|
8416
|
-
|
|
8417
|
-
|
|
8418
|
-
|
|
8419
|
-
);
|
|
8420
|
-
|
|
8421
|
-
|
|
8422
|
-
|
|
8423
|
-
|
|
8387
|
+
static getPricePerLamport(tokenXDecimal, tokenYDecimal, price) {
|
|
8388
|
+
return new Decimal5(price).mul(new Decimal5(10 ** (tokenYDecimal - tokenXDecimal))).toString();
|
|
8389
|
+
}
|
|
8390
|
+
static getBinIdFromPrice(price, binStep, min) {
|
|
8391
|
+
const binStepNum = new Decimal5(binStep).div(new Decimal5(BASIS_POINT_MAX));
|
|
8392
|
+
const binId = new Decimal5(price).log().dividedBy(new Decimal5(1).add(binStepNum).log());
|
|
8393
|
+
return (min ? binId.floor() : binId.ceil()).toNumber();
|
|
8394
|
+
}
|
|
8395
|
+
/**
|
|
8396
|
+
* The function `getLbPairLockInfo` retrieves all pair positions that has locked liquidity.
|
|
8397
|
+
* @param {number} [lockDurationOpt] - An optional value indicating the minimum position lock duration that the function should return.
|
|
8398
|
+
* Depending on the lbPair activationType, the param should be a number of seconds or a number of slots.
|
|
8399
|
+
* @returns The function `getLbPairLockInfo` returns a `Promise` that resolves to a `PairLockInfo`
|
|
8400
|
+
* object. The `PairLockInfo` object contains an array of `PositionLockInfo` objects.
|
|
8401
|
+
*/
|
|
8402
|
+
async getLbPairLockInfo(lockDurationOpt) {
|
|
8403
|
+
const lockDuration = lockDurationOpt | 0;
|
|
8404
|
+
const lbPairPositions = await this.program.account.positionV2.all([
|
|
8405
|
+
{
|
|
8406
|
+
memcmp: {
|
|
8407
|
+
bytes: bs58.encode(this.pubkey.toBuffer()),
|
|
8408
|
+
offset: 8
|
|
8409
|
+
}
|
|
8410
|
+
}
|
|
8411
|
+
]);
|
|
8412
|
+
const clockAccInfo = await this.program.provider.connection.getAccountInfo(SYSVAR_CLOCK_PUBKEY);
|
|
8413
|
+
const clock = ClockLayout.decode(clockAccInfo.data);
|
|
8414
|
+
const currentPoint = this.lbPair.activationType == 0 /* Slot */ ? clock.slot : clock.unixTimestamp;
|
|
8415
|
+
const minLockReleasePoint = currentPoint.add(new BN10(lockDuration));
|
|
8416
|
+
const positionsWithLock = lbPairPositions.filter((p) => p.account.lockReleasePoint.gt(minLockReleasePoint));
|
|
8417
|
+
if (positionsWithLock.length == 0) {
|
|
8418
|
+
return {
|
|
8419
|
+
positions: []
|
|
8420
|
+
};
|
|
8421
|
+
}
|
|
8422
|
+
const binArrayPubkeySetV2 = /* @__PURE__ */ new Set();
|
|
8423
|
+
positionsWithLock.forEach(({ account: { upperBinId, lowerBinId, lbPair } }) => {
|
|
8424
|
+
const lowerBinArrayIndex = binIdToBinArrayIndex(new BN10(lowerBinId));
|
|
8425
|
+
const upperBinArrayIndex = binIdToBinArrayIndex(new BN10(upperBinId));
|
|
8426
|
+
const [lowerBinArrayPubKey] = deriveBinArray(
|
|
8427
|
+
this.pubkey,
|
|
8428
|
+
lowerBinArrayIndex,
|
|
8429
|
+
this.program.programId
|
|
8430
|
+
);
|
|
8431
|
+
const [upperBinArrayPubKey] = deriveBinArray(
|
|
8432
|
+
this.pubkey,
|
|
8433
|
+
upperBinArrayIndex,
|
|
8434
|
+
this.program.programId
|
|
8435
|
+
);
|
|
8436
|
+
binArrayPubkeySetV2.add(lowerBinArrayPubKey.toBase58());
|
|
8437
|
+
binArrayPubkeySetV2.add(upperBinArrayPubKey.toBase58());
|
|
8438
|
+
});
|
|
8439
|
+
const binArrayPubkeyArrayV2 = Array.from(binArrayPubkeySetV2).map(
|
|
8440
|
+
(pubkey) => new PublicKey7(pubkey)
|
|
8424
8441
|
);
|
|
8425
|
-
const
|
|
8426
|
-
|
|
8442
|
+
const binArraysAccInfo = await chunkedGetMultipleAccountInfos(
|
|
8443
|
+
this.program.provider.connection,
|
|
8444
|
+
binArrayPubkeyArrayV2
|
|
8427
8445
|
);
|
|
8428
|
-
const
|
|
8429
|
-
|
|
8430
|
-
|
|
8431
|
-
|
|
8446
|
+
const positionBinArraysMapV2 = /* @__PURE__ */ new Map();
|
|
8447
|
+
for (let i = 0; i < binArraysAccInfo.length; i++) {
|
|
8448
|
+
const binArrayPubkey = binArrayPubkeyArrayV2[i];
|
|
8449
|
+
const binArrayAccBufferV2 = binArraysAccInfo[i];
|
|
8450
|
+
if (!binArrayAccBufferV2)
|
|
8451
|
+
throw new Error(
|
|
8452
|
+
`Bin Array account ${binArrayPubkey.toBase58()} not found`
|
|
8453
|
+
);
|
|
8454
|
+
const binArrayAccInfo = this.program.coder.accounts.decode(
|
|
8455
|
+
"binArray",
|
|
8456
|
+
binArrayAccBufferV2.data
|
|
8457
|
+
);
|
|
8458
|
+
positionBinArraysMapV2.set(binArrayPubkey.toBase58(), binArrayAccInfo);
|
|
8459
|
+
}
|
|
8460
|
+
const positionsLockInfo = await Promise.all(
|
|
8461
|
+
positionsWithLock.map(async ({ publicKey, account }) => {
|
|
8462
|
+
const { lowerBinId, upperBinId, feeOwner } = account;
|
|
8432
8463
|
const lowerBinArrayIndex = binIdToBinArrayIndex(new BN10(lowerBinId));
|
|
8433
|
-
const upperBinArrayIndex =
|
|
8464
|
+
const upperBinArrayIndex = binIdToBinArrayIndex(new BN10(upperBinId));
|
|
8434
8465
|
const [lowerBinArrayPubKey] = deriveBinArray(
|
|
8435
|
-
|
|
8466
|
+
this.pubkey,
|
|
8436
8467
|
lowerBinArrayIndex,
|
|
8437
|
-
program.programId
|
|
8468
|
+
this.program.programId
|
|
8438
8469
|
);
|
|
8439
8470
|
const [upperBinArrayPubKey] = deriveBinArray(
|
|
8440
|
-
|
|
8471
|
+
this.pubkey,
|
|
8441
8472
|
upperBinArrayIndex,
|
|
8442
|
-
program.programId
|
|
8473
|
+
this.program.programId
|
|
8443
8474
|
);
|
|
8444
|
-
const
|
|
8445
|
-
|
|
8446
|
-
|
|
8447
|
-
|
|
8448
|
-
|
|
8449
|
-
|
|
8450
|
-
|
|
8451
|
-
program
|
|
8452
|
-
|
|
8453
|
-
|
|
8454
|
-
|
|
8455
|
-
|
|
8456
|
-
|
|
8457
|
-
|
|
8458
|
-
|
|
8459
|
-
|
|
8475
|
+
const lowerBinArray = positionBinArraysMapV2.get(
|
|
8476
|
+
lowerBinArrayPubKey.toBase58()
|
|
8477
|
+
);
|
|
8478
|
+
const upperBinArray = positionBinArraysMapV2.get(
|
|
8479
|
+
upperBinArrayPubKey.toBase58()
|
|
8480
|
+
);
|
|
8481
|
+
const positionData = await DLMM.processPosition(
|
|
8482
|
+
this.program,
|
|
8483
|
+
1 /* V2 */,
|
|
8484
|
+
this.lbPair,
|
|
8485
|
+
clock.unixTimestamp.toNumber(),
|
|
8486
|
+
account,
|
|
8487
|
+
this.tokenX.decimal,
|
|
8488
|
+
this.tokenY.decimal,
|
|
8489
|
+
lowerBinArray,
|
|
8490
|
+
upperBinArray,
|
|
8491
|
+
feeOwner
|
|
8492
|
+
);
|
|
8493
|
+
return {
|
|
8494
|
+
positionAddress: publicKey,
|
|
8495
|
+
owner: account.owner,
|
|
8496
|
+
lockReleasePoint: account.lockReleasePoint.toNumber(),
|
|
8497
|
+
tokenXAmount: positionData.totalXAmount,
|
|
8498
|
+
tokenYAmount: positionData.totalYAmount
|
|
8499
|
+
};
|
|
8460
8500
|
})
|
|
8461
8501
|
);
|
|
8462
|
-
|
|
8463
|
-
|
|
8464
|
-
|
|
8465
|
-
}
|
|
8466
|
-
static getBinIdFromPrice(price, binStep, min) {
|
|
8467
|
-
const binStepNum = new Decimal5(binStep).div(new Decimal5(BASIS_POINT_MAX));
|
|
8468
|
-
const binId = new Decimal5(price).log().dividedBy(new Decimal5(1).add(binStepNum).log());
|
|
8469
|
-
return (min ? binId.floor() : binId.ceil()).toNumber();
|
|
8502
|
+
return {
|
|
8503
|
+
positions: positionsLockInfo
|
|
8504
|
+
};
|
|
8470
8505
|
}
|
|
8471
8506
|
/** Public methods */
|
|
8472
8507
|
static async createPermissionLbPair(connection, binStep, tokenX, tokenY, activeId, baseKey, creatorKey, feeBps, activationType, opt) {
|
|
@@ -8518,7 +8553,7 @@ var DLMM = class {
|
|
|
8518
8553
|
base: baseKey
|
|
8519
8554
|
}).transaction();
|
|
8520
8555
|
}
|
|
8521
|
-
static async createCustomizablePermissionlessLbPair(connection, binStep, tokenX, tokenY, activeId, feeBps, activationType, hasAlphaVault, creatorKey, activationPoint, opt) {
|
|
8556
|
+
static async createCustomizablePermissionlessLbPair(connection, binStep, tokenX, tokenY, activeId, feeBps, activationType, hasAlphaVault, creatorKey, activationPoint, creatorPoolOnOffControl, opt) {
|
|
8522
8557
|
const provider = new AnchorProvider2(
|
|
8523
8558
|
connection,
|
|
8524
8559
|
{},
|
|
@@ -8548,12 +8583,13 @@ var DLMM = class {
|
|
|
8548
8583
|
activationType,
|
|
8549
8584
|
activationPoint: activationPoint ? activationPoint : null,
|
|
8550
8585
|
hasAlphaVault,
|
|
8551
|
-
|
|
8586
|
+
creatorPoolOnOffControl: creatorPoolOnOffControl ? creatorPoolOnOffControl : false,
|
|
8587
|
+
padding: Array(63).fill(0)
|
|
8552
8588
|
};
|
|
8553
8589
|
const userTokenX = getAssociatedTokenAddressSync2(tokenX, creatorKey);
|
|
8590
|
+
const userTokenY = getAssociatedTokenAddressSync2(tokenY, creatorKey);
|
|
8554
8591
|
return program.methods.initializeCustomizablePermissionlessLbPair(ixData).accounts({
|
|
8555
8592
|
lbPair,
|
|
8556
|
-
rent: SYSVAR_RENT_PUBKEY,
|
|
8557
8593
|
reserveX,
|
|
8558
8594
|
reserveY,
|
|
8559
8595
|
binArrayBitmapExtension,
|
|
@@ -8563,6 +8599,7 @@ var DLMM = class {
|
|
|
8563
8599
|
oracle,
|
|
8564
8600
|
systemProgram: SystemProgram2.programId,
|
|
8565
8601
|
userTokenX,
|
|
8602
|
+
userTokenY,
|
|
8566
8603
|
funder: creatorKey
|
|
8567
8604
|
}).transaction();
|
|
8568
8605
|
}
|
|
@@ -8678,6 +8715,26 @@ var DLMM = class {
|
|
|
8678
8715
|
};
|
|
8679
8716
|
this.lbPair = lbPairState;
|
|
8680
8717
|
}
|
|
8718
|
+
/**
|
|
8719
|
+
* Set the status of a permissionless LB pair to either enabled or disabled. This require pool field `creator_pool_on_off_control` to be true and type `CustomizablePermissionless`.
|
|
8720
|
+
* Pool creator can enable/disable the pair anytime before the pool is opened / activated. Once the pool activation time is passed, the pool creator can only enable the pair.
|
|
8721
|
+
* Useful for token launches which do not have fixed activation time.
|
|
8722
|
+
* @param enable If true, the pair will be enabled. If false, the pair will be disabled.
|
|
8723
|
+
* @param creator The public key of the pool creator.
|
|
8724
|
+
* @returns a Promise that resolves to the transaction.
|
|
8725
|
+
*/
|
|
8726
|
+
async setPairStatusPermissionless(enable, creator) {
|
|
8727
|
+
const tx = await this.program.methods.setPairStatusPermissionless(Number(enable)).accounts({
|
|
8728
|
+
lbPair: this.pubkey,
|
|
8729
|
+
creator
|
|
8730
|
+
}).transaction();
|
|
8731
|
+
const { blockhash, lastValidBlockHeight } = await this.program.provider.connection.getLatestBlockhash("confirmed");
|
|
8732
|
+
return new Transaction({
|
|
8733
|
+
feePayer: this.lbPair.creator,
|
|
8734
|
+
blockhash,
|
|
8735
|
+
lastValidBlockHeight
|
|
8736
|
+
}).add(tx);
|
|
8737
|
+
}
|
|
8681
8738
|
/**
|
|
8682
8739
|
* The function `getBinArrays` returns an array of `BinArrayAccount` objects
|
|
8683
8740
|
* @returns a Promise that resolves to an array of BinArrayAccount objects.
|
|
@@ -8728,7 +8785,7 @@ var DLMM = class {
|
|
|
8728
8785
|
shouldStop = true;
|
|
8729
8786
|
}
|
|
8730
8787
|
const accountsToFetch = Array.from(binArraysPubkey).map(
|
|
8731
|
-
(pubkey) => new
|
|
8788
|
+
(pubkey) => new PublicKey7(pubkey)
|
|
8732
8789
|
);
|
|
8733
8790
|
const binArraysAccInfoBuffer = await chunkedGetMultipleAccountInfos(
|
|
8734
8791
|
this.program.provider.connection,
|
|
@@ -8951,20 +9008,6 @@ var DLMM = class {
|
|
|
8951
9008
|
async getPositionsByUserAndLbPair(userPubKey) {
|
|
8952
9009
|
const promiseResults = await Promise.all([
|
|
8953
9010
|
this.getActiveBin(),
|
|
8954
|
-
userPubKey && this.program.account.position.all([
|
|
8955
|
-
{
|
|
8956
|
-
memcmp: {
|
|
8957
|
-
bytes: bs58.encode(userPubKey.toBuffer()),
|
|
8958
|
-
offset: 8 + 32
|
|
8959
|
-
}
|
|
8960
|
-
},
|
|
8961
|
-
{
|
|
8962
|
-
memcmp: {
|
|
8963
|
-
bytes: bs58.encode(this.pubkey.toBuffer()),
|
|
8964
|
-
offset: 8
|
|
8965
|
-
}
|
|
8966
|
-
}
|
|
8967
|
-
]),
|
|
8968
9011
|
userPubKey && this.program.account.positionV2.all([
|
|
8969
9012
|
{
|
|
8970
9013
|
memcmp: {
|
|
@@ -8980,7 +9023,7 @@ var DLMM = class {
|
|
|
8980
9023
|
}
|
|
8981
9024
|
])
|
|
8982
9025
|
]);
|
|
8983
|
-
const [activeBin,
|
|
9026
|
+
const [activeBin, positionsV2] = promiseResults;
|
|
8984
9027
|
if (!activeBin) {
|
|
8985
9028
|
throw new Error("Error fetching active bin");
|
|
8986
9029
|
}
|
|
@@ -8990,29 +9033,9 @@ var DLMM = class {
|
|
|
8990
9033
|
userPositions: []
|
|
8991
9034
|
};
|
|
8992
9035
|
}
|
|
8993
|
-
if (!
|
|
9036
|
+
if (!positionsV2) {
|
|
8994
9037
|
throw new Error("Error fetching positions");
|
|
8995
9038
|
}
|
|
8996
|
-
const binArrayPubkeySet = /* @__PURE__ */ new Set();
|
|
8997
|
-
positions.forEach(({ account: { upperBinId, lowerBinId } }) => {
|
|
8998
|
-
const lowerBinArrayIndex = binIdToBinArrayIndex(new BN10(lowerBinId));
|
|
8999
|
-
const upperBinArrayIndex = binIdToBinArrayIndex(new BN10(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 PublicKey6(pubkey)
|
|
9015
|
-
);
|
|
9016
9039
|
const binArrayPubkeySetV2 = /* @__PURE__ */ new Set();
|
|
9017
9040
|
positionsV2.forEach(({ account: { upperBinId, lowerBinId, lbPair } }) => {
|
|
9018
9041
|
const lowerBinArrayIndex = binIdToBinArrayIndex(new BN10(lowerBinId));
|
|
@@ -9031,35 +9054,20 @@ var DLMM = class {
|
|
|
9031
9054
|
binArrayPubkeySetV2.add(upperBinArrayPubKey.toBase58());
|
|
9032
9055
|
});
|
|
9033
9056
|
const binArrayPubkeyArrayV2 = Array.from(binArrayPubkeySetV2).map(
|
|
9034
|
-
(pubkey) => new
|
|
9057
|
+
(pubkey) => new PublicKey7(pubkey)
|
|
9035
9058
|
);
|
|
9036
9059
|
const lbPairAndBinArrays = await chunkedGetMultipleAccountInfos(
|
|
9037
9060
|
this.program.provider.connection,
|
|
9038
9061
|
[
|
|
9039
9062
|
this.pubkey,
|
|
9040
9063
|
SYSVAR_CLOCK_PUBKEY,
|
|
9041
|
-
...binArrayPubkeyArray,
|
|
9042
9064
|
...binArrayPubkeyArrayV2
|
|
9043
9065
|
]
|
|
9044
9066
|
);
|
|
9045
9067
|
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
|
-
}
|
|
9060
9068
|
const positionBinArraysMapV2 = /* @__PURE__ */ new Map();
|
|
9061
|
-
for (let i =
|
|
9062
|
-
const binArrayPubkey = binArrayPubkeyArrayV2[i
|
|
9069
|
+
for (let i = 0; i < binArraysAccInfo.length; i++) {
|
|
9070
|
+
const binArrayPubkey = binArrayPubkeyArrayV2[i];
|
|
9063
9071
|
const binArrayAccBufferV2 = binArraysAccInfo[i];
|
|
9064
9072
|
if (!binArrayAccBufferV2)
|
|
9065
9073
|
throw new Error(
|
|
@@ -9076,45 +9084,6 @@ var DLMM = class {
|
|
|
9076
9084
|
const onChainTimestamp = new BN10(
|
|
9077
9085
|
clockAccInfo.data.readBigInt64LE(32).toString()
|
|
9078
9086
|
).toNumber();
|
|
9079
|
-
const userPositions = await Promise.all(
|
|
9080
|
-
positions.map(async ({ publicKey, account }) => {
|
|
9081
|
-
const { lowerBinId, upperBinId } = account;
|
|
9082
|
-
const lowerBinArrayIndex = binIdToBinArrayIndex(new BN10(lowerBinId));
|
|
9083
|
-
const upperBinArrayIndex = binIdToBinArrayIndex(new BN10(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
|
-
PublicKey6.default
|
|
9113
|
-
),
|
|
9114
|
-
version: 0 /* V1 */
|
|
9115
|
-
};
|
|
9116
|
-
})
|
|
9117
|
-
);
|
|
9118
9087
|
const userPositionsV2 = await Promise.all(
|
|
9119
9088
|
positionsV2.map(async ({ publicKey, account }) => {
|
|
9120
9089
|
const { lowerBinId, upperBinId, feeOwner } = account;
|
|
@@ -9156,7 +9125,7 @@ var DLMM = class {
|
|
|
9156
9125
|
);
|
|
9157
9126
|
return {
|
|
9158
9127
|
activeBin,
|
|
9159
|
-
userPositions:
|
|
9128
|
+
userPositions: userPositionsV2
|
|
9160
9129
|
};
|
|
9161
9130
|
}
|
|
9162
9131
|
async quoteCreatePosition({ strategy }) {
|
|
@@ -9217,6 +9186,93 @@ var DLMM = class {
|
|
|
9217
9186
|
feePayer: user
|
|
9218
9187
|
}).add(setCUIx, ...instructions);
|
|
9219
9188
|
}
|
|
9189
|
+
/**
|
|
9190
|
+
* The function `getPosition` retrieves position information for a given public key and processes it
|
|
9191
|
+
* using various data to return a `LbPosition` object.
|
|
9192
|
+
* @param {PublicKey} positionPubKey - The `getPosition` function you provided is an asynchronous
|
|
9193
|
+
* function that fetches position information based on a given public key. Here's a breakdown of the
|
|
9194
|
+
* parameters used in the function:
|
|
9195
|
+
* @returns The `getPosition` function returns a Promise that resolves to an object of type
|
|
9196
|
+
* `LbPosition`. The object contains the following properties:
|
|
9197
|
+
* - `publicKey`: The public key of the position account
|
|
9198
|
+
* - `positionData`: Position Object
|
|
9199
|
+
* - `version`: The version of the position (in this case, `Position.V2`)
|
|
9200
|
+
*/
|
|
9201
|
+
async getPosition(positionPubKey) {
|
|
9202
|
+
const positionAccountInfo = await this.program.account.positionV2.fetch(positionPubKey);
|
|
9203
|
+
if (!positionAccountInfo) {
|
|
9204
|
+
throw new Error(`Position account ${positionPubKey.toBase58()} not found`);
|
|
9205
|
+
}
|
|
9206
|
+
const { lowerBinId, upperBinId, feeOwner } = positionAccountInfo;
|
|
9207
|
+
const lowerBinArrayIndex = binIdToBinArrayIndex(new BN10(lowerBinId));
|
|
9208
|
+
const upperBinArrayIndex = binIdToBinArrayIndex(new BN10(upperBinId));
|
|
9209
|
+
const [lowerBinArrayPubKey] = deriveBinArray(
|
|
9210
|
+
this.pubkey,
|
|
9211
|
+
lowerBinArrayIndex,
|
|
9212
|
+
this.program.programId
|
|
9213
|
+
);
|
|
9214
|
+
const [upperBinArrayPubKey] = deriveBinArray(
|
|
9215
|
+
this.pubkey,
|
|
9216
|
+
upperBinArrayIndex,
|
|
9217
|
+
this.program.programId
|
|
9218
|
+
);
|
|
9219
|
+
const [clockAccInfo, lowerBinArrayAccInfo, upperBinArrayAccInfo] = await chunkedGetMultipleAccountInfos(
|
|
9220
|
+
this.program.provider.connection,
|
|
9221
|
+
[
|
|
9222
|
+
SYSVAR_CLOCK_PUBKEY,
|
|
9223
|
+
lowerBinArrayPubKey,
|
|
9224
|
+
upperBinArrayPubKey
|
|
9225
|
+
]
|
|
9226
|
+
);
|
|
9227
|
+
if (!lowerBinArrayAccInfo || !upperBinArrayAccInfo) {
|
|
9228
|
+
return {
|
|
9229
|
+
publicKey: positionPubKey,
|
|
9230
|
+
positionData: {
|
|
9231
|
+
totalXAmount: "0",
|
|
9232
|
+
totalYAmount: "0",
|
|
9233
|
+
positionBinData: [],
|
|
9234
|
+
lastUpdatedAt: new BN10(0),
|
|
9235
|
+
upperBinId,
|
|
9236
|
+
lowerBinId,
|
|
9237
|
+
feeX: new BN10(0),
|
|
9238
|
+
feeY: new BN10(0),
|
|
9239
|
+
rewardOne: new BN10(0),
|
|
9240
|
+
rewardTwo: new BN10(0),
|
|
9241
|
+
feeOwner,
|
|
9242
|
+
totalClaimedFeeXAmount: new BN10(0),
|
|
9243
|
+
totalClaimedFeeYAmount: new BN10(0)
|
|
9244
|
+
},
|
|
9245
|
+
version: 1 /* V2 */
|
|
9246
|
+
};
|
|
9247
|
+
}
|
|
9248
|
+
const onChainTimestamp = new BN10(
|
|
9249
|
+
clockAccInfo.data.readBigInt64LE(32).toString()
|
|
9250
|
+
).toNumber();
|
|
9251
|
+
const lowerBinArray = this.program.coder.accounts.decode(
|
|
9252
|
+
"binArray",
|
|
9253
|
+
lowerBinArrayAccInfo.data
|
|
9254
|
+
);
|
|
9255
|
+
const upperBinArray = this.program.coder.accounts.decode(
|
|
9256
|
+
"binArray",
|
|
9257
|
+
upperBinArrayAccInfo.data
|
|
9258
|
+
);
|
|
9259
|
+
return {
|
|
9260
|
+
publicKey: positionPubKey,
|
|
9261
|
+
positionData: await DLMM.processPosition(
|
|
9262
|
+
this.program,
|
|
9263
|
+
1 /* V2 */,
|
|
9264
|
+
this.lbPair,
|
|
9265
|
+
onChainTimestamp,
|
|
9266
|
+
positionAccountInfo,
|
|
9267
|
+
this.tokenX.decimal,
|
|
9268
|
+
this.tokenY.decimal,
|
|
9269
|
+
lowerBinArray,
|
|
9270
|
+
upperBinArray,
|
|
9271
|
+
feeOwner
|
|
9272
|
+
),
|
|
9273
|
+
version: 1 /* V2 */
|
|
9274
|
+
};
|
|
9275
|
+
}
|
|
9220
9276
|
/**
|
|
9221
9277
|
* The function `initializePositionAndAddLiquidityByStrategy` function is used to initializes a position and adds liquidity
|
|
9222
9278
|
* @param {TInitializePositionAndAddLiquidityParamsByStrategy}
|
|
@@ -9940,9 +9996,13 @@ var DLMM = class {
|
|
|
9940
9996
|
bps,
|
|
9941
9997
|
shouldClaimAndClose = false
|
|
9942
9998
|
}) {
|
|
9943
|
-
const
|
|
9944
|
-
const
|
|
9945
|
-
const
|
|
9999
|
+
const lowerBinIdToRemove = Math.min(...binIds);
|
|
10000
|
+
const upperBinIdToRemove = Math.max(...binIds);
|
|
10001
|
+
const { lbPair, owner, feeOwner, lowerBinId: positionLowerBinId, liquidityShares } = await this.program.account.positionV2.fetch(position);
|
|
10002
|
+
if (liquidityShares.every((share) => share.isZero())) {
|
|
10003
|
+
throw new Error("No liquidity to remove");
|
|
10004
|
+
}
|
|
10005
|
+
const lowerBinArrayIndex = binIdToBinArrayIndex(new BN10(positionLowerBinId));
|
|
9946
10006
|
const upperBinArrayIndex = lowerBinArrayIndex.add(new BN10(1));
|
|
9947
10007
|
const [binArrayLower] = deriveBinArray(
|
|
9948
10008
|
lbPair,
|
|
@@ -9955,7 +10015,7 @@ var DLMM = class {
|
|
|
9955
10015
|
this.program.programId
|
|
9956
10016
|
);
|
|
9957
10017
|
const preInstructions = [];
|
|
9958
|
-
const walletToReceiveFee = feeOwner.equals(
|
|
10018
|
+
const walletToReceiveFee = feeOwner.equals(PublicKey7.default) ? user : feeOwner;
|
|
9959
10019
|
const [
|
|
9960
10020
|
{ ataPubKey: userTokenX, ix: createPayerTokenXIx },
|
|
9961
10021
|
{ ataPubKey: userTokenY, ix: createPayerTokenYIx },
|
|
@@ -10002,8 +10062,8 @@ var DLMM = class {
|
|
|
10002
10062
|
lbPair: this.pubkey,
|
|
10003
10063
|
sender: user,
|
|
10004
10064
|
position,
|
|
10005
|
-
reserveX,
|
|
10006
|
-
reserveY,
|
|
10065
|
+
reserveX: this.lbPair.reserveX,
|
|
10066
|
+
reserveY: this.lbPair.reserveY,
|
|
10007
10067
|
tokenProgram: TOKEN_PROGRAM_ID2,
|
|
10008
10068
|
tokenXMint: this.tokenX.publicKey,
|
|
10009
10069
|
tokenYMint: this.tokenY.publicKey,
|
|
@@ -10013,7 +10073,7 @@ var DLMM = class {
|
|
|
10013
10073
|
postInstructions.push(claimSwapFeeIx);
|
|
10014
10074
|
for (let i = 0; i < 2; i++) {
|
|
10015
10075
|
const rewardInfo = this.lbPair.rewardInfos[i];
|
|
10016
|
-
if (!rewardInfo || rewardInfo.mint.equals(
|
|
10076
|
+
if (!rewardInfo || rewardInfo.mint.equals(PublicKey7.default))
|
|
10017
10077
|
continue;
|
|
10018
10078
|
const { ataPubKey, ix: rewardAtaIx } = await getOrCreateATAInstruction(
|
|
10019
10079
|
this.program.provider.connection,
|
|
@@ -10056,21 +10116,19 @@ var DLMM = class {
|
|
|
10056
10116
|
const closeWrappedSOLIx = await unwrapSOLInstruction(user);
|
|
10057
10117
|
closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
|
|
10058
10118
|
}
|
|
10059
|
-
const
|
|
10060
|
-
const
|
|
10061
|
-
const minBinArrayIndex = binIdToBinArrayIndex(new BN10(minBinId));
|
|
10062
|
-
const maxBinArrayIndex = binIdToBinArrayIndex(new BN10(maxBinId));
|
|
10119
|
+
const minBinArrayIndex = binIdToBinArrayIndex(new BN10(lowerBinIdToRemove));
|
|
10120
|
+
const maxBinArrayIndex = binIdToBinArrayIndex(new BN10(upperBinIdToRemove));
|
|
10063
10121
|
const useExtension = isOverflowDefaultBinArrayBitmap(minBinArrayIndex) || isOverflowDefaultBinArrayBitmap(maxBinArrayIndex);
|
|
10064
10122
|
const binArrayBitmapExtension = useExtension ? deriveBinArrayBitmapExtension(this.pubkey, this.program.programId)[0] : null;
|
|
10065
|
-
const
|
|
10123
|
+
const removeLiquidityTx = await this.program.methods.removeLiquidityByRange(lowerBinIdToRemove, upperBinIdToRemove, bps.toNumber()).accounts({
|
|
10066
10124
|
position,
|
|
10067
10125
|
lbPair,
|
|
10068
10126
|
userTokenX,
|
|
10069
10127
|
userTokenY,
|
|
10070
|
-
reserveX,
|
|
10071
|
-
reserveY,
|
|
10072
|
-
tokenXMint,
|
|
10073
|
-
tokenYMint,
|
|
10128
|
+
reserveX: this.lbPair.reserveX,
|
|
10129
|
+
reserveY: this.lbPair.reserveY,
|
|
10130
|
+
tokenXMint: this.tokenX.publicKey,
|
|
10131
|
+
tokenYMint: this.tokenY.publicKey,
|
|
10074
10132
|
binArrayLower,
|
|
10075
10133
|
binArrayUpper,
|
|
10076
10134
|
binArrayBitmapExtension,
|
|
@@ -10080,7 +10138,7 @@ var DLMM = class {
|
|
|
10080
10138
|
}).instruction();
|
|
10081
10139
|
const instructions = [
|
|
10082
10140
|
...preInstructions,
|
|
10083
|
-
|
|
10141
|
+
removeLiquidityTx,
|
|
10084
10142
|
...postInstructions
|
|
10085
10143
|
];
|
|
10086
10144
|
const setCUIx = await getEstimatedComputeUnitIxWithBuffer(
|
|
@@ -10163,6 +10221,7 @@ var DLMM = class {
|
|
|
10163
10221
|
* - `outAmount`: Amount of lamport to swap out
|
|
10164
10222
|
* - `swapForY`: Swap token X to Y when it is true, else reversed.
|
|
10165
10223
|
* - `allowedSlippage`: Allowed slippage for the swap. Expressed in BPS. To convert from slippage percentage to BPS unit: SLIPPAGE_PERCENTAGE * 100
|
|
10224
|
+
* - `maxExtraBinArrays`: Maximum number of extra binArrays to return
|
|
10166
10225
|
* @returns {SwapQuote}
|
|
10167
10226
|
* - `inAmount`: Amount of lamport to swap in
|
|
10168
10227
|
* - `outAmount`: Amount of lamport to swap out
|
|
@@ -10173,9 +10232,12 @@ var DLMM = class {
|
|
|
10173
10232
|
* @throws {DlmmSdkError}
|
|
10174
10233
|
*
|
|
10175
10234
|
*/
|
|
10176
|
-
swapQuoteExactOut(outAmount, swapForY, allowedSlippage, binArrays) {
|
|
10235
|
+
swapQuoteExactOut(outAmount, swapForY, allowedSlippage, binArrays, maxExtraBinArrays = 0) {
|
|
10177
10236
|
const currentTimestamp = Date.now() / 1e3;
|
|
10178
10237
|
let outAmountLeft = outAmount;
|
|
10238
|
+
if (maxExtraBinArrays < 0 || maxExtraBinArrays > MAX_EXTRA_BIN_ARRAYS) {
|
|
10239
|
+
throw new DlmmSdkError("INVALID_MAX_EXTRA_BIN_ARRAYS", `maxExtraBinArrays must be a value between 0 and ${MAX_EXTRA_BIN_ARRAYS}`);
|
|
10240
|
+
}
|
|
10179
10241
|
let vParameterClone = Object.assign({}, this.lbPair.vParameters);
|
|
10180
10242
|
let activeId = new BN10(this.lbPair.activeId);
|
|
10181
10243
|
const binStep = this.lbPair.binStep;
|
|
@@ -10249,6 +10311,41 @@ var DLMM = class {
|
|
|
10249
10311
|
);
|
|
10250
10312
|
const priceImpact = startPrice.sub(endPrice).abs().div(startPrice).mul(new Decimal5(100));
|
|
10251
10313
|
const maxInAmount = actualInAmount.mul(new BN10(BASIS_POINT_MAX).add(allowedSlippage)).div(new BN10(BASIS_POINT_MAX));
|
|
10314
|
+
if (maxExtraBinArrays > 0 && maxExtraBinArrays <= MAX_EXTRA_BIN_ARRAYS) {
|
|
10315
|
+
const extraBinArrays = new Array();
|
|
10316
|
+
while (extraBinArrays.length < maxExtraBinArrays) {
|
|
10317
|
+
let binArrayAccountToSwap = findNextBinArrayWithLiquidity(
|
|
10318
|
+
swapForY,
|
|
10319
|
+
activeId,
|
|
10320
|
+
this.lbPair,
|
|
10321
|
+
this.binArrayBitmapExtension?.account ?? null,
|
|
10322
|
+
binArrays
|
|
10323
|
+
);
|
|
10324
|
+
if (binArrayAccountToSwap == null) {
|
|
10325
|
+
break;
|
|
10326
|
+
}
|
|
10327
|
+
const binArrayAccountToSwapExisted = binArraysForSwap.has(binArrayAccountToSwap.publicKey);
|
|
10328
|
+
if (binArrayAccountToSwapExisted) {
|
|
10329
|
+
if (swapForY) {
|
|
10330
|
+
activeId = activeId.sub(new BN10(1));
|
|
10331
|
+
} else {
|
|
10332
|
+
activeId = activeId.add(new BN10(1));
|
|
10333
|
+
}
|
|
10334
|
+
} else {
|
|
10335
|
+
extraBinArrays.push(binArrayAccountToSwap.publicKey);
|
|
10336
|
+
const [lowerBinId, upperBinId] = getBinArrayLowerUpperBinId(binArrayAccountToSwap.account.index);
|
|
10337
|
+
if (swapForY) {
|
|
10338
|
+
activeId = lowerBinId.sub(new BN10(1));
|
|
10339
|
+
} else {
|
|
10340
|
+
activeId = upperBinId.add(new BN10(1));
|
|
10341
|
+
}
|
|
10342
|
+
}
|
|
10343
|
+
}
|
|
10344
|
+
extraBinArrays.forEach((binArrayPubkey) => {
|
|
10345
|
+
binArraysForSwap.set(binArrayPubkey, true);
|
|
10346
|
+
});
|
|
10347
|
+
}
|
|
10348
|
+
const binArraysPubkey = Array.from(binArraysForSwap.keys());
|
|
10252
10349
|
return {
|
|
10253
10350
|
inAmount: actualInAmount,
|
|
10254
10351
|
maxInAmount,
|
|
@@ -10256,7 +10353,7 @@ var DLMM = class {
|
|
|
10256
10353
|
priceImpact,
|
|
10257
10354
|
fee: feeAmount,
|
|
10258
10355
|
protocolFee: protocolFeeAmount,
|
|
10259
|
-
binArraysPubkey
|
|
10356
|
+
binArraysPubkey
|
|
10260
10357
|
};
|
|
10261
10358
|
}
|
|
10262
10359
|
/**
|
|
@@ -10267,6 +10364,7 @@ var DLMM = class {
|
|
|
10267
10364
|
* - `allowedSlippage`: Allowed slippage for the swap. Expressed in BPS. To convert from slippage percentage to BPS unit: SLIPPAGE_PERCENTAGE * 100
|
|
10268
10365
|
* - `binArrays`: binArrays for swapQuote.
|
|
10269
10366
|
* - `isPartialFill`: Flag to check whether the the swapQuote is partial fill, default = false.
|
|
10367
|
+
* - `maxExtraBinArrays`: Maximum number of extra binArrays to return
|
|
10270
10368
|
* @returns {SwapQuote}
|
|
10271
10369
|
* - `consumedInAmount`: Amount of lamport to swap in
|
|
10272
10370
|
* - `outAmount`: Amount of lamport to swap out
|
|
@@ -10277,9 +10375,12 @@ var DLMM = class {
|
|
|
10277
10375
|
* - `binArraysPubkey`: Array of bin arrays involved in the swap
|
|
10278
10376
|
* @throws {DlmmSdkError}
|
|
10279
10377
|
*/
|
|
10280
|
-
swapQuote(inAmount, swapForY, allowedSlippage, binArrays, isPartialFill) {
|
|
10378
|
+
swapQuote(inAmount, swapForY, allowedSlippage, binArrays, isPartialFill, maxExtraBinArrays = 0) {
|
|
10281
10379
|
const currentTimestamp = Date.now() / 1e3;
|
|
10282
10380
|
let inAmountLeft = inAmount;
|
|
10381
|
+
if (maxExtraBinArrays < 0 || maxExtraBinArrays > MAX_EXTRA_BIN_ARRAYS) {
|
|
10382
|
+
throw new DlmmSdkError("INVALID_MAX_EXTRA_BIN_ARRAYS", `maxExtraBinArrays must be a value between 0 and ${MAX_EXTRA_BIN_ARRAYS}`);
|
|
10383
|
+
}
|
|
10283
10384
|
let vParameterClone = Object.assign({}, this.lbPair.vParameters);
|
|
10284
10385
|
let activeId = new BN10(this.lbPair.activeId);
|
|
10285
10386
|
const binStep = this.lbPair.binStep;
|
|
@@ -10295,6 +10396,7 @@ var DLMM = class {
|
|
|
10295
10396
|
let actualOutAmount = new BN10(0);
|
|
10296
10397
|
let feeAmount = new BN10(0);
|
|
10297
10398
|
let protocolFeeAmount = new BN10(0);
|
|
10399
|
+
let lastFilledActiveBinId = activeId;
|
|
10298
10400
|
while (!inAmountLeft.isZero()) {
|
|
10299
10401
|
let binArrayAccountToSwap = findNextBinArrayWithLiquidity(
|
|
10300
10402
|
swapForY,
|
|
@@ -10340,6 +10442,7 @@ var DLMM = class {
|
|
|
10340
10442
|
if (!startBin) {
|
|
10341
10443
|
startBin = bin;
|
|
10342
10444
|
}
|
|
10445
|
+
lastFilledActiveBinId = activeId;
|
|
10343
10446
|
}
|
|
10344
10447
|
}
|
|
10345
10448
|
if (!inAmountLeft.isZero()) {
|
|
@@ -10367,9 +10470,44 @@ var DLMM = class {
|
|
|
10367
10470
|
const priceImpact = new Decimal5(actualOutAmount.toString()).sub(new Decimal5(outAmountWithoutSlippage.toString())).div(new Decimal5(outAmountWithoutSlippage.toString())).mul(new Decimal5(100));
|
|
10368
10471
|
const minOutAmount = actualOutAmount.mul(new BN10(BASIS_POINT_MAX).sub(allowedSlippage)).div(new BN10(BASIS_POINT_MAX));
|
|
10369
10472
|
const endPrice = getPriceOfBinByBinId(
|
|
10370
|
-
|
|
10473
|
+
lastFilledActiveBinId.toNumber(),
|
|
10371
10474
|
this.lbPair.binStep
|
|
10372
10475
|
);
|
|
10476
|
+
if (maxExtraBinArrays > 0 && maxExtraBinArrays <= MAX_EXTRA_BIN_ARRAYS) {
|
|
10477
|
+
const extraBinArrays = new Array();
|
|
10478
|
+
while (extraBinArrays.length < maxExtraBinArrays) {
|
|
10479
|
+
let binArrayAccountToSwap = findNextBinArrayWithLiquidity(
|
|
10480
|
+
swapForY,
|
|
10481
|
+
activeId,
|
|
10482
|
+
this.lbPair,
|
|
10483
|
+
this.binArrayBitmapExtension?.account ?? null,
|
|
10484
|
+
binArrays
|
|
10485
|
+
);
|
|
10486
|
+
if (binArrayAccountToSwap == null) {
|
|
10487
|
+
break;
|
|
10488
|
+
}
|
|
10489
|
+
const binArrayAccountToSwapExisted = binArraysForSwap.has(binArrayAccountToSwap.publicKey);
|
|
10490
|
+
if (binArrayAccountToSwapExisted) {
|
|
10491
|
+
if (swapForY) {
|
|
10492
|
+
activeId = activeId.sub(new BN10(1));
|
|
10493
|
+
} else {
|
|
10494
|
+
activeId = activeId.add(new BN10(1));
|
|
10495
|
+
}
|
|
10496
|
+
} else {
|
|
10497
|
+
extraBinArrays.push(binArrayAccountToSwap.publicKey);
|
|
10498
|
+
const [lowerBinId, upperBinId] = getBinArrayLowerUpperBinId(binArrayAccountToSwap.account.index);
|
|
10499
|
+
if (swapForY) {
|
|
10500
|
+
activeId = lowerBinId.sub(new BN10(1));
|
|
10501
|
+
} else {
|
|
10502
|
+
activeId = upperBinId.add(new BN10(1));
|
|
10503
|
+
}
|
|
10504
|
+
}
|
|
10505
|
+
}
|
|
10506
|
+
extraBinArrays.forEach((binArrayPubkey) => {
|
|
10507
|
+
binArraysForSwap.set(binArrayPubkey, true);
|
|
10508
|
+
});
|
|
10509
|
+
}
|
|
10510
|
+
const binArraysPubkey = Array.from(binArraysForSwap.keys());
|
|
10373
10511
|
return {
|
|
10374
10512
|
consumedInAmount: inAmount,
|
|
10375
10513
|
outAmount: actualOutAmount,
|
|
@@ -10377,7 +10515,7 @@ var DLMM = class {
|
|
|
10377
10515
|
protocolFee: protocolFeeAmount,
|
|
10378
10516
|
minOutAmount,
|
|
10379
10517
|
priceImpact,
|
|
10380
|
-
binArraysPubkey
|
|
10518
|
+
binArraysPubkey,
|
|
10381
10519
|
endPrice
|
|
10382
10520
|
};
|
|
10383
10521
|
}
|
|
@@ -10484,7 +10622,6 @@ var DLMM = class {
|
|
|
10484
10622
|
priceImpact,
|
|
10485
10623
|
binArraysPubkey
|
|
10486
10624
|
}) {
|
|
10487
|
-
const { tokenXMint, tokenYMint, reserveX, reserveY, activeId, oracle } = await this.program.account.lbPair.fetch(lbPair);
|
|
10488
10625
|
const preInstructions = [];
|
|
10489
10626
|
const postInstructions = [];
|
|
10490
10627
|
const [
|
|
@@ -10518,9 +10655,6 @@ var DLMM = class {
|
|
|
10518
10655
|
const closeWrappedSOLIx = await unwrapSOLInstruction(user);
|
|
10519
10656
|
closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
|
|
10520
10657
|
}
|
|
10521
|
-
let swapForY = true;
|
|
10522
|
-
if (outToken.equals(tokenXMint))
|
|
10523
|
-
swapForY = false;
|
|
10524
10658
|
const binArrays = binArraysPubkey.map((pubkey) => {
|
|
10525
10659
|
return {
|
|
10526
10660
|
isSigner: false,
|
|
@@ -10534,17 +10668,17 @@ var DLMM = class {
|
|
|
10534
10668
|
priceImpact.toNumber()
|
|
10535
10669
|
).accounts({
|
|
10536
10670
|
lbPair,
|
|
10537
|
-
reserveX,
|
|
10538
|
-
reserveY,
|
|
10539
|
-
tokenXMint,
|
|
10540
|
-
tokenYMint,
|
|
10671
|
+
reserveX: this.lbPair.reserveX,
|
|
10672
|
+
reserveY: this.lbPair.reserveY,
|
|
10673
|
+
tokenXMint: this.lbPair.tokenXMint,
|
|
10674
|
+
tokenYMint: this.lbPair.tokenYMint,
|
|
10541
10675
|
tokenXProgram: TOKEN_PROGRAM_ID2,
|
|
10542
10676
|
tokenYProgram: TOKEN_PROGRAM_ID2,
|
|
10543
10677
|
user,
|
|
10544
10678
|
userTokenIn,
|
|
10545
10679
|
userTokenOut,
|
|
10546
10680
|
binArrayBitmapExtension: this.binArrayBitmapExtension ? this.binArrayBitmapExtension.publicKey : null,
|
|
10547
|
-
oracle,
|
|
10681
|
+
oracle: this.lbPair.oracle,
|
|
10548
10682
|
hostFeeIn: null
|
|
10549
10683
|
}).remainingAccounts(binArrays).instruction();
|
|
10550
10684
|
const instructions = [...preInstructions, swapIx, ...postInstructions];
|
|
@@ -10582,7 +10716,6 @@ var DLMM = class {
|
|
|
10582
10716
|
user,
|
|
10583
10717
|
binArraysPubkey
|
|
10584
10718
|
}) {
|
|
10585
|
-
const { tokenXMint, tokenYMint, reserveX, reserveY, activeId, oracle } = await this.program.account.lbPair.fetch(lbPair);
|
|
10586
10719
|
const preInstructions = [];
|
|
10587
10720
|
const postInstructions = [];
|
|
10588
10721
|
const [
|
|
@@ -10616,9 +10749,6 @@ var DLMM = class {
|
|
|
10616
10749
|
const closeWrappedSOLIx = await unwrapSOLInstruction(user);
|
|
10617
10750
|
closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
|
|
10618
10751
|
}
|
|
10619
|
-
let swapForY = true;
|
|
10620
|
-
if (outToken.equals(tokenXMint))
|
|
10621
|
-
swapForY = false;
|
|
10622
10752
|
const binArrays = binArraysPubkey.map((pubkey) => {
|
|
10623
10753
|
return {
|
|
10624
10754
|
isSigner: false,
|
|
@@ -10628,10 +10758,10 @@ var DLMM = class {
|
|
|
10628
10758
|
});
|
|
10629
10759
|
const swapIx = await this.program.methods.swap(inAmount, minOutAmount).accounts({
|
|
10630
10760
|
lbPair,
|
|
10631
|
-
reserveX,
|
|
10632
|
-
reserveY,
|
|
10633
|
-
tokenXMint,
|
|
10634
|
-
tokenYMint,
|
|
10761
|
+
reserveX: this.lbPair.reserveX,
|
|
10762
|
+
reserveY: this.lbPair.reserveY,
|
|
10763
|
+
tokenXMint: this.lbPair.tokenXMint,
|
|
10764
|
+
tokenYMint: this.lbPair.tokenYMint,
|
|
10635
10765
|
tokenXProgram: TOKEN_PROGRAM_ID2,
|
|
10636
10766
|
// dont use 2022 first; lack familiarity
|
|
10637
10767
|
tokenYProgram: TOKEN_PROGRAM_ID2,
|
|
@@ -10640,7 +10770,7 @@ var DLMM = class {
|
|
|
10640
10770
|
userTokenIn,
|
|
10641
10771
|
userTokenOut,
|
|
10642
10772
|
binArrayBitmapExtension: this.binArrayBitmapExtension ? this.binArrayBitmapExtension.publicKey : null,
|
|
10643
|
-
oracle,
|
|
10773
|
+
oracle: this.lbPair.oracle,
|
|
10644
10774
|
hostFeeIn: null
|
|
10645
10775
|
}).remainingAccounts(binArrays).instruction();
|
|
10646
10776
|
const instructions = [...preInstructions, swapIx, ...postInstructions];
|
|
@@ -10742,6 +10872,21 @@ var DLMM = class {
|
|
|
10742
10872
|
lastValidBlockHeight
|
|
10743
10873
|
}).add(setActivationPointTx);
|
|
10744
10874
|
}
|
|
10875
|
+
async setPairStatus(enabled) {
|
|
10876
|
+
const pairStatus = enabled ? 0 : 1;
|
|
10877
|
+
const tx = await this.program.methods.setPairStatus(pairStatus).accounts(
|
|
10878
|
+
{
|
|
10879
|
+
lbPair: this.pubkey,
|
|
10880
|
+
admin: this.lbPair.creator
|
|
10881
|
+
}
|
|
10882
|
+
).transaction();
|
|
10883
|
+
const { blockhash, lastValidBlockHeight } = await this.program.provider.connection.getLatestBlockhash("confirmed");
|
|
10884
|
+
return new Transaction({
|
|
10885
|
+
feePayer: this.lbPair.creator,
|
|
10886
|
+
blockhash,
|
|
10887
|
+
lastValidBlockHeight
|
|
10888
|
+
}).add(tx);
|
|
10889
|
+
}
|
|
10745
10890
|
/**
|
|
10746
10891
|
* The function `claimSwapFee` is used to claim swap fees for a specific position owned by a specific owner.
|
|
10747
10892
|
* @param
|
|
@@ -10821,11 +10966,11 @@ var DLMM = class {
|
|
|
10821
10966
|
const tokensInvolved = [...pairTokens];
|
|
10822
10967
|
for (let i = 0; i < 2; i++) {
|
|
10823
10968
|
const rewardMint = this.lbPair.rewardInfos[i].mint;
|
|
10824
|
-
if (!tokensInvolved.some((pubkey) => rewardMint.equals(pubkey)) && !rewardMint.equals(
|
|
10969
|
+
if (!tokensInvolved.some((pubkey) => rewardMint.equals(pubkey)) && !rewardMint.equals(PublicKey7.default)) {
|
|
10825
10970
|
tokensInvolved.push(this.lbPair.rewardInfos[i].mint);
|
|
10826
10971
|
}
|
|
10827
10972
|
}
|
|
10828
|
-
const feeOwner = position.positionData.feeOwner.equals(
|
|
10973
|
+
const feeOwner = position.positionData.feeOwner.equals(PublicKey7.default) ? owner : position.positionData.feeOwner;
|
|
10829
10974
|
const createATAAccAndIx = await Promise.all(
|
|
10830
10975
|
tokensInvolved.map((token) => {
|
|
10831
10976
|
if (pairTokens.some((t) => t.equals(token))) {
|
|
@@ -10900,9 +11045,14 @@ var DLMM = class {
|
|
|
10900
11045
|
* - `minPrice`: Start price in UI format
|
|
10901
11046
|
* - `maxPrice`: End price in UI format
|
|
10902
11047
|
* - `base`: Base key
|
|
11048
|
+
* - `txPayer`: Account rental fee payer
|
|
11049
|
+
* - `feeOwner`: Fee owner key. Default to position owner
|
|
11050
|
+
* - `operator`: Operator key
|
|
11051
|
+
* - `lockReleasePoint`: Timelock. Point (slot/timestamp) the position can withdraw the liquidity,
|
|
11052
|
+
* - `shouldSeedPositionOwner` (optional): Whether to send 1 lamport amount of token X to the position owner to prove ownership.
|
|
10903
11053
|
* @returns {Promise<SeedLiquidityResponse>}
|
|
10904
11054
|
*/
|
|
10905
|
-
async seedLiquidity(owner, seedAmount, curvature, minPrice, maxPrice, base) {
|
|
11055
|
+
async seedLiquidity(owner, seedAmount, curvature, minPrice, maxPrice, base, payer, feeOwner, operator, lockReleasePoint, shouldSeedPositionOwner = false) {
|
|
10906
11056
|
const toLamportMultiplier = new Decimal5(
|
|
10907
11057
|
10 ** (this.tokenY.decimal - this.tokenX.decimal)
|
|
10908
11058
|
);
|
|
@@ -10947,13 +11097,56 @@ var DLMM = class {
|
|
|
10947
11097
|
);
|
|
10948
11098
|
const positionCount = getPositionCount(minBinId, maxBinId.sub(new BN10(1)));
|
|
10949
11099
|
const seederTokenX = getAssociatedTokenAddressSync2(
|
|
11100
|
+
this.lbPair.tokenXMint,
|
|
11101
|
+
operator,
|
|
11102
|
+
false
|
|
11103
|
+
);
|
|
11104
|
+
const seederTokenY = getAssociatedTokenAddressSync2(
|
|
11105
|
+
this.lbPair.tokenYMint,
|
|
11106
|
+
operator,
|
|
11107
|
+
false
|
|
11108
|
+
);
|
|
11109
|
+
const ownerTokenX = getAssociatedTokenAddressSync2(
|
|
10950
11110
|
this.lbPair.tokenXMint,
|
|
10951
11111
|
owner,
|
|
10952
11112
|
false
|
|
10953
11113
|
);
|
|
11114
|
+
const sendPositionOwnerTokenProveIxs = [];
|
|
10954
11115
|
const initializeBinArraysAndPositionIxs = [];
|
|
10955
11116
|
const addLiquidityIxs = [];
|
|
10956
11117
|
const appendedInitBinArrayIx = /* @__PURE__ */ new Set();
|
|
11118
|
+
if (shouldSeedPositionOwner) {
|
|
11119
|
+
const positionOwnerTokenX = await this.program.provider.connection.getAccountInfo(ownerTokenX);
|
|
11120
|
+
let requireTokenProve = false;
|
|
11121
|
+
if (positionOwnerTokenX) {
|
|
11122
|
+
const ownerTokenXState = unpackAccount(
|
|
11123
|
+
ownerTokenX,
|
|
11124
|
+
positionOwnerTokenX,
|
|
11125
|
+
TOKEN_PROGRAM_ID2
|
|
11126
|
+
);
|
|
11127
|
+
requireTokenProve = ownerTokenXState.amount == 0n;
|
|
11128
|
+
} else {
|
|
11129
|
+
requireTokenProve = true;
|
|
11130
|
+
}
|
|
11131
|
+
if (requireTokenProve) {
|
|
11132
|
+
const initPositionOwnerTokenX = createAssociatedTokenAccountIdempotentInstruction2(
|
|
11133
|
+
payer,
|
|
11134
|
+
ownerTokenX,
|
|
11135
|
+
owner,
|
|
11136
|
+
this.lbPair.tokenXMint,
|
|
11137
|
+
TOKEN_PROGRAM_ID2
|
|
11138
|
+
);
|
|
11139
|
+
sendPositionOwnerTokenProveIxs.push(initPositionOwnerTokenX);
|
|
11140
|
+
sendPositionOwnerTokenProveIxs.push(
|
|
11141
|
+
createTransferInstruction(
|
|
11142
|
+
seederTokenX,
|
|
11143
|
+
ownerTokenX,
|
|
11144
|
+
operator,
|
|
11145
|
+
1n
|
|
11146
|
+
)
|
|
11147
|
+
);
|
|
11148
|
+
}
|
|
11149
|
+
}
|
|
10957
11150
|
for (let i = 0; i < positionCount.toNumber(); i++) {
|
|
10958
11151
|
const lowerBinId = minBinId.add(MAX_BIN_PER_POSITION.mul(new BN10(i)));
|
|
10959
11152
|
const upperBinId = lowerBinId.add(MAX_BIN_PER_POSITION).sub(new BN10(1));
|
|
@@ -10988,7 +11181,7 @@ var DLMM = class {
|
|
|
10988
11181
|
await this.program.methods.initializeBinArray(lowerBinArrayIndex).accounts({
|
|
10989
11182
|
lbPair: this.pubkey,
|
|
10990
11183
|
binArray: lowerBinArray,
|
|
10991
|
-
funder:
|
|
11184
|
+
funder: payer
|
|
10992
11185
|
}).instruction()
|
|
10993
11186
|
);
|
|
10994
11187
|
appendedInitBinArrayIx.add(lowerBinArray.toBase58());
|
|
@@ -10999,7 +11192,7 @@ var DLMM = class {
|
|
|
10999
11192
|
await this.program.methods.initializeBinArray(upperBinArrayIndex).accounts({
|
|
11000
11193
|
lbPair: this.pubkey,
|
|
11001
11194
|
binArray: upperBinArray,
|
|
11002
|
-
funder:
|
|
11195
|
+
funder: payer
|
|
11003
11196
|
}).instruction()
|
|
11004
11197
|
);
|
|
11005
11198
|
appendedInitBinArrayIx.add(upperBinArray.toBase58());
|
|
@@ -11007,26 +11200,25 @@ var DLMM = class {
|
|
|
11007
11200
|
const positionAccount = accounts[2];
|
|
11008
11201
|
if (!positionAccount) {
|
|
11009
11202
|
instructions.push(
|
|
11010
|
-
await this.program.methods.
|
|
11203
|
+
await this.program.methods.initializePositionByOperator(
|
|
11011
11204
|
lowerBinId.toNumber(),
|
|
11012
|
-
MAX_BIN_PER_POSITION.toNumber()
|
|
11205
|
+
MAX_BIN_PER_POSITION.toNumber(),
|
|
11206
|
+
feeOwner,
|
|
11207
|
+
lockReleasePoint
|
|
11013
11208
|
).accounts({
|
|
11014
11209
|
lbPair: this.pubkey,
|
|
11015
11210
|
position: positionPda,
|
|
11016
11211
|
base,
|
|
11017
11212
|
owner,
|
|
11018
|
-
payer
|
|
11213
|
+
payer,
|
|
11214
|
+
operator,
|
|
11215
|
+
operatorTokenX: seederTokenX,
|
|
11216
|
+
ownerTokenX,
|
|
11217
|
+
systemProgram: SystemProgram2.programId
|
|
11019
11218
|
}).instruction()
|
|
11020
11219
|
);
|
|
11021
11220
|
}
|
|
11022
11221
|
if (instructions.length > 1) {
|
|
11023
|
-
instructions.push(
|
|
11024
|
-
await getEstimatedComputeUnitIxWithBuffer(
|
|
11025
|
-
this.program.provider.connection,
|
|
11026
|
-
instructions,
|
|
11027
|
-
owner
|
|
11028
|
-
)
|
|
11029
|
-
);
|
|
11030
11222
|
initializeBinArraysAndPositionIxs.push(instructions);
|
|
11031
11223
|
instructions = [];
|
|
11032
11224
|
}
|
|
@@ -11056,7 +11248,7 @@ var DLMM = class {
|
|
|
11056
11248
|
tokenMint: this.lbPair.tokenXMint,
|
|
11057
11249
|
binArrayLower: lowerBinArray,
|
|
11058
11250
|
binArrayUpper: upperBinArray,
|
|
11059
|
-
sender:
|
|
11251
|
+
sender: operator
|
|
11060
11252
|
}).instruction()
|
|
11061
11253
|
);
|
|
11062
11254
|
if (i + 1 >= positionCount.toNumber() && !finalLoss.isZero()) {
|
|
@@ -11080,19 +11272,21 @@ var DLMM = class {
|
|
|
11080
11272
|
tokenMint: this.lbPair.tokenXMint,
|
|
11081
11273
|
binArrayLower: lowerBinArray,
|
|
11082
11274
|
binArrayUpper: upperBinArray,
|
|
11083
|
-
sender:
|
|
11275
|
+
sender: operator
|
|
11084
11276
|
}).instruction()
|
|
11085
11277
|
);
|
|
11086
11278
|
}
|
|
11087
11279
|
addLiquidityIxs.push([
|
|
11088
|
-
|
|
11280
|
+
ComputeBudgetProgram3.setComputeUnitLimit({
|
|
11089
11281
|
units: DEFAULT_ADD_LIQUIDITY_CU
|
|
11090
11282
|
}),
|
|
11091
11283
|
...instructions
|
|
11092
11284
|
]);
|
|
11093
11285
|
}
|
|
11094
11286
|
}
|
|
11287
|
+
console.log("let return");
|
|
11095
11288
|
return {
|
|
11289
|
+
sendPositionOwnerTokenProveIxs,
|
|
11096
11290
|
initializeBinArraysAndPositionIxs,
|
|
11097
11291
|
addLiquidityIxs
|
|
11098
11292
|
};
|
|
@@ -11372,7 +11566,7 @@ var DLMM = class {
|
|
|
11372
11566
|
const tokensInvolved = [...pairsToken];
|
|
11373
11567
|
for (let i = 0; i < 2; i++) {
|
|
11374
11568
|
const rewardMint = this.lbPair.rewardInfos[i].mint;
|
|
11375
|
-
if (!tokensInvolved.some((pubkey) => rewardMint.equals(pubkey)) && !rewardMint.equals(
|
|
11569
|
+
if (!tokensInvolved.some((pubkey) => rewardMint.equals(pubkey)) && !rewardMint.equals(PublicKey7.default)) {
|
|
11376
11570
|
tokensInvolved.push(this.lbPair.rewardInfos[i].mint);
|
|
11377
11571
|
}
|
|
11378
11572
|
}
|
|
@@ -11382,9 +11576,9 @@ var DLMM = class {
|
|
|
11382
11576
|
const feeOwners = [
|
|
11383
11577
|
.../* @__PURE__ */ new Set([
|
|
11384
11578
|
owner.toBase58(),
|
|
11385
|
-
...positions.filter((p) => !p.positionData.feeOwner.equals(
|
|
11579
|
+
...positions.filter((p) => !p.positionData.feeOwner.equals(PublicKey7.default)).map((p) => p.positionData.feeOwner.toBase58())
|
|
11386
11580
|
])
|
|
11387
|
-
].map((pk) => new
|
|
11581
|
+
].map((pk) => new PublicKey7(pk));
|
|
11388
11582
|
const createATAAccAndIx = await Promise.all(
|
|
11389
11583
|
tokensInvolved.map((token) => {
|
|
11390
11584
|
if (pairsToken.some((p) => p.equals(token))) {
|
|
@@ -11718,7 +11912,7 @@ var DLMM = class {
|
|
|
11718
11912
|
const preActivationSwapPoint = this.lbPair.activationPoint.sub(
|
|
11719
11913
|
this.lbPair.preActivationDuration
|
|
11720
11914
|
);
|
|
11721
|
-
const activationPoint = !this.lbPair.preActivationSwapAddress.equals(
|
|
11915
|
+
const activationPoint = !this.lbPair.preActivationSwapAddress.equals(PublicKey7.default) && this.lbPair.preActivationSwapAddress.equals(swapInitiator) ? preActivationSwapPoint : this.lbPair.activationPoint;
|
|
11722
11916
|
if (currentPoint < activationPoint) {
|
|
11723
11917
|
return true;
|
|
11724
11918
|
}
|
|
@@ -11772,7 +11966,7 @@ var DLMM = class {
|
|
|
11772
11966
|
const liquidityShare = positionVersion === 0 /* V1 */ ? position.liquidityShares[binIdxInPosition] : position.liquidityShares[binIdxInPosition].shrn(64);
|
|
11773
11967
|
for (let j = 0; j < 2; j++) {
|
|
11774
11968
|
const pairRewardInfo = lbPair.rewardInfos[j];
|
|
11775
|
-
if (!pairRewardInfo.mint.equals(
|
|
11969
|
+
if (!pairRewardInfo.mint.equals(PublicKey7.default)) {
|
|
11776
11970
|
let rewardPerTokenStored = binState.rewardPerTokenStored[j];
|
|
11777
11971
|
if (i == lbPair.activeId && !binState.liquiditySupply.isZero()) {
|
|
11778
11972
|
const currentTime = new BN10(
|
|
@@ -11885,12 +12079,7 @@ var DLMM = class {
|
|
|
11885
12079
|
let totalYAmount = new Decimal5(0);
|
|
11886
12080
|
bins.forEach((bin, idx) => {
|
|
11887
12081
|
const binSupply = new Decimal5(bin.supply.toString());
|
|
11888
|
-
|
|
11889
|
-
if (bin.version === 1 && version === 0 /* V1 */) {
|
|
11890
|
-
posShare = new Decimal5(posShares[idx].shln(64).toString());
|
|
11891
|
-
} else {
|
|
11892
|
-
posShare = new Decimal5(posShares[idx].toString());
|
|
11893
|
-
}
|
|
12082
|
+
const posShare = new Decimal5(posShares[idx].toString());
|
|
11894
12083
|
const positionXAmount = binSupply.eq(new Decimal5("0")) ? new Decimal5("0") : posShare.mul(bin.xAmount.toString()).div(binSupply);
|
|
11895
12084
|
const positionYAmount = binSupply.eq(new Decimal5("0")) ? new Decimal5("0") : posShare.mul(bin.yAmount.toString()).div(binSupply);
|
|
11896
12085
|
totalXAmount = totalXAmount.add(positionXAmount);
|
|
@@ -12138,7 +12327,7 @@ var DLMM = class {
|
|
|
12138
12327
|
const claimTransactions = [];
|
|
12139
12328
|
for (let i = 0; i < 2; i++) {
|
|
12140
12329
|
const rewardInfo = this.lbPair.rewardInfos[i];
|
|
12141
|
-
if (!rewardInfo || rewardInfo.mint.equals(
|
|
12330
|
+
if (!rewardInfo || rewardInfo.mint.equals(PublicKey7.default))
|
|
12142
12331
|
continue;
|
|
12143
12332
|
const preInstructions = [];
|
|
12144
12333
|
const { ataPubKey, ix } = await getOrCreateATAInstruction(
|
|
@@ -12191,7 +12380,7 @@ var DLMM = class {
|
|
|
12191
12380
|
this.pubkey,
|
|
12192
12381
|
this.program.programId
|
|
12193
12382
|
);
|
|
12194
|
-
const walletToReceiveFee = feeOwner.equals(
|
|
12383
|
+
const walletToReceiveFee = feeOwner.equals(PublicKey7.default) ? owner : feeOwner;
|
|
12195
12384
|
const preInstructions = [];
|
|
12196
12385
|
const [
|
|
12197
12386
|
{ ataPubKey: userTokenX, ix: createInTokenAccountIx },
|
|
@@ -12262,6 +12451,7 @@ export {
|
|
|
12262
12451
|
MAX_BIN_PER_POSITION,
|
|
12263
12452
|
MAX_BIN_PER_TX,
|
|
12264
12453
|
MAX_CLAIM_ALL_ALLOWED,
|
|
12454
|
+
MAX_EXTRA_BIN_ARRAYS,
|
|
12265
12455
|
MAX_FEE_RATE,
|
|
12266
12456
|
Network,
|
|
12267
12457
|
POSITION_FEE,
|
|
@@ -12330,7 +12520,6 @@ export {
|
|
|
12330
12520
|
toAmountBidSide,
|
|
12331
12521
|
toAmountBothSide,
|
|
12332
12522
|
toAmountsBothSideByStrategy,
|
|
12333
|
-
toAmountsOneSideByStrategy,
|
|
12334
12523
|
toStrategyParameters,
|
|
12335
12524
|
toWeightDistribution,
|
|
12336
12525
|
unwrapSOLInstruction,
|