@nadohq/engine-client 0.14.0 → 0.17.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 (190) hide show
  1. package/dist/EngineBaseClient-DOOXIhnZ.d.ts +75 -0
  2. package/dist/EngineBaseClient-DOOXIhnZ.d.ts.map +1 -0
  3. package/dist/EngineBaseClient-L1ue7jBx.d.cts +75 -0
  4. package/dist/EngineBaseClient-L1ue7jBx.d.cts.map +1 -0
  5. package/dist/EngineBaseClient-Uc1D8ftx.cjs +150 -0
  6. package/dist/EngineBaseClient-Uc1D8ftx.cjs.map +1 -0
  7. package/dist/EngineBaseClient.cjs +3 -167
  8. package/dist/EngineBaseClient.d.cts +2 -75
  9. package/dist/EngineBaseClient.d.ts +2 -75
  10. package/dist/EngineBaseClient.js +112 -131
  11. package/dist/EngineBaseClient.js.map +1 -1
  12. package/dist/EngineClient.cjs +13 -38
  13. package/dist/EngineClient.cjs.map +1 -1
  14. package/dist/EngineClient.d.cts +8 -18
  15. package/dist/EngineClient.d.cts.map +1 -0
  16. package/dist/EngineClient.d.ts +8 -18
  17. package/dist/EngineClient.d.ts.map +1 -0
  18. package/dist/EngineClient.js +9 -11
  19. package/dist/EngineClient.js.map +1 -1
  20. package/dist/EngineExecuteBuilder-VLrEndhv.d.cts +105 -0
  21. package/dist/EngineExecuteBuilder-VLrEndhv.d.cts.map +1 -0
  22. package/dist/EngineExecuteBuilder-t8EQ5Rmp.d.ts +105 -0
  23. package/dist/EngineExecuteBuilder-t8EQ5Rmp.d.ts.map +1 -0
  24. package/dist/EngineExecuteBuilder.cjs +232 -277
  25. package/dist/EngineExecuteBuilder.cjs.map +1 -1
  26. package/dist/EngineExecuteBuilder.d.cts +2 -108
  27. package/dist/EngineExecuteBuilder.d.ts +2 -108
  28. package/dist/EngineExecuteBuilder.js +230 -256
  29. package/dist/EngineExecuteBuilder.js.map +1 -1
  30. package/dist/EngineExecuteClient-0EBoXRd7.d.ts +24 -0
  31. package/dist/EngineExecuteClient-0EBoXRd7.d.ts.map +1 -0
  32. package/dist/EngineExecuteClient-BGlNK5Le.d.cts +24 -0
  33. package/dist/EngineExecuteClient-BGlNK5Le.d.cts.map +1 -0
  34. package/dist/EngineExecuteClient.cjs +57 -110
  35. package/dist/EngineExecuteClient.cjs.map +1 -1
  36. package/dist/EngineExecuteClient.d.cts +2 -28
  37. package/dist/EngineExecuteClient.d.ts +2 -28
  38. package/dist/EngineExecuteClient.js +54 -83
  39. package/dist/EngineExecuteClient.js.map +1 -1
  40. package/dist/EngineQueryClient-C_7p1oRx.d.cts +147 -0
  41. package/dist/EngineQueryClient-C_7p1oRx.d.cts.map +1 -0
  42. package/dist/EngineQueryClient-DQwCRaYl.d.ts +147 -0
  43. package/dist/EngineQueryClient-DQwCRaYl.d.ts.map +1 -0
  44. package/dist/EngineQueryClient.cjs +354 -447
  45. package/dist/EngineQueryClient.cjs.map +1 -1
  46. package/dist/EngineQueryClient.d.cts +2 -149
  47. package/dist/EngineQueryClient.d.ts +2 -149
  48. package/dist/EngineQueryClient.js +351 -440
  49. package/dist/EngineQueryClient.js.map +1 -1
  50. package/dist/EngineServerFailureError-CDabRrF4.d.ts +11 -0
  51. package/dist/EngineServerFailureError-CDabRrF4.d.ts.map +1 -0
  52. package/dist/EngineServerFailureError-DpPY0--L.d.cts +11 -0
  53. package/dist/EngineServerFailureError-DpPY0--L.d.cts.map +1 -0
  54. package/dist/EngineWebClient-CEwqgd4t.d.ts +35 -0
  55. package/dist/EngineWebClient-CEwqgd4t.d.ts.map +1 -0
  56. package/dist/EngineWebClient-DajZqKAQ.d.cts +35 -0
  57. package/dist/EngineWebClient-DajZqKAQ.d.cts.map +1 -0
  58. package/dist/EngineWebClient.cjs +49 -86
  59. package/dist/EngineWebClient.cjs.map +1 -1
  60. package/dist/EngineWebClient.d.cts +2 -39
  61. package/dist/EngineWebClient.d.ts +2 -39
  62. package/dist/EngineWebClient.js +47 -60
  63. package/dist/EngineWebClient.js.map +1 -1
  64. package/dist/clientExecuteTypes-BlJOgCL_.d.cts +91 -0
  65. package/dist/clientExecuteTypes-BlJOgCL_.d.cts.map +1 -0
  66. package/dist/clientExecuteTypes-CJ08_c4q.d.ts +91 -0
  67. package/dist/clientExecuteTypes-CJ08_c4q.d.ts.map +1 -0
  68. package/dist/clientQueryTypes-DlTtS_mX.d.cts +221 -0
  69. package/dist/clientQueryTypes-DlTtS_mX.d.cts.map +1 -0
  70. package/dist/clientQueryTypes-DuRgEeBT.d.ts +221 -0
  71. package/dist/clientQueryTypes-DuRgEeBT.d.ts.map +1 -0
  72. package/dist/endpoints.cjs +19 -45
  73. package/dist/endpoints.cjs.map +1 -1
  74. package/dist/endpoints.d.cts +4 -2
  75. package/dist/endpoints.d.cts.map +1 -0
  76. package/dist/endpoints.d.ts +4 -2
  77. package/dist/endpoints.d.ts.map +1 -0
  78. package/dist/endpoints.js +16 -18
  79. package/dist/endpoints.js.map +1 -1
  80. package/dist/index-CmCelmEL.d.cts +1 -0
  81. package/dist/index-D0E78WnU.d.ts +1 -0
  82. package/dist/index.cjs +26 -31
  83. package/dist/index.d.cts +12 -20
  84. package/dist/index.d.ts +12 -20
  85. package/dist/index.js +8 -6
  86. package/dist/queryDataMappers-BguxA579.d.ts +21 -0
  87. package/dist/queryDataMappers-BguxA579.d.ts.map +1 -0
  88. package/dist/queryDataMappers-DO9yWdLo.d.cts +21 -0
  89. package/dist/queryDataMappers-DO9yWdLo.d.cts.map +1 -0
  90. package/dist/serverExecuteTypes-CgbHjnWM.d.ts +92 -0
  91. package/dist/serverExecuteTypes-CgbHjnWM.d.ts.map +1 -0
  92. package/dist/serverExecuteTypes-DejTR8Is.d.cts +92 -0
  93. package/dist/serverExecuteTypes-DejTR8Is.d.cts.map +1 -0
  94. package/dist/serverQueryModelTypes-85xnbU-a.d.cts +98 -0
  95. package/dist/serverQueryModelTypes-85xnbU-a.d.cts.map +1 -0
  96. package/dist/serverQueryModelTypes-CENoy5Hm.d.ts +98 -0
  97. package/dist/serverQueryModelTypes-CENoy5Hm.d.ts.map +1 -0
  98. package/dist/serverQueryTypes-B3vC8vxT.d.ts +301 -0
  99. package/dist/serverQueryTypes-B3vC8vxT.d.ts.map +1 -0
  100. package/dist/serverQueryTypes-Dva9R2tV.d.cts +301 -0
  101. package/dist/serverQueryTypes-Dva9R2tV.d.cts.map +1 -0
  102. package/dist/serverSubscriptionEventTypes-BMUrTkTg.d.cts +135 -0
  103. package/dist/serverSubscriptionEventTypes-BMUrTkTg.d.cts.map +1 -0
  104. package/dist/serverSubscriptionEventTypes-UCYAjmt7.d.ts +135 -0
  105. package/dist/serverSubscriptionEventTypes-UCYAjmt7.d.ts.map +1 -0
  106. package/dist/serverSubscriptionTypes-BSuYa6z_.d.cts +82 -0
  107. package/dist/serverSubscriptionTypes-BSuYa6z_.d.cts.map +1 -0
  108. package/dist/serverSubscriptionTypes-DoMWeKgY.d.ts +82 -0
  109. package/dist/serverSubscriptionTypes-DoMWeKgY.d.ts.map +1 -0
  110. package/dist/types/EngineServerFailureError.cjs +9 -33
  111. package/dist/types/EngineServerFailureError.cjs.map +1 -1
  112. package/dist/types/EngineServerFailureError.d.cts +2 -11
  113. package/dist/types/EngineServerFailureError.d.ts +2 -11
  114. package/dist/types/EngineServerFailureError.js +8 -8
  115. package/dist/types/EngineServerFailureError.js.map +1 -1
  116. package/dist/types/clientExecuteTypes.cjs +0 -19
  117. package/dist/types/clientExecuteTypes.d.cts +2 -91
  118. package/dist/types/clientExecuteTypes.d.ts +2 -91
  119. package/dist/types/clientExecuteTypes.js +1 -1
  120. package/dist/types/clientQueryTypes.cjs +0 -19
  121. package/dist/types/clientQueryTypes.d.cts +2 -219
  122. package/dist/types/clientQueryTypes.d.ts +2 -219
  123. package/dist/types/clientQueryTypes.js +1 -1
  124. package/dist/types/index.cjs +5 -39
  125. package/dist/types/index.d.cts +9 -10
  126. package/dist/types/index.d.ts +9 -10
  127. package/dist/types/index.js +3 -10
  128. package/dist/types/serverExecuteTypes.cjs +0 -19
  129. package/dist/types/serverExecuteTypes.d.cts +2 -93
  130. package/dist/types/serverExecuteTypes.d.ts +2 -93
  131. package/dist/types/serverExecuteTypes.js +1 -1
  132. package/dist/types/serverQueryModelTypes.cjs +0 -19
  133. package/dist/types/serverQueryModelTypes.d.cts +2 -96
  134. package/dist/types/serverQueryModelTypes.d.ts +2 -96
  135. package/dist/types/serverQueryModelTypes.js +1 -1
  136. package/dist/types/serverQueryTypes.cjs +12 -36
  137. package/dist/types/serverQueryTypes.cjs.map +1 -1
  138. package/dist/types/serverQueryTypes.d.cts +2 -309
  139. package/dist/types/serverQueryTypes.d.ts +2 -309
  140. package/dist/types/serverQueryTypes.js +11 -11
  141. package/dist/types/serverQueryTypes.js.map +1 -1
  142. package/dist/types/serverSubscriptionEventTypes.cjs +0 -19
  143. package/dist/types/serverSubscriptionEventTypes.d.cts +2 -135
  144. package/dist/types/serverSubscriptionEventTypes.d.ts +2 -135
  145. package/dist/types/serverSubscriptionEventTypes.js +1 -1
  146. package/dist/types/serverSubscriptionTypes.cjs +0 -19
  147. package/dist/types/serverSubscriptionTypes.d.cts +2 -80
  148. package/dist/types/serverSubscriptionTypes.d.ts +2 -80
  149. package/dist/types/serverSubscriptionTypes.js +1 -1
  150. package/dist/utils/index.cjs +14 -25
  151. package/dist/utils/index.d.cts +2 -6
  152. package/dist/utils/index.d.ts +2 -6
  153. package/dist/utils/index.js +2 -3
  154. package/dist/utils/productEngineTypeMappers.cjs +16 -44
  155. package/dist/utils/productEngineTypeMappers.cjs.map +1 -1
  156. package/dist/utils/productEngineTypeMappers.d.cts +5 -3
  157. package/dist/utils/productEngineTypeMappers.d.cts.map +1 -0
  158. package/dist/utils/productEngineTypeMappers.d.ts +5 -3
  159. package/dist/utils/productEngineTypeMappers.d.ts.map +1 -0
  160. package/dist/utils/productEngineTypeMappers.js +12 -17
  161. package/dist/utils/productEngineTypeMappers.js.map +1 -1
  162. package/dist/utils/queryDataMappers.cjs +204 -292
  163. package/dist/utils/queryDataMappers.cjs.map +1 -1
  164. package/dist/utils/queryDataMappers.d.cts +2 -20
  165. package/dist/utils/queryDataMappers.d.ts +2 -20
  166. package/dist/utils/queryDataMappers.js +190 -264
  167. package/dist/utils/queryDataMappers.js.map +1 -1
  168. package/package.json +9 -9
  169. package/src/EngineQueryClient.ts +4 -0
  170. package/src/types/clientQueryTypes.ts +3 -0
  171. package/src/types/serverQueryTypes.ts +3 -0
  172. package/dist/EngineBaseClient.cjs.map +0 -1
  173. package/dist/index.cjs.map +0 -1
  174. package/dist/index.js.map +0 -1
  175. package/dist/types/clientExecuteTypes.cjs.map +0 -1
  176. package/dist/types/clientExecuteTypes.js.map +0 -1
  177. package/dist/types/clientQueryTypes.cjs.map +0 -1
  178. package/dist/types/clientQueryTypes.js.map +0 -1
  179. package/dist/types/index.cjs.map +0 -1
  180. package/dist/types/index.js.map +0 -1
  181. package/dist/types/serverExecuteTypes.cjs.map +0 -1
  182. package/dist/types/serverExecuteTypes.js.map +0 -1
  183. package/dist/types/serverQueryModelTypes.cjs.map +0 -1
  184. package/dist/types/serverQueryModelTypes.js.map +0 -1
  185. package/dist/types/serverSubscriptionEventTypes.cjs.map +0 -1
  186. package/dist/types/serverSubscriptionEventTypes.js.map +0 -1
  187. package/dist/types/serverSubscriptionTypes.cjs.map +0 -1
  188. package/dist/types/serverSubscriptionTypes.js.map +0 -1
  189. package/dist/utils/index.cjs.map +0 -1
  190. package/dist/utils/index.js.map +0 -1
@@ -1,319 +1,231 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/utils/queryDataMappers.ts
21
- var queryDataMappers_exports = {};
22
- __export(queryDataMappers_exports, {
23
- mapEngineMarketPrice: () => mapEngineMarketPrice,
24
- mapEngineServerBalanceHealthContributions: () => mapEngineServerBalanceHealthContributions,
25
- mapEngineServerIsolatedPositions: () => mapEngineServerIsolatedPositions,
26
- mapEngineServerNlpLockedBalances: () => mapEngineServerNlpLockedBalances,
27
- mapEngineServerNlpPoolInfo: () => mapEngineServerNlpPoolInfo,
28
- mapEngineServerOrder: () => mapEngineServerOrder,
29
- mapEngineServerPerpProduct: () => mapEngineServerPerpProduct,
30
- mapEngineServerSpotProduct: () => mapEngineServerSpotProduct,
31
- mapEngineServerSymbol: () => mapEngineServerSymbol,
32
- mapEngineServerSymbols: () => mapEngineServerSymbols,
33
- mapEngineServerTickLiquidity: () => mapEngineServerTickLiquidity,
34
- mapSubaccountSummary: () => mapSubaccountSummary
35
- });
36
- module.exports = __toCommonJS(queryDataMappers_exports);
37
- var import_shared = require("@nadohq/shared");
38
- var import_productEngineTypeMappers = require("./productEngineTypeMappers.cjs");
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ require("../EngineBaseClient-Uc1D8ftx.cjs");
3
+ const require_utils_productEngineTypeMappers = require("./productEngineTypeMappers.cjs");
4
+ let _nadohq_shared = require("@nadohq/shared");
5
+ //#region src/utils/queryDataMappers.ts
39
6
  function mapEngineServerTickLiquidity(tick) {
40
- return {
41
- price: (0, import_shared.removeDecimals)(tick[0]),
42
- liquidity: (0, import_shared.toBigNumber)(tick[1])
43
- };
7
+ return {
8
+ price: (0, _nadohq_shared.removeDecimals)(tick[0]),
9
+ liquidity: (0, _nadohq_shared.toBigNumber)(tick[1])
10
+ };
44
11
  }
45
12
  function mapEngineServerOrder(order) {
46
- const subaccount = (0, import_shared.subaccountFromHex)(order.sender);
47
- return {
48
- digest: order.digest,
49
- expiration: Number(order.expiration),
50
- nonce: order.nonce,
51
- price: (0, import_shared.removeDecimals)(order.price_x18),
52
- productId: order.product_id,
53
- subaccountOwner: subaccount.subaccountOwner,
54
- subaccountName: subaccount.subaccountName,
55
- totalAmount: (0, import_shared.toBigNumber)(order.amount),
56
- unfilledAmount: (0, import_shared.toBigNumber)(order.unfilled_amount),
57
- placementTime: order.placed_at,
58
- appendix: (0, import_shared.unpackOrderAppendix)(order.appendix)
59
- };
13
+ const subaccount = (0, _nadohq_shared.subaccountFromHex)(order.sender);
14
+ return {
15
+ digest: order.digest,
16
+ expiration: Number(order.expiration),
17
+ nonce: order.nonce,
18
+ price: (0, _nadohq_shared.removeDecimals)(order.price_x18),
19
+ productId: order.product_id,
20
+ subaccountOwner: subaccount.subaccountOwner,
21
+ subaccountName: subaccount.subaccountName,
22
+ totalAmount: (0, _nadohq_shared.toBigNumber)(order.amount),
23
+ unfilledAmount: (0, _nadohq_shared.toBigNumber)(order.unfilled_amount),
24
+ placementTime: order.placed_at,
25
+ appendix: (0, _nadohq_shared.unpackOrderAppendix)(order.appendix)
26
+ };
60
27
  }
61
28
  function mapEngineServerSpotProduct(product) {
62
- return {
63
- type: import_shared.ProductEngineType.SPOT,
64
- productId: product.product_id,
65
- minSize: (0, import_shared.toBigNumber)(product.book_info.min_size),
66
- priceIncrement: (0, import_shared.removeDecimals)(product.book_info.price_increment_x18),
67
- sizeIncrement: (0, import_shared.toBigNumber)(product.book_info.size_increment),
68
- product: {
69
- productId: product.product_id,
70
- type: import_shared.ProductEngineType.SPOT,
71
- totalBorrowed: (0, import_shared.calcTotalBorrowed)(
72
- product.state.total_borrows_normalized,
73
- product.state.cumulative_borrows_multiplier_x18
74
- ),
75
- totalDeposited: (0, import_shared.calcTotalDeposited)(
76
- product.state.total_deposits_normalized,
77
- product.state.cumulative_deposits_multiplier_x18
78
- ),
79
- oraclePrice: (0, import_shared.removeDecimals)(product.oracle_price_x18),
80
- interestFloor: (0, import_shared.removeDecimals)(product.config.interest_floor_x18),
81
- interestInflectionUtil: (0, import_shared.removeDecimals)(
82
- product.config.interest_inflection_util_x18
83
- ),
84
- interestLargeCap: (0, import_shared.removeDecimals)(product.config.interest_large_cap_x18),
85
- interestSmallCap: (0, import_shared.removeDecimals)(product.config.interest_small_cap_x18),
86
- minDepositRate: (0, import_shared.removeDecimals)(product.config.min_deposit_rate_x18),
87
- longWeightInitial: (0, import_shared.removeDecimals)(product.risk.long_weight_initial_x18),
88
- longWeightMaintenance: (0, import_shared.removeDecimals)(
89
- product.risk.long_weight_maintenance_x18
90
- ),
91
- shortWeightInitial: (0, import_shared.removeDecimals)(product.risk.short_weight_initial_x18),
92
- shortWeightMaintenance: (0, import_shared.removeDecimals)(
93
- product.risk.short_weight_maintenance_x18
94
- ),
95
- tokenAddr: product.config.token
96
- }
97
- };
29
+ return {
30
+ type: _nadohq_shared.ProductEngineType.SPOT,
31
+ productId: product.product_id,
32
+ minSize: (0, _nadohq_shared.toBigNumber)(product.book_info.min_size),
33
+ priceIncrement: (0, _nadohq_shared.removeDecimals)(product.book_info.price_increment_x18),
34
+ sizeIncrement: (0, _nadohq_shared.toBigNumber)(product.book_info.size_increment),
35
+ product: {
36
+ productId: product.product_id,
37
+ type: _nadohq_shared.ProductEngineType.SPOT,
38
+ totalBorrowed: (0, _nadohq_shared.calcTotalBorrowed)(product.state.total_borrows_normalized, product.state.cumulative_borrows_multiplier_x18),
39
+ totalDeposited: (0, _nadohq_shared.calcTotalDeposited)(product.state.total_deposits_normalized, product.state.cumulative_deposits_multiplier_x18),
40
+ oraclePrice: (0, _nadohq_shared.removeDecimals)(product.oracle_price_x18),
41
+ interestFloor: (0, _nadohq_shared.removeDecimals)(product.config.interest_floor_x18),
42
+ interestInflectionUtil: (0, _nadohq_shared.removeDecimals)(product.config.interest_inflection_util_x18),
43
+ interestLargeCap: (0, _nadohq_shared.removeDecimals)(product.config.interest_large_cap_x18),
44
+ interestSmallCap: (0, _nadohq_shared.removeDecimals)(product.config.interest_small_cap_x18),
45
+ minDepositRate: (0, _nadohq_shared.removeDecimals)(product.config.min_deposit_rate_x18),
46
+ longWeightInitial: (0, _nadohq_shared.removeDecimals)(product.risk.long_weight_initial_x18),
47
+ longWeightMaintenance: (0, _nadohq_shared.removeDecimals)(product.risk.long_weight_maintenance_x18),
48
+ shortWeightInitial: (0, _nadohq_shared.removeDecimals)(product.risk.short_weight_initial_x18),
49
+ shortWeightMaintenance: (0, _nadohq_shared.removeDecimals)(product.risk.short_weight_maintenance_x18),
50
+ tokenAddr: product.config.token
51
+ }
52
+ };
98
53
  }
99
54
  function mapEngineServerPerpProduct(product) {
100
- return {
101
- type: import_shared.ProductEngineType.PERP,
102
- productId: product.product_id,
103
- minSize: (0, import_shared.toBigNumber)(product.book_info.min_size),
104
- priceIncrement: (0, import_shared.removeDecimals)(product.book_info.price_increment_x18),
105
- sizeIncrement: (0, import_shared.toBigNumber)(product.book_info.size_increment),
106
- product: {
107
- productId: product.product_id,
108
- type: import_shared.ProductEngineType.PERP,
109
- oraclePrice: (0, import_shared.removeDecimals)(product.oracle_price_x18),
110
- longWeightInitial: (0, import_shared.removeDecimals)(product.risk.long_weight_initial_x18),
111
- longWeightMaintenance: (0, import_shared.removeDecimals)(
112
- product.risk.long_weight_maintenance_x18
113
- ),
114
- shortWeightInitial: (0, import_shared.removeDecimals)(product.risk.short_weight_initial_x18),
115
- shortWeightMaintenance: (0, import_shared.removeDecimals)(
116
- product.risk.short_weight_maintenance_x18
117
- ),
118
- openInterest: (0, import_shared.toBigNumber)(product.state.open_interest),
119
- cumulativeFundingLong: (0, import_shared.removeDecimals)(
120
- product.state.cumulative_funding_long_x18
121
- ),
122
- cumulativeFundingShort: (0, import_shared.removeDecimals)(
123
- product.state.cumulative_funding_short_x18
124
- )
125
- }
126
- };
55
+ return {
56
+ type: _nadohq_shared.ProductEngineType.PERP,
57
+ productId: product.product_id,
58
+ minSize: (0, _nadohq_shared.toBigNumber)(product.book_info.min_size),
59
+ priceIncrement: (0, _nadohq_shared.removeDecimals)(product.book_info.price_increment_x18),
60
+ sizeIncrement: (0, _nadohq_shared.toBigNumber)(product.book_info.size_increment),
61
+ product: {
62
+ productId: product.product_id,
63
+ type: _nadohq_shared.ProductEngineType.PERP,
64
+ oraclePrice: (0, _nadohq_shared.removeDecimals)(product.oracle_price_x18),
65
+ longWeightInitial: (0, _nadohq_shared.removeDecimals)(product.risk.long_weight_initial_x18),
66
+ longWeightMaintenance: (0, _nadohq_shared.removeDecimals)(product.risk.long_weight_maintenance_x18),
67
+ shortWeightInitial: (0, _nadohq_shared.removeDecimals)(product.risk.short_weight_initial_x18),
68
+ shortWeightMaintenance: (0, _nadohq_shared.removeDecimals)(product.risk.short_weight_maintenance_x18),
69
+ openInterest: (0, _nadohq_shared.toBigNumber)(product.state.open_interest),
70
+ cumulativeFundingLong: (0, _nadohq_shared.removeDecimals)(product.state.cumulative_funding_long_x18),
71
+ cumulativeFundingShort: (0, _nadohq_shared.removeDecimals)(product.state.cumulative_funding_short_x18)
72
+ }
73
+ };
127
74
  }
128
75
  function mapEngineServerBalanceHealthContributions(healthContributionsForBalance) {
129
- return {
130
- initial: (0, import_shared.toBigNumber)(healthContributionsForBalance[0]),
131
- maintenance: (0, import_shared.toBigNumber)(healthContributionsForBalance[1]),
132
- unweighted: (0, import_shared.toBigNumber)(healthContributionsForBalance[2])
133
- };
76
+ return {
77
+ initial: (0, _nadohq_shared.toBigNumber)(healthContributionsForBalance[0]),
78
+ maintenance: (0, _nadohq_shared.toBigNumber)(healthContributionsForBalance[1]),
79
+ unweighted: (0, _nadohq_shared.toBigNumber)(healthContributionsForBalance[2])
80
+ };
134
81
  }
135
82
  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
- };
83
+ return {
84
+ exists: baseResponse.exists,
85
+ ...mapSubaccountSummaryState(baseResponse, baseResponse.spot_products, baseResponse.perp_products),
86
+ preState: baseResponse.pre_state ? mapSubaccountSummaryState(baseResponse.pre_state, baseResponse.spot_products, baseResponse.perp_products) : void 0
87
+ };
149
88
  }
150
89
  function mapSubaccountSummaryState(state, spotProducts, perpProducts) {
151
- const balances = [];
152
- state.spot_balances.forEach((spotBalance) => {
153
- const product = spotProducts.find(
154
- (product2) => product2.product_id === spotBalance.product_id
155
- );
156
- if (!product) {
157
- throw Error(`Could not find product ${spotBalance.product_id}`);
158
- }
159
- balances.push({
160
- amount: (0, import_shared.toBigNumber)(spotBalance.balance.amount),
161
- healthContributions: mapEngineServerBalanceHealthContributions(
162
- state.health_contributions[spotBalance.product_id]
163
- ),
164
- ...mapEngineServerSpotProduct(product).product
165
- });
166
- });
167
- state.perp_balances.forEach((perpBalance) => {
168
- const product = perpProducts.find(
169
- (product2) => product2.product_id === perpBalance.product_id
170
- );
171
- if (!product) {
172
- throw Error(`Could not find product ${perpBalance.product_id}`);
173
- }
174
- balances.push({
175
- amount: (0, import_shared.toBigNumber)(perpBalance.balance.amount),
176
- vQuoteBalance: (0, import_shared.toBigNumber)(perpBalance.balance.v_quote_balance),
177
- healthContributions: mapEngineServerBalanceHealthContributions(
178
- state.health_contributions[perpBalance.product_id]
179
- ),
180
- ...mapEngineServerPerpProduct(product).product
181
- });
182
- });
183
- return {
184
- balances,
185
- health: {
186
- initial: {
187
- health: (0, import_shared.toBigNumber)(state.healths[0].health),
188
- assets: (0, import_shared.toBigNumber)(state.healths[0].assets),
189
- liabilities: (0, import_shared.toBigNumber)(state.healths[0].liabilities)
190
- },
191
- maintenance: {
192
- health: (0, import_shared.toBigNumber)(state.healths[1].health),
193
- assets: (0, import_shared.toBigNumber)(state.healths[1].assets),
194
- liabilities: (0, import_shared.toBigNumber)(state.healths[1].liabilities)
195
- },
196
- unweighted: {
197
- health: (0, import_shared.toBigNumber)(state.healths[2].health),
198
- assets: (0, import_shared.toBigNumber)(state.healths[2].assets),
199
- liabilities: (0, import_shared.toBigNumber)(state.healths[2].liabilities)
200
- }
201
- }
202
- };
90
+ const balances = [];
91
+ state.spot_balances.forEach((spotBalance) => {
92
+ const product = spotProducts.find((product) => product.product_id === spotBalance.product_id);
93
+ if (!product) throw Error(`Could not find product ${spotBalance.product_id}`);
94
+ balances.push({
95
+ amount: (0, _nadohq_shared.toBigNumber)(spotBalance.balance.amount),
96
+ healthContributions: mapEngineServerBalanceHealthContributions(state.health_contributions[spotBalance.product_id]),
97
+ ...mapEngineServerSpotProduct(product).product
98
+ });
99
+ });
100
+ state.perp_balances.forEach((perpBalance) => {
101
+ const product = perpProducts.find((product) => product.product_id === perpBalance.product_id);
102
+ if (!product) throw Error(`Could not find product ${perpBalance.product_id}`);
103
+ balances.push({
104
+ amount: (0, _nadohq_shared.toBigNumber)(perpBalance.balance.amount),
105
+ vQuoteBalance: (0, _nadohq_shared.toBigNumber)(perpBalance.balance.v_quote_balance),
106
+ healthContributions: mapEngineServerBalanceHealthContributions(state.health_contributions[perpBalance.product_id]),
107
+ ...mapEngineServerPerpProduct(product).product
108
+ });
109
+ });
110
+ return {
111
+ balances,
112
+ health: {
113
+ initial: {
114
+ health: (0, _nadohq_shared.toBigNumber)(state.healths[0].health),
115
+ assets: (0, _nadohq_shared.toBigNumber)(state.healths[0].assets),
116
+ liabilities: (0, _nadohq_shared.toBigNumber)(state.healths[0].liabilities)
117
+ },
118
+ maintenance: {
119
+ health: (0, _nadohq_shared.toBigNumber)(state.healths[1].health),
120
+ assets: (0, _nadohq_shared.toBigNumber)(state.healths[1].assets),
121
+ liabilities: (0, _nadohq_shared.toBigNumber)(state.healths[1].liabilities)
122
+ },
123
+ unweighted: {
124
+ health: (0, _nadohq_shared.toBigNumber)(state.healths[2].health),
125
+ assets: (0, _nadohq_shared.toBigNumber)(state.healths[2].assets),
126
+ liabilities: (0, _nadohq_shared.toBigNumber)(state.healths[2].liabilities)
127
+ }
128
+ }
129
+ };
203
130
  }
204
131
  function mapEngineServerIsolatedPositions(baseResponse) {
205
- return baseResponse.isolated_positions.map((position) => {
206
- const perpBalance = position.base_balance;
207
- const quoteBalance = position.quote_balance;
208
- return {
209
- subaccount: (0, import_shared.subaccountFromHex)(position.subaccount),
210
- healths: {
211
- initial: (0, import_shared.toBigNumber)(position.healths[0].health),
212
- maintenance: (0, import_shared.toBigNumber)(position.healths[1].health),
213
- unweighted: (0, import_shared.toBigNumber)(position.healths[2].health)
214
- },
215
- baseBalance: {
216
- amount: (0, import_shared.toBigNumber)(perpBalance.balance.amount),
217
- vQuoteBalance: (0, import_shared.toBigNumber)(perpBalance.balance.v_quote_balance),
218
- // Health contributions === healths for an isolated position
219
- healthContributions: {
220
- initial: (0, import_shared.toBigNumber)(position.base_healths[0]),
221
- maintenance: (0, import_shared.toBigNumber)(position.base_healths[1]),
222
- unweighted: (0, import_shared.toBigNumber)(position.base_healths[2])
223
- },
224
- ...mapEngineServerPerpProduct(position.base_product).product
225
- },
226
- quoteBalance: {
227
- amount: (0, import_shared.toBigNumber)(quoteBalance.balance.amount),
228
- healthContributions: {
229
- initial: (0, import_shared.toBigNumber)(position.quote_healths[0]),
230
- maintenance: (0, import_shared.toBigNumber)(position.quote_healths[1]),
231
- unweighted: (0, import_shared.toBigNumber)(position.quote_healths[2])
232
- },
233
- ...mapEngineServerSpotProduct(position.quote_product).product
234
- }
235
- };
236
- });
132
+ return baseResponse.isolated_positions.map((position) => {
133
+ const perpBalance = position.base_balance;
134
+ const quoteBalance = position.quote_balance;
135
+ return {
136
+ subaccount: (0, _nadohq_shared.subaccountFromHex)(position.subaccount),
137
+ healths: {
138
+ initial: (0, _nadohq_shared.toBigNumber)(position.healths[0].health),
139
+ maintenance: (0, _nadohq_shared.toBigNumber)(position.healths[1].health),
140
+ unweighted: (0, _nadohq_shared.toBigNumber)(position.healths[2].health)
141
+ },
142
+ baseBalance: {
143
+ amount: (0, _nadohq_shared.toBigNumber)(perpBalance.balance.amount),
144
+ vQuoteBalance: (0, _nadohq_shared.toBigNumber)(perpBalance.balance.v_quote_balance),
145
+ healthContributions: {
146
+ initial: (0, _nadohq_shared.toBigNumber)(position.base_healths[0]),
147
+ maintenance: (0, _nadohq_shared.toBigNumber)(position.base_healths[1]),
148
+ unweighted: (0, _nadohq_shared.toBigNumber)(position.base_healths[2])
149
+ },
150
+ ...mapEngineServerPerpProduct(position.base_product).product
151
+ },
152
+ quoteBalance: {
153
+ amount: (0, _nadohq_shared.toBigNumber)(quoteBalance.balance.amount),
154
+ healthContributions: {
155
+ initial: (0, _nadohq_shared.toBigNumber)(position.quote_healths[0]),
156
+ maintenance: (0, _nadohq_shared.toBigNumber)(position.quote_healths[1]),
157
+ unweighted: (0, _nadohq_shared.toBigNumber)(position.quote_healths[2])
158
+ },
159
+ ...mapEngineServerSpotProduct(position.quote_product).product
160
+ }
161
+ };
162
+ });
237
163
  }
238
164
  function mapEngineServerSymbols(baseResponse) {
239
- const symbols = (0, import_shared.mapValues)(
240
- baseResponse.symbols,
241
- mapEngineServerSymbol
242
- );
243
- return {
244
- symbols
245
- };
165
+ return { symbols: (0, _nadohq_shared.mapValues)(baseResponse.symbols, mapEngineServerSymbol) };
246
166
  }
247
167
  function mapEngineServerSymbol(engineServerSymbol) {
248
- return {
249
- type: (0, import_productEngineTypeMappers.mapEngineServerProductType)(engineServerSymbol.type),
250
- productId: engineServerSymbol.product_id,
251
- symbol: engineServerSymbol.symbol,
252
- priceIncrement: (0, import_shared.removeDecimals)(engineServerSymbol.price_increment_x18),
253
- sizeIncrement: (0, import_shared.toBigNumber)(engineServerSymbol.size_increment),
254
- minSize: (0, import_shared.toBigNumber)(engineServerSymbol.min_size),
255
- makerFeeRate: (0, import_shared.removeDecimals)(engineServerSymbol.maker_fee_rate_x18),
256
- takerFeeRate: (0, import_shared.removeDecimals)(engineServerSymbol.taker_fee_rate_x18),
257
- longWeightInitial: (0, import_shared.removeDecimals)(
258
- engineServerSymbol.long_weight_initial_x18
259
- ),
260
- longWeightMaintenance: (0, import_shared.removeDecimals)(
261
- engineServerSymbol.long_weight_maintenance_x18
262
- ),
263
- maxOpenInterest: (0, import_shared.removeDecimals)(engineServerSymbol.max_open_interest_x18),
264
- isolatedOnly: engineServerSymbol.isolated_only
265
- };
168
+ return {
169
+ type: require_utils_productEngineTypeMappers.mapEngineServerProductType(engineServerSymbol.type),
170
+ productId: engineServerSymbol.product_id,
171
+ symbol: engineServerSymbol.symbol,
172
+ priceIncrement: (0, _nadohq_shared.removeDecimals)(engineServerSymbol.price_increment_x18),
173
+ sizeIncrement: (0, _nadohq_shared.toBigNumber)(engineServerSymbol.size_increment),
174
+ minSize: (0, _nadohq_shared.toBigNumber)(engineServerSymbol.min_size),
175
+ makerFeeRate: (0, _nadohq_shared.removeDecimals)(engineServerSymbol.maker_fee_rate_x18),
176
+ takerFeeRate: (0, _nadohq_shared.removeDecimals)(engineServerSymbol.taker_fee_rate_x18),
177
+ longWeightInitial: (0, _nadohq_shared.removeDecimals)(engineServerSymbol.long_weight_initial_x18),
178
+ longWeightMaintenance: (0, _nadohq_shared.removeDecimals)(engineServerSymbol.long_weight_maintenance_x18),
179
+ maxOpenInterest: (0, _nadohq_shared.removeDecimals)(engineServerSymbol.max_open_interest_x18),
180
+ isolatedOnly: engineServerSymbol.isolated_only
181
+ };
266
182
  }
267
183
  function mapEngineMarketPrice(baseResponse) {
268
- return {
269
- ask: (0, import_shared.removeDecimals)(baseResponse.ask_x18),
270
- bid: (0, import_shared.removeDecimals)(baseResponse.bid_x18),
271
- productId: baseResponse.product_id
272
- };
184
+ return {
185
+ ask: (0, _nadohq_shared.removeDecimals)(baseResponse.ask_x18),
186
+ bid: (0, _nadohq_shared.removeDecimals)(baseResponse.bid_x18),
187
+ productId: baseResponse.product_id
188
+ };
273
189
  }
274
190
  function mapEngineServerNlpLockedBalances(baseResponse) {
275
- const lockedBalances = baseResponse.locked_balances.map((lockedBalance) => ({
276
- productId: lockedBalance.balance.product_id,
277
- balance: (0, import_shared.toBigNumber)(lockedBalance.balance.balance.amount),
278
- unlockedAt: lockedBalance.unlocked_at
279
- }));
280
- return {
281
- lockedBalances,
282
- balanceLocked: {
283
- productId: baseResponse.balance_locked.product_id,
284
- balance: (0, import_shared.toBigNumber)(baseResponse.balance_locked.balance.amount)
285
- },
286
- balanceUnlocked: {
287
- productId: baseResponse.balance_unlocked.product_id,
288
- balance: (0, import_shared.toBigNumber)(baseResponse.balance_unlocked.balance.amount)
289
- }
290
- };
191
+ return {
192
+ lockedBalances: baseResponse.locked_balances.map((lockedBalance) => ({
193
+ productId: lockedBalance.balance.product_id,
194
+ balance: (0, _nadohq_shared.toBigNumber)(lockedBalance.balance.balance.amount),
195
+ unlockedAt: lockedBalance.unlocked_at
196
+ })),
197
+ balanceLocked: {
198
+ productId: baseResponse.balance_locked.product_id,
199
+ balance: (0, _nadohq_shared.toBigNumber)(baseResponse.balance_locked.balance.amount)
200
+ },
201
+ balanceUnlocked: {
202
+ productId: baseResponse.balance_unlocked.product_id,
203
+ balance: (0, _nadohq_shared.toBigNumber)(baseResponse.balance_unlocked.balance.amount)
204
+ }
205
+ };
291
206
  }
292
207
  function mapEngineServerNlpPoolInfo(baseResponse) {
293
- return {
294
- nlpPools: baseResponse.nlp_pools.map((pool) => ({
295
- poolId: pool.pool_id,
296
- subaccountHex: pool.subaccount,
297
- ownerAddress: pool.owner,
298
- balanceWeight: (0, import_shared.removeDecimals)(pool.balance_weight_x18),
299
- subaccountInfo: mapSubaccountSummary(pool.subaccount_info),
300
- openOrders: pool.open_orders.map(mapEngineServerOrder)
301
- }))
302
- };
208
+ return { nlpPools: baseResponse.nlp_pools.map((pool) => ({
209
+ poolId: pool.pool_id,
210
+ subaccountHex: pool.subaccount,
211
+ ownerAddress: pool.owner,
212
+ balanceWeight: (0, _nadohq_shared.removeDecimals)(pool.balance_weight_x18),
213
+ subaccountInfo: mapSubaccountSummary(pool.subaccount_info),
214
+ openOrders: pool.open_orders.map(mapEngineServerOrder)
215
+ })) };
303
216
  }
304
- // Annotate the CommonJS export names for ESM import in node:
305
- 0 && (module.exports = {
306
- mapEngineMarketPrice,
307
- mapEngineServerBalanceHealthContributions,
308
- mapEngineServerIsolatedPositions,
309
- mapEngineServerNlpLockedBalances,
310
- mapEngineServerNlpPoolInfo,
311
- mapEngineServerOrder,
312
- mapEngineServerPerpProduct,
313
- mapEngineServerSpotProduct,
314
- mapEngineServerSymbol,
315
- mapEngineServerSymbols,
316
- mapEngineServerTickLiquidity,
317
- mapSubaccountSummary
318
- });
217
+ //#endregion
218
+ exports.mapEngineMarketPrice = mapEngineMarketPrice;
219
+ exports.mapEngineServerBalanceHealthContributions = mapEngineServerBalanceHealthContributions;
220
+ exports.mapEngineServerIsolatedPositions = mapEngineServerIsolatedPositions;
221
+ exports.mapEngineServerNlpLockedBalances = mapEngineServerNlpLockedBalances;
222
+ exports.mapEngineServerNlpPoolInfo = mapEngineServerNlpPoolInfo;
223
+ exports.mapEngineServerOrder = mapEngineServerOrder;
224
+ exports.mapEngineServerPerpProduct = mapEngineServerPerpProduct;
225
+ exports.mapEngineServerSpotProduct = mapEngineServerSpotProduct;
226
+ exports.mapEngineServerSymbol = mapEngineServerSymbol;
227
+ exports.mapEngineServerSymbols = mapEngineServerSymbols;
228
+ exports.mapEngineServerTickLiquidity = mapEngineServerTickLiquidity;
229
+ exports.mapSubaccountSummary = mapSubaccountSummary;
230
+
319
231
  //# sourceMappingURL=queryDataMappers.cjs.map
@@ -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 toBigNumber,\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: toBigNumber(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: toBigNumber(order.amount),\n unfilledAmount: toBigNumber(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: toBigNumber(product.book_info.min_size),\n priceIncrement: removeDecimals(product.book_info.price_increment_x18),\n sizeIncrement: toBigNumber(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: toBigNumber(product.book_info.min_size),\n priceIncrement: removeDecimals(product.book_info.price_increment_x18),\n sizeIncrement: toBigNumber(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: toBigNumber(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: toBigNumber(healthContributionsForBalance[0]),\n maintenance: toBigNumber(healthContributionsForBalance[1]),\n unweighted: toBigNumber(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: toBigNumber(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: toBigNumber(perpBalance.balance.amount),\n vQuoteBalance: toBigNumber(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: toBigNumber(state.healths[0].health),\n assets: toBigNumber(state.healths[0].assets),\n liabilities: toBigNumber(state.healths[0].liabilities),\n },\n maintenance: {\n health: toBigNumber(state.healths[1].health),\n assets: toBigNumber(state.healths[1].assets),\n liabilities: toBigNumber(state.healths[1].liabilities),\n },\n unweighted: {\n health: toBigNumber(state.healths[2].health),\n assets: toBigNumber(state.healths[2].assets),\n liabilities: toBigNumber(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: toBigNumber(position.healths[0].health),\n maintenance: toBigNumber(position.healths[1].health),\n unweighted: toBigNumber(position.healths[2].health),\n },\n baseBalance: {\n amount: toBigNumber(perpBalance.balance.amount),\n vQuoteBalance: toBigNumber(perpBalance.balance.v_quote_balance),\n // Health contributions === healths for an isolated position\n healthContributions: {\n initial: toBigNumber(position.base_healths[0]),\n maintenance: toBigNumber(position.base_healths[1]),\n unweighted: toBigNumber(position.base_healths[2]),\n },\n ...mapEngineServerPerpProduct(position.base_product).product,\n },\n quoteBalance: {\n amount: toBigNumber(quoteBalance.balance.amount),\n healthContributions: {\n initial: toBigNumber(position.quote_healths[0]),\n maintenance: toBigNumber(position.quote_healths[1]),\n unweighted: toBigNumber(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: toBigNumber(engineServerSymbol.size_increment),\n minSize: toBigNumber(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 isolatedOnly: engineServerSymbol.isolated_only,\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: toBigNumber(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: toBigNumber(baseResponse.balance_locked.balance.amount),\n },\n balanceUnlocked: {\n productId: baseResponse.balance_unlocked.product_id,\n balance: toBigNumber(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":";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A,IACA,qBAAiB,8BAAe,mBAAmB,qBAAqB;AAAA,IACxE,cAAc,mBAAmB;AAAA,EACnC;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;AAEO,SAAS,iCACd,cACoC;AACpC,QAAM,iBACJ,aAAa,gBAAgB,IAAI,CAAC,mBAAmB;AAAA,IACnD,WAAW,cAAc,QAAQ;AAAA,IACjC,aAAS,2BAAY,cAAc,QAAQ,QAAQ,MAAM;AAAA,IACzD,YAAY,cAAc;AAAA,EAC5B,EAAE;AAEJ,SAAO;AAAA,IACL;AAAA,IACA,eAAe;AAAA,MACb,WAAW,aAAa,eAAe;AAAA,MACvC,aAAS,2BAAY,aAAa,eAAe,QAAQ,MAAM;AAAA,IACjE;AAAA,IACA,iBAAiB;AAAA,MACf,WAAW,aAAa,iBAAiB;AAAA,MACzC,aAAS,2BAAY,aAAa,iBAAiB,QAAQ,MAAM;AAAA,IACnE;AAAA,EACF;AACF;AAEO,SAAS,2BACd,cAC8B;AAC9B,SAAO;AAAA,IACL,UAAU,aAAa,UAAU,IAAI,CAAC,UAAU;AAAA,MAC9C,QAAQ,KAAK;AAAA,MACb,eAAe,KAAK;AAAA,MACpB,cAAc,KAAK;AAAA,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
+ {"version":3,"file":"queryDataMappers.cjs","names":["ProductEngineType","mapEngineServerProductType"],"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 toBigNumber,\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: toBigNumber(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: toBigNumber(order.amount),\n unfilledAmount: toBigNumber(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: toBigNumber(product.book_info.min_size),\n priceIncrement: removeDecimals(product.book_info.price_increment_x18),\n sizeIncrement: toBigNumber(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: toBigNumber(product.book_info.min_size),\n priceIncrement: removeDecimals(product.book_info.price_increment_x18),\n sizeIncrement: toBigNumber(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: toBigNumber(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: toBigNumber(healthContributionsForBalance[0]),\n maintenance: toBigNumber(healthContributionsForBalance[1]),\n unweighted: toBigNumber(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: toBigNumber(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: toBigNumber(perpBalance.balance.amount),\n vQuoteBalance: toBigNumber(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: toBigNumber(state.healths[0].health),\n assets: toBigNumber(state.healths[0].assets),\n liabilities: toBigNumber(state.healths[0].liabilities),\n },\n maintenance: {\n health: toBigNumber(state.healths[1].health),\n assets: toBigNumber(state.healths[1].assets),\n liabilities: toBigNumber(state.healths[1].liabilities),\n },\n unweighted: {\n health: toBigNumber(state.healths[2].health),\n assets: toBigNumber(state.healths[2].assets),\n liabilities: toBigNumber(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: toBigNumber(position.healths[0].health),\n maintenance: toBigNumber(position.healths[1].health),\n unweighted: toBigNumber(position.healths[2].health),\n },\n baseBalance: {\n amount: toBigNumber(perpBalance.balance.amount),\n vQuoteBalance: toBigNumber(perpBalance.balance.v_quote_balance),\n // Health contributions === healths for an isolated position\n healthContributions: {\n initial: toBigNumber(position.base_healths[0]),\n maintenance: toBigNumber(position.base_healths[1]),\n unweighted: toBigNumber(position.base_healths[2]),\n },\n ...mapEngineServerPerpProduct(position.base_product).product,\n },\n quoteBalance: {\n amount: toBigNumber(quoteBalance.balance.amount),\n healthContributions: {\n initial: toBigNumber(position.quote_healths[0]),\n maintenance: toBigNumber(position.quote_healths[1]),\n unweighted: toBigNumber(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: toBigNumber(engineServerSymbol.size_increment),\n minSize: toBigNumber(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 isolatedOnly: engineServerSymbol.isolated_only,\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: toBigNumber(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: toBigNumber(baseResponse.balance_locked.balance.amount),\n },\n balanceUnlocked: {\n productId: baseResponse.balance_unlocked.product_id,\n balance: toBigNumber(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 };\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