@nadohq/engine-client 0.14.0 → 0.17.0

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