@nadohq/engine-client 0.1.0-alpha.38 → 0.1.0-alpha.39

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.
@@ -25,6 +25,7 @@ import {
25
25
  EngineServerPriceTickLiquidity,
26
26
  EngineServerSpotProduct,
27
27
  EngineServerSubaccountInfoResponse,
28
+ EngineServerSubaccountInfoState,
28
29
  EngineServerSymbol,
29
30
  EngineServerSymbolsResponse,
30
31
  EngineSymbol,
@@ -33,6 +34,7 @@ import {
33
34
  GetEngineNlpLockedBalancesResponse,
34
35
  GetEngineNlpPoolInfoResponse,
35
36
  GetEngineSubaccountSummaryResponse,
37
+ SubaccountSummaryState,
36
38
  } from '../types';
37
39
  import { mapEngineServerProductType } from './productEngineTypeMappers';
38
40
 
@@ -150,10 +152,32 @@ export function mapEngineServerBalanceHealthContributions(
150
152
  export function mapSubaccountSummary(
151
153
  baseResponse: EngineServerSubaccountInfoResponse,
152
154
  ): GetEngineSubaccountSummaryResponse {
153
- const balances: GetEngineSubaccountSummaryResponse['balances'] = [];
155
+ return {
156
+ exists: baseResponse.exists,
157
+ ...mapSubaccountSummaryState(
158
+ baseResponse,
159
+ baseResponse.spot_products,
160
+ baseResponse.perp_products,
161
+ ),
162
+ preState: baseResponse.pre_state
163
+ ? mapSubaccountSummaryState(
164
+ baseResponse.pre_state,
165
+ baseResponse.spot_products,
166
+ baseResponse.perp_products,
167
+ )
168
+ : undefined,
169
+ };
170
+ }
171
+
172
+ function mapSubaccountSummaryState(
173
+ state: EngineServerSubaccountInfoState,
174
+ spotProducts: EngineServerSubaccountInfoResponse['spot_products'],
175
+ perpProducts: EngineServerSubaccountInfoResponse['perp_products'],
176
+ ): SubaccountSummaryState {
177
+ const balances: SubaccountSummaryState['balances'] = [];
154
178
 
155
- baseResponse.spot_balances.forEach((spotBalance) => {
156
- const product = baseResponse.spot_products.find(
179
+ state.spot_balances.forEach((spotBalance) => {
180
+ const product = spotProducts.find(
157
181
  (product) => product.product_id === spotBalance.product_id,
158
182
  );
159
183
  if (!product) {
@@ -163,14 +187,14 @@ export function mapSubaccountSummary(
163
187
  balances.push({
164
188
  amount: toBigDecimal(spotBalance.balance.amount),
165
189
  healthContributions: mapEngineServerBalanceHealthContributions(
166
- baseResponse.health_contributions[spotBalance.product_id],
190
+ state.health_contributions[spotBalance.product_id],
167
191
  ),
168
192
  ...mapEngineServerSpotProduct(product).product,
169
193
  });
170
194
  });
171
195
 
172
- baseResponse.perp_balances.forEach((perpBalance) => {
173
- const product = baseResponse.perp_products.find(
196
+ state.perp_balances.forEach((perpBalance) => {
197
+ const product = perpProducts.find(
174
198
  (product) => product.product_id === perpBalance.product_id,
175
199
  );
176
200
  if (!product) {
@@ -181,30 +205,29 @@ export function mapSubaccountSummary(
181
205
  amount: toBigDecimal(perpBalance.balance.amount),
182
206
  vQuoteBalance: toBigDecimal(perpBalance.balance.v_quote_balance),
183
207
  healthContributions: mapEngineServerBalanceHealthContributions(
184
- baseResponse.health_contributions[perpBalance.product_id],
208
+ state.health_contributions[perpBalance.product_id],
185
209
  ),
186
210
  ...mapEngineServerPerpProduct(product).product,
187
211
  });
188
212
  });
189
213
 
190
214
  return {
191
- balances: balances,
192
- exists: baseResponse.exists,
215
+ balances,
193
216
  health: {
194
217
  initial: {
195
- health: toBigDecimal(baseResponse.healths[0].health),
196
- assets: toBigDecimal(baseResponse.healths[0].assets),
197
- liabilities: toBigDecimal(baseResponse.healths[0].liabilities),
218
+ health: toBigDecimal(state.healths[0].health),
219
+ assets: toBigDecimal(state.healths[0].assets),
220
+ liabilities: toBigDecimal(state.healths[0].liabilities),
198
221
  },
199
222
  maintenance: {
200
- health: toBigDecimal(baseResponse.healths[1].health),
201
- assets: toBigDecimal(baseResponse.healths[1].assets),
202
- liabilities: toBigDecimal(baseResponse.healths[1].liabilities),
223
+ health: toBigDecimal(state.healths[1].health),
224
+ assets: toBigDecimal(state.healths[1].assets),
225
+ liabilities: toBigDecimal(state.healths[1].liabilities),
203
226
  },
204
227
  unweighted: {
205
- health: toBigDecimal(baseResponse.healths[2].health),
206
- assets: toBigDecimal(baseResponse.healths[2].assets),
207
- liabilities: toBigDecimal(baseResponse.healths[2].liabilities),
228
+ health: toBigDecimal(state.healths[2].health),
229
+ assets: toBigDecimal(state.healths[2].assets),
230
+ liabilities: toBigDecimal(state.healths[2].liabilities),
208
231
  },
209
232
  },
210
233
  };