@nadohq/engine-client 0.1.0-alpha.3 → 0.1.0-alpha.30

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 (110) hide show
  1. package/dist/EngineBaseClient.cjs +8 -7
  2. package/dist/EngineBaseClient.cjs.map +1 -1
  3. package/dist/EngineBaseClient.d.cts +2 -3
  4. package/dist/EngineBaseClient.d.ts +2 -3
  5. package/dist/EngineBaseClient.js +7 -5
  6. package/dist/EngineBaseClient.js.map +1 -1
  7. package/dist/EngineClient.d.cts +1 -2
  8. package/dist/EngineClient.d.ts +1 -2
  9. package/dist/EngineExecuteBuilder.cjs +25 -50
  10. package/dist/EngineExecuteBuilder.cjs.map +1 -1
  11. package/dist/EngineExecuteBuilder.d.cts +6 -17
  12. package/dist/EngineExecuteBuilder.d.ts +6 -17
  13. package/dist/EngineExecuteBuilder.js +15 -40
  14. package/dist/EngineExecuteBuilder.js.map +1 -1
  15. package/dist/EngineExecuteClient.cjs +5 -9
  16. package/dist/EngineExecuteClient.cjs.map +1 -1
  17. package/dist/EngineExecuteClient.d.cts +3 -4
  18. package/dist/EngineExecuteClient.d.ts +3 -4
  19. package/dist/EngineExecuteClient.js +5 -9
  20. package/dist/EngineExecuteClient.js.map +1 -1
  21. package/dist/EngineQueryClient.cjs +70 -53
  22. package/dist/EngineQueryClient.cjs.map +1 -1
  23. package/dist/EngineQueryClient.d.cts +17 -12
  24. package/dist/EngineQueryClient.d.ts +17 -12
  25. package/dist/EngineQueryClient.js +50 -31
  26. package/dist/EngineQueryClient.js.map +1 -1
  27. package/dist/EngineWebClient.cjs +0 -2
  28. package/dist/EngineWebClient.cjs.map +1 -1
  29. package/dist/EngineWebClient.d.cts +1 -2
  30. package/dist/EngineWebClient.d.ts +1 -2
  31. package/dist/EngineWebClient.js +0 -2
  32. package/dist/EngineWebClient.js.map +1 -1
  33. package/dist/endpoints.cjs +6 -6
  34. package/dist/endpoints.cjs.map +1 -1
  35. package/dist/endpoints.d.cts +1 -1
  36. package/dist/endpoints.d.ts +1 -1
  37. package/dist/endpoints.js +6 -6
  38. package/dist/endpoints.js.map +1 -1
  39. package/dist/index.cjs +4 -4
  40. package/dist/index.cjs.map +1 -1
  41. package/dist/index.d.cts +11 -12
  42. package/dist/index.d.ts +11 -12
  43. package/dist/index.js +2 -2
  44. package/dist/index.js.map +1 -1
  45. package/dist/types/EngineServerFailureError.cjs +1 -1
  46. package/dist/types/EngineServerFailureError.cjs.map +1 -1
  47. package/dist/types/EngineServerFailureError.d.cts +2 -2
  48. package/dist/types/EngineServerFailureError.d.ts +2 -2
  49. package/dist/types/EngineServerFailureError.js +1 -1
  50. package/dist/types/EngineServerFailureError.js.map +1 -1
  51. package/dist/types/clientExecuteTypes.cjs.map +1 -1
  52. package/dist/types/clientExecuteTypes.d.cts +11 -12
  53. package/dist/types/clientExecuteTypes.d.ts +11 -12
  54. package/dist/types/clientQueryTypes.cjs.map +1 -1
  55. package/dist/types/clientQueryTypes.d.cts +41 -23
  56. package/dist/types/clientQueryTypes.d.ts +41 -23
  57. package/dist/types/index.cjs +10 -10
  58. package/dist/types/index.cjs.map +1 -1
  59. package/dist/types/index.d.cts +8 -9
  60. package/dist/types/index.d.ts +8 -9
  61. package/dist/types/index.js +5 -5
  62. package/dist/types/index.js.map +1 -1
  63. package/dist/types/serverExecuteTypes.cjs.map +1 -1
  64. package/dist/types/serverExecuteTypes.d.cts +13 -14
  65. package/dist/types/serverExecuteTypes.d.ts +13 -14
  66. package/dist/types/serverQueryModelTypes.cjs.map +1 -1
  67. package/dist/types/serverQueryModelTypes.d.cts +25 -2
  68. package/dist/types/serverQueryModelTypes.d.ts +25 -2
  69. package/dist/types/serverQueryTypes.cjs.map +1 -1
  70. package/dist/types/serverQueryTypes.d.cts +37 -26
  71. package/dist/types/serverQueryTypes.d.ts +37 -26
  72. package/dist/types/serverSubscriptionEventTypes.cjs.map +1 -1
  73. package/dist/types/serverSubscriptionEventTypes.d.cts +87 -23
  74. package/dist/types/serverSubscriptionEventTypes.d.ts +87 -23
  75. package/dist/types/serverSubscriptionTypes.cjs.map +1 -1
  76. package/dist/types/serverSubscriptionTypes.d.cts +21 -4
  77. package/dist/types/serverSubscriptionTypes.d.ts +21 -4
  78. package/dist/utils/index.d.cts +3 -4
  79. package/dist/utils/index.d.ts +3 -4
  80. package/dist/utils/productEngineTypeMappers.cjs +5 -5
  81. package/dist/utils/productEngineTypeMappers.cjs.map +1 -1
  82. package/dist/utils/productEngineTypeMappers.d.cts +1 -1
  83. package/dist/utils/productEngineTypeMappers.d.ts +1 -1
  84. package/dist/utils/productEngineTypeMappers.js +1 -1
  85. package/dist/utils/productEngineTypeMappers.js.map +1 -1
  86. package/dist/utils/queryDataMappers.cjs +113 -90
  87. package/dist/utils/queryDataMappers.cjs.map +1 -1
  88. package/dist/utils/queryDataMappers.d.cts +6 -5
  89. package/dist/utils/queryDataMappers.d.ts +6 -5
  90. package/dist/utils/queryDataMappers.js +39 -19
  91. package/dist/utils/queryDataMappers.js.map +1 -1
  92. package/package.json +3 -4
  93. package/src/EngineBaseClient.ts +5 -3
  94. package/src/EngineExecuteBuilder.ts +16 -53
  95. package/src/EngineExecuteClient.ts +5 -13
  96. package/src/EngineQueryClient.ts +62 -32
  97. package/src/EngineWebClient.ts +0 -2
  98. package/src/endpoints.ts +4 -5
  99. package/src/index.ts +2 -2
  100. package/src/types/EngineServerFailureError.ts +2 -2
  101. package/src/types/clientExecuteTypes.ts +12 -17
  102. package/src/types/clientQueryTypes.ts +57 -32
  103. package/src/types/index.ts +5 -5
  104. package/src/types/serverExecuteTypes.ts +14 -18
  105. package/src/types/serverQueryModelTypes.ts +26 -1
  106. package/src/types/serverQueryTypes.ts +46 -29
  107. package/src/types/serverSubscriptionEventTypes.ts +131 -21
  108. package/src/types/serverSubscriptionTypes.ts +23 -3
  109. package/src/utils/productEngineTypeMappers.ts +1 -1
  110. package/src/utils/queryDataMappers.ts +50 -20
@@ -1,5 +1,6 @@
1
1
  interface EngineServerOrderUpdateStreamParams {
2
- product_id: number;
2
+ /** when not provided, subscribes to all products */
3
+ product_id?: number;
3
4
  subaccount: string;
4
5
  }
5
6
  interface EngineServerTradeStreamParams {
@@ -9,16 +10,29 @@ interface EngineServerBestBidOfferStreamParams {
9
10
  product_id: number;
10
11
  }
11
12
  interface EngineServerFillStreamParams {
12
- product_id: number;
13
+ /** when not provided, subscribes to all products */
14
+ product_id?: number;
13
15
  subaccount: string;
14
16
  }
15
17
  interface EngineServerPositionChangeStreamParams {
16
- product_id: number;
18
+ /** when not provided, subscribes to all products */
19
+ product_id?: number;
17
20
  subaccount: string;
18
21
  }
19
22
  interface EngineServerBookDepthStreamParams {
20
23
  product_id: number;
21
24
  }
25
+ interface EngineServerLatestCandlestickStreamParams {
26
+ product_id: number;
27
+ granularity: number;
28
+ }
29
+ interface EngineServerLiquidationStreamParams {
30
+ /** when not provided, subscribes to all products */
31
+ product_id?: number;
32
+ }
33
+ interface EngineServerFundingPaymentStreamParams {
34
+ product_id: number;
35
+ }
22
36
  /**
23
37
  * Available subscription streams
24
38
  */
@@ -29,6 +43,9 @@ interface EngineServerSubscriptionStreamParamsByType {
29
43
  fill: EngineServerFillStreamParams;
30
44
  position_change: EngineServerPositionChangeStreamParams;
31
45
  book_depth: EngineServerBookDepthStreamParams;
46
+ liquidation: EngineServerLiquidationStreamParams;
47
+ latest_candlestick: EngineServerLatestCandlestickStreamParams;
48
+ funding_payment: EngineServerFundingPaymentStreamParams;
32
49
  }
33
50
  type EngineServerSubscriptionStreamParamsType = keyof EngineServerSubscriptionStreamParamsByType;
34
51
  /**
@@ -60,4 +77,4 @@ type EngineServerSubscriptionRequest<TRequestType extends EngineServerSubscripti
60
77
  method: TRequestType;
61
78
  } & EngineServerSubscriptionRequestByType[TRequestType];
62
79
 
63
- export type { EngineServerBestBidOfferStreamParams, EngineServerBookDepthStreamParams, EngineServerFillStreamParams, EngineServerOrderUpdateStreamParams, EngineServerPositionChangeStreamParams, EngineServerSubscriptionParams, EngineServerSubscriptionRequest, EngineServerSubscriptionRequestByType, EngineServerSubscriptionRequestType, EngineServerSubscriptionStream, EngineServerSubscriptionStreamParamsByType, EngineServerSubscriptionStreamParamsType, EngineServerTradeStreamParams };
80
+ export type { EngineServerBestBidOfferStreamParams, EngineServerBookDepthStreamParams, EngineServerFillStreamParams, EngineServerFundingPaymentStreamParams, EngineServerLatestCandlestickStreamParams, EngineServerLiquidationStreamParams, EngineServerOrderUpdateStreamParams, EngineServerPositionChangeStreamParams, EngineServerSubscriptionParams, EngineServerSubscriptionRequest, EngineServerSubscriptionRequestByType, EngineServerSubscriptionRequestType, EngineServerSubscriptionStream, EngineServerSubscriptionStreamParamsByType, EngineServerSubscriptionStreamParamsType, EngineServerTradeStreamParams };
@@ -1,5 +1,6 @@
1
1
  interface EngineServerOrderUpdateStreamParams {
2
- product_id: number;
2
+ /** when not provided, subscribes to all products */
3
+ product_id?: number;
3
4
  subaccount: string;
4
5
  }
5
6
  interface EngineServerTradeStreamParams {
@@ -9,16 +10,29 @@ interface EngineServerBestBidOfferStreamParams {
9
10
  product_id: number;
10
11
  }
11
12
  interface EngineServerFillStreamParams {
12
- product_id: number;
13
+ /** when not provided, subscribes to all products */
14
+ product_id?: number;
13
15
  subaccount: string;
14
16
  }
15
17
  interface EngineServerPositionChangeStreamParams {
16
- product_id: number;
18
+ /** when not provided, subscribes to all products */
19
+ product_id?: number;
17
20
  subaccount: string;
18
21
  }
19
22
  interface EngineServerBookDepthStreamParams {
20
23
  product_id: number;
21
24
  }
25
+ interface EngineServerLatestCandlestickStreamParams {
26
+ product_id: number;
27
+ granularity: number;
28
+ }
29
+ interface EngineServerLiquidationStreamParams {
30
+ /** when not provided, subscribes to all products */
31
+ product_id?: number;
32
+ }
33
+ interface EngineServerFundingPaymentStreamParams {
34
+ product_id: number;
35
+ }
22
36
  /**
23
37
  * Available subscription streams
24
38
  */
@@ -29,6 +43,9 @@ interface EngineServerSubscriptionStreamParamsByType {
29
43
  fill: EngineServerFillStreamParams;
30
44
  position_change: EngineServerPositionChangeStreamParams;
31
45
  book_depth: EngineServerBookDepthStreamParams;
46
+ liquidation: EngineServerLiquidationStreamParams;
47
+ latest_candlestick: EngineServerLatestCandlestickStreamParams;
48
+ funding_payment: EngineServerFundingPaymentStreamParams;
32
49
  }
33
50
  type EngineServerSubscriptionStreamParamsType = keyof EngineServerSubscriptionStreamParamsByType;
34
51
  /**
@@ -60,4 +77,4 @@ type EngineServerSubscriptionRequest<TRequestType extends EngineServerSubscripti
60
77
  method: TRequestType;
61
78
  } & EngineServerSubscriptionRequestByType[TRequestType];
62
79
 
63
- export type { EngineServerBestBidOfferStreamParams, EngineServerBookDepthStreamParams, EngineServerFillStreamParams, EngineServerOrderUpdateStreamParams, EngineServerPositionChangeStreamParams, EngineServerSubscriptionParams, EngineServerSubscriptionRequest, EngineServerSubscriptionRequestByType, EngineServerSubscriptionRequestType, EngineServerSubscriptionStream, EngineServerSubscriptionStreamParamsByType, EngineServerSubscriptionStreamParamsType, EngineServerTradeStreamParams };
80
+ export type { EngineServerBestBidOfferStreamParams, EngineServerBookDepthStreamParams, EngineServerFillStreamParams, EngineServerFundingPaymentStreamParams, EngineServerLatestCandlestickStreamParams, EngineServerLiquidationStreamParams, EngineServerOrderUpdateStreamParams, EngineServerPositionChangeStreamParams, EngineServerSubscriptionParams, EngineServerSubscriptionRequest, EngineServerSubscriptionRequestByType, EngineServerSubscriptionRequestType, EngineServerSubscriptionStream, EngineServerSubscriptionStreamParamsByType, EngineServerSubscriptionStreamParamsType, EngineServerTradeStreamParams };
@@ -1,6 +1,5 @@
1
- export { mapEngineMarketPrice, mapEngineServerBalanceHealthContributions, mapEngineServerIsolatedPositions, mapEngineServerOrder, mapEngineServerPerpProduct, mapEngineServerSpotProduct, mapEngineServerSymbol, mapEngineServerSymbols, mapEngineServerTickLiquidity, mapSubaccountSummary } from './queryDataMappers.cjs';
2
- import '@nadohq/contracts';
3
- import '../types/clientQueryTypes.cjs';
4
- import '@nadohq/utils';
1
+ export { mapEngineMarketPrice, mapEngineServerBalanceHealthContributions, mapEngineServerIsolatedPositions, mapEngineServerNlpLockedBalances, mapEngineServerNlpPoolInfo, mapEngineServerOrder, mapEngineServerPerpProduct, mapEngineServerSpotProduct, mapEngineServerSymbol, mapEngineServerSymbols, mapEngineServerTickLiquidity, mapSubaccountSummary } from './queryDataMappers.cjs';
2
+ import '@nadohq/shared';
5
3
  import '../types/serverQueryTypes.cjs';
6
4
  import '../types/serverQueryModelTypes.cjs';
5
+ import '../types/clientQueryTypes.cjs';
@@ -1,6 +1,5 @@
1
- export { mapEngineMarketPrice, mapEngineServerBalanceHealthContributions, mapEngineServerIsolatedPositions, mapEngineServerOrder, mapEngineServerPerpProduct, mapEngineServerSpotProduct, mapEngineServerSymbol, mapEngineServerSymbols, mapEngineServerTickLiquidity, mapSubaccountSummary } from './queryDataMappers.js';
2
- import '@nadohq/contracts';
3
- import '../types/clientQueryTypes.js';
4
- import '@nadohq/utils';
1
+ export { mapEngineMarketPrice, mapEngineServerBalanceHealthContributions, mapEngineServerIsolatedPositions, mapEngineServerNlpLockedBalances, mapEngineServerNlpPoolInfo, mapEngineServerOrder, mapEngineServerPerpProduct, mapEngineServerSpotProduct, mapEngineServerSymbol, mapEngineServerSymbols, mapEngineServerTickLiquidity, mapSubaccountSummary } from './queryDataMappers.js';
2
+ import '@nadohq/shared';
5
3
  import '../types/serverQueryTypes.js';
6
4
  import '../types/serverQueryModelTypes.js';
5
+ import '../types/clientQueryTypes.js';
@@ -24,21 +24,21 @@ __export(productEngineTypeMappers_exports, {
24
24
  mapProductEngineType: () => mapProductEngineType
25
25
  });
26
26
  module.exports = __toCommonJS(productEngineTypeMappers_exports);
27
- var import_contracts = require("@nadohq/contracts");
27
+ var import_shared = require("@nadohq/shared");
28
28
  function mapProductEngineType(productEngineType) {
29
29
  switch (productEngineType) {
30
- case import_contracts.ProductEngineType.SPOT:
30
+ case import_shared.ProductEngineType.SPOT:
31
31
  return "spot";
32
- case import_contracts.ProductEngineType.PERP:
32
+ case import_shared.ProductEngineType.PERP:
33
33
  return "perp";
34
34
  }
35
35
  }
36
36
  function mapEngineServerProductType(productEngineServerType) {
37
37
  switch (productEngineServerType) {
38
38
  case "spot":
39
- return import_contracts.ProductEngineType.SPOT;
39
+ return import_shared.ProductEngineType.SPOT;
40
40
  case "perp":
41
- return import_contracts.ProductEngineType.PERP;
41
+ return import_shared.ProductEngineType.PERP;
42
42
  }
43
43
  }
44
44
  // Annotate the CommonJS export names for ESM import in node:
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/productEngineTypeMappers.ts"],"sourcesContent":["import { ProductEngineType } from '@nadohq/contracts';\nimport { EngineServerProductType } from '../types';\n\nexport function mapProductEngineType(\n productEngineType: ProductEngineType,\n): EngineServerProductType {\n switch (productEngineType) {\n case ProductEngineType.SPOT:\n return 'spot';\n case ProductEngineType.PERP:\n return 'perp';\n }\n}\n\nexport function mapEngineServerProductType(\n productEngineServerType: EngineServerProductType,\n): ProductEngineType {\n switch (productEngineServerType) {\n case 'spot':\n return ProductEngineType.SPOT;\n case 'perp':\n return ProductEngineType.PERP;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAkC;AAG3B,SAAS,qBACd,mBACyB;AACzB,UAAQ,mBAAmB;AAAA,IACzB,KAAK,mCAAkB;AACrB,aAAO;AAAA,IACT,KAAK,mCAAkB;AACrB,aAAO;AAAA,EACX;AACF;AAEO,SAAS,2BACd,yBACmB;AACnB,UAAQ,yBAAyB;AAAA,IAC/B,KAAK;AACH,aAAO,mCAAkB;AAAA,IAC3B,KAAK;AACH,aAAO,mCAAkB;AAAA,EAC7B;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/utils/productEngineTypeMappers.ts"],"sourcesContent":["import { ProductEngineType } from '@nadohq/shared';\nimport { EngineServerProductType } from '../types';\n\nexport function mapProductEngineType(\n productEngineType: ProductEngineType,\n): EngineServerProductType {\n switch (productEngineType) {\n case ProductEngineType.SPOT:\n return 'spot';\n case ProductEngineType.PERP:\n return 'perp';\n }\n}\n\nexport function mapEngineServerProductType(\n productEngineServerType: EngineServerProductType,\n): ProductEngineType {\n switch (productEngineServerType) {\n case 'spot':\n return ProductEngineType.SPOT;\n case 'perp':\n return ProductEngineType.PERP;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAkC;AAG3B,SAAS,qBACd,mBACyB;AACzB,UAAQ,mBAAmB;AAAA,IACzB,KAAK,gCAAkB;AACrB,aAAO;AAAA,IACT,KAAK,gCAAkB;AACrB,aAAO;AAAA,EACX;AACF;AAEO,SAAS,2BACd,yBACmB;AACnB,UAAQ,yBAAyB;AAAA,IAC/B,KAAK;AACH,aAAO,gCAAkB;AAAA,IAC3B,KAAK;AACH,aAAO,gCAAkB;AAAA,EAC7B;AACF;","names":[]}
@@ -1,4 +1,4 @@
1
- import { ProductEngineType } from '@nadohq/contracts';
1
+ import { ProductEngineType } from '@nadohq/shared';
2
2
  import { EngineServerProductType } from '../types/serverQueryModelTypes.cjs';
3
3
 
4
4
  declare function mapProductEngineType(productEngineType: ProductEngineType): EngineServerProductType;
@@ -1,4 +1,4 @@
1
- import { ProductEngineType } from '@nadohq/contracts';
1
+ import { ProductEngineType } from '@nadohq/shared';
2
2
  import { EngineServerProductType } from '../types/serverQueryModelTypes.js';
3
3
 
4
4
  declare function mapProductEngineType(productEngineType: ProductEngineType): EngineServerProductType;
@@ -1,5 +1,5 @@
1
1
  // src/utils/productEngineTypeMappers.ts
2
- import { ProductEngineType } from "@nadohq/contracts";
2
+ import { ProductEngineType } from "@nadohq/shared";
3
3
  function mapProductEngineType(productEngineType) {
4
4
  switch (productEngineType) {
5
5
  case ProductEngineType.SPOT:
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/productEngineTypeMappers.ts"],"sourcesContent":["import { ProductEngineType } from '@nadohq/contracts';\nimport { EngineServerProductType } from '../types';\n\nexport function mapProductEngineType(\n productEngineType: ProductEngineType,\n): EngineServerProductType {\n switch (productEngineType) {\n case ProductEngineType.SPOT:\n return 'spot';\n case ProductEngineType.PERP:\n return 'perp';\n }\n}\n\nexport function mapEngineServerProductType(\n productEngineServerType: EngineServerProductType,\n): ProductEngineType {\n switch (productEngineServerType) {\n case 'spot':\n return ProductEngineType.SPOT;\n case 'perp':\n return ProductEngineType.PERP;\n }\n}\n"],"mappings":";AAAA,SAAS,yBAAyB;AAG3B,SAAS,qBACd,mBACyB;AACzB,UAAQ,mBAAmB;AAAA,IACzB,KAAK,kBAAkB;AACrB,aAAO;AAAA,IACT,KAAK,kBAAkB;AACrB,aAAO;AAAA,EACX;AACF;AAEO,SAAS,2BACd,yBACmB;AACnB,UAAQ,yBAAyB;AAAA,IAC/B,KAAK;AACH,aAAO,kBAAkB;AAAA,IAC3B,KAAK;AACH,aAAO,kBAAkB;AAAA,EAC7B;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/utils/productEngineTypeMappers.ts"],"sourcesContent":["import { ProductEngineType } from '@nadohq/shared';\nimport { EngineServerProductType } from '../types';\n\nexport function mapProductEngineType(\n productEngineType: ProductEngineType,\n): EngineServerProductType {\n switch (productEngineType) {\n case ProductEngineType.SPOT:\n return 'spot';\n case ProductEngineType.PERP:\n return 'perp';\n }\n}\n\nexport function mapEngineServerProductType(\n productEngineServerType: EngineServerProductType,\n): ProductEngineType {\n switch (productEngineServerType) {\n case 'spot':\n return ProductEngineType.SPOT;\n case 'perp':\n return ProductEngineType.PERP;\n }\n}\n"],"mappings":";AAAA,SAAS,yBAAyB;AAG3B,SAAS,qBACd,mBACyB;AACzB,UAAQ,mBAAmB;AAAA,IACzB,KAAK,kBAAkB;AACrB,aAAO;AAAA,IACT,KAAK,kBAAkB;AACrB,aAAO;AAAA,EACX;AACF;AAEO,SAAS,2BACd,yBACmB;AACnB,UAAQ,yBAAyB;AAAA,IAC/B,KAAK;AACH,aAAO,kBAAkB;AAAA,IAC3B,KAAK;AACH,aAAO,kBAAkB;AAAA,EAC7B;AACF;","names":[]}
@@ -23,6 +23,8 @@ __export(queryDataMappers_exports, {
23
23
  mapEngineMarketPrice: () => mapEngineMarketPrice,
24
24
  mapEngineServerBalanceHealthContributions: () => mapEngineServerBalanceHealthContributions,
25
25
  mapEngineServerIsolatedPositions: () => mapEngineServerIsolatedPositions,
26
+ mapEngineServerNlpLockedBalances: () => mapEngineServerNlpLockedBalances,
27
+ mapEngineServerNlpPoolInfo: () => mapEngineServerNlpPoolInfo,
26
28
  mapEngineServerOrder: () => mapEngineServerOrder,
27
29
  mapEngineServerPerpProduct: () => mapEngineServerPerpProduct,
28
30
  mapEngineServerSpotProduct: () => mapEngineServerSpotProduct,
@@ -32,73 +34,62 @@ __export(queryDataMappers_exports, {
32
34
  mapSubaccountSummary: () => mapSubaccountSummary
33
35
  });
34
36
  module.exports = __toCommonJS(queryDataMappers_exports);
35
- var import_contracts = require("@nadohq/contracts");
36
- var import_utils = require("@nadohq/utils");
37
+ var import_shared = require("@nadohq/shared");
37
38
  var import_productEngineTypeMappers = require("./productEngineTypeMappers.cjs");
38
39
  function mapEngineServerTickLiquidity(tick) {
39
40
  return {
40
- price: (0, import_utils.removeDecimals)(tick[0]),
41
- liquidity: (0, import_utils.toBigDecimal)(tick[1])
41
+ price: (0, import_shared.removeDecimals)(tick[0]),
42
+ liquidity: (0, import_shared.toBigDecimal)(tick[1])
42
43
  };
43
44
  }
44
45
  function mapEngineServerOrder(order) {
45
- const subaccount = (0, import_contracts.subaccountFromHex)(order.sender);
46
+ const subaccount = (0, import_shared.subaccountFromHex)(order.sender);
46
47
  return {
47
48
  digest: order.digest,
48
- expiration: (0, import_utils.toBigDecimal)(order.expiration),
49
+ expiration: Number(order.expiration),
49
50
  nonce: order.nonce,
50
- price: (0, import_utils.removeDecimals)(order.price_x18),
51
+ price: (0, import_shared.removeDecimals)(order.price_x18),
51
52
  productId: order.product_id,
52
53
  subaccountOwner: subaccount.subaccountOwner,
53
54
  subaccountName: subaccount.subaccountName,
54
- totalAmount: (0, import_utils.toBigDecimal)(order.amount),
55
- unfilledAmount: (0, import_utils.toBigDecimal)(order.unfilled_amount),
56
- margin: order.margin ? (0, import_utils.toBigDecimal)(order.margin) : null,
57
- // Standardizes from hex
58
- // toFixed is required as toString gives values with `e`
59
- orderParams: {
60
- amount: (0, import_utils.toIntegerString)(order.amount),
61
- expiration: (0, import_utils.toIntegerString)(order.expiration),
62
- nonce: order.nonce,
63
- price: (0, import_utils.toIntegerString)((0, import_utils.removeDecimals)(order.price_x18)),
64
- subaccountOwner: subaccount.subaccountOwner,
65
- subaccountName: subaccount.subaccountName
66
- },
55
+ totalAmount: (0, import_shared.toBigDecimal)(order.amount),
56
+ unfilledAmount: (0, import_shared.toBigDecimal)(order.unfilled_amount),
67
57
  placementTime: order.placed_at,
68
- orderType: order.order_type
58
+ appendix: (0, import_shared.unpackOrderAppendix)(order.appendix)
69
59
  };
70
60
  }
71
61
  function mapEngineServerSpotProduct(product) {
72
62
  return {
73
- type: import_contracts.ProductEngineType.SPOT,
63
+ type: import_shared.ProductEngineType.SPOT,
74
64
  productId: product.product_id,
75
- minSize: (0, import_utils.toBigDecimal)(product.book_info.min_size),
76
- priceIncrement: (0, import_utils.removeDecimals)(product.book_info.price_increment_x18),
77
- sizeIncrement: (0, import_utils.toBigDecimal)(product.book_info.size_increment),
65
+ minSize: (0, import_shared.toBigDecimal)(product.book_info.min_size),
66
+ priceIncrement: (0, import_shared.removeDecimals)(product.book_info.price_increment_x18),
67
+ sizeIncrement: (0, import_shared.toBigDecimal)(product.book_info.size_increment),
78
68
  product: {
79
69
  productId: product.product_id,
80
- type: import_contracts.ProductEngineType.SPOT,
81
- totalBorrowed: (0, import_contracts.calcTotalBorrowed)(
70
+ type: import_shared.ProductEngineType.SPOT,
71
+ totalBorrowed: (0, import_shared.calcTotalBorrowed)(
82
72
  product.state.total_borrows_normalized,
83
73
  product.state.cumulative_borrows_multiplier_x18
84
74
  ),
85
- totalDeposited: (0, import_contracts.calcTotalDeposited)(
75
+ totalDeposited: (0, import_shared.calcTotalDeposited)(
86
76
  product.state.total_deposits_normalized,
87
77
  product.state.cumulative_deposits_multiplier_x18
88
78
  ),
89
- oraclePrice: (0, import_utils.removeDecimals)(product.oracle_price_x18),
90
- interestFloor: (0, import_utils.removeDecimals)(product.config.interest_floor_x18),
91
- interestInflectionUtil: (0, import_utils.removeDecimals)(
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)(
92
82
  product.config.interest_inflection_util_x18
93
83
  ),
94
- interestLargeCap: (0, import_utils.removeDecimals)(product.config.interest_large_cap_x18),
95
- interestSmallCap: (0, import_utils.removeDecimals)(product.config.interest_small_cap_x18),
96
- longWeightInitial: (0, import_utils.removeDecimals)(product.risk.long_weight_initial_x18),
97
- longWeightMaintenance: (0, import_utils.removeDecimals)(
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)(
98
89
  product.risk.long_weight_maintenance_x18
99
90
  ),
100
- shortWeightInitial: (0, import_utils.removeDecimals)(product.risk.short_weight_initial_x18),
101
- shortWeightMaintenance: (0, import_utils.removeDecimals)(
91
+ shortWeightInitial: (0, import_shared.removeDecimals)(product.risk.short_weight_initial_x18),
92
+ shortWeightMaintenance: (0, import_shared.removeDecimals)(
102
93
  product.risk.short_weight_maintenance_x18
103
94
  ),
104
95
  tokenAddr: product.config.token
@@ -107,28 +98,28 @@ function mapEngineServerSpotProduct(product) {
107
98
  }
108
99
  function mapEngineServerPerpProduct(product) {
109
100
  return {
110
- type: import_contracts.ProductEngineType.PERP,
101
+ type: import_shared.ProductEngineType.PERP,
111
102
  productId: product.product_id,
112
- minSize: (0, import_utils.toBigDecimal)(product.book_info.min_size),
113
- priceIncrement: (0, import_utils.removeDecimals)(product.book_info.price_increment_x18),
114
- sizeIncrement: (0, import_utils.toBigDecimal)(product.book_info.size_increment),
103
+ minSize: (0, import_shared.toBigDecimal)(product.book_info.min_size),
104
+ priceIncrement: (0, import_shared.removeDecimals)(product.book_info.price_increment_x18),
105
+ sizeIncrement: (0, import_shared.toBigDecimal)(product.book_info.size_increment),
115
106
  product: {
116
107
  productId: product.product_id,
117
- type: import_contracts.ProductEngineType.PERP,
118
- oraclePrice: (0, import_utils.removeDecimals)(product.oracle_price_x18),
119
- longWeightInitial: (0, import_utils.removeDecimals)(product.risk.long_weight_initial_x18),
120
- longWeightMaintenance: (0, import_utils.removeDecimals)(
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)(
121
112
  product.risk.long_weight_maintenance_x18
122
113
  ),
123
- shortWeightInitial: (0, import_utils.removeDecimals)(product.risk.short_weight_initial_x18),
124
- shortWeightMaintenance: (0, import_utils.removeDecimals)(
114
+ shortWeightInitial: (0, import_shared.removeDecimals)(product.risk.short_weight_initial_x18),
115
+ shortWeightMaintenance: (0, import_shared.removeDecimals)(
125
116
  product.risk.short_weight_maintenance_x18
126
117
  ),
127
- openInterest: (0, import_utils.toBigDecimal)(product.state.open_interest),
128
- cumulativeFundingLong: (0, import_utils.removeDecimals)(
118
+ openInterest: (0, import_shared.toBigDecimal)(product.state.open_interest),
119
+ cumulativeFundingLong: (0, import_shared.removeDecimals)(
129
120
  product.state.cumulative_funding_long_x18
130
121
  ),
131
- cumulativeFundingShort: (0, import_utils.removeDecimals)(
122
+ cumulativeFundingShort: (0, import_shared.removeDecimals)(
132
123
  product.state.cumulative_funding_short_x18
133
124
  )
134
125
  }
@@ -136,9 +127,9 @@ function mapEngineServerPerpProduct(product) {
136
127
  }
137
128
  function mapEngineServerBalanceHealthContributions(healthContributionsForBalance) {
138
129
  return {
139
- initial: (0, import_utils.toBigDecimal)(healthContributionsForBalance[0]),
140
- maintenance: (0, import_utils.toBigDecimal)(healthContributionsForBalance[1]),
141
- unweighted: (0, import_utils.toBigDecimal)(healthContributionsForBalance[2])
130
+ initial: (0, import_shared.toBigDecimal)(healthContributionsForBalance[0]),
131
+ maintenance: (0, import_shared.toBigDecimal)(healthContributionsForBalance[1]),
132
+ unweighted: (0, import_shared.toBigDecimal)(healthContributionsForBalance[2])
142
133
  };
143
134
  }
144
135
  function mapSubaccountSummary(baseResponse) {
@@ -151,7 +142,7 @@ function mapSubaccountSummary(baseResponse) {
151
142
  throw Error(`Could not find product ${spotBalance.product_id}`);
152
143
  }
153
144
  balances.push({
154
- amount: (0, import_utils.toBigDecimal)(spotBalance.balance.amount),
145
+ amount: (0, import_shared.toBigDecimal)(spotBalance.balance.amount),
155
146
  healthContributions: mapEngineServerBalanceHealthContributions(
156
147
  baseResponse.health_contributions[spotBalance.product_id]
157
148
  ),
@@ -166,8 +157,8 @@ function mapSubaccountSummary(baseResponse) {
166
157
  throw Error(`Could not find product ${perpBalance.product_id}`);
167
158
  }
168
159
  balances.push({
169
- amount: (0, import_utils.toBigDecimal)(perpBalance.balance.amount),
170
- vQuoteBalance: (0, import_utils.toBigDecimal)(perpBalance.balance.v_quote_balance),
160
+ amount: (0, import_shared.toBigDecimal)(perpBalance.balance.amount),
161
+ vQuoteBalance: (0, import_shared.toBigDecimal)(perpBalance.balance.v_quote_balance),
171
162
  healthContributions: mapEngineServerBalanceHealthContributions(
172
163
  baseResponse.health_contributions[perpBalance.product_id]
173
164
  ),
@@ -179,19 +170,19 @@ function mapSubaccountSummary(baseResponse) {
179
170
  exists: baseResponse.exists,
180
171
  health: {
181
172
  initial: {
182
- health: (0, import_utils.toBigDecimal)(baseResponse.healths[0].health),
183
- assets: (0, import_utils.toBigDecimal)(baseResponse.healths[0].assets),
184
- liabilities: (0, import_utils.toBigDecimal)(baseResponse.healths[0].liabilities)
173
+ health: (0, import_shared.toBigDecimal)(baseResponse.healths[0].health),
174
+ assets: (0, import_shared.toBigDecimal)(baseResponse.healths[0].assets),
175
+ liabilities: (0, import_shared.toBigDecimal)(baseResponse.healths[0].liabilities)
185
176
  },
186
177
  maintenance: {
187
- health: (0, import_utils.toBigDecimal)(baseResponse.healths[1].health),
188
- assets: (0, import_utils.toBigDecimal)(baseResponse.healths[1].assets),
189
- liabilities: (0, import_utils.toBigDecimal)(baseResponse.healths[1].liabilities)
178
+ health: (0, import_shared.toBigDecimal)(baseResponse.healths[1].health),
179
+ assets: (0, import_shared.toBigDecimal)(baseResponse.healths[1].assets),
180
+ liabilities: (0, import_shared.toBigDecimal)(baseResponse.healths[1].liabilities)
190
181
  },
191
182
  unweighted: {
192
- health: (0, import_utils.toBigDecimal)(baseResponse.healths[2].health),
193
- assets: (0, import_utils.toBigDecimal)(baseResponse.healths[2].assets),
194
- liabilities: (0, import_utils.toBigDecimal)(baseResponse.healths[2].liabilities)
183
+ health: (0, import_shared.toBigDecimal)(baseResponse.healths[2].health),
184
+ assets: (0, import_shared.toBigDecimal)(baseResponse.healths[2].assets),
185
+ liabilities: (0, import_shared.toBigDecimal)(baseResponse.healths[2].liabilities)
195
186
  }
196
187
  }
197
188
  };
@@ -201,29 +192,29 @@ function mapEngineServerIsolatedPositions(baseResponse) {
201
192
  const perpBalance = position.base_balance;
202
193
  const quoteBalance = position.quote_balance;
203
194
  return {
204
- subaccount: (0, import_contracts.subaccountFromHex)(position.subaccount),
195
+ subaccount: (0, import_shared.subaccountFromHex)(position.subaccount),
205
196
  healths: {
206
- initial: (0, import_utils.toBigDecimal)(position.healths[0].health),
207
- maintenance: (0, import_utils.toBigDecimal)(position.healths[1].health),
208
- unweighted: (0, import_utils.toBigDecimal)(position.healths[2].health)
197
+ initial: (0, import_shared.toBigDecimal)(position.healths[0].health),
198
+ maintenance: (0, import_shared.toBigDecimal)(position.healths[1].health),
199
+ unweighted: (0, import_shared.toBigDecimal)(position.healths[2].health)
209
200
  },
210
201
  baseBalance: {
211
- amount: (0, import_utils.toBigDecimal)(perpBalance.balance.amount),
212
- vQuoteBalance: (0, import_utils.toBigDecimal)(perpBalance.balance.v_quote_balance),
202
+ amount: (0, import_shared.toBigDecimal)(perpBalance.balance.amount),
203
+ vQuoteBalance: (0, import_shared.toBigDecimal)(perpBalance.balance.v_quote_balance),
213
204
  // Health contributions === healths for an isolated position
214
205
  healthContributions: {
215
- initial: (0, import_utils.toBigDecimal)(position.base_healths[0]),
216
- maintenance: (0, import_utils.toBigDecimal)(position.base_healths[1]),
217
- unweighted: (0, import_utils.toBigDecimal)(position.base_healths[2])
206
+ initial: (0, import_shared.toBigDecimal)(position.base_healths[0]),
207
+ maintenance: (0, import_shared.toBigDecimal)(position.base_healths[1]),
208
+ unweighted: (0, import_shared.toBigDecimal)(position.base_healths[2])
218
209
  },
219
210
  ...mapEngineServerPerpProduct(position.base_product).product
220
211
  },
221
212
  quoteBalance: {
222
- amount: (0, import_utils.toBigDecimal)(quoteBalance.balance.amount),
213
+ amount: (0, import_shared.toBigDecimal)(quoteBalance.balance.amount),
223
214
  healthContributions: {
224
- initial: (0, import_utils.toBigDecimal)(position.quote_healths[0]),
225
- maintenance: (0, import_utils.toBigDecimal)(position.quote_healths[1]),
226
- unweighted: (0, import_utils.toBigDecimal)(position.quote_healths[2])
215
+ initial: (0, import_shared.toBigDecimal)(position.quote_healths[0]),
216
+ maintenance: (0, import_shared.toBigDecimal)(position.quote_healths[1]),
217
+ unweighted: (0, import_shared.toBigDecimal)(position.quote_healths[2])
227
218
  },
228
219
  ...mapEngineServerSpotProduct(position.quote_product).product
229
220
  }
@@ -231,7 +222,7 @@ function mapEngineServerIsolatedPositions(baseResponse) {
231
222
  });
232
223
  }
233
224
  function mapEngineServerSymbols(baseResponse) {
234
- const symbols = (0, import_utils.mapValues)(
225
+ const symbols = (0, import_shared.mapValues)(
235
226
  baseResponse.symbols,
236
227
  mapEngineServerSymbol
237
228
  );
@@ -244,33 +235,65 @@ function mapEngineServerSymbol(engineServerSymbol) {
244
235
  type: (0, import_productEngineTypeMappers.mapEngineServerProductType)(engineServerSymbol.type),
245
236
  productId: engineServerSymbol.product_id,
246
237
  symbol: engineServerSymbol.symbol,
247
- priceIncrement: (0, import_utils.removeDecimals)(engineServerSymbol.price_increment_x18),
248
- sizeIncrement: (0, import_utils.toBigDecimal)(engineServerSymbol.size_increment),
249
- minSize: (0, import_utils.toBigDecimal)(engineServerSymbol.min_size),
250
- minDepth: (0, import_utils.removeDecimals)(engineServerSymbol.min_depth_x18),
251
- maxSpreadRate: (0, import_utils.removeDecimals)(engineServerSymbol.max_spread_rate_x18),
252
- makerFeeRate: (0, import_utils.removeDecimals)(engineServerSymbol.maker_fee_rate_x18),
253
- takerFeeRate: (0, import_utils.removeDecimals)(engineServerSymbol.taker_fee_rate_x18),
254
- longWeightInitial: (0, import_utils.removeDecimals)(
238
+ priceIncrement: (0, import_shared.removeDecimals)(engineServerSymbol.price_increment_x18),
239
+ sizeIncrement: (0, import_shared.toBigDecimal)(engineServerSymbol.size_increment),
240
+ minSize: (0, import_shared.toBigDecimal)(engineServerSymbol.min_size),
241
+ minDepth: (0, import_shared.removeDecimals)(engineServerSymbol.min_depth_x18),
242
+ maxSpreadRate: (0, import_shared.removeDecimals)(engineServerSymbol.max_spread_rate_x18),
243
+ makerFeeRate: (0, import_shared.removeDecimals)(engineServerSymbol.maker_fee_rate_x18),
244
+ takerFeeRate: (0, import_shared.removeDecimals)(engineServerSymbol.taker_fee_rate_x18),
245
+ longWeightInitial: (0, import_shared.removeDecimals)(
255
246
  engineServerSymbol.long_weight_initial_x18
256
247
  ),
257
- longWeightMaintenance: (0, import_utils.removeDecimals)(
248
+ longWeightMaintenance: (0, import_shared.removeDecimals)(
258
249
  engineServerSymbol.long_weight_maintenance_x18
259
250
  )
260
251
  };
261
252
  }
262
253
  function mapEngineMarketPrice(baseResponse) {
263
254
  return {
264
- ask: (0, import_utils.removeDecimals)(baseResponse.ask_x18),
265
- bid: (0, import_utils.removeDecimals)(baseResponse.bid_x18),
255
+ ask: (0, import_shared.removeDecimals)(baseResponse.ask_x18),
256
+ bid: (0, import_shared.removeDecimals)(baseResponse.bid_x18),
266
257
  productId: baseResponse.product_id
267
258
  };
268
259
  }
260
+ function mapEngineServerNlpLockedBalances(baseResponse) {
261
+ const lockedBalances = baseResponse.locked_balances.map((lockedBalance) => ({
262
+ productId: lockedBalance.balance.product_id,
263
+ balance: (0, import_shared.toBigDecimal)(lockedBalance.balance.balance.amount),
264
+ unlockedAt: lockedBalance.unlocked_at
265
+ }));
266
+ return {
267
+ lockedBalances,
268
+ balanceLocked: {
269
+ productId: baseResponse.balance_locked.product_id,
270
+ balance: (0, import_shared.toBigDecimal)(baseResponse.balance_locked.balance.amount)
271
+ },
272
+ balanceUnlocked: {
273
+ productId: baseResponse.balance_unlocked.product_id,
274
+ balance: (0, import_shared.toBigDecimal)(baseResponse.balance_unlocked.balance.amount)
275
+ }
276
+ };
277
+ }
278
+ function mapEngineServerNlpPoolInfo(baseResponse) {
279
+ return {
280
+ nlpPools: baseResponse.nlp_pools.map((pool) => ({
281
+ poolId: pool.pool_id,
282
+ subaccountHex: pool.subaccount,
283
+ ownerAddress: pool.owner,
284
+ balanceWeight: (0, import_shared.removeDecimals)(pool.balance_weight_x18),
285
+ subaccountInfo: mapSubaccountSummary(pool.subaccount_info),
286
+ openOrders: pool.open_orders.map(mapEngineServerOrder)
287
+ }))
288
+ };
289
+ }
269
290
  // Annotate the CommonJS export names for ESM import in node:
270
291
  0 && (module.exports = {
271
292
  mapEngineMarketPrice,
272
293
  mapEngineServerBalanceHealthContributions,
273
294
  mapEngineServerIsolatedPositions,
295
+ mapEngineServerNlpLockedBalances,
296
+ mapEngineServerNlpPoolInfo,
274
297
  mapEngineServerOrder,
275
298
  mapEngineServerPerpProduct,
276
299
  mapEngineServerSpotProduct,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/queryDataMappers.ts"],"sourcesContent":["import {\n BalanceHealthContributions,\n calcTotalBorrowed,\n calcTotalDeposited,\n OrderExpirationType,\n PerpMarket,\n ProductEngineType,\n SpotMarket,\n subaccountFromHex,\n} from '@nadohq/contracts';\nimport {\n mapValues,\n removeDecimals,\n toBigDecimal,\n toIntegerString,\n} from '@nadohq/utils';\nimport {\n EngineMarketPrice,\n EngineOrder,\n EnginePriceTickLiquidity,\n EngineServerIsolatedPositionsResponse,\n EngineServerMarketPrice,\n EngineServerOrderResponse,\n EngineServerPerpProduct,\n EngineServerPriceTickLiquidity,\n EngineServerSpotProduct,\n EngineServerSubaccountInfoResponse,\n EngineServerSymbol,\n EngineServerSymbolsResponse,\n EngineSymbol,\n EngineSymbolsResponse,\n GetEngineIsolatedPositionsResponse,\n GetEngineSubaccountSummaryResponse,\n} from '../types';\nimport { mapEngineServerProductType } from './productEngineTypeMappers';\n\nexport function mapEngineServerTickLiquidity(\n tick: EngineServerPriceTickLiquidity,\n): EnginePriceTickLiquidity {\n return {\n price: removeDecimals(tick[0]),\n liquidity: toBigDecimal(tick[1]),\n };\n}\n\nexport function mapEngineServerOrder(\n order: EngineServerOrderResponse,\n): EngineOrder {\n const subaccount = subaccountFromHex(order.sender);\n return {\n digest: order.digest,\n expiration: toBigDecimal(order.expiration),\n nonce: order.nonce,\n price: removeDecimals(order.price_x18),\n productId: order.product_id,\n subaccountOwner: subaccount.subaccountOwner,\n subaccountName: subaccount.subaccountName,\n totalAmount: toBigDecimal(order.amount),\n unfilledAmount: toBigDecimal(order.unfilled_amount),\n margin: order.margin ? toBigDecimal(order.margin) : null,\n // Standardizes from hex\n // toFixed is required as toString gives values with `e`\n orderParams: {\n amount: toIntegerString(order.amount),\n expiration: toIntegerString(order.expiration),\n nonce: order.nonce,\n price: toIntegerString(removeDecimals(order.price_x18)),\n subaccountOwner: subaccount.subaccountOwner,\n subaccountName: subaccount.subaccountName,\n },\n placementTime: order.placed_at,\n orderType: order.order_type as OrderExpirationType,\n };\n}\n\nexport function mapEngineServerSpotProduct(\n product: EngineServerSpotProduct,\n): SpotMarket {\n return {\n type: ProductEngineType.SPOT,\n productId: product.product_id,\n minSize: toBigDecimal(product.book_info.min_size),\n priceIncrement: removeDecimals(product.book_info.price_increment_x18),\n sizeIncrement: toBigDecimal(product.book_info.size_increment),\n product: {\n productId: product.product_id,\n type: ProductEngineType.SPOT,\n totalBorrowed: calcTotalBorrowed(\n product.state.total_borrows_normalized,\n product.state.cumulative_borrows_multiplier_x18,\n ),\n totalDeposited: calcTotalDeposited(\n product.state.total_deposits_normalized,\n product.state.cumulative_deposits_multiplier_x18,\n ),\n oraclePrice: removeDecimals(product.oracle_price_x18),\n interestFloor: removeDecimals(product.config.interest_floor_x18),\n interestInflectionUtil: removeDecimals(\n product.config.interest_inflection_util_x18,\n ),\n interestLargeCap: removeDecimals(product.config.interest_large_cap_x18),\n interestSmallCap: removeDecimals(product.config.interest_small_cap_x18),\n longWeightInitial: removeDecimals(product.risk.long_weight_initial_x18),\n longWeightMaintenance: removeDecimals(\n product.risk.long_weight_maintenance_x18,\n ),\n shortWeightInitial: removeDecimals(product.risk.short_weight_initial_x18),\n shortWeightMaintenance: removeDecimals(\n product.risk.short_weight_maintenance_x18,\n ),\n tokenAddr: product.config.token,\n },\n };\n}\n\nexport function mapEngineServerPerpProduct(\n product: EngineServerPerpProduct,\n): PerpMarket {\n return {\n type: ProductEngineType.PERP,\n productId: product.product_id,\n minSize: toBigDecimal(product.book_info.min_size),\n priceIncrement: removeDecimals(product.book_info.price_increment_x18),\n sizeIncrement: toBigDecimal(product.book_info.size_increment),\n product: {\n productId: product.product_id,\n type: ProductEngineType.PERP,\n oraclePrice: removeDecimals(product.oracle_price_x18),\n longWeightInitial: removeDecimals(product.risk.long_weight_initial_x18),\n longWeightMaintenance: removeDecimals(\n product.risk.long_weight_maintenance_x18,\n ),\n shortWeightInitial: removeDecimals(product.risk.short_weight_initial_x18),\n shortWeightMaintenance: removeDecimals(\n product.risk.short_weight_maintenance_x18,\n ),\n openInterest: toBigDecimal(product.state.open_interest),\n cumulativeFundingLong: removeDecimals(\n product.state.cumulative_funding_long_x18,\n ),\n cumulativeFundingShort: removeDecimals(\n product.state.cumulative_funding_short_x18,\n ),\n },\n };\n}\n\nexport function mapEngineServerBalanceHealthContributions(\n healthContributionsForBalance: string[],\n): BalanceHealthContributions {\n return {\n initial: toBigDecimal(healthContributionsForBalance[0]),\n maintenance: toBigDecimal(healthContributionsForBalance[1]),\n unweighted: toBigDecimal(healthContributionsForBalance[2]),\n };\n}\n\nexport function mapSubaccountSummary(\n baseResponse: EngineServerSubaccountInfoResponse,\n): GetEngineSubaccountSummaryResponse {\n const balances: GetEngineSubaccountSummaryResponse['balances'] = [];\n\n baseResponse.spot_balances.forEach((spotBalance) => {\n const product = baseResponse.spot_products.find(\n (product) => product.product_id === spotBalance.product_id,\n );\n if (!product) {\n throw Error(`Could not find product ${spotBalance.product_id}`);\n }\n\n balances.push({\n amount: toBigDecimal(spotBalance.balance.amount),\n healthContributions: mapEngineServerBalanceHealthContributions(\n baseResponse.health_contributions[spotBalance.product_id],\n ),\n ...mapEngineServerSpotProduct(product).product,\n });\n });\n\n baseResponse.perp_balances.forEach((perpBalance) => {\n const product = baseResponse.perp_products.find(\n (product) => product.product_id === perpBalance.product_id,\n );\n if (!product) {\n throw Error(`Could not find product ${perpBalance.product_id}`);\n }\n\n balances.push({\n amount: toBigDecimal(perpBalance.balance.amount),\n vQuoteBalance: toBigDecimal(perpBalance.balance.v_quote_balance),\n healthContributions: mapEngineServerBalanceHealthContributions(\n baseResponse.health_contributions[perpBalance.product_id],\n ),\n ...mapEngineServerPerpProduct(product).product,\n });\n });\n\n return {\n balances: balances,\n exists: baseResponse.exists,\n health: {\n initial: {\n health: toBigDecimal(baseResponse.healths[0].health),\n assets: toBigDecimal(baseResponse.healths[0].assets),\n liabilities: toBigDecimal(baseResponse.healths[0].liabilities),\n },\n maintenance: {\n health: toBigDecimal(baseResponse.healths[1].health),\n assets: toBigDecimal(baseResponse.healths[1].assets),\n liabilities: toBigDecimal(baseResponse.healths[1].liabilities),\n },\n unweighted: {\n health: toBigDecimal(baseResponse.healths[2].health),\n assets: toBigDecimal(baseResponse.healths[2].assets),\n liabilities: toBigDecimal(baseResponse.healths[2].liabilities),\n },\n },\n };\n}\n\nexport function mapEngineServerIsolatedPositions(\n baseResponse: EngineServerIsolatedPositionsResponse,\n): GetEngineIsolatedPositionsResponse {\n return baseResponse.isolated_positions.map((position) => {\n const perpBalance = position.base_balance;\n const quoteBalance = position.quote_balance;\n\n return {\n subaccount: subaccountFromHex(position.subaccount),\n healths: {\n initial: toBigDecimal(position.healths[0].health),\n maintenance: toBigDecimal(position.healths[1].health),\n unweighted: toBigDecimal(position.healths[2].health),\n },\n baseBalance: {\n amount: toBigDecimal(perpBalance.balance.amount),\n vQuoteBalance: toBigDecimal(perpBalance.balance.v_quote_balance),\n // Health contributions === healths for an isolated position\n healthContributions: {\n initial: toBigDecimal(position.base_healths[0]),\n maintenance: toBigDecimal(position.base_healths[1]),\n unweighted: toBigDecimal(position.base_healths[2]),\n },\n ...mapEngineServerPerpProduct(position.base_product).product,\n },\n quoteBalance: {\n amount: toBigDecimal(quoteBalance.balance.amount),\n healthContributions: {\n initial: toBigDecimal(position.quote_healths[0]),\n maintenance: toBigDecimal(position.quote_healths[1]),\n unweighted: toBigDecimal(position.quote_healths[2]),\n },\n ...mapEngineServerSpotProduct(position.quote_product).product,\n },\n };\n });\n}\n\nexport function mapEngineServerSymbols(\n baseResponse: EngineServerSymbolsResponse,\n): EngineSymbolsResponse {\n const symbols: Record<string, EngineSymbol> = mapValues(\n baseResponse.symbols,\n mapEngineServerSymbol,\n );\n\n return {\n symbols,\n };\n}\n\nexport function mapEngineServerSymbol(\n engineServerSymbol: EngineServerSymbol,\n): EngineSymbol {\n return {\n type: mapEngineServerProductType(engineServerSymbol.type),\n productId: engineServerSymbol.product_id,\n symbol: engineServerSymbol.symbol,\n priceIncrement: removeDecimals(engineServerSymbol.price_increment_x18),\n sizeIncrement: toBigDecimal(engineServerSymbol.size_increment),\n minSize: toBigDecimal(engineServerSymbol.min_size),\n minDepth: removeDecimals(engineServerSymbol.min_depth_x18),\n maxSpreadRate: removeDecimals(engineServerSymbol.max_spread_rate_x18),\n makerFeeRate: removeDecimals(engineServerSymbol.maker_fee_rate_x18),\n takerFeeRate: removeDecimals(engineServerSymbol.taker_fee_rate_x18),\n longWeightInitial: removeDecimals(\n engineServerSymbol.long_weight_initial_x18,\n ),\n longWeightMaintenance: removeDecimals(\n engineServerSymbol.long_weight_maintenance_x18,\n ),\n };\n}\n\nexport function mapEngineMarketPrice(\n baseResponse: EngineServerMarketPrice,\n): EngineMarketPrice {\n return {\n ask: removeDecimals(baseResponse.ask_x18),\n bid: removeDecimals(baseResponse.bid_x18),\n productId: baseResponse.product_id,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBASO;AACP,mBAKO;AAmBP,sCAA2C;AAEpC,SAAS,6BACd,MAC0B;AAC1B,SAAO;AAAA,IACL,WAAO,6BAAe,KAAK,CAAC,CAAC;AAAA,IAC7B,eAAW,2BAAa,KAAK,CAAC,CAAC;AAAA,EACjC;AACF;AAEO,SAAS,qBACd,OACa;AACb,QAAM,iBAAa,oCAAkB,MAAM,MAAM;AACjD,SAAO;AAAA,IACL,QAAQ,MAAM;AAAA,IACd,gBAAY,2BAAa,MAAM,UAAU;AAAA,IACzC,OAAO,MAAM;AAAA,IACb,WAAO,6BAAe,MAAM,SAAS;AAAA,IACrC,WAAW,MAAM;AAAA,IAC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AC;AAAA,UACnD,gBAAY,2BAAa,SAAS,cAAc,CAAC,CAAC;AAAA,QACpD;AAAA,QACA,GAAG,2BAA2B,SAAS,aAAa,EAAE;AAAA,MACxD;AAAA,IACF;AAAA,EACF,CAAC;AACH;AAEO,SAAS,uBACd,cACuB;AACvB,QAAM,cAAwC;AAAA,IAC5C,aAAa;AAAA,IACb;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,EACF;AACF;AAEO,SAAS,sBACd,oBACc;AACd,SAAO;AAAA,IACL,UAAM,4DAA2B,mBAAmB,IAAI;AAAA,IACxD,WAAW,mBAAmB;AAAA,IAC9B,QAAQ,mBAAmB;AAAA,IAC3B,oBAAgB,6BAAe,mBAAmB,mBAAmB;AAAA,IACrE,mBAAe,2BAAa,mBAAmB,cAAc;AAAA,IAC7D,aAAS,2BAAa,mBAAmB,QAAQ;AAAA,IACjD,cAAU,6BAAe,mBAAmB,aAAa;AAAA,IACzD,mBAAe,6BAAe,mBAAmB,mBAAmB;AAAA,IACpE,kBAAc,6BAAe,mBAAmB,kBAAkB;AAAA,IAClE,kBAAc,6BAAe,mBAAmB,kBAAkB;AAAA,IAClE,uBAAmB;AAAA,MACjB,mBAAmB;AAAA,IACrB;AAAA,IACA,2BAAuB;AAAA,MACrB,mBAAmB;AAAA,IACrB;AAAA,EACF;AACF;AAEO,SAAS,qBACd,cACmB;AACnB,SAAO;AAAA,IACL,SAAK,6BAAe,aAAa,OAAO;AAAA,IACxC,SAAK,6BAAe,aAAa,OAAO;AAAA,IACxC,WAAW,aAAa;AAAA,EAC1B;AACF;","names":["product"]}
1
+ {"version":3,"sources":["../../src/utils/queryDataMappers.ts"],"sourcesContent":["import {\n BalanceHealthContributions,\n calcTotalBorrowed,\n calcTotalDeposited,\n mapValues,\n PerpMarket,\n ProductEngineType,\n removeDecimals,\n SpotMarket,\n subaccountFromHex,\n toBigDecimal,\n unpackOrderAppendix,\n} from '@nadohq/shared';\nimport {\n EngineMarketPrice,\n EngineNlpLockedBalance,\n EngineOrder,\n EnginePriceTickLiquidity,\n EngineServerIsolatedPositionsResponse,\n EngineServerMarketPrice,\n EngineServerNlpLockedBalancesResponse,\n EngineServerNlpPoolInfoResponse,\n EngineServerOrderResponse,\n EngineServerPerpProduct,\n EngineServerPriceTickLiquidity,\n EngineServerSpotProduct,\n EngineServerSubaccountInfoResponse,\n EngineServerSymbol,\n EngineServerSymbolsResponse,\n EngineSymbol,\n EngineSymbolsResponse,\n GetEngineIsolatedPositionsResponse,\n GetEngineNlpLockedBalancesResponse,\n GetEngineNlpPoolInfoResponse,\n GetEngineSubaccountSummaryResponse,\n} from '../types';\nimport { mapEngineServerProductType } from './productEngineTypeMappers';\n\nexport function mapEngineServerTickLiquidity(\n tick: EngineServerPriceTickLiquidity,\n): EnginePriceTickLiquidity {\n return {\n price: removeDecimals(tick[0]),\n liquidity: toBigDecimal(tick[1]),\n };\n}\n\nexport function mapEngineServerOrder(\n order: EngineServerOrderResponse,\n): EngineOrder {\n const subaccount = subaccountFromHex(order.sender);\n return {\n digest: order.digest,\n expiration: Number(order.expiration),\n nonce: order.nonce,\n price: removeDecimals(order.price_x18),\n productId: order.product_id,\n subaccountOwner: subaccount.subaccountOwner,\n subaccountName: subaccount.subaccountName,\n totalAmount: toBigDecimal(order.amount),\n unfilledAmount: toBigDecimal(order.unfilled_amount),\n placementTime: order.placed_at,\n appendix: unpackOrderAppendix(order.appendix),\n };\n}\n\nexport function mapEngineServerSpotProduct(\n product: EngineServerSpotProduct,\n): SpotMarket {\n return {\n type: ProductEngineType.SPOT,\n productId: product.product_id,\n minSize: toBigDecimal(product.book_info.min_size),\n priceIncrement: removeDecimals(product.book_info.price_increment_x18),\n sizeIncrement: toBigDecimal(product.book_info.size_increment),\n product: {\n productId: product.product_id,\n type: ProductEngineType.SPOT,\n totalBorrowed: calcTotalBorrowed(\n product.state.total_borrows_normalized,\n product.state.cumulative_borrows_multiplier_x18,\n ),\n totalDeposited: calcTotalDeposited(\n product.state.total_deposits_normalized,\n product.state.cumulative_deposits_multiplier_x18,\n ),\n oraclePrice: removeDecimals(product.oracle_price_x18),\n interestFloor: removeDecimals(product.config.interest_floor_x18),\n interestInflectionUtil: removeDecimals(\n product.config.interest_inflection_util_x18,\n ),\n interestLargeCap: removeDecimals(product.config.interest_large_cap_x18),\n interestSmallCap: removeDecimals(product.config.interest_small_cap_x18),\n minDepositRate: removeDecimals(product.config.min_deposit_rate_x18),\n longWeightInitial: removeDecimals(product.risk.long_weight_initial_x18),\n longWeightMaintenance: removeDecimals(\n product.risk.long_weight_maintenance_x18,\n ),\n shortWeightInitial: removeDecimals(product.risk.short_weight_initial_x18),\n shortWeightMaintenance: removeDecimals(\n product.risk.short_weight_maintenance_x18,\n ),\n tokenAddr: product.config.token,\n },\n };\n}\n\nexport function mapEngineServerPerpProduct(\n product: EngineServerPerpProduct,\n): PerpMarket {\n return {\n type: ProductEngineType.PERP,\n productId: product.product_id,\n minSize: toBigDecimal(product.book_info.min_size),\n priceIncrement: removeDecimals(product.book_info.price_increment_x18),\n sizeIncrement: toBigDecimal(product.book_info.size_increment),\n product: {\n productId: product.product_id,\n type: ProductEngineType.PERP,\n oraclePrice: removeDecimals(product.oracle_price_x18),\n longWeightInitial: removeDecimals(product.risk.long_weight_initial_x18),\n longWeightMaintenance: removeDecimals(\n product.risk.long_weight_maintenance_x18,\n ),\n shortWeightInitial: removeDecimals(product.risk.short_weight_initial_x18),\n shortWeightMaintenance: removeDecimals(\n product.risk.short_weight_maintenance_x18,\n ),\n openInterest: toBigDecimal(product.state.open_interest),\n cumulativeFundingLong: removeDecimals(\n product.state.cumulative_funding_long_x18,\n ),\n cumulativeFundingShort: removeDecimals(\n product.state.cumulative_funding_short_x18,\n ),\n },\n };\n}\n\nexport function mapEngineServerBalanceHealthContributions(\n healthContributionsForBalance: string[],\n): BalanceHealthContributions {\n return {\n initial: toBigDecimal(healthContributionsForBalance[0]),\n maintenance: toBigDecimal(healthContributionsForBalance[1]),\n unweighted: toBigDecimal(healthContributionsForBalance[2]),\n };\n}\n\nexport function mapSubaccountSummary(\n baseResponse: EngineServerSubaccountInfoResponse,\n): GetEngineSubaccountSummaryResponse {\n const balances: GetEngineSubaccountSummaryResponse['balances'] = [];\n\n baseResponse.spot_balances.forEach((spotBalance) => {\n const product = baseResponse.spot_products.find(\n (product) => product.product_id === spotBalance.product_id,\n );\n if (!product) {\n throw Error(`Could not find product ${spotBalance.product_id}`);\n }\n\n balances.push({\n amount: toBigDecimal(spotBalance.balance.amount),\n healthContributions: mapEngineServerBalanceHealthContributions(\n baseResponse.health_contributions[spotBalance.product_id],\n ),\n ...mapEngineServerSpotProduct(product).product,\n });\n });\n\n baseResponse.perp_balances.forEach((perpBalance) => {\n const product = baseResponse.perp_products.find(\n (product) => product.product_id === perpBalance.product_id,\n );\n if (!product) {\n throw Error(`Could not find product ${perpBalance.product_id}`);\n }\n\n balances.push({\n amount: toBigDecimal(perpBalance.balance.amount),\n vQuoteBalance: toBigDecimal(perpBalance.balance.v_quote_balance),\n healthContributions: mapEngineServerBalanceHealthContributions(\n baseResponse.health_contributions[perpBalance.product_id],\n ),\n ...mapEngineServerPerpProduct(product).product,\n });\n });\n\n return {\n balances: balances,\n exists: baseResponse.exists,\n health: {\n initial: {\n health: toBigDecimal(baseResponse.healths[0].health),\n assets: toBigDecimal(baseResponse.healths[0].assets),\n liabilities: toBigDecimal(baseResponse.healths[0].liabilities),\n },\n maintenance: {\n health: toBigDecimal(baseResponse.healths[1].health),\n assets: toBigDecimal(baseResponse.healths[1].assets),\n liabilities: toBigDecimal(baseResponse.healths[1].liabilities),\n },\n unweighted: {\n health: toBigDecimal(baseResponse.healths[2].health),\n assets: toBigDecimal(baseResponse.healths[2].assets),\n liabilities: toBigDecimal(baseResponse.healths[2].liabilities),\n },\n },\n };\n}\n\nexport function mapEngineServerIsolatedPositions(\n baseResponse: EngineServerIsolatedPositionsResponse,\n): GetEngineIsolatedPositionsResponse {\n return baseResponse.isolated_positions.map((position) => {\n const perpBalance = position.base_balance;\n const quoteBalance = position.quote_balance;\n\n return {\n subaccount: subaccountFromHex(position.subaccount),\n healths: {\n initial: toBigDecimal(position.healths[0].health),\n maintenance: toBigDecimal(position.healths[1].health),\n unweighted: toBigDecimal(position.healths[2].health),\n },\n baseBalance: {\n amount: toBigDecimal(perpBalance.balance.amount),\n vQuoteBalance: toBigDecimal(perpBalance.balance.v_quote_balance),\n // Health contributions === healths for an isolated position\n healthContributions: {\n initial: toBigDecimal(position.base_healths[0]),\n maintenance: toBigDecimal(position.base_healths[1]),\n unweighted: toBigDecimal(position.base_healths[2]),\n },\n ...mapEngineServerPerpProduct(position.base_product).product,\n },\n quoteBalance: {\n amount: toBigDecimal(quoteBalance.balance.amount),\n healthContributions: {\n initial: toBigDecimal(position.quote_healths[0]),\n maintenance: toBigDecimal(position.quote_healths[1]),\n unweighted: toBigDecimal(position.quote_healths[2]),\n },\n ...mapEngineServerSpotProduct(position.quote_product).product,\n },\n };\n });\n}\n\nexport function mapEngineServerSymbols(\n baseResponse: EngineServerSymbolsResponse,\n): EngineSymbolsResponse {\n const symbols: Record<string, EngineSymbol> = mapValues(\n baseResponse.symbols,\n mapEngineServerSymbol,\n );\n\n return {\n symbols,\n };\n}\n\nexport function mapEngineServerSymbol(\n engineServerSymbol: EngineServerSymbol,\n): EngineSymbol {\n return {\n type: mapEngineServerProductType(engineServerSymbol.type),\n productId: engineServerSymbol.product_id,\n symbol: engineServerSymbol.symbol,\n priceIncrement: removeDecimals(engineServerSymbol.price_increment_x18),\n sizeIncrement: toBigDecimal(engineServerSymbol.size_increment),\n minSize: toBigDecimal(engineServerSymbol.min_size),\n minDepth: removeDecimals(engineServerSymbol.min_depth_x18),\n maxSpreadRate: removeDecimals(engineServerSymbol.max_spread_rate_x18),\n makerFeeRate: removeDecimals(engineServerSymbol.maker_fee_rate_x18),\n takerFeeRate: removeDecimals(engineServerSymbol.taker_fee_rate_x18),\n longWeightInitial: removeDecimals(\n engineServerSymbol.long_weight_initial_x18,\n ),\n longWeightMaintenance: removeDecimals(\n engineServerSymbol.long_weight_maintenance_x18,\n ),\n };\n}\n\nexport function mapEngineMarketPrice(\n baseResponse: EngineServerMarketPrice,\n): EngineMarketPrice {\n return {\n ask: removeDecimals(baseResponse.ask_x18),\n bid: removeDecimals(baseResponse.bid_x18),\n productId: baseResponse.product_id,\n };\n}\n\nexport function mapEngineServerNlpLockedBalances(\n baseResponse: EngineServerNlpLockedBalancesResponse,\n): GetEngineNlpLockedBalancesResponse {\n const lockedBalances: EngineNlpLockedBalance[] =\n baseResponse.locked_balances.map((lockedBalance) => ({\n productId: lockedBalance.balance.product_id,\n balance: toBigDecimal(lockedBalance.balance.balance.amount),\n unlockedAt: lockedBalance.unlocked_at,\n }));\n\n return {\n lockedBalances,\n balanceLocked: {\n productId: baseResponse.balance_locked.product_id,\n balance: toBigDecimal(baseResponse.balance_locked.balance.amount),\n },\n balanceUnlocked: {\n productId: baseResponse.balance_unlocked.product_id,\n balance: toBigDecimal(baseResponse.balance_unlocked.balance.amount),\n },\n };\n}\n\nexport function mapEngineServerNlpPoolInfo(\n baseResponse: EngineServerNlpPoolInfoResponse,\n): GetEngineNlpPoolInfoResponse {\n return {\n nlpPools: baseResponse.nlp_pools.map((pool) => ({\n poolId: pool.pool_id,\n subaccountHex: pool.subaccount,\n ownerAddress: pool.owner,\n balanceWeight: removeDecimals(pool.balance_weight_x18),\n subaccountInfo: mapSubaccountSummary(pool.subaccount_info),\n openOrders: pool.open_orders.map(mapEngineServerOrder),\n })),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAYO;AAwBP,sCAA2C;AAEpC,SAAS,6BACd,MAC0B;AAC1B,SAAO;AAAA,IACL,WAAO,8BAAe,KAAK,CAAC,CAAC;AAAA,IAC7B,eAAW,4BAAa,KAAK,CAAC,CAAC;AAAA,EACj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