Ts client temp merge into dev (#386)

* fix buildHealthRemainingAccounts to not modify the mangoAccount obj

* Fix bug where health accounts were not packed correctly

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>

* Fix bug in building health accounts

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
Co-authored-by: tjs <tjshipe@gmail.com>
This commit is contained in:
microwavedcola1 2023-01-13 11:23:37 +01:00 committed by GitHub
parent 70616f74dd
commit 22ed8f2385
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 14 deletions

View File

@ -58,7 +58,7 @@ import {
} from './utils';
import { sendTransaction } from './utils/rpc';
enum AccountRetriever {
export enum AccountRetriever {
Scanning,
Fixed,
}
@ -2583,9 +2583,7 @@ export class MangoClient {
);
}
/// private
private buildHealthRemainingAccounts(
public buildHealthRemainingAccounts(
retriever: AccountRetriever,
group: Group,
mangoAccounts: MangoAccount[],
@ -2625,12 +2623,12 @@ export class MangoClient {
const tokenPositionIndices = mangoAccount.tokens.map((t) => t.tokenIndex);
for (const bank of banks) {
const tokenPositionExists =
tokenPositionIndices.indexOf(bank.tokenIndex) > 0;
tokenPositionIndices.indexOf(bank.tokenIndex) > -1;
if (!tokenPositionExists) {
const inactiveTokenPosition = tokenPositionIndices.findIndex(
(index) => index === TokenPosition.TokenIndexUnset,
);
if (inactiveTokenPosition) {
if (inactiveTokenPosition != -1) {
tokenPositionIndices[inactiveTokenPosition] = bank.tokenIndex;
}
}
@ -2650,12 +2648,12 @@ export class MangoClient {
const perpPositionIndices = mangoAccount.perps.map((p) => p.marketIndex);
for (const perpMarket of perpMarkets) {
const perpPositionExists =
perpPositionIndices.indexOf(perpMarket.perpMarketIndex) > 0;
perpPositionIndices.indexOf(perpMarket.perpMarketIndex) > -1;
if (!perpPositionExists) {
const inactivePerpPosition = perpPositionIndices.find(
const inactivePerpPosition = perpPositionIndices.findIndex(
(perpIdx) => perpIdx === PerpPosition.PerpMarketIndexUnset,
);
if (inactivePerpPosition) {
if (inactivePerpPosition != -1) {
perpPositionIndices[inactivePerpPosition] =
perpMarket.perpMarketIndex;
}
@ -2679,15 +2677,16 @@ export class MangoClient {
const ooPositionExists =
serumPositionIndices.findIndex(
(i) => i.marketIndex === serum3Market.marketIndex,
) > 0;
) > -1;
if (!ooPositionExists) {
const inactiveSerumPosition = serumPositionIndices.find(
const inactiveSerumPosition = serumPositionIndices.findIndex(
(serumPos) =>
serumPos.marketIndex === Serum3Orders.Serum3MarketIndexUnset,
);
if (inactiveSerumPosition) {
inactiveSerumPosition.marketIndex = serum3Market.marketIndex;
inactiveSerumPosition.openOrders = openOrderPk;
if (inactiveSerumPosition != -1) {
serumPositionIndices[inactiveSerumPosition].marketIndex =
serum3Market.marketIndex;
serumPositionIndices[inactiveSerumPosition].openOrders = openOrderPk;
}
}
}