@nadohq/engine-client 0.1.0-alpha.1 → 0.1.0-alpha.10

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 (100) hide show
  1. package/dist/EngineBaseClient.cjs +8 -7
  2. package/dist/EngineBaseClient.cjs.map +1 -1
  3. package/dist/EngineBaseClient.d.cts +1 -2
  4. package/dist/EngineBaseClient.d.ts +1 -2
  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 +33 -61
  10. package/dist/EngineExecuteBuilder.cjs.map +1 -1
  11. package/dist/EngineExecuteBuilder.d.cts +14 -25
  12. package/dist/EngineExecuteBuilder.d.ts +14 -25
  13. package/dist/EngineExecuteBuilder.js +25 -53
  14. package/dist/EngineExecuteBuilder.js.map +1 -1
  15. package/dist/EngineExecuteClient.cjs +12 -16
  16. package/dist/EngineExecuteClient.cjs.map +1 -1
  17. package/dist/EngineExecuteClient.d.cts +5 -6
  18. package/dist/EngineExecuteClient.d.ts +5 -6
  19. package/dist/EngineExecuteClient.js +12 -16
  20. package/dist/EngineExecuteClient.js.map +1 -1
  21. package/dist/EngineQueryClient.cjs +33 -57
  22. package/dist/EngineQueryClient.cjs.map +1 -1
  23. package/dist/EngineQueryClient.d.cts +4 -15
  24. package/dist/EngineQueryClient.d.ts +4 -15
  25. package/dist/EngineQueryClient.js +11 -35
  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.d.cts +7 -8
  40. package/dist/index.d.ts +7 -8
  41. package/dist/types/EngineServerFailureError.cjs +1 -1
  42. package/dist/types/EngineServerFailureError.cjs.map +1 -1
  43. package/dist/types/EngineServerFailureError.d.cts +2 -2
  44. package/dist/types/EngineServerFailureError.d.ts +2 -2
  45. package/dist/types/EngineServerFailureError.js +1 -1
  46. package/dist/types/EngineServerFailureError.js.map +1 -1
  47. package/dist/types/clientExecuteTypes.cjs.map +1 -1
  48. package/dist/types/clientExecuteTypes.d.cts +8 -16
  49. package/dist/types/clientExecuteTypes.d.ts +8 -16
  50. package/dist/types/clientQueryTypes.cjs.map +1 -1
  51. package/dist/types/clientQueryTypes.d.cts +15 -25
  52. package/dist/types/clientQueryTypes.d.ts +15 -25
  53. package/dist/types/index.d.cts +7 -8
  54. package/dist/types/index.d.ts +7 -8
  55. package/dist/types/serverExecuteTypes.cjs.map +1 -1
  56. package/dist/types/serverExecuteTypes.d.cts +10 -18
  57. package/dist/types/serverExecuteTypes.d.ts +10 -18
  58. package/dist/types/serverQueryModelTypes.cjs.map +1 -1
  59. package/dist/types/serverQueryModelTypes.d.cts +1 -1
  60. package/dist/types/serverQueryModelTypes.d.ts +1 -1
  61. package/dist/types/serverQueryTypes.cjs.map +1 -1
  62. package/dist/types/serverQueryTypes.d.cts +8 -17
  63. package/dist/types/serverQueryTypes.d.ts +8 -17
  64. package/dist/types/serverSubscriptionEventTypes.cjs.map +1 -1
  65. package/dist/types/serverSubscriptionEventTypes.d.cts +83 -24
  66. package/dist/types/serverSubscriptionEventTypes.d.ts +83 -24
  67. package/dist/types/serverSubscriptionTypes.cjs.map +1 -1
  68. package/dist/types/serverSubscriptionTypes.d.cts +21 -4
  69. package/dist/types/serverSubscriptionTypes.d.ts +21 -4
  70. package/dist/utils/index.d.cts +1 -2
  71. package/dist/utils/index.d.ts +1 -2
  72. package/dist/utils/productEngineTypeMappers.cjs +5 -5
  73. package/dist/utils/productEngineTypeMappers.cjs.map +1 -1
  74. package/dist/utils/productEngineTypeMappers.d.cts +1 -1
  75. package/dist/utils/productEngineTypeMappers.d.ts +1 -1
  76. package/dist/utils/productEngineTypeMappers.js +1 -1
  77. package/dist/utils/productEngineTypeMappers.js.map +1 -1
  78. package/dist/utils/queryDataMappers.cjs +79 -90
  79. package/dist/utils/queryDataMappers.cjs.map +1 -1
  80. package/dist/utils/queryDataMappers.d.cts +1 -2
  81. package/dist/utils/queryDataMappers.d.ts +1 -2
  82. package/dist/utils/queryDataMappers.js +7 -19
  83. package/dist/utils/queryDataMappers.js.map +1 -1
  84. package/package.json +3 -4
  85. package/src/EngineBaseClient.ts +5 -3
  86. package/src/EngineExecuteBuilder.ts +30 -70
  87. package/src/EngineExecuteClient.ts +13 -21
  88. package/src/EngineQueryClient.ts +14 -42
  89. package/src/EngineWebClient.ts +0 -2
  90. package/src/endpoints.ts +4 -5
  91. package/src/types/EngineServerFailureError.ts +2 -2
  92. package/src/types/clientExecuteTypes.ts +13 -25
  93. package/src/types/clientQueryTypes.ts +21 -34
  94. package/src/types/serverExecuteTypes.ts +13 -24
  95. package/src/types/serverQueryModelTypes.ts +1 -1
  96. package/src/types/serverQueryTypes.ts +7 -20
  97. package/src/types/serverSubscriptionEventTypes.ts +130 -22
  98. package/src/types/serverSubscriptionTypes.ts +23 -3
  99. package/src/utils/productEngineTypeMappers.ts +1 -1
  100. package/src/utils/queryDataMappers.ts +7 -20
@@ -23,8 +23,7 @@ __export(EngineQueryClient_exports, {
23
23
  EngineQueryClient: () => EngineQueryClient
24
24
  });
25
25
  module.exports = __toCommonJS(EngineQueryClient_exports);
26
- var import_contracts = require("@nadohq/contracts");
27
- var import_utils = require("@nadohq/utils");
26
+ var import_shared = require("@nadohq/shared");
28
27
  var import_EngineBaseClient = require("./EngineBaseClient.cjs");
29
28
  var import_productEngineTypeMappers = require("./utils/productEngineTypeMappers.cjs");
30
29
  var import_queryDataMappers = require("./utils/queryDataMappers.cjs");
@@ -36,8 +35,7 @@ var EngineQueryClient = class extends import_EngineBaseClient.EngineBaseClient {
36
35
  const baseResponse = await this.query("contracts", {});
37
36
  return {
38
37
  chainId: Number(baseResponse.chain_id),
39
- endpointAddr: baseResponse.endpoint_addr,
40
- orderbookAddrs: baseResponse.book_addrs
38
+ endpointAddr: baseResponse.endpoint_addr
41
39
  };
42
40
  }
43
41
  /**
@@ -53,7 +51,7 @@ var EngineQueryClient = class extends import_EngineBaseClient.EngineBaseClient {
53
51
  * @param params
54
52
  */
55
53
  async getSubaccountSummary(params) {
56
- const subaccount = (0, import_contracts.subaccountToHex)({
54
+ const subaccount = (0, import_shared.subaccountToHex)({
57
55
  subaccountOwner: params.subaccountOwner,
58
56
  subaccountName: params.subaccountName
59
57
  });
@@ -68,7 +66,7 @@ var EngineQueryClient = class extends import_EngineBaseClient.EngineBaseClient {
68
66
  * @param params
69
67
  */
70
68
  async getIsolatedPositions(params) {
71
- const subaccount = (0, import_contracts.subaccountToHex)({
69
+ const subaccount = (0, import_shared.subaccountToHex)({
72
70
  subaccountOwner: params.subaccountOwner,
73
71
  subaccountName: params.subaccountName
74
72
  });
@@ -83,7 +81,7 @@ var EngineQueryClient = class extends import_EngineBaseClient.EngineBaseClient {
83
81
  * @param params
84
82
  */
85
83
  async getEstimatedSubaccountSummary(params) {
86
- const subaccount = (0, import_contracts.subaccountToHex)({
84
+ const subaccount = (0, import_shared.subaccountToHex)({
87
85
  subaccountOwner: params.subaccountOwner,
88
86
  subaccountName: params.subaccountName
89
87
  });
@@ -97,8 +95,8 @@ var EngineQueryClient = class extends import_EngineBaseClient.EngineBaseClient {
97
95
  apply_delta: {
98
96
  product_id: tx.tx.productId,
99
97
  subaccount,
100
- amount_delta: (0, import_utils.toIntegerString)(tx.tx.amountDelta),
101
- v_quote_delta: (0, import_utils.toIntegerString)(tx.tx.vQuoteDelta)
98
+ amount_delta: (0, import_shared.toIntegerString)(tx.tx.amountDelta),
99
+ v_quote_delta: (0, import_shared.toIntegerString)(tx.tx.vQuoteDelta)
102
100
  }
103
101
  };
104
102
  }
@@ -142,7 +140,7 @@ var EngineQueryClient = class extends import_EngineBaseClient.EngineBaseClient {
142
140
  */
143
141
  async getEdgeAllMarkets() {
144
142
  const baseResponse = await this.query("edge_all_products", {});
145
- return (0, import_utils.mapValues)(baseResponse.edge_all_products, (allProducts) => {
143
+ return (0, import_shared.mapValues)(baseResponse.edge_all_products, (allProducts) => {
146
144
  const markets = [];
147
145
  allProducts.spot_products.forEach((spotProduct) => {
148
146
  markets.push((0, import_queryDataMappers.mapEngineServerSpotProduct)(spotProduct));
@@ -169,20 +167,6 @@ var EngineQueryClient = class extends import_EngineBaseClient.EngineBaseClient {
169
167
  )
170
168
  };
171
169
  }
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
170
  /**
187
171
  * Retrieves an order from the offchain engine
188
172
  *
@@ -205,7 +189,7 @@ var EngineQueryClient = class extends import_EngineBaseClient.EngineBaseClient {
205
189
  order: params.order,
206
190
  signature: await this.sign(
207
191
  "place_order",
208
- params.orderbookAddr,
192
+ (0, import_shared.getOrderVerifyingAddress)(params.productId),
209
193
  params.chainId,
210
194
  params.order
211
195
  )
@@ -223,7 +207,7 @@ var EngineQueryClient = class extends import_EngineBaseClient.EngineBaseClient {
223
207
  async validateSignedOrderParams(params) {
224
208
  const baseResponse = await this.query("validate_order", {
225
209
  product_id: params.productId,
226
- order: (0, import_contracts.encodeSignedOrder)(params.signedOrder)
210
+ order: (0, import_shared.encodeSignedOrder)(params.signedOrder)
227
211
  });
228
212
  return {
229
213
  productId: baseResponse.product_id,
@@ -236,7 +220,7 @@ var EngineQueryClient = class extends import_EngineBaseClient.EngineBaseClient {
236
220
  */
237
221
  async getSubaccountOrders(params) {
238
222
  const baseResponse = await this.query("subaccount_orders", {
239
- sender: (0, import_contracts.subaccountToHex)({
223
+ sender: (0, import_shared.subaccountToHex)({
240
224
  subaccountOwner: params.subaccountOwner,
241
225
  subaccountName: params.subaccountName
242
226
  }),
@@ -253,7 +237,7 @@ var EngineQueryClient = class extends import_EngineBaseClient.EngineBaseClient {
253
237
  */
254
238
  async getSubaccountMultiProductOrders(params) {
255
239
  const baseResponse = await this.query("orders", {
256
- sender: (0, import_contracts.subaccountToHex)({
240
+ sender: (0, import_shared.subaccountToHex)({
257
241
  subaccountOwner: params.subaccountOwner,
258
242
  subaccountName: params.subaccountName
259
243
  }),
@@ -274,24 +258,24 @@ var EngineQueryClient = class extends import_EngineBaseClient.EngineBaseClient {
274
258
  */
275
259
  async getSubaccountFeeRates(params) {
276
260
  const baseResponse = await this.query("fee_rates", {
277
- sender: (0, import_contracts.subaccountToHex)({
261
+ sender: (0, import_shared.subaccountToHex)({
278
262
  subaccountOwner: params.subaccountOwner,
279
263
  subaccountName: params.subaccountName
280
264
  })
281
265
  });
282
266
  return {
283
- healthCheckSequencerFee: (0, import_utils.toBigDecimal)(
267
+ healthCheckSequencerFee: (0, import_shared.toBigDecimal)(
284
268
  baseResponse.health_check_sequencer_fee
285
269
  ),
286
- liquidationSequencerFee: (0, import_utils.toBigDecimal)(
270
+ liquidationSequencerFee: (0, import_shared.toBigDecimal)(
287
271
  baseResponse.liquidation_sequencer_fee
288
272
  ),
289
- takerSequencerFee: (0, import_utils.toBigDecimal)(baseResponse.taker_sequencer_fee),
273
+ takerSequencerFee: (0, import_shared.toBigDecimal)(baseResponse.taker_sequencer_fee),
290
274
  orders: baseResponse.taker_fee_rates_x18.reduce(
291
275
  (acc, takerRateX18, currIndex) => {
292
276
  acc[currIndex] = {
293
- taker: (0, import_utils.removeDecimals)(takerRateX18),
294
- maker: (0, import_utils.removeDecimals)(baseResponse.maker_fee_rates_x18[currIndex])
277
+ taker: (0, import_shared.removeDecimals)(takerRateX18),
278
+ maker: (0, import_shared.removeDecimals)(baseResponse.maker_fee_rates_x18[currIndex])
295
279
  };
296
280
  return acc;
297
281
  },
@@ -299,11 +283,12 @@ var EngineQueryClient = class extends import_EngineBaseClient.EngineBaseClient {
299
283
  ),
300
284
  withdrawal: baseResponse.withdraw_sequencer_fees.reduce(
301
285
  (acc, productFee, currIndex) => {
302
- acc[currIndex] = (0, import_utils.toBigDecimal)(productFee);
286
+ acc[currIndex] = (0, import_shared.toBigDecimal)(productFee);
303
287
  return acc;
304
288
  },
305
289
  {}
306
- )
290
+ ),
291
+ feeTier: baseResponse.fee_tier
307
292
  };
308
293
  }
309
294
  /**
@@ -349,16 +334,16 @@ var EngineQueryClient = class extends import_EngineBaseClient.EngineBaseClient {
349
334
  async getMaxOrderSize(params) {
350
335
  const baseResponse = await this.query("max_order_size", {
351
336
  direction: params.side,
352
- price_x18: (0, import_utils.toIntegerString)((0, import_utils.addDecimals)(params.price)),
337
+ price_x18: (0, import_shared.toIntegerString)((0, import_shared.addDecimals)(params.price)),
353
338
  product_id: params.productId,
354
- sender: (0, import_contracts.subaccountToHex)({
339
+ sender: (0, import_shared.subaccountToHex)({
355
340
  subaccountOwner: params.subaccountOwner,
356
341
  subaccountName: params.subaccountName
357
342
  }),
358
343
  spot_leverage: params.spotLeverage != null ? String(params.spotLeverage) : null,
359
344
  reduce_only: params.reduceOnly != null ? String(params.reduceOnly) : null
360
345
  });
361
- return (0, import_utils.toBigDecimal)(baseResponse.max_order_size);
346
+ return (0, import_shared.toBigDecimal)(baseResponse.max_order_size);
362
347
  }
363
348
  /**
364
349
  * Retrieves the estimated max withdrawal size for a product
@@ -367,28 +352,28 @@ var EngineQueryClient = class extends import_EngineBaseClient.EngineBaseClient {
367
352
  async getMaxWithdrawable(params) {
368
353
  const baseResponse = await this.query("max_withdrawable", {
369
354
  product_id: params.productId,
370
- sender: (0, import_contracts.subaccountToHex)({
355
+ sender: (0, import_shared.subaccountToHex)({
371
356
  subaccountOwner: params.subaccountOwner,
372
357
  subaccountName: params.subaccountName
373
358
  }),
374
359
  spot_leverage: params.spotLeverage != null ? String(params.spotLeverage) : null
375
360
  });
376
- return (0, import_utils.toBigDecimal)(baseResponse.max_withdrawable);
361
+ return (0, import_shared.toBigDecimal)(baseResponse.max_withdrawable);
377
362
  }
378
363
  /**
379
- * Retrieves the estimated max quote amount for minting VLP.
364
+ * Retrieves the estimated max quote amount for minting NLP.
380
365
  *
381
366
  * @param params
382
367
  */
383
- async getMaxMintVlpAmount(params) {
384
- const baseResponse = await this.query("max_vlp_mintable", {
385
- sender: (0, import_contracts.subaccountToHex)({
368
+ async getMaxMintNlpAmount(params) {
369
+ const baseResponse = await this.query("max_nlp_mintable", {
370
+ sender: (0, import_shared.subaccountToHex)({
386
371
  subaccountOwner: params.subaccountOwner,
387
372
  subaccountName: params.subaccountName
388
373
  }),
389
374
  spot_leverage: params.spotLeverage != null ? String(params.spotLeverage) : null
390
375
  });
391
- return (0, import_utils.toBigDecimal)(baseResponse.max_quote_amount);
376
+ return (0, import_shared.toBigDecimal)(baseResponse.max_quote_amount);
392
377
  }
393
378
  /**
394
379
  * Gets the currently linked signer for the subaccount
@@ -397,7 +382,7 @@ var EngineQueryClient = class extends import_EngineBaseClient.EngineBaseClient {
397
382
  */
398
383
  async getLinkedSigner(params) {
399
384
  const baseResponse = await this.query("linked_signer", {
400
- subaccount: (0, import_contracts.subaccountToHex)({
385
+ subaccount: (0, import_shared.subaccountToHex)({
401
386
  subaccountOwner: params.subaccountOwner,
402
387
  subaccountName: params.subaccountName
403
388
  })
@@ -412,16 +397,7 @@ var EngineQueryClient = class extends import_EngineBaseClient.EngineBaseClient {
412
397
  */
413
398
  async getInsurance() {
414
399
  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];
400
+ return (0, import_shared.toBigDecimal)(baseResponse.insurance);
425
401
  }
426
402
  };
427
403
  // Annotate the CommonJS export names for ESM import in node:
@@ -1 +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,WA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AO;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":[]}
1
+ {"version":3,"sources":["../src/EngineQueryClient.ts"],"sourcesContent":["import {\n addDecimals,\n BigDecimal,\n encodeSignedOrder,\n getOrderVerifyingAddress,\n mapValues,\n MarketWithProduct,\n removeDecimals,\n subaccountToHex,\n toBigDecimal,\n toIntegerString,\n} from '@nadohq/shared';\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 GetEngineMaxMintNlpAmountParams,\n GetEngineMaxMintNlpAmountResponse,\n GetEngineMaxOrderSizeParams,\n GetEngineMaxOrderSizeResponse,\n GetEngineMaxWithdrawableParams,\n GetEngineMaxWithdrawableResponse,\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 };\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 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 getOrderVerifyingAddress(params.productId),\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 feeTier: baseResponse.fee_tier,\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 NLP.\n *\n * @param params\n */\n async getMaxMintNlpAmount(\n params: GetEngineMaxMintNlpAmountParams,\n ): Promise<GetEngineMaxMintNlpAmountResponse> {\n const baseResponse = await this.query('max_nlp_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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAWO;AACP,8BAAiC;AA0CjC,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,IAC7B;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,E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YAAQ,+BAAgB;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,4BAAa,aAAa,gBAAgB;AAAA,EACnD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,oBACJ,QAC4C;AAC5C,UAAM,eAAe,MAAM,KAAK,MAAM,oBAAoB;AAAA,MACxD,YAAQ,+BAAgB;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,4BAAa,aAAa,gBAAgB;AAAA,EACnD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAa,gBACX,QACwC;AACxC,UAAM,eAAe,MAAM,KAAK,MAAM,iBAAiB;AAAA,MACrD,gBAAY,+BAAgB;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,4BAAa,aAAa,SAAS;AAAA,EAC5C;AACF;","names":[]}
@@ -1,10 +1,9 @@
1
- import { MarketWithProduct } from '@nadohq/contracts';
1
+ import { MarketWithProduct } from '@nadohq/shared';
2
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';
3
+ import { GetEngineContractsResponse, GetEngineSubaccountSummaryParams, GetEngineSubaccountSummaryResponse, GetEngineIsolatedPositionsParams, GetEngineIsolatedPositionsResponse, GetEngineEstimatedSubaccountSummaryParams, GetEngineSymbolsParams, EngineSymbolsResponse, GetEngineAllMarketsResponse, GetEngineHealthGroupsResponse, GetEngineOrderParams, GetEngineOrderResponse, ValidateEngineOrderParams, ValidateEngineOrderResponse, ValidateSignedEngineOrderParams, GetEngineSubaccountOrdersParams, GetEngineSubaccountOrdersResponse, GetEngineSubaccountProductOrdersParams, GetEngineSubaccountProductOrdersResponse, GetEngineSubaccountFeeRatesParams, GetEngineSubaccountFeeRatesResponse, GetEngineMarketLiquidityParams, GetEngineMarketLiquidityResponse, GetEngineMarketPriceParams, GetEngineMarketPriceResponse, GetEngineMarketPricesParams, GetEngineMarketPricesResponse, GetEngineMaxOrderSizeParams, GetEngineMaxOrderSizeResponse, GetEngineMaxWithdrawableParams, GetEngineMaxWithdrawableResponse, GetEngineMaxMintNlpAmountParams, GetEngineMaxMintNlpAmountResponse, GetEngineLinkedSignerParams, GetEngineLinkedSignerResponse, GetEngineInsuranceResponse } from './types/clientQueryTypes.cjs';
4
4
  import { EngineServerStatusResponse } from './types/serverQueryTypes.cjs';
5
5
  import 'axios';
6
6
  import './types/serverExecuteTypes.cjs';
7
- import '@nadohq/utils';
8
7
  import './types/serverQueryModelTypes.cjs';
9
8
 
10
9
  declare class EngineQueryClient extends EngineBaseClient {
@@ -53,10 +52,6 @@ declare class EngineQueryClient extends EngineBaseClient {
53
52
  * Retrieves all health groups (linked spot & perp products) from the engine
54
53
  */
55
54
  getHealthGroups(): Promise<GetEngineHealthGroupsResponse>;
56
- /**
57
- * Retrieves min deposit rates for all spot products from the engine
58
- */
59
- getMinDepositRates(): Promise<GetEngineMinDepositRatesResponse>;
60
55
  /**
61
56
  * Retrieves an order from the offchain engine
62
57
  *
@@ -116,11 +111,11 @@ declare class EngineQueryClient extends EngineBaseClient {
116
111
  */
117
112
  getMaxWithdrawable(params: GetEngineMaxWithdrawableParams): Promise<GetEngineMaxWithdrawableResponse>;
118
113
  /**
119
- * Retrieves the estimated max quote amount for minting VLP.
114
+ * Retrieves the estimated max quote amount for minting NLP.
120
115
  *
121
116
  * @param params
122
117
  */
123
- getMaxMintVlpAmount(params: GetEngineMaxMintVlpAmountParams): Promise<GetEngineMaxMintVlpAmountResponse>;
118
+ getMaxMintNlpAmount(params: GetEngineMaxMintNlpAmountParams): Promise<GetEngineMaxMintNlpAmountResponse>;
124
119
  /**
125
120
  * Gets the currently linked signer for the subaccount
126
121
  * @param params
@@ -132,12 +127,6 @@ declare class EngineQueryClient extends EngineBaseClient {
132
127
  * @returns
133
128
  */
134
129
  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
130
  }
142
131
 
143
132
  export { EngineQueryClient };
@@ -1,10 +1,9 @@
1
- import { MarketWithProduct } from '@nadohq/contracts';
1
+ import { MarketWithProduct } from '@nadohq/shared';
2
2
  import { EngineBaseClient } from './EngineBaseClient.js';
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.js';
3
+ import { GetEngineContractsResponse, GetEngineSubaccountSummaryParams, GetEngineSubaccountSummaryResponse, GetEngineIsolatedPositionsParams, GetEngineIsolatedPositionsResponse, GetEngineEstimatedSubaccountSummaryParams, GetEngineSymbolsParams, EngineSymbolsResponse, GetEngineAllMarketsResponse, GetEngineHealthGroupsResponse, GetEngineOrderParams, GetEngineOrderResponse, ValidateEngineOrderParams, ValidateEngineOrderResponse, ValidateSignedEngineOrderParams, GetEngineSubaccountOrdersParams, GetEngineSubaccountOrdersResponse, GetEngineSubaccountProductOrdersParams, GetEngineSubaccountProductOrdersResponse, GetEngineSubaccountFeeRatesParams, GetEngineSubaccountFeeRatesResponse, GetEngineMarketLiquidityParams, GetEngineMarketLiquidityResponse, GetEngineMarketPriceParams, GetEngineMarketPriceResponse, GetEngineMarketPricesParams, GetEngineMarketPricesResponse, GetEngineMaxOrderSizeParams, GetEngineMaxOrderSizeResponse, GetEngineMaxWithdrawableParams, GetEngineMaxWithdrawableResponse, GetEngineMaxMintNlpAmountParams, GetEngineMaxMintNlpAmountResponse, GetEngineLinkedSignerParams, GetEngineLinkedSignerResponse, GetEngineInsuranceResponse } from './types/clientQueryTypes.js';
4
4
  import { EngineServerStatusResponse } from './types/serverQueryTypes.js';
5
5
  import 'axios';
6
6
  import './types/serverExecuteTypes.js';
7
- import '@nadohq/utils';
8
7
  import './types/serverQueryModelTypes.js';
9
8
 
10
9
  declare class EngineQueryClient extends EngineBaseClient {
@@ -53,10 +52,6 @@ declare class EngineQueryClient extends EngineBaseClient {
53
52
  * Retrieves all health groups (linked spot & perp products) from the engine
54
53
  */
55
54
  getHealthGroups(): Promise<GetEngineHealthGroupsResponse>;
56
- /**
57
- * Retrieves min deposit rates for all spot products from the engine
58
- */
59
- getMinDepositRates(): Promise<GetEngineMinDepositRatesResponse>;
60
55
  /**
61
56
  * Retrieves an order from the offchain engine
62
57
  *
@@ -116,11 +111,11 @@ declare class EngineQueryClient extends EngineBaseClient {
116
111
  */
117
112
  getMaxWithdrawable(params: GetEngineMaxWithdrawableParams): Promise<GetEngineMaxWithdrawableResponse>;
118
113
  /**
119
- * Retrieves the estimated max quote amount for minting VLP.
114
+ * Retrieves the estimated max quote amount for minting NLP.
120
115
  *
121
116
  * @param params
122
117
  */
123
- getMaxMintVlpAmount(params: GetEngineMaxMintVlpAmountParams): Promise<GetEngineMaxMintVlpAmountResponse>;
118
+ getMaxMintNlpAmount(params: GetEngineMaxMintNlpAmountParams): Promise<GetEngineMaxMintNlpAmountResponse>;
124
119
  /**
125
120
  * Gets the currently linked signer for the subaccount
126
121
  * @param params
@@ -132,12 +127,6 @@ declare class EngineQueryClient extends EngineBaseClient {
132
127
  * @returns
133
128
  */
134
129
  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
130
  }
142
131
 
143
132
  export { EngineQueryClient };
@@ -1,15 +1,14 @@
1
1
  // src/EngineQueryClient.ts
2
- import {
3
- encodeSignedOrder,
4
- subaccountToHex
5
- } from "@nadohq/contracts";
6
2
  import {
7
3
  addDecimals,
4
+ encodeSignedOrder,
5
+ getOrderVerifyingAddress,
8
6
  mapValues,
9
7
  removeDecimals,
8
+ subaccountToHex,
10
9
  toBigDecimal,
11
10
  toIntegerString
12
- } from "@nadohq/utils";
11
+ } from "@nadohq/shared";
13
12
  import { EngineBaseClient } from "./EngineBaseClient.js";
14
13
  import { mapProductEngineType } from "./utils/productEngineTypeMappers.js";
15
14
  import {
@@ -30,8 +29,7 @@ var EngineQueryClient = class extends EngineBaseClient {
30
29
  const baseResponse = await this.query("contracts", {});
31
30
  return {
32
31
  chainId: Number(baseResponse.chain_id),
33
- endpointAddr: baseResponse.endpoint_addr,
34
- orderbookAddrs: baseResponse.book_addrs
32
+ endpointAddr: baseResponse.endpoint_addr
35
33
  };
36
34
  }
37
35
  /**
@@ -163,20 +161,6 @@ var EngineQueryClient = class extends EngineBaseClient {
163
161
  )
164
162
  };
165
163
  }
166
- /**
167
- * Retrieves min deposit rates for all spot products from the engine
168
- */
169
- async getMinDepositRates() {
170
- const baseResponse = await this.query("min_deposit_rates", {});
171
- return {
172
- minDepositRates: mapValues(baseResponse.min_deposit_rates, (m) => {
173
- return {
174
- productId: m.product_id,
175
- minDepositRate: removeDecimals(m.min_deposit_rate_x18)
176
- };
177
- })
178
- };
179
- }
180
164
  /**
181
165
  * Retrieves an order from the offchain engine
182
166
  *
@@ -199,7 +183,7 @@ var EngineQueryClient = class extends EngineBaseClient {
199
183
  order: params.order,
200
184
  signature: await this.sign(
201
185
  "place_order",
202
- params.orderbookAddr,
186
+ getOrderVerifyingAddress(params.productId),
203
187
  params.chainId,
204
188
  params.order
205
189
  )
@@ -297,7 +281,8 @@ var EngineQueryClient = class extends EngineBaseClient {
297
281
  return acc;
298
282
  },
299
283
  {}
300
- )
284
+ ),
285
+ feeTier: baseResponse.fee_tier
301
286
  };
302
287
  }
303
288
  /**
@@ -370,12 +355,12 @@ var EngineQueryClient = class extends EngineBaseClient {
370
355
  return toBigDecimal(baseResponse.max_withdrawable);
371
356
  }
372
357
  /**
373
- * Retrieves the estimated max quote amount for minting VLP.
358
+ * Retrieves the estimated max quote amount for minting NLP.
374
359
  *
375
360
  * @param params
376
361
  */
377
- async getMaxMintVlpAmount(params) {
378
- const baseResponse = await this.query("max_vlp_mintable", {
362
+ async getMaxMintNlpAmount(params) {
363
+ const baseResponse = await this.query("max_nlp_mintable", {
379
364
  sender: subaccountToHex({
380
365
  subaccountOwner: params.subaccountOwner,
381
366
  subaccountName: params.subaccountName
@@ -408,15 +393,6 @@ var EngineQueryClient = class extends EngineBaseClient {
408
393
  const baseResponse = await this.query("insurance", {});
409
394
  return toBigDecimal(baseResponse.insurance);
410
395
  }
411
- /**
412
- * Gets the orderbook contract address for a given product
413
- * @param productId
414
- * @returns
415
- */
416
- async getOrderbookAddress(productId) {
417
- const contracts = await this.getContracts();
418
- return contracts.orderbookAddrs[productId];
419
- }
420
396
  };
421
397
  export {
422
398
  EngineQueryClient