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

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 (94) hide show
  1. package/dist/EngineBaseClient.cjs +8 -7
  2. package/dist/EngineBaseClient.cjs.map +1 -1
  3. package/dist/EngineBaseClient.d.cts +1 -2
  4. package/dist/EngineBaseClient.d.ts +1 -2
  5. package/dist/EngineBaseClient.js +7 -5
  6. package/dist/EngineBaseClient.js.map +1 -1
  7. package/dist/EngineClient.d.cts +1 -2
  8. package/dist/EngineClient.d.ts +1 -2
  9. package/dist/EngineExecuteBuilder.cjs +23 -51
  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 +13 -41
  14. package/dist/EngineExecuteBuilder.js.map +1 -1
  15. package/dist/EngineExecuteClient.cjs +6 -10
  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 +6 -10
  20. package/dist/EngineExecuteClient.js.map +1 -1
  21. package/dist/EngineQueryClient.cjs +28 -53
  22. package/dist/EngineQueryClient.cjs.map +1 -1
  23. package/dist/EngineQueryClient.d.cts +2 -13
  24. package/dist/EngineQueryClient.d.ts +2 -13
  25. package/dist/EngineQueryClient.js +6 -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.d.cts +5 -6
  40. package/dist/index.d.ts +5 -6
  41. package/dist/types/EngineServerFailureError.cjs +1 -1
  42. package/dist/types/EngineServerFailureError.cjs.map +1 -1
  43. package/dist/types/EngineServerFailureError.d.cts +2 -2
  44. package/dist/types/EngineServerFailureError.d.ts +2 -2
  45. package/dist/types/EngineServerFailureError.js +1 -1
  46. package/dist/types/EngineServerFailureError.js.map +1 -1
  47. package/dist/types/clientExecuteTypes.cjs.map +1 -1
  48. package/dist/types/clientExecuteTypes.d.cts +4 -12
  49. package/dist/types/clientExecuteTypes.d.ts +4 -12
  50. package/dist/types/clientQueryTypes.cjs.map +1 -1
  51. package/dist/types/clientQueryTypes.d.cts +12 -23
  52. package/dist/types/clientQueryTypes.d.ts +12 -23
  53. package/dist/types/index.d.cts +5 -6
  54. package/dist/types/index.d.ts +5 -6
  55. package/dist/types/serverExecuteTypes.cjs.map +1 -1
  56. package/dist/types/serverExecuteTypes.d.cts +6 -14
  57. package/dist/types/serverExecuteTypes.d.ts +6 -14
  58. package/dist/types/serverQueryModelTypes.cjs.map +1 -1
  59. package/dist/types/serverQueryModelTypes.d.cts +1 -1
  60. package/dist/types/serverQueryModelTypes.d.ts +1 -1
  61. package/dist/types/serverQueryTypes.cjs.map +1 -1
  62. package/dist/types/serverQueryTypes.d.cts +3 -13
  63. package/dist/types/serverQueryTypes.d.ts +3 -13
  64. package/dist/types/serverSubscriptionEventTypes.d.cts +1 -1
  65. package/dist/types/serverSubscriptionEventTypes.d.ts +1 -1
  66. package/dist/utils/index.d.cts +1 -2
  67. package/dist/utils/index.d.ts +1 -2
  68. package/dist/utils/productEngineTypeMappers.cjs +5 -5
  69. package/dist/utils/productEngineTypeMappers.cjs.map +1 -1
  70. package/dist/utils/productEngineTypeMappers.d.cts +1 -1
  71. package/dist/utils/productEngineTypeMappers.d.ts +1 -1
  72. package/dist/utils/productEngineTypeMappers.js +1 -1
  73. package/dist/utils/productEngineTypeMappers.js.map +1 -1
  74. package/dist/utils/queryDataMappers.cjs +79 -90
  75. package/dist/utils/queryDataMappers.cjs.map +1 -1
  76. package/dist/utils/queryDataMappers.d.cts +1 -2
  77. package/dist/utils/queryDataMappers.d.ts +1 -2
  78. package/dist/utils/queryDataMappers.js +7 -19
  79. package/dist/utils/queryDataMappers.js.map +1 -1
  80. package/package.json +3 -4
  81. package/src/EngineBaseClient.ts +5 -3
  82. package/src/EngineExecuteBuilder.ts +14 -54
  83. package/src/EngineExecuteClient.ts +7 -15
  84. package/src/EngineQueryClient.ts +6 -35
  85. package/src/EngineWebClient.ts +0 -2
  86. package/src/endpoints.ts +4 -5
  87. package/src/types/EngineServerFailureError.ts +2 -2
  88. package/src/types/clientExecuteTypes.ts +5 -17
  89. package/src/types/clientQueryTypes.ts +18 -32
  90. package/src/types/serverExecuteTypes.ts +7 -18
  91. package/src/types/serverQueryModelTypes.ts +1 -1
  92. package/src/types/serverQueryTypes.ts +2 -16
  93. package/src/utils/productEngineTypeMappers.ts +1 -1
  94. package/src/utils/queryDataMappers.ts +7 -20
@@ -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 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,IACpE,kBAAc,6BAAe,mBAAmB,kBAAkB;AAAA,IAClE,kBAAc,6BAAe,mBAAmB,kBAAkB;AAAA,IAClE,uBAAmB;AAAA,MACjB,mBAAmB;AAAA,IACrB;AAAA,IACA,2BAAuB;AAAA,MACrB,mBAAmB;AAAA,IACrB;AAAA,EACF;AACF;AAEO,SAAS,qBACd,cACmB;AACnB,SAAO;AAAA,IACL,SAAK,6BAAe,aAAa,OAAO;AAAA,IACxC,SAAK,6BAAe,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 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: 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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAYO;AAmBP,sCAA2C;AAEpC,SAAS,6BACd,MAC0B;AAC1B,SAAO;AAAA,IACL,WAAO,8BAAe,KAAK,CAAC,CAAC;AAAA,IAC7B,eAAW,4BAAa,KAAK,CAAC,CAAC;AAAA,EACjC;AACF;AAEO,SAAS,qBACd,OACa;AACb,QAAM,iBAAa,iCAAkB,MAAM,MAAM;AACjD,SAAO;AAAA,IACL,QAAQ,MAAM;AAAA,IACd,YAAY,OAAO,MAAM,UAAU;AAAA,IACnC,OAAO,MAAM;AAAA,IACb,WAAO,8BAAe,MAAM,SAAS;AAAA,IACrC,WAAW,MAAM;AAAA,IACjB,iBAAiB,W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,IACL;AAAA,EACF;AACF;AAEO,SAAS,sBACd,oBACc;AACd,SAAO;AAAA,IACL,UAAM,4DAA2B,mBAAmB,IAAI;AAAA,IACxD,WAAW,mBAAmB;AAAA,IAC9B,QAAQ,mBAAmB;AAAA,IAC3B,oBAAgB,8BAAe,mBAAmB,mBAAmB;AAAA,IACrE,mBAAe,4BAAa,mBAAmB,cAAc;AAAA,IAC7D,aAAS,4BAAa,mBAAmB,QAAQ;AAAA,IACjD,cAAU,8BAAe,mBAAmB,aAAa;AAAA,IACzD,mBAAe,8BAAe,mBAAmB,mBAAmB;AAAA,IACpE,kBAAc,8BAAe,mBAAmB,kBAAkB;AAAA,IAClE,kBAAc,8BAAe,mBAAmB,kBAAkB;AAAA,IAClE,uBAAmB;AAAA,MACjB,mBAAmB;AAAA,IACrB;AAAA,IACA,2BAAuB;AAAA,MACrB,mBAAmB;AAAA,IACrB;AAAA,EACF;AACF;AAEO,SAAS,qBACd,cACmB;AACnB,SAAO;AAAA,IACL,SAAK,8BAAe,aAAa,OAAO;AAAA,IACxC,SAAK,8BAAe,aAAa,OAAO;AAAA,IACxC,WAAW,aAAa;AAAA,EAC1B;AACF;","names":["product"]}
@@ -1,8 +1,7 @@
1
- import { SpotMarket, PerpMarket, BalanceHealthContributions } from '@nadohq/contracts';
1
+ import { SpotMarket, PerpMarket, BalanceHealthContributions } from '@nadohq/shared';
2
2
  import { EnginePriceTickLiquidity, EngineOrder, GetEngineSubaccountSummaryResponse, GetEngineIsolatedPositionsResponse, EngineSymbolsResponse, EngineSymbol, EngineMarketPrice } from '../types/clientQueryTypes.cjs';
3
3
  import { EngineServerPriceTickLiquidity, EngineServerOrderResponse, EngineServerSubaccountInfoResponse, EngineServerIsolatedPositionsResponse, EngineServerSymbolsResponse, EngineServerSymbol, EngineServerMarketPrice } from '../types/serverQueryTypes.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;
@@ -1,8 +1,7 @@
1
- import { SpotMarket, PerpMarket, BalanceHealthContributions } from '@nadohq/contracts';
1
+ import { SpotMarket, PerpMarket, BalanceHealthContributions } from '@nadohq/shared';
2
2
  import { EnginePriceTickLiquidity, EngineOrder, GetEngineSubaccountSummaryResponse, GetEngineIsolatedPositionsResponse, EngineSymbolsResponse, EngineSymbol, EngineMarketPrice } from '../types/clientQueryTypes.js';
3
3
  import { EngineServerPriceTickLiquidity, EngineServerOrderResponse, EngineServerSubaccountInfoResponse, EngineServerIsolatedPositionsResponse, EngineServerSymbolsResponse, EngineServerSymbol, EngineServerMarketPrice } from '../types/serverQueryTypes.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;
@@ -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
@@ -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;AAAA,IACrB,WAAW,MAAM;AAAA,EACnB;AACF;AAEO,SAAS,2BACd,SACY;AACZ,SAAO;AAAA,IACL,MAAM,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,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 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: 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"],"mappings":";AAAA;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EAEA;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,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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,mBAAmB;AAAA,IAC9B,QAAQ,mBAAmB;AAAA,IAC3B,gBAAgB,eAAe,mBAAmB,mBAAmB;AAAA,IACrE,eAAe,aAAa,mBAAmB,cAAc;AAAA,IAC7D,SAAS,aAAa,mBAAmB,QAAQ;AAAA,IACjD,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"]}
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.5",
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.5",
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": "de119d61db2be44b2cab79b8d373b66eb0f8ffe6"
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,64 +124,26 @@ 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
139
- */
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
134
+ * Builds server payload for the `place_orders` execute action.
135
+ * @param clientParams Client PlaceOrders params.
136
+ * @returns `place_orders` payload
164
137
  */
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,
138
+ async buildPlaceOrdersPayload(
139
+ clientParams: EngineExecuteRequestParamsByType['place_orders'],
140
+ ): Promise<EngineServerExecuteRequestByType['place_orders']> {
141
+ return Promise.all(
142
+ clientParams.map(async (orderParams) => {
143
+ const payload = await this.buildPlaceOrderPayload(orderParams);
144
+ return payload.payload;
145
+ }),
175
146
  );
176
-
177
- 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,
186
- };
187
147
  }
188
148
 
189
149
  /**
@@ -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,20 +42,6 @@ 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
- };
58
- }
59
-
60
45
  async cancelOrders(
61
46
  params: EngineExecuteRequestParamsByType['cancel_orders'],
62
47
  ) {
@@ -119,4 +104,11 @@ export class EngineExecuteClient extends EngineBaseClient {
119
104
  await this.payloadBuilder.buildBurnNlpPayload(params),
120
105
  );
121
106
  }
107
+
108
+ async placeOrders(params: EngineExecuteRequestParamsByType['place_orders']) {
109
+ return this.execute(
110
+ 'place_orders',
111
+ await this.payloadBuilder.buildPlaceOrdersPayload(params),
112
+ );
113
+ }
122
114
  }
@@ -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,
@@ -37,7 +36,6 @@ import {
37
36
  GetEngineMaxOrderSizeResponse,
38
37
  GetEngineMaxWithdrawableParams,
39
38
  GetEngineMaxWithdrawableResponse,
40
- GetEngineMinDepositRatesResponse,
41
39
  GetEngineOrderParams,
42
40
  GetEngineOrderResponse,
43
41
  GetEngineSubaccountFeeRatesParams,
@@ -75,7 +73,6 @@ export class EngineQueryClient extends EngineBaseClient {
75
73
  return {
76
74
  chainId: Number(baseResponse.chain_id),
77
75
  endpointAddr: baseResponse.endpoint_addr,
78
- orderbookAddrs: baseResponse.book_addrs,
79
76
  };
80
77
  }
81
78
 
@@ -241,22 +238,6 @@ export class EngineQueryClient extends EngineBaseClient {
241
238
  };
242
239
  }
243
240
 
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
241
  /**
261
242
  * Retrieves an order from the offchain engine
262
243
  *
@@ -285,7 +266,7 @@ export class EngineQueryClient extends EngineBaseClient {
285
266
  order: params.order,
286
267
  signature: await this.sign(
287
268
  'place_order',
288
- params.orderbookAddr,
269
+ getOrderVerifyingAddress(params.productId),
289
270
  params.chainId,
290
271
  params.order,
291
272
  ),
@@ -540,14 +521,4 @@ export class EngineQueryClient extends EngineBaseClient {
540
521
 
541
522
  return toBigDecimal(baseResponse.insurance);
542
523
  }
543
-
544
- /**
545
- * Gets the orderbook contract address for a given product
546
- * @param productId
547
- * @returns
548
- */
549
- public async getOrderbookAddress(productId: number): Promise<string> {
550
- const contracts = await this.getContracts();
551
- return contracts.orderbookAddrs[productId];
552
- }
553
524
  }
@@ -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
  };
@@ -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
  }
@@ -2,14 +2,13 @@ import {
2
2
  EIP712BurnNlpParams,
3
3
  EIP712CancelOrdersParams,
4
4
  EIP712CancelProductOrdersParams,
5
- EIP712IsolatedOrderParams,
6
5
  EIP712LinkSignerParams,
7
6
  EIP712LiquidateSubaccountParams,
8
7
  EIP712MintNlpParams,
9
8
  EIP712OrderParams,
10
9
  EIP712TransferQuoteParams,
11
10
  EIP712WithdrawCollateralParams,
12
- } from '@nadohq/contracts';
11
+ } from '@nadohq/shared';
13
12
  import { EngineServerExecuteSuccessResult } from './serverExecuteTypes';
14
13
 
15
14
  /**
@@ -50,15 +49,7 @@ export type EnginePlaceOrderParams = WithBaseEngineExecuteParams<{
50
49
  order: EngineOrderParams;
51
50
  // If not given, engine defaults to true (leverage/borrow enabled)
52
51
  spotLeverage?: boolean;
53
- }>;
54
-
55
- export type EngineIsolatedOrderParams = WithoutNonce<EIP712IsolatedOrderParams>;
56
-
57
- export type EnginePlaceIsolatedOrderParams = WithBaseEngineExecuteParams<{
58
- id?: number;
59
- productId: number;
60
- order: EngineIsolatedOrderParams;
61
- // Whether the cross subaccount can borrow quote for the margin transfer into the isolated subaccount. If not given, engine defaults to true.
52
+ // For isolated orders, this specifies whether margin can be borrowed (i.e. whether the cross account can have a negative USDC balance)
62
53
  borrowMargin?: boolean;
63
54
  }>;
64
55
 
@@ -93,6 +84,8 @@ export type EngineMintNlpParams = WithBaseEngineExecuteParams<
93
84
  export type EngineBurnNlpParams =
94
85
  WithBaseEngineExecuteParams<EIP712BurnNlpParams>;
95
86
 
87
+ export type EnginePlaceOrdersParams = EnginePlaceOrderParams[];
88
+
96
89
  export interface EngineExecuteRequestParamsByType {
97
90
  burn_nlp: EngineBurnNlpParams;
98
91
  cancel_and_place: EngineCancelAndPlaceParams;
@@ -101,8 +94,8 @@ export interface EngineExecuteRequestParamsByType {
101
94
  link_signer: EngineLinkSignerParams;
102
95
  liquidate_subaccount: EngineLiquidateSubaccountParams;
103
96
  mint_nlp: EngineMintNlpParams;
104
- place_isolated_order: EnginePlaceIsolatedOrderParams;
105
97
  place_order: EnginePlaceOrderParams;
98
+ place_orders: EnginePlaceOrdersParams;
106
99
  transfer_quote: EngineTransferQuoteParams;
107
100
  withdraw_collateral: EngineWithdrawCollateralParams;
108
101
  }
@@ -111,8 +104,3 @@ export type EnginePlaceOrderResult =
111
104
  EngineServerExecuteSuccessResult<'place_order'> & {
112
105
  orderParams: EIP712OrderParams;
113
106
  };
114
-
115
- export type EnginePlaceIsolatedOrderResult =
116
- EngineServerExecuteSuccessResult<'place_isolated_order'> & {
117
- orderParams: EIP712IsolatedOrderParams;
118
- };