@nadohq/engine-client 0.1.0-alpha.9 → 0.1.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.
Files changed (83) hide show
  1. package/dist/EngineBaseClient.d.cts +2 -1
  2. package/dist/EngineBaseClient.d.ts +2 -1
  3. package/dist/EngineClient.d.cts +1 -0
  4. package/dist/EngineClient.d.ts +1 -0
  5. package/dist/EngineExecuteBuilder.cjs +9 -6
  6. package/dist/EngineExecuteBuilder.cjs.map +1 -1
  7. package/dist/EngineExecuteBuilder.d.cts +1 -0
  8. package/dist/EngineExecuteBuilder.d.ts +1 -0
  9. package/dist/EngineExecuteBuilder.js +9 -6
  10. package/dist/EngineExecuteBuilder.js.map +1 -1
  11. package/dist/EngineExecuteClient.cjs +6 -6
  12. package/dist/EngineExecuteClient.cjs.map +1 -1
  13. package/dist/EngineExecuteClient.d.cts +2 -1
  14. package/dist/EngineExecuteClient.d.ts +2 -1
  15. package/dist/EngineExecuteClient.js +6 -6
  16. package/dist/EngineExecuteClient.js.map +1 -1
  17. package/dist/EngineQueryClient.cjs +54 -11
  18. package/dist/EngineQueryClient.cjs.map +1 -1
  19. package/dist/EngineQueryClient.d.cts +19 -2
  20. package/dist/EngineQueryClient.d.ts +19 -2
  21. package/dist/EngineQueryClient.js +57 -12
  22. package/dist/EngineQueryClient.js.map +1 -1
  23. package/dist/EngineWebClient.d.cts +1 -0
  24. package/dist/EngineWebClient.d.ts +1 -0
  25. package/dist/endpoints.cjs +6 -6
  26. package/dist/endpoints.cjs.map +1 -1
  27. package/dist/endpoints.js +6 -6
  28. package/dist/endpoints.js.map +1 -1
  29. package/dist/index.cjs +4 -4
  30. package/dist/index.cjs.map +1 -1
  31. package/dist/index.d.cts +9 -8
  32. package/dist/index.d.ts +9 -8
  33. package/dist/index.js +2 -2
  34. package/dist/index.js.map +1 -1
  35. package/dist/types/clientExecuteTypes.cjs.map +1 -1
  36. package/dist/types/clientExecuteTypes.d.cts +8 -1
  37. package/dist/types/clientExecuteTypes.d.ts +8 -1
  38. package/dist/types/clientQueryTypes.cjs.map +1 -1
  39. package/dist/types/clientQueryTypes.d.cts +66 -33
  40. package/dist/types/clientQueryTypes.d.ts +66 -33
  41. package/dist/types/index.cjs +10 -10
  42. package/dist/types/index.cjs.map +1 -1
  43. package/dist/types/index.d.cts +6 -5
  44. package/dist/types/index.d.ts +6 -5
  45. package/dist/types/index.js +5 -5
  46. package/dist/types/index.js.map +1 -1
  47. package/dist/types/serverExecuteTypes.cjs.map +1 -1
  48. package/dist/types/serverExecuteTypes.d.cts +8 -1
  49. package/dist/types/serverExecuteTypes.d.ts +8 -1
  50. package/dist/types/serverQueryModelTypes.cjs.map +1 -1
  51. package/dist/types/serverQueryModelTypes.d.cts +24 -1
  52. package/dist/types/serverQueryModelTypes.d.ts +24 -1
  53. package/dist/types/serverQueryTypes.cjs +19 -0
  54. package/dist/types/serverQueryTypes.cjs.map +1 -1
  55. package/dist/types/serverQueryTypes.d.cts +49 -23
  56. package/dist/types/serverQueryTypes.d.ts +49 -23
  57. package/dist/types/serverQueryTypes.js +12 -0
  58. package/dist/types/serverQueryTypes.js.map +1 -1
  59. package/dist/types/serverSubscriptionEventTypes.cjs.map +1 -1
  60. package/dist/types/serverSubscriptionEventTypes.d.cts +7 -2
  61. package/dist/types/serverSubscriptionEventTypes.d.ts +7 -2
  62. package/dist/utils/index.d.cts +3 -2
  63. package/dist/utils/index.d.ts +3 -2
  64. package/dist/utils/queryDataMappers.cjs +95 -47
  65. package/dist/utils/queryDataMappers.cjs.map +1 -1
  66. package/dist/utils/queryDataMappers.d.cts +8 -5
  67. package/dist/utils/queryDataMappers.d.ts +8 -5
  68. package/dist/utils/queryDataMappers.js +94 -48
  69. package/dist/utils/queryDataMappers.js.map +1 -1
  70. package/package.json +13 -7
  71. package/src/EngineExecuteBuilder.ts +9 -6
  72. package/src/EngineExecuteClient.ts +7 -7
  73. package/src/EngineQueryClient.ts +73 -12
  74. package/src/endpoints.ts +6 -6
  75. package/src/index.ts +2 -2
  76. package/src/types/clientExecuteTypes.ts +9 -2
  77. package/src/types/clientQueryTypes.ts +76 -32
  78. package/src/types/index.ts +5 -5
  79. package/src/types/serverExecuteTypes.ts +9 -2
  80. package/src/types/serverQueryModelTypes.ts +25 -0
  81. package/src/types/serverQueryTypes.ts +74 -31
  82. package/src/types/serverSubscriptionEventTypes.ts +18 -25
  83. package/src/utils/queryDataMappers.ts +115 -49
@@ -1,6 +1,9 @@
1
1
  import { HealthStatus } from '@nadohq/shared';
2
2
  import {
3
3
  EngineServerHealthBreakdown,
4
+ EngineServerNlpBalance,
5
+ EngineServerNlpLockedBalance,
6
+ EngineServerOrder,
4
7
  EngineServerPerpBalance,
5
8
  EngineServerPerpProduct,
6
9
  EngineServerProductType,
@@ -22,6 +25,8 @@ export interface EngineServerSubaccountInfoQueryParams {
22
25
  v_quote_delta: string;
23
26
  };
24
27
  }>;
28
+ // If not given, engine defaults to 'false'
29
+ pre_state?: string;
25
30
  }
26
31
 
27
32
  export interface EngineServerIsolatedPositionsQueryParams {
@@ -89,6 +94,10 @@ export interface EngineServerMaxOrderSizeQueryParams {
89
94
  // If not given, engine defaults to false. If true, the max order size will be capped to the subaccount's current position size;
90
95
  // If no position exists, it will return 0.
91
96
  reduce_only: string | null;
97
+ isolated: string | null;
98
+ // For isolated, max order size includes available collateral to transfer from parent cross subaccount
99
+ // If not given, engine defaults to true (borrow enabled)
100
+ borrow_margin: string | null;
92
101
  }
93
102
 
94
103
  export interface EngineServerLinkedSignerParams {
@@ -101,6 +110,14 @@ export interface EngineServerMaxMintNlpQueryParams {
101
110
  spot_leverage: string | null;
102
111
  }
103
112
 
113
+ export interface EngineServerMaxBurnNlpQueryParams {
114
+ sender: string;
115
+ }
116
+
117
+ export interface EngineServerNlpLockedBalancesQueryParams {
118
+ subaccount: string;
119
+ }
120
+
104
121
  export interface EngineServerQueryRequestByType {
105
122
  all_products: Record<string, never>;
106
123
  contracts: Record<string, never>;
@@ -113,8 +130,11 @@ export interface EngineServerQueryRequestByType {
113
130
  market_liquidity: EngineServerMarketLiquidityQueryParams;
114
131
  market_price: EngineServerMarketPriceQueryParams;
115
132
  market_prices: EngineServerMarketPricesQueryParams;
133
+ max_nlp_burnable: EngineServerMaxBurnNlpQueryParams;
116
134
  max_nlp_mintable: EngineServerMaxMintNlpQueryParams;
117
135
  max_order_size: EngineServerMaxOrderSizeQueryParams;
136
+ nlp_locked_balances: EngineServerNlpLockedBalancesQueryParams;
137
+ nlp_pool_info: Record<string, never>;
118
138
  max_withdrawable: EngineServerMaxWithdrawableQueryParams;
119
139
  nonces: EngineServerNoncesParams;
120
140
  order: EngineServerGetOrderQueryParams;
@@ -143,22 +163,36 @@ export interface EngineServerContractsResponse {
143
163
  }
144
164
 
145
165
  // Unless in active state, engine is not fully operational
166
+ export const ENGINE_SERVER_STATUS_VALUES = [
167
+ 'started',
168
+ 'active',
169
+ 'stopping',
170
+ 'syncing',
171
+ 'live_syncing',
172
+ 'failed',
173
+ ] as const;
174
+
146
175
  export type EngineServerStatusResponse =
147
- | 'started'
148
- | 'active'
149
- | 'stopping'
150
- | 'syncing'
151
- | 'live_syncing'
152
- | 'failed';
176
+ (typeof ENGINE_SERVER_STATUS_VALUES)[number];
153
177
 
154
178
  export interface EngineServerNoncesResponse {
155
179
  order_nonce: string;
156
180
  tx_nonce: string;
157
181
  }
158
182
 
159
- export interface EngineServerSubaccountInfoResponse {
183
+ export interface EngineServerSubaccountInfoResponse extends EngineServerSubaccountInfoState {
160
184
  exists: boolean;
161
185
  subaccount: string;
186
+ spot_count: number;
187
+ perp_count: number;
188
+ spot_products: EngineServerSpotProduct[];
189
+ perp_products: EngineServerPerpProduct[];
190
+
191
+ /** This is set if request has `pre_state` flag set to 'true' */
192
+ pre_state: EngineServerSubaccountInfoState | undefined;
193
+ }
194
+
195
+ export interface EngineServerSubaccountInfoState {
162
196
  healths: [
163
197
  initial: EngineServerHealthBreakdown,
164
198
  maintenance: EngineServerHealthBreakdown,
@@ -166,12 +200,8 @@ export interface EngineServerSubaccountInfoResponse {
166
200
  ];
167
201
  // First index is product ID, each subarray is of length 3 [initial, maintenance, unweighted]
168
202
  health_contributions: string[][];
169
- spot_count: number;
170
- perp_count: number;
171
203
  spot_balances: EngineServerSpotBalance[];
172
204
  perp_balances: EngineServerPerpBalance[];
173
- spot_products: EngineServerSpotProduct[];
174
- perp_products: EngineServerPerpProduct[];
175
205
  }
176
206
 
177
207
  export interface EngineServerIsolatedPosition {
@@ -200,12 +230,13 @@ export interface EngineServerSymbol {
200
230
  price_increment_x18: string;
201
231
  size_increment: string;
202
232
  min_size: string;
203
- min_depth_x18: string;
204
- max_spread_rate_x18: string;
205
233
  maker_fee_rate_x18: string;
206
234
  taker_fee_rate_x18: string;
207
235
  long_weight_initial_x18: string;
208
236
  long_weight_maintenance_x18: string;
237
+ // undefined when there is no max open interest limit (always undefined for spot products)
238
+ max_open_interest_x18: string | undefined;
239
+ isolated_only: boolean;
209
240
  }
210
241
 
211
242
  export interface EngineServerSymbolsResponse {
@@ -268,20 +299,6 @@ export interface EngineServerMarketPricesResponse {
268
299
  market_prices: EngineServerMarketPrice[];
269
300
  }
270
301
 
271
- export interface EngineServerOrder {
272
- product_id: number;
273
- sender: string;
274
- price_x18: string;
275
- amount: string;
276
- expiration: string;
277
- nonce: string;
278
- unfilled_amount: string;
279
- digest: string;
280
- placed_at: number;
281
- order_type: string;
282
- appendix: string;
283
- }
284
-
285
302
  export type EngineServerOrderResponse = EngineServerOrder;
286
303
 
287
304
  export interface EngineServerValidateOrderResponse {
@@ -318,10 +335,33 @@ export interface EngineServerEdgeAllProductsResponse {
318
335
  edge_all_products: Record<number, EngineServerAllProductsResponse>;
319
336
  }
320
337
 
338
+ export interface EngineServerMaxBurnNlpResponse {
339
+ max_nlp_amount: string;
340
+ }
341
+
321
342
  export interface EngineServerMaxMintNlpResponse {
322
343
  max_quote_amount: string;
323
344
  }
324
345
 
346
+ export interface EngineServerNlpLockedBalancesResponse {
347
+ balance_locked: EngineServerNlpBalance;
348
+ balance_unlocked: EngineServerNlpBalance;
349
+ locked_balances: EngineServerNlpLockedBalance[];
350
+ }
351
+
352
+ export interface EngineServerNlpPool {
353
+ pool_id: number;
354
+ subaccount: string;
355
+ owner: string;
356
+ balance_weight_x18: string;
357
+ subaccount_info: EngineServerSubaccountInfoResponse;
358
+ open_orders: EngineServerOrder[];
359
+ }
360
+
361
+ export interface EngineServerNlpPoolInfoResponse {
362
+ nlp_pools: EngineServerNlpPool[];
363
+ }
364
+
325
365
  export interface EngineServerQueryResponseByType {
326
366
  all_products: EngineServerAllProductsResponse;
327
367
  contracts: EngineServerContractsResponse;
@@ -334,8 +374,11 @@ export interface EngineServerQueryResponseByType {
334
374
  market_liquidity: EngineServerMarketLiquidityResponse;
335
375
  market_price: EngineServerMarketPriceResponse;
336
376
  market_prices: EngineServerMarketPricesResponse;
377
+ max_nlp_burnable: EngineServerMaxBurnNlpResponse;
337
378
  max_nlp_mintable: EngineServerMaxMintNlpResponse;
338
379
  max_order_size: EngineServerMaxOrderSizeResponse;
380
+ nlp_locked_balances: EngineServerNlpLockedBalancesResponse;
381
+ nlp_pool_info: EngineServerNlpPoolInfoResponse;
339
382
  max_withdrawable: EngineServerMaxWithdrawableResponse;
340
383
  nonces: EngineServerNoncesResponse;
341
384
  order: EngineServerOrderResponse;
@@ -348,8 +391,8 @@ export interface EngineServerQueryResponseByType {
348
391
  }
349
392
 
350
393
  export interface EngineServerQuerySuccessResponse<
351
- TQueryType extends
352
- keyof EngineServerQueryResponseByType = EngineServerQueryRequestType,
394
+ TQueryType extends keyof EngineServerQueryResponseByType =
395
+ EngineServerQueryRequestType,
353
396
  > {
354
397
  status: 'success';
355
398
  data: EngineServerQueryResponseByType[TQueryType];
@@ -362,8 +405,8 @@ export interface EngineServerQueryFailureResponse {
362
405
  }
363
406
 
364
407
  export type EngineServerQueryResponse<
365
- TQueryType extends
366
- keyof EngineServerQueryResponseByType = EngineServerQueryRequestType,
408
+ TQueryType extends keyof EngineServerQueryResponseByType =
409
+ EngineServerQueryRequestType,
367
410
  > =
368
411
  | EngineServerQuerySuccessResponse<TQueryType>
369
412
  | EngineServerQueryFailureResponse;
@@ -1,7 +1,4 @@
1
- import {
2
- EngineServerOrder,
3
- EngineServerPriceTickLiquidity,
4
- } from './serverQueryTypes';
1
+ import { EngineServerPriceTickLiquidity } from './serverQueryTypes';
5
2
 
6
3
  /**
7
4
  * Reasons that can trigger position change events.
@@ -33,8 +30,8 @@ export type EngineServerSubscriptionEventType =
33
30
  | 'funding_payment';
34
31
 
35
32
  export interface EngineServerSubscriptionBaseEvent<
36
- T extends
37
- EngineServerSubscriptionEventType = EngineServerSubscriptionEventType,
33
+ T extends EngineServerSubscriptionEventType =
34
+ EngineServerSubscriptionEventType,
38
35
  > {
39
36
  type: T;
40
37
  product_id: number;
@@ -43,8 +40,7 @@ export interface EngineServerSubscriptionBaseEvent<
43
40
  /**
44
41
  * Event from subscribing to a `trade` stream.
45
42
  */
46
- export interface EngineServerSubscriptionTradeEvent
47
- extends EngineServerSubscriptionBaseEvent<'trade'> {
43
+ export interface EngineServerSubscriptionTradeEvent extends EngineServerSubscriptionBaseEvent<'trade'> {
48
44
  timestamp: string;
49
45
  price: string;
50
46
  taker_qty: string;
@@ -55,8 +51,7 @@ export interface EngineServerSubscriptionTradeEvent
55
51
  /**
56
52
  * Event from subscribing to a `best_bid_offer` stream.
57
53
  */
58
- export interface EngineServerSubscriptionBestBidOfferEvent
59
- extends EngineServerSubscriptionBaseEvent<'best_bid_offer'> {
54
+ export interface EngineServerSubscriptionBestBidOfferEvent extends EngineServerSubscriptionBaseEvent<'best_bid_offer'> {
60
55
  timestamp: string;
61
56
  bid_price: string;
62
57
  bid_qty: string;
@@ -67,8 +62,7 @@ export interface EngineServerSubscriptionBestBidOfferEvent
67
62
  /**
68
63
  * Event from subscribing to a `book_depth` stream.
69
64
  */
70
- export interface EngineServerSubscriptionBookDepthEvent
71
- extends EngineServerSubscriptionBaseEvent<'book_depth'> {
65
+ export interface EngineServerSubscriptionBookDepthEvent extends EngineServerSubscriptionBaseEvent<'book_depth'> {
72
66
  last_max_timestamp: string;
73
67
  min_timestamp: string;
74
68
  max_timestamp: string;
@@ -79,8 +73,7 @@ export interface EngineServerSubscriptionBookDepthEvent
79
73
  /**
80
74
  * Event from subscribing to a `fill` stream.
81
75
  */
82
- export interface EngineServerSubscriptionFillEvent
83
- extends EngineServerSubscriptionBaseEvent<'fill'> {
76
+ export interface EngineServerSubscriptionFillEvent extends EngineServerSubscriptionBaseEvent<'fill'> {
84
77
  // NOTE: `id` is excluded from the response to avoid parsing issues.
85
78
  // type of `id` on the backend is `u64` which can overflow until we introduce proper parsing on the SDK.
86
79
  timestamp: string;
@@ -100,31 +93,33 @@ export interface EngineServerSubscriptionFillEvent
100
93
  /**
101
94
  * Event from subscribing to a `position_change` stream.
102
95
  */
103
- export interface EngineServerSubscriptionPositionChangeEvent
104
- extends EngineServerSubscriptionBaseEvent<'position_change'> {
96
+ export interface EngineServerSubscriptionPositionChangeEvent extends EngineServerSubscriptionBaseEvent<'position_change'> {
105
97
  timestamp: string;
106
98
  subaccount: string;
107
99
  amount: string;
108
100
  /** Zero for everything except perps */
109
101
  v_quote_amount: string;
110
102
  reason: PositionChangeReason;
103
+ /**
104
+ * True if the position change was for an isolated position
105
+ */
106
+ isolated: boolean;
111
107
  }
112
108
 
113
109
  /**
114
110
  * Event from subscribing to an `order_update` stream.
115
111
  */
116
- export interface EngineServerSubscriptionOrderUpdateEvent
117
- extends EngineServerSubscriptionBaseEvent<'order_update'> {
112
+ export interface EngineServerSubscriptionOrderUpdateEvent extends EngineServerSubscriptionBaseEvent<'order_update'> {
118
113
  timestamp: string;
119
- order: EngineServerOrder;
114
+ digest: string;
115
+ amount: string;
120
116
  reason: OrderUpdateReason;
121
117
  }
122
118
 
123
119
  /**
124
120
  * Event from subscribing to a `liquidation` stream.
125
121
  */
126
- export interface EngineServerSubscriptionLiquidationEvent
127
- extends EngineServerSubscriptionBaseEvent<'liquidation'> {
122
+ export interface EngineServerSubscriptionLiquidationEvent extends EngineServerSubscriptionBaseEvent<'liquidation'> {
128
123
  timestamp: string;
129
124
  /** Single element for regular liquidations, two elements for spread liquidations [spotId, perpId] */
130
125
  product_ids: number[];
@@ -139,8 +134,7 @@ export interface EngineServerSubscriptionLiquidationEvent
139
134
  /**
140
135
  * Event from subscribing to a `latest_candlestick` stream.
141
136
  */
142
- export interface EngineServerSubscriptionLatestCandlestickEvent
143
- extends EngineServerSubscriptionBaseEvent<'latest_candlestick'> {
137
+ export interface EngineServerSubscriptionLatestCandlestickEvent extends EngineServerSubscriptionBaseEvent<'latest_candlestick'> {
144
138
  timestamp: string;
145
139
  granularity: number;
146
140
  open_x18: string;
@@ -153,8 +147,7 @@ export interface EngineServerSubscriptionLatestCandlestickEvent
153
147
  /**
154
148
  * Event from subscribing to a `funding_payment` stream.
155
149
  */
156
- export interface EngineServerSubscriptionFundingPaymentEvent
157
- extends EngineServerSubscriptionBaseEvent<'funding_payment'> {
150
+ export interface EngineServerSubscriptionFundingPaymentEvent extends EngineServerSubscriptionBaseEvent<'funding_payment'> {
158
151
  timestamp: string;
159
152
  /** Funding payment amount (positive = receive, negative = pay) */
160
153
  payment_amount: string;
@@ -8,26 +8,33 @@ import {
8
8
  removeDecimals,
9
9
  SpotMarket,
10
10
  subaccountFromHex,
11
- toBigDecimal,
11
+ toBigNumber,
12
12
  unpackOrderAppendix,
13
13
  } from '@nadohq/shared';
14
14
  import {
15
15
  EngineMarketPrice,
16
+ EngineNlpLockedBalance,
16
17
  EngineOrder,
17
18
  EnginePriceTickLiquidity,
18
19
  EngineServerIsolatedPositionsResponse,
19
20
  EngineServerMarketPrice,
21
+ EngineServerNlpLockedBalancesResponse,
22
+ EngineServerNlpPoolInfoResponse,
20
23
  EngineServerOrderResponse,
21
24
  EngineServerPerpProduct,
22
25
  EngineServerPriceTickLiquidity,
23
26
  EngineServerSpotProduct,
24
27
  EngineServerSubaccountInfoResponse,
28
+ EngineServerSubaccountInfoState,
25
29
  EngineServerSymbol,
26
30
  EngineServerSymbolsResponse,
27
31
  EngineSymbol,
28
32
  EngineSymbolsResponse,
29
33
  GetEngineIsolatedPositionsResponse,
34
+ GetEngineNlpLockedBalancesResponse,
35
+ GetEngineNlpPoolInfoResponse,
30
36
  GetEngineSubaccountSummaryResponse,
37
+ SubaccountSummaryState,
31
38
  } from '../types';
32
39
  import { mapEngineServerProductType } from './productEngineTypeMappers';
33
40
 
@@ -36,7 +43,7 @@ export function mapEngineServerTickLiquidity(
36
43
  ): EnginePriceTickLiquidity {
37
44
  return {
38
45
  price: removeDecimals(tick[0]),
39
- liquidity: toBigDecimal(tick[1]),
46
+ liquidity: toBigNumber(tick[1]),
40
47
  };
41
48
  }
42
49
 
@@ -52,8 +59,8 @@ export function mapEngineServerOrder(
52
59
  productId: order.product_id,
53
60
  subaccountOwner: subaccount.subaccountOwner,
54
61
  subaccountName: subaccount.subaccountName,
55
- totalAmount: toBigDecimal(order.amount),
56
- unfilledAmount: toBigDecimal(order.unfilled_amount),
62
+ totalAmount: toBigNumber(order.amount),
63
+ unfilledAmount: toBigNumber(order.unfilled_amount),
57
64
  placementTime: order.placed_at,
58
65
  appendix: unpackOrderAppendix(order.appendix),
59
66
  };
@@ -65,9 +72,9 @@ export function mapEngineServerSpotProduct(
65
72
  return {
66
73
  type: ProductEngineType.SPOT,
67
74
  productId: product.product_id,
68
- minSize: toBigDecimal(product.book_info.min_size),
75
+ minSize: toBigNumber(product.book_info.min_size),
69
76
  priceIncrement: removeDecimals(product.book_info.price_increment_x18),
70
- sizeIncrement: toBigDecimal(product.book_info.size_increment),
77
+ sizeIncrement: toBigNumber(product.book_info.size_increment),
71
78
  product: {
72
79
  productId: product.product_id,
73
80
  type: ProductEngineType.SPOT,
@@ -106,9 +113,9 @@ export function mapEngineServerPerpProduct(
106
113
  return {
107
114
  type: ProductEngineType.PERP,
108
115
  productId: product.product_id,
109
- minSize: toBigDecimal(product.book_info.min_size),
116
+ minSize: toBigNumber(product.book_info.min_size),
110
117
  priceIncrement: removeDecimals(product.book_info.price_increment_x18),
111
- sizeIncrement: toBigDecimal(product.book_info.size_increment),
118
+ sizeIncrement: toBigNumber(product.book_info.size_increment),
112
119
  product: {
113
120
  productId: product.product_id,
114
121
  type: ProductEngineType.PERP,
@@ -121,7 +128,7 @@ export function mapEngineServerPerpProduct(
121
128
  shortWeightMaintenance: removeDecimals(
122
129
  product.risk.short_weight_maintenance_x18,
123
130
  ),
124
- openInterest: toBigDecimal(product.state.open_interest),
131
+ openInterest: toBigNumber(product.state.open_interest),
125
132
  cumulativeFundingLong: removeDecimals(
126
133
  product.state.cumulative_funding_long_x18,
127
134
  ),
@@ -136,19 +143,41 @@ export function mapEngineServerBalanceHealthContributions(
136
143
  healthContributionsForBalance: string[],
137
144
  ): BalanceHealthContributions {
138
145
  return {
139
- initial: toBigDecimal(healthContributionsForBalance[0]),
140
- maintenance: toBigDecimal(healthContributionsForBalance[1]),
141
- unweighted: toBigDecimal(healthContributionsForBalance[2]),
146
+ initial: toBigNumber(healthContributionsForBalance[0]),
147
+ maintenance: toBigNumber(healthContributionsForBalance[1]),
148
+ unweighted: toBigNumber(healthContributionsForBalance[2]),
142
149
  };
143
150
  }
144
151
 
145
152
  export function mapSubaccountSummary(
146
153
  baseResponse: EngineServerSubaccountInfoResponse,
147
154
  ): GetEngineSubaccountSummaryResponse {
148
- 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
+ }
149
171
 
150
- baseResponse.spot_balances.forEach((spotBalance) => {
151
- const product = baseResponse.spot_products.find(
172
+ function mapSubaccountSummaryState(
173
+ state: EngineServerSubaccountInfoState,
174
+ spotProducts: EngineServerSubaccountInfoResponse['spot_products'],
175
+ perpProducts: EngineServerSubaccountInfoResponse['perp_products'],
176
+ ): SubaccountSummaryState {
177
+ const balances: SubaccountSummaryState['balances'] = [];
178
+
179
+ state.spot_balances.forEach((spotBalance) => {
180
+ const product = spotProducts.find(
152
181
  (product) => product.product_id === spotBalance.product_id,
153
182
  );
154
183
  if (!product) {
@@ -156,16 +185,16 @@ export function mapSubaccountSummary(
156
185
  }
157
186
 
158
187
  balances.push({
159
- amount: toBigDecimal(spotBalance.balance.amount),
188
+ amount: toBigNumber(spotBalance.balance.amount),
160
189
  healthContributions: mapEngineServerBalanceHealthContributions(
161
- baseResponse.health_contributions[spotBalance.product_id],
190
+ state.health_contributions[spotBalance.product_id],
162
191
  ),
163
192
  ...mapEngineServerSpotProduct(product).product,
164
193
  });
165
194
  });
166
195
 
167
- baseResponse.perp_balances.forEach((perpBalance) => {
168
- const product = baseResponse.perp_products.find(
196
+ state.perp_balances.forEach((perpBalance) => {
197
+ const product = perpProducts.find(
169
198
  (product) => product.product_id === perpBalance.product_id,
170
199
  );
171
200
  if (!product) {
@@ -173,33 +202,32 @@ export function mapSubaccountSummary(
173
202
  }
174
203
 
175
204
  balances.push({
176
- amount: toBigDecimal(perpBalance.balance.amount),
177
- vQuoteBalance: toBigDecimal(perpBalance.balance.v_quote_balance),
205
+ amount: toBigNumber(perpBalance.balance.amount),
206
+ vQuoteBalance: toBigNumber(perpBalance.balance.v_quote_balance),
178
207
  healthContributions: mapEngineServerBalanceHealthContributions(
179
- baseResponse.health_contributions[perpBalance.product_id],
208
+ state.health_contributions[perpBalance.product_id],
180
209
  ),
181
210
  ...mapEngineServerPerpProduct(product).product,
182
211
  });
183
212
  });
184
213
 
185
214
  return {
186
- balances: balances,
187
- exists: baseResponse.exists,
215
+ balances,
188
216
  health: {
189
217
  initial: {
190
- health: toBigDecimal(baseResponse.healths[0].health),
191
- assets: toBigDecimal(baseResponse.healths[0].assets),
192
- liabilities: toBigDecimal(baseResponse.healths[0].liabilities),
218
+ health: toBigNumber(state.healths[0].health),
219
+ assets: toBigNumber(state.healths[0].assets),
220
+ liabilities: toBigNumber(state.healths[0].liabilities),
193
221
  },
194
222
  maintenance: {
195
- health: toBigDecimal(baseResponse.healths[1].health),
196
- assets: toBigDecimal(baseResponse.healths[1].assets),
197
- liabilities: toBigDecimal(baseResponse.healths[1].liabilities),
223
+ health: toBigNumber(state.healths[1].health),
224
+ assets: toBigNumber(state.healths[1].assets),
225
+ liabilities: toBigNumber(state.healths[1].liabilities),
198
226
  },
199
227
  unweighted: {
200
- health: toBigDecimal(baseResponse.healths[2].health),
201
- assets: toBigDecimal(baseResponse.healths[2].assets),
202
- liabilities: toBigDecimal(baseResponse.healths[2].liabilities),
228
+ health: toBigNumber(state.healths[2].health),
229
+ assets: toBigNumber(state.healths[2].assets),
230
+ liabilities: toBigNumber(state.healths[2].liabilities),
203
231
  },
204
232
  },
205
233
  };
@@ -215,27 +243,27 @@ export function mapEngineServerIsolatedPositions(
215
243
  return {
216
244
  subaccount: subaccountFromHex(position.subaccount),
217
245
  healths: {
218
- initial: toBigDecimal(position.healths[0].health),
219
- maintenance: toBigDecimal(position.healths[1].health),
220
- unweighted: toBigDecimal(position.healths[2].health),
246
+ initial: toBigNumber(position.healths[0].health),
247
+ maintenance: toBigNumber(position.healths[1].health),
248
+ unweighted: toBigNumber(position.healths[2].health),
221
249
  },
222
250
  baseBalance: {
223
- amount: toBigDecimal(perpBalance.balance.amount),
224
- vQuoteBalance: toBigDecimal(perpBalance.balance.v_quote_balance),
251
+ amount: toBigNumber(perpBalance.balance.amount),
252
+ vQuoteBalance: toBigNumber(perpBalance.balance.v_quote_balance),
225
253
  // Health contributions === healths for an isolated position
226
254
  healthContributions: {
227
- initial: toBigDecimal(position.base_healths[0]),
228
- maintenance: toBigDecimal(position.base_healths[1]),
229
- unweighted: toBigDecimal(position.base_healths[2]),
255
+ initial: toBigNumber(position.base_healths[0]),
256
+ maintenance: toBigNumber(position.base_healths[1]),
257
+ unweighted: toBigNumber(position.base_healths[2]),
230
258
  },
231
259
  ...mapEngineServerPerpProduct(position.base_product).product,
232
260
  },
233
261
  quoteBalance: {
234
- amount: toBigDecimal(quoteBalance.balance.amount),
262
+ amount: toBigNumber(quoteBalance.balance.amount),
235
263
  healthContributions: {
236
- initial: toBigDecimal(position.quote_healths[0]),
237
- maintenance: toBigDecimal(position.quote_healths[1]),
238
- unweighted: toBigDecimal(position.quote_healths[2]),
264
+ initial: toBigNumber(position.quote_healths[0]),
265
+ maintenance: toBigNumber(position.quote_healths[1]),
266
+ unweighted: toBigNumber(position.quote_healths[2]),
239
267
  },
240
268
  ...mapEngineServerSpotProduct(position.quote_product).product,
241
269
  },
@@ -264,10 +292,8 @@ export function mapEngineServerSymbol(
264
292
  productId: engineServerSymbol.product_id,
265
293
  symbol: engineServerSymbol.symbol,
266
294
  priceIncrement: removeDecimals(engineServerSymbol.price_increment_x18),
267
- sizeIncrement: toBigDecimal(engineServerSymbol.size_increment),
268
- minSize: toBigDecimal(engineServerSymbol.min_size),
269
- minDepth: removeDecimals(engineServerSymbol.min_depth_x18),
270
- maxSpreadRate: removeDecimals(engineServerSymbol.max_spread_rate_x18),
295
+ sizeIncrement: toBigNumber(engineServerSymbol.size_increment),
296
+ minSize: toBigNumber(engineServerSymbol.min_size),
271
297
  makerFeeRate: removeDecimals(engineServerSymbol.maker_fee_rate_x18),
272
298
  takerFeeRate: removeDecimals(engineServerSymbol.taker_fee_rate_x18),
273
299
  longWeightInitial: removeDecimals(
@@ -276,6 +302,8 @@ export function mapEngineServerSymbol(
276
302
  longWeightMaintenance: removeDecimals(
277
303
  engineServerSymbol.long_weight_maintenance_x18,
278
304
  ),
305
+ maxOpenInterest: removeDecimals(engineServerSymbol.max_open_interest_x18),
306
+ isolatedOnly: engineServerSymbol.isolated_only,
279
307
  };
280
308
  }
281
309
 
@@ -288,3 +316,41 @@ export function mapEngineMarketPrice(
288
316
  productId: baseResponse.product_id,
289
317
  };
290
318
  }
319
+
320
+ export function mapEngineServerNlpLockedBalances(
321
+ baseResponse: EngineServerNlpLockedBalancesResponse,
322
+ ): GetEngineNlpLockedBalancesResponse {
323
+ const lockedBalances: EngineNlpLockedBalance[] =
324
+ baseResponse.locked_balances.map((lockedBalance) => ({
325
+ productId: lockedBalance.balance.product_id,
326
+ balance: toBigNumber(lockedBalance.balance.balance.amount),
327
+ unlockedAt: lockedBalance.unlocked_at,
328
+ }));
329
+
330
+ return {
331
+ lockedBalances,
332
+ balanceLocked: {
333
+ productId: baseResponse.balance_locked.product_id,
334
+ balance: toBigNumber(baseResponse.balance_locked.balance.amount),
335
+ },
336
+ balanceUnlocked: {
337
+ productId: baseResponse.balance_unlocked.product_id,
338
+ balance: toBigNumber(baseResponse.balance_unlocked.balance.amount),
339
+ },
340
+ };
341
+ }
342
+
343
+ export function mapEngineServerNlpPoolInfo(
344
+ baseResponse: EngineServerNlpPoolInfoResponse,
345
+ ): GetEngineNlpPoolInfoResponse {
346
+ return {
347
+ nlpPools: baseResponse.nlp_pools.map((pool) => ({
348
+ poolId: pool.pool_id,
349
+ subaccountHex: pool.subaccount,
350
+ ownerAddress: pool.owner,
351
+ balanceWeight: removeDecimals(pool.balance_weight_x18),
352
+ subaccountInfo: mapSubaccountSummary(pool.subaccount_info),
353
+ openOrders: pool.open_orders.map(mapEngineServerOrder),
354
+ })),
355
+ };
356
+ }