@nadohq/engine-client 0.1.0-alpha.4 → 0.1.0-alpha.41

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 +1 -1
  2. package/dist/EngineBaseClient.d.ts +1 -1
  3. package/dist/EngineExecuteBuilder.cjs +9 -6
  4. package/dist/EngineExecuteBuilder.cjs.map +1 -1
  5. package/dist/EngineExecuteBuilder.js +9 -6
  6. package/dist/EngineExecuteBuilder.js.map +1 -1
  7. package/dist/EngineExecuteClient.cjs +6 -6
  8. package/dist/EngineExecuteClient.cjs.map +1 -1
  9. package/dist/EngineExecuteClient.d.cts +1 -1
  10. package/dist/EngineExecuteClient.d.ts +1 -1
  11. package/dist/EngineExecuteClient.js +6 -6
  12. package/dist/EngineExecuteClient.js.map +1 -1
  13. package/dist/EngineQueryClient.cjs +48 -4
  14. package/dist/EngineQueryClient.cjs.map +1 -1
  15. package/dist/EngineQueryClient.d.cts +18 -2
  16. package/dist/EngineQueryClient.d.ts +18 -2
  17. package/dist/EngineQueryClient.js +50 -4
  18. package/dist/EngineQueryClient.js.map +1 -1
  19. package/dist/endpoints.cjs +6 -6
  20. package/dist/endpoints.cjs.map +1 -1
  21. package/dist/endpoints.js +6 -6
  22. package/dist/endpoints.js.map +1 -1
  23. package/dist/index.cjs +4 -4
  24. package/dist/index.cjs.map +1 -1
  25. package/dist/index.d.cts +9 -9
  26. package/dist/index.d.ts +9 -9
  27. package/dist/index.js +2 -2
  28. package/dist/index.js.map +1 -1
  29. package/dist/types/EngineServerFailureError.cjs +1 -1
  30. package/dist/types/EngineServerFailureError.cjs.map +1 -1
  31. package/dist/types/EngineServerFailureError.js +1 -1
  32. package/dist/types/EngineServerFailureError.js.map +1 -1
  33. package/dist/types/clientExecuteTypes.cjs.map +1 -1
  34. package/dist/types/clientExecuteTypes.d.cts +8 -1
  35. package/dist/types/clientExecuteTypes.d.ts +8 -1
  36. package/dist/types/clientQueryTypes.cjs.map +1 -1
  37. package/dist/types/clientQueryTypes.d.cts +37 -5
  38. package/dist/types/clientQueryTypes.d.ts +37 -5
  39. package/dist/types/index.cjs +10 -10
  40. package/dist/types/index.cjs.map +1 -1
  41. package/dist/types/index.d.cts +6 -6
  42. package/dist/types/index.d.ts +6 -6
  43. package/dist/types/index.js +5 -5
  44. package/dist/types/index.js.map +1 -1
  45. package/dist/types/serverExecuteTypes.cjs.map +1 -1
  46. package/dist/types/serverExecuteTypes.d.cts +8 -1
  47. package/dist/types/serverExecuteTypes.d.ts +8 -1
  48. package/dist/types/serverQueryModelTypes.cjs.map +1 -1
  49. package/dist/types/serverQueryModelTypes.d.cts +24 -1
  50. package/dist/types/serverQueryModelTypes.d.ts +24 -1
  51. package/dist/types/serverQueryTypes.cjs.map +1 -1
  52. package/dist/types/serverQueryTypes.d.cts +47 -22
  53. package/dist/types/serverQueryTypes.d.ts +47 -22
  54. package/dist/types/serverSubscriptionEventTypes.cjs.map +1 -1
  55. package/dist/types/serverSubscriptionEventTypes.d.cts +86 -22
  56. package/dist/types/serverSubscriptionEventTypes.d.ts +86 -22
  57. package/dist/types/serverSubscriptionTypes.cjs.map +1 -1
  58. package/dist/types/serverSubscriptionTypes.d.cts +21 -4
  59. package/dist/types/serverSubscriptionTypes.d.ts +21 -4
  60. package/dist/utils/index.d.cts +2 -2
  61. package/dist/utils/index.d.ts +2 -2
  62. package/dist/utils/queryDataMappers.cjs +66 -19
  63. package/dist/utils/queryDataMappers.cjs.map +1 -1
  64. package/dist/utils/queryDataMappers.d.cts +5 -3
  65. package/dist/utils/queryDataMappers.d.ts +5 -3
  66. package/dist/utils/queryDataMappers.js +64 -19
  67. package/dist/utils/queryDataMappers.js.map +1 -1
  68. package/package.json +7 -3
  69. package/src/EngineExecuteBuilder.ts +9 -6
  70. package/src/EngineExecuteClient.ts +7 -7
  71. package/src/EngineQueryClient.ts +63 -1
  72. package/src/endpoints.ts +6 -6
  73. package/src/index.ts +2 -2
  74. package/src/types/EngineServerFailureError.ts +1 -1
  75. package/src/types/clientExecuteTypes.ts +9 -2
  76. package/src/types/clientQueryTypes.ts +49 -4
  77. package/src/types/index.ts +5 -5
  78. package/src/types/serverExecuteTypes.ts +9 -2
  79. package/src/types/serverQueryModelTypes.ts +25 -0
  80. package/src/types/serverQueryTypes.ts +61 -21
  81. package/src/types/serverSubscriptionEventTypes.ts +131 -21
  82. package/src/types/serverSubscriptionTypes.ts +23 -3
  83. package/src/utils/queryDataMappers.ts +85 -20
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/types/serverSubscriptionTypes.ts"],"sourcesContent":["export interface EngineServerOrderUpdateStreamParams {\n product_id: number;\n subaccount: string;\n}\n\nexport interface EngineServerTradeStreamParams {\n product_id: number;\n}\n\nexport interface EngineServerBestBidOfferStreamParams {\n product_id: number;\n}\n\nexport interface EngineServerFillStreamParams {\n product_id: number;\n subaccount: string;\n}\n\nexport interface EngineServerPositionChangeStreamParams {\n product_id: number;\n subaccount: string;\n}\n\nexport interface EngineServerBookDepthStreamParams {\n product_id: number;\n}\n\n/**\n * Available subscription streams\n */\nexport interface EngineServerSubscriptionStreamParamsByType {\n order_update: EngineServerOrderUpdateStreamParams;\n trade: EngineServerTradeStreamParams;\n best_bid_offer: EngineServerBestBidOfferStreamParams;\n fill: EngineServerFillStreamParams;\n position_change: EngineServerPositionChangeStreamParams;\n book_depth: EngineServerBookDepthStreamParams;\n}\n\nexport type EngineServerSubscriptionStreamParamsType =\n keyof EngineServerSubscriptionStreamParamsByType;\n\n/**\n * Describes a stream that can be subscribed to.\n */\nexport type EngineServerSubscriptionStream<\n TStreamType extends EngineServerSubscriptionStreamParamsType,\n> = {\n type: TStreamType;\n} & EngineServerSubscriptionStreamParamsByType[TStreamType];\n\n/**\n * Params to provide to a `subscribe` / `unsubscribe` action.\n */\nexport interface EngineServerSubscriptionParams {\n stream: EngineServerSubscriptionStream<EngineServerSubscriptionStreamParamsType>;\n}\n\n/**\n * Available actions on the subscription API.\n */\nexport interface EngineServerSubscriptionRequestByType {\n subscribe: EngineServerSubscriptionParams;\n unsubscribe: EngineServerSubscriptionParams;\n list: Record<string, never>;\n}\n\nexport type EngineServerSubscriptionRequestType =\n keyof EngineServerSubscriptionRequestByType;\n\n/**\n * Top level request to send to the server.\n */\nexport type EngineServerSubscriptionRequest<\n TRequestType extends EngineServerSubscriptionRequestType,\n> = {\n id: number;\n method: TRequestType;\n} & EngineServerSubscriptionRequestByType[TRequestType];\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
1
+ {"version":3,"sources":["../../src/types/serverSubscriptionTypes.ts"],"sourcesContent":["export interface EngineServerOrderUpdateStreamParams {\n /** when not provided, subscribes to all products */\n product_id?: number;\n subaccount: string;\n}\n\nexport interface EngineServerTradeStreamParams {\n product_id: number;\n}\n\nexport interface EngineServerBestBidOfferStreamParams {\n product_id: number;\n}\n\nexport interface EngineServerFillStreamParams {\n /** when not provided, subscribes to all products */\n product_id?: number;\n subaccount: string;\n}\n\nexport interface EngineServerPositionChangeStreamParams {\n /** when not provided, subscribes to all products */\n product_id?: number;\n subaccount: string;\n}\n\nexport interface EngineServerBookDepthStreamParams {\n product_id: number;\n}\n\nexport interface EngineServerLatestCandlestickStreamParams {\n product_id: number;\n granularity: number;\n}\n\nexport interface EngineServerLiquidationStreamParams {\n /** when not provided, subscribes to all products */\n product_id?: number;\n}\n\nexport interface EngineServerFundingPaymentStreamParams {\n product_id: number;\n}\n\n/**\n * Available subscription streams\n */\nexport interface EngineServerSubscriptionStreamParamsByType {\n order_update: EngineServerOrderUpdateStreamParams;\n trade: EngineServerTradeStreamParams;\n best_bid_offer: EngineServerBestBidOfferStreamParams;\n fill: EngineServerFillStreamParams;\n position_change: EngineServerPositionChangeStreamParams;\n book_depth: EngineServerBookDepthStreamParams;\n liquidation: EngineServerLiquidationStreamParams;\n latest_candlestick: EngineServerLatestCandlestickStreamParams;\n funding_payment: EngineServerFundingPaymentStreamParams;\n}\n\nexport type EngineServerSubscriptionStreamParamsType =\n keyof EngineServerSubscriptionStreamParamsByType;\n\n/**\n * Describes a stream that can be subscribed to.\n */\nexport type EngineServerSubscriptionStream<\n TStreamType extends EngineServerSubscriptionStreamParamsType,\n> = {\n type: TStreamType;\n} & EngineServerSubscriptionStreamParamsByType[TStreamType];\n\n/**\n * Params to provide to a `subscribe` / `unsubscribe` action.\n */\nexport interface EngineServerSubscriptionParams {\n stream: EngineServerSubscriptionStream<EngineServerSubscriptionStreamParamsType>;\n}\n\n/**\n * Available actions on the subscription API.\n */\nexport interface EngineServerSubscriptionRequestByType {\n subscribe: EngineServerSubscriptionParams;\n unsubscribe: EngineServerSubscriptionParams;\n list: Record<string, never>;\n}\n\nexport type EngineServerSubscriptionRequestType =\n keyof EngineServerSubscriptionRequestByType;\n\n/**\n * Top level request to send to the server.\n */\nexport type EngineServerSubscriptionRequest<\n TRequestType extends EngineServerSubscriptionRequestType,\n> = {\n id: number;\n method: TRequestType;\n} & EngineServerSubscriptionRequestByType[TRequestType];\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -1,5 +1,6 @@
1
1
  interface EngineServerOrderUpdateStreamParams {
2
- product_id: number;
2
+ /** when not provided, subscribes to all products */
3
+ product_id?: number;
3
4
  subaccount: string;
4
5
  }
5
6
  interface EngineServerTradeStreamParams {
@@ -9,16 +10,29 @@ interface EngineServerBestBidOfferStreamParams {
9
10
  product_id: number;
10
11
  }
11
12
  interface EngineServerFillStreamParams {
12
- product_id: number;
13
+ /** when not provided, subscribes to all products */
14
+ product_id?: number;
13
15
  subaccount: string;
14
16
  }
15
17
  interface EngineServerPositionChangeStreamParams {
16
- product_id: number;
18
+ /** when not provided, subscribes to all products */
19
+ product_id?: number;
17
20
  subaccount: string;
18
21
  }
19
22
  interface EngineServerBookDepthStreamParams {
20
23
  product_id: number;
21
24
  }
25
+ interface EngineServerLatestCandlestickStreamParams {
26
+ product_id: number;
27
+ granularity: number;
28
+ }
29
+ interface EngineServerLiquidationStreamParams {
30
+ /** when not provided, subscribes to all products */
31
+ product_id?: number;
32
+ }
33
+ interface EngineServerFundingPaymentStreamParams {
34
+ product_id: number;
35
+ }
22
36
  /**
23
37
  * Available subscription streams
24
38
  */
@@ -29,6 +43,9 @@ interface EngineServerSubscriptionStreamParamsByType {
29
43
  fill: EngineServerFillStreamParams;
30
44
  position_change: EngineServerPositionChangeStreamParams;
31
45
  book_depth: EngineServerBookDepthStreamParams;
46
+ liquidation: EngineServerLiquidationStreamParams;
47
+ latest_candlestick: EngineServerLatestCandlestickStreamParams;
48
+ funding_payment: EngineServerFundingPaymentStreamParams;
32
49
  }
33
50
  type EngineServerSubscriptionStreamParamsType = keyof EngineServerSubscriptionStreamParamsByType;
34
51
  /**
@@ -60,4 +77,4 @@ type EngineServerSubscriptionRequest<TRequestType extends EngineServerSubscripti
60
77
  method: TRequestType;
61
78
  } & EngineServerSubscriptionRequestByType[TRequestType];
62
79
 
63
- export type { EngineServerBestBidOfferStreamParams, EngineServerBookDepthStreamParams, EngineServerFillStreamParams, EngineServerOrderUpdateStreamParams, EngineServerPositionChangeStreamParams, EngineServerSubscriptionParams, EngineServerSubscriptionRequest, EngineServerSubscriptionRequestByType, EngineServerSubscriptionRequestType, EngineServerSubscriptionStream, EngineServerSubscriptionStreamParamsByType, EngineServerSubscriptionStreamParamsType, EngineServerTradeStreamParams };
80
+ export type { EngineServerBestBidOfferStreamParams, EngineServerBookDepthStreamParams, EngineServerFillStreamParams, EngineServerFundingPaymentStreamParams, EngineServerLatestCandlestickStreamParams, EngineServerLiquidationStreamParams, EngineServerOrderUpdateStreamParams, EngineServerPositionChangeStreamParams, EngineServerSubscriptionParams, EngineServerSubscriptionRequest, EngineServerSubscriptionRequestByType, EngineServerSubscriptionRequestType, EngineServerSubscriptionStream, EngineServerSubscriptionStreamParamsByType, EngineServerSubscriptionStreamParamsType, EngineServerTradeStreamParams };
@@ -1,5 +1,6 @@
1
1
  interface EngineServerOrderUpdateStreamParams {
2
- product_id: number;
2
+ /** when not provided, subscribes to all products */
3
+ product_id?: number;
3
4
  subaccount: string;
4
5
  }
5
6
  interface EngineServerTradeStreamParams {
@@ -9,16 +10,29 @@ interface EngineServerBestBidOfferStreamParams {
9
10
  product_id: number;
10
11
  }
11
12
  interface EngineServerFillStreamParams {
12
- product_id: number;
13
+ /** when not provided, subscribes to all products */
14
+ product_id?: number;
13
15
  subaccount: string;
14
16
  }
15
17
  interface EngineServerPositionChangeStreamParams {
16
- product_id: number;
18
+ /** when not provided, subscribes to all products */
19
+ product_id?: number;
17
20
  subaccount: string;
18
21
  }
19
22
  interface EngineServerBookDepthStreamParams {
20
23
  product_id: number;
21
24
  }
25
+ interface EngineServerLatestCandlestickStreamParams {
26
+ product_id: number;
27
+ granularity: number;
28
+ }
29
+ interface EngineServerLiquidationStreamParams {
30
+ /** when not provided, subscribes to all products */
31
+ product_id?: number;
32
+ }
33
+ interface EngineServerFundingPaymentStreamParams {
34
+ product_id: number;
35
+ }
22
36
  /**
23
37
  * Available subscription streams
24
38
  */
@@ -29,6 +43,9 @@ interface EngineServerSubscriptionStreamParamsByType {
29
43
  fill: EngineServerFillStreamParams;
30
44
  position_change: EngineServerPositionChangeStreamParams;
31
45
  book_depth: EngineServerBookDepthStreamParams;
46
+ liquidation: EngineServerLiquidationStreamParams;
47
+ latest_candlestick: EngineServerLatestCandlestickStreamParams;
48
+ funding_payment: EngineServerFundingPaymentStreamParams;
32
49
  }
33
50
  type EngineServerSubscriptionStreamParamsType = keyof EngineServerSubscriptionStreamParamsByType;
34
51
  /**
@@ -60,4 +77,4 @@ type EngineServerSubscriptionRequest<TRequestType extends EngineServerSubscripti
60
77
  method: TRequestType;
61
78
  } & EngineServerSubscriptionRequestByType[TRequestType];
62
79
 
63
- export type { EngineServerBestBidOfferStreamParams, EngineServerBookDepthStreamParams, EngineServerFillStreamParams, EngineServerOrderUpdateStreamParams, EngineServerPositionChangeStreamParams, EngineServerSubscriptionParams, EngineServerSubscriptionRequest, EngineServerSubscriptionRequestByType, EngineServerSubscriptionRequestType, EngineServerSubscriptionStream, EngineServerSubscriptionStreamParamsByType, EngineServerSubscriptionStreamParamsType, EngineServerTradeStreamParams };
80
+ export type { EngineServerBestBidOfferStreamParams, EngineServerBookDepthStreamParams, EngineServerFillStreamParams, EngineServerFundingPaymentStreamParams, EngineServerLatestCandlestickStreamParams, EngineServerLiquidationStreamParams, EngineServerOrderUpdateStreamParams, EngineServerPositionChangeStreamParams, EngineServerSubscriptionParams, EngineServerSubscriptionRequest, EngineServerSubscriptionRequestByType, EngineServerSubscriptionRequestType, EngineServerSubscriptionStream, EngineServerSubscriptionStreamParamsByType, EngineServerSubscriptionStreamParamsType, EngineServerTradeStreamParams };
@@ -1,5 +1,5 @@
1
- export { mapEngineMarketPrice, mapEngineServerBalanceHealthContributions, mapEngineServerIsolatedPositions, mapEngineServerOrder, mapEngineServerPerpProduct, mapEngineServerSpotProduct, mapEngineServerSymbol, mapEngineServerSymbols, mapEngineServerTickLiquidity, mapSubaccountSummary } from './queryDataMappers.cjs';
1
+ export { mapEngineMarketPrice, mapEngineServerBalanceHealthContributions, mapEngineServerIsolatedPositions, mapEngineServerNlpLockedBalances, mapEngineServerNlpPoolInfo, mapEngineServerOrder, mapEngineServerPerpProduct, mapEngineServerSpotProduct, mapEngineServerSymbol, mapEngineServerSymbols, mapEngineServerTickLiquidity, mapSubaccountSummary } from './queryDataMappers.cjs';
2
2
  import '@nadohq/shared';
3
- import '../types/clientQueryTypes.cjs';
4
3
  import '../types/serverQueryTypes.cjs';
5
4
  import '../types/serverQueryModelTypes.cjs';
5
+ import '../types/clientQueryTypes.cjs';
@@ -1,5 +1,5 @@
1
- export { mapEngineMarketPrice, mapEngineServerBalanceHealthContributions, mapEngineServerIsolatedPositions, mapEngineServerOrder, mapEngineServerPerpProduct, mapEngineServerSpotProduct, mapEngineServerSymbol, mapEngineServerSymbols, mapEngineServerTickLiquidity, mapSubaccountSummary } from './queryDataMappers.js';
1
+ export { mapEngineMarketPrice, mapEngineServerBalanceHealthContributions, mapEngineServerIsolatedPositions, mapEngineServerNlpLockedBalances, mapEngineServerNlpPoolInfo, mapEngineServerOrder, mapEngineServerPerpProduct, mapEngineServerSpotProduct, mapEngineServerSymbol, mapEngineServerSymbols, mapEngineServerTickLiquidity, mapSubaccountSummary } from './queryDataMappers.js';
2
2
  import '@nadohq/shared';
3
- import '../types/clientQueryTypes.js';
4
3
  import '../types/serverQueryTypes.js';
5
4
  import '../types/serverQueryModelTypes.js';
5
+ import '../types/clientQueryTypes.js';
@@ -23,6 +23,8 @@ __export(queryDataMappers_exports, {
23
23
  mapEngineMarketPrice: () => mapEngineMarketPrice,
24
24
  mapEngineServerBalanceHealthContributions: () => mapEngineServerBalanceHealthContributions,
25
25
  mapEngineServerIsolatedPositions: () => mapEngineServerIsolatedPositions,
26
+ mapEngineServerNlpLockedBalances: () => mapEngineServerNlpLockedBalances,
27
+ mapEngineServerNlpPoolInfo: () => mapEngineServerNlpPoolInfo,
26
28
  mapEngineServerOrder: () => mapEngineServerOrder,
27
29
  mapEngineServerPerpProduct: () => mapEngineServerPerpProduct,
28
30
  mapEngineServerSpotProduct: () => mapEngineServerSpotProduct,
@@ -131,9 +133,24 @@ function mapEngineServerBalanceHealthContributions(healthContributionsForBalance
131
133
  };
132
134
  }
133
135
  function mapSubaccountSummary(baseResponse) {
136
+ return {
137
+ exists: baseResponse.exists,
138
+ ...mapSubaccountSummaryState(
139
+ baseResponse,
140
+ baseResponse.spot_products,
141
+ baseResponse.perp_products
142
+ ),
143
+ preState: baseResponse.pre_state ? mapSubaccountSummaryState(
144
+ baseResponse.pre_state,
145
+ baseResponse.spot_products,
146
+ baseResponse.perp_products
147
+ ) : void 0
148
+ };
149
+ }
150
+ function mapSubaccountSummaryState(state, spotProducts, perpProducts) {
134
151
  const balances = [];
135
- baseResponse.spot_balances.forEach((spotBalance) => {
136
- const product = baseResponse.spot_products.find(
152
+ state.spot_balances.forEach((spotBalance) => {
153
+ const product = spotProducts.find(
137
154
  (product2) => product2.product_id === spotBalance.product_id
138
155
  );
139
156
  if (!product) {
@@ -142,13 +159,13 @@ function mapSubaccountSummary(baseResponse) {
142
159
  balances.push({
143
160
  amount: (0, import_shared.toBigDecimal)(spotBalance.balance.amount),
144
161
  healthContributions: mapEngineServerBalanceHealthContributions(
145
- baseResponse.health_contributions[spotBalance.product_id]
162
+ state.health_contributions[spotBalance.product_id]
146
163
  ),
147
164
  ...mapEngineServerSpotProduct(product).product
148
165
  });
149
166
  });
150
- baseResponse.perp_balances.forEach((perpBalance) => {
151
- const product = baseResponse.perp_products.find(
167
+ state.perp_balances.forEach((perpBalance) => {
168
+ const product = perpProducts.find(
152
169
  (product2) => product2.product_id === perpBalance.product_id
153
170
  );
154
171
  if (!product) {
@@ -158,29 +175,28 @@ function mapSubaccountSummary(baseResponse) {
158
175
  amount: (0, import_shared.toBigDecimal)(perpBalance.balance.amount),
159
176
  vQuoteBalance: (0, import_shared.toBigDecimal)(perpBalance.balance.v_quote_balance),
160
177
  healthContributions: mapEngineServerBalanceHealthContributions(
161
- baseResponse.health_contributions[perpBalance.product_id]
178
+ state.health_contributions[perpBalance.product_id]
162
179
  ),
163
180
  ...mapEngineServerPerpProduct(product).product
164
181
  });
165
182
  });
166
183
  return {
167
184
  balances,
168
- exists: baseResponse.exists,
169
185
  health: {
170
186
  initial: {
171
- health: (0, import_shared.toBigDecimal)(baseResponse.healths[0].health),
172
- assets: (0, import_shared.toBigDecimal)(baseResponse.healths[0].assets),
173
- liabilities: (0, import_shared.toBigDecimal)(baseResponse.healths[0].liabilities)
187
+ health: (0, import_shared.toBigDecimal)(state.healths[0].health),
188
+ assets: (0, import_shared.toBigDecimal)(state.healths[0].assets),
189
+ liabilities: (0, import_shared.toBigDecimal)(state.healths[0].liabilities)
174
190
  },
175
191
  maintenance: {
176
- health: (0, import_shared.toBigDecimal)(baseResponse.healths[1].health),
177
- assets: (0, import_shared.toBigDecimal)(baseResponse.healths[1].assets),
178
- liabilities: (0, import_shared.toBigDecimal)(baseResponse.healths[1].liabilities)
192
+ health: (0, import_shared.toBigDecimal)(state.healths[1].health),
193
+ assets: (0, import_shared.toBigDecimal)(state.healths[1].assets),
194
+ liabilities: (0, import_shared.toBigDecimal)(state.healths[1].liabilities)
179
195
  },
180
196
  unweighted: {
181
- health: (0, import_shared.toBigDecimal)(baseResponse.healths[2].health),
182
- assets: (0, import_shared.toBigDecimal)(baseResponse.healths[2].assets),
183
- liabilities: (0, import_shared.toBigDecimal)(baseResponse.healths[2].liabilities)
197
+ health: (0, import_shared.toBigDecimal)(state.healths[2].health),
198
+ assets: (0, import_shared.toBigDecimal)(state.healths[2].assets),
199
+ liabilities: (0, import_shared.toBigDecimal)(state.healths[2].liabilities)
184
200
  }
185
201
  }
186
202
  };
@@ -236,8 +252,6 @@ function mapEngineServerSymbol(engineServerSymbol) {
236
252
  priceIncrement: (0, import_shared.removeDecimals)(engineServerSymbol.price_increment_x18),
237
253
  sizeIncrement: (0, import_shared.toBigDecimal)(engineServerSymbol.size_increment),
238
254
  minSize: (0, import_shared.toBigDecimal)(engineServerSymbol.min_size),
239
- minDepth: (0, import_shared.removeDecimals)(engineServerSymbol.min_depth_x18),
240
- maxSpreadRate: (0, import_shared.removeDecimals)(engineServerSymbol.max_spread_rate_x18),
241
255
  makerFeeRate: (0, import_shared.removeDecimals)(engineServerSymbol.maker_fee_rate_x18),
242
256
  takerFeeRate: (0, import_shared.removeDecimals)(engineServerSymbol.taker_fee_rate_x18),
243
257
  longWeightInitial: (0, import_shared.removeDecimals)(
@@ -245,7 +259,8 @@ function mapEngineServerSymbol(engineServerSymbol) {
245
259
  ),
246
260
  longWeightMaintenance: (0, import_shared.removeDecimals)(
247
261
  engineServerSymbol.long_weight_maintenance_x18
248
- )
262
+ ),
263
+ maxOpenInterest: (0, import_shared.removeDecimals)(engineServerSymbol.max_open_interest_x18)
249
264
  };
250
265
  }
251
266
  function mapEngineMarketPrice(baseResponse) {
@@ -255,11 +270,43 @@ function mapEngineMarketPrice(baseResponse) {
255
270
  productId: baseResponse.product_id
256
271
  };
257
272
  }
273
+ function mapEngineServerNlpLockedBalances(baseResponse) {
274
+ const lockedBalances = baseResponse.locked_balances.map((lockedBalance) => ({
275
+ productId: lockedBalance.balance.product_id,
276
+ balance: (0, import_shared.toBigDecimal)(lockedBalance.balance.balance.amount),
277
+ unlockedAt: lockedBalance.unlocked_at
278
+ }));
279
+ return {
280
+ lockedBalances,
281
+ balanceLocked: {
282
+ productId: baseResponse.balance_locked.product_id,
283
+ balance: (0, import_shared.toBigDecimal)(baseResponse.balance_locked.balance.amount)
284
+ },
285
+ balanceUnlocked: {
286
+ productId: baseResponse.balance_unlocked.product_id,
287
+ balance: (0, import_shared.toBigDecimal)(baseResponse.balance_unlocked.balance.amount)
288
+ }
289
+ };
290
+ }
291
+ function mapEngineServerNlpPoolInfo(baseResponse) {
292
+ return {
293
+ nlpPools: baseResponse.nlp_pools.map((pool) => ({
294
+ poolId: pool.pool_id,
295
+ subaccountHex: pool.subaccount,
296
+ ownerAddress: pool.owner,
297
+ balanceWeight: (0, import_shared.removeDecimals)(pool.balance_weight_x18),
298
+ subaccountInfo: mapSubaccountSummary(pool.subaccount_info),
299
+ openOrders: pool.open_orders.map(mapEngineServerOrder)
300
+ }))
301
+ };
302
+ }
258
303
  // Annotate the CommonJS export names for ESM import in node:
259
304
  0 && (module.exports = {
260
305
  mapEngineMarketPrice,
261
306
  mapEngineServerBalanceHealthContributions,
262
307
  mapEngineServerIsolatedPositions,
308
+ mapEngineServerNlpLockedBalances,
309
+ mapEngineServerNlpPoolInfo,
263
310
  mapEngineServerOrder,
264
311
  mapEngineServerPerpProduct,
265
312
  mapEngineServerSpotProduct,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/queryDataMappers.ts"],"sourcesContent":["import {\n BalanceHealthContributions,\n calcTotalBorrowed,\n calcTotalDeposited,\n mapValues,\n PerpMarket,\n ProductEngineType,\n removeDecimals,\n SpotMarket,\n subaccountFromHex,\n toBigDecimal,\n unpackOrderAppendix,\n} from '@nadohq/shared';\nimport {\n EngineMarketPrice,\n EngineOrder,\n EnginePriceTickLiquidity,\n EngineServerIsolatedPositionsResponse,\n EngineServerMarketPrice,\n EngineServerOrderResponse,\n EngineServerPerpProduct,\n EngineServerPriceTickLiquidity,\n EngineServerSpotProduct,\n EngineServerSubaccountInfoResponse,\n EngineServerSymbol,\n EngineServerSymbolsResponse,\n EngineSymbol,\n EngineSymbolsResponse,\n GetEngineIsolatedPositionsResponse,\n GetEngineSubaccountSummaryResponse,\n} from '../types';\nimport { mapEngineServerProductType } from './productEngineTypeMappers';\n\nexport function mapEngineServerTickLiquidity(\n tick: EngineServerPriceTickLiquidity,\n): EnginePriceTickLiquidity {\n return {\n price: removeDecimals(tick[0]),\n liquidity: toBigDecimal(tick[1]),\n };\n}\n\nexport function mapEngineServerOrder(\n order: EngineServerOrderResponse,\n): EngineOrder {\n const subaccount = subaccountFromHex(order.sender);\n return {\n digest: order.digest,\n expiration: Number(order.expiration),\n nonce: order.nonce,\n price: removeDecimals(order.price_x18),\n productId: order.product_id,\n subaccountOwner: subaccount.subaccountOwner,\n subaccountName: subaccount.subaccountName,\n totalAmount: toBigDecimal(order.amount),\n unfilledAmount: toBigDecimal(order.unfilled_amount),\n placementTime: order.placed_at,\n appendix: unpackOrderAppendix(order.appendix),\n };\n}\n\nexport function mapEngineServerSpotProduct(\n product: EngineServerSpotProduct,\n): SpotMarket {\n return {\n type: ProductEngineType.SPOT,\n productId: product.product_id,\n minSize: toBigDecimal(product.book_info.min_size),\n priceIncrement: removeDecimals(product.book_info.price_increment_x18),\n sizeIncrement: toBigDecimal(product.book_info.size_increment),\n product: {\n productId: product.product_id,\n type: ProductEngineType.SPOT,\n totalBorrowed: calcTotalBorrowed(\n product.state.total_borrows_normalized,\n product.state.cumulative_borrows_multiplier_x18,\n ),\n totalDeposited: calcTotalDeposited(\n product.state.total_deposits_normalized,\n product.state.cumulative_deposits_multiplier_x18,\n ),\n oraclePrice: removeDecimals(product.oracle_price_x18),\n interestFloor: removeDecimals(product.config.interest_floor_x18),\n interestInflectionUtil: removeDecimals(\n product.config.interest_inflection_util_x18,\n ),\n interestLargeCap: removeDecimals(product.config.interest_large_cap_x18),\n interestSmallCap: removeDecimals(product.config.interest_small_cap_x18),\n minDepositRate: removeDecimals(product.config.min_deposit_rate_x18),\n longWeightInitial: removeDecimals(product.risk.long_weight_initial_x18),\n longWeightMaintenance: removeDecimals(\n product.risk.long_weight_maintenance_x18,\n ),\n shortWeightInitial: removeDecimals(product.risk.short_weight_initial_x18),\n shortWeightMaintenance: removeDecimals(\n product.risk.short_weight_maintenance_x18,\n ),\n tokenAddr: product.config.token,\n },\n };\n}\n\nexport function mapEngineServerPerpProduct(\n product: EngineServerPerpProduct,\n): PerpMarket {\n return {\n type: ProductEngineType.PERP,\n productId: product.product_id,\n minSize: toBigDecimal(product.book_info.min_size),\n priceIncrement: removeDecimals(product.book_info.price_increment_x18),\n sizeIncrement: toBigDecimal(product.book_info.size_increment),\n product: {\n productId: product.product_id,\n type: ProductEngineType.PERP,\n oraclePrice: removeDecimals(product.oracle_price_x18),\n longWeightInitial: removeDecimals(product.risk.long_weight_initial_x18),\n longWeightMaintenance: removeDecimals(\n product.risk.long_weight_maintenance_x18,\n ),\n shortWeightInitial: removeDecimals(product.risk.short_weight_initial_x18),\n shortWeightMaintenance: removeDecimals(\n product.risk.short_weight_maintenance_x18,\n ),\n openInterest: toBigDecimal(product.state.open_interest),\n cumulativeFundingLong: removeDecimals(\n product.state.cumulative_funding_long_x18,\n ),\n cumulativeFundingShort: removeDecimals(\n product.state.cumulative_funding_short_x18,\n ),\n },\n };\n}\n\nexport function mapEngineServerBalanceHealthContributions(\n healthContributionsForBalance: string[],\n): BalanceHealthContributions {\n return {\n initial: toBigDecimal(healthContributionsForBalance[0]),\n maintenance: toBigDecimal(healthContributionsForBalance[1]),\n unweighted: toBigDecimal(healthContributionsForBalance[2]),\n };\n}\n\nexport function mapSubaccountSummary(\n baseResponse: EngineServerSubaccountInfoResponse,\n): GetEngineSubaccountSummaryResponse {\n const balances: GetEngineSubaccountSummaryResponse['balances'] = [];\n\n baseResponse.spot_balances.forEach((spotBalance) => {\n const product = baseResponse.spot_products.find(\n (product) => product.product_id === spotBalance.product_id,\n );\n if (!product) {\n throw Error(`Could not find product ${spotBalance.product_id}`);\n }\n\n balances.push({\n amount: toBigDecimal(spotBalance.balance.amount),\n healthContributions: mapEngineServerBalanceHealthContributions(\n baseResponse.health_contributions[spotBalance.product_id],\n ),\n ...mapEngineServerSpotProduct(product).product,\n });\n });\n\n baseResponse.perp_balances.forEach((perpBalance) => {\n const product = baseResponse.perp_products.find(\n (product) => product.product_id === perpBalance.product_id,\n );\n if (!product) {\n throw Error(`Could not find product ${perpBalance.product_id}`);\n }\n\n balances.push({\n amount: toBigDecimal(perpBalance.balance.amount),\n vQuoteBalance: toBigDecimal(perpBalance.balance.v_quote_balance),\n healthContributions: mapEngineServerBalanceHealthContributions(\n baseResponse.health_contributions[perpBalance.product_id],\n ),\n ...mapEngineServerPerpProduct(product).product,\n });\n });\n\n return {\n balances: balances,\n exists: baseResponse.exists,\n health: {\n initial: {\n health: toBigDecimal(baseResponse.healths[0].health),\n assets: toBigDecimal(baseResponse.healths[0].assets),\n liabilities: toBigDecimal(baseResponse.healths[0].liabilities),\n },\n maintenance: {\n health: toBigDecimal(baseResponse.healths[1].health),\n assets: toBigDecimal(baseResponse.healths[1].assets),\n liabilities: toBigDecimal(baseResponse.healths[1].liabilities),\n },\n unweighted: {\n health: toBigDecimal(baseResponse.healths[2].health),\n assets: toBigDecimal(baseResponse.healths[2].assets),\n liabilities: toBigDecimal(baseResponse.healths[2].liabilities),\n },\n },\n };\n}\n\nexport function mapEngineServerIsolatedPositions(\n baseResponse: EngineServerIsolatedPositionsResponse,\n): GetEngineIsolatedPositionsResponse {\n return baseResponse.isolated_positions.map((position) => {\n const perpBalance = position.base_balance;\n const quoteBalance = position.quote_balance;\n\n return {\n subaccount: subaccountFromHex(position.subaccount),\n healths: {\n initial: toBigDecimal(position.healths[0].health),\n maintenance: toBigDecimal(position.healths[1].health),\n unweighted: toBigDecimal(position.healths[2].health),\n },\n baseBalance: {\n amount: toBigDecimal(perpBalance.balance.amount),\n vQuoteBalance: toBigDecimal(perpBalance.balance.v_quote_balance),\n // Health contributions === healths for an isolated position\n healthContributions: {\n initial: toBigDecimal(position.base_healths[0]),\n maintenance: toBigDecimal(position.base_healths[1]),\n unweighted: toBigDecimal(position.base_healths[2]),\n },\n ...mapEngineServerPerpProduct(position.base_product).product,\n },\n quoteBalance: {\n amount: toBigDecimal(quoteBalance.balance.amount),\n healthContributions: {\n initial: toBigDecimal(position.quote_healths[0]),\n maintenance: toBigDecimal(position.quote_healths[1]),\n unweighted: toBigDecimal(position.quote_healths[2]),\n },\n ...mapEngineServerSpotProduct(position.quote_product).product,\n },\n };\n });\n}\n\nexport function mapEngineServerSymbols(\n baseResponse: EngineServerSymbolsResponse,\n): EngineSymbolsResponse {\n const symbols: Record<string, EngineSymbol> = mapValues(\n baseResponse.symbols,\n mapEngineServerSymbol,\n );\n\n return {\n symbols,\n };\n}\n\nexport function mapEngineServerSymbol(\n engineServerSymbol: EngineServerSymbol,\n): EngineSymbol {\n return {\n type: mapEngineServerProductType(engineServerSymbol.type),\n productId: engineServerSymbol.product_id,\n symbol: engineServerSymbol.symbol,\n priceIncrement: removeDecimals(engineServerSymbol.price_increment_x18),\n sizeIncrement: toBigDecimal(engineServerSymbol.size_increment),\n minSize: toBigDecimal(engineServerSymbol.min_size),\n minDepth: removeDecimals(engineServerSymbol.min_depth_x18),\n maxSpreadRate: removeDecimals(engineServerSymbol.max_spread_rate_x18),\n makerFeeRate: removeDecimals(engineServerSymbol.maker_fee_rate_x18),\n takerFeeRate: removeDecimals(engineServerSymbol.taker_fee_rate_x18),\n longWeightInitial: removeDecimals(\n engineServerSymbol.long_weight_initial_x18,\n ),\n longWeightMaintenance: removeDecimals(\n engineServerSymbol.long_weight_maintenance_x18,\n ),\n };\n}\n\nexport function mapEngineMarketPrice(\n baseResponse: EngineServerMarketPrice,\n): EngineMarketPrice {\n return {\n ask: removeDecimals(baseResponse.ask_x18),\n bid: removeDecimals(baseResponse.bid_x18),\n productId: baseResponse.product_id,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAYO;AAmBP,sCAA2C;AAEpC,SAAS,6BACd,MAC0B;AAC1B,SAAO;AAAA,IACL,WAAO,8BAAe,KAAK,CAAC,CAAC;AAAA,IAC7B,eAAW,4BAAa,KAAK,CAAC,CAAC;AAAA,EACjC;AACF;AAEO,SAAS,qBACd,OACa;AACb,QAAM,iBAAa,iCAAkB,MAAM,MAAM;AACjD,SAAO;AAAA,IACL,QAAQ,MAAM;AAAA,IACd,YAAY,OAAO,MAAM,UAAU;AAAA,IACnC,OAAO,MAAM;AAAA,IACb,WAAO,8BAAe,MAAM,SAAS;AAAA,IACrC,WAAW,MAAM;AAAA,IACjB,iBAAiB,WAAW;AAAA,IAC5B,gBAAgB,WAAW;AAAA,IAC3B,iBAAa,4BAAa,MAAM,MAAM;AAAA,IACtC,oBAAgB,4BAAa,MAAM,eAAe;AAAA,IAClD,eAAe,MAAM;AAAA,IACrB,cAAU,mCAAoB,MAAM,QAAQ;AAAA,EAC9C;AACF;AAEO,SAAS,2BACd,SACY;AACZ,SAAO;AAAA,IACL,MAAM,gCAAkB;AAAA,IACxB,WAAW,QAAQ;AAAA,IACnB,aAAS,4BAAa,QAAQ,UAAU,QAAQ;AAAA,IAChD,oBAAgB,8BAAe,QAAQ,UAAU,mBAAmB;AAAA,IACpE,mBAAe,4BAAa,QAAQ,UAAU,cAAc;AAAA,IAC5D,SAAS;AAAA,MACP,WAAW,QAAQ;AAAA,MACnB,MAAM,gCAAkB;AAAA,MACxB,mBAAe;AAAA,QACb,QA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AAAA,MACrB,mBAAmB;AAAA,IACrB;AAAA,EACF;AACF;AAEO,SAAS,qBACd,cACmB;AACnB,SAAO;AAAA,IACL,SAAK,8BAAe,aAAa,OAAO;AAAA,IACxC,SAAK,8BAAe,aAAa,OAAO;AAAA,IACxC,WAAW,aAAa;AAAA,EAC1B;AACF;","names":["product"]}
1
+ {"version":3,"sources":["../../src/utils/queryDataMappers.ts"],"sourcesContent":["import {\n BalanceHealthContributions,\n calcTotalBorrowed,\n calcTotalDeposited,\n mapValues,\n PerpMarket,\n ProductEngineType,\n removeDecimals,\n SpotMarket,\n subaccountFromHex,\n toBigDecimal,\n unpackOrderAppendix,\n} from '@nadohq/shared';\nimport {\n EngineMarketPrice,\n EngineNlpLockedBalance,\n EngineOrder,\n EnginePriceTickLiquidity,\n EngineServerIsolatedPositionsResponse,\n EngineServerMarketPrice,\n EngineServerNlpLockedBalancesResponse,\n EngineServerNlpPoolInfoResponse,\n EngineServerOrderResponse,\n EngineServerPerpProduct,\n EngineServerPriceTickLiquidity,\n EngineServerSpotProduct,\n EngineServerSubaccountInfoResponse,\n EngineServerSubaccountInfoState,\n EngineServerSymbol,\n EngineServerSymbolsResponse,\n EngineSymbol,\n EngineSymbolsResponse,\n GetEngineIsolatedPositionsResponse,\n GetEngineNlpLockedBalancesResponse,\n GetEngineNlpPoolInfoResponse,\n GetEngineSubaccountSummaryResponse,\n SubaccountSummaryState,\n} from '../types';\nimport { mapEngineServerProductType } from './productEngineTypeMappers';\n\nexport function mapEngineServerTickLiquidity(\n tick: EngineServerPriceTickLiquidity,\n): EnginePriceTickLiquidity {\n return {\n price: removeDecimals(tick[0]),\n liquidity: toBigDecimal(tick[1]),\n };\n}\n\nexport function mapEngineServerOrder(\n order: EngineServerOrderResponse,\n): EngineOrder {\n const subaccount = subaccountFromHex(order.sender);\n return {\n digest: order.digest,\n expiration: Number(order.expiration),\n nonce: order.nonce,\n price: removeDecimals(order.price_x18),\n productId: order.product_id,\n subaccountOwner: subaccount.subaccountOwner,\n subaccountName: subaccount.subaccountName,\n totalAmount: toBigDecimal(order.amount),\n unfilledAmount: toBigDecimal(order.unfilled_amount),\n placementTime: order.placed_at,\n appendix: unpackOrderAppendix(order.appendix),\n };\n}\n\nexport function mapEngineServerSpotProduct(\n product: EngineServerSpotProduct,\n): SpotMarket {\n return {\n type: ProductEngineType.SPOT,\n productId: product.product_id,\n minSize: toBigDecimal(product.book_info.min_size),\n priceIncrement: removeDecimals(product.book_info.price_increment_x18),\n sizeIncrement: toBigDecimal(product.book_info.size_increment),\n product: {\n productId: product.product_id,\n type: ProductEngineType.SPOT,\n totalBorrowed: calcTotalBorrowed(\n product.state.total_borrows_normalized,\n product.state.cumulative_borrows_multiplier_x18,\n ),\n totalDeposited: calcTotalDeposited(\n product.state.total_deposits_normalized,\n product.state.cumulative_deposits_multiplier_x18,\n ),\n oraclePrice: removeDecimals(product.oracle_price_x18),\n interestFloor: removeDecimals(product.config.interest_floor_x18),\n interestInflectionUtil: removeDecimals(\n product.config.interest_inflection_util_x18,\n ),\n interestLargeCap: removeDecimals(product.config.interest_large_cap_x18),\n interestSmallCap: removeDecimals(product.config.interest_small_cap_x18),\n minDepositRate: removeDecimals(product.config.min_deposit_rate_x18),\n longWeightInitial: removeDecimals(product.risk.long_weight_initial_x18),\n longWeightMaintenance: removeDecimals(\n product.risk.long_weight_maintenance_x18,\n ),\n shortWeightInitial: removeDecimals(product.risk.short_weight_initial_x18),\n shortWeightMaintenance: removeDecimals(\n product.risk.short_weight_maintenance_x18,\n ),\n tokenAddr: product.config.token,\n },\n };\n}\n\nexport function mapEngineServerPerpProduct(\n product: EngineServerPerpProduct,\n): PerpMarket {\n return {\n type: ProductEngineType.PERP,\n productId: product.product_id,\n minSize: toBigDecimal(product.book_info.min_size),\n priceIncrement: removeDecimals(product.book_info.price_increment_x18),\n sizeIncrement: toBigDecimal(product.book_info.size_increment),\n product: {\n productId: product.product_id,\n type: ProductEngineType.PERP,\n oraclePrice: removeDecimals(product.oracle_price_x18),\n longWeightInitial: removeDecimals(product.risk.long_weight_initial_x18),\n longWeightMaintenance: removeDecimals(\n product.risk.long_weight_maintenance_x18,\n ),\n shortWeightInitial: removeDecimals(product.risk.short_weight_initial_x18),\n shortWeightMaintenance: removeDecimals(\n product.risk.short_weight_maintenance_x18,\n ),\n openInterest: toBigDecimal(product.state.open_interest),\n cumulativeFundingLong: removeDecimals(\n product.state.cumulative_funding_long_x18,\n ),\n cumulativeFundingShort: removeDecimals(\n product.state.cumulative_funding_short_x18,\n ),\n },\n };\n}\n\nexport function mapEngineServerBalanceHealthContributions(\n healthContributionsForBalance: string[],\n): BalanceHealthContributions {\n return {\n initial: toBigDecimal(healthContributionsForBalance[0]),\n maintenance: toBigDecimal(healthContributionsForBalance[1]),\n unweighted: toBigDecimal(healthContributionsForBalance[2]),\n };\n}\n\nexport function mapSubaccountSummary(\n baseResponse: EngineServerSubaccountInfoResponse,\n): GetEngineSubaccountSummaryResponse {\n return {\n exists: baseResponse.exists,\n ...mapSubaccountSummaryState(\n baseResponse,\n baseResponse.spot_products,\n baseResponse.perp_products,\n ),\n preState: baseResponse.pre_state\n ? mapSubaccountSummaryState(\n baseResponse.pre_state,\n baseResponse.spot_products,\n baseResponse.perp_products,\n )\n : undefined,\n };\n}\n\nfunction mapSubaccountSummaryState(\n state: EngineServerSubaccountInfoState,\n spotProducts: EngineServerSubaccountInfoResponse['spot_products'],\n perpProducts: EngineServerSubaccountInfoResponse['perp_products'],\n): SubaccountSummaryState {\n const balances: SubaccountSummaryState['balances'] = [];\n\n state.spot_balances.forEach((spotBalance) => {\n const product = spotProducts.find(\n (product) => product.product_id === spotBalance.product_id,\n );\n if (!product) {\n throw Error(`Could not find product ${spotBalance.product_id}`);\n }\n\n balances.push({\n amount: toBigDecimal(spotBalance.balance.amount),\n healthContributions: mapEngineServerBalanceHealthContributions(\n state.health_contributions[spotBalance.product_id],\n ),\n ...mapEngineServerSpotProduct(product).product,\n });\n });\n\n state.perp_balances.forEach((perpBalance) => {\n const product = perpProducts.find(\n (product) => product.product_id === perpBalance.product_id,\n );\n if (!product) {\n throw Error(`Could not find product ${perpBalance.product_id}`);\n }\n\n balances.push({\n amount: toBigDecimal(perpBalance.balance.amount),\n vQuoteBalance: toBigDecimal(perpBalance.balance.v_quote_balance),\n healthContributions: mapEngineServerBalanceHealthContributions(\n state.health_contributions[perpBalance.product_id],\n ),\n ...mapEngineServerPerpProduct(product).product,\n });\n });\n\n return {\n balances,\n health: {\n initial: {\n health: toBigDecimal(state.healths[0].health),\n assets: toBigDecimal(state.healths[0].assets),\n liabilities: toBigDecimal(state.healths[0].liabilities),\n },\n maintenance: {\n health: toBigDecimal(state.healths[1].health),\n assets: toBigDecimal(state.healths[1].assets),\n liabilities: toBigDecimal(state.healths[1].liabilities),\n },\n unweighted: {\n health: toBigDecimal(state.healths[2].health),\n assets: toBigDecimal(state.healths[2].assets),\n liabilities: toBigDecimal(state.healths[2].liabilities),\n },\n },\n };\n}\n\nexport function mapEngineServerIsolatedPositions(\n baseResponse: EngineServerIsolatedPositionsResponse,\n): GetEngineIsolatedPositionsResponse {\n return baseResponse.isolated_positions.map((position) => {\n const perpBalance = position.base_balance;\n const quoteBalance = position.quote_balance;\n\n return {\n subaccount: subaccountFromHex(position.subaccount),\n healths: {\n initial: toBigDecimal(position.healths[0].health),\n maintenance: toBigDecimal(position.healths[1].health),\n unweighted: toBigDecimal(position.healths[2].health),\n },\n baseBalance: {\n amount: toBigDecimal(perpBalance.balance.amount),\n vQuoteBalance: toBigDecimal(perpBalance.balance.v_quote_balance),\n // Health contributions === healths for an isolated position\n healthContributions: {\n initial: toBigDecimal(position.base_healths[0]),\n maintenance: toBigDecimal(position.base_healths[1]),\n unweighted: toBigDecimal(position.base_healths[2]),\n },\n ...mapEngineServerPerpProduct(position.base_product).product,\n },\n quoteBalance: {\n amount: toBigDecimal(quoteBalance.balance.amount),\n healthContributions: {\n initial: toBigDecimal(position.quote_healths[0]),\n maintenance: toBigDecimal(position.quote_healths[1]),\n unweighted: toBigDecimal(position.quote_healths[2]),\n },\n ...mapEngineServerSpotProduct(position.quote_product).product,\n },\n };\n });\n}\n\nexport function mapEngineServerSymbols(\n baseResponse: EngineServerSymbolsResponse,\n): EngineSymbolsResponse {\n const symbols: Record<string, EngineSymbol> = mapValues(\n baseResponse.symbols,\n mapEngineServerSymbol,\n );\n\n return {\n symbols,\n };\n}\n\nexport function mapEngineServerSymbol(\n engineServerSymbol: EngineServerSymbol,\n): EngineSymbol {\n return {\n type: mapEngineServerProductType(engineServerSymbol.type),\n productId: engineServerSymbol.product_id,\n symbol: engineServerSymbol.symbol,\n priceIncrement: removeDecimals(engineServerSymbol.price_increment_x18),\n sizeIncrement: toBigDecimal(engineServerSymbol.size_increment),\n minSize: toBigDecimal(engineServerSymbol.min_size),\n makerFeeRate: removeDecimals(engineServerSymbol.maker_fee_rate_x18),\n takerFeeRate: removeDecimals(engineServerSymbol.taker_fee_rate_x18),\n longWeightInitial: removeDecimals(\n engineServerSymbol.long_weight_initial_x18,\n ),\n longWeightMaintenance: removeDecimals(\n engineServerSymbol.long_weight_maintenance_x18,\n ),\n maxOpenInterest: removeDecimals(engineServerSymbol.max_open_interest_x18),\n };\n}\n\nexport function mapEngineMarketPrice(\n baseResponse: EngineServerMarketPrice,\n): EngineMarketPrice {\n return {\n ask: removeDecimals(baseResponse.ask_x18),\n bid: removeDecimals(baseResponse.bid_x18),\n productId: baseResponse.product_id,\n };\n}\n\nexport function mapEngineServerNlpLockedBalances(\n baseResponse: EngineServerNlpLockedBalancesResponse,\n): GetEngineNlpLockedBalancesResponse {\n const lockedBalances: EngineNlpLockedBalance[] =\n baseResponse.locked_balances.map((lockedBalance) => ({\n productId: lockedBalance.balance.product_id,\n balance: toBigDecimal(lockedBalance.balance.balance.amount),\n unlockedAt: lockedBalance.unlocked_at,\n }));\n\n return {\n lockedBalances,\n balanceLocked: {\n productId: baseResponse.balance_locked.product_id,\n balance: toBigDecimal(baseResponse.balance_locked.balance.amount),\n },\n balanceUnlocked: {\n productId: baseResponse.balance_unlocked.product_id,\n balance: toBigDecimal(baseResponse.balance_unlocked.balance.amount),\n },\n };\n}\n\nexport function mapEngineServerNlpPoolInfo(\n baseResponse: EngineServerNlpPoolInfoResponse,\n): GetEngineNlpPoolInfoResponse {\n return {\n nlpPools: baseResponse.nlp_pools.map((pool) => ({\n poolId: pool.pool_id,\n subaccountHex: pool.subaccount,\n ownerAddress: pool.owner,\n balanceWeight: removeDecimals(pool.balance_weight_x18),\n subaccountInfo: mapSubaccountSummary(pool.subaccount_info),\n openOrders: pool.open_orders.map(mapEngineServerOrder),\n })),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAYO;AA0BP,sCAA2C;AAEpC,SAAS,6BACd,MAC0B;AAC1B,SAAO;AAAA,IACL,WAAO,8BAAe,KAAK,CAAC,CAAC;AAAA,IAC7B,eAAW,4BAAa,KAAK,CAAC,CAAC;AAAA,EACjC;AACF;AAEO,SAAS,qBACd,OACa;AACb,QAAM,iBAAa,iCAAkB,MAAM,MAAM;AACjD,SAAO;AAAA,IACL,QAAQ,MAAM;AAAA,IACd,YAAY,OAAO,MAAM,UAAU;AAAA,IACnC,OAAO,MAAM;AAAA,IACb,WAAO,8BAAe,MAAM,SAAS;AAAA,IACrC,WAAW,MAAM;AAAA,IACjB,iBAAiB,WAAW;AAAA,IAC5B,gBAAgB,WAAW;AAAA,IAC3B,iBAAa,4BAAa,MAAM,MAAM;AAAA,IACtC,oBAAgB,4BAAa,MAAM,eAAe;AAAA,IAClD,eAAe,MAAM;AAAA,IACrB,cAAU,mCAAoB,MAAM,QAAQ;AAAA,EAC9C;AACF;AAEO,SAAS,2BACd,SACY;AACZ,SAAO;AAAA,IACL,MAAM,gCAAkB;AAAA,IACxB,WAAW,QAAQ;AAAA,IACnB,aAAS,4BAAa,QA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AA,MACnB,mBAAe,8BAAe,KAAK,kBAAkB;AAAA,MACrD,gBAAgB,qBAAqB,KAAK,eAAe;AAAA,MACzD,YAAY,KAAK,YAAY,IAAI,oBAAoB;AAAA,IACvD,EAAE;AAAA,EACJ;AACF;","names":["product"]}
@@ -1,6 +1,6 @@
1
1
  import { SpotMarket, PerpMarket, BalanceHealthContributions } from '@nadohq/shared';
2
- import { EnginePriceTickLiquidity, EngineOrder, GetEngineSubaccountSummaryResponse, GetEngineIsolatedPositionsResponse, EngineSymbolsResponse, EngineSymbol, EngineMarketPrice } from '../types/clientQueryTypes.cjs';
3
- import { EngineServerPriceTickLiquidity, EngineServerOrderResponse, EngineServerSubaccountInfoResponse, EngineServerIsolatedPositionsResponse, EngineServerSymbolsResponse, EngineServerSymbol, EngineServerMarketPrice } from '../types/serverQueryTypes.cjs';
2
+ import { EngineServerPriceTickLiquidity, EngineServerOrderResponse, EngineServerSubaccountInfoResponse, EngineServerIsolatedPositionsResponse, EngineServerSymbolsResponse, EngineServerSymbol, EngineServerMarketPrice, EngineServerNlpLockedBalancesResponse, EngineServerNlpPoolInfoResponse } from '../types/serverQueryTypes.cjs';
3
+ import { EnginePriceTickLiquidity, EngineOrder, GetEngineSubaccountSummaryResponse, GetEngineIsolatedPositionsResponse, EngineSymbolsResponse, EngineSymbol, EngineMarketPrice, GetEngineNlpLockedBalancesResponse, GetEngineNlpPoolInfoResponse } from '../types/clientQueryTypes.cjs';
4
4
  import { EngineServerSpotProduct, EngineServerPerpProduct } from '../types/serverQueryModelTypes.cjs';
5
5
 
6
6
  declare function mapEngineServerTickLiquidity(tick: EngineServerPriceTickLiquidity): EnginePriceTickLiquidity;
@@ -13,5 +13,7 @@ declare function mapEngineServerIsolatedPositions(baseResponse: EngineServerIsol
13
13
  declare function mapEngineServerSymbols(baseResponse: EngineServerSymbolsResponse): EngineSymbolsResponse;
14
14
  declare function mapEngineServerSymbol(engineServerSymbol: EngineServerSymbol): EngineSymbol;
15
15
  declare function mapEngineMarketPrice(baseResponse: EngineServerMarketPrice): EngineMarketPrice;
16
+ declare function mapEngineServerNlpLockedBalances(baseResponse: EngineServerNlpLockedBalancesResponse): GetEngineNlpLockedBalancesResponse;
17
+ declare function mapEngineServerNlpPoolInfo(baseResponse: EngineServerNlpPoolInfoResponse): GetEngineNlpPoolInfoResponse;
16
18
 
17
- export { mapEngineMarketPrice, mapEngineServerBalanceHealthContributions, mapEngineServerIsolatedPositions, mapEngineServerOrder, mapEngineServerPerpProduct, mapEngineServerSpotProduct, mapEngineServerSymbol, mapEngineServerSymbols, mapEngineServerTickLiquidity, mapSubaccountSummary };
19
+ export { mapEngineMarketPrice, mapEngineServerBalanceHealthContributions, mapEngineServerIsolatedPositions, mapEngineServerNlpLockedBalances, mapEngineServerNlpPoolInfo, mapEngineServerOrder, mapEngineServerPerpProduct, mapEngineServerSpotProduct, mapEngineServerSymbol, mapEngineServerSymbols, mapEngineServerTickLiquidity, mapSubaccountSummary };
@@ -1,6 +1,6 @@
1
1
  import { SpotMarket, PerpMarket, BalanceHealthContributions } from '@nadohq/shared';
2
- import { EnginePriceTickLiquidity, EngineOrder, GetEngineSubaccountSummaryResponse, GetEngineIsolatedPositionsResponse, EngineSymbolsResponse, EngineSymbol, EngineMarketPrice } from '../types/clientQueryTypes.js';
3
- import { EngineServerPriceTickLiquidity, EngineServerOrderResponse, EngineServerSubaccountInfoResponse, EngineServerIsolatedPositionsResponse, EngineServerSymbolsResponse, EngineServerSymbol, EngineServerMarketPrice } from '../types/serverQueryTypes.js';
2
+ import { EngineServerPriceTickLiquidity, EngineServerOrderResponse, EngineServerSubaccountInfoResponse, EngineServerIsolatedPositionsResponse, EngineServerSymbolsResponse, EngineServerSymbol, EngineServerMarketPrice, EngineServerNlpLockedBalancesResponse, EngineServerNlpPoolInfoResponse } from '../types/serverQueryTypes.js';
3
+ import { EnginePriceTickLiquidity, EngineOrder, GetEngineSubaccountSummaryResponse, GetEngineIsolatedPositionsResponse, EngineSymbolsResponse, EngineSymbol, EngineMarketPrice, GetEngineNlpLockedBalancesResponse, GetEngineNlpPoolInfoResponse } from '../types/clientQueryTypes.js';
4
4
  import { EngineServerSpotProduct, EngineServerPerpProduct } from '../types/serverQueryModelTypes.js';
5
5
 
6
6
  declare function mapEngineServerTickLiquidity(tick: EngineServerPriceTickLiquidity): EnginePriceTickLiquidity;
@@ -13,5 +13,7 @@ declare function mapEngineServerIsolatedPositions(baseResponse: EngineServerIsol
13
13
  declare function mapEngineServerSymbols(baseResponse: EngineServerSymbolsResponse): EngineSymbolsResponse;
14
14
  declare function mapEngineServerSymbol(engineServerSymbol: EngineServerSymbol): EngineSymbol;
15
15
  declare function mapEngineMarketPrice(baseResponse: EngineServerMarketPrice): EngineMarketPrice;
16
+ declare function mapEngineServerNlpLockedBalances(baseResponse: EngineServerNlpLockedBalancesResponse): GetEngineNlpLockedBalancesResponse;
17
+ declare function mapEngineServerNlpPoolInfo(baseResponse: EngineServerNlpPoolInfoResponse): GetEngineNlpPoolInfoResponse;
16
18
 
17
- export { mapEngineMarketPrice, mapEngineServerBalanceHealthContributions, mapEngineServerIsolatedPositions, mapEngineServerOrder, mapEngineServerPerpProduct, mapEngineServerSpotProduct, mapEngineServerSymbol, mapEngineServerSymbols, mapEngineServerTickLiquidity, mapSubaccountSummary };
19
+ export { mapEngineMarketPrice, mapEngineServerBalanceHealthContributions, mapEngineServerIsolatedPositions, mapEngineServerNlpLockedBalances, mapEngineServerNlpPoolInfo, mapEngineServerOrder, mapEngineServerPerpProduct, mapEngineServerSpotProduct, mapEngineServerSymbol, mapEngineServerSymbols, mapEngineServerTickLiquidity, mapSubaccountSummary };
@@ -107,9 +107,24 @@ function mapEngineServerBalanceHealthContributions(healthContributionsForBalance
107
107
  };
108
108
  }
109
109
  function mapSubaccountSummary(baseResponse) {
110
+ return {
111
+ exists: baseResponse.exists,
112
+ ...mapSubaccountSummaryState(
113
+ baseResponse,
114
+ baseResponse.spot_products,
115
+ baseResponse.perp_products
116
+ ),
117
+ preState: baseResponse.pre_state ? mapSubaccountSummaryState(
118
+ baseResponse.pre_state,
119
+ baseResponse.spot_products,
120
+ baseResponse.perp_products
121
+ ) : void 0
122
+ };
123
+ }
124
+ function mapSubaccountSummaryState(state, spotProducts, perpProducts) {
110
125
  const balances = [];
111
- baseResponse.spot_balances.forEach((spotBalance) => {
112
- const product = baseResponse.spot_products.find(
126
+ state.spot_balances.forEach((spotBalance) => {
127
+ const product = spotProducts.find(
113
128
  (product2) => product2.product_id === spotBalance.product_id
114
129
  );
115
130
  if (!product) {
@@ -118,13 +133,13 @@ function mapSubaccountSummary(baseResponse) {
118
133
  balances.push({
119
134
  amount: toBigDecimal(spotBalance.balance.amount),
120
135
  healthContributions: mapEngineServerBalanceHealthContributions(
121
- baseResponse.health_contributions[spotBalance.product_id]
136
+ state.health_contributions[spotBalance.product_id]
122
137
  ),
123
138
  ...mapEngineServerSpotProduct(product).product
124
139
  });
125
140
  });
126
- baseResponse.perp_balances.forEach((perpBalance) => {
127
- const product = baseResponse.perp_products.find(
141
+ state.perp_balances.forEach((perpBalance) => {
142
+ const product = perpProducts.find(
128
143
  (product2) => product2.product_id === perpBalance.product_id
129
144
  );
130
145
  if (!product) {
@@ -134,29 +149,28 @@ function mapSubaccountSummary(baseResponse) {
134
149
  amount: toBigDecimal(perpBalance.balance.amount),
135
150
  vQuoteBalance: toBigDecimal(perpBalance.balance.v_quote_balance),
136
151
  healthContributions: mapEngineServerBalanceHealthContributions(
137
- baseResponse.health_contributions[perpBalance.product_id]
152
+ state.health_contributions[perpBalance.product_id]
138
153
  ),
139
154
  ...mapEngineServerPerpProduct(product).product
140
155
  });
141
156
  });
142
157
  return {
143
158
  balances,
144
- exists: baseResponse.exists,
145
159
  health: {
146
160
  initial: {
147
- health: toBigDecimal(baseResponse.healths[0].health),
148
- assets: toBigDecimal(baseResponse.healths[0].assets),
149
- liabilities: toBigDecimal(baseResponse.healths[0].liabilities)
161
+ health: toBigDecimal(state.healths[0].health),
162
+ assets: toBigDecimal(state.healths[0].assets),
163
+ liabilities: toBigDecimal(state.healths[0].liabilities)
150
164
  },
151
165
  maintenance: {
152
- health: toBigDecimal(baseResponse.healths[1].health),
153
- assets: toBigDecimal(baseResponse.healths[1].assets),
154
- liabilities: toBigDecimal(baseResponse.healths[1].liabilities)
166
+ health: toBigDecimal(state.healths[1].health),
167
+ assets: toBigDecimal(state.healths[1].assets),
168
+ liabilities: toBigDecimal(state.healths[1].liabilities)
155
169
  },
156
170
  unweighted: {
157
- health: toBigDecimal(baseResponse.healths[2].health),
158
- assets: toBigDecimal(baseResponse.healths[2].assets),
159
- liabilities: toBigDecimal(baseResponse.healths[2].liabilities)
171
+ health: toBigDecimal(state.healths[2].health),
172
+ assets: toBigDecimal(state.healths[2].assets),
173
+ liabilities: toBigDecimal(state.healths[2].liabilities)
160
174
  }
161
175
  }
162
176
  };
@@ -212,8 +226,6 @@ function mapEngineServerSymbol(engineServerSymbol) {
212
226
  priceIncrement: removeDecimals(engineServerSymbol.price_increment_x18),
213
227
  sizeIncrement: toBigDecimal(engineServerSymbol.size_increment),
214
228
  minSize: toBigDecimal(engineServerSymbol.min_size),
215
- minDepth: removeDecimals(engineServerSymbol.min_depth_x18),
216
- maxSpreadRate: removeDecimals(engineServerSymbol.max_spread_rate_x18),
217
229
  makerFeeRate: removeDecimals(engineServerSymbol.maker_fee_rate_x18),
218
230
  takerFeeRate: removeDecimals(engineServerSymbol.taker_fee_rate_x18),
219
231
  longWeightInitial: removeDecimals(
@@ -221,7 +233,8 @@ function mapEngineServerSymbol(engineServerSymbol) {
221
233
  ),
222
234
  longWeightMaintenance: removeDecimals(
223
235
  engineServerSymbol.long_weight_maintenance_x18
224
- )
236
+ ),
237
+ maxOpenInterest: removeDecimals(engineServerSymbol.max_open_interest_x18)
225
238
  };
226
239
  }
227
240
  function mapEngineMarketPrice(baseResponse) {
@@ -231,10 +244,42 @@ function mapEngineMarketPrice(baseResponse) {
231
244
  productId: baseResponse.product_id
232
245
  };
233
246
  }
247
+ function mapEngineServerNlpLockedBalances(baseResponse) {
248
+ const lockedBalances = baseResponse.locked_balances.map((lockedBalance) => ({
249
+ productId: lockedBalance.balance.product_id,
250
+ balance: toBigDecimal(lockedBalance.balance.balance.amount),
251
+ unlockedAt: lockedBalance.unlocked_at
252
+ }));
253
+ return {
254
+ lockedBalances,
255
+ balanceLocked: {
256
+ productId: baseResponse.balance_locked.product_id,
257
+ balance: toBigDecimal(baseResponse.balance_locked.balance.amount)
258
+ },
259
+ balanceUnlocked: {
260
+ productId: baseResponse.balance_unlocked.product_id,
261
+ balance: toBigDecimal(baseResponse.balance_unlocked.balance.amount)
262
+ }
263
+ };
264
+ }
265
+ function mapEngineServerNlpPoolInfo(baseResponse) {
266
+ return {
267
+ nlpPools: baseResponse.nlp_pools.map((pool) => ({
268
+ poolId: pool.pool_id,
269
+ subaccountHex: pool.subaccount,
270
+ ownerAddress: pool.owner,
271
+ balanceWeight: removeDecimals(pool.balance_weight_x18),
272
+ subaccountInfo: mapSubaccountSummary(pool.subaccount_info),
273
+ openOrders: pool.open_orders.map(mapEngineServerOrder)
274
+ }))
275
+ };
276
+ }
234
277
  export {
235
278
  mapEngineMarketPrice,
236
279
  mapEngineServerBalanceHealthContributions,
237
280
  mapEngineServerIsolatedPositions,
281
+ mapEngineServerNlpLockedBalances,
282
+ mapEngineServerNlpPoolInfo,
238
283
  mapEngineServerOrder,
239
284
  mapEngineServerPerpProduct,
240
285
  mapEngineServerSpotProduct,