@meteora-ag/dlmm 1.3.1-sam.0 → 1.3.1
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 +19 -14
- package/dist/index.js +486 -138
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +472 -124
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -7975,14 +7975,49 @@ var DLMM = class {
|
|
|
7975
7975
|
opt?.programId ?? LBCLMM_PROGRAM_IDS[cluster],
|
|
7976
7976
|
provider
|
|
7977
7977
|
);
|
|
7978
|
-
const positionsV2 = await
|
|
7979
|
-
|
|
7980
|
-
|
|
7981
|
-
|
|
7982
|
-
|
|
7978
|
+
const [positions, positionsV2] = await Promise.all([
|
|
7979
|
+
program.account.position.all([
|
|
7980
|
+
{
|
|
7981
|
+
memcmp: {
|
|
7982
|
+
bytes: bs58.encode(userPubKey.toBuffer()),
|
|
7983
|
+
offset: 8 + 32
|
|
7984
|
+
}
|
|
7983
7985
|
}
|
|
7984
|
-
|
|
7986
|
+
]),
|
|
7987
|
+
program.account.positionV2.all([
|
|
7988
|
+
{
|
|
7989
|
+
memcmp: {
|
|
7990
|
+
bytes: bs58.encode(userPubKey.toBuffer()),
|
|
7991
|
+
offset: 8 + 32
|
|
7992
|
+
}
|
|
7993
|
+
}
|
|
7994
|
+
])
|
|
7985
7995
|
]);
|
|
7996
|
+
const binArrayPubkeySet = /* @__PURE__ */ new Set();
|
|
7997
|
+
const lbPairSet = /* @__PURE__ */ new Set();
|
|
7998
|
+
positions.forEach(({ account: { upperBinId, lowerBinId, lbPair } }) => {
|
|
7999
|
+
const lowerBinArrayIndex = binIdToBinArrayIndex(new BN9(lowerBinId));
|
|
8000
|
+
const upperBinArrayIndex = binIdToBinArrayIndex(new BN9(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 PublicKey6(pubkey)
|
|
8017
|
+
);
|
|
8018
|
+
const lbPairArray = Array.from(lbPairSet).map(
|
|
8019
|
+
(pubkey) => new PublicKey6(pubkey)
|
|
8020
|
+
);
|
|
7986
8021
|
const binArrayPubkeySetV2 = /* @__PURE__ */ new Set();
|
|
7987
8022
|
const lbPairSetV2 = /* @__PURE__ */ new Set();
|
|
7988
8023
|
positionsV2.forEach(({ account: { upperBinId, lowerBinId, lbPair } }) => {
|
|
@@ -8010,12 +8045,46 @@ var DLMM = class {
|
|
|
8010
8045
|
);
|
|
8011
8046
|
const [clockAccInfo, ...binArraysAccInfo] = await chunkedGetMultipleAccountInfos(connection, [
|
|
8012
8047
|
SYSVAR_CLOCK_PUBKEY,
|
|
8048
|
+
...binArrayPubkeyArray,
|
|
8049
|
+
...lbPairArray,
|
|
8013
8050
|
...binArrayPubkeyArrayV2,
|
|
8014
8051
|
...lbPairArrayV2
|
|
8015
8052
|
]);
|
|
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();
|
|
8016
8085
|
const positionBinArraysMapV2 = /* @__PURE__ */ new Map();
|
|
8017
|
-
for (let i =
|
|
8018
|
-
const binArrayPubkey = binArrayPubkeyArrayV2[i];
|
|
8086
|
+
for (let i = binArrayPubkeyArray.length + lbPairArray.length; i < binArrayPubkeyArray.length + lbPairArray.length + binArrayPubkeyArrayV2.length; i++) {
|
|
8087
|
+
const binArrayPubkey = binArrayPubkeyArrayV2[i - (binArrayPubkeyArray.length + lbPairArray.length)];
|
|
8019
8088
|
const binArrayAccInfoBufferV2 = binArraysAccInfo[i];
|
|
8020
8089
|
if (!binArrayAccInfoBufferV2)
|
|
8021
8090
|
throw new Error(
|
|
@@ -8028,8 +8097,8 @@ var DLMM = class {
|
|
|
8028
8097
|
positionBinArraysMapV2.set(binArrayPubkey.toBase58(), binArrayAccInfo);
|
|
8029
8098
|
}
|
|
8030
8099
|
const lbPairArraysMapV2 = /* @__PURE__ */ new Map();
|
|
8031
|
-
for (let i = binArrayPubkeyArrayV2.length; i < binArraysAccInfo.length; i++) {
|
|
8032
|
-
const lbPairPubkey = lbPairArrayV2[i - binArrayPubkeyArrayV2.length];
|
|
8100
|
+
for (let i = binArrayPubkeyArray.length + lbPairArray.length + binArrayPubkeyArrayV2.length; i < binArraysAccInfo.length; i++) {
|
|
8101
|
+
const lbPairPubkey = lbPairArrayV2[i - (binArrayPubkeyArray.length + lbPairArray.length + binArrayPubkeyArrayV2.length)];
|
|
8033
8102
|
const lbPairAccInfoBufferV2 = binArraysAccInfo[i];
|
|
8034
8103
|
if (!lbPairAccInfoBufferV2)
|
|
8035
8104
|
throw new Error(`LB Pair account ${lbPairPubkey.toBase58()} not found`);
|
|
@@ -8047,14 +8116,43 @@ var DLMM = class {
|
|
|
8047
8116
|
]).flat();
|
|
8048
8117
|
const reserveAccountsInfo = await chunkedGetMultipleAccountInfos(
|
|
8049
8118
|
program.provider.connection,
|
|
8050
|
-
reservePublicKeysV2
|
|
8119
|
+
[...reservePublicKeys, ...reservePublicKeysV2]
|
|
8051
8120
|
);
|
|
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 = AccountLayout.decode(reserveAccBufferX.data);
|
|
8132
|
+
const reserveAccY = 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 = MintLayout.decode(mintXBuffer.data);
|
|
8144
|
+
const mintY = MintLayout.decode(mintYBuffer.data);
|
|
8145
|
+
lbPairMintMap.set(lbPair.toBase58(), {
|
|
8146
|
+
mintXDecimal: mintX.decimals,
|
|
8147
|
+
mintYDecimal: mintY.decimals
|
|
8148
|
+
});
|
|
8149
|
+
});
|
|
8052
8150
|
const lbPairReserveMapV2 = /* @__PURE__ */ new Map();
|
|
8053
8151
|
const lbPairMintMapV2 = /* @__PURE__ */ new Map();
|
|
8054
8152
|
lbPairArrayV2.forEach((lbPair, idx) => {
|
|
8055
8153
|
const index = idx * 4;
|
|
8056
|
-
const reserveAccBufferXV2 = reserveAccountsInfo[index];
|
|
8057
|
-
const reserveAccBufferYV2 = reserveAccountsInfo[index + 1];
|
|
8154
|
+
const reserveAccBufferXV2 = reserveAccountsInfo[reservePublicKeys.length + index];
|
|
8155
|
+
const reserveAccBufferYV2 = reserveAccountsInfo[reservePublicKeys.length + index + 1];
|
|
8058
8156
|
if (!reserveAccBufferXV2 || !reserveAccBufferYV2)
|
|
8059
8157
|
throw new Error(
|
|
8060
8158
|
`Reserve account for LB Pair ${lbPair.toBase58()} not found`
|
|
@@ -8065,8 +8163,8 @@ var DLMM = class {
|
|
|
8065
8163
|
reserveX: reserveAccX.amount,
|
|
8066
8164
|
reserveY: reserveAccY.amount
|
|
8067
8165
|
});
|
|
8068
|
-
const mintXBufferV2 = reserveAccountsInfo[index + 2];
|
|
8069
|
-
const mintYBufferV2 = reserveAccountsInfo[index + 3];
|
|
8166
|
+
const mintXBufferV2 = reserveAccountsInfo[reservePublicKeys.length + index + 2];
|
|
8167
|
+
const mintYBufferV2 = reserveAccountsInfo[reservePublicKeys.length + index + 3];
|
|
8070
8168
|
if (!mintXBufferV2 || !mintYBufferV2)
|
|
8071
8169
|
throw new Error(
|
|
8072
8170
|
`Mint account for LB Pair ${lbPair.toBase58()} not found`
|
|
@@ -8082,6 +8180,74 @@ var DLMM = class {
|
|
|
8082
8180
|
clockAccInfo.data.readBigInt64LE(32).toString()
|
|
8083
8181
|
).toNumber();
|
|
8084
8182
|
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 BN9(lowerBinId));
|
|
8187
|
+
const upperBinArrayIndex = binIdToBinArrayIndex(new BN9(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 = lbPairReserveMap.get(lbPair.toBase58())?.reserveX ?? BigInt(0);
|
|
8209
|
+
const reserveYBalance = lbPairReserveMap.get(lbPair.toBase58())?.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
|
+
PublicKey6.default
|
|
8233
|
+
);
|
|
8234
|
+
if (positionData) {
|
|
8235
|
+
positionsMap.set(lbPair.toBase58(), {
|
|
8236
|
+
publicKey: lbPair,
|
|
8237
|
+
lbPair: lbPairAcc,
|
|
8238
|
+
tokenX,
|
|
8239
|
+
tokenY,
|
|
8240
|
+
lbPairPositionsData: [
|
|
8241
|
+
...positionsMap.get(lbPair.toBase58())?.lbPairPositionsData ?? [],
|
|
8242
|
+
{
|
|
8243
|
+
publicKey: positionPubKey,
|
|
8244
|
+
positionData,
|
|
8245
|
+
version: 0 /* V1 */
|
|
8246
|
+
}
|
|
8247
|
+
]
|
|
8248
|
+
});
|
|
8249
|
+
}
|
|
8250
|
+
}
|
|
8085
8251
|
for (let position of positionsV2) {
|
|
8086
8252
|
const { account, publicKey: positionPubKey } = position;
|
|
8087
8253
|
const { upperBinId, lowerBinId, lbPair, feeOwner } = account;
|
|
@@ -8153,6 +8319,56 @@ var DLMM = class {
|
|
|
8153
8319
|
}
|
|
8154
8320
|
return positionsMap;
|
|
8155
8321
|
}
|
|
8322
|
+
static async migratePosition(connection, positions, newPositions, walletPubkey, opt) {
|
|
8323
|
+
const cluster = opt?.cluster || "mainnet-beta";
|
|
8324
|
+
const provider = new AnchorProvider2(
|
|
8325
|
+
connection,
|
|
8326
|
+
{},
|
|
8327
|
+
AnchorProvider2.defaultOptions()
|
|
8328
|
+
);
|
|
8329
|
+
const program = new Program2(
|
|
8330
|
+
IDL,
|
|
8331
|
+
opt?.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 BN9(lowerBinId));
|
|
8342
|
+
const upperBinArrayIndex = lowerBinArrayIndex.add(new BN9(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: SystemProgram2.programId
|
|
8363
|
+
}).transaction();
|
|
8364
|
+
return new Transaction({
|
|
8365
|
+
blockhash,
|
|
8366
|
+
lastValidBlockHeight,
|
|
8367
|
+
feePayer: walletPubkey
|
|
8368
|
+
}).add(migrateTx);
|
|
8369
|
+
})
|
|
8370
|
+
);
|
|
8371
|
+
}
|
|
8156
8372
|
static getPricePerLamport(tokenXDecimal, tokenYDecimal, price) {
|
|
8157
8373
|
return new Decimal4(price).mul(new Decimal4(10 ** (tokenYDecimal - tokenXDecimal))).toString();
|
|
8158
8374
|
}
|
|
@@ -8644,6 +8860,20 @@ var DLMM = class {
|
|
|
8644
8860
|
async getPositionsByUserAndLbPair(userPubKey) {
|
|
8645
8861
|
const promiseResults = await Promise.all([
|
|
8646
8862
|
this.getActiveBin(),
|
|
8863
|
+
userPubKey && this.program.account.position.all([
|
|
8864
|
+
{
|
|
8865
|
+
memcmp: {
|
|
8866
|
+
bytes: bs58.encode(userPubKey.toBuffer()),
|
|
8867
|
+
offset: 8 + 32
|
|
8868
|
+
}
|
|
8869
|
+
},
|
|
8870
|
+
{
|
|
8871
|
+
memcmp: {
|
|
8872
|
+
bytes: bs58.encode(this.pubkey.toBuffer()),
|
|
8873
|
+
offset: 8
|
|
8874
|
+
}
|
|
8875
|
+
}
|
|
8876
|
+
]),
|
|
8647
8877
|
userPubKey && this.program.account.positionV2.all([
|
|
8648
8878
|
{
|
|
8649
8879
|
memcmp: {
|
|
@@ -8659,7 +8889,7 @@ var DLMM = class {
|
|
|
8659
8889
|
}
|
|
8660
8890
|
])
|
|
8661
8891
|
]);
|
|
8662
|
-
const [activeBin, positionsV2] = promiseResults;
|
|
8892
|
+
const [activeBin, positions, positionsV2] = promiseResults;
|
|
8663
8893
|
if (!activeBin) {
|
|
8664
8894
|
throw new Error("Error fetching active bin");
|
|
8665
8895
|
}
|
|
@@ -8669,9 +8899,29 @@ var DLMM = class {
|
|
|
8669
8899
|
userPositions: []
|
|
8670
8900
|
};
|
|
8671
8901
|
}
|
|
8672
|
-
if (!positionsV2) {
|
|
8902
|
+
if (!positions || !positionsV2) {
|
|
8673
8903
|
throw new Error("Error fetching positions");
|
|
8674
8904
|
}
|
|
8905
|
+
const binArrayPubkeySet = /* @__PURE__ */ new Set();
|
|
8906
|
+
positions.forEach(({ account: { upperBinId, lowerBinId } }) => {
|
|
8907
|
+
const lowerBinArrayIndex = binIdToBinArrayIndex(new BN9(lowerBinId));
|
|
8908
|
+
const upperBinArrayIndex = binIdToBinArrayIndex(new BN9(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 PublicKey6(pubkey)
|
|
8924
|
+
);
|
|
8675
8925
|
const binArrayPubkeySetV2 = /* @__PURE__ */ new Set();
|
|
8676
8926
|
positionsV2.forEach(({ account: { upperBinId, lowerBinId, lbPair } }) => {
|
|
8677
8927
|
const lowerBinArrayIndex = binIdToBinArrayIndex(new BN9(lowerBinId));
|
|
@@ -8697,13 +8947,28 @@ var DLMM = class {
|
|
|
8697
8947
|
[
|
|
8698
8948
|
this.pubkey,
|
|
8699
8949
|
SYSVAR_CLOCK_PUBKEY,
|
|
8950
|
+
...binArrayPubkeyArray,
|
|
8700
8951
|
...binArrayPubkeyArrayV2
|
|
8701
8952
|
]
|
|
8702
8953
|
);
|
|
8703
8954
|
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
|
+
}
|
|
8704
8969
|
const positionBinArraysMapV2 = /* @__PURE__ */ new Map();
|
|
8705
|
-
for (let i =
|
|
8706
|
-
const binArrayPubkey = binArrayPubkeyArrayV2[i];
|
|
8970
|
+
for (let i = binArrayPubkeyArray.length; i < binArraysAccInfo.length; i++) {
|
|
8971
|
+
const binArrayPubkey = binArrayPubkeyArrayV2[i - binArrayPubkeyArray.length];
|
|
8707
8972
|
const binArrayAccBufferV2 = binArraysAccInfo[i];
|
|
8708
8973
|
if (!binArrayAccBufferV2)
|
|
8709
8974
|
throw new Error(
|
|
@@ -8720,6 +8985,45 @@ var DLMM = class {
|
|
|
8720
8985
|
const onChainTimestamp = new BN9(
|
|
8721
8986
|
clockAccInfo.data.readBigInt64LE(32).toString()
|
|
8722
8987
|
).toNumber();
|
|
8988
|
+
const userPositions = await Promise.all(
|
|
8989
|
+
positions.map(async ({ publicKey, account }) => {
|
|
8990
|
+
const { lowerBinId, upperBinId } = account;
|
|
8991
|
+
const lowerBinArrayIndex = binIdToBinArrayIndex(new BN9(lowerBinId));
|
|
8992
|
+
const upperBinArrayIndex = binIdToBinArrayIndex(new BN9(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
|
+
PublicKey6.default
|
|
9022
|
+
),
|
|
9023
|
+
version: 0 /* V1 */
|
|
9024
|
+
};
|
|
9025
|
+
})
|
|
9026
|
+
);
|
|
8723
9027
|
const userPositionsV2 = await Promise.all(
|
|
8724
9028
|
positionsV2.map(async ({ publicKey, account }) => {
|
|
8725
9029
|
const { lowerBinId, upperBinId, feeOwner } = account;
|
|
@@ -8761,7 +9065,7 @@ var DLMM = class {
|
|
|
8761
9065
|
);
|
|
8762
9066
|
return {
|
|
8763
9067
|
activeBin,
|
|
8764
|
-
userPositions: userPositionsV2
|
|
9068
|
+
userPositions: [...userPositions, ...userPositionsV2]
|
|
8765
9069
|
};
|
|
8766
9070
|
}
|
|
8767
9071
|
async quoteCreatePosition({ strategy }) {
|
|
@@ -8817,72 +9121,6 @@ var DLMM = class {
|
|
|
8817
9121
|
feePayer: user
|
|
8818
9122
|
}).add(setComputeUnitLimitIx, createPositionIx, ...createBinArrayIxs);
|
|
8819
9123
|
}
|
|
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 BN9(lowerBinId));
|
|
8839
|
-
const upperBinArrayIndex = binIdToBinArrayIndex(new BN9(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
|
-
SYSVAR_CLOCK_PUBKEY,
|
|
8854
|
-
lowerBinArrayPubKey,
|
|
8855
|
-
upperBinArrayPubKey
|
|
8856
|
-
]
|
|
8857
|
-
);
|
|
8858
|
-
const onChainTimestamp = new BN9(
|
|
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
|
-
}
|
|
8886
9124
|
/**
|
|
8887
9125
|
* The function `initializePositionAndAddLiquidityByStrategy` function is used to initializes a position and adds liquidity
|
|
8888
9126
|
* @param {TInitializePositionAndAddLiquidityParamsByStrategy}
|
|
@@ -9561,40 +9799,9 @@ var DLMM = class {
|
|
|
9561
9799
|
bps,
|
|
9562
9800
|
shouldClaimAndClose = false
|
|
9563
9801
|
}) {
|
|
9564
|
-
const
|
|
9565
|
-
const
|
|
9566
|
-
const
|
|
9567
|
-
const [upperBinArrayPubKey] = deriveBinArray(this.pubkey, binIdToBinArrayIndex(new BN9(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 BN9(positionLowerBinId));
|
|
9802
|
+
const { lbPair, lowerBinId, owner, feeOwner } = await this.program.account.positionV2.fetch(position);
|
|
9803
|
+
const { reserveX, reserveY, tokenXMint, tokenYMint } = await this.program.account.lbPair.fetch(lbPair);
|
|
9804
|
+
const lowerBinArrayIndex = binIdToBinArrayIndex(new BN9(lowerBinId));
|
|
9598
9805
|
const upperBinArrayIndex = lowerBinArrayIndex.add(new BN9(1));
|
|
9599
9806
|
const [binArrayLower] = deriveBinArray(
|
|
9600
9807
|
lbPair,
|
|
@@ -9710,11 +9917,13 @@ var DLMM = class {
|
|
|
9710
9917
|
const closeWrappedSOLIx = await unwrapSOLInstruction(user);
|
|
9711
9918
|
closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
|
|
9712
9919
|
}
|
|
9713
|
-
const
|
|
9714
|
-
const
|
|
9920
|
+
const minBinId = Math.min(...binIds);
|
|
9921
|
+
const maxBinId = Math.max(...binIds);
|
|
9922
|
+
const minBinArrayIndex = binIdToBinArrayIndex(new BN9(minBinId));
|
|
9923
|
+
const maxBinArrayIndex = binIdToBinArrayIndex(new BN9(maxBinId));
|
|
9715
9924
|
const useExtension = isOverflowDefaultBinArrayBitmap(minBinArrayIndex) || isOverflowDefaultBinArrayBitmap(maxBinArrayIndex);
|
|
9716
9925
|
const binArrayBitmapExtension = useExtension ? deriveBinArrayBitmapExtension(this.pubkey, this.program.programId)[0] : null;
|
|
9717
|
-
const removeLiquidityTx = await this.program.methods.removeLiquidityByRange(
|
|
9926
|
+
const removeLiquidityTx = await this.program.methods.removeLiquidityByRange(minBinId, maxBinId, bps.toNumber()).accounts({
|
|
9718
9927
|
position,
|
|
9719
9928
|
lbPair,
|
|
9720
9929
|
userTokenX,
|
|
@@ -10660,6 +10869,140 @@ var DLMM = class {
|
|
|
10660
10869
|
addLiquidityIxs
|
|
10661
10870
|
};
|
|
10662
10871
|
}
|
|
10872
|
+
/**
|
|
10873
|
+
* The `seedLiquidity` function create multiple grouped instructions. The grouped instructions will be either [initialize bin array + initialize position instructions] or [deposit instruction] combination.
|
|
10874
|
+
* @param
|
|
10875
|
+
* - `owner`: The public key of the positions owner.
|
|
10876
|
+
* - `base`: Base key
|
|
10877
|
+
* - `seedAmount`: Token X lamport amount to be seeded to the pool.
|
|
10878
|
+
* - `price`: TokenX/TokenY Price in UI format
|
|
10879
|
+
* - `roundingUp`: Whether to round up the price
|
|
10880
|
+
* - `feeOwner`: Position fee owner
|
|
10881
|
+
* - `operator`: Operator of the position. Operator able to manage the position on behalf of the position owner. However, liquidity withdrawal issue by the operator can only send to the position owner.
|
|
10882
|
+
* - `lockReleasePoint`: The lock release point of the position.
|
|
10883
|
+
*
|
|
10884
|
+
* The returned instructions need to be executed sequentially if it was separated into multiple transactions.
|
|
10885
|
+
* @returns {Promise<TransactionInstruction[]>}
|
|
10886
|
+
*/
|
|
10887
|
+
async seedLiquiditySingleBin(owner, base, seedAmount, price, roundingUp, feeOwner, operator, lockReleasePoint) {
|
|
10888
|
+
const pricePerLamport = DLMM.getPricePerLamport(this.tokenX.decimal, this.tokenY.decimal, price);
|
|
10889
|
+
const binIdNumber = DLMM.getBinIdFromPrice(pricePerLamport, this.lbPair.binStep, !roundingUp);
|
|
10890
|
+
const binId = new BN9(binIdNumber);
|
|
10891
|
+
const lowerBinArrayIndex = binIdToBinArrayIndex(binId);
|
|
10892
|
+
const upperBinArrayIndex = lowerBinArrayIndex.add(new BN9(1));
|
|
10893
|
+
const [lowerBinArray] = deriveBinArray(this.pubkey, lowerBinArrayIndex, this.program.programId);
|
|
10894
|
+
const [upperBinArray] = deriveBinArray(this.pubkey, upperBinArrayIndex, this.program.programId);
|
|
10895
|
+
const [positionPda] = derivePosition(this.pubkey, base, binId, new BN9(1), this.program.programId);
|
|
10896
|
+
const operatorTokenX = getAssociatedTokenAddressSync2(
|
|
10897
|
+
this.lbPair.tokenXMint,
|
|
10898
|
+
operator,
|
|
10899
|
+
true
|
|
10900
|
+
);
|
|
10901
|
+
const ownerTokenX = getAssociatedTokenAddressSync2(
|
|
10902
|
+
this.lbPair.tokenXMint,
|
|
10903
|
+
owner,
|
|
10904
|
+
true
|
|
10905
|
+
);
|
|
10906
|
+
const preInstructions = [];
|
|
10907
|
+
const [
|
|
10908
|
+
{ ataPubKey: userTokenX, ix: createPayerTokenXIx },
|
|
10909
|
+
{ ataPubKey: userTokenY, ix: createPayerTokenYIx }
|
|
10910
|
+
] = await Promise.all([
|
|
10911
|
+
getOrCreateATAInstruction(
|
|
10912
|
+
this.program.provider.connection,
|
|
10913
|
+
this.tokenX.publicKey,
|
|
10914
|
+
owner
|
|
10915
|
+
),
|
|
10916
|
+
getOrCreateATAInstruction(
|
|
10917
|
+
this.program.provider.connection,
|
|
10918
|
+
this.tokenY.publicKey,
|
|
10919
|
+
owner
|
|
10920
|
+
)
|
|
10921
|
+
]);
|
|
10922
|
+
createPayerTokenXIx && preInstructions.push(createPayerTokenXIx);
|
|
10923
|
+
createPayerTokenYIx && preInstructions.push(createPayerTokenYIx);
|
|
10924
|
+
let [binArrayBitmapExtension] = deriveBinArrayBitmapExtension(this.pubkey, this.program.programId);
|
|
10925
|
+
const accounts = await this.program.provider.connection.getMultipleAccountsInfo([
|
|
10926
|
+
lowerBinArray,
|
|
10927
|
+
upperBinArray,
|
|
10928
|
+
positionPda,
|
|
10929
|
+
binArrayBitmapExtension
|
|
10930
|
+
]);
|
|
10931
|
+
if (isOverflowDefaultBinArrayBitmap(lowerBinArrayIndex)) {
|
|
10932
|
+
const bitmapExtensionAccount = accounts[3];
|
|
10933
|
+
if (!bitmapExtensionAccount) {
|
|
10934
|
+
preInstructions.push(await this.program.methods.initializeBinArrayBitmapExtension().accounts({
|
|
10935
|
+
binArrayBitmapExtension,
|
|
10936
|
+
funder: owner,
|
|
10937
|
+
lbPair: this.pubkey
|
|
10938
|
+
}).instruction());
|
|
10939
|
+
}
|
|
10940
|
+
} else {
|
|
10941
|
+
binArrayBitmapExtension = this.program.programId;
|
|
10942
|
+
}
|
|
10943
|
+
const lowerBinArrayAccount = accounts[0];
|
|
10944
|
+
const upperBinArrayAccount = accounts[1];
|
|
10945
|
+
const positionAccount = accounts[2];
|
|
10946
|
+
if (!lowerBinArrayAccount) {
|
|
10947
|
+
preInstructions.push(
|
|
10948
|
+
await this.program.methods.initializeBinArray(lowerBinArrayIndex).accounts({
|
|
10949
|
+
binArray: lowerBinArray,
|
|
10950
|
+
funder: owner,
|
|
10951
|
+
lbPair: this.pubkey
|
|
10952
|
+
}).instruction()
|
|
10953
|
+
);
|
|
10954
|
+
}
|
|
10955
|
+
if (!upperBinArrayAccount) {
|
|
10956
|
+
preInstructions.push(
|
|
10957
|
+
await this.program.methods.initializeBinArray(upperBinArrayIndex).accounts({
|
|
10958
|
+
binArray: upperBinArray,
|
|
10959
|
+
funder: owner,
|
|
10960
|
+
lbPair: this.pubkey
|
|
10961
|
+
}).instruction()
|
|
10962
|
+
);
|
|
10963
|
+
}
|
|
10964
|
+
if (!positionAccount) {
|
|
10965
|
+
preInstructions.push(
|
|
10966
|
+
await this.program.methods.initializePositionByOperator(binId.toNumber(), 1, feeOwner, lockReleasePoint).accounts({
|
|
10967
|
+
payer: owner,
|
|
10968
|
+
base,
|
|
10969
|
+
position: positionPda,
|
|
10970
|
+
lbPair: this.pubkey,
|
|
10971
|
+
owner,
|
|
10972
|
+
operator,
|
|
10973
|
+
operatorTokenX,
|
|
10974
|
+
ownerTokenX
|
|
10975
|
+
}).instruction()
|
|
10976
|
+
);
|
|
10977
|
+
}
|
|
10978
|
+
const binLiquidityDist = {
|
|
10979
|
+
binId: binIdNumber,
|
|
10980
|
+
distributionX: BASIS_POINT_MAX,
|
|
10981
|
+
distributionY: 0
|
|
10982
|
+
};
|
|
10983
|
+
const addLiquidityParams = {
|
|
10984
|
+
amountX: seedAmount,
|
|
10985
|
+
amountY: new BN9(0),
|
|
10986
|
+
binLiquidityDist: [binLiquidityDist]
|
|
10987
|
+
};
|
|
10988
|
+
const depositLiquidityIx = await this.program.methods.addLiquidity(addLiquidityParams).accounts({
|
|
10989
|
+
position: positionPda,
|
|
10990
|
+
lbPair: this.pubkey,
|
|
10991
|
+
binArrayBitmapExtension,
|
|
10992
|
+
userTokenX,
|
|
10993
|
+
userTokenY,
|
|
10994
|
+
reserveX: this.lbPair.reserveX,
|
|
10995
|
+
reserveY: this.lbPair.reserveY,
|
|
10996
|
+
tokenXMint: this.lbPair.tokenXMint,
|
|
10997
|
+
tokenYMint: this.lbPair.tokenYMint,
|
|
10998
|
+
binArrayLower: lowerBinArray,
|
|
10999
|
+
binArrayUpper: upperBinArray,
|
|
11000
|
+
sender: owner,
|
|
11001
|
+
tokenXProgram: TOKEN_PROGRAM_ID2,
|
|
11002
|
+
tokenYProgram: TOKEN_PROGRAM_ID2
|
|
11003
|
+
}).instruction();
|
|
11004
|
+
return [...preInstructions, depositLiquidityIx];
|
|
11005
|
+
}
|
|
10663
11006
|
/**
|
|
10664
11007
|
* Initializes bin arrays for the given bin array indexes if it wasn't initialized.
|
|
10665
11008
|
*
|
|
@@ -11268,7 +11611,12 @@ var DLMM = class {
|
|
|
11268
11611
|
let totalYAmount = new Decimal4(0);
|
|
11269
11612
|
bins.forEach((bin, idx) => {
|
|
11270
11613
|
const binSupply = new Decimal4(bin.supply.toString());
|
|
11271
|
-
|
|
11614
|
+
let posShare;
|
|
11615
|
+
if (bin.version === 1 && version === 0 /* V1 */) {
|
|
11616
|
+
posShare = new Decimal4(posShares[idx].shln(64).toString());
|
|
11617
|
+
} else {
|
|
11618
|
+
posShare = new Decimal4(posShares[idx].toString());
|
|
11619
|
+
}
|
|
11272
11620
|
const positionXAmount = binSupply.eq(new Decimal4("0")) ? new Decimal4("0") : posShare.mul(bin.xAmount.toString()).div(binSupply);
|
|
11273
11621
|
const positionYAmount = binSupply.eq(new Decimal4("0")) ? new Decimal4("0") : posShare.mul(bin.yAmount.toString()).div(binSupply);
|
|
11274
11622
|
totalXAmount = totalXAmount.add(positionXAmount);
|