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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/dist/EngineBaseClient.cjs +8 -7
  2. package/dist/EngineBaseClient.cjs.map +1 -1
  3. package/dist/EngineBaseClient.d.cts +2 -3
  4. package/dist/EngineBaseClient.d.ts +2 -3
  5. package/dist/EngineBaseClient.js +7 -5
  6. package/dist/EngineBaseClient.js.map +1 -1
  7. package/dist/EngineClient.d.cts +1 -2
  8. package/dist/EngineClient.d.ts +1 -2
  9. package/dist/EngineExecuteBuilder.cjs +25 -50
  10. package/dist/EngineExecuteBuilder.cjs.map +1 -1
  11. package/dist/EngineExecuteBuilder.d.cts +6 -17
  12. package/dist/EngineExecuteBuilder.d.ts +6 -17
  13. package/dist/EngineExecuteBuilder.js +15 -40
  14. package/dist/EngineExecuteBuilder.js.map +1 -1
  15. package/dist/EngineExecuteClient.cjs +5 -9
  16. package/dist/EngineExecuteClient.cjs.map +1 -1
  17. package/dist/EngineExecuteClient.d.cts +3 -4
  18. package/dist/EngineExecuteClient.d.ts +3 -4
  19. package/dist/EngineExecuteClient.js +5 -9
  20. package/dist/EngineExecuteClient.js.map +1 -1
  21. package/dist/EngineQueryClient.cjs +70 -53
  22. package/dist/EngineQueryClient.cjs.map +1 -1
  23. package/dist/EngineQueryClient.d.cts +17 -12
  24. package/dist/EngineQueryClient.d.ts +17 -12
  25. package/dist/EngineQueryClient.js +50 -31
  26. package/dist/EngineQueryClient.js.map +1 -1
  27. package/dist/EngineWebClient.cjs +0 -2
  28. package/dist/EngineWebClient.cjs.map +1 -1
  29. package/dist/EngineWebClient.d.cts +1 -2
  30. package/dist/EngineWebClient.d.ts +1 -2
  31. package/dist/EngineWebClient.js +0 -2
  32. package/dist/EngineWebClient.js.map +1 -1
  33. package/dist/endpoints.cjs +6 -6
  34. package/dist/endpoints.cjs.map +1 -1
  35. package/dist/endpoints.d.cts +1 -1
  36. package/dist/endpoints.d.ts +1 -1
  37. package/dist/endpoints.js +6 -6
  38. package/dist/endpoints.js.map +1 -1
  39. package/dist/index.cjs +4 -4
  40. package/dist/index.cjs.map +1 -1
  41. package/dist/index.d.cts +11 -12
  42. package/dist/index.d.ts +11 -12
  43. package/dist/index.js +2 -2
  44. package/dist/index.js.map +1 -1
  45. package/dist/types/EngineServerFailureError.cjs +1 -1
  46. package/dist/types/EngineServerFailureError.cjs.map +1 -1
  47. package/dist/types/EngineServerFailureError.d.cts +2 -2
  48. package/dist/types/EngineServerFailureError.d.ts +2 -2
  49. package/dist/types/EngineServerFailureError.js +1 -1
  50. package/dist/types/EngineServerFailureError.js.map +1 -1
  51. package/dist/types/clientExecuteTypes.cjs.map +1 -1
  52. package/dist/types/clientExecuteTypes.d.cts +11 -12
  53. package/dist/types/clientExecuteTypes.d.ts +11 -12
  54. package/dist/types/clientQueryTypes.cjs.map +1 -1
  55. package/dist/types/clientQueryTypes.d.cts +41 -23
  56. package/dist/types/clientQueryTypes.d.ts +41 -23
  57. package/dist/types/index.cjs +10 -10
  58. package/dist/types/index.cjs.map +1 -1
  59. package/dist/types/index.d.cts +8 -9
  60. package/dist/types/index.d.ts +8 -9
  61. package/dist/types/index.js +5 -5
  62. package/dist/types/index.js.map +1 -1
  63. package/dist/types/serverExecuteTypes.cjs.map +1 -1
  64. package/dist/types/serverExecuteTypes.d.cts +13 -14
  65. package/dist/types/serverExecuteTypes.d.ts +13 -14
  66. package/dist/types/serverQueryModelTypes.cjs.map +1 -1
  67. package/dist/types/serverQueryModelTypes.d.cts +25 -2
  68. package/dist/types/serverQueryModelTypes.d.ts +25 -2
  69. package/dist/types/serverQueryTypes.cjs.map +1 -1
  70. package/dist/types/serverQueryTypes.d.cts +37 -26
  71. package/dist/types/serverQueryTypes.d.ts +37 -26
  72. package/dist/types/serverSubscriptionEventTypes.cjs.map +1 -1
  73. package/dist/types/serverSubscriptionEventTypes.d.cts +87 -23
  74. package/dist/types/serverSubscriptionEventTypes.d.ts +87 -23
  75. package/dist/types/serverSubscriptionTypes.cjs.map +1 -1
  76. package/dist/types/serverSubscriptionTypes.d.cts +21 -4
  77. package/dist/types/serverSubscriptionTypes.d.ts +21 -4
  78. package/dist/utils/index.d.cts +3 -4
  79. package/dist/utils/index.d.ts +3 -4
  80. package/dist/utils/productEngineTypeMappers.cjs +5 -5
  81. package/dist/utils/productEngineTypeMappers.cjs.map +1 -1
  82. package/dist/utils/productEngineTypeMappers.d.cts +1 -1
  83. package/dist/utils/productEngineTypeMappers.d.ts +1 -1
  84. package/dist/utils/productEngineTypeMappers.js +1 -1
  85. package/dist/utils/productEngineTypeMappers.js.map +1 -1
  86. package/dist/utils/queryDataMappers.cjs +113 -90
  87. package/dist/utils/queryDataMappers.cjs.map +1 -1
  88. package/dist/utils/queryDataMappers.d.cts +6 -5
  89. package/dist/utils/queryDataMappers.d.ts +6 -5
  90. package/dist/utils/queryDataMappers.js +39 -19
  91. package/dist/utils/queryDataMappers.js.map +1 -1
  92. package/package.json +3 -4
  93. package/src/EngineBaseClient.ts +5 -3
  94. package/src/EngineExecuteBuilder.ts +16 -53
  95. package/src/EngineExecuteClient.ts +5 -13
  96. package/src/EngineQueryClient.ts +62 -32
  97. package/src/EngineWebClient.ts +0 -2
  98. package/src/endpoints.ts +4 -5
  99. package/src/index.ts +2 -2
  100. package/src/types/EngineServerFailureError.ts +2 -2
  101. package/src/types/clientExecuteTypes.ts +12 -17
  102. package/src/types/clientQueryTypes.ts +57 -32
  103. package/src/types/index.ts +5 -5
  104. package/src/types/serverExecuteTypes.ts +14 -18
  105. package/src/types/serverQueryModelTypes.ts +26 -1
  106. package/src/types/serverQueryTypes.ts +46 -29
  107. package/src/types/serverSubscriptionEventTypes.ts +131 -21
  108. package/src/types/serverSubscriptionTypes.ts +23 -3
  109. package/src/utils/productEngineTypeMappers.ts +1 -1
  110. package/src/utils/queryDataMappers.ts +50 -20
@@ -1,8 +1,7 @@
1
- import { SpotMarket, PerpMarket, BalanceHealthContributions } from '@nadohq/contracts';
2
- import { EnginePriceTickLiquidity, EngineOrder, GetEngineSubaccountSummaryResponse, GetEngineIsolatedPositionsResponse, EngineSymbolsResponse, EngineSymbol, EngineMarketPrice } from '../types/clientQueryTypes.cjs';
3
- import { EngineServerPriceTickLiquidity, EngineServerOrderResponse, EngineServerSubaccountInfoResponse, EngineServerIsolatedPositionsResponse, EngineServerSymbolsResponse, EngineServerSymbol, EngineServerMarketPrice } from '../types/serverQueryTypes.cjs';
1
+ import { SpotMarket, PerpMarket, BalanceHealthContributions } from '@nadohq/shared';
2
+ import { EngineServerPriceTickLiquidity, EngineServerOrderResponse, EngineServerSubaccountInfoResponse, EngineServerIsolatedPositionsResponse, EngineServerSymbolsResponse, EngineServerSymbol, EngineServerMarketPrice, EngineServerNlpLockedBalancesResponse, EngineServerNlpPoolInfoResponse } from '../types/serverQueryTypes.cjs';
3
+ import { EnginePriceTickLiquidity, EngineOrder, GetEngineSubaccountSummaryResponse, GetEngineIsolatedPositionsResponse, EngineSymbolsResponse, EngineSymbol, EngineMarketPrice, GetEngineNlpLockedBalancesResponse, GetEngineNlpPoolInfoResponse } from '../types/clientQueryTypes.cjs';
4
4
  import { EngineServerSpotProduct, EngineServerPerpProduct } from '../types/serverQueryModelTypes.cjs';
5
- import '@nadohq/utils';
6
5
 
7
6
  declare function mapEngineServerTickLiquidity(tick: EngineServerPriceTickLiquidity): EnginePriceTickLiquidity;
8
7
  declare function mapEngineServerOrder(order: EngineServerOrderResponse): EngineOrder;
@@ -14,5 +13,7 @@ declare function mapEngineServerIsolatedPositions(baseResponse: EngineServerIsol
14
13
  declare function mapEngineServerSymbols(baseResponse: EngineServerSymbolsResponse): EngineSymbolsResponse;
15
14
  declare function mapEngineServerSymbol(engineServerSymbol: EngineServerSymbol): EngineSymbol;
16
15
  declare function mapEngineMarketPrice(baseResponse: EngineServerMarketPrice): EngineMarketPrice;
16
+ declare function mapEngineServerNlpLockedBalances(baseResponse: EngineServerNlpLockedBalancesResponse): GetEngineNlpLockedBalancesResponse;
17
+ declare function mapEngineServerNlpPoolInfo(baseResponse: EngineServerNlpPoolInfoResponse): GetEngineNlpPoolInfoResponse;
17
18
 
18
- export { mapEngineMarketPrice, mapEngineServerBalanceHealthContributions, mapEngineServerIsolatedPositions, mapEngineServerOrder, mapEngineServerPerpProduct, mapEngineServerSpotProduct, mapEngineServerSymbol, mapEngineServerSymbols, mapEngineServerTickLiquidity, mapSubaccountSummary };
19
+ export { mapEngineMarketPrice, mapEngineServerBalanceHealthContributions, mapEngineServerIsolatedPositions, mapEngineServerNlpLockedBalances, mapEngineServerNlpPoolInfo, mapEngineServerOrder, mapEngineServerPerpProduct, mapEngineServerSpotProduct, mapEngineServerSymbol, mapEngineServerSymbols, mapEngineServerTickLiquidity, mapSubaccountSummary };
@@ -1,8 +1,7 @@
1
- import { SpotMarket, PerpMarket, BalanceHealthContributions } from '@nadohq/contracts';
2
- import { EnginePriceTickLiquidity, EngineOrder, GetEngineSubaccountSummaryResponse, GetEngineIsolatedPositionsResponse, EngineSymbolsResponse, EngineSymbol, EngineMarketPrice } from '../types/clientQueryTypes.js';
3
- import { EngineServerPriceTickLiquidity, EngineServerOrderResponse, EngineServerSubaccountInfoResponse, EngineServerIsolatedPositionsResponse, EngineServerSymbolsResponse, EngineServerSymbol, EngineServerMarketPrice } from '../types/serverQueryTypes.js';
1
+ import { SpotMarket, PerpMarket, BalanceHealthContributions } from '@nadohq/shared';
2
+ import { EngineServerPriceTickLiquidity, EngineServerOrderResponse, EngineServerSubaccountInfoResponse, EngineServerIsolatedPositionsResponse, EngineServerSymbolsResponse, EngineServerSymbol, EngineServerMarketPrice, EngineServerNlpLockedBalancesResponse, EngineServerNlpPoolInfoResponse } from '../types/serverQueryTypes.js';
3
+ import { EnginePriceTickLiquidity, EngineOrder, GetEngineSubaccountSummaryResponse, GetEngineIsolatedPositionsResponse, EngineSymbolsResponse, EngineSymbol, EngineMarketPrice, GetEngineNlpLockedBalancesResponse, GetEngineNlpPoolInfoResponse } from '../types/clientQueryTypes.js';
4
4
  import { EngineServerSpotProduct, EngineServerPerpProduct } from '../types/serverQueryModelTypes.js';
5
- import '@nadohq/utils';
6
5
 
7
6
  declare function mapEngineServerTickLiquidity(tick: EngineServerPriceTickLiquidity): EnginePriceTickLiquidity;
8
7
  declare function mapEngineServerOrder(order: EngineServerOrderResponse): EngineOrder;
@@ -14,5 +13,7 @@ declare function mapEngineServerIsolatedPositions(baseResponse: EngineServerIsol
14
13
  declare function mapEngineServerSymbols(baseResponse: EngineServerSymbolsResponse): EngineSymbolsResponse;
15
14
  declare function mapEngineServerSymbol(engineServerSymbol: EngineServerSymbol): EngineSymbol;
16
15
  declare function mapEngineMarketPrice(baseResponse: EngineServerMarketPrice): EngineMarketPrice;
16
+ declare function mapEngineServerNlpLockedBalances(baseResponse: EngineServerNlpLockedBalancesResponse): GetEngineNlpLockedBalancesResponse;
17
+ declare function mapEngineServerNlpPoolInfo(baseResponse: EngineServerNlpPoolInfoResponse): GetEngineNlpPoolInfoResponse;
17
18
 
18
- export { mapEngineMarketPrice, mapEngineServerBalanceHealthContributions, mapEngineServerIsolatedPositions, mapEngineServerOrder, mapEngineServerPerpProduct, mapEngineServerSpotProduct, mapEngineServerSymbol, mapEngineServerSymbols, mapEngineServerTickLiquidity, mapSubaccountSummary };
19
+ export { mapEngineMarketPrice, mapEngineServerBalanceHealthContributions, mapEngineServerIsolatedPositions, mapEngineServerNlpLockedBalances, mapEngineServerNlpPoolInfo, mapEngineServerOrder, mapEngineServerPerpProduct, mapEngineServerSpotProduct, mapEngineServerSymbol, mapEngineServerSymbols, mapEngineServerTickLiquidity, mapSubaccountSummary };
@@ -2,15 +2,13 @@
2
2
  import {
3
3
  calcTotalBorrowed,
4
4
  calcTotalDeposited,
5
- ProductEngineType,
6
- subaccountFromHex
7
- } from "@nadohq/contracts";
8
- import {
9
5
  mapValues,
6
+ ProductEngineType,
10
7
  removeDecimals,
8
+ subaccountFromHex,
11
9
  toBigDecimal,
12
- toIntegerString
13
- } from "@nadohq/utils";
10
+ unpackOrderAppendix
11
+ } from "@nadohq/shared";
14
12
  import { mapEngineServerProductType } from "./productEngineTypeMappers.js";
15
13
  function mapEngineServerTickLiquidity(tick) {
16
14
  return {
@@ -22,7 +20,7 @@ function mapEngineServerOrder(order) {
22
20
  const subaccount = subaccountFromHex(order.sender);
23
21
  return {
24
22
  digest: order.digest,
25
- expiration: toBigDecimal(order.expiration),
23
+ expiration: Number(order.expiration),
26
24
  nonce: order.nonce,
27
25
  price: removeDecimals(order.price_x18),
28
26
  productId: order.product_id,
@@ -30,19 +28,8 @@ function mapEngineServerOrder(order) {
30
28
  subaccountName: subaccount.subaccountName,
31
29
  totalAmount: toBigDecimal(order.amount),
32
30
  unfilledAmount: toBigDecimal(order.unfilled_amount),
33
- margin: order.margin ? toBigDecimal(order.margin) : null,
34
- // Standardizes from hex
35
- // toFixed is required as toString gives values with `e`
36
- orderParams: {
37
- amount: toIntegerString(order.amount),
38
- expiration: toIntegerString(order.expiration),
39
- nonce: order.nonce,
40
- price: toIntegerString(removeDecimals(order.price_x18)),
41
- subaccountOwner: subaccount.subaccountOwner,
42
- subaccountName: subaccount.subaccountName
43
- },
44
31
  placementTime: order.placed_at,
45
- orderType: order.order_type
32
+ appendix: unpackOrderAppendix(order.appendix)
46
33
  };
47
34
  }
48
35
  function mapEngineServerSpotProduct(product) {
@@ -70,6 +57,7 @@ function mapEngineServerSpotProduct(product) {
70
57
  ),
71
58
  interestLargeCap: removeDecimals(product.config.interest_large_cap_x18),
72
59
  interestSmallCap: removeDecimals(product.config.interest_small_cap_x18),
60
+ minDepositRate: removeDecimals(product.config.min_deposit_rate_x18),
73
61
  longWeightInitial: removeDecimals(product.risk.long_weight_initial_x18),
74
62
  longWeightMaintenance: removeDecimals(
75
63
  product.risk.long_weight_maintenance_x18
@@ -243,10 +231,42 @@ function mapEngineMarketPrice(baseResponse) {
243
231
  productId: baseResponse.product_id
244
232
  };
245
233
  }
234
+ function mapEngineServerNlpLockedBalances(baseResponse) {
235
+ const lockedBalances = baseResponse.locked_balances.map((lockedBalance) => ({
236
+ productId: lockedBalance.balance.product_id,
237
+ balance: toBigDecimal(lockedBalance.balance.balance.amount),
238
+ unlockedAt: lockedBalance.unlocked_at
239
+ }));
240
+ return {
241
+ lockedBalances,
242
+ balanceLocked: {
243
+ productId: baseResponse.balance_locked.product_id,
244
+ balance: toBigDecimal(baseResponse.balance_locked.balance.amount)
245
+ },
246
+ balanceUnlocked: {
247
+ productId: baseResponse.balance_unlocked.product_id,
248
+ balance: toBigDecimal(baseResponse.balance_unlocked.balance.amount)
249
+ }
250
+ };
251
+ }
252
+ function mapEngineServerNlpPoolInfo(baseResponse) {
253
+ return {
254
+ nlpPools: baseResponse.nlp_pools.map((pool) => ({
255
+ poolId: pool.pool_id,
256
+ subaccountHex: pool.subaccount,
257
+ ownerAddress: pool.owner,
258
+ balanceWeight: removeDecimals(pool.balance_weight_x18),
259
+ subaccountInfo: mapSubaccountSummary(pool.subaccount_info),
260
+ openOrders: pool.open_orders.map(mapEngineServerOrder)
261
+ }))
262
+ };
263
+ }
246
264
  export {
247
265
  mapEngineMarketPrice,
248
266
  mapEngineServerBalanceHealthContributions,
249
267
  mapEngineServerIsolatedPositions,
268
+ mapEngineServerNlpLockedBalances,
269
+ mapEngineServerNlpPoolInfo,
250
270
  mapEngineServerOrder,
251
271
  mapEngineServerPerpProduct,
252
272
  mapEngineServerSpotProduct,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/queryDataMappers.ts"],"sourcesContent":["import {\n BalanceHealthContributions,\n calcTotalBorrowed,\n calcTotalDeposited,\n OrderExpirationType,\n PerpMarket,\n ProductEngineType,\n SpotMarket,\n subaccountFromHex,\n} from '@nadohq/contracts';\nimport {\n mapValues,\n removeDecimals,\n toBigDecimal,\n toIntegerString,\n} from '@nadohq/utils';\nimport {\n EngineMarketPrice,\n EngineOrder,\n EnginePriceTickLiquidity,\n EngineServerIsolatedPositionsResponse,\n EngineServerMarketPrice,\n EngineServerOrderResponse,\n EngineServerPerpProduct,\n EngineServerPriceTickLiquidity,\n EngineServerSpotProduct,\n EngineServerSubaccountInfoResponse,\n EngineServerSymbol,\n EngineServerSymbolsResponse,\n EngineSymbol,\n EngineSymbolsResponse,\n GetEngineIsolatedPositionsResponse,\n GetEngineSubaccountSummaryResponse,\n} from '../types';\nimport { mapEngineServerProductType } from './productEngineTypeMappers';\n\nexport function mapEngineServerTickLiquidity(\n tick: EngineServerPriceTickLiquidity,\n): EnginePriceTickLiquidity {\n return {\n price: removeDecimals(tick[0]),\n liquidity: toBigDecimal(tick[1]),\n };\n}\n\nexport function mapEngineServerOrder(\n order: EngineServerOrderResponse,\n): EngineOrder {\n const subaccount = subaccountFromHex(order.sender);\n return {\n digest: order.digest,\n expiration: toBigDecimal(order.expiration),\n nonce: order.nonce,\n price: removeDecimals(order.price_x18),\n productId: order.product_id,\n subaccountOwner: subaccount.subaccountOwner,\n subaccountName: subaccount.subaccountName,\n totalAmount: toBigDecimal(order.amount),\n unfilledAmount: toBigDecimal(order.unfilled_amount),\n margin: order.margin ? toBigDecimal(order.margin) : null,\n // Standardizes from hex\n // toFixed is required as toString gives values with `e`\n orderParams: {\n amount: toIntegerString(order.amount),\n expiration: toIntegerString(order.expiration),\n nonce: order.nonce,\n price: toIntegerString(removeDecimals(order.price_x18)),\n subaccountOwner: subaccount.subaccountOwner,\n subaccountName: subaccount.subaccountName,\n },\n placementTime: order.placed_at,\n orderType: order.order_type as OrderExpirationType,\n };\n}\n\nexport function mapEngineServerSpotProduct(\n product: EngineServerSpotProduct,\n): SpotMarket {\n return {\n type: ProductEngineType.SPOT,\n productId: product.product_id,\n minSize: toBigDecimal(product.book_info.min_size),\n priceIncrement: removeDecimals(product.book_info.price_increment_x18),\n sizeIncrement: toBigDecimal(product.book_info.size_increment),\n product: {\n productId: product.product_id,\n type: ProductEngineType.SPOT,\n totalBorrowed: calcTotalBorrowed(\n product.state.total_borrows_normalized,\n product.state.cumulative_borrows_multiplier_x18,\n ),\n totalDeposited: calcTotalDeposited(\n product.state.total_deposits_normalized,\n product.state.cumulative_deposits_multiplier_x18,\n ),\n oraclePrice: removeDecimals(product.oracle_price_x18),\n interestFloor: removeDecimals(product.config.interest_floor_x18),\n interestInflectionUtil: removeDecimals(\n product.config.interest_inflection_util_x18,\n ),\n interestLargeCap: removeDecimals(product.config.interest_large_cap_x18),\n interestSmallCap: removeDecimals(product.config.interest_small_cap_x18),\n longWeightInitial: removeDecimals(product.risk.long_weight_initial_x18),\n longWeightMaintenance: removeDecimals(\n product.risk.long_weight_maintenance_x18,\n ),\n shortWeightInitial: removeDecimals(product.risk.short_weight_initial_x18),\n shortWeightMaintenance: removeDecimals(\n product.risk.short_weight_maintenance_x18,\n ),\n tokenAddr: product.config.token,\n },\n };\n}\n\nexport function mapEngineServerPerpProduct(\n product: EngineServerPerpProduct,\n): PerpMarket {\n return {\n type: ProductEngineType.PERP,\n productId: product.product_id,\n minSize: toBigDecimal(product.book_info.min_size),\n priceIncrement: removeDecimals(product.book_info.price_increment_x18),\n sizeIncrement: toBigDecimal(product.book_info.size_increment),\n product: {\n productId: product.product_id,\n type: ProductEngineType.PERP,\n oraclePrice: removeDecimals(product.oracle_price_x18),\n longWeightInitial: removeDecimals(product.risk.long_weight_initial_x18),\n longWeightMaintenance: removeDecimals(\n product.risk.long_weight_maintenance_x18,\n ),\n shortWeightInitial: removeDecimals(product.risk.short_weight_initial_x18),\n shortWeightMaintenance: removeDecimals(\n product.risk.short_weight_maintenance_x18,\n ),\n openInterest: toBigDecimal(product.state.open_interest),\n cumulativeFundingLong: removeDecimals(\n product.state.cumulative_funding_long_x18,\n ),\n cumulativeFundingShort: removeDecimals(\n product.state.cumulative_funding_short_x18,\n ),\n },\n };\n}\n\nexport function mapEngineServerBalanceHealthContributions(\n healthContributionsForBalance: string[],\n): BalanceHealthContributions {\n return {\n initial: toBigDecimal(healthContributionsForBalance[0]),\n maintenance: toBigDecimal(healthContributionsForBalance[1]),\n unweighted: toBigDecimal(healthContributionsForBalance[2]),\n };\n}\n\nexport function mapSubaccountSummary(\n baseResponse: EngineServerSubaccountInfoResponse,\n): GetEngineSubaccountSummaryResponse {\n const balances: GetEngineSubaccountSummaryResponse['balances'] = [];\n\n baseResponse.spot_balances.forEach((spotBalance) => {\n const product = baseResponse.spot_products.find(\n (product) => product.product_id === spotBalance.product_id,\n );\n if (!product) {\n throw Error(`Could not find product ${spotBalance.product_id}`);\n }\n\n balances.push({\n amount: toBigDecimal(spotBalance.balance.amount),\n healthContributions: mapEngineServerBalanceHealthContributions(\n baseResponse.health_contributions[spotBalance.product_id],\n ),\n ...mapEngineServerSpotProduct(product).product,\n });\n });\n\n baseResponse.perp_balances.forEach((perpBalance) => {\n const product = baseResponse.perp_products.find(\n (product) => product.product_id === perpBalance.product_id,\n );\n if (!product) {\n throw Error(`Could not find product ${perpBalance.product_id}`);\n }\n\n balances.push({\n amount: toBigDecimal(perpBalance.balance.amount),\n vQuoteBalance: toBigDecimal(perpBalance.balance.v_quote_balance),\n healthContributions: mapEngineServerBalanceHealthContributions(\n baseResponse.health_contributions[perpBalance.product_id],\n ),\n ...mapEngineServerPerpProduct(product).product,\n });\n });\n\n return {\n balances: balances,\n exists: baseResponse.exists,\n health: {\n initial: {\n health: toBigDecimal(baseResponse.healths[0].health),\n assets: toBigDecimal(baseResponse.healths[0].assets),\n liabilities: toBigDecimal(baseResponse.healths[0].liabilities),\n },\n maintenance: {\n health: toBigDecimal(baseResponse.healths[1].health),\n assets: toBigDecimal(baseResponse.healths[1].assets),\n liabilities: toBigDecimal(baseResponse.healths[1].liabilities),\n },\n unweighted: {\n health: toBigDecimal(baseResponse.healths[2].health),\n assets: toBigDecimal(baseResponse.healths[2].assets),\n liabilities: toBigDecimal(baseResponse.healths[2].liabilities),\n },\n },\n };\n}\n\nexport function mapEngineServerIsolatedPositions(\n baseResponse: EngineServerIsolatedPositionsResponse,\n): GetEngineIsolatedPositionsResponse {\n return baseResponse.isolated_positions.map((position) => {\n const perpBalance = position.base_balance;\n const quoteBalance = position.quote_balance;\n\n return {\n subaccount: subaccountFromHex(position.subaccount),\n healths: {\n initial: toBigDecimal(position.healths[0].health),\n maintenance: toBigDecimal(position.healths[1].health),\n unweighted: toBigDecimal(position.healths[2].health),\n },\n baseBalance: {\n amount: toBigDecimal(perpBalance.balance.amount),\n vQuoteBalance: toBigDecimal(perpBalance.balance.v_quote_balance),\n // Health contributions === healths for an isolated position\n healthContributions: {\n initial: toBigDecimal(position.base_healths[0]),\n maintenance: toBigDecimal(position.base_healths[1]),\n unweighted: toBigDecimal(position.base_healths[2]),\n },\n ...mapEngineServerPerpProduct(position.base_product).product,\n },\n quoteBalance: {\n amount: toBigDecimal(quoteBalance.balance.amount),\n healthContributions: {\n initial: toBigDecimal(position.quote_healths[0]),\n maintenance: toBigDecimal(position.quote_healths[1]),\n unweighted: toBigDecimal(position.quote_healths[2]),\n },\n ...mapEngineServerSpotProduct(position.quote_product).product,\n },\n };\n });\n}\n\nexport function mapEngineServerSymbols(\n baseResponse: EngineServerSymbolsResponse,\n): EngineSymbolsResponse {\n const symbols: Record<string, EngineSymbol> = mapValues(\n baseResponse.symbols,\n mapEngineServerSymbol,\n );\n\n return {\n symbols,\n };\n}\n\nexport function mapEngineServerSymbol(\n engineServerSymbol: EngineServerSymbol,\n): EngineSymbol {\n return {\n type: mapEngineServerProductType(engineServerSymbol.type),\n productId: engineServerSymbol.product_id,\n symbol: engineServerSymbol.symbol,\n priceIncrement: removeDecimals(engineServerSymbol.price_increment_x18),\n sizeIncrement: toBigDecimal(engineServerSymbol.size_increment),\n minSize: toBigDecimal(engineServerSymbol.min_size),\n minDepth: removeDecimals(engineServerSymbol.min_depth_x18),\n maxSpreadRate: removeDecimals(engineServerSymbol.max_spread_rate_x18),\n makerFeeRate: removeDecimals(engineServerSymbol.maker_fee_rate_x18),\n takerFeeRate: removeDecimals(engineServerSymbol.taker_fee_rate_x18),\n longWeightInitial: removeDecimals(\n engineServerSymbol.long_weight_initial_x18,\n ),\n longWeightMaintenance: removeDecimals(\n engineServerSymbol.long_weight_maintenance_x18,\n ),\n };\n}\n\nexport function mapEngineMarketPrice(\n baseResponse: EngineServerMarketPrice,\n): EngineMarketPrice {\n return {\n ask: removeDecimals(baseResponse.ask_x18),\n bid: removeDecimals(baseResponse.bid_x18),\n productId: baseResponse.product_id,\n };\n}\n"],"mappings":";AAAA;AAAA,EAEE;AAAA,EACA;AAAA,EAGA;AAAA,EAEA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAmBP,SAAS,kCAAkC;AAEpC,SAAS,6BACd,MAC0B;AAC1B,SAAO;AAAA,IACL,OAAO,eAAe,KAAK,CAAC,CAAC;AAAA,IAC7B,WAAW,aAAa,KAAK,CAAC,CAAC;AAAA,EACjC;AACF;AAEO,SAAS,qBACd,OACa;AACb,QAAM,aAAa,kBAAkB,MAAM,MAAM;AACjD,SAAO;AAAA,IACL,QAAQ,MAAM;AAAA,IACd,YAAY,aAAa,MAAM,UAAU;AAAA,IACzC,OAAO,MAAM;AAAA,IACb,OAAO,eAAe,MAAM,SAAS;AAAA,IACrC,WAAW,MAAM;AAAA,IACjB,iBAAiB,WAAW;AAAA,IAC5B,gBAAgB,WAAW;AAAA,IAC3B,aAAa,aAAa,MAAM,MAAM;AAAA,IACtC,gBAAgB,aAAa,MAAM,eAAe;AAAA,IAClD,QAAQ,MAAM,SAAS,aAAa,MAAM,MAAM,IAAI;AAAA;AAAA;AAAA,IAGpD,aAAa;AAAA,MACX,QAAQ,gBAAgB,MAAM,MAAM;AAAA,MACpC,YAAY,gBAAgB,MAAM,UAAU;AAAA,MAC5C,OAAO,MAAM;AAAA,MACb,OAAO,gBAAgB,eAAe,MAAM,SAAS,CAAC;AAAA,MACtD,iBAAiB,WAAW;AAAA,MAC5B,gBAAgB,WAAW;AAAA,IAC7B;AAAA,IACA,eAAe,MAAM;AAA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ACjD,UAAU,eAAe,mBAAmB,aAAa;AAAA,IACzD,eAAe,eAAe,mBAAmB,mBAAmB;AAAA,IACpE,cAAc,eAAe,mBAAmB,kBAAkB;AAAA,IAClE,cAAc,eAAe,mBAAmB,kBAAkB;AAAA,IAClE,mBAAmB;AAAA,MACjB,mBAAmB;AAAA,IACrB;AAAA,IACA,uBAAuB;AAAA,MACrB,mBAAmB;AAAA,IACrB;AAAA,EACF;AACF;AAEO,SAAS,qBACd,cACmB;AACnB,SAAO;AAAA,IACL,KAAK,eAAe,aAAa,OAAO;AAAA,IACxC,KAAK,eAAe,aAAa,OAAO;AAAA,IACxC,WAAW,aAAa;AAAA,EAC1B;AACF;","names":["product"]}
1
+ {"version":3,"sources":["../../src/utils/queryDataMappers.ts"],"sourcesContent":["import {\n BalanceHealthContributions,\n calcTotalBorrowed,\n calcTotalDeposited,\n mapValues,\n PerpMarket,\n ProductEngineType,\n removeDecimals,\n SpotMarket,\n subaccountFromHex,\n toBigDecimal,\n unpackOrderAppendix,\n} from '@nadohq/shared';\nimport {\n EngineMarketPrice,\n EngineNlpLockedBalance,\n EngineOrder,\n EnginePriceTickLiquidity,\n EngineServerIsolatedPositionsResponse,\n EngineServerMarketPrice,\n EngineServerNlpLockedBalancesResponse,\n EngineServerNlpPoolInfoResponse,\n EngineServerOrderResponse,\n EngineServerPerpProduct,\n EngineServerPriceTickLiquidity,\n EngineServerSpotProduct,\n EngineServerSubaccountInfoResponse,\n EngineServerSymbol,\n EngineServerSymbolsResponse,\n EngineSymbol,\n EngineSymbolsResponse,\n GetEngineIsolatedPositionsResponse,\n GetEngineNlpLockedBalancesResponse,\n GetEngineNlpPoolInfoResponse,\n GetEngineSubaccountSummaryResponse,\n} from '../types';\nimport { mapEngineServerProductType } from './productEngineTypeMappers';\n\nexport function mapEngineServerTickLiquidity(\n tick: EngineServerPriceTickLiquidity,\n): EnginePriceTickLiquidity {\n return {\n price: removeDecimals(tick[0]),\n liquidity: toBigDecimal(tick[1]),\n };\n}\n\nexport function mapEngineServerOrder(\n order: EngineServerOrderResponse,\n): EngineOrder {\n const subaccount = subaccountFromHex(order.sender);\n return {\n digest: order.digest,\n expiration: Number(order.expiration),\n nonce: order.nonce,\n price: removeDecimals(order.price_x18),\n productId: order.product_id,\n subaccountOwner: subaccount.subaccountOwner,\n subaccountName: subaccount.subaccountName,\n totalAmount: toBigDecimal(order.amount),\n unfilledAmount: toBigDecimal(order.unfilled_amount),\n placementTime: order.placed_at,\n appendix: unpackOrderAppendix(order.appendix),\n };\n}\n\nexport function mapEngineServerSpotProduct(\n product: EngineServerSpotProduct,\n): SpotMarket {\n return {\n type: ProductEngineType.SPOT,\n productId: product.product_id,\n minSize: toBigDecimal(product.book_info.min_size),\n priceIncrement: removeDecimals(product.book_info.price_increment_x18),\n sizeIncrement: toBigDecimal(product.book_info.size_increment),\n product: {\n productId: product.product_id,\n type: ProductEngineType.SPOT,\n totalBorrowed: calcTotalBorrowed(\n product.state.total_borrows_normalized,\n product.state.cumulative_borrows_multiplier_x18,\n ),\n totalDeposited: calcTotalDeposited(\n product.state.total_deposits_normalized,\n product.state.cumulative_deposits_multiplier_x18,\n ),\n oraclePrice: removeDecimals(product.oracle_price_x18),\n interestFloor: removeDecimals(product.config.interest_floor_x18),\n interestInflectionUtil: removeDecimals(\n product.config.interest_inflection_util_x18,\n ),\n interestLargeCap: removeDecimals(product.config.interest_large_cap_x18),\n interestSmallCap: removeDecimals(product.config.interest_small_cap_x18),\n minDepositRate: removeDecimals(product.config.min_deposit_rate_x18),\n longWeightInitial: removeDecimals(product.risk.long_weight_initial_x18),\n longWeightMaintenance: removeDecimals(\n product.risk.long_weight_maintenance_x18,\n ),\n shortWeightInitial: removeDecimals(product.risk.short_weight_initial_x18),\n shortWeightMaintenance: removeDecimals(\n product.risk.short_weight_maintenance_x18,\n ),\n tokenAddr: product.config.token,\n },\n };\n}\n\nexport function mapEngineServerPerpProduct(\n product: EngineServerPerpProduct,\n): PerpMarket {\n return {\n type: ProductEngineType.PERP,\n productId: product.product_id,\n minSize: toBigDecimal(product.book_info.min_size),\n priceIncrement: removeDecimals(product.book_info.price_increment_x18),\n sizeIncrement: toBigDecimal(product.book_info.size_increment),\n product: {\n productId: product.product_id,\n type: ProductEngineType.PERP,\n oraclePrice: removeDecimals(product.oracle_price_x18),\n longWeightInitial: removeDecimals(product.risk.long_weight_initial_x18),\n longWeightMaintenance: removeDecimals(\n product.risk.long_weight_maintenance_x18,\n ),\n shortWeightInitial: removeDecimals(product.risk.short_weight_initial_x18),\n shortWeightMaintenance: removeDecimals(\n product.risk.short_weight_maintenance_x18,\n ),\n openInterest: toBigDecimal(product.state.open_interest),\n cumulativeFundingLong: removeDecimals(\n product.state.cumulative_funding_long_x18,\n ),\n cumulativeFundingShort: removeDecimals(\n product.state.cumulative_funding_short_x18,\n ),\n },\n };\n}\n\nexport function mapEngineServerBalanceHealthContributions(\n healthContributionsForBalance: string[],\n): BalanceHealthContributions {\n return {\n initial: toBigDecimal(healthContributionsForBalance[0]),\n maintenance: toBigDecimal(healthContributionsForBalance[1]),\n unweighted: toBigDecimal(healthContributionsForBalance[2]),\n };\n}\n\nexport function mapSubaccountSummary(\n baseResponse: EngineServerSubaccountInfoResponse,\n): GetEngineSubaccountSummaryResponse {\n const balances: GetEngineSubaccountSummaryResponse['balances'] = [];\n\n baseResponse.spot_balances.forEach((spotBalance) => {\n const product = baseResponse.spot_products.find(\n (product) => product.product_id === spotBalance.product_id,\n );\n if (!product) {\n throw Error(`Could not find product ${spotBalance.product_id}`);\n }\n\n balances.push({\n amount: toBigDecimal(spotBalance.balance.amount),\n healthContributions: mapEngineServerBalanceHealthContributions(\n baseResponse.health_contributions[spotBalance.product_id],\n ),\n ...mapEngineServerSpotProduct(product).product,\n });\n });\n\n baseResponse.perp_balances.forEach((perpBalance) => {\n const product = baseResponse.perp_products.find(\n (product) => product.product_id === perpBalance.product_id,\n );\n if (!product) {\n throw Error(`Could not find product ${perpBalance.product_id}`);\n }\n\n balances.push({\n amount: toBigDecimal(perpBalance.balance.amount),\n vQuoteBalance: toBigDecimal(perpBalance.balance.v_quote_balance),\n healthContributions: mapEngineServerBalanceHealthContributions(\n baseResponse.health_contributions[perpBalance.product_id],\n ),\n ...mapEngineServerPerpProduct(product).product,\n });\n });\n\n return {\n balances: balances,\n exists: baseResponse.exists,\n health: {\n initial: {\n health: toBigDecimal(baseResponse.healths[0].health),\n assets: toBigDecimal(baseResponse.healths[0].assets),\n liabilities: toBigDecimal(baseResponse.healths[0].liabilities),\n },\n maintenance: {\n health: toBigDecimal(baseResponse.healths[1].health),\n assets: toBigDecimal(baseResponse.healths[1].assets),\n liabilities: toBigDecimal(baseResponse.healths[1].liabilities),\n },\n unweighted: {\n health: toBigDecimal(baseResponse.healths[2].health),\n assets: toBigDecimal(baseResponse.healths[2].assets),\n liabilities: toBigDecimal(baseResponse.healths[2].liabilities),\n },\n },\n };\n}\n\nexport function mapEngineServerIsolatedPositions(\n baseResponse: EngineServerIsolatedPositionsResponse,\n): GetEngineIsolatedPositionsResponse {\n return baseResponse.isolated_positions.map((position) => {\n const perpBalance = position.base_balance;\n const quoteBalance = position.quote_balance;\n\n return {\n subaccount: subaccountFromHex(position.subaccount),\n healths: {\n initial: toBigDecimal(position.healths[0].health),\n maintenance: toBigDecimal(position.healths[1].health),\n unweighted: toBigDecimal(position.healths[2].health),\n },\n baseBalance: {\n amount: toBigDecimal(perpBalance.balance.amount),\n vQuoteBalance: toBigDecimal(perpBalance.balance.v_quote_balance),\n // Health contributions === healths for an isolated position\n healthContributions: {\n initial: toBigDecimal(position.base_healths[0]),\n maintenance: toBigDecimal(position.base_healths[1]),\n unweighted: toBigDecimal(position.base_healths[2]),\n },\n ...mapEngineServerPerpProduct(position.base_product).product,\n },\n quoteBalance: {\n amount: toBigDecimal(quoteBalance.balance.amount),\n healthContributions: {\n initial: toBigDecimal(position.quote_healths[0]),\n maintenance: toBigDecimal(position.quote_healths[1]),\n unweighted: toBigDecimal(position.quote_healths[2]),\n },\n ...mapEngineServerSpotProduct(position.quote_product).product,\n },\n };\n });\n}\n\nexport function mapEngineServerSymbols(\n baseResponse: EngineServerSymbolsResponse,\n): EngineSymbolsResponse {\n const symbols: Record<string, EngineSymbol> = mapValues(\n baseResponse.symbols,\n mapEngineServerSymbol,\n );\n\n return {\n symbols,\n };\n}\n\nexport function mapEngineServerSymbol(\n engineServerSymbol: EngineServerSymbol,\n): EngineSymbol {\n return {\n type: mapEngineServerProductType(engineServerSymbol.type),\n productId: engineServerSymbol.product_id,\n symbol: engineServerSymbol.symbol,\n priceIncrement: removeDecimals(engineServerSymbol.price_increment_x18),\n sizeIncrement: toBigDecimal(engineServerSymbol.size_increment),\n minSize: toBigDecimal(engineServerSymbol.min_size),\n minDepth: removeDecimals(engineServerSymbol.min_depth_x18),\n maxSpreadRate: removeDecimals(engineServerSymbol.max_spread_rate_x18),\n makerFeeRate: removeDecimals(engineServerSymbol.maker_fee_rate_x18),\n takerFeeRate: removeDecimals(engineServerSymbol.taker_fee_rate_x18),\n longWeightInitial: removeDecimals(\n engineServerSymbol.long_weight_initial_x18,\n ),\n longWeightMaintenance: removeDecimals(\n engineServerSymbol.long_weight_maintenance_x18,\n ),\n };\n}\n\nexport function mapEngineMarketPrice(\n baseResponse: EngineServerMarketPrice,\n): EngineMarketPrice {\n return {\n ask: removeDecimals(baseResponse.ask_x18),\n bid: removeDecimals(baseResponse.bid_x18),\n productId: baseResponse.product_id,\n };\n}\n\nexport function mapEngineServerNlpLockedBalances(\n baseResponse: EngineServerNlpLockedBalancesResponse,\n): GetEngineNlpLockedBalancesResponse {\n const lockedBalances: EngineNlpLockedBalance[] =\n baseResponse.locked_balances.map((lockedBalance) => ({\n productId: lockedBalance.balance.product_id,\n balance: toBigDecimal(lockedBalance.balance.balance.amount),\n unlockedAt: lockedBalance.unlocked_at,\n }));\n\n return {\n lockedBalances,\n balanceLocked: {\n productId: baseResponse.balance_locked.product_id,\n balance: toBigDecimal(baseResponse.balance_locked.balance.amount),\n },\n balanceUnlocked: {\n productId: baseResponse.balance_unlocked.product_id,\n balance: toBigDecimal(baseResponse.balance_unlocked.balance.amount),\n },\n };\n}\n\nexport function mapEngineServerNlpPoolInfo(\n baseResponse: EngineServerNlpPoolInfoResponse,\n): GetEngineNlpPoolInfoResponse {\n return {\n nlpPools: baseResponse.nlp_pools.map((pool) => ({\n poolId: pool.pool_id,\n subaccountHex: pool.subaccount,\n ownerAddress: pool.owner,\n balanceWeight: removeDecimals(pool.balance_weight_x18),\n subaccountInfo: mapSubaccountSummary(pool.subaccount_info),\n openOrders: pool.open_orders.map(mapEngineServerOrder),\n })),\n };\n}\n"],"mappings":";AAAA;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAwBP,SAAS,kCAAkC;AAEpC,SAAS,6BACd,MAC0B;AAC1B,SAAO;AAAA,IACL,OAAO,eAAe,KAAK,CAAC,CAAC;AAAA,IAC7B,WAAW,aAAa,KAAK,CAAC,CAAC;AAAA,EACjC;AACF;AAEO,SAAS,qBACd,OACa;AACb,QAAM,aAAa,kBAAkB,MAAM,MAAM;AACjD,SAAO;AAAA,IACL,QAAQ,MAAM;AAAA,IACd,YAAY,OAAO,MAAM,UAAU;AAAA,IACnC,OAAO,MAAM;AAAA,IACb,OAAO,eAAe,MAAM,SAAS;AAAA,IACrC,WAAW,MAAM;AAAA,IACjB,iBAAiB,WAAW;AAAA,IAC5B,gBAAgB,WAAW;AAAA,IAC3B,aAAa,aAAa,MAAM,MAAM;AAAA,IACtC,gBAAgB,aAAa,MAAM,eAAe;AAAA,IAClD,eAAe,MAAM;AAAA,IACrB,UAAU,oBAAoB,MAAM,QAAQ;AAAA,EAC9C;AACF;AAEO,SAAS,2BACd,SACY;AACZ,SAAO;AAAA,IACL,MAAM,kBAAkB;AAAA,IACxB,WAAW,QAAQ;AAAA,IACnB,SAAS,aAAa,QAAQ,UAAU,QAAQ;AAAA,IAChD,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eAAe,mBAAmB,kBAAkB;AAAA,IAClE,mBAAmB;AAAA,MACjB,mBAAmB;AAAA,IACrB;AAAA,IACA,uBAAuB;AAAA,MACrB,mBAAmB;AAAA,IACrB;AAAA,EACF;AACF;AAEO,SAAS,qBACd,cACmB;AACnB,SAAO;AAAA,IACL,KAAK,eAAe,aAAa,OAAO;AAAA,IACxC,KAAK,eAAe,aAAa,OAAO;AAAA,IACxC,WAAW,aAAa;AAAA,EAC1B;AACF;AAEO,SAAS,iCACd,cACoC;AACpC,QAAM,iBACJ,aAAa,gBAAgB,IAAI,CAAC,mBAAmB;AAAA,IACnD,WAAW,cAAc,QAAQ;AAAA,IACjC,SAAS,aAAa,cAAc,QAAQ,QAAQ,MAAM;AAAA,IAC1D,YAAY,cAAc;AAAA,EAC5B,EAAE;AAEJ,SAAO;AAAA,IACL;AAAA,IACA,eAAe;AAAA,MACb,WAAW,aAAa,eAAe;AAAA,MACvC,SAAS,aAAa,aAAa,eAAe,QAAQ,MAAM;AAAA,IAClE;AAAA,IACA,iBAAiB;AAAA,MACf,WAAW,aAAa,iBAAiB;AAAA,MACzC,SAAS,aAAa,aAAa,iBAAiB,QAAQ,MAAM;AAAA,IACpE;AAAA,EACF;AACF;AAEO,SAAS,2BACd,cAC8B;AAC9B,SAAO;AAAA,IACL,UAAU,aAAa,UAAU,IAAI,CAAC,UAAU;AAAA,MAC9C,QAAQ,KAAK;AAAA,MACb,eAAe,KAAK;AAAA,MACpB,cAAc,KAAK;AAAA,MACnB,eAAe,eAAe,KAAK,kBAAkB;AAAA,MACrD,gBAAgB,qBAAqB,KAAK,eAAe;AAAA,MACzD,YAAY,KAAK,YAAY,IAAI,oBAAoB;AAAA,IACvD,EAAE;AAAA,EACJ;AACF;","names":["product"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nadohq/engine-client",
3
- "version": "0.1.0-alpha.3",
3
+ "version": "0.1.0-alpha.30",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "description": "> TODO: description",
@@ -37,8 +37,7 @@
37
37
  }
38
38
  },
39
39
  "dependencies": {
40
- "@nadohq/contracts": "^0.1.0-alpha.3",
41
- "@nadohq/utils": "^0.1.0-alpha.3",
40
+ "@nadohq/shared": "^0.1.0-alpha.30",
42
41
  "axios": "*",
43
42
  "ts-mixer": "*"
44
43
  },
@@ -48,5 +47,5 @@
48
47
  "devDependencies": {
49
48
  "viem": "*"
50
49
  },
51
- "gitHead": "2bfcc344b596b7a33e9b8e4e3256a117de3fda04"
50
+ "gitHead": "f91906311b3dfc22e8e174d5ed8fa459ec812a08"
52
51
  }
@@ -3,8 +3,8 @@ import {
3
3
  SignableRequestType,
4
4
  SignableRequestTypeToParams,
5
5
  WalletClientWithAccount,
6
- } from '@nadohq/contracts';
7
- import { WalletNotProvidedError } from '@nadohq/utils';
6
+ WalletNotProvidedError,
7
+ } from '@nadohq/shared';
8
8
  import axios, { AxiosInstance, AxiosResponse } from 'axios';
9
9
  import {
10
10
  EngineServerExecuteRequestByType,
@@ -49,6 +49,8 @@ export class EngineBaseClient {
49
49
  this.opts = opts;
50
50
  this.axiosInstance = axios.create({
51
51
  withCredentials: true,
52
+ // We have custom logic to validate response status and create an appropriate error
53
+ validateStatus: () => true,
52
54
  });
53
55
  }
54
56
 
@@ -206,7 +208,7 @@ export class EngineBaseClient {
206
208
  private checkResponseStatus(response: AxiosResponse) {
207
209
  if (response.status !== 200 || !response.data) {
208
210
  throw Error(
209
- `Unexpected response from server: ${response.status} ${response.statusText}`,
211
+ `Unexpected response from server: ${response.status} ${response.statusText}. Data: ${response.data}`,
210
212
  );
211
213
  }
212
214
  }
@@ -1,15 +1,13 @@
1
1
  import {
2
- EIP712IsolatedOrderParams,
3
2
  EIP712OrderParams,
4
3
  getNadoEIP712Values,
5
4
  getOrderNonce,
6
5
  SignableRequestType,
7
6
  SignableRequestTypeToParams,
8
- } from '@nadohq/contracts';
7
+ } from '@nadohq/shared';
9
8
  import { EngineBaseClient } from './EngineBaseClient';
10
9
  import {
11
10
  EngineExecuteRequestParamsByType,
12
- EngineServerExecutePlaceIsolatedOrderPayload,
13
11
  EngineServerExecutePlaceOrderPayload,
14
12
  EngineServerExecuteRequestByType,
15
13
  SignatureParams,
@@ -89,7 +87,7 @@ export class EngineExecuteBuilder {
89
87
  const orderWithNonce = { ...clientParams.order, nonce };
90
88
 
91
89
  const signature = await this.getSignatureIfNeeded('place_order', {
92
- // Gets expected type
90
+ // Gets expected type (signature params from `clientParams` and order params from `orderWithNonce`)
93
91
  ...clientParams,
94
92
  ...orderWithNonce,
95
93
  });
@@ -126,63 +124,28 @@ export class EngineExecuteBuilder {
126
124
  order: orderEIP712Values,
127
125
  signature: clientParams.signature,
128
126
  spot_leverage: clientParams.spotLeverage ?? null,
127
+ borrow_margin: clientParams.borrowMargin ?? null,
129
128
  },
130
129
  orderParams: clientParams.order,
131
130
  };
132
131
  }
133
132
 
134
133
  /**
135
- * Builds server payload for the `place_isolated_order` execute action.
136
- *
137
- * @param clientParams Client PlaceIsolatedOrder params.
138
- * @returns `place_isolated_order` payload
134
+ * Builds server payload for the `place_orders` execute action.
135
+ * @param clientParams Client PlaceOrders params.
136
+ * @returns `place_orders` payload
139
137
  */
140
- async buildIsolatedPlaceOrderPayload(
141
- clientParams: EngineExecuteRequestParamsByType['place_isolated_order'],
142
- ): Promise<EngineServerExecutePlaceIsolatedOrderPayload> {
143
- const nonce = this.getOrderNonceIfNeeded(clientParams);
144
- const orderWithNonce = { ...clientParams.order, nonce };
145
-
146
- const signature = await this.getSignatureIfNeeded('place_isolated_order', {
147
- // Gets expected type
148
- ...clientParams,
149
- ...orderWithNonce,
150
- });
151
-
152
- return this.buildPlaceIsolatedOrderPayloadSync({
153
- ...clientParams,
154
- order: orderWithNonce,
155
- signature,
156
- });
157
- }
158
-
159
- /**
160
- * Synchronously builds server payload for the `place_isolated_order` execute action.
161
- *
162
- * @param clientParams Client PlaceIsolatedOrder params.
163
- * @returns `place_isolated_order` payload
164
- */
165
- buildPlaceIsolatedOrderPayloadSync(
166
- clientParams: WithSignature<
167
- EngineExecuteRequestParamsByType['place_isolated_order'] & {
168
- order: EIP712IsolatedOrderParams;
169
- }
170
- >,
171
- ): EngineServerExecutePlaceIsolatedOrderPayload {
172
- const isolatedOrderEIP712Values = getNadoEIP712Values(
173
- 'place_isolated_order',
174
- clientParams.order,
175
- );
176
-
138
+ async buildPlaceOrdersPayload(
139
+ clientParams: EngineExecuteRequestParamsByType['place_orders'],
140
+ ): Promise<EngineServerExecuteRequestByType['place_orders']> {
177
141
  return {
178
- payload: {
179
- id: clientParams.id ?? null,
180
- product_id: clientParams.productId,
181
- isolated_order: isolatedOrderEIP712Values,
182
- signature: clientParams.signature,
183
- borrow_margin: clientParams.borrowMargin ?? null,
184
- },
185
- orderParams: clientParams.order,
142
+ orders: await Promise.all(
143
+ clientParams.orders.map(async (orderParams) => {
144
+ const payload = await this.buildPlaceOrderPayload(orderParams);
145
+ return payload.payload;
146
+ }),
147
+ ),
148
+ cancel_on_failure: clientParams.cancelOnFailure ?? null,
186
149
  };
187
150
  }
188
151
 
@@ -2,7 +2,6 @@ import { EngineBaseClient, EngineClientOpts } from './EngineBaseClient';
2
2
  import { EngineExecuteBuilder } from './EngineExecuteBuilder';
3
3
  import {
4
4
  EngineExecuteRequestParamsByType,
5
- EnginePlaceIsolatedOrderResult,
6
5
  EnginePlaceOrderResult,
7
6
  } from './types';
8
7
 
@@ -43,18 +42,11 @@ export class EngineExecuteClient extends EngineBaseClient {
43
42
  };
44
43
  }
45
44
 
46
- async placeIsolatedOrder(
47
- params: EngineExecuteRequestParamsByType['place_isolated_order'],
48
- ): Promise<EnginePlaceIsolatedOrderResult> {
49
- const placeOrderPayload =
50
- await this.payloadBuilder.buildIsolatedPlaceOrderPayload(params);
51
- return {
52
- ...(await this.execute(
53
- 'place_isolated_order',
54
- placeOrderPayload.payload,
55
- )),
56
- orderParams: placeOrderPayload.orderParams,
57
- };
45
+ async placeOrders(params: EngineExecuteRequestParamsByType['place_orders']) {
46
+ return this.execute(
47
+ 'place_orders',
48
+ await this.payloadBuilder.buildPlaceOrdersPayload(params),
49
+ );
58
50
  }
59
51
 
60
52
  async cancelOrders(
@@ -1,16 +1,15 @@
1
- import {
2
- encodeSignedOrder,
3
- MarketWithProduct,
4
- subaccountToHex,
5
- } from '@nadohq/contracts';
6
1
  import {
7
2
  addDecimals,
8
3
  BigDecimal,
4
+ encodeSignedOrder,
5
+ getOrderVerifyingAddress,
9
6
  mapValues,
7
+ MarketWithProduct,
10
8
  removeDecimals,
9
+ subaccountToHex,
11
10
  toBigDecimal,
12
11
  toIntegerString,
13
- } from '@nadohq/utils';
12
+ } from '@nadohq/shared';
14
13
  import { EngineBaseClient } from './EngineBaseClient';
15
14
  import {
16
15
  EngineServerStatusResponse,
@@ -31,13 +30,17 @@ import {
31
30
  GetEngineMarketPriceResponse,
32
31
  GetEngineMarketPricesParams,
33
32
  GetEngineMarketPricesResponse,
33
+ GetEngineMaxBurnNlpAmountParams,
34
+ GetEngineMaxBurnNlpAmountResponse,
34
35
  GetEngineMaxMintNlpAmountParams,
35
36
  GetEngineMaxMintNlpAmountResponse,
36
37
  GetEngineMaxOrderSizeParams,
37
38
  GetEngineMaxOrderSizeResponse,
38
39
  GetEngineMaxWithdrawableParams,
39
40
  GetEngineMaxWithdrawableResponse,
40
- GetEngineMinDepositRatesResponse,
41
+ GetEngineNlpLockedBalancesParams,
42
+ GetEngineNlpLockedBalancesResponse,
43
+ GetEngineNlpPoolInfoResponse,
41
44
  GetEngineOrderParams,
42
45
  GetEngineOrderResponse,
43
46
  GetEngineSubaccountFeeRatesParams,
@@ -58,6 +61,8 @@ import { mapProductEngineType } from './utils/productEngineTypeMappers';
58
61
  import {
59
62
  mapEngineMarketPrice,
60
63
  mapEngineServerIsolatedPositions,
64
+ mapEngineServerNlpLockedBalances,
65
+ mapEngineServerNlpPoolInfo,
61
66
  mapEngineServerOrder,
62
67
  mapEngineServerPerpProduct,
63
68
  mapEngineServerSpotProduct,
@@ -75,7 +80,6 @@ export class EngineQueryClient extends EngineBaseClient {
75
80
  return {
76
81
  chainId: Number(baseResponse.chain_id),
77
82
  endpointAddr: baseResponse.endpoint_addr,
78
- orderbookAddrs: baseResponse.book_addrs,
79
83
  };
80
84
  }
81
85
 
@@ -241,22 +245,6 @@ export class EngineQueryClient extends EngineBaseClient {
241
245
  };
242
246
  }
243
247
 
244
- /**
245
- * Retrieves min deposit rates for all spot products from the engine
246
- */
247
- async getMinDepositRates(): Promise<GetEngineMinDepositRatesResponse> {
248
- const baseResponse = await this.query('min_deposit_rates', {});
249
-
250
- return {
251
- minDepositRates: mapValues(baseResponse.min_deposit_rates, (m) => {
252
- return {
253
- productId: m.product_id,
254
- minDepositRate: removeDecimals(m.min_deposit_rate_x18),
255
- };
256
- }),
257
- };
258
- }
259
-
260
248
  /**
261
249
  * Retrieves an order from the offchain engine
262
250
  *
@@ -285,7 +273,7 @@ export class EngineQueryClient extends EngineBaseClient {
285
273
  order: params.order,
286
274
  signature: await this.sign(
287
275
  'place_order',
288
- params.orderbookAddr,
276
+ getOrderVerifyingAddress(params.productId),
289
277
  params.chainId,
290
278
  params.order,
291
279
  ),
@@ -400,6 +388,7 @@ export class EngineQueryClient extends EngineBaseClient {
400
388
  },
401
389
  {} as Record<number, BigDecimal>,
402
390
  ),
391
+ feeTier: baseResponse.fee_tier,
403
392
  };
404
393
  }
405
394
 
@@ -463,9 +452,16 @@ export class EngineQueryClient extends EngineBaseClient {
463
452
  subaccountOwner: params.subaccountOwner,
464
453
  subaccountName: params.subaccountName,
465
454
  }),
455
+ // Backend expects string variants of booleans
466
456
  spot_leverage:
467
457
  params.spotLeverage != null ? String(params.spotLeverage) : null,
468
458
  reduce_only: params.reduceOnly != null ? String(params.reduceOnly) : null,
459
+ isolated: params.isolated != null ? String(params.isolated) : null,
460
+ borrow_margin:
461
+ // This field is only relevant for isolated orders
462
+ params.isolated && params.isoBorrowMargin != null
463
+ ? String(params.isoBorrowMargin)
464
+ : null,
469
465
  });
470
466
 
471
467
  return toBigDecimal(baseResponse.max_order_size);
@@ -511,6 +507,24 @@ export class EngineQueryClient extends EngineBaseClient {
511
507
  return toBigDecimal(baseResponse.max_quote_amount);
512
508
  }
513
509
 
510
+ /**
511
+ * Retrieves the max amount of NLP that can be burned.
512
+ *
513
+ * @param params
514
+ */
515
+ async getMaxBurnNlpAmount(
516
+ params: GetEngineMaxBurnNlpAmountParams,
517
+ ): Promise<GetEngineMaxBurnNlpAmountResponse> {
518
+ const baseResponse = await this.query('max_nlp_burnable', {
519
+ sender: subaccountToHex({
520
+ subaccountOwner: params.subaccountOwner,
521
+ subaccountName: params.subaccountName,
522
+ }),
523
+ });
524
+
525
+ return toBigDecimal(baseResponse.max_nlp_amount);
526
+ }
527
+
514
528
  /**
515
529
  * Gets the currently linked signer for the subaccount
516
530
  * @param params
@@ -532,7 +546,7 @@ export class EngineQueryClient extends EngineBaseClient {
532
546
  }
533
547
 
534
548
  /**
535
- * Gets the insurance funds in USDC.
549
+ * Gets the insurance funds in USDT.
536
550
  * @returns
537
551
  */
538
552
  public async getInsurance(): Promise<GetEngineInsuranceResponse> {
@@ -542,12 +556,28 @@ export class EngineQueryClient extends EngineBaseClient {
542
556
  }
543
557
 
544
558
  /**
545
- * Gets the orderbook contract address for a given product
546
- * @param productId
547
- * @returns
559
+ * Retrieves the NLP locked and unlocked balances for a subaccount.
560
+ *
561
+ * @param params
562
+ */
563
+ async getNlpLockedBalances(
564
+ params: GetEngineNlpLockedBalancesParams,
565
+ ): Promise<GetEngineNlpLockedBalancesResponse> {
566
+ const baseResponse = await this.query('nlp_locked_balances', {
567
+ subaccount: subaccountToHex({
568
+ subaccountOwner: params.subaccountOwner,
569
+ subaccountName: params.subaccountName,
570
+ }),
571
+ });
572
+
573
+ return mapEngineServerNlpLockedBalances(baseResponse);
574
+ }
575
+
576
+ /**
577
+ * Retrieves information about all NLP sub-pools
548
578
  */
549
- public async getOrderbookAddress(productId: number): Promise<string> {
550
- const contracts = await this.getContracts();
551
- return contracts.orderbookAddrs[productId];
579
+ async getNlpPoolInfo(): Promise<GetEngineNlpPoolInfoResponse> {
580
+ const baseResponse = await this.query('nlp_pool_info', {});
581
+ return mapEngineServerNlpPoolInfo(baseResponse);
552
582
  }
553
583
  }
@@ -18,8 +18,6 @@ export class EngineWebClient extends EngineBaseClient {
18
18
  this.axiosInstance
19
19
  // Use the /time endpoint and listen to 403 responses
20
20
  .get(`${this.opts.url}/ip`, {
21
- // Allow all statuses
22
- validateStatus: () => true,
23
21
  // IP checks go through Cloudflare, which uses allow-origin as *, so withCredentials needs to be false
24
22
  withCredentials: false,
25
23
  })
package/src/endpoints.ts CHANGED
@@ -1,21 +1,20 @@
1
- import { ChainEnv } from '@nadohq/contracts';
1
+ import { ChainEnv } from '@nadohq/shared';
2
2
 
3
3
  export const ENGINE_CLIENT_ENDPOINTS: Record<ChainEnv, string> = {
4
4
  local: 'http://localhost:80',
5
- arbitrumTestnet: 'https://gateway.sepolia-test.vertexprotocol.com/v1',
6
5
  arbitrum: 'https://gateway.prod.vertexprotocol.com/v1',
6
+ inkTestnet: 'https://gateway.test.nado-backend.xyz/v1',
7
7
  };
8
8
 
9
9
  export const ENGINE_WS_CLIENT_ENDPOINTS: Record<ChainEnv, string> = {
10
10
  local: 'ws://localhost:80',
11
- arbitrumTestnet: 'wss://gateway.sepolia-test.vertexprotocol.com/v1/ws',
12
11
  arbitrum: 'wss://gateway.prod.vertexprotocol.com/v1/ws',
12
+ inkTestnet: 'wss://gateway.test.nado-backend.xyz/v1/ws',
13
13
  };
14
14
 
15
15
  export const ENGINE_WS_SUBSCRIPTION_CLIENT_ENDPOINTS: Record<ChainEnv, string> =
16
16
  {
17
17
  local: 'ws://localhost:80',
18
- arbitrumTestnet:
19
- 'wss://gateway.sepolia-test.vertexprotocol.com/v1/subscribe',
20
18
  arbitrum: 'wss://gateway.prod.vertexprotocol.com/v1/subscribe',
19
+ inkTestnet: 'wss://gateway.test.nado-backend.xyz/v1/subscribe',
21
20
  };
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- export * from './types';
2
- export * from './EngineClient';
3
1
  export * from './endpoints';
2
+ export * from './EngineClient';
3
+ export * from './types';
4
4
  export * from './utils';
@@ -1,5 +1,5 @@
1
- import { EngineServerQueryFailureResponse } from './serverQueryTypes';
2
1
  import { EngineServerExecuteFailureResult } from './serverExecuteTypes';
2
+ import { EngineServerQueryFailureResponse } from './serverQueryTypes';
3
3
 
4
4
  export class EngineServerFailureError extends Error {
5
5
  constructor(
@@ -7,6 +7,6 @@ export class EngineServerFailureError extends Error {
7
7
  | EngineServerQueryFailureResponse
8
8
  | EngineServerExecuteFailureResult,
9
9
  ) {
10
- super();
10
+ super(`${responseData.error_code}: ${responseData.error}`);
11
11
  }
12
12
  }