@nadohq/engine-client 0.15.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 (187) 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 -448
  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 -441
  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 -220
  122. package/dist/types/clientQueryTypes.d.ts +2 -220
  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 -310
  139. package/dist/types/serverQueryTypes.d.ts +2 -310
  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/dist/EngineBaseClient.cjs.map +0 -1
  170. package/dist/index.cjs.map +0 -1
  171. package/dist/index.js.map +0 -1
  172. package/dist/types/clientExecuteTypes.cjs.map +0 -1
  173. package/dist/types/clientExecuteTypes.js.map +0 -1
  174. package/dist/types/clientQueryTypes.cjs.map +0 -1
  175. package/dist/types/clientQueryTypes.js.map +0 -1
  176. package/dist/types/index.cjs.map +0 -1
  177. package/dist/types/index.js.map +0 -1
  178. package/dist/types/serverExecuteTypes.cjs.map +0 -1
  179. package/dist/types/serverExecuteTypes.js.map +0 -1
  180. package/dist/types/serverQueryModelTypes.cjs.map +0 -1
  181. package/dist/types/serverQueryModelTypes.js.map +0 -1
  182. package/dist/types/serverSubscriptionEventTypes.cjs.map +0 -1
  183. package/dist/types/serverSubscriptionEventTypes.js.map +0 -1
  184. package/dist/types/serverSubscriptionTypes.cjs.map +0 -1
  185. package/dist/types/serverSubscriptionTypes.js.map +0 -1
  186. package/dist/utils/index.cjs.map +0 -1
  187. package/dist/utils/index.js.map +0 -1
@@ -1,20 +1,2 @@
1
- import { BalanceHealthContributions, PerpMarket, SpotMarket } from '@nadohq/shared';
2
- import { EngineServerMarketPrice, EngineServerIsolatedPositionsResponse, EngineServerNlpLockedBalancesResponse, EngineServerNlpPoolInfoResponse, EngineServerOrderResponse, EngineServerSymbol, EngineServerSymbolsResponse, EngineServerPriceTickLiquidity, EngineServerSubaccountInfoResponse } from '../types/serverQueryTypes.cjs';
3
- import { EngineMarketPrice, GetEngineIsolatedPositionsResponse, GetEngineNlpLockedBalancesResponse, GetEngineNlpPoolInfoResponse, EngineOrder, EngineSymbol, EngineSymbolsResponse, EnginePriceTickLiquidity, GetEngineSubaccountSummaryResponse } from '../types/clientQueryTypes.cjs';
4
- import { EngineServerPerpProduct, EngineServerSpotProduct } from '../types/serverQueryModelTypes.cjs';
5
- import 'bignumber.js';
6
-
7
- declare function mapEngineServerTickLiquidity(tick: EngineServerPriceTickLiquidity): EnginePriceTickLiquidity;
8
- declare function mapEngineServerOrder(order: EngineServerOrderResponse): EngineOrder;
9
- declare function mapEngineServerSpotProduct(product: EngineServerSpotProduct): SpotMarket;
10
- declare function mapEngineServerPerpProduct(product: EngineServerPerpProduct): PerpMarket;
11
- declare function mapEngineServerBalanceHealthContributions(healthContributionsForBalance: string[]): BalanceHealthContributions;
12
- declare function mapSubaccountSummary(baseResponse: EngineServerSubaccountInfoResponse): GetEngineSubaccountSummaryResponse;
13
- declare function mapEngineServerIsolatedPositions(baseResponse: EngineServerIsolatedPositionsResponse): GetEngineIsolatedPositionsResponse;
14
- declare function mapEngineServerSymbols(baseResponse: EngineServerSymbolsResponse): EngineSymbolsResponse;
15
- declare function mapEngineServerSymbol(engineServerSymbol: EngineServerSymbol): EngineSymbol;
16
- declare function mapEngineMarketPrice(baseResponse: EngineServerMarketPrice): EngineMarketPrice;
17
- declare function mapEngineServerNlpLockedBalances(baseResponse: EngineServerNlpLockedBalancesResponse): GetEngineNlpLockedBalancesResponse;
18
- declare function mapEngineServerNlpPoolInfo(baseResponse: EngineServerNlpPoolInfoResponse): GetEngineNlpPoolInfoResponse;
19
-
20
- export { mapEngineMarketPrice, mapEngineServerBalanceHealthContributions, mapEngineServerIsolatedPositions, mapEngineServerNlpLockedBalances, mapEngineServerNlpPoolInfo, mapEngineServerOrder, mapEngineServerPerpProduct, mapEngineServerSpotProduct, mapEngineServerSymbol, mapEngineServerSymbols, mapEngineServerTickLiquidity, mapSubaccountSummary };
1
+ import { a as mapEngineServerNlpPoolInfo, c as mapEngineServerSpotProduct, d as mapEngineServerTickLiquidity, f as mapSubaccountSummary, i as mapEngineServerNlpLockedBalances, l as mapEngineServerSymbol, n as mapEngineServerBalanceHealthContributions, o as mapEngineServerOrder, r as mapEngineServerIsolatedPositions, s as mapEngineServerPerpProduct, t as mapEngineMarketPrice, u as mapEngineServerSymbols } from "../queryDataMappers-DO9yWdLo.cjs";
2
+ export { mapEngineMarketPrice, mapEngineServerBalanceHealthContributions, mapEngineServerIsolatedPositions, mapEngineServerNlpLockedBalances, mapEngineServerNlpPoolInfo, mapEngineServerOrder, mapEngineServerPerpProduct, mapEngineServerSpotProduct, mapEngineServerSymbol, mapEngineServerSymbols, mapEngineServerTickLiquidity, mapSubaccountSummary };
@@ -1,20 +1,2 @@
1
- import { BalanceHealthContributions, PerpMarket, SpotMarket } from '@nadohq/shared';
2
- import { EngineServerMarketPrice, EngineServerIsolatedPositionsResponse, EngineServerNlpLockedBalancesResponse, EngineServerNlpPoolInfoResponse, EngineServerOrderResponse, EngineServerSymbol, EngineServerSymbolsResponse, EngineServerPriceTickLiquidity, EngineServerSubaccountInfoResponse } from '../types/serverQueryTypes.js';
3
- import { EngineMarketPrice, GetEngineIsolatedPositionsResponse, GetEngineNlpLockedBalancesResponse, GetEngineNlpPoolInfoResponse, EngineOrder, EngineSymbol, EngineSymbolsResponse, EnginePriceTickLiquidity, GetEngineSubaccountSummaryResponse } from '../types/clientQueryTypes.js';
4
- import { EngineServerPerpProduct, EngineServerSpotProduct } from '../types/serverQueryModelTypes.js';
5
- import 'bignumber.js';
6
-
7
- declare function mapEngineServerTickLiquidity(tick: EngineServerPriceTickLiquidity): EnginePriceTickLiquidity;
8
- declare function mapEngineServerOrder(order: EngineServerOrderResponse): EngineOrder;
9
- declare function mapEngineServerSpotProduct(product: EngineServerSpotProduct): SpotMarket;
10
- declare function mapEngineServerPerpProduct(product: EngineServerPerpProduct): PerpMarket;
11
- declare function mapEngineServerBalanceHealthContributions(healthContributionsForBalance: string[]): BalanceHealthContributions;
12
- declare function mapSubaccountSummary(baseResponse: EngineServerSubaccountInfoResponse): GetEngineSubaccountSummaryResponse;
13
- declare function mapEngineServerIsolatedPositions(baseResponse: EngineServerIsolatedPositionsResponse): GetEngineIsolatedPositionsResponse;
14
- declare function mapEngineServerSymbols(baseResponse: EngineServerSymbolsResponse): EngineSymbolsResponse;
15
- declare function mapEngineServerSymbol(engineServerSymbol: EngineServerSymbol): EngineSymbol;
16
- declare function mapEngineMarketPrice(baseResponse: EngineServerMarketPrice): EngineMarketPrice;
17
- declare function mapEngineServerNlpLockedBalances(baseResponse: EngineServerNlpLockedBalancesResponse): GetEngineNlpLockedBalancesResponse;
18
- declare function mapEngineServerNlpPoolInfo(baseResponse: EngineServerNlpPoolInfoResponse): GetEngineNlpPoolInfoResponse;
19
-
20
- export { mapEngineMarketPrice, mapEngineServerBalanceHealthContributions, mapEngineServerIsolatedPositions, mapEngineServerNlpLockedBalances, mapEngineServerNlpPoolInfo, mapEngineServerOrder, mapEngineServerPerpProduct, mapEngineServerSpotProduct, mapEngineServerSymbol, mapEngineServerSymbols, mapEngineServerTickLiquidity, mapSubaccountSummary };
1
+ import { a as mapEngineServerNlpPoolInfo, c as mapEngineServerSpotProduct, d as mapEngineServerTickLiquidity, f as mapSubaccountSummary, i as mapEngineServerNlpLockedBalances, l as mapEngineServerSymbol, n as mapEngineServerBalanceHealthContributions, o as mapEngineServerOrder, r as mapEngineServerIsolatedPositions, s as mapEngineServerPerpProduct, t as mapEngineMarketPrice, u as mapEngineServerSymbols } from "../queryDataMappers-BguxA579.js";
2
+ export { mapEngineMarketPrice, mapEngineServerBalanceHealthContributions, mapEngineServerIsolatedPositions, mapEngineServerNlpLockedBalances, mapEngineServerNlpPoolInfo, mapEngineServerOrder, mapEngineServerPerpProduct, mapEngineServerSpotProduct, mapEngineServerSymbol, mapEngineServerSymbols, mapEngineServerTickLiquidity, mapSubaccountSummary };
@@ -1,292 +1,218 @@
1
- // src/utils/queryDataMappers.ts
2
- import {
3
- calcTotalBorrowed,
4
- calcTotalDeposited,
5
- mapValues,
6
- ProductEngineType,
7
- removeDecimals,
8
- subaccountFromHex,
9
- toBigNumber,
10
- unpackOrderAppendix
11
- } from "@nadohq/shared";
12
1
  import { mapEngineServerProductType } from "./productEngineTypeMappers.js";
2
+ import { ProductEngineType, calcTotalBorrowed, calcTotalDeposited, mapValues, removeDecimals, subaccountFromHex, toBigNumber, unpackOrderAppendix } from "@nadohq/shared";
3
+ //#region src/utils/queryDataMappers.ts
13
4
  function mapEngineServerTickLiquidity(tick) {
14
- return {
15
- price: removeDecimals(tick[0]),
16
- liquidity: toBigNumber(tick[1])
17
- };
5
+ return {
6
+ price: removeDecimals(tick[0]),
7
+ liquidity: toBigNumber(tick[1])
8
+ };
18
9
  }
19
10
  function mapEngineServerOrder(order) {
20
- const subaccount = subaccountFromHex(order.sender);
21
- return {
22
- digest: order.digest,
23
- expiration: Number(order.expiration),
24
- nonce: order.nonce,
25
- price: removeDecimals(order.price_x18),
26
- productId: order.product_id,
27
- subaccountOwner: subaccount.subaccountOwner,
28
- subaccountName: subaccount.subaccountName,
29
- totalAmount: toBigNumber(order.amount),
30
- unfilledAmount: toBigNumber(order.unfilled_amount),
31
- placementTime: order.placed_at,
32
- appendix: unpackOrderAppendix(order.appendix)
33
- };
11
+ const subaccount = subaccountFromHex(order.sender);
12
+ return {
13
+ digest: order.digest,
14
+ expiration: Number(order.expiration),
15
+ nonce: order.nonce,
16
+ price: removeDecimals(order.price_x18),
17
+ productId: order.product_id,
18
+ subaccountOwner: subaccount.subaccountOwner,
19
+ subaccountName: subaccount.subaccountName,
20
+ totalAmount: toBigNumber(order.amount),
21
+ unfilledAmount: toBigNumber(order.unfilled_amount),
22
+ placementTime: order.placed_at,
23
+ appendix: unpackOrderAppendix(order.appendix)
24
+ };
34
25
  }
35
26
  function mapEngineServerSpotProduct(product) {
36
- return {
37
- type: ProductEngineType.SPOT,
38
- productId: product.product_id,
39
- minSize: toBigNumber(product.book_info.min_size),
40
- priceIncrement: removeDecimals(product.book_info.price_increment_x18),
41
- sizeIncrement: toBigNumber(product.book_info.size_increment),
42
- product: {
43
- productId: product.product_id,
44
- type: ProductEngineType.SPOT,
45
- totalBorrowed: calcTotalBorrowed(
46
- product.state.total_borrows_normalized,
47
- product.state.cumulative_borrows_multiplier_x18
48
- ),
49
- totalDeposited: calcTotalDeposited(
50
- product.state.total_deposits_normalized,
51
- product.state.cumulative_deposits_multiplier_x18
52
- ),
53
- oraclePrice: removeDecimals(product.oracle_price_x18),
54
- interestFloor: removeDecimals(product.config.interest_floor_x18),
55
- interestInflectionUtil: removeDecimals(
56
- product.config.interest_inflection_util_x18
57
- ),
58
- interestLargeCap: removeDecimals(product.config.interest_large_cap_x18),
59
- interestSmallCap: removeDecimals(product.config.interest_small_cap_x18),
60
- minDepositRate: removeDecimals(product.config.min_deposit_rate_x18),
61
- longWeightInitial: removeDecimals(product.risk.long_weight_initial_x18),
62
- longWeightMaintenance: removeDecimals(
63
- product.risk.long_weight_maintenance_x18
64
- ),
65
- shortWeightInitial: removeDecimals(product.risk.short_weight_initial_x18),
66
- shortWeightMaintenance: removeDecimals(
67
- product.risk.short_weight_maintenance_x18
68
- ),
69
- tokenAddr: product.config.token
70
- }
71
- };
27
+ return {
28
+ type: ProductEngineType.SPOT,
29
+ productId: product.product_id,
30
+ minSize: toBigNumber(product.book_info.min_size),
31
+ priceIncrement: removeDecimals(product.book_info.price_increment_x18),
32
+ sizeIncrement: toBigNumber(product.book_info.size_increment),
33
+ product: {
34
+ productId: product.product_id,
35
+ type: ProductEngineType.SPOT,
36
+ totalBorrowed: calcTotalBorrowed(product.state.total_borrows_normalized, product.state.cumulative_borrows_multiplier_x18),
37
+ totalDeposited: calcTotalDeposited(product.state.total_deposits_normalized, product.state.cumulative_deposits_multiplier_x18),
38
+ oraclePrice: removeDecimals(product.oracle_price_x18),
39
+ interestFloor: removeDecimals(product.config.interest_floor_x18),
40
+ interestInflectionUtil: removeDecimals(product.config.interest_inflection_util_x18),
41
+ interestLargeCap: removeDecimals(product.config.interest_large_cap_x18),
42
+ interestSmallCap: removeDecimals(product.config.interest_small_cap_x18),
43
+ minDepositRate: removeDecimals(product.config.min_deposit_rate_x18),
44
+ longWeightInitial: removeDecimals(product.risk.long_weight_initial_x18),
45
+ longWeightMaintenance: removeDecimals(product.risk.long_weight_maintenance_x18),
46
+ shortWeightInitial: removeDecimals(product.risk.short_weight_initial_x18),
47
+ shortWeightMaintenance: removeDecimals(product.risk.short_weight_maintenance_x18),
48
+ tokenAddr: product.config.token
49
+ }
50
+ };
72
51
  }
73
52
  function mapEngineServerPerpProduct(product) {
74
- return {
75
- type: ProductEngineType.PERP,
76
- productId: product.product_id,
77
- minSize: toBigNumber(product.book_info.min_size),
78
- priceIncrement: removeDecimals(product.book_info.price_increment_x18),
79
- sizeIncrement: toBigNumber(product.book_info.size_increment),
80
- product: {
81
- productId: product.product_id,
82
- type: ProductEngineType.PERP,
83
- oraclePrice: removeDecimals(product.oracle_price_x18),
84
- longWeightInitial: removeDecimals(product.risk.long_weight_initial_x18),
85
- longWeightMaintenance: removeDecimals(
86
- product.risk.long_weight_maintenance_x18
87
- ),
88
- shortWeightInitial: removeDecimals(product.risk.short_weight_initial_x18),
89
- shortWeightMaintenance: removeDecimals(
90
- product.risk.short_weight_maintenance_x18
91
- ),
92
- openInterest: toBigNumber(product.state.open_interest),
93
- cumulativeFundingLong: removeDecimals(
94
- product.state.cumulative_funding_long_x18
95
- ),
96
- cumulativeFundingShort: removeDecimals(
97
- product.state.cumulative_funding_short_x18
98
- )
99
- }
100
- };
53
+ return {
54
+ type: ProductEngineType.PERP,
55
+ productId: product.product_id,
56
+ minSize: toBigNumber(product.book_info.min_size),
57
+ priceIncrement: removeDecimals(product.book_info.price_increment_x18),
58
+ sizeIncrement: toBigNumber(product.book_info.size_increment),
59
+ product: {
60
+ productId: product.product_id,
61
+ type: ProductEngineType.PERP,
62
+ oraclePrice: removeDecimals(product.oracle_price_x18),
63
+ longWeightInitial: removeDecimals(product.risk.long_weight_initial_x18),
64
+ longWeightMaintenance: removeDecimals(product.risk.long_weight_maintenance_x18),
65
+ shortWeightInitial: removeDecimals(product.risk.short_weight_initial_x18),
66
+ shortWeightMaintenance: removeDecimals(product.risk.short_weight_maintenance_x18),
67
+ openInterest: toBigNumber(product.state.open_interest),
68
+ cumulativeFundingLong: removeDecimals(product.state.cumulative_funding_long_x18),
69
+ cumulativeFundingShort: removeDecimals(product.state.cumulative_funding_short_x18)
70
+ }
71
+ };
101
72
  }
102
73
  function mapEngineServerBalanceHealthContributions(healthContributionsForBalance) {
103
- return {
104
- initial: toBigNumber(healthContributionsForBalance[0]),
105
- maintenance: toBigNumber(healthContributionsForBalance[1]),
106
- unweighted: toBigNumber(healthContributionsForBalance[2])
107
- };
74
+ return {
75
+ initial: toBigNumber(healthContributionsForBalance[0]),
76
+ maintenance: toBigNumber(healthContributionsForBalance[1]),
77
+ unweighted: toBigNumber(healthContributionsForBalance[2])
78
+ };
108
79
  }
109
80
  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
- };
81
+ return {
82
+ exists: baseResponse.exists,
83
+ ...mapSubaccountSummaryState(baseResponse, baseResponse.spot_products, baseResponse.perp_products),
84
+ preState: baseResponse.pre_state ? mapSubaccountSummaryState(baseResponse.pre_state, baseResponse.spot_products, baseResponse.perp_products) : void 0
85
+ };
123
86
  }
124
87
  function mapSubaccountSummaryState(state, spotProducts, perpProducts) {
125
- const balances = [];
126
- state.spot_balances.forEach((spotBalance) => {
127
- const product = spotProducts.find(
128
- (product2) => product2.product_id === spotBalance.product_id
129
- );
130
- if (!product) {
131
- throw Error(`Could not find product ${spotBalance.product_id}`);
132
- }
133
- balances.push({
134
- amount: toBigNumber(spotBalance.balance.amount),
135
- healthContributions: mapEngineServerBalanceHealthContributions(
136
- state.health_contributions[spotBalance.product_id]
137
- ),
138
- ...mapEngineServerSpotProduct(product).product
139
- });
140
- });
141
- state.perp_balances.forEach((perpBalance) => {
142
- const product = perpProducts.find(
143
- (product2) => product2.product_id === perpBalance.product_id
144
- );
145
- if (!product) {
146
- throw Error(`Could not find product ${perpBalance.product_id}`);
147
- }
148
- balances.push({
149
- amount: toBigNumber(perpBalance.balance.amount),
150
- vQuoteBalance: toBigNumber(perpBalance.balance.v_quote_balance),
151
- healthContributions: mapEngineServerBalanceHealthContributions(
152
- state.health_contributions[perpBalance.product_id]
153
- ),
154
- ...mapEngineServerPerpProduct(product).product
155
- });
156
- });
157
- return {
158
- balances,
159
- health: {
160
- initial: {
161
- health: toBigNumber(state.healths[0].health),
162
- assets: toBigNumber(state.healths[0].assets),
163
- liabilities: toBigNumber(state.healths[0].liabilities)
164
- },
165
- maintenance: {
166
- health: toBigNumber(state.healths[1].health),
167
- assets: toBigNumber(state.healths[1].assets),
168
- liabilities: toBigNumber(state.healths[1].liabilities)
169
- },
170
- unweighted: {
171
- health: toBigNumber(state.healths[2].health),
172
- assets: toBigNumber(state.healths[2].assets),
173
- liabilities: toBigNumber(state.healths[2].liabilities)
174
- }
175
- }
176
- };
88
+ const balances = [];
89
+ state.spot_balances.forEach((spotBalance) => {
90
+ const product = spotProducts.find((product) => product.product_id === spotBalance.product_id);
91
+ if (!product) throw Error(`Could not find product ${spotBalance.product_id}`);
92
+ balances.push({
93
+ amount: toBigNumber(spotBalance.balance.amount),
94
+ healthContributions: mapEngineServerBalanceHealthContributions(state.health_contributions[spotBalance.product_id]),
95
+ ...mapEngineServerSpotProduct(product).product
96
+ });
97
+ });
98
+ state.perp_balances.forEach((perpBalance) => {
99
+ const product = perpProducts.find((product) => product.product_id === perpBalance.product_id);
100
+ if (!product) throw Error(`Could not find product ${perpBalance.product_id}`);
101
+ balances.push({
102
+ amount: toBigNumber(perpBalance.balance.amount),
103
+ vQuoteBalance: toBigNumber(perpBalance.balance.v_quote_balance),
104
+ healthContributions: mapEngineServerBalanceHealthContributions(state.health_contributions[perpBalance.product_id]),
105
+ ...mapEngineServerPerpProduct(product).product
106
+ });
107
+ });
108
+ return {
109
+ balances,
110
+ health: {
111
+ initial: {
112
+ health: toBigNumber(state.healths[0].health),
113
+ assets: toBigNumber(state.healths[0].assets),
114
+ liabilities: toBigNumber(state.healths[0].liabilities)
115
+ },
116
+ maintenance: {
117
+ health: toBigNumber(state.healths[1].health),
118
+ assets: toBigNumber(state.healths[1].assets),
119
+ liabilities: toBigNumber(state.healths[1].liabilities)
120
+ },
121
+ unweighted: {
122
+ health: toBigNumber(state.healths[2].health),
123
+ assets: toBigNumber(state.healths[2].assets),
124
+ liabilities: toBigNumber(state.healths[2].liabilities)
125
+ }
126
+ }
127
+ };
177
128
  }
178
129
  function mapEngineServerIsolatedPositions(baseResponse) {
179
- return baseResponse.isolated_positions.map((position) => {
180
- const perpBalance = position.base_balance;
181
- const quoteBalance = position.quote_balance;
182
- return {
183
- subaccount: subaccountFromHex(position.subaccount),
184
- healths: {
185
- initial: toBigNumber(position.healths[0].health),
186
- maintenance: toBigNumber(position.healths[1].health),
187
- unweighted: toBigNumber(position.healths[2].health)
188
- },
189
- baseBalance: {
190
- amount: toBigNumber(perpBalance.balance.amount),
191
- vQuoteBalance: toBigNumber(perpBalance.balance.v_quote_balance),
192
- // Health contributions === healths for an isolated position
193
- healthContributions: {
194
- initial: toBigNumber(position.base_healths[0]),
195
- maintenance: toBigNumber(position.base_healths[1]),
196
- unweighted: toBigNumber(position.base_healths[2])
197
- },
198
- ...mapEngineServerPerpProduct(position.base_product).product
199
- },
200
- quoteBalance: {
201
- amount: toBigNumber(quoteBalance.balance.amount),
202
- healthContributions: {
203
- initial: toBigNumber(position.quote_healths[0]),
204
- maintenance: toBigNumber(position.quote_healths[1]),
205
- unweighted: toBigNumber(position.quote_healths[2])
206
- },
207
- ...mapEngineServerSpotProduct(position.quote_product).product
208
- }
209
- };
210
- });
130
+ return baseResponse.isolated_positions.map((position) => {
131
+ const perpBalance = position.base_balance;
132
+ const quoteBalance = position.quote_balance;
133
+ return {
134
+ subaccount: subaccountFromHex(position.subaccount),
135
+ healths: {
136
+ initial: toBigNumber(position.healths[0].health),
137
+ maintenance: toBigNumber(position.healths[1].health),
138
+ unweighted: toBigNumber(position.healths[2].health)
139
+ },
140
+ baseBalance: {
141
+ amount: toBigNumber(perpBalance.balance.amount),
142
+ vQuoteBalance: toBigNumber(perpBalance.balance.v_quote_balance),
143
+ healthContributions: {
144
+ initial: toBigNumber(position.base_healths[0]),
145
+ maintenance: toBigNumber(position.base_healths[1]),
146
+ unweighted: toBigNumber(position.base_healths[2])
147
+ },
148
+ ...mapEngineServerPerpProduct(position.base_product).product
149
+ },
150
+ quoteBalance: {
151
+ amount: toBigNumber(quoteBalance.balance.amount),
152
+ healthContributions: {
153
+ initial: toBigNumber(position.quote_healths[0]),
154
+ maintenance: toBigNumber(position.quote_healths[1]),
155
+ unweighted: toBigNumber(position.quote_healths[2])
156
+ },
157
+ ...mapEngineServerSpotProduct(position.quote_product).product
158
+ }
159
+ };
160
+ });
211
161
  }
212
162
  function mapEngineServerSymbols(baseResponse) {
213
- const symbols = mapValues(
214
- baseResponse.symbols,
215
- mapEngineServerSymbol
216
- );
217
- return {
218
- symbols
219
- };
163
+ return { symbols: mapValues(baseResponse.symbols, mapEngineServerSymbol) };
220
164
  }
221
165
  function mapEngineServerSymbol(engineServerSymbol) {
222
- return {
223
- type: mapEngineServerProductType(engineServerSymbol.type),
224
- productId: engineServerSymbol.product_id,
225
- symbol: engineServerSymbol.symbol,
226
- priceIncrement: removeDecimals(engineServerSymbol.price_increment_x18),
227
- sizeIncrement: toBigNumber(engineServerSymbol.size_increment),
228
- minSize: toBigNumber(engineServerSymbol.min_size),
229
- makerFeeRate: removeDecimals(engineServerSymbol.maker_fee_rate_x18),
230
- takerFeeRate: removeDecimals(engineServerSymbol.taker_fee_rate_x18),
231
- longWeightInitial: removeDecimals(
232
- engineServerSymbol.long_weight_initial_x18
233
- ),
234
- longWeightMaintenance: removeDecimals(
235
- engineServerSymbol.long_weight_maintenance_x18
236
- ),
237
- maxOpenInterest: removeDecimals(engineServerSymbol.max_open_interest_x18),
238
- isolatedOnly: engineServerSymbol.isolated_only
239
- };
166
+ return {
167
+ type: mapEngineServerProductType(engineServerSymbol.type),
168
+ productId: engineServerSymbol.product_id,
169
+ symbol: engineServerSymbol.symbol,
170
+ priceIncrement: removeDecimals(engineServerSymbol.price_increment_x18),
171
+ sizeIncrement: toBigNumber(engineServerSymbol.size_increment),
172
+ minSize: toBigNumber(engineServerSymbol.min_size),
173
+ makerFeeRate: removeDecimals(engineServerSymbol.maker_fee_rate_x18),
174
+ takerFeeRate: removeDecimals(engineServerSymbol.taker_fee_rate_x18),
175
+ longWeightInitial: removeDecimals(engineServerSymbol.long_weight_initial_x18),
176
+ longWeightMaintenance: removeDecimals(engineServerSymbol.long_weight_maintenance_x18),
177
+ maxOpenInterest: removeDecimals(engineServerSymbol.max_open_interest_x18),
178
+ isolatedOnly: engineServerSymbol.isolated_only
179
+ };
240
180
  }
241
181
  function mapEngineMarketPrice(baseResponse) {
242
- return {
243
- ask: removeDecimals(baseResponse.ask_x18),
244
- bid: removeDecimals(baseResponse.bid_x18),
245
- productId: baseResponse.product_id
246
- };
182
+ return {
183
+ ask: removeDecimals(baseResponse.ask_x18),
184
+ bid: removeDecimals(baseResponse.bid_x18),
185
+ productId: baseResponse.product_id
186
+ };
247
187
  }
248
188
  function mapEngineServerNlpLockedBalances(baseResponse) {
249
- const lockedBalances = baseResponse.locked_balances.map((lockedBalance) => ({
250
- productId: lockedBalance.balance.product_id,
251
- balance: toBigNumber(lockedBalance.balance.balance.amount),
252
- unlockedAt: lockedBalance.unlocked_at
253
- }));
254
- return {
255
- lockedBalances,
256
- balanceLocked: {
257
- productId: baseResponse.balance_locked.product_id,
258
- balance: toBigNumber(baseResponse.balance_locked.balance.amount)
259
- },
260
- balanceUnlocked: {
261
- productId: baseResponse.balance_unlocked.product_id,
262
- balance: toBigNumber(baseResponse.balance_unlocked.balance.amount)
263
- }
264
- };
189
+ return {
190
+ lockedBalances: baseResponse.locked_balances.map((lockedBalance) => ({
191
+ productId: lockedBalance.balance.product_id,
192
+ balance: toBigNumber(lockedBalance.balance.balance.amount),
193
+ unlockedAt: lockedBalance.unlocked_at
194
+ })),
195
+ balanceLocked: {
196
+ productId: baseResponse.balance_locked.product_id,
197
+ balance: toBigNumber(baseResponse.balance_locked.balance.amount)
198
+ },
199
+ balanceUnlocked: {
200
+ productId: baseResponse.balance_unlocked.product_id,
201
+ balance: toBigNumber(baseResponse.balance_unlocked.balance.amount)
202
+ }
203
+ };
265
204
  }
266
205
  function mapEngineServerNlpPoolInfo(baseResponse) {
267
- return {
268
- nlpPools: baseResponse.nlp_pools.map((pool) => ({
269
- poolId: pool.pool_id,
270
- subaccountHex: pool.subaccount,
271
- ownerAddress: pool.owner,
272
- balanceWeight: removeDecimals(pool.balance_weight_x18),
273
- subaccountInfo: mapSubaccountSummary(pool.subaccount_info),
274
- openOrders: pool.open_orders.map(mapEngineServerOrder)
275
- }))
276
- };
206
+ return { nlpPools: baseResponse.nlp_pools.map((pool) => ({
207
+ poolId: pool.pool_id,
208
+ subaccountHex: pool.subaccount,
209
+ ownerAddress: pool.owner,
210
+ balanceWeight: removeDecimals(pool.balance_weight_x18),
211
+ subaccountInfo: mapSubaccountSummary(pool.subaccount_info),
212
+ openOrders: pool.open_orders.map(mapEngineServerOrder)
213
+ })) };
277
214
  }
278
- export {
279
- mapEngineMarketPrice,
280
- mapEngineServerBalanceHealthContributions,
281
- mapEngineServerIsolatedPositions,
282
- mapEngineServerNlpLockedBalances,
283
- mapEngineServerNlpPoolInfo,
284
- mapEngineServerOrder,
285
- mapEngineServerPerpProduct,
286
- mapEngineServerSpotProduct,
287
- mapEngineServerSymbol,
288
- mapEngineServerSymbols,
289
- mapEngineServerTickLiquidity,
290
- mapSubaccountSummary
291
- };
215
+ //#endregion
216
+ export { mapEngineMarketPrice, mapEngineServerBalanceHealthContributions, mapEngineServerIsolatedPositions, mapEngineServerNlpLockedBalances, mapEngineServerNlpPoolInfo, mapEngineServerOrder, mapEngineServerPerpProduct, mapEngineServerSpotProduct, mapEngineServerSymbol, mapEngineServerSymbols, mapEngineServerTickLiquidity, mapSubaccountSummary };
217
+
292
218
  //# sourceMappingURL=queryDataMappers.js.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":";AAAA;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AA0BP,SAAS,kCAAkC;AAEpC,SAAS,6BACd,MAC0B;AAC1B,SAAO;AAAA,IACL,OAAO,eAAe,KAAK,CAAC,CAAC;AAAA,IAC7B,WAAW,YAAY,KAAK,CAAC,CAAC;AAAA,EAChC;AACF;AAEO,SAAS,qBACd,OACa;AACb,QAAM,aAAa,kBAAkB,MAAM,MAAM;AACjD,SAAO;AAAA,IACL,QAAQ,MAAM;AAAA,IACd,YAAY,OAAO,MAAM,UAAU;AAAA,IACnC,OAAO,MAAM;AAAA,IACb,OAAO,eAAe,MAAM,SAAS;AAAA,IACrC,WAAW,MAAM;AAAA,IACjB,iBAAiB,WAAW;AAAA,IAC5B,gBAAgB,WAAW;AAAA,IAC3B,aAAa,YAAY,MAAM,MAAM;AAAA,IACrC,gBAAgB,YAAY,MAAM,eAAe;AAAA,IACjD,eAAe,MAAM;AAAA,IACrB,UAAU,oBAAoB,MAAM,QAAQ;AAAA,EAC9C;AACF;AAEO,SAAS,2BACd,SACY;AACZ,SAAO;AAAA,IACL,MAAM,kBAAkB;AAAA,IACxB,WAAW,QAAQ;AAAA,IACnB,SAAS,YAAY,QAAQ,UAAU,QAAQ;AAAA,IAC/C,gBAAgB,e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IAAI,oBAAoB;AAAA,IACvD,EAAE;AAAA,EACJ;AACF;","names":["product"]}
1
+ {"version":3,"file":"queryDataMappers.js","names":[],"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":";;;AAwCA,SAAgB,6BACd,MAC0B;CAC1B,OAAO;EACL,OAAO,eAAe,KAAK,EAAE;EAC7B,WAAW,YAAY,KAAK,EAAE;CAChC;AACF;AAEA,SAAgB,qBACd,OACa;CACb,MAAM,aAAa,kBAAkB,MAAM,MAAM;CACjD,OAAO;EACL,QAAQ,MAAM;EACd,YAAY,OAAO,MAAM,UAAU;EACnC,OAAO,MAAM;EACb,OAAO,eAAe,MAAM,SAAS;EACrC,WAAW,MAAM;EACjB,iBAAiB,WAAW;EAC5B,gBAAgB,WAAW;EAC3B,aAAa,YAAY,MAAM,MAAM;EACrC,gBAAgB,YAAY,MAAM,eAAe;EACjD,eAAe,MAAM;EACrB,UAAU,oBAAoB,MAAM,QAAQ;CAC9C;AACF;AAEA,SAAgB,2BACd,SACY;CACZ,OAAO;EACL,MAAM,kBAAkB;EACxB,WAAW,QAAQ;EACnB,SAAS,YAAY,QAAQ,UAAU,QAAQ;EAC/C,gBAAgB,eAAe,QAAQ,UAAU,mBAAmB;EACpE,eAAe,YAAY,QAAQ,UAAU,cAAc;EAC3D,SAAS;GACP,WAAW,QAAQ;GACnB,MAAM,kBAAkB;GACxB,eAAe,kBACb,QAAQ,MAAM,0BACd,QAAQ,MAAM,iCAChB;GACA,gBAAgB,mBACd,QAAQ,MAAM,2BACd,QAAQ,MAAM,kCAChB;GACA,aAAa,eAAe,QAAQ,gBAAgB;GACpD,eAAe,eAAe,QAAQ,OAAO,kBAAkB;GAC/D,wBAAwB,eACtB,QAAQ,OAAO,4BACjB;GACA,kBAAkB,eAAe,QAAQ,OAAO,sBAAs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