@meteora-ag/dlmm 1.3.5 → 1.3.6-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 +13 -1
- package/dist/index.js +161 -354
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +146 -339
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -8066,49 +8066,14 @@ var DLMM = class {
|
|
|
8066
8066
|
opt?.programId ?? LBCLMM_PROGRAM_IDS[cluster],
|
|
8067
8067
|
provider
|
|
8068
8068
|
);
|
|
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
|
-
}
|
|
8069
|
+
const positionsV2 = await program.account.positionV2.all([
|
|
8070
|
+
{
|
|
8071
|
+
memcmp: {
|
|
8072
|
+
bytes: bs58.encode(userPubKey.toBuffer()),
|
|
8073
|
+
offset: 8 + 32
|
|
8084
8074
|
}
|
|
8085
|
-
|
|
8075
|
+
}
|
|
8086
8076
|
]);
|
|
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
8077
|
const binArrayPubkeySetV2 = /* @__PURE__ */ new Set();
|
|
8113
8078
|
const lbPairSetV2 = /* @__PURE__ */ new Set();
|
|
8114
8079
|
positionsV2.forEach(({ account: { upperBinId, lowerBinId, lbPair } }) => {
|
|
@@ -8136,46 +8101,12 @@ var DLMM = class {
|
|
|
8136
8101
|
);
|
|
8137
8102
|
const [clockAccInfo, ...binArraysAccInfo] = await chunkedGetMultipleAccountInfos(connection, [
|
|
8138
8103
|
SYSVAR_CLOCK_PUBKEY,
|
|
8139
|
-
...binArrayPubkeyArray,
|
|
8140
|
-
...lbPairArray,
|
|
8141
8104
|
...binArrayPubkeyArrayV2,
|
|
8142
8105
|
...lbPairArrayV2
|
|
8143
8106
|
]);
|
|
8144
|
-
const positionBinArraysMap = /* @__PURE__ */ new Map();
|
|
8145
|
-
for (let i = 0; i < binArrayPubkeyArray.length; i++) {
|
|
8146
|
-
const binArrayPubkey = binArrayPubkeyArray[i];
|
|
8147
|
-
const binArrayAccInfoBuffer = binArraysAccInfo[i];
|
|
8148
|
-
if (!binArrayAccInfoBuffer)
|
|
8149
|
-
throw new Error(
|
|
8150
|
-
`Bin Array account ${binArrayPubkey.toBase58()} not found`
|
|
8151
|
-
);
|
|
8152
|
-
const binArrayAccInfo = program.coder.accounts.decode(
|
|
8153
|
-
"binArray",
|
|
8154
|
-
binArrayAccInfoBuffer.data
|
|
8155
|
-
);
|
|
8156
|
-
positionBinArraysMap.set(binArrayPubkey.toBase58(), binArrayAccInfo);
|
|
8157
|
-
}
|
|
8158
|
-
const lbPairArraysMap = /* @__PURE__ */ new Map();
|
|
8159
|
-
for (let i = binArrayPubkeyArray.length; i < binArrayPubkeyArray.length + lbPairArray.length; i++) {
|
|
8160
|
-
const lbPairPubkey = lbPairArray[i - binArrayPubkeyArray.length];
|
|
8161
|
-
const lbPairAccInfoBuffer = binArraysAccInfo[i];
|
|
8162
|
-
if (!lbPairAccInfoBuffer)
|
|
8163
|
-
throw new Error(`LB Pair account ${lbPairPubkey.toBase58()} not found`);
|
|
8164
|
-
const lbPairAccInfo = program.coder.accounts.decode(
|
|
8165
|
-
"lbPair",
|
|
8166
|
-
lbPairAccInfoBuffer.data
|
|
8167
|
-
);
|
|
8168
|
-
lbPairArraysMap.set(lbPairPubkey.toBase58(), lbPairAccInfo);
|
|
8169
|
-
}
|
|
8170
|
-
const reservePublicKeys = Array.from(lbPairArraysMap.values()).map(({ reserveX, reserveY, tokenXMint, tokenYMint }) => [
|
|
8171
|
-
reserveX,
|
|
8172
|
-
reserveY,
|
|
8173
|
-
tokenXMint,
|
|
8174
|
-
tokenYMint
|
|
8175
|
-
]).flat();
|
|
8176
8107
|
const positionBinArraysMapV2 = /* @__PURE__ */ new Map();
|
|
8177
|
-
for (let i =
|
|
8178
|
-
const binArrayPubkey = binArrayPubkeyArrayV2[i
|
|
8108
|
+
for (let i = 0; i < binArrayPubkeyArrayV2.length; i++) {
|
|
8109
|
+
const binArrayPubkey = binArrayPubkeyArrayV2[i];
|
|
8179
8110
|
const binArrayAccInfoBufferV2 = binArraysAccInfo[i];
|
|
8180
8111
|
if (!binArrayAccInfoBufferV2)
|
|
8181
8112
|
throw new Error(
|
|
@@ -8188,8 +8119,8 @@ var DLMM = class {
|
|
|
8188
8119
|
positionBinArraysMapV2.set(binArrayPubkey.toBase58(), binArrayAccInfo);
|
|
8189
8120
|
}
|
|
8190
8121
|
const lbPairArraysMapV2 = /* @__PURE__ */ new Map();
|
|
8191
|
-
for (let i =
|
|
8192
|
-
const lbPairPubkey = lbPairArrayV2[i -
|
|
8122
|
+
for (let i = binArrayPubkeyArrayV2.length; i < binArraysAccInfo.length; i++) {
|
|
8123
|
+
const lbPairPubkey = lbPairArrayV2[i - binArrayPubkeyArrayV2.length];
|
|
8193
8124
|
const lbPairAccInfoBufferV2 = binArraysAccInfo[i];
|
|
8194
8125
|
if (!lbPairAccInfoBufferV2)
|
|
8195
8126
|
throw new Error(`LB Pair account ${lbPairPubkey.toBase58()} not found`);
|
|
@@ -8207,43 +8138,14 @@ var DLMM = class {
|
|
|
8207
8138
|
]).flat();
|
|
8208
8139
|
const reserveAccountsInfo = await chunkedGetMultipleAccountInfos(
|
|
8209
8140
|
program.provider.connection,
|
|
8210
|
-
|
|
8141
|
+
reservePublicKeysV2
|
|
8211
8142
|
);
|
|
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
8143
|
const lbPairReserveMapV2 = /* @__PURE__ */ new Map();
|
|
8242
8144
|
const lbPairMintMapV2 = /* @__PURE__ */ new Map();
|
|
8243
8145
|
lbPairArrayV2.forEach((lbPair, idx) => {
|
|
8244
8146
|
const index = idx * 4;
|
|
8245
|
-
const reserveAccBufferXV2 = reserveAccountsInfo[
|
|
8246
|
-
const reserveAccBufferYV2 = reserveAccountsInfo[
|
|
8147
|
+
const reserveAccBufferXV2 = reserveAccountsInfo[index];
|
|
8148
|
+
const reserveAccBufferYV2 = reserveAccountsInfo[index + 1];
|
|
8247
8149
|
if (!reserveAccBufferXV2 || !reserveAccBufferYV2)
|
|
8248
8150
|
throw new Error(
|
|
8249
8151
|
`Reserve account for LB Pair ${lbPair.toBase58()} not found`
|
|
@@ -8254,8 +8156,8 @@ var DLMM = class {
|
|
|
8254
8156
|
reserveX: reserveAccX.amount,
|
|
8255
8157
|
reserveY: reserveAccY.amount
|
|
8256
8158
|
});
|
|
8257
|
-
const mintXBufferV2 = reserveAccountsInfo[
|
|
8258
|
-
const mintYBufferV2 = reserveAccountsInfo[
|
|
8159
|
+
const mintXBufferV2 = reserveAccountsInfo[index + 2];
|
|
8160
|
+
const mintYBufferV2 = reserveAccountsInfo[index + 3];
|
|
8259
8161
|
if (!mintXBufferV2 || !mintYBufferV2)
|
|
8260
8162
|
throw new Error(
|
|
8261
8163
|
`Mint account for LB Pair ${lbPair.toBase58()} not found`
|
|
@@ -8271,74 +8173,6 @@ var DLMM = class {
|
|
|
8271
8173
|
clockAccInfo.data.readBigInt64LE(32).toString()
|
|
8272
8174
|
).toNumber();
|
|
8273
8175
|
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
8176
|
for (let position of positionsV2) {
|
|
8343
8177
|
const { account, publicKey: positionPubKey } = position;
|
|
8344
8178
|
const { upperBinId, lowerBinId, lbPair, feeOwner } = account;
|
|
@@ -8410,56 +8244,6 @@ var DLMM = class {
|
|
|
8410
8244
|
}
|
|
8411
8245
|
return positionsMap;
|
|
8412
8246
|
}
|
|
8413
|
-
static async migratePosition(connection, positions, newPositions, walletPubkey, opt) {
|
|
8414
|
-
const cluster = opt?.cluster || "mainnet-beta";
|
|
8415
|
-
const provider = new AnchorProvider2(
|
|
8416
|
-
connection,
|
|
8417
|
-
{},
|
|
8418
|
-
AnchorProvider2.defaultOptions()
|
|
8419
|
-
);
|
|
8420
|
-
const program = new Program3(
|
|
8421
|
-
IDL,
|
|
8422
|
-
opt?.programId ?? LBCLMM_PROGRAM_IDS[cluster],
|
|
8423
|
-
provider
|
|
8424
|
-
);
|
|
8425
|
-
const positionsState = await program.account.position.fetchMultiple(
|
|
8426
|
-
positions
|
|
8427
|
-
);
|
|
8428
|
-
const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash("confirmed");
|
|
8429
|
-
return Promise.all(
|
|
8430
|
-
positionsState.map(async ({ lbPair, lowerBinId }, idx) => {
|
|
8431
|
-
const position = positions[idx];
|
|
8432
|
-
const lowerBinArrayIndex = binIdToBinArrayIndex(new BN10(lowerBinId));
|
|
8433
|
-
const upperBinArrayIndex = lowerBinArrayIndex.add(new BN10(1));
|
|
8434
|
-
const [lowerBinArrayPubKey] = deriveBinArray(
|
|
8435
|
-
lbPair,
|
|
8436
|
-
lowerBinArrayIndex,
|
|
8437
|
-
program.programId
|
|
8438
|
-
);
|
|
8439
|
-
const [upperBinArrayPubKey] = deriveBinArray(
|
|
8440
|
-
lbPair,
|
|
8441
|
-
upperBinArrayIndex,
|
|
8442
|
-
program.programId
|
|
8443
|
-
);
|
|
8444
|
-
const migrateTx = await program.methods.migratePosition().accounts({
|
|
8445
|
-
binArrayLower: lowerBinArrayPubKey,
|
|
8446
|
-
binArrayUpper: upperBinArrayPubKey,
|
|
8447
|
-
lbPair,
|
|
8448
|
-
owner: walletPubkey,
|
|
8449
|
-
positionV1: position,
|
|
8450
|
-
positionV2: newPositions[idx],
|
|
8451
|
-
program: program.programId,
|
|
8452
|
-
rentReceiver: walletPubkey,
|
|
8453
|
-
systemProgram: SystemProgram2.programId
|
|
8454
|
-
}).transaction();
|
|
8455
|
-
return new Transaction({
|
|
8456
|
-
blockhash,
|
|
8457
|
-
lastValidBlockHeight,
|
|
8458
|
-
feePayer: walletPubkey
|
|
8459
|
-
}).add(migrateTx);
|
|
8460
|
-
})
|
|
8461
|
-
);
|
|
8462
|
-
}
|
|
8463
8247
|
static getPricePerLamport(tokenXDecimal, tokenYDecimal, price) {
|
|
8464
8248
|
return new Decimal5(price).mul(new Decimal5(10 ** (tokenYDecimal - tokenXDecimal))).toString();
|
|
8465
8249
|
}
|
|
@@ -8951,20 +8735,6 @@ var DLMM = class {
|
|
|
8951
8735
|
async getPositionsByUserAndLbPair(userPubKey) {
|
|
8952
8736
|
const promiseResults = await Promise.all([
|
|
8953
8737
|
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
8738
|
userPubKey && this.program.account.positionV2.all([
|
|
8969
8739
|
{
|
|
8970
8740
|
memcmp: {
|
|
@@ -8980,7 +8750,7 @@ var DLMM = class {
|
|
|
8980
8750
|
}
|
|
8981
8751
|
])
|
|
8982
8752
|
]);
|
|
8983
|
-
const [activeBin,
|
|
8753
|
+
const [activeBin, positionsV2] = promiseResults;
|
|
8984
8754
|
if (!activeBin) {
|
|
8985
8755
|
throw new Error("Error fetching active bin");
|
|
8986
8756
|
}
|
|
@@ -8990,29 +8760,9 @@ var DLMM = class {
|
|
|
8990
8760
|
userPositions: []
|
|
8991
8761
|
};
|
|
8992
8762
|
}
|
|
8993
|
-
if (!
|
|
8763
|
+
if (!positionsV2) {
|
|
8994
8764
|
throw new Error("Error fetching positions");
|
|
8995
8765
|
}
|
|
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
8766
|
const binArrayPubkeySetV2 = /* @__PURE__ */ new Set();
|
|
9017
8767
|
positionsV2.forEach(({ account: { upperBinId, lowerBinId, lbPair } }) => {
|
|
9018
8768
|
const lowerBinArrayIndex = binIdToBinArrayIndex(new BN10(lowerBinId));
|
|
@@ -9038,28 +8788,13 @@ var DLMM = class {
|
|
|
9038
8788
|
[
|
|
9039
8789
|
this.pubkey,
|
|
9040
8790
|
SYSVAR_CLOCK_PUBKEY,
|
|
9041
|
-
...binArrayPubkeyArray,
|
|
9042
8791
|
...binArrayPubkeyArrayV2
|
|
9043
8792
|
]
|
|
9044
8793
|
);
|
|
9045
8794
|
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
8795
|
const positionBinArraysMapV2 = /* @__PURE__ */ new Map();
|
|
9061
|
-
for (let i =
|
|
9062
|
-
const binArrayPubkey = binArrayPubkeyArrayV2[i
|
|
8796
|
+
for (let i = 0; i < binArraysAccInfo.length; i++) {
|
|
8797
|
+
const binArrayPubkey = binArrayPubkeyArrayV2[i];
|
|
9063
8798
|
const binArrayAccBufferV2 = binArraysAccInfo[i];
|
|
9064
8799
|
if (!binArrayAccBufferV2)
|
|
9065
8800
|
throw new Error(
|
|
@@ -9076,45 +8811,6 @@ var DLMM = class {
|
|
|
9076
8811
|
const onChainTimestamp = new BN10(
|
|
9077
8812
|
clockAccInfo.data.readBigInt64LE(32).toString()
|
|
9078
8813
|
).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
8814
|
const userPositionsV2 = await Promise.all(
|
|
9119
8815
|
positionsV2.map(async ({ publicKey, account }) => {
|
|
9120
8816
|
const { lowerBinId, upperBinId, feeOwner } = account;
|
|
@@ -9156,7 +8852,7 @@ var DLMM = class {
|
|
|
9156
8852
|
);
|
|
9157
8853
|
return {
|
|
9158
8854
|
activeBin,
|
|
9159
|
-
userPositions:
|
|
8855
|
+
userPositions: userPositionsV2
|
|
9160
8856
|
};
|
|
9161
8857
|
}
|
|
9162
8858
|
async quoteCreatePosition({ strategy }) {
|
|
@@ -9217,6 +8913,93 @@ var DLMM = class {
|
|
|
9217
8913
|
feePayer: user
|
|
9218
8914
|
}).add(setCUIx, ...instructions);
|
|
9219
8915
|
}
|
|
8916
|
+
/**
|
|
8917
|
+
* The function `getPosition` retrieves position information for a given public key and processes it
|
|
8918
|
+
* using various data to return a `LbPosition` object.
|
|
8919
|
+
* @param {PublicKey} positionPubKey - The `getPosition` function you provided is an asynchronous
|
|
8920
|
+
* function that fetches position information based on a given public key. Here's a breakdown of the
|
|
8921
|
+
* parameters used in the function:
|
|
8922
|
+
* @returns The `getPosition` function returns a Promise that resolves to an object of type
|
|
8923
|
+
* `LbPosition`. The object contains the following properties:
|
|
8924
|
+
* - `publicKey`: The public key of the position account
|
|
8925
|
+
* - `positionData`: Position Object
|
|
8926
|
+
* - `version`: The version of the position (in this case, `Position.V2`)
|
|
8927
|
+
*/
|
|
8928
|
+
async getPosition(positionPubKey) {
|
|
8929
|
+
const positionAccountInfo = await this.program.account.positionV2.fetch(positionPubKey);
|
|
8930
|
+
if (!positionAccountInfo) {
|
|
8931
|
+
throw new Error(`Position account ${positionPubKey.toBase58()} not found`);
|
|
8932
|
+
}
|
|
8933
|
+
const { lowerBinId, upperBinId, feeOwner } = positionAccountInfo;
|
|
8934
|
+
const lowerBinArrayIndex = binIdToBinArrayIndex(new BN10(lowerBinId));
|
|
8935
|
+
const upperBinArrayIndex = binIdToBinArrayIndex(new BN10(upperBinId));
|
|
8936
|
+
const [lowerBinArrayPubKey] = deriveBinArray(
|
|
8937
|
+
this.pubkey,
|
|
8938
|
+
lowerBinArrayIndex,
|
|
8939
|
+
this.program.programId
|
|
8940
|
+
);
|
|
8941
|
+
const [upperBinArrayPubKey] = deriveBinArray(
|
|
8942
|
+
this.pubkey,
|
|
8943
|
+
upperBinArrayIndex,
|
|
8944
|
+
this.program.programId
|
|
8945
|
+
);
|
|
8946
|
+
const [clockAccInfo, lowerBinArrayAccInfo, upperBinArrayAccInfo] = await chunkedGetMultipleAccountInfos(
|
|
8947
|
+
this.program.provider.connection,
|
|
8948
|
+
[
|
|
8949
|
+
SYSVAR_CLOCK_PUBKEY,
|
|
8950
|
+
lowerBinArrayPubKey,
|
|
8951
|
+
upperBinArrayPubKey
|
|
8952
|
+
]
|
|
8953
|
+
);
|
|
8954
|
+
if (!lowerBinArrayAccInfo || !upperBinArrayAccInfo) {
|
|
8955
|
+
return {
|
|
8956
|
+
publicKey: positionPubKey,
|
|
8957
|
+
positionData: {
|
|
8958
|
+
totalXAmount: "0",
|
|
8959
|
+
totalYAmount: "0",
|
|
8960
|
+
positionBinData: [],
|
|
8961
|
+
lastUpdatedAt: new BN10(0),
|
|
8962
|
+
upperBinId,
|
|
8963
|
+
lowerBinId,
|
|
8964
|
+
feeX: new BN10(0),
|
|
8965
|
+
feeY: new BN10(0),
|
|
8966
|
+
rewardOne: new BN10(0),
|
|
8967
|
+
rewardTwo: new BN10(0),
|
|
8968
|
+
feeOwner,
|
|
8969
|
+
totalClaimedFeeXAmount: new BN10(0),
|
|
8970
|
+
totalClaimedFeeYAmount: new BN10(0)
|
|
8971
|
+
},
|
|
8972
|
+
version: 1 /* V2 */
|
|
8973
|
+
};
|
|
8974
|
+
}
|
|
8975
|
+
const onChainTimestamp = new BN10(
|
|
8976
|
+
clockAccInfo.data.readBigInt64LE(32).toString()
|
|
8977
|
+
).toNumber();
|
|
8978
|
+
const lowerBinArray = this.program.coder.accounts.decode(
|
|
8979
|
+
"binArray",
|
|
8980
|
+
lowerBinArrayAccInfo.data
|
|
8981
|
+
);
|
|
8982
|
+
const upperBinArray = this.program.coder.accounts.decode(
|
|
8983
|
+
"binArray",
|
|
8984
|
+
upperBinArrayAccInfo.data
|
|
8985
|
+
);
|
|
8986
|
+
return {
|
|
8987
|
+
publicKey: positionPubKey,
|
|
8988
|
+
positionData: await DLMM.processPosition(
|
|
8989
|
+
this.program,
|
|
8990
|
+
1 /* V2 */,
|
|
8991
|
+
this.lbPair,
|
|
8992
|
+
onChainTimestamp,
|
|
8993
|
+
positionAccountInfo,
|
|
8994
|
+
this.tokenX.decimal,
|
|
8995
|
+
this.tokenY.decimal,
|
|
8996
|
+
lowerBinArray,
|
|
8997
|
+
upperBinArray,
|
|
8998
|
+
feeOwner
|
|
8999
|
+
),
|
|
9000
|
+
version: 1 /* V2 */
|
|
9001
|
+
};
|
|
9002
|
+
}
|
|
9220
9003
|
/**
|
|
9221
9004
|
* The function `initializePositionAndAddLiquidityByStrategy` function is used to initializes a position and adds liquidity
|
|
9222
9005
|
* @param {TInitializePositionAndAddLiquidityParamsByStrategy}
|
|
@@ -9940,9 +9723,40 @@ var DLMM = class {
|
|
|
9940
9723
|
bps,
|
|
9941
9724
|
shouldClaimAndClose = false
|
|
9942
9725
|
}) {
|
|
9943
|
-
const
|
|
9944
|
-
const
|
|
9945
|
-
const
|
|
9726
|
+
const lowerBinIdToRemove = Math.min(...binIds);
|
|
9727
|
+
const upperBinIdToRemove = Math.max(...binIds);
|
|
9728
|
+
const [lowerBinArrayPubKey] = deriveBinArray(this.pubkey, binIdToBinArrayIndex(new BN10(binIds[0])), this.program.programId);
|
|
9729
|
+
const [upperBinArrayPubKey] = deriveBinArray(this.pubkey, binIdToBinArrayIndex(new BN10(binIds[binIds.length - 1])), this.program.programId);
|
|
9730
|
+
const [positionAccInfo, lbPairAccInfo, upperBinArrayInfoAcc, lowerBinArrayInfoAcc] = await this.program.provider.connection.getMultipleAccountsInfo([
|
|
9731
|
+
position,
|
|
9732
|
+
this.pubkey,
|
|
9733
|
+
upperBinArrayPubKey,
|
|
9734
|
+
lowerBinArrayPubKey
|
|
9735
|
+
]);
|
|
9736
|
+
const { lbPair, owner, feeOwner, upperBinId: positionUpperBinId, lowerBinId: positionLowerBinId } = this.program.coder.accounts.decode(
|
|
9737
|
+
"positionV2",
|
|
9738
|
+
positionAccInfo.data
|
|
9739
|
+
);
|
|
9740
|
+
const { reserveX, reserveY, tokenXMint, tokenYMint } = this.program.coder.accounts.decode(
|
|
9741
|
+
"lbPair",
|
|
9742
|
+
lbPairAccInfo.data
|
|
9743
|
+
);
|
|
9744
|
+
const upperBinArray = this.program.coder.accounts.decode("binArray", upperBinArrayInfoAcc.data);
|
|
9745
|
+
const lowerBinArray = this.program.coder.accounts.decode("binArray", lowerBinArrayInfoAcc.data);
|
|
9746
|
+
const bins = await this.getBins(
|
|
9747
|
+
this.pubkey,
|
|
9748
|
+
positionLowerBinId,
|
|
9749
|
+
positionUpperBinId,
|
|
9750
|
+
this.tokenX.decimal,
|
|
9751
|
+
this.tokenY.decimal,
|
|
9752
|
+
lowerBinArray,
|
|
9753
|
+
upperBinArray
|
|
9754
|
+
);
|
|
9755
|
+
const positionHasNoLiquidity = bins.every(({ supply }) => supply.isZero());
|
|
9756
|
+
if (positionHasNoLiquidity) {
|
|
9757
|
+
throw new Error("No liquidity to remove");
|
|
9758
|
+
}
|
|
9759
|
+
const lowerBinArrayIndex = binIdToBinArrayIndex(new BN10(positionLowerBinId));
|
|
9946
9760
|
const upperBinArrayIndex = lowerBinArrayIndex.add(new BN10(1));
|
|
9947
9761
|
const [binArrayLower] = deriveBinArray(
|
|
9948
9762
|
lbPair,
|
|
@@ -10056,13 +9870,11 @@ var DLMM = class {
|
|
|
10056
9870
|
const closeWrappedSOLIx = await unwrapSOLInstruction(user);
|
|
10057
9871
|
closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
|
|
10058
9872
|
}
|
|
10059
|
-
const
|
|
10060
|
-
const
|
|
10061
|
-
const minBinArrayIndex = binIdToBinArrayIndex(new BN10(minBinId));
|
|
10062
|
-
const maxBinArrayIndex = binIdToBinArrayIndex(new BN10(maxBinId));
|
|
9873
|
+
const minBinArrayIndex = binIdToBinArrayIndex(new BN10(lowerBinIdToRemove));
|
|
9874
|
+
const maxBinArrayIndex = binIdToBinArrayIndex(new BN10(upperBinIdToRemove));
|
|
10063
9875
|
const useExtension = isOverflowDefaultBinArrayBitmap(minBinArrayIndex) || isOverflowDefaultBinArrayBitmap(maxBinArrayIndex);
|
|
10064
9876
|
const binArrayBitmapExtension = useExtension ? deriveBinArrayBitmapExtension(this.pubkey, this.program.programId)[0] : null;
|
|
10065
|
-
const
|
|
9877
|
+
const removeLiquidityTx = await this.program.methods.removeLiquidityByRange(lowerBinIdToRemove, upperBinIdToRemove, bps.toNumber()).accounts({
|
|
10066
9878
|
position,
|
|
10067
9879
|
lbPair,
|
|
10068
9880
|
userTokenX,
|
|
@@ -10080,7 +9892,7 @@ var DLMM = class {
|
|
|
10080
9892
|
}).instruction();
|
|
10081
9893
|
const instructions = [
|
|
10082
9894
|
...preInstructions,
|
|
10083
|
-
|
|
9895
|
+
removeLiquidityTx,
|
|
10084
9896
|
...postInstructions
|
|
10085
9897
|
];
|
|
10086
9898
|
const setCUIx = await getEstimatedComputeUnitIxWithBuffer(
|
|
@@ -11885,12 +11697,7 @@ var DLMM = class {
|
|
|
11885
11697
|
let totalYAmount = new Decimal5(0);
|
|
11886
11698
|
bins.forEach((bin, idx) => {
|
|
11887
11699
|
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
|
-
}
|
|
11700
|
+
const posShare = new Decimal5(posShares[idx].toString());
|
|
11894
11701
|
const positionXAmount = binSupply.eq(new Decimal5("0")) ? new Decimal5("0") : posShare.mul(bin.xAmount.toString()).div(binSupply);
|
|
11895
11702
|
const positionYAmount = binSupply.eq(new Decimal5("0")) ? new Decimal5("0") : posShare.mul(bin.yAmount.toString()).div(binSupply);
|
|
11896
11703
|
totalXAmount = totalXAmount.add(positionXAmount);
|