@nadohq/engine-client 0.14.0 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (190) hide show
  1. package/dist/EngineBaseClient-DOOXIhnZ.d.ts +75 -0
  2. package/dist/EngineBaseClient-DOOXIhnZ.d.ts.map +1 -0
  3. package/dist/EngineBaseClient-L1ue7jBx.d.cts +75 -0
  4. package/dist/EngineBaseClient-L1ue7jBx.d.cts.map +1 -0
  5. package/dist/EngineBaseClient-Uc1D8ftx.cjs +150 -0
  6. package/dist/EngineBaseClient-Uc1D8ftx.cjs.map +1 -0
  7. package/dist/EngineBaseClient.cjs +3 -167
  8. package/dist/EngineBaseClient.d.cts +2 -75
  9. package/dist/EngineBaseClient.d.ts +2 -75
  10. package/dist/EngineBaseClient.js +112 -131
  11. package/dist/EngineBaseClient.js.map +1 -1
  12. package/dist/EngineClient.cjs +13 -38
  13. package/dist/EngineClient.cjs.map +1 -1
  14. package/dist/EngineClient.d.cts +8 -18
  15. package/dist/EngineClient.d.cts.map +1 -0
  16. package/dist/EngineClient.d.ts +8 -18
  17. package/dist/EngineClient.d.ts.map +1 -0
  18. package/dist/EngineClient.js +9 -11
  19. package/dist/EngineClient.js.map +1 -1
  20. package/dist/EngineExecuteBuilder-VLrEndhv.d.cts +105 -0
  21. package/dist/EngineExecuteBuilder-VLrEndhv.d.cts.map +1 -0
  22. package/dist/EngineExecuteBuilder-t8EQ5Rmp.d.ts +105 -0
  23. package/dist/EngineExecuteBuilder-t8EQ5Rmp.d.ts.map +1 -0
  24. package/dist/EngineExecuteBuilder.cjs +232 -277
  25. package/dist/EngineExecuteBuilder.cjs.map +1 -1
  26. package/dist/EngineExecuteBuilder.d.cts +2 -108
  27. package/dist/EngineExecuteBuilder.d.ts +2 -108
  28. package/dist/EngineExecuteBuilder.js +230 -256
  29. package/dist/EngineExecuteBuilder.js.map +1 -1
  30. package/dist/EngineExecuteClient-0EBoXRd7.d.ts +24 -0
  31. package/dist/EngineExecuteClient-0EBoXRd7.d.ts.map +1 -0
  32. package/dist/EngineExecuteClient-BGlNK5Le.d.cts +24 -0
  33. package/dist/EngineExecuteClient-BGlNK5Le.d.cts.map +1 -0
  34. package/dist/EngineExecuteClient.cjs +57 -110
  35. package/dist/EngineExecuteClient.cjs.map +1 -1
  36. package/dist/EngineExecuteClient.d.cts +2 -28
  37. package/dist/EngineExecuteClient.d.ts +2 -28
  38. package/dist/EngineExecuteClient.js +54 -83
  39. package/dist/EngineExecuteClient.js.map +1 -1
  40. package/dist/EngineQueryClient-C_7p1oRx.d.cts +147 -0
  41. package/dist/EngineQueryClient-C_7p1oRx.d.cts.map +1 -0
  42. package/dist/EngineQueryClient-DQwCRaYl.d.ts +147 -0
  43. package/dist/EngineQueryClient-DQwCRaYl.d.ts.map +1 -0
  44. package/dist/EngineQueryClient.cjs +354 -447
  45. package/dist/EngineQueryClient.cjs.map +1 -1
  46. package/dist/EngineQueryClient.d.cts +2 -149
  47. package/dist/EngineQueryClient.d.ts +2 -149
  48. package/dist/EngineQueryClient.js +351 -440
  49. package/dist/EngineQueryClient.js.map +1 -1
  50. package/dist/EngineServerFailureError-CDabRrF4.d.ts +11 -0
  51. package/dist/EngineServerFailureError-CDabRrF4.d.ts.map +1 -0
  52. package/dist/EngineServerFailureError-DpPY0--L.d.cts +11 -0
  53. package/dist/EngineServerFailureError-DpPY0--L.d.cts.map +1 -0
  54. package/dist/EngineWebClient-CEwqgd4t.d.ts +35 -0
  55. package/dist/EngineWebClient-CEwqgd4t.d.ts.map +1 -0
  56. package/dist/EngineWebClient-DajZqKAQ.d.cts +35 -0
  57. package/dist/EngineWebClient-DajZqKAQ.d.cts.map +1 -0
  58. package/dist/EngineWebClient.cjs +49 -86
  59. package/dist/EngineWebClient.cjs.map +1 -1
  60. package/dist/EngineWebClient.d.cts +2 -39
  61. package/dist/EngineWebClient.d.ts +2 -39
  62. package/dist/EngineWebClient.js +47 -60
  63. package/dist/EngineWebClient.js.map +1 -1
  64. package/dist/clientExecuteTypes-BlJOgCL_.d.cts +91 -0
  65. package/dist/clientExecuteTypes-BlJOgCL_.d.cts.map +1 -0
  66. package/dist/clientExecuteTypes-CJ08_c4q.d.ts +91 -0
  67. package/dist/clientExecuteTypes-CJ08_c4q.d.ts.map +1 -0
  68. package/dist/clientQueryTypes-DlTtS_mX.d.cts +221 -0
  69. package/dist/clientQueryTypes-DlTtS_mX.d.cts.map +1 -0
  70. package/dist/clientQueryTypes-DuRgEeBT.d.ts +221 -0
  71. package/dist/clientQueryTypes-DuRgEeBT.d.ts.map +1 -0
  72. package/dist/endpoints.cjs +19 -45
  73. package/dist/endpoints.cjs.map +1 -1
  74. package/dist/endpoints.d.cts +4 -2
  75. package/dist/endpoints.d.cts.map +1 -0
  76. package/dist/endpoints.d.ts +4 -2
  77. package/dist/endpoints.d.ts.map +1 -0
  78. package/dist/endpoints.js +16 -18
  79. package/dist/endpoints.js.map +1 -1
  80. package/dist/index-CmCelmEL.d.cts +1 -0
  81. package/dist/index-D0E78WnU.d.ts +1 -0
  82. package/dist/index.cjs +26 -31
  83. package/dist/index.d.cts +12 -20
  84. package/dist/index.d.ts +12 -20
  85. package/dist/index.js +8 -6
  86. package/dist/queryDataMappers-BguxA579.d.ts +21 -0
  87. package/dist/queryDataMappers-BguxA579.d.ts.map +1 -0
  88. package/dist/queryDataMappers-DO9yWdLo.d.cts +21 -0
  89. package/dist/queryDataMappers-DO9yWdLo.d.cts.map +1 -0
  90. package/dist/serverExecuteTypes-CgbHjnWM.d.ts +92 -0
  91. package/dist/serverExecuteTypes-CgbHjnWM.d.ts.map +1 -0
  92. package/dist/serverExecuteTypes-DejTR8Is.d.cts +92 -0
  93. package/dist/serverExecuteTypes-DejTR8Is.d.cts.map +1 -0
  94. package/dist/serverQueryModelTypes-85xnbU-a.d.cts +98 -0
  95. package/dist/serverQueryModelTypes-85xnbU-a.d.cts.map +1 -0
  96. package/dist/serverQueryModelTypes-CENoy5Hm.d.ts +98 -0
  97. package/dist/serverQueryModelTypes-CENoy5Hm.d.ts.map +1 -0
  98. package/dist/serverQueryTypes-B3vC8vxT.d.ts +301 -0
  99. package/dist/serverQueryTypes-B3vC8vxT.d.ts.map +1 -0
  100. package/dist/serverQueryTypes-Dva9R2tV.d.cts +301 -0
  101. package/dist/serverQueryTypes-Dva9R2tV.d.cts.map +1 -0
  102. package/dist/serverSubscriptionEventTypes-BMUrTkTg.d.cts +135 -0
  103. package/dist/serverSubscriptionEventTypes-BMUrTkTg.d.cts.map +1 -0
  104. package/dist/serverSubscriptionEventTypes-UCYAjmt7.d.ts +135 -0
  105. package/dist/serverSubscriptionEventTypes-UCYAjmt7.d.ts.map +1 -0
  106. package/dist/serverSubscriptionTypes-BSuYa6z_.d.cts +82 -0
  107. package/dist/serverSubscriptionTypes-BSuYa6z_.d.cts.map +1 -0
  108. package/dist/serverSubscriptionTypes-DoMWeKgY.d.ts +82 -0
  109. package/dist/serverSubscriptionTypes-DoMWeKgY.d.ts.map +1 -0
  110. package/dist/types/EngineServerFailureError.cjs +9 -33
  111. package/dist/types/EngineServerFailureError.cjs.map +1 -1
  112. package/dist/types/EngineServerFailureError.d.cts +2 -11
  113. package/dist/types/EngineServerFailureError.d.ts +2 -11
  114. package/dist/types/EngineServerFailureError.js +8 -8
  115. package/dist/types/EngineServerFailureError.js.map +1 -1
  116. package/dist/types/clientExecuteTypes.cjs +0 -19
  117. package/dist/types/clientExecuteTypes.d.cts +2 -91
  118. package/dist/types/clientExecuteTypes.d.ts +2 -91
  119. package/dist/types/clientExecuteTypes.js +1 -1
  120. package/dist/types/clientQueryTypes.cjs +0 -19
  121. package/dist/types/clientQueryTypes.d.cts +2 -219
  122. package/dist/types/clientQueryTypes.d.ts +2 -219
  123. package/dist/types/clientQueryTypes.js +1 -1
  124. package/dist/types/index.cjs +5 -39
  125. package/dist/types/index.d.cts +9 -10
  126. package/dist/types/index.d.ts +9 -10
  127. package/dist/types/index.js +3 -10
  128. package/dist/types/serverExecuteTypes.cjs +0 -19
  129. package/dist/types/serverExecuteTypes.d.cts +2 -93
  130. package/dist/types/serverExecuteTypes.d.ts +2 -93
  131. package/dist/types/serverExecuteTypes.js +1 -1
  132. package/dist/types/serverQueryModelTypes.cjs +0 -19
  133. package/dist/types/serverQueryModelTypes.d.cts +2 -96
  134. package/dist/types/serverQueryModelTypes.d.ts +2 -96
  135. package/dist/types/serverQueryModelTypes.js +1 -1
  136. package/dist/types/serverQueryTypes.cjs +12 -36
  137. package/dist/types/serverQueryTypes.cjs.map +1 -1
  138. package/dist/types/serverQueryTypes.d.cts +2 -309
  139. package/dist/types/serverQueryTypes.d.ts +2 -309
  140. package/dist/types/serverQueryTypes.js +11 -11
  141. package/dist/types/serverQueryTypes.js.map +1 -1
  142. package/dist/types/serverSubscriptionEventTypes.cjs +0 -19
  143. package/dist/types/serverSubscriptionEventTypes.d.cts +2 -135
  144. package/dist/types/serverSubscriptionEventTypes.d.ts +2 -135
  145. package/dist/types/serverSubscriptionEventTypes.js +1 -1
  146. package/dist/types/serverSubscriptionTypes.cjs +0 -19
  147. package/dist/types/serverSubscriptionTypes.d.cts +2 -80
  148. package/dist/types/serverSubscriptionTypes.d.ts +2 -80
  149. package/dist/types/serverSubscriptionTypes.js +1 -1
  150. package/dist/utils/index.cjs +14 -25
  151. package/dist/utils/index.d.cts +2 -6
  152. package/dist/utils/index.d.ts +2 -6
  153. package/dist/utils/index.js +2 -3
  154. package/dist/utils/productEngineTypeMappers.cjs +16 -44
  155. package/dist/utils/productEngineTypeMappers.cjs.map +1 -1
  156. package/dist/utils/productEngineTypeMappers.d.cts +5 -3
  157. package/dist/utils/productEngineTypeMappers.d.cts.map +1 -0
  158. package/dist/utils/productEngineTypeMappers.d.ts +5 -3
  159. package/dist/utils/productEngineTypeMappers.d.ts.map +1 -0
  160. package/dist/utils/productEngineTypeMappers.js +12 -17
  161. package/dist/utils/productEngineTypeMappers.js.map +1 -1
  162. package/dist/utils/queryDataMappers.cjs +204 -292
  163. package/dist/utils/queryDataMappers.cjs.map +1 -1
  164. package/dist/utils/queryDataMappers.d.cts +2 -20
  165. package/dist/utils/queryDataMappers.d.ts +2 -20
  166. package/dist/utils/queryDataMappers.js +190 -264
  167. package/dist/utils/queryDataMappers.js.map +1 -1
  168. package/package.json +9 -9
  169. package/src/EngineQueryClient.ts +4 -0
  170. package/src/types/clientQueryTypes.ts +3 -0
  171. package/src/types/serverQueryTypes.ts +3 -0
  172. package/dist/EngineBaseClient.cjs.map +0 -1
  173. package/dist/index.cjs.map +0 -1
  174. package/dist/index.js.map +0 -1
  175. package/dist/types/clientExecuteTypes.cjs.map +0 -1
  176. package/dist/types/clientExecuteTypes.js.map +0 -1
  177. package/dist/types/clientQueryTypes.cjs.map +0 -1
  178. package/dist/types/clientQueryTypes.js.map +0 -1
  179. package/dist/types/index.cjs.map +0 -1
  180. package/dist/types/index.js.map +0 -1
  181. package/dist/types/serverExecuteTypes.cjs.map +0 -1
  182. package/dist/types/serverExecuteTypes.js.map +0 -1
  183. package/dist/types/serverQueryModelTypes.cjs.map +0 -1
  184. package/dist/types/serverQueryModelTypes.js.map +0 -1
  185. package/dist/types/serverSubscriptionEventTypes.cjs.map +0 -1
  186. package/dist/types/serverSubscriptionEventTypes.js.map +0 -1
  187. package/dist/types/serverSubscriptionTypes.cjs.map +0 -1
  188. package/dist/types/serverSubscriptionTypes.js.map +0 -1
  189. package/dist/utils/index.cjs.map +0 -1
  190. package/dist/utils/index.js.map +0 -1
@@ -1,450 +1,357 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_EngineBaseClient = require("./EngineBaseClient-Uc1D8ftx.cjs");
3
+ const require_utils_productEngineTypeMappers = require("./utils/productEngineTypeMappers.cjs");
4
+ const require_utils_queryDataMappers = require("./utils/queryDataMappers.cjs");
5
+ let _nadohq_shared = require("@nadohq/shared");
6
+ //#region src/EngineQueryClient.ts
7
+ var EngineQueryClient = class extends require_EngineBaseClient.EngineBaseClient {
8
+ /**
9
+ * Retrieves the set of contracts that the engine is interfacing with
10
+ */
11
+ async getContracts() {
12
+ const baseResponse = await this.query("contracts", {});
13
+ return {
14
+ chainId: Number(baseResponse.chain_id),
15
+ endpointAddr: baseResponse.endpoint_addr
16
+ };
17
+ }
18
+ /**
19
+ * Retrieves current engine status
20
+ */
21
+ async getStatus() {
22
+ return this.query("status", {});
23
+ }
24
+ /**
25
+ * Retrieves a subaccount summary reflective of the state within the offchain engine. This adheres to the
26
+ * same return interface as the contract version
27
+ *
28
+ * @param params
29
+ */
30
+ async getSubaccountSummary(params) {
31
+ const subaccount = (0, _nadohq_shared.subaccountToHex)({
32
+ subaccountOwner: params.subaccountOwner,
33
+ subaccountName: params.subaccountName
34
+ });
35
+ return require_utils_queryDataMappers.mapSubaccountSummary(await this.query("subaccount_info", { subaccount }));
36
+ }
37
+ /**
38
+ * Retrieves a list of isolated positions
39
+ *
40
+ * @param params
41
+ */
42
+ async getIsolatedPositions(params) {
43
+ const subaccount = (0, _nadohq_shared.subaccountToHex)({
44
+ subaccountOwner: params.subaccountOwner,
45
+ subaccountName: params.subaccountName
46
+ });
47
+ return require_utils_queryDataMappers.mapEngineServerIsolatedPositions(await this.query("isolated_positions", { subaccount }));
48
+ }
49
+ /**
50
+ * Retrieves an estimated subaccount summary with the applied transactions
51
+ *
52
+ * @param params
53
+ */
54
+ async getEstimatedSubaccountSummary(params) {
55
+ const subaccount = (0, _nadohq_shared.subaccountToHex)({
56
+ subaccountOwner: params.subaccountOwner,
57
+ subaccountName: params.subaccountName
58
+ });
59
+ const queryParams = {
60
+ subaccount,
61
+ txns: params.txs.map((tx) => {
62
+ switch (tx.type) {
63
+ case "apply_delta": return { apply_delta: {
64
+ product_id: tx.tx.productId,
65
+ subaccount,
66
+ amount_delta: (0, _nadohq_shared.toIntegerString)(tx.tx.amountDelta),
67
+ v_quote_delta: (0, _nadohq_shared.toIntegerString)(tx.tx.vQuoteDelta)
68
+ } };
69
+ }
70
+ })
71
+ };
72
+ return require_utils_queryDataMappers.mapSubaccountSummary(await this.query("subaccount_info", {
73
+ subaccount: queryParams.subaccount,
74
+ txns: JSON.stringify(queryParams.txns),
75
+ pre_state: params.preState !== void 0 ? String(params.preState) : void 0
76
+ }));
77
+ }
78
+ /**
79
+ * Retrieves symbols and product info
80
+ *
81
+ * @param params
82
+ */
83
+ async getSymbols(params) {
84
+ return require_utils_queryDataMappers.mapEngineServerSymbols(await this.query("symbols", {
85
+ product_ids: params.productIds,
86
+ product_type: params.productType != null ? require_utils_productEngineTypeMappers.mapProductEngineType(params.productType) : void 0
87
+ }));
88
+ }
89
+ /**
90
+ * Retrieves all market states as per the offchain engine. Same return interface as contracts
91
+ */
92
+ async getAllMarkets() {
93
+ const markets = [];
94
+ const baseResponse = await this.query("all_products", {});
95
+ baseResponse.spot_products.forEach((spotProduct) => {
96
+ markets.push(require_utils_queryDataMappers.mapEngineServerSpotProduct(spotProduct));
97
+ });
98
+ baseResponse.perp_products.forEach((perpProduct) => {
99
+ markets.push(require_utils_queryDataMappers.mapEngineServerPerpProduct(perpProduct));
100
+ });
101
+ return markets;
102
+ }
103
+ /**
104
+ * Retrieves all markets by chain id.
105
+ */
106
+ async getEdgeAllMarkets() {
107
+ return (0, _nadohq_shared.mapValues)((await this.query("edge_all_products", {})).edge_all_products, (allProducts) => {
108
+ const markets = [];
109
+ allProducts.spot_products.forEach((spotProduct) => {
110
+ markets.push(require_utils_queryDataMappers.mapEngineServerSpotProduct(spotProduct));
111
+ });
112
+ allProducts.perp_products.forEach((perpProduct) => {
113
+ markets.push(require_utils_queryDataMappers.mapEngineServerPerpProduct(perpProduct));
114
+ });
115
+ return markets;
116
+ });
117
+ }
118
+ /**
119
+ * Retrieves all health groups (linked spot & perp products) from the engine
120
+ */
121
+ async getHealthGroups() {
122
+ return { healthGroups: (await this.query("health_groups", {})).health_groups.map(([spotProductId, perpProductId]) => {
123
+ return {
124
+ spotProductId,
125
+ perpProductId
126
+ };
127
+ }) };
128
+ }
129
+ /**
130
+ * Retrieves an order from the offchain engine
131
+ *
132
+ * @param params
133
+ */
134
+ async getOrder(params) {
135
+ return require_utils_queryDataMappers.mapEngineServerOrder(await this.query("order", {
136
+ digest: params.digest,
137
+ product_id: params.productId
138
+ }));
139
+ }
140
+ /**
141
+ * Signs and validates with the engine that the order is valid to be submitted (i.e. does not violate health reqs)
142
+ *
143
+ * @param params
144
+ */
145
+ async validateOrderParams(params) {
146
+ const signedOrder = {
147
+ order: params.order,
148
+ signature: await this.sign("place_order", (0, _nadohq_shared.getOrderVerifyingAddress)(params.productId), params.chainId, params.order)
149
+ };
150
+ return this.validateSignedOrderParams({
151
+ signedOrder,
152
+ productId: params.productId
153
+ });
154
+ }
155
+ /**
156
+ * Validates an existing signed order with the engine as a pre-check for health
157
+ *
158
+ * @param params
159
+ */
160
+ async validateSignedOrderParams(params) {
161
+ const baseResponse = await this.query("validate_order", {
162
+ product_id: params.productId,
163
+ order: (0, _nadohq_shared.encodeSignedOrder)(params.signedOrder)
164
+ });
165
+ return {
166
+ productId: baseResponse.product_id,
167
+ valid: baseResponse.valid
168
+ };
169
+ }
170
+ /**
171
+ * Get all subaccount orders from the engine, per product ID
172
+ * @param params
173
+ */
174
+ async getSubaccountOrders(params) {
175
+ return {
176
+ orders: (await this.query("subaccount_orders", {
177
+ sender: (0, _nadohq_shared.subaccountToHex)({
178
+ subaccountOwner: params.subaccountOwner,
179
+ subaccountName: params.subaccountName
180
+ }),
181
+ product_id: params.productId
182
+ })).orders.map(require_utils_queryDataMappers.mapEngineServerOrder),
183
+ productId: params.productId
184
+ };
185
+ }
186
+ /**
187
+ * Get all subaccount orders from the engine, for multiple products
188
+ * @param params
189
+ */
190
+ async getSubaccountMultiProductOrders(params) {
191
+ return { productOrders: (await this.query("orders", {
192
+ sender: (0, _nadohq_shared.subaccountToHex)({
193
+ subaccountOwner: params.subaccountOwner,
194
+ subaccountName: params.subaccountName
195
+ }),
196
+ product_ids: params.productIds
197
+ })).product_orders.map((orders) => {
198
+ return {
199
+ orders: orders.orders.map(require_utils_queryDataMappers.mapEngineServerOrder),
200
+ productId: orders.product_id
201
+ };
202
+ }) };
203
+ }
204
+ /**
205
+ * Gets maker & taker fee rates for order fees
206
+ * @param params
207
+ */
208
+ async getSubaccountFeeRates(params) {
209
+ const baseResponse = await this.query("fee_rates", { sender: (0, _nadohq_shared.subaccountToHex)({
210
+ subaccountOwner: params.subaccountOwner,
211
+ subaccountName: params.subaccountName
212
+ }) });
213
+ return {
214
+ healthCheckSequencerFee: (0, _nadohq_shared.toBigNumber)(baseResponse.health_check_sequencer_fee),
215
+ liquidationSequencerFee: (0, _nadohq_shared.toBigNumber)(baseResponse.liquidation_sequencer_fee),
216
+ takerSequencerFee: (0, _nadohq_shared.toBigNumber)(baseResponse.taker_sequencer_fee),
217
+ orders: baseResponse.taker_fee_rates_x18.reduce((acc, takerRateX18, currIndex) => {
218
+ acc[currIndex] = {
219
+ taker: (0, _nadohq_shared.removeDecimals)(takerRateX18),
220
+ maker: (0, _nadohq_shared.removeDecimals)(baseResponse.maker_fee_rates_x18[currIndex])
221
+ };
222
+ return acc;
223
+ }, {}),
224
+ withdrawal: baseResponse.withdraw_sequencer_fees.reduce((acc, productFee, currIndex) => {
225
+ acc[currIndex] = (0, _nadohq_shared.toBigNumber)(productFee);
226
+ return acc;
227
+ }, {}),
228
+ feeTier: baseResponse.fee_tier
229
+ };
230
+ }
231
+ /**
232
+ * Gets "price ticks" for a given market, useful for constructing liquidity levels at each price
233
+ * @param params
234
+ */
235
+ async getMarketLiquidity(params) {
236
+ const baseResponse = await this.query("market_liquidity", {
237
+ product_id: params.productId,
238
+ depth: params.depth
239
+ });
240
+ return {
241
+ asks: baseResponse.asks.map(require_utils_queryDataMappers.mapEngineServerTickLiquidity),
242
+ bids: baseResponse.bids.map(require_utils_queryDataMappers.mapEngineServerTickLiquidity)
243
+ };
244
+ }
245
+ /**
246
+ * Retrieves the latest price for a given market
247
+ * @param params
248
+ */
249
+ async getMarketPrice(params) {
250
+ return require_utils_queryDataMappers.mapEngineMarketPrice(await this.query("market_price", { product_id: params.productId }));
251
+ }
252
+ /**
253
+ * Retrieves the latest prices for provided markets
254
+ * @param params
255
+ */
256
+ async getMarketPrices(params) {
257
+ return { marketPrices: (await this.query("market_prices", { product_ids: params.productIds })).market_prices.map(require_utils_queryDataMappers.mapEngineMarketPrice) };
258
+ }
259
+ /**
260
+ * Retrieves the estimated max order size for a product
261
+ * @param params
262
+ */
263
+ async getMaxOrderSize(params) {
264
+ return (0, _nadohq_shared.toBigNumber)((await this.query("max_order_size", {
265
+ direction: params.side,
266
+ price_x18: (0, _nadohq_shared.toIntegerString)((0, _nadohq_shared.addDecimals)(params.price)),
267
+ avg_price_x18: params.avgPrice != null ? (0, _nadohq_shared.toIntegerString)((0, _nadohq_shared.addDecimals)(params.avgPrice)) : null,
268
+ product_id: params.productId,
269
+ sender: (0, _nadohq_shared.subaccountToHex)({
270
+ subaccountOwner: params.subaccountOwner,
271
+ subaccountName: params.subaccountName
272
+ }),
273
+ spot_leverage: params.spotLeverage != null ? String(params.spotLeverage) : null,
274
+ reduce_only: params.reduceOnly != null ? String(params.reduceOnly) : null,
275
+ isolated: params.isolated != null ? String(params.isolated) : null,
276
+ borrow_margin: params.isolated && params.isoBorrowMargin != null ? String(params.isoBorrowMargin) : null
277
+ })).max_order_size);
278
+ }
279
+ /**
280
+ * Retrieves the estimated max withdrawal size for a product
281
+ * @param params
282
+ */
283
+ async getMaxWithdrawable(params) {
284
+ return (0, _nadohq_shared.toBigNumber)((await this.query("max_withdrawable", {
285
+ product_id: params.productId,
286
+ sender: (0, _nadohq_shared.subaccountToHex)({
287
+ subaccountOwner: params.subaccountOwner,
288
+ subaccountName: params.subaccountName
289
+ }),
290
+ spot_leverage: params.spotLeverage != null ? String(params.spotLeverage) : null
291
+ })).max_withdrawable);
292
+ }
293
+ /**
294
+ * Retrieves the estimated max quote amount for minting NLP.
295
+ *
296
+ * @param params
297
+ */
298
+ async getMaxMintNlpAmount(params) {
299
+ return (0, _nadohq_shared.toBigNumber)((await this.query("max_nlp_mintable", {
300
+ sender: (0, _nadohq_shared.subaccountToHex)({
301
+ subaccountOwner: params.subaccountOwner,
302
+ subaccountName: params.subaccountName
303
+ }),
304
+ spot_leverage: params.spotLeverage != null ? String(params.spotLeverage) : null
305
+ })).max_quote_amount);
306
+ }
307
+ /**
308
+ * Retrieves the max amount of NLP that can be burned.
309
+ *
310
+ * @param params
311
+ */
312
+ async getMaxBurnNlpAmount(params) {
313
+ return (0, _nadohq_shared.toBigNumber)((await this.query("max_nlp_burnable", { sender: (0, _nadohq_shared.subaccountToHex)({
314
+ subaccountOwner: params.subaccountOwner,
315
+ subaccountName: params.subaccountName
316
+ }) })).max_nlp_amount);
317
+ }
318
+ /**
319
+ * Gets the currently linked signer for the subaccount
320
+ * @param params
321
+ * @returns
322
+ */
323
+ async getLinkedSigner(params) {
324
+ return { signer: (await this.query("linked_signer", { subaccount: (0, _nadohq_shared.subaccountToHex)({
325
+ subaccountOwner: params.subaccountOwner,
326
+ subaccountName: params.subaccountName
327
+ }) })).linked_signer };
328
+ }
329
+ /**
330
+ * Gets the insurance funds in USDT.
331
+ * @returns
332
+ */
333
+ async getInsurance() {
334
+ return (0, _nadohq_shared.toBigNumber)((await this.query("insurance", {})).insurance);
335
+ }
336
+ /**
337
+ * Retrieves the NLP locked and unlocked balances for a subaccount.
338
+ *
339
+ * @param params
340
+ */
341
+ async getNlpLockedBalances(params) {
342
+ return require_utils_queryDataMappers.mapEngineServerNlpLockedBalances(await this.query("nlp_locked_balances", { subaccount: (0, _nadohq_shared.subaccountToHex)({
343
+ subaccountOwner: params.subaccountOwner,
344
+ subaccountName: params.subaccountName
345
+ }) }));
346
+ }
347
+ /**
348
+ * Retrieves information about all NLP sub-pools
349
+ */
350
+ async getNlpPoolInfo() {
351
+ return require_utils_queryDataMappers.mapEngineServerNlpPoolInfo(await this.query("nlp_pool_info", {}));
352
+ }
9
353
  };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
354
+ //#endregion
355
+ exports.EngineQueryClient = EngineQueryClient;
19
356
 
20
- // src/EngineQueryClient.ts
21
- var EngineQueryClient_exports = {};
22
- __export(EngineQueryClient_exports, {
23
- EngineQueryClient: () => EngineQueryClient
24
- });
25
- module.exports = __toCommonJS(EngineQueryClient_exports);
26
- var import_shared = require("@nadohq/shared");
27
- var import_EngineBaseClient = require("./EngineBaseClient.cjs");
28
- var import_productEngineTypeMappers = require("./utils/productEngineTypeMappers.cjs");
29
- var import_queryDataMappers = require("./utils/queryDataMappers.cjs");
30
- var EngineQueryClient = class extends import_EngineBaseClient.EngineBaseClient {
31
- /**
32
- * Retrieves the set of contracts that the engine is interfacing with
33
- */
34
- async getContracts() {
35
- const baseResponse = await this.query("contracts", {});
36
- return {
37
- chainId: Number(baseResponse.chain_id),
38
- endpointAddr: baseResponse.endpoint_addr
39
- };
40
- }
41
- /**
42
- * Retrieves current engine status
43
- */
44
- async getStatus() {
45
- return this.query("status", {});
46
- }
47
- /**
48
- * Retrieves a subaccount summary reflective of the state within the offchain engine. This adheres to the
49
- * same return interface as the contract version
50
- *
51
- * @param params
52
- */
53
- async getSubaccountSummary(params) {
54
- const subaccount = (0, import_shared.subaccountToHex)({
55
- subaccountOwner: params.subaccountOwner,
56
- subaccountName: params.subaccountName
57
- });
58
- const baseResponse = await this.query("subaccount_info", {
59
- subaccount
60
- });
61
- return (0, import_queryDataMappers.mapSubaccountSummary)(baseResponse);
62
- }
63
- /**
64
- * Retrieves a list of isolated positions
65
- *
66
- * @param params
67
- */
68
- async getIsolatedPositions(params) {
69
- const subaccount = (0, import_shared.subaccountToHex)({
70
- subaccountOwner: params.subaccountOwner,
71
- subaccountName: params.subaccountName
72
- });
73
- const baseResponse = await this.query("isolated_positions", {
74
- subaccount
75
- });
76
- return (0, import_queryDataMappers.mapEngineServerIsolatedPositions)(baseResponse);
77
- }
78
- /**
79
- * Retrieves an estimated subaccount summary with the applied transactions
80
- *
81
- * @param params
82
- */
83
- async getEstimatedSubaccountSummary(params) {
84
- const subaccount = (0, import_shared.subaccountToHex)({
85
- subaccountOwner: params.subaccountOwner,
86
- subaccountName: params.subaccountName
87
- });
88
- const queryParams = {
89
- subaccount,
90
- txns: params.txs.map(
91
- (tx) => {
92
- switch (tx.type) {
93
- case "apply_delta":
94
- return {
95
- apply_delta: {
96
- product_id: tx.tx.productId,
97
- subaccount,
98
- amount_delta: (0, import_shared.toIntegerString)(tx.tx.amountDelta),
99
- v_quote_delta: (0, import_shared.toIntegerString)(tx.tx.vQuoteDelta)
100
- }
101
- };
102
- }
103
- }
104
- )
105
- };
106
- const baseResponse = await this.query("subaccount_info", {
107
- subaccount: queryParams.subaccount,
108
- txns: JSON.stringify(queryParams.txns),
109
- // Backend expects string variants of booleans
110
- pre_state: params.preState !== void 0 ? String(params.preState) : void 0
111
- });
112
- return (0, import_queryDataMappers.mapSubaccountSummary)(baseResponse);
113
- }
114
- /**
115
- * Retrieves symbols and product info
116
- *
117
- * @param params
118
- */
119
- async getSymbols(params) {
120
- const baseResponse = await this.query("symbols", {
121
- product_ids: params.productIds,
122
- product_type: params.productType != null ? (0, import_productEngineTypeMappers.mapProductEngineType)(params.productType) : void 0
123
- });
124
- return (0, import_queryDataMappers.mapEngineServerSymbols)(baseResponse);
125
- }
126
- /**
127
- * Retrieves all market states as per the offchain engine. Same return interface as contracts
128
- */
129
- async getAllMarkets() {
130
- const markets = [];
131
- const baseResponse = await this.query("all_products", {});
132
- baseResponse.spot_products.forEach((spotProduct) => {
133
- markets.push((0, import_queryDataMappers.mapEngineServerSpotProduct)(spotProduct));
134
- });
135
- baseResponse.perp_products.forEach((perpProduct) => {
136
- markets.push((0, import_queryDataMappers.mapEngineServerPerpProduct)(perpProduct));
137
- });
138
- return markets;
139
- }
140
- /**
141
- * Retrieves all markets by chain id.
142
- */
143
- async getEdgeAllMarkets() {
144
- const baseResponse = await this.query("edge_all_products", {});
145
- return (0, import_shared.mapValues)(baseResponse.edge_all_products, (allProducts) => {
146
- const markets = [];
147
- allProducts.spot_products.forEach((spotProduct) => {
148
- markets.push((0, import_queryDataMappers.mapEngineServerSpotProduct)(spotProduct));
149
- });
150
- allProducts.perp_products.forEach((perpProduct) => {
151
- markets.push((0, import_queryDataMappers.mapEngineServerPerpProduct)(perpProduct));
152
- });
153
- return markets;
154
- });
155
- }
156
- /**
157
- * Retrieves all health groups (linked spot & perp products) from the engine
158
- */
159
- async getHealthGroups() {
160
- const baseResponse = await this.query("health_groups", {});
161
- return {
162
- healthGroups: baseResponse.health_groups.map(
163
- ([spotProductId, perpProductId]) => {
164
- return {
165
- spotProductId,
166
- perpProductId
167
- };
168
- }
169
- )
170
- };
171
- }
172
- /**
173
- * Retrieves an order from the offchain engine
174
- *
175
- * @param params
176
- */
177
- async getOrder(params) {
178
- const baseResponse = await this.query("order", {
179
- digest: params.digest,
180
- product_id: params.productId
181
- });
182
- return (0, import_queryDataMappers.mapEngineServerOrder)(baseResponse);
183
- }
184
- /**
185
- * Signs and validates with the engine that the order is valid to be submitted (i.e. does not violate health reqs)
186
- *
187
- * @param params
188
- */
189
- async validateOrderParams(params) {
190
- const signedOrder = {
191
- order: params.order,
192
- signature: await this.sign(
193
- "place_order",
194
- (0, import_shared.getOrderVerifyingAddress)(params.productId),
195
- params.chainId,
196
- params.order
197
- )
198
- };
199
- return this.validateSignedOrderParams({
200
- signedOrder,
201
- productId: params.productId
202
- });
203
- }
204
- /**
205
- * Validates an existing signed order with the engine as a pre-check for health
206
- *
207
- * @param params
208
- */
209
- async validateSignedOrderParams(params) {
210
- const baseResponse = await this.query("validate_order", {
211
- product_id: params.productId,
212
- order: (0, import_shared.encodeSignedOrder)(params.signedOrder)
213
- });
214
- return {
215
- productId: baseResponse.product_id,
216
- valid: baseResponse.valid
217
- };
218
- }
219
- /**
220
- * Get all subaccount orders from the engine, per product ID
221
- * @param params
222
- */
223
- async getSubaccountOrders(params) {
224
- const baseResponse = await this.query("subaccount_orders", {
225
- sender: (0, import_shared.subaccountToHex)({
226
- subaccountOwner: params.subaccountOwner,
227
- subaccountName: params.subaccountName
228
- }),
229
- product_id: params.productId
230
- });
231
- return {
232
- orders: baseResponse.orders.map(import_queryDataMappers.mapEngineServerOrder),
233
- productId: params.productId
234
- };
235
- }
236
- /**
237
- * Get all subaccount orders from the engine, for multiple products
238
- * @param params
239
- */
240
- async getSubaccountMultiProductOrders(params) {
241
- const baseResponse = await this.query("orders", {
242
- sender: (0, import_shared.subaccountToHex)({
243
- subaccountOwner: params.subaccountOwner,
244
- subaccountName: params.subaccountName
245
- }),
246
- product_ids: params.productIds
247
- });
248
- return {
249
- productOrders: baseResponse.product_orders.map((orders) => {
250
- return {
251
- orders: orders.orders.map(import_queryDataMappers.mapEngineServerOrder),
252
- productId: orders.product_id
253
- };
254
- })
255
- };
256
- }
257
- /**
258
- * Gets maker & taker fee rates for order fees
259
- * @param params
260
- */
261
- async getSubaccountFeeRates(params) {
262
- const baseResponse = await this.query("fee_rates", {
263
- sender: (0, import_shared.subaccountToHex)({
264
- subaccountOwner: params.subaccountOwner,
265
- subaccountName: params.subaccountName
266
- })
267
- });
268
- return {
269
- healthCheckSequencerFee: (0, import_shared.toBigNumber)(
270
- baseResponse.health_check_sequencer_fee
271
- ),
272
- liquidationSequencerFee: (0, import_shared.toBigNumber)(
273
- baseResponse.liquidation_sequencer_fee
274
- ),
275
- takerSequencerFee: (0, import_shared.toBigNumber)(baseResponse.taker_sequencer_fee),
276
- orders: baseResponse.taker_fee_rates_x18.reduce(
277
- (acc, takerRateX18, currIndex) => {
278
- acc[currIndex] = {
279
- taker: (0, import_shared.removeDecimals)(takerRateX18),
280
- maker: (0, import_shared.removeDecimals)(baseResponse.maker_fee_rates_x18[currIndex])
281
- };
282
- return acc;
283
- },
284
- {}
285
- ),
286
- withdrawal: baseResponse.withdraw_sequencer_fees.reduce(
287
- (acc, productFee, currIndex) => {
288
- acc[currIndex] = (0, import_shared.toBigNumber)(productFee);
289
- return acc;
290
- },
291
- {}
292
- ),
293
- feeTier: baseResponse.fee_tier
294
- };
295
- }
296
- /**
297
- * Gets "price ticks" for a given market, useful for constructing liquidity levels at each price
298
- * @param params
299
- */
300
- async getMarketLiquidity(params) {
301
- const baseResponse = await this.query("market_liquidity", {
302
- product_id: params.productId,
303
- depth: params.depth
304
- });
305
- return {
306
- asks: baseResponse.asks.map(import_queryDataMappers.mapEngineServerTickLiquidity),
307
- bids: baseResponse.bids.map(import_queryDataMappers.mapEngineServerTickLiquidity)
308
- };
309
- }
310
- /**
311
- * Retrieves the latest price for a given market
312
- * @param params
313
- */
314
- async getMarketPrice(params) {
315
- const baseResponse = await this.query("market_price", {
316
- product_id: params.productId
317
- });
318
- return (0, import_queryDataMappers.mapEngineMarketPrice)(baseResponse);
319
- }
320
- /**
321
- * Retrieves the latest prices for provided markets
322
- * @param params
323
- */
324
- async getMarketPrices(params) {
325
- const baseResponse = await this.query("market_prices", {
326
- product_ids: params.productIds
327
- });
328
- return {
329
- marketPrices: baseResponse.market_prices.map(import_queryDataMappers.mapEngineMarketPrice)
330
- };
331
- }
332
- /**
333
- * Retrieves the estimated max order size for a product
334
- * @param params
335
- */
336
- async getMaxOrderSize(params) {
337
- const baseResponse = await this.query("max_order_size", {
338
- direction: params.side,
339
- price_x18: (0, import_shared.toIntegerString)((0, import_shared.addDecimals)(params.price)),
340
- product_id: params.productId,
341
- sender: (0, import_shared.subaccountToHex)({
342
- subaccountOwner: params.subaccountOwner,
343
- subaccountName: params.subaccountName
344
- }),
345
- // Backend expects string variants of booleans
346
- spot_leverage: params.spotLeverage != null ? String(params.spotLeverage) : null,
347
- reduce_only: params.reduceOnly != null ? String(params.reduceOnly) : null,
348
- isolated: params.isolated != null ? String(params.isolated) : null,
349
- borrow_margin: (
350
- // This field is only relevant for isolated orders
351
- params.isolated && params.isoBorrowMargin != null ? String(params.isoBorrowMargin) : null
352
- )
353
- });
354
- return (0, import_shared.toBigNumber)(baseResponse.max_order_size);
355
- }
356
- /**
357
- * Retrieves the estimated max withdrawal size for a product
358
- * @param params
359
- */
360
- async getMaxWithdrawable(params) {
361
- const baseResponse = await this.query("max_withdrawable", {
362
- product_id: params.productId,
363
- sender: (0, import_shared.subaccountToHex)({
364
- subaccountOwner: params.subaccountOwner,
365
- subaccountName: params.subaccountName
366
- }),
367
- spot_leverage: params.spotLeverage != null ? String(params.spotLeverage) : null
368
- });
369
- return (0, import_shared.toBigNumber)(baseResponse.max_withdrawable);
370
- }
371
- /**
372
- * Retrieves the estimated max quote amount for minting NLP.
373
- *
374
- * @param params
375
- */
376
- async getMaxMintNlpAmount(params) {
377
- const baseResponse = await this.query("max_nlp_mintable", {
378
- sender: (0, import_shared.subaccountToHex)({
379
- subaccountOwner: params.subaccountOwner,
380
- subaccountName: params.subaccountName
381
- }),
382
- spot_leverage: params.spotLeverage != null ? String(params.spotLeverage) : null
383
- });
384
- return (0, import_shared.toBigNumber)(baseResponse.max_quote_amount);
385
- }
386
- /**
387
- * Retrieves the max amount of NLP that can be burned.
388
- *
389
- * @param params
390
- */
391
- async getMaxBurnNlpAmount(params) {
392
- const baseResponse = await this.query("max_nlp_burnable", {
393
- sender: (0, import_shared.subaccountToHex)({
394
- subaccountOwner: params.subaccountOwner,
395
- subaccountName: params.subaccountName
396
- })
397
- });
398
- return (0, import_shared.toBigNumber)(baseResponse.max_nlp_amount);
399
- }
400
- /**
401
- * Gets the currently linked signer for the subaccount
402
- * @param params
403
- * @returns
404
- */
405
- async getLinkedSigner(params) {
406
- const baseResponse = await this.query("linked_signer", {
407
- subaccount: (0, import_shared.subaccountToHex)({
408
- subaccountOwner: params.subaccountOwner,
409
- subaccountName: params.subaccountName
410
- })
411
- });
412
- return {
413
- signer: baseResponse.linked_signer
414
- };
415
- }
416
- /**
417
- * Gets the insurance funds in USDT.
418
- * @returns
419
- */
420
- async getInsurance() {
421
- const baseResponse = await this.query("insurance", {});
422
- return (0, import_shared.toBigNumber)(baseResponse.insurance);
423
- }
424
- /**
425
- * Retrieves the NLP locked and unlocked balances for a subaccount.
426
- *
427
- * @param params
428
- */
429
- async getNlpLockedBalances(params) {
430
- const baseResponse = await this.query("nlp_locked_balances", {
431
- subaccount: (0, import_shared.subaccountToHex)({
432
- subaccountOwner: params.subaccountOwner,
433
- subaccountName: params.subaccountName
434
- })
435
- });
436
- return (0, import_queryDataMappers.mapEngineServerNlpLockedBalances)(baseResponse);
437
- }
438
- /**
439
- * Retrieves information about all NLP sub-pools
440
- */
441
- async getNlpPoolInfo() {
442
- const baseResponse = await this.query("nlp_pool_info", {});
443
- return (0, import_queryDataMappers.mapEngineServerNlpPoolInfo)(baseResponse);
444
- }
445
- };
446
- // Annotate the CommonJS export names for ESM import in node:
447
- 0 && (module.exports = {
448
- EngineQueryClient
449
- });
450
357
  //# sourceMappingURL=EngineQueryClient.cjs.map