From 22ed8f2385523b5a369be239a86ca400fcfc25a3 Mon Sep 17 00:00:00 2001 From: microwavedcola1 <89031858+microwavedcola1@users.noreply.github.com> Date: Fri, 13 Jan 2023 11:23:37 +0100 Subject: [PATCH] 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 * Fix bug in building health accounts Signed-off-by: microwavedcola1 Signed-off-by: microwavedcola1 Co-authored-by: tjs --- ts/client/src/client.ts | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/ts/client/src/client.ts b/ts/client/src/client.ts index 4d8d067ca..432216186 100644 --- a/ts/client/src/client.ts +++ b/ts/client/src/client.ts @@ -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; } } }