@nadohq/engine-client 0.1.0-alpha.1

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 (142) hide show
  1. package/README.md +2 -0
  2. package/dist/EngineBaseClient.cjs +166 -0
  3. package/dist/EngineBaseClient.cjs.map +1 -0
  4. package/dist/EngineBaseClient.d.cts +75 -0
  5. package/dist/EngineBaseClient.d.ts +75 -0
  6. package/dist/EngineBaseClient.js +133 -0
  7. package/dist/EngineBaseClient.js.map +1 -0
  8. package/dist/EngineClient.cjs +40 -0
  9. package/dist/EngineClient.cjs.map +1 -0
  10. package/dist/EngineClient.d.cts +23 -0
  11. package/dist/EngineClient.d.ts +23 -0
  12. package/dist/EngineClient.js +15 -0
  13. package/dist/EngineClient.js.map +1 -0
  14. package/dist/EngineExecuteBuilder.cjs +304 -0
  15. package/dist/EngineExecuteBuilder.cjs.map +1 -0
  16. package/dist/EngineExecuteBuilder.d.cts +118 -0
  17. package/dist/EngineExecuteBuilder.d.ts +118 -0
  18. package/dist/EngineExecuteBuilder.js +282 -0
  19. package/dist/EngineExecuteBuilder.js.map +1 -0
  20. package/dist/EngineExecuteClient.cjs +114 -0
  21. package/dist/EngineExecuteClient.cjs.map +1 -0
  22. package/dist/EngineExecuteClient.d.cts +28 -0
  23. package/dist/EngineExecuteClient.d.ts +28 -0
  24. package/dist/EngineExecuteClient.js +89 -0
  25. package/dist/EngineExecuteClient.js.map +1 -0
  26. package/dist/EngineQueryClient.cjs +431 -0
  27. package/dist/EngineQueryClient.cjs.map +1 -0
  28. package/dist/EngineQueryClient.d.cts +143 -0
  29. package/dist/EngineQueryClient.d.ts +143 -0
  30. package/dist/EngineQueryClient.js +424 -0
  31. package/dist/EngineQueryClient.js.map +1 -0
  32. package/dist/EngineWebClient.cjs +75 -0
  33. package/dist/EngineWebClient.cjs.map +1 -0
  34. package/dist/EngineWebClient.d.cts +31 -0
  35. package/dist/EngineWebClient.d.ts +31 -0
  36. package/dist/EngineWebClient.js +50 -0
  37. package/dist/EngineWebClient.js.map +1 -0
  38. package/dist/endpoints.cjs +49 -0
  39. package/dist/endpoints.cjs.map +1 -0
  40. package/dist/endpoints.d.cts +7 -0
  41. package/dist/endpoints.d.ts +7 -0
  42. package/dist/endpoints.js +22 -0
  43. package/dist/endpoints.js.map +1 -0
  44. package/dist/index.cjs +31 -0
  45. package/dist/index.cjs.map +1 -0
  46. package/dist/index.d.cts +20 -0
  47. package/dist/index.d.ts +20 -0
  48. package/dist/index.js +6 -0
  49. package/dist/index.js.map +1 -0
  50. package/dist/types/EngineServerFailureError.cjs +36 -0
  51. package/dist/types/EngineServerFailureError.cjs.map +1 -0
  52. package/dist/types/EngineServerFailureError.d.cts +11 -0
  53. package/dist/types/EngineServerFailureError.d.ts +11 -0
  54. package/dist/types/EngineServerFailureError.js +11 -0
  55. package/dist/types/EngineServerFailureError.js.map +1 -0
  56. package/dist/types/clientExecuteTypes.cjs +19 -0
  57. package/dist/types/clientExecuteTypes.cjs.map +1 -0
  58. package/dist/types/clientExecuteTypes.d.cts +74 -0
  59. package/dist/types/clientExecuteTypes.d.ts +74 -0
  60. package/dist/types/clientExecuteTypes.js +1 -0
  61. package/dist/types/clientExecuteTypes.js.map +1 -0
  62. package/dist/types/clientQueryTypes.cjs +19 -0
  63. package/dist/types/clientQueryTypes.cjs.map +1 -0
  64. package/dist/types/clientQueryTypes.d.cts +189 -0
  65. package/dist/types/clientQueryTypes.d.ts +189 -0
  66. package/dist/types/clientQueryTypes.js +1 -0
  67. package/dist/types/clientQueryTypes.js.map +1 -0
  68. package/dist/types/index.cjs +39 -0
  69. package/dist/types/index.cjs.map +1 -0
  70. package/dist/types/index.d.cts +10 -0
  71. package/dist/types/index.d.ts +10 -0
  72. package/dist/types/index.js +10 -0
  73. package/dist/types/index.js.map +1 -0
  74. package/dist/types/serverExecuteTypes.cjs +19 -0
  75. package/dist/types/serverExecuteTypes.cjs.map +1 -0
  76. package/dist/types/serverExecuteTypes.d.cts +91 -0
  77. package/dist/types/serverExecuteTypes.d.ts +91 -0
  78. package/dist/types/serverExecuteTypes.js +1 -0
  79. package/dist/types/serverExecuteTypes.js.map +1 -0
  80. package/dist/types/serverQueryModelTypes.cjs +19 -0
  81. package/dist/types/serverQueryModelTypes.cjs.map +1 -0
  82. package/dist/types/serverQueryModelTypes.d.cts +73 -0
  83. package/dist/types/serverQueryModelTypes.d.ts +73 -0
  84. package/dist/types/serverQueryModelTypes.js +1 -0
  85. package/dist/types/serverQueryModelTypes.js.map +1 -0
  86. package/dist/types/serverQueryTypes.cjs +19 -0
  87. package/dist/types/serverQueryTypes.cjs.map +1 -0
  88. package/dist/types/serverQueryTypes.d.cts +292 -0
  89. package/dist/types/serverQueryTypes.d.ts +292 -0
  90. package/dist/types/serverQueryTypes.js +1 -0
  91. package/dist/types/serverQueryTypes.js.map +1 -0
  92. package/dist/types/serverSubscriptionEventTypes.cjs +19 -0
  93. package/dist/types/serverSubscriptionEventTypes.cjs.map +1 -0
  94. package/dist/types/serverSubscriptionEventTypes.d.cts +71 -0
  95. package/dist/types/serverSubscriptionEventTypes.d.ts +71 -0
  96. package/dist/types/serverSubscriptionEventTypes.js +1 -0
  97. package/dist/types/serverSubscriptionEventTypes.js.map +1 -0
  98. package/dist/types/serverSubscriptionTypes.cjs +19 -0
  99. package/dist/types/serverSubscriptionTypes.cjs.map +1 -0
  100. package/dist/types/serverSubscriptionTypes.d.cts +63 -0
  101. package/dist/types/serverSubscriptionTypes.d.ts +63 -0
  102. package/dist/types/serverSubscriptionTypes.js +1 -0
  103. package/dist/types/serverSubscriptionTypes.js.map +1 -0
  104. package/dist/utils/index.cjs +25 -0
  105. package/dist/utils/index.cjs.map +1 -0
  106. package/dist/utils/index.d.cts +6 -0
  107. package/dist/utils/index.d.ts +6 -0
  108. package/dist/utils/index.js +3 -0
  109. package/dist/utils/index.js.map +1 -0
  110. package/dist/utils/productEngineTypeMappers.cjs +49 -0
  111. package/dist/utils/productEngineTypeMappers.cjs.map +1 -0
  112. package/dist/utils/productEngineTypeMappers.d.cts +7 -0
  113. package/dist/utils/productEngineTypeMappers.d.ts +7 -0
  114. package/dist/utils/productEngineTypeMappers.js +23 -0
  115. package/dist/utils/productEngineTypeMappers.js.map +1 -0
  116. package/dist/utils/queryDataMappers.cjs +282 -0
  117. package/dist/utils/queryDataMappers.cjs.map +1 -0
  118. package/dist/utils/queryDataMappers.d.cts +18 -0
  119. package/dist/utils/queryDataMappers.d.ts +18 -0
  120. package/dist/utils/queryDataMappers.js +258 -0
  121. package/dist/utils/queryDataMappers.js.map +1 -0
  122. package/package.json +52 -0
  123. package/src/EngineBaseClient.ts +223 -0
  124. package/src/EngineClient.ts +13 -0
  125. package/src/EngineExecuteBuilder.ts +381 -0
  126. package/src/EngineExecuteClient.ts +122 -0
  127. package/src/EngineQueryClient.ts +553 -0
  128. package/src/EngineWebClient.ts +72 -0
  129. package/src/endpoints.ts +21 -0
  130. package/src/index.ts +4 -0
  131. package/src/types/EngineServerFailureError.ts +12 -0
  132. package/src/types/clientExecuteTypes.ts +118 -0
  133. package/src/types/clientQueryTypes.ts +267 -0
  134. package/src/types/index.ts +8 -0
  135. package/src/types/serverExecuteTypes.ts +138 -0
  136. package/src/types/serverQueryModelTypes.ts +83 -0
  137. package/src/types/serverQueryTypes.ts +382 -0
  138. package/src/types/serverSubscriptionEventTypes.ts +74 -0
  139. package/src/types/serverSubscriptionTypes.ts +79 -0
  140. package/src/utils/index.ts +1 -0
  141. package/src/utils/productEngineTypeMappers.ts +24 -0
  142. package/src/utils/queryDataMappers.ts +303 -0
@@ -0,0 +1,431 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/EngineQueryClient.ts
21
+ var EngineQueryClient_exports = {};
22
+ __export(EngineQueryClient_exports, {
23
+ EngineQueryClient: () => EngineQueryClient
24
+ });
25
+ module.exports = __toCommonJS(EngineQueryClient_exports);
26
+ var import_contracts = require("@nadohq/contracts");
27
+ var import_utils = require("@nadohq/utils");
28
+ var import_EngineBaseClient = require("./EngineBaseClient.cjs");
29
+ var import_productEngineTypeMappers = require("./utils/productEngineTypeMappers.cjs");
30
+ var import_queryDataMappers = require("./utils/queryDataMappers.cjs");
31
+ var EngineQueryClient = class extends import_EngineBaseClient.EngineBaseClient {
32
+ /**
33
+ * Retrieves the set of contracts that the engine is interfacing with
34
+ */
35
+ async getContracts() {
36
+ const baseResponse = await this.query("contracts", {});
37
+ return {
38
+ chainId: Number(baseResponse.chain_id),
39
+ endpointAddr: baseResponse.endpoint_addr,
40
+ orderbookAddrs: baseResponse.book_addrs
41
+ };
42
+ }
43
+ /**
44
+ * Retrieves current engine status
45
+ */
46
+ async getStatus() {
47
+ return this.query("status", {});
48
+ }
49
+ /**
50
+ * Retrieves a subaccount summary reflective of the state within the offchain engine. This adheres to the
51
+ * same return interface as the contract version
52
+ *
53
+ * @param params
54
+ */
55
+ async getSubaccountSummary(params) {
56
+ const subaccount = (0, import_contracts.subaccountToHex)({
57
+ subaccountOwner: params.subaccountOwner,
58
+ subaccountName: params.subaccountName
59
+ });
60
+ const baseResponse = await this.query("subaccount_info", {
61
+ subaccount
62
+ });
63
+ return (0, import_queryDataMappers.mapSubaccountSummary)(baseResponse);
64
+ }
65
+ /**
66
+ * Retrieves a list of isolated positions
67
+ *
68
+ * @param params
69
+ */
70
+ async getIsolatedPositions(params) {
71
+ const subaccount = (0, import_contracts.subaccountToHex)({
72
+ subaccountOwner: params.subaccountOwner,
73
+ subaccountName: params.subaccountName
74
+ });
75
+ const baseResponse = await this.query("isolated_positions", {
76
+ subaccount
77
+ });
78
+ return (0, import_queryDataMappers.mapEngineServerIsolatedPositions)(baseResponse);
79
+ }
80
+ /**
81
+ * Retrieves an estimated subaccount summary with the applied transactions
82
+ *
83
+ * @param params
84
+ */
85
+ async getEstimatedSubaccountSummary(params) {
86
+ const subaccount = (0, import_contracts.subaccountToHex)({
87
+ subaccountOwner: params.subaccountOwner,
88
+ subaccountName: params.subaccountName
89
+ });
90
+ const queryParams = {
91
+ subaccount,
92
+ txns: params.txs.map(
93
+ (tx) => {
94
+ switch (tx.type) {
95
+ case "apply_delta":
96
+ return {
97
+ apply_delta: {
98
+ product_id: tx.tx.productId,
99
+ subaccount,
100
+ amount_delta: (0, import_utils.toIntegerString)(tx.tx.amountDelta),
101
+ v_quote_delta: (0, import_utils.toIntegerString)(tx.tx.vQuoteDelta)
102
+ }
103
+ };
104
+ }
105
+ }
106
+ )
107
+ };
108
+ const baseResponse = await this.query("subaccount_info", {
109
+ subaccount: queryParams.subaccount,
110
+ txns: JSON.stringify(queryParams.txns)
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_utils.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 min deposit rates for all spot products from the engine
174
+ */
175
+ async getMinDepositRates() {
176
+ const baseResponse = await this.query("min_deposit_rates", {});
177
+ return {
178
+ minDepositRates: (0, import_utils.mapValues)(baseResponse.min_deposit_rates, (m) => {
179
+ return {
180
+ productId: m.product_id,
181
+ minDepositRate: (0, import_utils.removeDecimals)(m.min_deposit_rate_x18)
182
+ };
183
+ })
184
+ };
185
+ }
186
+ /**
187
+ * Retrieves an order from the offchain engine
188
+ *
189
+ * @param params
190
+ */
191
+ async getOrder(params) {
192
+ const baseResponse = await this.query("order", {
193
+ digest: params.digest,
194
+ product_id: params.productId
195
+ });
196
+ return (0, import_queryDataMappers.mapEngineServerOrder)(baseResponse);
197
+ }
198
+ /**
199
+ * Signs and validates with the engine that the order is valid to be submitted (i.e. does not violate health reqs)
200
+ *
201
+ * @param params
202
+ */
203
+ async validateOrderParams(params) {
204
+ const signedOrder = {
205
+ order: params.order,
206
+ signature: await this.sign(
207
+ "place_order",
208
+ params.orderbookAddr,
209
+ params.chainId,
210
+ params.order
211
+ )
212
+ };
213
+ return this.validateSignedOrderParams({
214
+ signedOrder,
215
+ productId: params.productId
216
+ });
217
+ }
218
+ /**
219
+ * Validates an existing signed order with the engine as a pre-check for health
220
+ *
221
+ * @param params
222
+ */
223
+ async validateSignedOrderParams(params) {
224
+ const baseResponse = await this.query("validate_order", {
225
+ product_id: params.productId,
226
+ order: (0, import_contracts.encodeSignedOrder)(params.signedOrder)
227
+ });
228
+ return {
229
+ productId: baseResponse.product_id,
230
+ valid: baseResponse.valid
231
+ };
232
+ }
233
+ /**
234
+ * Get all subaccount orders from the engine, per product ID
235
+ * @param params
236
+ */
237
+ async getSubaccountOrders(params) {
238
+ const baseResponse = await this.query("subaccount_orders", {
239
+ sender: (0, import_contracts.subaccountToHex)({
240
+ subaccountOwner: params.subaccountOwner,
241
+ subaccountName: params.subaccountName
242
+ }),
243
+ product_id: params.productId
244
+ });
245
+ return {
246
+ orders: baseResponse.orders.map(import_queryDataMappers.mapEngineServerOrder),
247
+ productId: params.productId
248
+ };
249
+ }
250
+ /**
251
+ * Get all subaccount orders from the engine, for multiple products
252
+ * @param params
253
+ */
254
+ async getSubaccountMultiProductOrders(params) {
255
+ const baseResponse = await this.query("orders", {
256
+ sender: (0, import_contracts.subaccountToHex)({
257
+ subaccountOwner: params.subaccountOwner,
258
+ subaccountName: params.subaccountName
259
+ }),
260
+ product_ids: params.productIds
261
+ });
262
+ return {
263
+ productOrders: baseResponse.product_orders.map((orders) => {
264
+ return {
265
+ orders: orders.orders.map(import_queryDataMappers.mapEngineServerOrder),
266
+ productId: orders.product_id
267
+ };
268
+ })
269
+ };
270
+ }
271
+ /**
272
+ * Gets maker & taker fee rates for order fees
273
+ * @param params
274
+ */
275
+ async getSubaccountFeeRates(params) {
276
+ const baseResponse = await this.query("fee_rates", {
277
+ sender: (0, import_contracts.subaccountToHex)({
278
+ subaccountOwner: params.subaccountOwner,
279
+ subaccountName: params.subaccountName
280
+ })
281
+ });
282
+ return {
283
+ healthCheckSequencerFee: (0, import_utils.toBigDecimal)(
284
+ baseResponse.health_check_sequencer_fee
285
+ ),
286
+ liquidationSequencerFee: (0, import_utils.toBigDecimal)(
287
+ baseResponse.liquidation_sequencer_fee
288
+ ),
289
+ takerSequencerFee: (0, import_utils.toBigDecimal)(baseResponse.taker_sequencer_fee),
290
+ orders: baseResponse.taker_fee_rates_x18.reduce(
291
+ (acc, takerRateX18, currIndex) => {
292
+ acc[currIndex] = {
293
+ taker: (0, import_utils.removeDecimals)(takerRateX18),
294
+ maker: (0, import_utils.removeDecimals)(baseResponse.maker_fee_rates_x18[currIndex])
295
+ };
296
+ return acc;
297
+ },
298
+ {}
299
+ ),
300
+ withdrawal: baseResponse.withdraw_sequencer_fees.reduce(
301
+ (acc, productFee, currIndex) => {
302
+ acc[currIndex] = (0, import_utils.toBigDecimal)(productFee);
303
+ return acc;
304
+ },
305
+ {}
306
+ )
307
+ };
308
+ }
309
+ /**
310
+ * Gets "price ticks" for a given market, useful for constructing liquidity levels at each price
311
+ * @param params
312
+ */
313
+ async getMarketLiquidity(params) {
314
+ const baseResponse = await this.query("market_liquidity", {
315
+ product_id: params.productId,
316
+ depth: params.depth
317
+ });
318
+ return {
319
+ asks: baseResponse.asks.map(import_queryDataMappers.mapEngineServerTickLiquidity),
320
+ bids: baseResponse.bids.map(import_queryDataMappers.mapEngineServerTickLiquidity)
321
+ };
322
+ }
323
+ /**
324
+ * Retrieves the latest price for a given market
325
+ * @param params
326
+ */
327
+ async getMarketPrice(params) {
328
+ const baseResponse = await this.query("market_price", {
329
+ product_id: params.productId
330
+ });
331
+ return (0, import_queryDataMappers.mapEngineMarketPrice)(baseResponse);
332
+ }
333
+ /**
334
+ * Retrieves the latest prices for provided markets
335
+ * @param params
336
+ */
337
+ async getMarketPrices(params) {
338
+ const baseResponse = await this.query("market_prices", {
339
+ product_ids: params.productIds
340
+ });
341
+ return {
342
+ marketPrices: baseResponse.market_prices.map(import_queryDataMappers.mapEngineMarketPrice)
343
+ };
344
+ }
345
+ /**
346
+ * Retrieves the estimated max order size for a product
347
+ * @param params
348
+ */
349
+ async getMaxOrderSize(params) {
350
+ const baseResponse = await this.query("max_order_size", {
351
+ direction: params.side,
352
+ price_x18: (0, import_utils.toIntegerString)((0, import_utils.addDecimals)(params.price)),
353
+ product_id: params.productId,
354
+ sender: (0, import_contracts.subaccountToHex)({
355
+ subaccountOwner: params.subaccountOwner,
356
+ subaccountName: params.subaccountName
357
+ }),
358
+ spot_leverage: params.spotLeverage != null ? String(params.spotLeverage) : null,
359
+ reduce_only: params.reduceOnly != null ? String(params.reduceOnly) : null
360
+ });
361
+ return (0, import_utils.toBigDecimal)(baseResponse.max_order_size);
362
+ }
363
+ /**
364
+ * Retrieves the estimated max withdrawal size for a product
365
+ * @param params
366
+ */
367
+ async getMaxWithdrawable(params) {
368
+ const baseResponse = await this.query("max_withdrawable", {
369
+ product_id: params.productId,
370
+ sender: (0, import_contracts.subaccountToHex)({
371
+ subaccountOwner: params.subaccountOwner,
372
+ subaccountName: params.subaccountName
373
+ }),
374
+ spot_leverage: params.spotLeverage != null ? String(params.spotLeverage) : null
375
+ });
376
+ return (0, import_utils.toBigDecimal)(baseResponse.max_withdrawable);
377
+ }
378
+ /**
379
+ * Retrieves the estimated max quote amount for minting VLP.
380
+ *
381
+ * @param params
382
+ */
383
+ async getMaxMintVlpAmount(params) {
384
+ const baseResponse = await this.query("max_vlp_mintable", {
385
+ sender: (0, import_contracts.subaccountToHex)({
386
+ subaccountOwner: params.subaccountOwner,
387
+ subaccountName: params.subaccountName
388
+ }),
389
+ spot_leverage: params.spotLeverage != null ? String(params.spotLeverage) : null
390
+ });
391
+ return (0, import_utils.toBigDecimal)(baseResponse.max_quote_amount);
392
+ }
393
+ /**
394
+ * Gets the currently linked signer for the subaccount
395
+ * @param params
396
+ * @returns
397
+ */
398
+ async getLinkedSigner(params) {
399
+ const baseResponse = await this.query("linked_signer", {
400
+ subaccount: (0, import_contracts.subaccountToHex)({
401
+ subaccountOwner: params.subaccountOwner,
402
+ subaccountName: params.subaccountName
403
+ })
404
+ });
405
+ return {
406
+ signer: baseResponse.linked_signer
407
+ };
408
+ }
409
+ /**
410
+ * Gets the insurance funds in USDC.
411
+ * @returns
412
+ */
413
+ async getInsurance() {
414
+ const baseResponse = await this.query("insurance", {});
415
+ return (0, import_utils.toBigDecimal)(baseResponse.insurance);
416
+ }
417
+ /**
418
+ * Gets the orderbook contract address for a given product
419
+ * @param productId
420
+ * @returns
421
+ */
422
+ async getOrderbookAddress(productId) {
423
+ const contracts = await this.getContracts();
424
+ return contracts.orderbookAddrs[productId];
425
+ }
426
+ };
427
+ // Annotate the CommonJS export names for ESM import in node:
428
+ 0 && (module.exports = {
429
+ EngineQueryClient
430
+ });
431
+ //# sourceMappingURL=EngineQueryClient.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/EngineQueryClient.ts"],"sourcesContent":["import {\n encodeSignedOrder,\n MarketWithProduct,\n subaccountToHex,\n} from '@nadohq/contracts';\nimport {\n addDecimals,\n BigDecimal,\n mapValues,\n removeDecimals,\n toBigDecimal,\n toIntegerString,\n} from '@nadohq/utils';\nimport { EngineBaseClient } from './EngineBaseClient';\nimport {\n EngineServerStatusResponse,\n EngineServerSubaccountInfoQueryParams,\n EngineSymbolsResponse,\n GetEngineAllMarketsResponse,\n GetEngineContractsResponse,\n GetEngineEstimatedSubaccountSummaryParams,\n GetEngineHealthGroupsResponse,\n GetEngineInsuranceResponse,\n GetEngineIsolatedPositionsParams,\n GetEngineIsolatedPositionsResponse,\n GetEngineLinkedSignerParams,\n GetEngineLinkedSignerResponse,\n GetEngineMarketLiquidityParams,\n GetEngineMarketLiquidityResponse,\n GetEngineMarketPriceParams,\n GetEngineMarketPriceResponse,\n GetEngineMarketPricesParams,\n GetEngineMarketPricesResponse,\n GetEngineMaxMintVlpAmountParams,\n GetEngineMaxMintVlpAmountResponse,\n GetEngineMaxOrderSizeParams,\n GetEngineMaxOrderSizeResponse,\n GetEngineMaxWithdrawableParams,\n GetEngineMaxWithdrawableResponse,\n GetEngineMinDepositRatesResponse,\n GetEngineOrderParams,\n GetEngineOrderResponse,\n GetEngineSubaccountFeeRatesParams,\n GetEngineSubaccountFeeRatesResponse,\n GetEngineSubaccountOrdersParams,\n GetEngineSubaccountOrdersResponse,\n GetEngineSubaccountProductOrdersParams,\n GetEngineSubaccountProductOrdersResponse,\n GetEngineSubaccountSummaryParams,\n GetEngineSubaccountSummaryResponse,\n GetEngineSymbolsParams,\n SubaccountOrderFeeRates,\n ValidateEngineOrderParams,\n ValidateEngineOrderResponse,\n ValidateSignedEngineOrderParams,\n} from './types';\nimport { mapProductEngineType } from './utils/productEngineTypeMappers';\nimport {\n mapEngineMarketPrice,\n mapEngineServerIsolatedPositions,\n mapEngineServerOrder,\n mapEngineServerPerpProduct,\n mapEngineServerSpotProduct,\n mapEngineServerSymbols,\n mapEngineServerTickLiquidity,\n mapSubaccountSummary,\n} from './utils/queryDataMappers';\n\nexport class EngineQueryClient extends EngineBaseClient {\n /**\n * Retrieves the set of contracts that the engine is interfacing with\n */\n async getContracts(): Promise<GetEngineContractsResponse> {\n const baseResponse = await this.query('contracts', {});\n return {\n chainId: Number(baseResponse.chain_id),\n endpointAddr: baseResponse.endpoint_addr,\n orderbookAddrs: baseResponse.book_addrs,\n };\n }\n\n /**\n * Retrieves current engine status\n */\n async getStatus(): Promise<EngineServerStatusResponse> {\n return this.query('status', {});\n }\n\n /**\n * Retrieves a subaccount summary reflective of the state within the offchain engine. This adheres to the\n * same return interface as the contract version\n *\n * @param params\n */\n async getSubaccountSummary(\n params: GetEngineSubaccountSummaryParams,\n ): Promise<GetEngineSubaccountSummaryResponse> {\n const subaccount = subaccountToHex({\n subaccountOwner: params.subaccountOwner,\n subaccountName: params.subaccountName,\n });\n const baseResponse = await this.query('subaccount_info', {\n subaccount,\n });\n\n return mapSubaccountSummary(baseResponse);\n }\n\n /**\n * Retrieves a list of isolated positions\n *\n * @param params\n */\n async getIsolatedPositions(\n params: GetEngineIsolatedPositionsParams,\n ): Promise<GetEngineIsolatedPositionsResponse> {\n const subaccount = subaccountToHex({\n subaccountOwner: params.subaccountOwner,\n subaccountName: params.subaccountName,\n });\n const baseResponse = await this.query('isolated_positions', {\n subaccount,\n });\n\n return mapEngineServerIsolatedPositions(baseResponse);\n }\n\n /**\n * Retrieves an estimated subaccount summary with the applied transactions\n *\n * @param params\n */\n async getEstimatedSubaccountSummary(\n params: GetEngineEstimatedSubaccountSummaryParams,\n ): Promise<GetEngineSubaccountSummaryResponse> {\n const subaccount = subaccountToHex({\n subaccountOwner: params.subaccountOwner,\n subaccountName: params.subaccountName,\n });\n const queryParams: EngineServerSubaccountInfoQueryParams = {\n subaccount: subaccount,\n txns: params.txs.map(\n (\n tx,\n ): NonNullable<\n EngineServerSubaccountInfoQueryParams['txns']\n >[number] => {\n switch (tx.type) {\n case 'apply_delta':\n return {\n apply_delta: {\n product_id: tx.tx.productId,\n subaccount,\n amount_delta: toIntegerString(tx.tx.amountDelta),\n v_quote_delta: toIntegerString(tx.tx.vQuoteDelta),\n },\n };\n }\n },\n ),\n };\n const baseResponse = await this.query('subaccount_info', {\n subaccount: queryParams.subaccount,\n txns: JSON.stringify(queryParams.txns),\n });\n\n return mapSubaccountSummary(baseResponse);\n }\n\n /**\n * Retrieves symbols and product info\n *\n * @param params\n */\n async getSymbols(\n params: GetEngineSymbolsParams,\n ): Promise<EngineSymbolsResponse> {\n const baseResponse = await this.query('symbols', {\n product_ids: params.productIds,\n product_type:\n params.productType != null\n ? mapProductEngineType(params.productType)\n : undefined,\n });\n return mapEngineServerSymbols(baseResponse);\n }\n\n /**\n * Retrieves all market states as per the offchain engine. Same return interface as contracts\n */\n async getAllMarkets(): Promise<GetEngineAllMarketsResponse> {\n const markets: MarketWithProduct[] = [];\n\n const baseResponse = await this.query('all_products', {});\n baseResponse.spot_products.forEach((spotProduct) => {\n markets.push(mapEngineServerSpotProduct(spotProduct));\n });\n baseResponse.perp_products.forEach((perpProduct) => {\n markets.push(mapEngineServerPerpProduct(perpProduct));\n });\n\n return markets;\n }\n\n /**\n * Retrieves all markets by chain id.\n */\n async getEdgeAllMarkets(): Promise<Record<number, MarketWithProduct[]>> {\n const baseResponse = await this.query('edge_all_products', {});\n\n return mapValues(baseResponse.edge_all_products, (allProducts) => {\n const markets: MarketWithProduct[] = [];\n\n allProducts.spot_products.forEach((spotProduct) => {\n markets.push(mapEngineServerSpotProduct(spotProduct));\n });\n\n allProducts.perp_products.forEach((perpProduct) => {\n markets.push(mapEngineServerPerpProduct(perpProduct));\n });\n\n return markets;\n });\n }\n\n /**\n * Retrieves all health groups (linked spot & perp products) from the engine\n */\n async getHealthGroups(): Promise<GetEngineHealthGroupsResponse> {\n const baseResponse = await this.query('health_groups', {});\n\n return {\n healthGroups: baseResponse.health_groups.map(\n ([spotProductId, perpProductId]) => {\n return {\n spotProductId,\n perpProductId,\n };\n },\n ),\n };\n }\n\n /**\n * Retrieves min deposit rates for all spot products from the engine\n */\n async getMinDepositRates(): Promise<GetEngineMinDepositRatesResponse> {\n const baseResponse = await this.query('min_deposit_rates', {});\n\n return {\n minDepositRates: mapValues(baseResponse.min_deposit_rates, (m) => {\n return {\n productId: m.product_id,\n minDepositRate: removeDecimals(m.min_deposit_rate_x18),\n };\n }),\n };\n }\n\n /**\n * Retrieves an order from the offchain engine\n *\n * @param params\n */\n async getOrder(\n params: GetEngineOrderParams,\n ): Promise<GetEngineOrderResponse> {\n const baseResponse = await this.query('order', {\n digest: params.digest,\n product_id: params.productId,\n });\n\n return mapEngineServerOrder(baseResponse);\n }\n\n /**\n * Signs and validates with the engine that the order is valid to be submitted (i.e. does not violate health reqs)\n *\n * @param params\n */\n async validateOrderParams(\n params: ValidateEngineOrderParams,\n ): Promise<ValidateEngineOrderResponse> {\n const signedOrder = {\n order: params.order,\n signature: await this.sign(\n 'place_order',\n params.orderbookAddr,\n params.chainId,\n params.order,\n ),\n };\n return this.validateSignedOrderParams({\n signedOrder,\n productId: params.productId,\n });\n }\n\n /**\n * Validates an existing signed order with the engine as a pre-check for health\n *\n * @param params\n */\n async validateSignedOrderParams(\n params: ValidateSignedEngineOrderParams,\n ): Promise<ValidateEngineOrderResponse> {\n const baseResponse = await this.query('validate_order', {\n product_id: params.productId,\n order: encodeSignedOrder(params.signedOrder),\n });\n\n return {\n productId: baseResponse.product_id,\n valid: baseResponse.valid,\n };\n }\n\n /**\n * Get all subaccount orders from the engine, per product ID\n * @param params\n */\n async getSubaccountOrders(\n params: GetEngineSubaccountOrdersParams,\n ): Promise<GetEngineSubaccountOrdersResponse> {\n const baseResponse = await this.query('subaccount_orders', {\n sender: subaccountToHex({\n subaccountOwner: params.subaccountOwner,\n subaccountName: params.subaccountName,\n }),\n product_id: params.productId,\n });\n\n return {\n orders: baseResponse.orders.map(mapEngineServerOrder),\n productId: params.productId,\n };\n }\n\n /**\n * Get all subaccount orders from the engine, for multiple products\n * @param params\n */\n async getSubaccountMultiProductOrders(\n params: GetEngineSubaccountProductOrdersParams,\n ): Promise<GetEngineSubaccountProductOrdersResponse> {\n const baseResponse = await this.query('orders', {\n sender: subaccountToHex({\n subaccountOwner: params.subaccountOwner,\n subaccountName: params.subaccountName,\n }),\n product_ids: params.productIds,\n });\n\n return {\n productOrders: baseResponse.product_orders.map((orders) => {\n return {\n orders: orders.orders.map(mapEngineServerOrder),\n productId: orders.product_id,\n };\n }),\n };\n }\n\n /**\n * Gets maker & taker fee rates for order fees\n * @param params\n */\n async getSubaccountFeeRates(\n params: GetEngineSubaccountFeeRatesParams,\n ): Promise<GetEngineSubaccountFeeRatesResponse> {\n const baseResponse = await this.query('fee_rates', {\n sender: subaccountToHex({\n subaccountOwner: params.subaccountOwner,\n subaccountName: params.subaccountName,\n }),\n });\n\n return {\n healthCheckSequencerFee: toBigDecimal(\n baseResponse.health_check_sequencer_fee,\n ),\n liquidationSequencerFee: toBigDecimal(\n baseResponse.liquidation_sequencer_fee,\n ),\n takerSequencerFee: toBigDecimal(baseResponse.taker_sequencer_fee),\n orders: baseResponse.taker_fee_rates_x18.reduce(\n (acc, takerRateX18, currIndex) => {\n acc[currIndex] = {\n taker: removeDecimals(takerRateX18),\n maker: removeDecimals(baseResponse.maker_fee_rates_x18[currIndex]),\n };\n return acc;\n },\n {} as Record<number, SubaccountOrderFeeRates>,\n ),\n withdrawal: baseResponse.withdraw_sequencer_fees.reduce(\n (acc, productFee, currIndex) => {\n acc[currIndex] = toBigDecimal(productFee);\n return acc;\n },\n {} as Record<number, BigDecimal>,\n ),\n };\n }\n\n /**\n * Gets \"price ticks\" for a given market, useful for constructing liquidity levels at each price\n * @param params\n */\n async getMarketLiquidity(\n params: GetEngineMarketLiquidityParams,\n ): Promise<GetEngineMarketLiquidityResponse> {\n const baseResponse = await this.query('market_liquidity', {\n product_id: params.productId,\n depth: params.depth,\n });\n return {\n asks: baseResponse.asks.map(mapEngineServerTickLiquidity),\n bids: baseResponse.bids.map(mapEngineServerTickLiquidity),\n };\n }\n\n /**\n * Retrieves the latest price for a given market\n * @param params\n */\n async getMarketPrice(\n params: GetEngineMarketPriceParams,\n ): Promise<GetEngineMarketPriceResponse> {\n const baseResponse = await this.query('market_price', {\n product_id: params.productId,\n });\n return mapEngineMarketPrice(baseResponse);\n }\n\n /**\n * Retrieves the latest prices for provided markets\n * @param params\n */\n async getMarketPrices(\n params: GetEngineMarketPricesParams,\n ): Promise<GetEngineMarketPricesResponse> {\n const baseResponse = await this.query('market_prices', {\n product_ids: params.productIds,\n });\n return {\n marketPrices: baseResponse.market_prices.map(mapEngineMarketPrice),\n };\n }\n\n /**\n * Retrieves the estimated max order size for a product\n * @param params\n */\n async getMaxOrderSize(\n params: GetEngineMaxOrderSizeParams,\n ): Promise<GetEngineMaxOrderSizeResponse> {\n const baseResponse = await this.query('max_order_size', {\n direction: params.side,\n price_x18: toIntegerString(addDecimals(params.price)),\n product_id: params.productId,\n sender: subaccountToHex({\n subaccountOwner: params.subaccountOwner,\n subaccountName: params.subaccountName,\n }),\n spot_leverage:\n params.spotLeverage != null ? String(params.spotLeverage) : null,\n reduce_only: params.reduceOnly != null ? String(params.reduceOnly) : null,\n });\n\n return toBigDecimal(baseResponse.max_order_size);\n }\n\n /**\n * Retrieves the estimated max withdrawal size for a product\n * @param params\n */\n async getMaxWithdrawable(\n params: GetEngineMaxWithdrawableParams,\n ): Promise<GetEngineMaxWithdrawableResponse> {\n const baseResponse = await this.query('max_withdrawable', {\n product_id: params.productId,\n sender: subaccountToHex({\n subaccountOwner: params.subaccountOwner,\n subaccountName: params.subaccountName,\n }),\n spot_leverage:\n params.spotLeverage != null ? String(params.spotLeverage) : null,\n });\n\n return toBigDecimal(baseResponse.max_withdrawable);\n }\n\n /**\n * Retrieves the estimated max quote amount for minting VLP.\n *\n * @param params\n */\n async getMaxMintVlpAmount(\n params: GetEngineMaxMintVlpAmountParams,\n ): Promise<GetEngineMaxMintVlpAmountResponse> {\n const baseResponse = await this.query('max_vlp_mintable', {\n sender: subaccountToHex({\n subaccountOwner: params.subaccountOwner,\n subaccountName: params.subaccountName,\n }),\n spot_leverage:\n params.spotLeverage != null ? String(params.spotLeverage) : null,\n });\n\n return toBigDecimal(baseResponse.max_quote_amount);\n }\n\n /**\n * Gets the currently linked signer for the subaccount\n * @param params\n * @returns\n */\n public async getLinkedSigner(\n params: GetEngineLinkedSignerParams,\n ): Promise<GetEngineLinkedSignerResponse> {\n const baseResponse = await this.query('linked_signer', {\n subaccount: subaccountToHex({\n subaccountOwner: params.subaccountOwner,\n subaccountName: params.subaccountName,\n }),\n });\n\n return {\n signer: baseResponse.linked_signer,\n };\n }\n\n /**\n * Gets the insurance funds in USDC.\n * @returns\n */\n public async getInsurance(): Promise<GetEngineInsuranceResponse> {\n const baseResponse = await this.query('insurance', {});\n\n return toBigDecimal(baseResponse.insurance);\n }\n\n /**\n * Gets the orderbook contract address for a given product\n * @param productId\n * @returns\n */\n public async getOrderbookAddress(productId: number): Promise<string> {\n const contracts = await this.getContracts();\n return contracts.orderbookAddrs[productId];\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAIO;AACP,mBAOO;AACP,8BAAiC;AA2CjC,sCAAqC;AACrC,8BASO;AAEA,IAAM,oBAAN,cAAgC,yCAAiB;AAAA;AAAA;AAAA;AAAA,EAItD,MAAM,eAAoD;AACxD,UAAM,eAAe,MAAM,KAAK,MAAM,aAAa,CAAC,CAAC;AACrD,WAAO;AAAA,MACL,SAAS,OAAO,aAAa,QAAQ;AAAA,MACrC,cAAc,aAAa;AAAA,MAC3B,gBAAgB,aAAa;AAAA,IAC/B;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,YAAiD;AACrD,WAAO,KAAK,MAAM,UAAU,CAAC,CAAC;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,qBACJ,QAC6C;AAC7C,UAAM,iBAAa,kCAAgB;AAAA,MACjC,iBAAiB,OAAO;AAAA,MACxB,gBAAgB,OAAO;AAAA,IACzB,CAAC;AACD,UAAM,eAAe,MAAM,KAAK,MAAM,mBAAmB;AAAA,MACvD;AAAA,IACF,CAAC;AAED,eAAO,8CAAqB,YAAY;AAAA,EAC1C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,qBACJ,QAC6C;AAC7C,UAAM,iBAAa,kCAAgB;AAAA,MACjC,iBAAiB,OAAO;AAAA,MACxB,gBAAgB,OAAO;AAAA,IACzB,CAAC;AACD,UAAM,eAAe,MAAM,KAAK,MAAM,sBAAsB;AAAA,MAC1D;AAAA,IACF,CAAC;AAED,eAAO,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AAA;AAAA;AAAA,EAOA,MAAM,oBACJ,QAC4C;AAC5C,UAAM,eAAe,MAAM,KAAK,MAAM,oBAAoB;AAAA,MACxD,YAAQ,kCAAgB;AAAA,QACtB,iBAAiB,OAAO;AAAA,QACxB,gBAAgB,OAAO;AAAA,MACzB,CAAC;AAAA,MACD,eACE,OAAO,gBAAgB,OAAO,OAAO,OAAO,YAAY,IAAI;AAAA,IAChE,CAAC;AAED,eAAO,2BAAa,aAAa,gBAAgB;AAAA,EACnD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAa,gBACX,QACwC;AACxC,UAAM,eAAe,MAAM,KAAK,MAAM,iBAAiB;AAAA,MACrD,gBAAY,kCAAgB;AAAA,QAC1B,iBAAiB,OAAO;AAAA,QACxB,gBAAgB,OAAO;AAAA,MACzB,CAAC;AAAA,IACH,CAAC;AAED,WAAO;AAAA,MACL,QAAQ,aAAa;AAAA,IACvB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAa,eAAoD;AAC/D,UAAM,eAAe,MAAM,KAAK,MAAM,aAAa,CAAC,CAAC;AAErD,eAAO,2BAAa,aAAa,SAAS;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAa,oBAAoB,WAAoC;AACnE,UAAM,YAAY,MAAM,KAAK,aAAa;AAC1C,WAAO,UAAU,eAAe,SAAS;AAAA,EAC3C;AACF;","names":[]}
@@ -0,0 +1,143 @@
1
+ import { MarketWithProduct } from '@nadohq/contracts';
2
+ import { EngineBaseClient } from './EngineBaseClient.cjs';
3
+ import { GetEngineContractsResponse, GetEngineSubaccountSummaryParams, GetEngineSubaccountSummaryResponse, GetEngineIsolatedPositionsParams, GetEngineIsolatedPositionsResponse, GetEngineEstimatedSubaccountSummaryParams, GetEngineSymbolsParams, EngineSymbolsResponse, GetEngineAllMarketsResponse, GetEngineHealthGroupsResponse, GetEngineMinDepositRatesResponse, GetEngineOrderParams, GetEngineOrderResponse, ValidateEngineOrderParams, ValidateEngineOrderResponse, ValidateSignedEngineOrderParams, GetEngineSubaccountOrdersParams, GetEngineSubaccountOrdersResponse, GetEngineSubaccountProductOrdersParams, GetEngineSubaccountProductOrdersResponse, GetEngineSubaccountFeeRatesParams, GetEngineSubaccountFeeRatesResponse, GetEngineMarketLiquidityParams, GetEngineMarketLiquidityResponse, GetEngineMarketPriceParams, GetEngineMarketPriceResponse, GetEngineMarketPricesParams, GetEngineMarketPricesResponse, GetEngineMaxOrderSizeParams, GetEngineMaxOrderSizeResponse, GetEngineMaxWithdrawableParams, GetEngineMaxWithdrawableResponse, GetEngineMaxMintVlpAmountParams, GetEngineMaxMintVlpAmountResponse, GetEngineLinkedSignerParams, GetEngineLinkedSignerResponse, GetEngineInsuranceResponse } from './types/clientQueryTypes.cjs';
4
+ import { EngineServerStatusResponse } from './types/serverQueryTypes.cjs';
5
+ import 'axios';
6
+ import './types/serverExecuteTypes.cjs';
7
+ import '@nadohq/utils';
8
+ import './types/serverQueryModelTypes.cjs';
9
+
10
+ declare class EngineQueryClient extends EngineBaseClient {
11
+ /**
12
+ * Retrieves the set of contracts that the engine is interfacing with
13
+ */
14
+ getContracts(): Promise<GetEngineContractsResponse>;
15
+ /**
16
+ * Retrieves current engine status
17
+ */
18
+ getStatus(): Promise<EngineServerStatusResponse>;
19
+ /**
20
+ * Retrieves a subaccount summary reflective of the state within the offchain engine. This adheres to the
21
+ * same return interface as the contract version
22
+ *
23
+ * @param params
24
+ */
25
+ getSubaccountSummary(params: GetEngineSubaccountSummaryParams): Promise<GetEngineSubaccountSummaryResponse>;
26
+ /**
27
+ * Retrieves a list of isolated positions
28
+ *
29
+ * @param params
30
+ */
31
+ getIsolatedPositions(params: GetEngineIsolatedPositionsParams): Promise<GetEngineIsolatedPositionsResponse>;
32
+ /**
33
+ * Retrieves an estimated subaccount summary with the applied transactions
34
+ *
35
+ * @param params
36
+ */
37
+ getEstimatedSubaccountSummary(params: GetEngineEstimatedSubaccountSummaryParams): Promise<GetEngineSubaccountSummaryResponse>;
38
+ /**
39
+ * Retrieves symbols and product info
40
+ *
41
+ * @param params
42
+ */
43
+ getSymbols(params: GetEngineSymbolsParams): Promise<EngineSymbolsResponse>;
44
+ /**
45
+ * Retrieves all market states as per the offchain engine. Same return interface as contracts
46
+ */
47
+ getAllMarkets(): Promise<GetEngineAllMarketsResponse>;
48
+ /**
49
+ * Retrieves all markets by chain id.
50
+ */
51
+ getEdgeAllMarkets(): Promise<Record<number, MarketWithProduct[]>>;
52
+ /**
53
+ * Retrieves all health groups (linked spot & perp products) from the engine
54
+ */
55
+ getHealthGroups(): Promise<GetEngineHealthGroupsResponse>;
56
+ /**
57
+ * Retrieves min deposit rates for all spot products from the engine
58
+ */
59
+ getMinDepositRates(): Promise<GetEngineMinDepositRatesResponse>;
60
+ /**
61
+ * Retrieves an order from the offchain engine
62
+ *
63
+ * @param params
64
+ */
65
+ getOrder(params: GetEngineOrderParams): Promise<GetEngineOrderResponse>;
66
+ /**
67
+ * Signs and validates with the engine that the order is valid to be submitted (i.e. does not violate health reqs)
68
+ *
69
+ * @param params
70
+ */
71
+ validateOrderParams(params: ValidateEngineOrderParams): Promise<ValidateEngineOrderResponse>;
72
+ /**
73
+ * Validates an existing signed order with the engine as a pre-check for health
74
+ *
75
+ * @param params
76
+ */
77
+ validateSignedOrderParams(params: ValidateSignedEngineOrderParams): Promise<ValidateEngineOrderResponse>;
78
+ /**
79
+ * Get all subaccount orders from the engine, per product ID
80
+ * @param params
81
+ */
82
+ getSubaccountOrders(params: GetEngineSubaccountOrdersParams): Promise<GetEngineSubaccountOrdersResponse>;
83
+ /**
84
+ * Get all subaccount orders from the engine, for multiple products
85
+ * @param params
86
+ */
87
+ getSubaccountMultiProductOrders(params: GetEngineSubaccountProductOrdersParams): Promise<GetEngineSubaccountProductOrdersResponse>;
88
+ /**
89
+ * Gets maker & taker fee rates for order fees
90
+ * @param params
91
+ */
92
+ getSubaccountFeeRates(params: GetEngineSubaccountFeeRatesParams): Promise<GetEngineSubaccountFeeRatesResponse>;
93
+ /**
94
+ * Gets "price ticks" for a given market, useful for constructing liquidity levels at each price
95
+ * @param params
96
+ */
97
+ getMarketLiquidity(params: GetEngineMarketLiquidityParams): Promise<GetEngineMarketLiquidityResponse>;
98
+ /**
99
+ * Retrieves the latest price for a given market
100
+ * @param params
101
+ */
102
+ getMarketPrice(params: GetEngineMarketPriceParams): Promise<GetEngineMarketPriceResponse>;
103
+ /**
104
+ * Retrieves the latest prices for provided markets
105
+ * @param params
106
+ */
107
+ getMarketPrices(params: GetEngineMarketPricesParams): Promise<GetEngineMarketPricesResponse>;
108
+ /**
109
+ * Retrieves the estimated max order size for a product
110
+ * @param params
111
+ */
112
+ getMaxOrderSize(params: GetEngineMaxOrderSizeParams): Promise<GetEngineMaxOrderSizeResponse>;
113
+ /**
114
+ * Retrieves the estimated max withdrawal size for a product
115
+ * @param params
116
+ */
117
+ getMaxWithdrawable(params: GetEngineMaxWithdrawableParams): Promise<GetEngineMaxWithdrawableResponse>;
118
+ /**
119
+ * Retrieves the estimated max quote amount for minting VLP.
120
+ *
121
+ * @param params
122
+ */
123
+ getMaxMintVlpAmount(params: GetEngineMaxMintVlpAmountParams): Promise<GetEngineMaxMintVlpAmountResponse>;
124
+ /**
125
+ * Gets the currently linked signer for the subaccount
126
+ * @param params
127
+ * @returns
128
+ */
129
+ getLinkedSigner(params: GetEngineLinkedSignerParams): Promise<GetEngineLinkedSignerResponse>;
130
+ /**
131
+ * Gets the insurance funds in USDC.
132
+ * @returns
133
+ */
134
+ getInsurance(): Promise<GetEngineInsuranceResponse>;
135
+ /**
136
+ * Gets the orderbook contract address for a given product
137
+ * @param productId
138
+ * @returns
139
+ */
140
+ getOrderbookAddress(productId: number): Promise<string>;
141
+ }
142
+
143
+ export { EngineQueryClient };