@meteora-ag/dlmm 1.3.0 → 1.3.1-sam.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +13 -1
- package/dist/index.js +138 -352
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +124 -338
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -7975,49 +7975,14 @@ var DLMM = class {
|
|
|
7975
7975
|
_nullishCoalesce(_optionalChain([opt, 'optionalAccess', _46 => _46.programId]), () => ( LBCLMM_PROGRAM_IDS[cluster])),
|
|
7976
7976
|
provider
|
|
7977
7977
|
);
|
|
7978
|
-
const
|
|
7979
|
-
|
|
7980
|
-
{
|
|
7981
|
-
|
|
7982
|
-
|
|
7983
|
-
offset: 8 + 32
|
|
7984
|
-
}
|
|
7985
|
-
}
|
|
7986
|
-
]),
|
|
7987
|
-
program.account.positionV2.all([
|
|
7988
|
-
{
|
|
7989
|
-
memcmp: {
|
|
7990
|
-
bytes: _bytes.bs58.encode(userPubKey.toBuffer()),
|
|
7991
|
-
offset: 8 + 32
|
|
7992
|
-
}
|
|
7978
|
+
const positionsV2 = await program.account.positionV2.all([
|
|
7979
|
+
{
|
|
7980
|
+
memcmp: {
|
|
7981
|
+
bytes: _bytes.bs58.encode(userPubKey.toBuffer()),
|
|
7982
|
+
offset: 8 + 32
|
|
7993
7983
|
}
|
|
7994
|
-
|
|
7984
|
+
}
|
|
7995
7985
|
]);
|
|
7996
|
-
const binArrayPubkeySet = /* @__PURE__ */ new Set();
|
|
7997
|
-
const lbPairSet = /* @__PURE__ */ new Set();
|
|
7998
|
-
positions.forEach(({ account: { upperBinId, lowerBinId, lbPair } }) => {
|
|
7999
|
-
const lowerBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(lowerBinId));
|
|
8000
|
-
const upperBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(upperBinId));
|
|
8001
|
-
const [lowerBinArrayPubKey] = deriveBinArray(
|
|
8002
|
-
lbPair,
|
|
8003
|
-
lowerBinArrayIndex,
|
|
8004
|
-
program.programId
|
|
8005
|
-
);
|
|
8006
|
-
const [upperBinArrayPubKey] = deriveBinArray(
|
|
8007
|
-
lbPair,
|
|
8008
|
-
upperBinArrayIndex,
|
|
8009
|
-
program.programId
|
|
8010
|
-
);
|
|
8011
|
-
binArrayPubkeySet.add(lowerBinArrayPubKey.toBase58());
|
|
8012
|
-
binArrayPubkeySet.add(upperBinArrayPubKey.toBase58());
|
|
8013
|
-
lbPairSet.add(lbPair.toBase58());
|
|
8014
|
-
});
|
|
8015
|
-
const binArrayPubkeyArray = Array.from(binArrayPubkeySet).map(
|
|
8016
|
-
(pubkey) => new (0, _web3js.PublicKey)(pubkey)
|
|
8017
|
-
);
|
|
8018
|
-
const lbPairArray = Array.from(lbPairSet).map(
|
|
8019
|
-
(pubkey) => new (0, _web3js.PublicKey)(pubkey)
|
|
8020
|
-
);
|
|
8021
7986
|
const binArrayPubkeySetV2 = /* @__PURE__ */ new Set();
|
|
8022
7987
|
const lbPairSetV2 = /* @__PURE__ */ new Set();
|
|
8023
7988
|
positionsV2.forEach(({ account: { upperBinId, lowerBinId, lbPair } }) => {
|
|
@@ -8045,46 +8010,12 @@ var DLMM = class {
|
|
|
8045
8010
|
);
|
|
8046
8011
|
const [clockAccInfo, ...binArraysAccInfo] = await chunkedGetMultipleAccountInfos(connection, [
|
|
8047
8012
|
_web3js.SYSVAR_CLOCK_PUBKEY,
|
|
8048
|
-
...binArrayPubkeyArray,
|
|
8049
|
-
...lbPairArray,
|
|
8050
8013
|
...binArrayPubkeyArrayV2,
|
|
8051
8014
|
...lbPairArrayV2
|
|
8052
8015
|
]);
|
|
8053
|
-
const positionBinArraysMap = /* @__PURE__ */ new Map();
|
|
8054
|
-
for (let i = 0; i < binArrayPubkeyArray.length; i++) {
|
|
8055
|
-
const binArrayPubkey = binArrayPubkeyArray[i];
|
|
8056
|
-
const binArrayAccInfoBuffer = binArraysAccInfo[i];
|
|
8057
|
-
if (!binArrayAccInfoBuffer)
|
|
8058
|
-
throw new Error(
|
|
8059
|
-
`Bin Array account ${binArrayPubkey.toBase58()} not found`
|
|
8060
|
-
);
|
|
8061
|
-
const binArrayAccInfo = program.coder.accounts.decode(
|
|
8062
|
-
"binArray",
|
|
8063
|
-
binArrayAccInfoBuffer.data
|
|
8064
|
-
);
|
|
8065
|
-
positionBinArraysMap.set(binArrayPubkey.toBase58(), binArrayAccInfo);
|
|
8066
|
-
}
|
|
8067
|
-
const lbPairArraysMap = /* @__PURE__ */ new Map();
|
|
8068
|
-
for (let i = binArrayPubkeyArray.length; i < binArrayPubkeyArray.length + lbPairArray.length; i++) {
|
|
8069
|
-
const lbPairPubkey = lbPairArray[i - binArrayPubkeyArray.length];
|
|
8070
|
-
const lbPairAccInfoBuffer = binArraysAccInfo[i];
|
|
8071
|
-
if (!lbPairAccInfoBuffer)
|
|
8072
|
-
throw new Error(`LB Pair account ${lbPairPubkey.toBase58()} not found`);
|
|
8073
|
-
const lbPairAccInfo = program.coder.accounts.decode(
|
|
8074
|
-
"lbPair",
|
|
8075
|
-
lbPairAccInfoBuffer.data
|
|
8076
|
-
);
|
|
8077
|
-
lbPairArraysMap.set(lbPairPubkey.toBase58(), lbPairAccInfo);
|
|
8078
|
-
}
|
|
8079
|
-
const reservePublicKeys = Array.from(lbPairArraysMap.values()).map(({ reserveX, reserveY, tokenXMint, tokenYMint }) => [
|
|
8080
|
-
reserveX,
|
|
8081
|
-
reserveY,
|
|
8082
|
-
tokenXMint,
|
|
8083
|
-
tokenYMint
|
|
8084
|
-
]).flat();
|
|
8085
8016
|
const positionBinArraysMapV2 = /* @__PURE__ */ new Map();
|
|
8086
|
-
for (let i =
|
|
8087
|
-
const binArrayPubkey = binArrayPubkeyArrayV2[i
|
|
8017
|
+
for (let i = 0; i < binArrayPubkeyArrayV2.length; i++) {
|
|
8018
|
+
const binArrayPubkey = binArrayPubkeyArrayV2[i];
|
|
8088
8019
|
const binArrayAccInfoBufferV2 = binArraysAccInfo[i];
|
|
8089
8020
|
if (!binArrayAccInfoBufferV2)
|
|
8090
8021
|
throw new Error(
|
|
@@ -8097,8 +8028,8 @@ var DLMM = class {
|
|
|
8097
8028
|
positionBinArraysMapV2.set(binArrayPubkey.toBase58(), binArrayAccInfo);
|
|
8098
8029
|
}
|
|
8099
8030
|
const lbPairArraysMapV2 = /* @__PURE__ */ new Map();
|
|
8100
|
-
for (let i =
|
|
8101
|
-
const lbPairPubkey = lbPairArrayV2[i -
|
|
8031
|
+
for (let i = binArrayPubkeyArrayV2.length; i < binArraysAccInfo.length; i++) {
|
|
8032
|
+
const lbPairPubkey = lbPairArrayV2[i - binArrayPubkeyArrayV2.length];
|
|
8102
8033
|
const lbPairAccInfoBufferV2 = binArraysAccInfo[i];
|
|
8103
8034
|
if (!lbPairAccInfoBufferV2)
|
|
8104
8035
|
throw new Error(`LB Pair account ${lbPairPubkey.toBase58()} not found`);
|
|
@@ -8116,43 +8047,14 @@ var DLMM = class {
|
|
|
8116
8047
|
]).flat();
|
|
8117
8048
|
const reserveAccountsInfo = await chunkedGetMultipleAccountInfos(
|
|
8118
8049
|
program.provider.connection,
|
|
8119
|
-
|
|
8050
|
+
reservePublicKeysV2
|
|
8120
8051
|
);
|
|
8121
|
-
const lbPairReserveMap = /* @__PURE__ */ new Map();
|
|
8122
|
-
const lbPairMintMap = /* @__PURE__ */ new Map();
|
|
8123
|
-
lbPairArray.forEach((lbPair, idx) => {
|
|
8124
|
-
const index = idx * 4;
|
|
8125
|
-
const reserveAccBufferX = reserveAccountsInfo[index];
|
|
8126
|
-
const reserveAccBufferY = reserveAccountsInfo[index + 1];
|
|
8127
|
-
if (!reserveAccBufferX || !reserveAccBufferY)
|
|
8128
|
-
throw new Error(
|
|
8129
|
-
`Reserve account for LB Pair ${lbPair.toBase58()} not found`
|
|
8130
|
-
);
|
|
8131
|
-
const reserveAccX = _spltoken.AccountLayout.decode(reserveAccBufferX.data);
|
|
8132
|
-
const reserveAccY = _spltoken.AccountLayout.decode(reserveAccBufferY.data);
|
|
8133
|
-
lbPairReserveMap.set(lbPair.toBase58(), {
|
|
8134
|
-
reserveX: reserveAccX.amount,
|
|
8135
|
-
reserveY: reserveAccY.amount
|
|
8136
|
-
});
|
|
8137
|
-
const mintXBuffer = reserveAccountsInfo[index + 2];
|
|
8138
|
-
const mintYBuffer = reserveAccountsInfo[index + 3];
|
|
8139
|
-
if (!mintXBuffer || !mintYBuffer)
|
|
8140
|
-
throw new Error(
|
|
8141
|
-
`Mint account for LB Pair ${lbPair.toBase58()} not found`
|
|
8142
|
-
);
|
|
8143
|
-
const mintX = _spltoken.MintLayout.decode(mintXBuffer.data);
|
|
8144
|
-
const mintY = _spltoken.MintLayout.decode(mintYBuffer.data);
|
|
8145
|
-
lbPairMintMap.set(lbPair.toBase58(), {
|
|
8146
|
-
mintXDecimal: mintX.decimals,
|
|
8147
|
-
mintYDecimal: mintY.decimals
|
|
8148
|
-
});
|
|
8149
|
-
});
|
|
8150
8052
|
const lbPairReserveMapV2 = /* @__PURE__ */ new Map();
|
|
8151
8053
|
const lbPairMintMapV2 = /* @__PURE__ */ new Map();
|
|
8152
8054
|
lbPairArrayV2.forEach((lbPair, idx) => {
|
|
8153
8055
|
const index = idx * 4;
|
|
8154
|
-
const reserveAccBufferXV2 = reserveAccountsInfo[
|
|
8155
|
-
const reserveAccBufferYV2 = reserveAccountsInfo[
|
|
8056
|
+
const reserveAccBufferXV2 = reserveAccountsInfo[index];
|
|
8057
|
+
const reserveAccBufferYV2 = reserveAccountsInfo[index + 1];
|
|
8156
8058
|
if (!reserveAccBufferXV2 || !reserveAccBufferYV2)
|
|
8157
8059
|
throw new Error(
|
|
8158
8060
|
`Reserve account for LB Pair ${lbPair.toBase58()} not found`
|
|
@@ -8163,8 +8065,8 @@ var DLMM = class {
|
|
|
8163
8065
|
reserveX: reserveAccX.amount,
|
|
8164
8066
|
reserveY: reserveAccY.amount
|
|
8165
8067
|
});
|
|
8166
|
-
const mintXBufferV2 = reserveAccountsInfo[
|
|
8167
|
-
const mintYBufferV2 = reserveAccountsInfo[
|
|
8068
|
+
const mintXBufferV2 = reserveAccountsInfo[index + 2];
|
|
8069
|
+
const mintYBufferV2 = reserveAccountsInfo[index + 3];
|
|
8168
8070
|
if (!mintXBufferV2 || !mintYBufferV2)
|
|
8169
8071
|
throw new Error(
|
|
8170
8072
|
`Mint account for LB Pair ${lbPair.toBase58()} not found`
|
|
@@ -8180,74 +8082,6 @@ var DLMM = class {
|
|
|
8180
8082
|
clockAccInfo.data.readBigInt64LE(32).toString()
|
|
8181
8083
|
).toNumber();
|
|
8182
8084
|
const positionsMap = /* @__PURE__ */ new Map();
|
|
8183
|
-
for (let position of positions) {
|
|
8184
|
-
const { account, publicKey: positionPubKey } = position;
|
|
8185
|
-
const { upperBinId, lowerBinId, lbPair } = account;
|
|
8186
|
-
const lowerBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(lowerBinId));
|
|
8187
|
-
const upperBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(upperBinId));
|
|
8188
|
-
const [lowerBinArrayPubKey] = deriveBinArray(
|
|
8189
|
-
lbPair,
|
|
8190
|
-
lowerBinArrayIndex,
|
|
8191
|
-
program.programId
|
|
8192
|
-
);
|
|
8193
|
-
const [upperBinArrayPubKey] = deriveBinArray(
|
|
8194
|
-
lbPair,
|
|
8195
|
-
upperBinArrayIndex,
|
|
8196
|
-
program.programId
|
|
8197
|
-
);
|
|
8198
|
-
const lowerBinArray = positionBinArraysMap.get(
|
|
8199
|
-
lowerBinArrayPubKey.toBase58()
|
|
8200
|
-
);
|
|
8201
|
-
const upperBinArray = positionBinArraysMap.get(
|
|
8202
|
-
upperBinArrayPubKey.toBase58()
|
|
8203
|
-
);
|
|
8204
|
-
const lbPairAcc = lbPairArraysMap.get(lbPair.toBase58());
|
|
8205
|
-
const { mintXDecimal, mintYDecimal } = lbPairMintMap.get(
|
|
8206
|
-
lbPair.toBase58()
|
|
8207
|
-
);
|
|
8208
|
-
const reserveXBalance = _nullishCoalesce(_optionalChain([lbPairReserveMap, 'access', _47 => _47.get, 'call', _48 => _48(lbPair.toBase58()), 'optionalAccess', _49 => _49.reserveX]), () => ( BigInt(0)));
|
|
8209
|
-
const reserveYBalance = _nullishCoalesce(_optionalChain([lbPairReserveMap, 'access', _50 => _50.get, 'call', _51 => _51(lbPair.toBase58()), 'optionalAccess', _52 => _52.reserveY]), () => ( BigInt(0)));
|
|
8210
|
-
const tokenX = {
|
|
8211
|
-
publicKey: lbPairAcc.tokenXMint,
|
|
8212
|
-
reserve: lbPairAcc.reserveX,
|
|
8213
|
-
amount: reserveXBalance,
|
|
8214
|
-
decimal: mintXDecimal
|
|
8215
|
-
};
|
|
8216
|
-
const tokenY = {
|
|
8217
|
-
publicKey: lbPairAcc.tokenYMint,
|
|
8218
|
-
reserve: lbPairAcc.reserveY,
|
|
8219
|
-
amount: reserveYBalance,
|
|
8220
|
-
decimal: mintYDecimal
|
|
8221
|
-
};
|
|
8222
|
-
const positionData = await DLMM.processPosition(
|
|
8223
|
-
program,
|
|
8224
|
-
0 /* V1 */,
|
|
8225
|
-
lbPairAcc,
|
|
8226
|
-
onChainTimestamp,
|
|
8227
|
-
account,
|
|
8228
|
-
mintXDecimal,
|
|
8229
|
-
mintYDecimal,
|
|
8230
|
-
lowerBinArray,
|
|
8231
|
-
upperBinArray,
|
|
8232
|
-
_web3js.PublicKey.default
|
|
8233
|
-
);
|
|
8234
|
-
if (positionData) {
|
|
8235
|
-
positionsMap.set(lbPair.toBase58(), {
|
|
8236
|
-
publicKey: lbPair,
|
|
8237
|
-
lbPair: lbPairAcc,
|
|
8238
|
-
tokenX,
|
|
8239
|
-
tokenY,
|
|
8240
|
-
lbPairPositionsData: [
|
|
8241
|
-
..._nullishCoalesce(_optionalChain([positionsMap, 'access', _53 => _53.get, 'call', _54 => _54(lbPair.toBase58()), 'optionalAccess', _55 => _55.lbPairPositionsData]), () => ( [])),
|
|
8242
|
-
{
|
|
8243
|
-
publicKey: positionPubKey,
|
|
8244
|
-
positionData,
|
|
8245
|
-
version: 0 /* V1 */
|
|
8246
|
-
}
|
|
8247
|
-
]
|
|
8248
|
-
});
|
|
8249
|
-
}
|
|
8250
|
-
}
|
|
8251
8085
|
for (let position of positionsV2) {
|
|
8252
8086
|
const { account, publicKey: positionPubKey } = position;
|
|
8253
8087
|
const { upperBinId, lowerBinId, lbPair, feeOwner } = account;
|
|
@@ -8274,8 +8108,8 @@ var DLMM = class {
|
|
|
8274
8108
|
getTokenDecimals(program.provider.connection, lbPairAcc.tokenXMint),
|
|
8275
8109
|
getTokenDecimals(program.provider.connection, lbPairAcc.tokenYMint)
|
|
8276
8110
|
]);
|
|
8277
|
-
const reserveXBalance = _nullishCoalesce(_optionalChain([lbPairReserveMapV2, 'access',
|
|
8278
|
-
const reserveYBalance = _nullishCoalesce(_optionalChain([lbPairReserveMapV2, 'access',
|
|
8111
|
+
const reserveXBalance = _nullishCoalesce(_optionalChain([lbPairReserveMapV2, 'access', _47 => _47.get, 'call', _48 => _48(lbPair.toBase58()), 'optionalAccess', _49 => _49.reserveX]), () => ( BigInt(0)));
|
|
8112
|
+
const reserveYBalance = _nullishCoalesce(_optionalChain([lbPairReserveMapV2, 'access', _50 => _50.get, 'call', _51 => _51(lbPair.toBase58()), 'optionalAccess', _52 => _52.reserveY]), () => ( BigInt(0)));
|
|
8279
8113
|
const tokenX = {
|
|
8280
8114
|
publicKey: lbPairAcc.tokenXMint,
|
|
8281
8115
|
reserve: lbPairAcc.reserveX,
|
|
@@ -8307,7 +8141,7 @@ var DLMM = class {
|
|
|
8307
8141
|
tokenX,
|
|
8308
8142
|
tokenY,
|
|
8309
8143
|
lbPairPositionsData: [
|
|
8310
|
-
..._nullishCoalesce(_optionalChain([positionsMap, 'access',
|
|
8144
|
+
..._nullishCoalesce(_optionalChain([positionsMap, 'access', _53 => _53.get, 'call', _54 => _54(lbPair.toBase58()), 'optionalAccess', _55 => _55.lbPairPositionsData]), () => ( [])),
|
|
8311
8145
|
{
|
|
8312
8146
|
publicKey: positionPubKey,
|
|
8313
8147
|
positionData,
|
|
@@ -8319,56 +8153,6 @@ var DLMM = class {
|
|
|
8319
8153
|
}
|
|
8320
8154
|
return positionsMap;
|
|
8321
8155
|
}
|
|
8322
|
-
static async migratePosition(connection, positions, newPositions, walletPubkey, opt) {
|
|
8323
|
-
const cluster = _optionalChain([opt, 'optionalAccess', _65 => _65.cluster]) || "mainnet-beta";
|
|
8324
|
-
const provider = new (0, _anchor.AnchorProvider)(
|
|
8325
|
-
connection,
|
|
8326
|
-
{},
|
|
8327
|
-
_anchor.AnchorProvider.defaultOptions()
|
|
8328
|
-
);
|
|
8329
|
-
const program = new (0, _anchor.Program)(
|
|
8330
|
-
IDL,
|
|
8331
|
-
_nullishCoalesce(_optionalChain([opt, 'optionalAccess', _66 => _66.programId]), () => ( LBCLMM_PROGRAM_IDS[cluster])),
|
|
8332
|
-
provider
|
|
8333
|
-
);
|
|
8334
|
-
const positionsState = await program.account.position.fetchMultiple(
|
|
8335
|
-
positions
|
|
8336
|
-
);
|
|
8337
|
-
const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash("confirmed");
|
|
8338
|
-
return Promise.all(
|
|
8339
|
-
positionsState.map(async ({ lbPair, lowerBinId }, idx) => {
|
|
8340
|
-
const position = positions[idx];
|
|
8341
|
-
const lowerBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(lowerBinId));
|
|
8342
|
-
const upperBinArrayIndex = lowerBinArrayIndex.add(new (0, _anchor.BN)(1));
|
|
8343
|
-
const [lowerBinArrayPubKey] = deriveBinArray(
|
|
8344
|
-
lbPair,
|
|
8345
|
-
lowerBinArrayIndex,
|
|
8346
|
-
program.programId
|
|
8347
|
-
);
|
|
8348
|
-
const [upperBinArrayPubKey] = deriveBinArray(
|
|
8349
|
-
lbPair,
|
|
8350
|
-
upperBinArrayIndex,
|
|
8351
|
-
program.programId
|
|
8352
|
-
);
|
|
8353
|
-
const migrateTx = await program.methods.migratePosition().accounts({
|
|
8354
|
-
binArrayLower: lowerBinArrayPubKey,
|
|
8355
|
-
binArrayUpper: upperBinArrayPubKey,
|
|
8356
|
-
lbPair,
|
|
8357
|
-
owner: walletPubkey,
|
|
8358
|
-
positionV1: position,
|
|
8359
|
-
positionV2: newPositions[idx],
|
|
8360
|
-
program: program.programId,
|
|
8361
|
-
rentReceiver: walletPubkey,
|
|
8362
|
-
systemProgram: _web3js.SystemProgram.programId
|
|
8363
|
-
}).transaction();
|
|
8364
|
-
return new (0, _web3js.Transaction)({
|
|
8365
|
-
blockhash,
|
|
8366
|
-
lastValidBlockHeight,
|
|
8367
|
-
feePayer: walletPubkey
|
|
8368
|
-
}).add(migrateTx);
|
|
8369
|
-
})
|
|
8370
|
-
);
|
|
8371
|
-
}
|
|
8372
8156
|
static getPricePerLamport(tokenXDecimal, tokenYDecimal, price) {
|
|
8373
8157
|
return new (0, _decimaljs2.default)(price).mul(new (0, _decimaljs2.default)(10 ** (tokenYDecimal - tokenXDecimal))).toString();
|
|
8374
8158
|
}
|
|
@@ -8386,7 +8170,7 @@ var DLMM = class {
|
|
|
8386
8170
|
);
|
|
8387
8171
|
const program = new (0, _anchor.Program)(
|
|
8388
8172
|
IDL,
|
|
8389
|
-
_nullishCoalesce(_optionalChain([opt, 'optionalAccess',
|
|
8173
|
+
_nullishCoalesce(_optionalChain([opt, 'optionalAccess', _56 => _56.programId]), () => ( LBCLMM_PROGRAM_IDS[opt.cluster])),
|
|
8390
8174
|
provider
|
|
8391
8175
|
);
|
|
8392
8176
|
const [lbPair] = derivePermissionLbPair(
|
|
@@ -8435,7 +8219,7 @@ var DLMM = class {
|
|
|
8435
8219
|
);
|
|
8436
8220
|
const program = new (0, _anchor.Program)(
|
|
8437
8221
|
IDL,
|
|
8438
|
-
_nullishCoalesce(_optionalChain([opt, 'optionalAccess',
|
|
8222
|
+
_nullishCoalesce(_optionalChain([opt, 'optionalAccess', _57 => _57.programId]), () => ( LBCLMM_PROGRAM_IDS[opt.cluster])),
|
|
8439
8223
|
provider
|
|
8440
8224
|
);
|
|
8441
8225
|
const [lbPair] = deriveCustomizablePermissionlessLbPair(
|
|
@@ -8483,7 +8267,7 @@ var DLMM = class {
|
|
|
8483
8267
|
);
|
|
8484
8268
|
const program = new (0, _anchor.Program)(
|
|
8485
8269
|
IDL,
|
|
8486
|
-
_nullishCoalesce(_optionalChain([opt, 'optionalAccess',
|
|
8270
|
+
_nullishCoalesce(_optionalChain([opt, 'optionalAccess', _58 => _58.programId]), () => ( LBCLMM_PROGRAM_IDS[opt.cluster])),
|
|
8487
8271
|
provider
|
|
8488
8272
|
);
|
|
8489
8273
|
const existsPool = await this.getPairPubkeyIfExists(
|
|
@@ -8619,7 +8403,7 @@ var DLMM = class {
|
|
|
8619
8403
|
swapForY,
|
|
8620
8404
|
new (0, _anchor.BN)(activeIdToLoop),
|
|
8621
8405
|
this.lbPair,
|
|
8622
|
-
_nullishCoalesce(_optionalChain([this, 'access',
|
|
8406
|
+
_nullishCoalesce(_optionalChain([this, 'access', _59 => _59.binArrayBitmapExtension, 'optionalAccess', _60 => _60.account]), () => ( null))
|
|
8623
8407
|
);
|
|
8624
8408
|
if (binArrayIndex === null)
|
|
8625
8409
|
shouldStop = true;
|
|
@@ -8860,20 +8644,6 @@ var DLMM = class {
|
|
|
8860
8644
|
async getPositionsByUserAndLbPair(userPubKey) {
|
|
8861
8645
|
const promiseResults = await Promise.all([
|
|
8862
8646
|
this.getActiveBin(),
|
|
8863
|
-
userPubKey && this.program.account.position.all([
|
|
8864
|
-
{
|
|
8865
|
-
memcmp: {
|
|
8866
|
-
bytes: _bytes.bs58.encode(userPubKey.toBuffer()),
|
|
8867
|
-
offset: 8 + 32
|
|
8868
|
-
}
|
|
8869
|
-
},
|
|
8870
|
-
{
|
|
8871
|
-
memcmp: {
|
|
8872
|
-
bytes: _bytes.bs58.encode(this.pubkey.toBuffer()),
|
|
8873
|
-
offset: 8
|
|
8874
|
-
}
|
|
8875
|
-
}
|
|
8876
|
-
]),
|
|
8877
8647
|
userPubKey && this.program.account.positionV2.all([
|
|
8878
8648
|
{
|
|
8879
8649
|
memcmp: {
|
|
@@ -8889,7 +8659,7 @@ var DLMM = class {
|
|
|
8889
8659
|
}
|
|
8890
8660
|
])
|
|
8891
8661
|
]);
|
|
8892
|
-
const [activeBin,
|
|
8662
|
+
const [activeBin, positionsV2] = promiseResults;
|
|
8893
8663
|
if (!activeBin) {
|
|
8894
8664
|
throw new Error("Error fetching active bin");
|
|
8895
8665
|
}
|
|
@@ -8899,29 +8669,9 @@ var DLMM = class {
|
|
|
8899
8669
|
userPositions: []
|
|
8900
8670
|
};
|
|
8901
8671
|
}
|
|
8902
|
-
if (!
|
|
8672
|
+
if (!positionsV2) {
|
|
8903
8673
|
throw new Error("Error fetching positions");
|
|
8904
8674
|
}
|
|
8905
|
-
const binArrayPubkeySet = /* @__PURE__ */ new Set();
|
|
8906
|
-
positions.forEach(({ account: { upperBinId, lowerBinId } }) => {
|
|
8907
|
-
const lowerBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(lowerBinId));
|
|
8908
|
-
const upperBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(upperBinId));
|
|
8909
|
-
const [lowerBinArrayPubKey] = deriveBinArray(
|
|
8910
|
-
this.pubkey,
|
|
8911
|
-
lowerBinArrayIndex,
|
|
8912
|
-
this.program.programId
|
|
8913
|
-
);
|
|
8914
|
-
const [upperBinArrayPubKey] = deriveBinArray(
|
|
8915
|
-
this.pubkey,
|
|
8916
|
-
upperBinArrayIndex,
|
|
8917
|
-
this.program.programId
|
|
8918
|
-
);
|
|
8919
|
-
binArrayPubkeySet.add(lowerBinArrayPubKey.toBase58());
|
|
8920
|
-
binArrayPubkeySet.add(upperBinArrayPubKey.toBase58());
|
|
8921
|
-
});
|
|
8922
|
-
const binArrayPubkeyArray = Array.from(binArrayPubkeySet).map(
|
|
8923
|
-
(pubkey) => new (0, _web3js.PublicKey)(pubkey)
|
|
8924
|
-
);
|
|
8925
8675
|
const binArrayPubkeySetV2 = /* @__PURE__ */ new Set();
|
|
8926
8676
|
positionsV2.forEach(({ account: { upperBinId, lowerBinId, lbPair } }) => {
|
|
8927
8677
|
const lowerBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(lowerBinId));
|
|
@@ -8947,28 +8697,13 @@ var DLMM = class {
|
|
|
8947
8697
|
[
|
|
8948
8698
|
this.pubkey,
|
|
8949
8699
|
_web3js.SYSVAR_CLOCK_PUBKEY,
|
|
8950
|
-
...binArrayPubkeyArray,
|
|
8951
8700
|
...binArrayPubkeyArrayV2
|
|
8952
8701
|
]
|
|
8953
8702
|
);
|
|
8954
8703
|
const [lbPairAccInfo, clockAccInfo, ...binArraysAccInfo] = lbPairAndBinArrays;
|
|
8955
|
-
const positionBinArraysMap = /* @__PURE__ */ new Map();
|
|
8956
|
-
for (let i = 0; i < binArrayPubkeyArray.length; i++) {
|
|
8957
|
-
const binArrayPubkey = binArrayPubkeyArray[i];
|
|
8958
|
-
const binArrayAccBuffer = binArraysAccInfo[i];
|
|
8959
|
-
if (!binArrayAccBuffer)
|
|
8960
|
-
throw new Error(
|
|
8961
|
-
`Bin Array account ${binArrayPubkey.toBase58()} not found`
|
|
8962
|
-
);
|
|
8963
|
-
const binArrayAccInfo = this.program.coder.accounts.decode(
|
|
8964
|
-
"binArray",
|
|
8965
|
-
binArrayAccBuffer.data
|
|
8966
|
-
);
|
|
8967
|
-
positionBinArraysMap.set(binArrayPubkey.toBase58(), binArrayAccInfo);
|
|
8968
|
-
}
|
|
8969
8704
|
const positionBinArraysMapV2 = /* @__PURE__ */ new Map();
|
|
8970
|
-
for (let i =
|
|
8971
|
-
const binArrayPubkey = binArrayPubkeyArrayV2[i
|
|
8705
|
+
for (let i = 0; i < binArraysAccInfo.length; i++) {
|
|
8706
|
+
const binArrayPubkey = binArrayPubkeyArrayV2[i];
|
|
8972
8707
|
const binArrayAccBufferV2 = binArraysAccInfo[i];
|
|
8973
8708
|
if (!binArrayAccBufferV2)
|
|
8974
8709
|
throw new Error(
|
|
@@ -8985,45 +8720,6 @@ var DLMM = class {
|
|
|
8985
8720
|
const onChainTimestamp = new (0, _anchor.BN)(
|
|
8986
8721
|
clockAccInfo.data.readBigInt64LE(32).toString()
|
|
8987
8722
|
).toNumber();
|
|
8988
|
-
const userPositions = await Promise.all(
|
|
8989
|
-
positions.map(async ({ publicKey, account }) => {
|
|
8990
|
-
const { lowerBinId, upperBinId } = account;
|
|
8991
|
-
const lowerBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(lowerBinId));
|
|
8992
|
-
const upperBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(upperBinId));
|
|
8993
|
-
const [lowerBinArrayPubKey] = deriveBinArray(
|
|
8994
|
-
this.pubkey,
|
|
8995
|
-
lowerBinArrayIndex,
|
|
8996
|
-
this.program.programId
|
|
8997
|
-
);
|
|
8998
|
-
const [upperBinArrayPubKey] = deriveBinArray(
|
|
8999
|
-
this.pubkey,
|
|
9000
|
-
upperBinArrayIndex,
|
|
9001
|
-
this.program.programId
|
|
9002
|
-
);
|
|
9003
|
-
const lowerBinArray = positionBinArraysMap.get(
|
|
9004
|
-
lowerBinArrayPubKey.toBase58()
|
|
9005
|
-
);
|
|
9006
|
-
const upperBinArray = positionBinArraysMap.get(
|
|
9007
|
-
upperBinArrayPubKey.toBase58()
|
|
9008
|
-
);
|
|
9009
|
-
return {
|
|
9010
|
-
publicKey,
|
|
9011
|
-
positionData: await DLMM.processPosition(
|
|
9012
|
-
this.program,
|
|
9013
|
-
0 /* V1 */,
|
|
9014
|
-
this.lbPair,
|
|
9015
|
-
onChainTimestamp,
|
|
9016
|
-
account,
|
|
9017
|
-
this.tokenX.decimal,
|
|
9018
|
-
this.tokenY.decimal,
|
|
9019
|
-
lowerBinArray,
|
|
9020
|
-
upperBinArray,
|
|
9021
|
-
_web3js.PublicKey.default
|
|
9022
|
-
),
|
|
9023
|
-
version: 0 /* V1 */
|
|
9024
|
-
};
|
|
9025
|
-
})
|
|
9026
|
-
);
|
|
9027
8723
|
const userPositionsV2 = await Promise.all(
|
|
9028
8724
|
positionsV2.map(async ({ publicKey, account }) => {
|
|
9029
8725
|
const { lowerBinId, upperBinId, feeOwner } = account;
|
|
@@ -9065,7 +8761,7 @@ var DLMM = class {
|
|
|
9065
8761
|
);
|
|
9066
8762
|
return {
|
|
9067
8763
|
activeBin,
|
|
9068
|
-
userPositions:
|
|
8764
|
+
userPositions: userPositionsV2
|
|
9069
8765
|
};
|
|
9070
8766
|
}
|
|
9071
8767
|
async quoteCreatePosition({ strategy }) {
|
|
@@ -9121,6 +8817,72 @@ var DLMM = class {
|
|
|
9121
8817
|
feePayer: user
|
|
9122
8818
|
}).add(setComputeUnitLimitIx, createPositionIx, ...createBinArrayIxs);
|
|
9123
8819
|
}
|
|
8820
|
+
/**
|
|
8821
|
+
* The function `getPosition` retrieves position information for a given public key and processes it
|
|
8822
|
+
* using various data to return a `LbPosition` object.
|
|
8823
|
+
* @param {PublicKey} positionPubKey - The `getPosition` function you provided is an asynchronous
|
|
8824
|
+
* function that fetches position information based on a given public key. Here's a breakdown of the
|
|
8825
|
+
* parameters used in the function:
|
|
8826
|
+
* @returns The `getPosition` function returns a Promise that resolves to an object of type
|
|
8827
|
+
* `LbPosition`. The object contains the following properties:
|
|
8828
|
+
* - `publicKey`: The public key of the position account
|
|
8829
|
+
* - `positionData`: Position Object
|
|
8830
|
+
* - `version`: The version of the position (in this case, `Position.V2`)
|
|
8831
|
+
*/
|
|
8832
|
+
async getPosition(positionPubKey) {
|
|
8833
|
+
const positionAccountInfo = await this.program.account.positionV2.fetch(positionPubKey);
|
|
8834
|
+
if (!positionAccountInfo) {
|
|
8835
|
+
throw new Error(`Position account ${positionPubKey.toBase58()} not found`);
|
|
8836
|
+
}
|
|
8837
|
+
const { lowerBinId, upperBinId, feeOwner } = positionAccountInfo;
|
|
8838
|
+
const lowerBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(lowerBinId));
|
|
8839
|
+
const upperBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(upperBinId));
|
|
8840
|
+
const [lowerBinArrayPubKey] = deriveBinArray(
|
|
8841
|
+
this.pubkey,
|
|
8842
|
+
lowerBinArrayIndex,
|
|
8843
|
+
this.program.programId
|
|
8844
|
+
);
|
|
8845
|
+
const [upperBinArrayPubKey] = deriveBinArray(
|
|
8846
|
+
this.pubkey,
|
|
8847
|
+
upperBinArrayIndex,
|
|
8848
|
+
this.program.programId
|
|
8849
|
+
);
|
|
8850
|
+
const [clockAccInfo, lowerBinArrayAccInfo, upperBinArrayAccInfo] = await chunkedGetMultipleAccountInfos(
|
|
8851
|
+
this.program.provider.connection,
|
|
8852
|
+
[
|
|
8853
|
+
_web3js.SYSVAR_CLOCK_PUBKEY,
|
|
8854
|
+
lowerBinArrayPubKey,
|
|
8855
|
+
upperBinArrayPubKey
|
|
8856
|
+
]
|
|
8857
|
+
);
|
|
8858
|
+
const onChainTimestamp = new (0, _anchor.BN)(
|
|
8859
|
+
clockAccInfo.data.readBigInt64LE(32).toString()
|
|
8860
|
+
).toNumber();
|
|
8861
|
+
const lowerBinArray = this.program.coder.accounts.decode(
|
|
8862
|
+
"binArray",
|
|
8863
|
+
lowerBinArrayAccInfo.data
|
|
8864
|
+
);
|
|
8865
|
+
const upperBinArray = this.program.coder.accounts.decode(
|
|
8866
|
+
"binArray",
|
|
8867
|
+
upperBinArrayAccInfo.data
|
|
8868
|
+
);
|
|
8869
|
+
return {
|
|
8870
|
+
publicKey: positionPubKey,
|
|
8871
|
+
positionData: await DLMM.processPosition(
|
|
8872
|
+
this.program,
|
|
8873
|
+
1 /* V2 */,
|
|
8874
|
+
this.lbPair,
|
|
8875
|
+
onChainTimestamp,
|
|
8876
|
+
positionAccountInfo,
|
|
8877
|
+
this.tokenX.decimal,
|
|
8878
|
+
this.tokenY.decimal,
|
|
8879
|
+
lowerBinArray,
|
|
8880
|
+
upperBinArray,
|
|
8881
|
+
feeOwner
|
|
8882
|
+
),
|
|
8883
|
+
version: 1 /* V2 */
|
|
8884
|
+
};
|
|
8885
|
+
}
|
|
9124
8886
|
/**
|
|
9125
8887
|
* The function `initializePositionAndAddLiquidityByStrategy` function is used to initializes a position and adds liquidity
|
|
9126
8888
|
* @param {TInitializePositionAndAddLiquidityParamsByStrategy}
|
|
@@ -9799,9 +9561,40 @@ var DLMM = class {
|
|
|
9799
9561
|
bps,
|
|
9800
9562
|
shouldClaimAndClose = false
|
|
9801
9563
|
}) {
|
|
9802
|
-
const
|
|
9803
|
-
const
|
|
9804
|
-
const
|
|
9564
|
+
const lowerBinIdToRemove = Math.min(...binIds);
|
|
9565
|
+
const upperBinIdToRemove = Math.max(...binIds);
|
|
9566
|
+
const [lowerBinArrayPubKey] = deriveBinArray(this.pubkey, binIdToBinArrayIndex(new (0, _anchor.BN)(binIds[0])), this.program.programId);
|
|
9567
|
+
const [upperBinArrayPubKey] = deriveBinArray(this.pubkey, binIdToBinArrayIndex(new (0, _anchor.BN)(binIds[binIds.length - 1])), this.program.programId);
|
|
9568
|
+
const [positionAccInfo, lbPairAccInfo, upperBinArrayInfoAcc, lowerBinArrayInfoAcc] = await this.program.provider.connection.getMultipleAccountsInfo([
|
|
9569
|
+
position,
|
|
9570
|
+
this.pubkey,
|
|
9571
|
+
upperBinArrayPubKey,
|
|
9572
|
+
lowerBinArrayPubKey
|
|
9573
|
+
]);
|
|
9574
|
+
const { lbPair, owner, feeOwner, upperBinId: positionUpperBinId, lowerBinId: positionLowerBinId } = this.program.coder.accounts.decode(
|
|
9575
|
+
"positionV2",
|
|
9576
|
+
positionAccInfo.data
|
|
9577
|
+
);
|
|
9578
|
+
const { reserveX, reserveY, tokenXMint, tokenYMint } = this.program.coder.accounts.decode(
|
|
9579
|
+
"lbPair",
|
|
9580
|
+
lbPairAccInfo.data
|
|
9581
|
+
);
|
|
9582
|
+
const upperBinArray = this.program.coder.accounts.decode("binArray", upperBinArrayInfoAcc.data);
|
|
9583
|
+
const lowerBinArray = this.program.coder.accounts.decode("binArray", lowerBinArrayInfoAcc.data);
|
|
9584
|
+
const bins = await this.getBins(
|
|
9585
|
+
this.pubkey,
|
|
9586
|
+
positionLowerBinId,
|
|
9587
|
+
positionUpperBinId,
|
|
9588
|
+
this.tokenX.decimal,
|
|
9589
|
+
this.tokenY.decimal,
|
|
9590
|
+
lowerBinArray,
|
|
9591
|
+
upperBinArray
|
|
9592
|
+
);
|
|
9593
|
+
const positionHasNoLiquidity = bins.every(({ supply }) => supply.isZero());
|
|
9594
|
+
if (positionHasNoLiquidity) {
|
|
9595
|
+
throw new Error("No liquidity to remove");
|
|
9596
|
+
}
|
|
9597
|
+
const lowerBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(positionLowerBinId));
|
|
9805
9598
|
const upperBinArrayIndex = lowerBinArrayIndex.add(new (0, _anchor.BN)(1));
|
|
9806
9599
|
const [binArrayLower] = deriveBinArray(
|
|
9807
9600
|
lbPair,
|
|
@@ -9917,13 +9710,11 @@ var DLMM = class {
|
|
|
9917
9710
|
const closeWrappedSOLIx = await unwrapSOLInstruction(user);
|
|
9918
9711
|
closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
|
|
9919
9712
|
}
|
|
9920
|
-
const
|
|
9921
|
-
const
|
|
9922
|
-
const minBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(minBinId));
|
|
9923
|
-
const maxBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(maxBinId));
|
|
9713
|
+
const minBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(lowerBinIdToRemove));
|
|
9714
|
+
const maxBinArrayIndex = binIdToBinArrayIndex(new (0, _anchor.BN)(upperBinIdToRemove));
|
|
9924
9715
|
const useExtension = isOverflowDefaultBinArrayBitmap(minBinArrayIndex) || isOverflowDefaultBinArrayBitmap(maxBinArrayIndex);
|
|
9925
9716
|
const binArrayBitmapExtension = useExtension ? deriveBinArrayBitmapExtension(this.pubkey, this.program.programId)[0] : null;
|
|
9926
|
-
const removeLiquidityTx = await this.program.methods.removeLiquidityByRange(
|
|
9717
|
+
const removeLiquidityTx = await this.program.methods.removeLiquidityByRange(lowerBinIdToRemove, upperBinIdToRemove, bps.toNumber()).accounts({
|
|
9927
9718
|
position,
|
|
9928
9719
|
lbPair,
|
|
9929
9720
|
userTokenX,
|
|
@@ -10040,7 +9831,7 @@ var DLMM = class {
|
|
|
10040
9831
|
swapForY,
|
|
10041
9832
|
activeId,
|
|
10042
9833
|
this.lbPair,
|
|
10043
|
-
_nullishCoalesce(_optionalChain([this, 'access',
|
|
9834
|
+
_nullishCoalesce(_optionalChain([this, 'access', _61 => _61.binArrayBitmapExtension, 'optionalAccess', _62 => _62.account]), () => ( null)),
|
|
10044
9835
|
binArrays
|
|
10045
9836
|
);
|
|
10046
9837
|
if (binArrayAccountToSwap == null) {
|
|
@@ -10144,7 +9935,7 @@ var DLMM = class {
|
|
|
10144
9935
|
swapForY,
|
|
10145
9936
|
activeId,
|
|
10146
9937
|
this.lbPair,
|
|
10147
|
-
_nullishCoalesce(_optionalChain([this, 'access',
|
|
9938
|
+
_nullishCoalesce(_optionalChain([this, 'access', _63 => _63.binArrayBitmapExtension, 'optionalAccess', _64 => _64.account]), () => ( null)),
|
|
10148
9939
|
binArrays
|
|
10149
9940
|
);
|
|
10150
9941
|
if (binArrayAccountToSwap == null) {
|
|
@@ -11078,7 +10869,7 @@ var DLMM = class {
|
|
|
11078
10869
|
swapForY,
|
|
11079
10870
|
new (0, _anchor.BN)(activeBinId),
|
|
11080
10871
|
this.lbPair,
|
|
11081
|
-
_nullishCoalesce(_optionalChain([this, 'access',
|
|
10872
|
+
_nullishCoalesce(_optionalChain([this, 'access', _65 => _65.binArrayBitmapExtension, 'optionalAccess', _66 => _66.account]), () => ( null))
|
|
11082
10873
|
);
|
|
11083
10874
|
if (toBinArrayIndex === null)
|
|
11084
10875
|
return true;
|
|
@@ -11115,7 +10906,7 @@ var DLMM = class {
|
|
|
11115
10906
|
swapForY,
|
|
11116
10907
|
new (0, _anchor.BN)(activeBinId),
|
|
11117
10908
|
this.lbPair,
|
|
11118
|
-
_nullishCoalesce(_optionalChain([this, 'access',
|
|
10909
|
+
_nullishCoalesce(_optionalChain([this, 'access', _67 => _67.binArrayBitmapExtension, 'optionalAccess', _68 => _68.account]), () => ( null))
|
|
11119
10910
|
);
|
|
11120
10911
|
const accountsToFetch = [];
|
|
11121
10912
|
const [binArrayBitMapExtensionPubkey] = deriveBinArrayBitmapExtension(
|
|
@@ -11146,13 +10937,13 @@ var DLMM = class {
|
|
|
11146
10937
|
let fromBinArray = null;
|
|
11147
10938
|
let toBinArray = null;
|
|
11148
10939
|
let binArrayBitmapExtension = null;
|
|
11149
|
-
if (!!_optionalChain([binArrayAccounts, 'optionalAccess',
|
|
10940
|
+
if (!!_optionalChain([binArrayAccounts, 'optionalAccess', _69 => _69[0]])) {
|
|
11150
10941
|
binArrayBitmapExtension = binArrayBitMapExtensionPubkey;
|
|
11151
10942
|
}
|
|
11152
|
-
if (!!_optionalChain([binArrayAccounts, 'optionalAccess',
|
|
10943
|
+
if (!!_optionalChain([binArrayAccounts, 'optionalAccess', _70 => _70[1]])) {
|
|
11153
10944
|
fromBinArray = fromBinArrayPubkey;
|
|
11154
10945
|
}
|
|
11155
|
-
if (!!_optionalChain([binArrayAccounts, 'optionalAccess',
|
|
10946
|
+
if (!!_optionalChain([binArrayAccounts, 'optionalAccess', _71 => _71[2]]) && !!toBinArrayIndex) {
|
|
11156
10947
|
toBinArray = toBinArrayPubkey;
|
|
11157
10948
|
}
|
|
11158
10949
|
const { blockhash, lastValidBlockHeight } = await this.program.provider.connection.getLatestBlockhash("confirmed");
|
|
@@ -11477,12 +11268,7 @@ var DLMM = class {
|
|
|
11477
11268
|
let totalYAmount = new (0, _decimaljs2.default)(0);
|
|
11478
11269
|
bins.forEach((bin, idx) => {
|
|
11479
11270
|
const binSupply = new (0, _decimaljs2.default)(bin.supply.toString());
|
|
11480
|
-
|
|
11481
|
-
if (bin.version === 1 && version === 0 /* V1 */) {
|
|
11482
|
-
posShare = new (0, _decimaljs2.default)(posShares[idx].shln(64).toString());
|
|
11483
|
-
} else {
|
|
11484
|
-
posShare = new (0, _decimaljs2.default)(posShares[idx].toString());
|
|
11485
|
-
}
|
|
11271
|
+
const posShare = new (0, _decimaljs2.default)(posShares[idx].toString());
|
|
11486
11272
|
const positionXAmount = binSupply.eq(new (0, _decimaljs2.default)("0")) ? new (0, _decimaljs2.default)("0") : posShare.mul(bin.xAmount.toString()).div(binSupply);
|
|
11487
11273
|
const positionYAmount = binSupply.eq(new (0, _decimaljs2.default)("0")) ? new (0, _decimaljs2.default)("0") : posShare.mul(bin.yAmount.toString()).div(binSupply);
|
|
11488
11274
|
totalXAmount = totalXAmount.add(positionXAmount);
|