@nadohq/engine-client 0.1.0-alpha.2 → 0.1.0-alpha.20

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 +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 +62 -52
  22. package/dist/EngineQueryClient.cjs.map +1 -1
  23. package/dist/EngineQueryClient.d.cts +12 -11
  24. package/dist/EngineQueryClient.d.ts +12 -11
  25. package/dist/EngineQueryClient.js +41 -30
  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 +4 -12
  53. package/dist/types/clientExecuteTypes.d.ts +4 -12
  54. package/dist/types/clientQueryTypes.cjs.map +1 -1
  55. package/dist/types/clientQueryTypes.d.cts +30 -23
  56. package/dist/types/clientQueryTypes.d.ts +30 -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 +6 -14
  65. package/dist/types/serverExecuteTypes.d.ts +6 -14
  66. package/dist/types/serverQueryModelTypes.cjs.map +1 -1
  67. package/dist/types/serverQueryModelTypes.d.cts +1 -1
  68. package/dist/types/serverQueryModelTypes.d.ts +1 -1
  69. package/dist/types/serverQueryTypes.cjs.map +1 -1
  70. package/dist/types/serverQueryTypes.d.cts +33 -13
  71. package/dist/types/serverQueryTypes.d.ts +33 -13
  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 +99 -90
  87. package/dist/utils/queryDataMappers.cjs.map +1 -1
  88. package/dist/utils/queryDataMappers.d.cts +5 -5
  89. package/dist/utils/queryDataMappers.d.ts +5 -5
  90. package/dist/utils/queryDataMappers.js +26 -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 +14 -54
  95. package/src/EngineExecuteClient.ts +7 -15
  96. package/src/EngineQueryClient.ts +51 -31
  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 +5 -17
  102. package/src/types/clientQueryTypes.ts +44 -32
  103. package/src/types/index.ts +5 -5
  104. package/src/types/serverExecuteTypes.ts +7 -18
  105. package/src/types/serverQueryModelTypes.ts +1 -1
  106. package/src/types/serverQueryTypes.ts +40 -16
  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 +33 -20
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/EngineQueryClient.ts"],"sourcesContent":["import {\n encodeSignedOrder,\n MarketWithProduct,\n subaccountToHex,\n} from '@nadohq/contracts';\nimport {\n addDecimals,\n BigDecimal,\n mapValues,\n removeDecimals,\n toBigDecimal,\n toIntegerString,\n} from '@nadohq/utils';\nimport { EngineBaseClient } from './EngineBaseClient';\nimport {\n EngineServerStatusResponse,\n EngineServerSubaccountInfoQueryParams,\n EngineSymbolsResponse,\n GetEngineAllMarketsResponse,\n GetEngineContractsResponse,\n GetEngineEstimatedSubaccountSummaryParams,\n GetEngineHealthGroupsResponse,\n GetEngineInsuranceResponse,\n GetEngineIsolatedPositionsParams,\n GetEngineIsolatedPositionsResponse,\n GetEngineLinkedSignerParams,\n GetEngineLinkedSignerResponse,\n GetEngineMarketLiquidityParams,\n GetEngineMarketLiquidityResponse,\n GetEngineMarketPriceParams,\n GetEngineMarketPriceResponse,\n GetEngineMarketPricesParams,\n GetEngineMarketPricesResponse,\n GetEngineMaxMintNlpAmountParams,\n GetEngineMaxMintNlpAmountResponse,\n GetEngineMaxOrderSizeParams,\n GetEngineMaxOrderSizeResponse,\n GetEngineMaxWithdrawableParams,\n GetEngineMaxWithdrawableResponse,\n GetEngineMinDepositRatesResponse,\n GetEngineOrderParams,\n GetEngineOrderResponse,\n GetEngineSubaccountFeeRatesParams,\n GetEngineSubaccountFeeRatesResponse,\n GetEngineSubaccountOrdersParams,\n GetEngineSubaccountOrdersResponse,\n GetEngineSubaccountProductOrdersParams,\n GetEngineSubaccountProductOrdersResponse,\n GetEngineSubaccountSummaryParams,\n GetEngineSubaccountSummaryResponse,\n GetEngineSymbolsParams,\n SubaccountOrderFeeRates,\n ValidateEngineOrderParams,\n ValidateEngineOrderResponse,\n ValidateSignedEngineOrderParams,\n} from './types';\nimport { mapProductEngineType } from './utils/productEngineTypeMappers';\nimport {\n mapEngineMarketPrice,\n mapEngineServerIsolatedPositions,\n mapEngineServerOrder,\n mapEngineServerPerpProduct,\n mapEngineServerSpotProduct,\n mapEngineServerSymbols,\n mapEngineServerTickLiquidity,\n mapSubaccountSummary,\n} from './utils/queryDataMappers';\n\nexport class EngineQueryClient extends EngineBaseClient {\n /**\n * Retrieves the set of contracts that the engine is interfacing with\n */\n async getContracts(): Promise<GetEngineContractsResponse> {\n const baseResponse = await this.query('contracts', {});\n return {\n chainId: Number(baseResponse.chain_id),\n endpointAddr: baseResponse.endpoint_addr,\n orderbookAddrs: baseResponse.book_addrs,\n };\n }\n\n /**\n * Retrieves current engine status\n */\n async getStatus(): Promise<EngineServerStatusResponse> {\n return this.query('status', {});\n }\n\n /**\n * Retrieves a subaccount summary reflective of the state within the offchain engine. This adheres to the\n * same return interface as the contract version\n *\n * @param params\n */\n async getSubaccountSummary(\n params: GetEngineSubaccountSummaryParams,\n ): Promise<GetEngineSubaccountSummaryResponse> {\n const subaccount = subaccountToHex({\n subaccountOwner: params.subaccountOwner,\n subaccountName: params.subaccountName,\n });\n const baseResponse = await this.query('subaccount_info', {\n subaccount,\n });\n\n return mapSubaccountSummary(baseResponse);\n }\n\n /**\n * Retrieves a list of isolated positions\n *\n * @param params\n */\n async getIsolatedPositions(\n params: GetEngineIsolatedPositionsParams,\n ): Promise<GetEngineIsolatedPositionsResponse> {\n const subaccount = subaccountToHex({\n subaccountOwner: params.subaccountOwner,\n subaccountName: params.subaccountName,\n });\n const baseResponse = await this.query('isolated_positions', {\n subaccount,\n });\n\n return mapEngineServerIsolatedPositions(baseResponse);\n }\n\n /**\n * Retrieves an estimated subaccount summary with the applied transactions\n *\n * @param params\n */\n async getEstimatedSubaccountSummary(\n params: GetEngineEstimatedSubaccountSummaryParams,\n ): Promise<GetEngineSubaccountSummaryResponse> {\n const subaccount = subaccountToHex({\n subaccountOwner: params.subaccountOwner,\n subaccountName: params.subaccountName,\n });\n const queryParams: EngineServerSubaccountInfoQueryParams = {\n subaccount: subaccount,\n txns: params.txs.map(\n (\n tx,\n ): NonNullable<\n EngineServerSubaccountInfoQueryParams['txns']\n >[number] => {\n switch (tx.type) {\n case 'apply_delta':\n return {\n apply_delta: {\n product_id: tx.tx.productId,\n subaccount,\n amount_delta: toIntegerString(tx.tx.amountDelta),\n v_quote_delta: toIntegerString(tx.tx.vQuoteDelta),\n },\n };\n }\n },\n ),\n };\n const baseResponse = await this.query('subaccount_info', {\n subaccount: queryParams.subaccount,\n txns: JSON.stringify(queryParams.txns),\n });\n\n return mapSubaccountSummary(baseResponse);\n }\n\n /**\n * Retrieves symbols and product info\n *\n * @param params\n */\n async getSymbols(\n params: GetEngineSymbolsParams,\n ): Promise<EngineSymbolsResponse> {\n const baseResponse = await this.query('symbols', {\n product_ids: params.productIds,\n product_type:\n params.productType != null\n ? mapProductEngineType(params.productType)\n : undefined,\n });\n return mapEngineServerSymbols(baseResponse);\n }\n\n /**\n * Retrieves all market states as per the offchain engine. Same return interface as contracts\n */\n async getAllMarkets(): Promise<GetEngineAllMarketsResponse> {\n const markets: MarketWithProduct[] = [];\n\n const baseResponse = await this.query('all_products', {});\n baseResponse.spot_products.forEach((spotProduct) => {\n markets.push(mapEngineServerSpotProduct(spotProduct));\n });\n baseResponse.perp_products.forEach((perpProduct) => {\n markets.push(mapEngineServerPerpProduct(perpProduct));\n });\n\n return markets;\n }\n\n /**\n * Retrieves all markets by chain id.\n */\n async getEdgeAllMarkets(): Promise<Record<number, MarketWithProduct[]>> {\n const baseResponse = await this.query('edge_all_products', {});\n\n return mapValues(baseResponse.edge_all_products, (allProducts) => {\n const markets: MarketWithProduct[] = [];\n\n allProducts.spot_products.forEach((spotProduct) => {\n markets.push(mapEngineServerSpotProduct(spotProduct));\n });\n\n allProducts.perp_products.forEach((perpProduct) => {\n markets.push(mapEngineServerPerpProduct(perpProduct));\n });\n\n return markets;\n });\n }\n\n /**\n * Retrieves all health groups (linked spot & perp products) from the engine\n */\n async getHealthGroups(): Promise<GetEngineHealthGroupsResponse> {\n const baseResponse = await this.query('health_groups', {});\n\n return {\n healthGroups: baseResponse.health_groups.map(\n ([spotProductId, perpProductId]) => {\n return {\n spotProductId,\n perpProductId,\n };\n },\n ),\n };\n }\n\n /**\n * Retrieves min deposit rates for all spot products from the engine\n */\n async getMinDepositRates(): Promise<GetEngineMinDepositRatesResponse> {\n const baseResponse = await this.query('min_deposit_rates', {});\n\n return {\n minDepositRates: mapValues(baseResponse.min_deposit_rates, (m) => {\n return {\n productId: m.product_id,\n minDepositRate: removeDecimals(m.min_deposit_rate_x18),\n };\n }),\n };\n }\n\n /**\n * Retrieves an order from the offchain engine\n *\n * @param params\n */\n async getOrder(\n params: GetEngineOrderParams,\n ): Promise<GetEngineOrderResponse> {\n const baseResponse = await this.query('order', {\n digest: params.digest,\n product_id: params.productId,\n });\n\n return mapEngineServerOrder(baseResponse);\n }\n\n /**\n * Signs and validates with the engine that the order is valid to be submitted (i.e. does not violate health reqs)\n *\n * @param params\n */\n async validateOrderParams(\n params: ValidateEngineOrderParams,\n ): Promise<ValidateEngineOrderResponse> {\n const signedOrder = {\n order: params.order,\n signature: await this.sign(\n 'place_order',\n params.orderbookAddr,\n params.chainId,\n params.order,\n ),\n };\n return this.validateSignedOrderParams({\n signedOrder,\n productId: params.productId,\n });\n }\n\n /**\n * Validates an existing signed order with the engine as a pre-check for health\n *\n * @param params\n */\n async validateSignedOrderParams(\n params: ValidateSignedEngineOrderParams,\n ): Promise<ValidateEngineOrderResponse> {\n const baseResponse = await this.query('validate_order', {\n product_id: params.productId,\n order: encodeSignedOrder(params.signedOrder),\n });\n\n return {\n productId: baseResponse.product_id,\n valid: baseResponse.valid,\n };\n }\n\n /**\n * Get all subaccount orders from the engine, per product ID\n * @param params\n */\n async getSubaccountOrders(\n params: GetEngineSubaccountOrdersParams,\n ): Promise<GetEngineSubaccountOrdersResponse> {\n const baseResponse = await this.query('subaccount_orders', {\n sender: subaccountToHex({\n subaccountOwner: params.subaccountOwner,\n subaccountName: params.subaccountName,\n }),\n product_id: params.productId,\n });\n\n return {\n orders: baseResponse.orders.map(mapEngineServerOrder),\n productId: params.productId,\n };\n }\n\n /**\n * Get all subaccount orders from the engine, for multiple products\n * @param params\n */\n async getSubaccountMultiProductOrders(\n params: GetEngineSubaccountProductOrdersParams,\n ): Promise<GetEngineSubaccountProductOrdersResponse> {\n const baseResponse = await this.query('orders', {\n sender: subaccountToHex({\n subaccountOwner: params.subaccountOwner,\n subaccountName: params.subaccountName,\n }),\n product_ids: params.productIds,\n });\n\n return {\n productOrders: baseResponse.product_orders.map((orders) => {\n return {\n orders: orders.orders.map(mapEngineServerOrder),\n productId: orders.product_id,\n };\n }),\n };\n }\n\n /**\n * Gets maker & taker fee rates for order fees\n * @param params\n */\n async getSubaccountFeeRates(\n params: GetEngineSubaccountFeeRatesParams,\n ): Promise<GetEngineSubaccountFeeRatesResponse> {\n const baseResponse = await this.query('fee_rates', {\n sender: subaccountToHex({\n subaccountOwner: params.subaccountOwner,\n subaccountName: params.subaccountName,\n }),\n });\n\n return {\n healthCheckSequencerFee: toBigDecimal(\n baseResponse.health_check_sequencer_fee,\n ),\n liquidationSequencerFee: toBigDecimal(\n baseResponse.liquidation_sequencer_fee,\n ),\n takerSequencerFee: toBigDecimal(baseResponse.taker_sequencer_fee),\n orders: baseResponse.taker_fee_rates_x18.reduce(\n (acc, takerRateX18, currIndex) => {\n acc[currIndex] = {\n taker: removeDecimals(takerRateX18),\n maker: removeDecimals(baseResponse.maker_fee_rates_x18[currIndex]),\n };\n return acc;\n },\n {} as Record<number, SubaccountOrderFeeRates>,\n ),\n withdrawal: baseResponse.withdraw_sequencer_fees.reduce(\n (acc, productFee, currIndex) => {\n acc[currIndex] = toBigDecimal(productFee);\n return acc;\n },\n {} as Record<number, BigDecimal>,\n ),\n };\n }\n\n /**\n * Gets \"price ticks\" for a given market, useful for constructing liquidity levels at each price\n * @param params\n */\n async getMarketLiquidity(\n params: GetEngineMarketLiquidityParams,\n ): Promise<GetEngineMarketLiquidityResponse> {\n const baseResponse = await this.query('market_liquidity', {\n product_id: params.productId,\n depth: params.depth,\n });\n return {\n asks: baseResponse.asks.map(mapEngineServerTickLiquidity),\n bids: baseResponse.bids.map(mapEngineServerTickLiquidity),\n };\n }\n\n /**\n * Retrieves the latest price for a given market\n * @param params\n */\n async getMarketPrice(\n params: GetEngineMarketPriceParams,\n ): Promise<GetEngineMarketPriceResponse> {\n const baseResponse = await this.query('market_price', {\n product_id: params.productId,\n });\n return mapEngineMarketPrice(baseResponse);\n }\n\n /**\n * Retrieves the latest prices for provided markets\n * @param params\n */\n async getMarketPrices(\n params: GetEngineMarketPricesParams,\n ): Promise<GetEngineMarketPricesResponse> {\n const baseResponse = await this.query('market_prices', {\n product_ids: params.productIds,\n });\n return {\n marketPrices: baseResponse.market_prices.map(mapEngineMarketPrice),\n };\n }\n\n /**\n * Retrieves the estimated max order size for a product\n * @param params\n */\n async getMaxOrderSize(\n params: GetEngineMaxOrderSizeParams,\n ): Promise<GetEngineMaxOrderSizeResponse> {\n const baseResponse = await this.query('max_order_size', {\n direction: params.side,\n price_x18: toIntegerString(addDecimals(params.price)),\n product_id: params.productId,\n sender: subaccountToHex({\n subaccountOwner: params.subaccountOwner,\n subaccountName: params.subaccountName,\n }),\n spot_leverage:\n params.spotLeverage != null ? String(params.spotLeverage) : null,\n reduce_only: params.reduceOnly != null ? String(params.reduceOnly) : null,\n });\n\n return toBigDecimal(baseResponse.max_order_size);\n }\n\n /**\n * Retrieves the estimated max withdrawal size for a product\n * @param params\n */\n async getMaxWithdrawable(\n params: GetEngineMaxWithdrawableParams,\n ): Promise<GetEngineMaxWithdrawableResponse> {\n const baseResponse = await this.query('max_withdrawable', {\n product_id: params.productId,\n sender: subaccountToHex({\n subaccountOwner: params.subaccountOwner,\n subaccountName: params.subaccountName,\n }),\n spot_leverage:\n params.spotLeverage != null ? String(params.spotLeverage) : null,\n });\n\n return toBigDecimal(baseResponse.max_withdrawable);\n }\n\n /**\n * Retrieves the estimated max quote amount for minting NLP.\n *\n * @param params\n */\n async getMaxMintNlpAmount(\n params: GetEngineMaxMintNlpAmountParams,\n ): Promise<GetEngineMaxMintNlpAmountResponse> {\n const baseResponse = await this.query('max_nlp_mintable', {\n sender: subaccountToHex({\n subaccountOwner: params.subaccountOwner,\n subaccountName: params.subaccountName,\n }),\n spot_leverage:\n params.spotLeverage != null ? String(params.spotLeverage) : null,\n });\n\n return toBigDecimal(baseResponse.max_quote_amount);\n }\n\n /**\n * Gets the currently linked signer for the subaccount\n * @param params\n * @returns\n */\n public async getLinkedSigner(\n params: GetEngineLinkedSignerParams,\n ): Promise<GetEngineLinkedSignerResponse> {\n const baseResponse = await this.query('linked_signer', {\n subaccount: subaccountToHex({\n subaccountOwner: params.subaccountOwner,\n subaccountName: params.subaccountName,\n }),\n });\n\n return {\n signer: baseResponse.linked_signer,\n };\n }\n\n /**\n * Gets the insurance funds in USDC.\n * @returns\n */\n public async getInsurance(): Promise<GetEngineInsuranceResponse> {\n const baseResponse = await this.query('insurance', {});\n\n return toBigDecimal(baseResponse.insurance);\n }\n\n /**\n * Gets the orderbook contract address for a given product\n * @param productId\n * @returns\n */\n public async getOrderbookAddress(productId: number): Promise<string> {\n const contracts = await this.getContracts();\n return contracts.orderbookAddrs[productId];\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAIO;AACP,mBAOO;AACP,8BAAiC;AA2CjC,sCAAqC;AACrC,8BASO;AAEA,IAAM,oBAAN,cAAgC,yCAAiB;AAAA;AAAA;AAAA;AAAA,EAItD,MAAM,eAAoD;AACxD,UAAM,eAAe,MAAM,KAAK,MAAM,aAAa,CAAC,CAAC;AACrD,WAAO;AAAA,MACL,SAAS,OAAO,aAAa,QAAQ;AAAA,MACrC,cAAc,aAAa;AAAA,MAC3B,gBAAgB,aAAa;AAAA,IAC/B;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,YAAiD;AACrD,WAAO,KAAK,MAAM,UAAU,CAAC,CAAC;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA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AA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAa,oBAAoB,WAAoC;AACnE,UAAM,YAAY,MAAM,KAAK,aAAa;AAC1C,WAAO,UAAU,eAAe,SAAS;AAAA,EAC3C;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/EngineQueryClient.ts"],"sourcesContent":["import {\n addDecimals,\n BigDecimal,\n encodeSignedOrder,\n getOrderVerifyingAddress,\n mapValues,\n MarketWithProduct,\n removeDecimals,\n subaccountToHex,\n toBigDecimal,\n toIntegerString,\n} from '@nadohq/shared';\nimport { EngineBaseClient } from './EngineBaseClient';\nimport {\n EngineServerStatusResponse,\n EngineServerSubaccountInfoQueryParams,\n EngineSymbolsResponse,\n GetEngineAllMarketsResponse,\n GetEngineContractsResponse,\n GetEngineEstimatedSubaccountSummaryParams,\n GetEngineHealthGroupsResponse,\n GetEngineInsuranceResponse,\n GetEngineIsolatedPositionsParams,\n GetEngineIsolatedPositionsResponse,\n GetEngineLinkedSignerParams,\n GetEngineLinkedSignerResponse,\n GetEngineMarketLiquidityParams,\n GetEngineMarketLiquidityResponse,\n GetEngineMarketPriceParams,\n GetEngineMarketPriceResponse,\n GetEngineMarketPricesParams,\n GetEngineMarketPricesResponse,\n GetEngineMaxBurnNlpAmountParams,\n GetEngineMaxBurnNlpAmountResponse,\n GetEngineMaxMintNlpAmountParams,\n GetEngineMaxMintNlpAmountResponse,\n GetEngineMaxOrderSizeParams,\n GetEngineMaxOrderSizeResponse,\n GetEngineMaxWithdrawableParams,\n GetEngineMaxWithdrawableResponse,\n GetEngineNlpLockedBalancesParams,\n GetEngineNlpLockedBalancesResponse,\n GetEngineOrderParams,\n GetEngineOrderResponse,\n GetEngineSubaccountFeeRatesParams,\n GetEngineSubaccountFeeRatesResponse,\n GetEngineSubaccountOrdersParams,\n GetEngineSubaccountOrdersResponse,\n GetEngineSubaccountProductOrdersParams,\n GetEngineSubaccountProductOrdersResponse,\n GetEngineSubaccountSummaryParams,\n GetEngineSubaccountSummaryResponse,\n GetEngineSymbolsParams,\n SubaccountOrderFeeRates,\n ValidateEngineOrderParams,\n ValidateEngineOrderResponse,\n ValidateSignedEngineOrderParams,\n} from './types';\nimport { mapProductEngineType } from './utils/productEngineTypeMappers';\nimport {\n mapEngineMarketPrice,\n mapEngineServerIsolatedPositions,\n mapEngineServerNlpLockedBalances,\n mapEngineServerOrder,\n mapEngineServerPerpProduct,\n mapEngineServerSpotProduct,\n mapEngineServerSymbols,\n mapEngineServerTickLiquidity,\n mapSubaccountSummary,\n} from './utils/queryDataMappers';\n\nexport class EngineQueryClient extends EngineBaseClient {\n /**\n * Retrieves the set of contracts that the engine is interfacing with\n */\n async getContracts(): Promise<GetEngineContractsResponse> {\n const baseResponse = await this.query('contracts', {});\n return {\n chainId: Number(baseResponse.chain_id),\n endpointAddr: baseResponse.endpoint_addr,\n };\n }\n\n /**\n * Retrieves current engine status\n */\n async getStatus(): Promise<EngineServerStatusResponse> {\n return this.query('status', {});\n }\n\n /**\n * Retrieves a subaccount summary reflective of the state within the offchain engine. This adheres to the\n * same return interface as the contract version\n *\n * @param params\n */\n async getSubaccountSummary(\n params: GetEngineSubaccountSummaryParams,\n ): Promise<GetEngineSubaccountSummaryResponse> {\n const subaccount = subaccountToHex({\n subaccountOwner: params.subaccountOwner,\n subaccountName: params.subaccountName,\n });\n const baseResponse = await this.query('subaccount_info', {\n subaccount,\n });\n\n return mapSubaccountSummary(baseResponse);\n }\n\n /**\n * Retrieves a list of isolated positions\n *\n * @param params\n */\n async getIsolatedPositions(\n params: GetEngineIsolatedPositionsParams,\n ): Promise<GetEngineIsolatedPositionsResponse> {\n const subaccount = subaccountToHex({\n subaccountOwner: params.subaccountOwner,\n subaccountName: params.subaccountName,\n });\n const baseResponse = await this.query('isolated_positions', {\n subaccount,\n });\n\n return mapEngineServerIsolatedPositions(baseResponse);\n }\n\n /**\n * Retrieves an estimated subaccount summary with the applied transactions\n *\n * @param params\n */\n async getEstimatedSubaccountSummary(\n params: GetEngineEstimatedSubaccountSummaryParams,\n ): Promise<GetEngineSubaccountSummaryResponse> {\n const subaccount = subaccountToHex({\n subaccountOwner: params.subaccountOwner,\n subaccountName: params.subaccountName,\n });\n const queryParams: EngineServerSubaccountInfoQueryParams = {\n subaccount: subaccount,\n txns: params.txs.map(\n (\n tx,\n ): NonNullable<\n EngineServerSubaccountInfoQueryParams['txns']\n >[number] => {\n switch (tx.type) {\n case 'apply_delta':\n return {\n apply_delta: {\n product_id: tx.tx.productId,\n subaccount,\n amount_delta: toIntegerString(tx.tx.amountDelta),\n v_quote_delta: toIntegerString(tx.tx.vQuoteDelta),\n },\n };\n }\n },\n ),\n };\n const baseResponse = await this.query('subaccount_info', {\n subaccount: queryParams.subaccount,\n txns: JSON.stringify(queryParams.txns),\n });\n\n return mapSubaccountSummary(baseResponse);\n }\n\n /**\n * Retrieves symbols and product info\n *\n * @param params\n */\n async getSymbols(\n params: GetEngineSymbolsParams,\n ): Promise<EngineSymbolsResponse> {\n const baseResponse = await this.query('symbols', {\n product_ids: params.productIds,\n product_type:\n params.productType != null\n ? mapProductEngineType(params.productType)\n : undefined,\n });\n return mapEngineServerSymbols(baseResponse);\n }\n\n /**\n * Retrieves all market states as per the offchain engine. Same return interface as contracts\n */\n async getAllMarkets(): Promise<GetEngineAllMarketsResponse> {\n const markets: MarketWithProduct[] = [];\n\n const baseResponse = await this.query('all_products', {});\n baseResponse.spot_products.forEach((spotProduct) => {\n markets.push(mapEngineServerSpotProduct(spotProduct));\n });\n baseResponse.perp_products.forEach((perpProduct) => {\n markets.push(mapEngineServerPerpProduct(perpProduct));\n });\n\n return markets;\n }\n\n /**\n * Retrieves all markets by chain id.\n */\n async getEdgeAllMarkets(): Promise<Record<number, MarketWithProduct[]>> {\n const baseResponse = await this.query('edge_all_products', {});\n\n return mapValues(baseResponse.edge_all_products, (allProducts) => {\n const markets: MarketWithProduct[] = [];\n\n allProducts.spot_products.forEach((spotProduct) => {\n markets.push(mapEngineServerSpotProduct(spotProduct));\n });\n\n allProducts.perp_products.forEach((perpProduct) => {\n markets.push(mapEngineServerPerpProduct(perpProduct));\n });\n\n return markets;\n });\n }\n\n /**\n * Retrieves all health groups (linked spot & perp products) from the engine\n */\n async getHealthGroups(): Promise<GetEngineHealthGroupsResponse> {\n const baseResponse = await this.query('health_groups', {});\n\n return {\n healthGroups: baseResponse.health_groups.map(\n ([spotProductId, perpProductId]) => {\n return {\n spotProductId,\n perpProductId,\n };\n },\n ),\n };\n }\n\n /**\n * Retrieves an order from the offchain engine\n *\n * @param params\n */\n async getOrder(\n params: GetEngineOrderParams,\n ): Promise<GetEngineOrderResponse> {\n const baseResponse = await this.query('order', {\n digest: params.digest,\n product_id: params.productId,\n });\n\n return mapEngineServerOrder(baseResponse);\n }\n\n /**\n * Signs and validates with the engine that the order is valid to be submitted (i.e. does not violate health reqs)\n *\n * @param params\n */\n async validateOrderParams(\n params: ValidateEngineOrderParams,\n ): Promise<ValidateEngineOrderResponse> {\n const signedOrder = {\n order: params.order,\n signature: await this.sign(\n 'place_order',\n getOrderVerifyingAddress(params.productId),\n params.chainId,\n params.order,\n ),\n };\n return this.validateSignedOrderParams({\n signedOrder,\n productId: params.productId,\n });\n }\n\n /**\n * Validates an existing signed order with the engine as a pre-check for health\n *\n * @param params\n */\n async validateSignedOrderParams(\n params: ValidateSignedEngineOrderParams,\n ): Promise<ValidateEngineOrderResponse> {\n const baseResponse = await this.query('validate_order', {\n product_id: params.productId,\n order: encodeSignedOrder(params.signedOrder),\n });\n\n return {\n productId: baseResponse.product_id,\n valid: baseResponse.valid,\n };\n }\n\n /**\n * Get all subaccount orders from the engine, per product ID\n * @param params\n */\n async getSubaccountOrders(\n params: GetEngineSubaccountOrdersParams,\n ): Promise<GetEngineSubaccountOrdersResponse> {\n const baseResponse = await this.query('subaccount_orders', {\n sender: subaccountToHex({\n subaccountOwner: params.subaccountOwner,\n subaccountName: params.subaccountName,\n }),\n product_id: params.productId,\n });\n\n return {\n orders: baseResponse.orders.map(mapEngineServerOrder),\n productId: params.productId,\n };\n }\n\n /**\n * Get all subaccount orders from the engine, for multiple products\n * @param params\n */\n async getSubaccountMultiProductOrders(\n params: GetEngineSubaccountProductOrdersParams,\n ): Promise<GetEngineSubaccountProductOrdersResponse> {\n const baseResponse = await this.query('orders', {\n sender: subaccountToHex({\n subaccountOwner: params.subaccountOwner,\n subaccountName: params.subaccountName,\n }),\n product_ids: params.productIds,\n });\n\n return {\n productOrders: baseResponse.product_orders.map((orders) => {\n return {\n orders: orders.orders.map(mapEngineServerOrder),\n productId: orders.product_id,\n };\n }),\n };\n }\n\n /**\n * Gets maker & taker fee rates for order fees\n * @param params\n */\n async getSubaccountFeeRates(\n params: GetEngineSubaccountFeeRatesParams,\n ): Promise<GetEngineSubaccountFeeRatesResponse> {\n const baseResponse = await this.query('fee_rates', {\n sender: subaccountToHex({\n subaccountOwner: params.subaccountOwner,\n subaccountName: params.subaccountName,\n }),\n });\n\n return {\n healthCheckSequencerFee: toBigDecimal(\n baseResponse.health_check_sequencer_fee,\n ),\n liquidationSequencerFee: toBigDecimal(\n baseResponse.liquidation_sequencer_fee,\n ),\n takerSequencerFee: toBigDecimal(baseResponse.taker_sequencer_fee),\n orders: baseResponse.taker_fee_rates_x18.reduce(\n (acc, takerRateX18, currIndex) => {\n acc[currIndex] = {\n taker: removeDecimals(takerRateX18),\n maker: removeDecimals(baseResponse.maker_fee_rates_x18[currIndex]),\n };\n return acc;\n },\n {} as Record<number, SubaccountOrderFeeRates>,\n ),\n withdrawal: baseResponse.withdraw_sequencer_fees.reduce(\n (acc, productFee, currIndex) => {\n acc[currIndex] = toBigDecimal(productFee);\n return acc;\n },\n {} as Record<number, BigDecimal>,\n ),\n feeTier: baseResponse.fee_tier,\n };\n }\n\n /**\n * Gets \"price ticks\" for a given market, useful for constructing liquidity levels at each price\n * @param params\n */\n async getMarketLiquidity(\n params: GetEngineMarketLiquidityParams,\n ): Promise<GetEngineMarketLiquidityResponse> {\n const baseResponse = await this.query('market_liquidity', {\n product_id: params.productId,\n depth: params.depth,\n });\n return {\n asks: baseResponse.asks.map(mapEngineServerTickLiquidity),\n bids: baseResponse.bids.map(mapEngineServerTickLiquidity),\n };\n }\n\n /**\n * Retrieves the latest price for a given market\n * @param params\n */\n async getMarketPrice(\n params: GetEngineMarketPriceParams,\n ): Promise<GetEngineMarketPriceResponse> {\n const baseResponse = await this.query('market_price', {\n product_id: params.productId,\n });\n return mapEngineMarketPrice(baseResponse);\n }\n\n /**\n * Retrieves the latest prices for provided markets\n * @param params\n */\n async getMarketPrices(\n params: GetEngineMarketPricesParams,\n ): Promise<GetEngineMarketPricesResponse> {\n const baseResponse = await this.query('market_prices', {\n product_ids: params.productIds,\n });\n return {\n marketPrices: baseResponse.market_prices.map(mapEngineMarketPrice),\n };\n }\n\n /**\n * Retrieves the estimated max order size for a product\n * @param params\n */\n async getMaxOrderSize(\n params: GetEngineMaxOrderSizeParams,\n ): Promise<GetEngineMaxOrderSizeResponse> {\n const baseResponse = await this.query('max_order_size', {\n direction: params.side,\n price_x18: toIntegerString(addDecimals(params.price)),\n product_id: params.productId,\n sender: subaccountToHex({\n subaccountOwner: params.subaccountOwner,\n subaccountName: params.subaccountName,\n }),\n // Backend expects string variants of booleans\n spot_leverage:\n params.spotLeverage != null ? String(params.spotLeverage) : null,\n reduce_only: params.reduceOnly != null ? String(params.reduceOnly) : null,\n isolated: params.isolated != null ? String(params.isolated) : null,\n borrow_margin:\n // This field is only relevant for isolated orders\n params.isolated && params.isoBorrowMargin != null\n ? String(params.isoBorrowMargin)\n : null,\n });\n\n return toBigDecimal(baseResponse.max_order_size);\n }\n\n /**\n * Retrieves the estimated max withdrawal size for a product\n * @param params\n */\n async getMaxWithdrawable(\n params: GetEngineMaxWithdrawableParams,\n ): Promise<GetEngineMaxWithdrawableResponse> {\n const baseResponse = await this.query('max_withdrawable', {\n product_id: params.productId,\n sender: subaccountToHex({\n subaccountOwner: params.subaccountOwner,\n subaccountName: params.subaccountName,\n }),\n spot_leverage:\n params.spotLeverage != null ? String(params.spotLeverage) : null,\n });\n\n return toBigDecimal(baseResponse.max_withdrawable);\n }\n\n /**\n * Retrieves the estimated max quote amount for minting NLP.\n *\n * @param params\n */\n async getMaxMintNlpAmount(\n params: GetEngineMaxMintNlpAmountParams,\n ): Promise<GetEngineMaxMintNlpAmountResponse> {\n const baseResponse = await this.query('max_nlp_mintable', {\n sender: subaccountToHex({\n subaccountOwner: params.subaccountOwner,\n subaccountName: params.subaccountName,\n }),\n spot_leverage:\n params.spotLeverage != null ? String(params.spotLeverage) : null,\n });\n\n return toBigDecimal(baseResponse.max_quote_amount);\n }\n\n /**\n * Retrieves the max amount of NLP that can be burned.\n *\n * @param params\n */\n async getMaxBurnNlpAmount(\n params: GetEngineMaxBurnNlpAmountParams,\n ): Promise<GetEngineMaxBurnNlpAmountResponse> {\n const baseResponse = await this.query('max_nlp_burnable', {\n sender: subaccountToHex({\n subaccountOwner: params.subaccountOwner,\n subaccountName: params.subaccountName,\n }),\n });\n\n return toBigDecimal(baseResponse.max_nlp_amount);\n }\n\n /**\n * Gets the currently linked signer for the subaccount\n * @param params\n * @returns\n */\n public async getLinkedSigner(\n params: GetEngineLinkedSignerParams,\n ): Promise<GetEngineLinkedSignerResponse> {\n const baseResponse = await this.query('linked_signer', {\n subaccount: subaccountToHex({\n subaccountOwner: params.subaccountOwner,\n subaccountName: params.subaccountName,\n }),\n });\n\n return {\n signer: baseResponse.linked_signer,\n };\n }\n\n /**\n * Gets the insurance funds in USDC.\n * @returns\n */\n public async getInsurance(): Promise<GetEngineInsuranceResponse> {\n const baseResponse = await this.query('insurance', {});\n\n return toBigDecimal(baseResponse.insurance);\n }\n\n /**\n * Retrieves the NLP locked and unlocked balances for a subaccount.\n *\n * @param params\n */\n async getNlpLockedBalances(\n params: GetEngineNlpLockedBalancesParams,\n ): Promise<GetEngineNlpLockedBalancesResponse> {\n const baseResponse = await this.query('nlp_locked_balances', {\n subaccount: subaccountToHex({\n subaccountOwner: params.subaccountOwner,\n subaccountName: params.subacc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AAAA,EACnD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,oBACJ,QAC4C;AAC5C,UAAM,eAAe,MAAM,KAAK,MAAM,oBAAoB;AAAA,MACxD,YAAQ,+BAAgB;AAAA,QACtB,iBAAiB,OAAO;AAAA,QACxB,gBAAgB,OAAO;AAAA,MACzB,CAAC;AAAA,IACH,CAAC;AAED,eAAO,4BAAa,aAAa,cAAc;AAAA,EACjD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAa,gBACX,QACwC;AACxC,UAAM,eAAe,MAAM,KAAK,MAAM,iBAAiB;AAAA,MACrD,gBAAY,+BAAgB;AAAA,QAC1B,iBAAiB,OAAO;AAAA,QACxB,gBAAgB,OAAO;AAAA,MACzB,CAAC;AAAA,IACH,CAAC;AAED,WAAO;AAAA,MACL,QAAQ,aAAa;AAAA,IACvB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAa,eAAoD;AAC/D,UAAM,eAAe,MAAM,KAAK,MAAM,aAAa,CAAC,CAAC;AAErD,eAAO,4BAAa,aAAa,SAAS;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,qBACJ,QAC6C;AAC7C,UAAM,eAAe,MAAM,KAAK,MAAM,uBAAuB;AAAA,MAC3D,gBAAY,+BAAgB;AAAA,QAC1B,iBAAiB,OAAO;AAAA,QACxB,gBAAgB,OAAO;AAAA,MACzB,CAAC;AAAA,IACH,CAAC;AAED,eAAO,0DAAiC,YAAY;AAAA,EACtD;AACF;","names":[]}
@@ -1,10 +1,9 @@
1
- import { MarketWithProduct } from '@nadohq/contracts';
1
+ import { MarketWithProduct } from '@nadohq/shared';
2
2
  import { EngineBaseClient } from './EngineBaseClient.cjs';
3
- import { GetEngineContractsResponse, GetEngineSubaccountSummaryParams, GetEngineSubaccountSummaryResponse, GetEngineIsolatedPositionsParams, GetEngineIsolatedPositionsResponse, GetEngineEstimatedSubaccountSummaryParams, GetEngineSymbolsParams, EngineSymbolsResponse, GetEngineAllMarketsResponse, GetEngineHealthGroupsResponse, GetEngineMinDepositRatesResponse, GetEngineOrderParams, GetEngineOrderResponse, ValidateEngineOrderParams, ValidateEngineOrderResponse, ValidateSignedEngineOrderParams, GetEngineSubaccountOrdersParams, GetEngineSubaccountOrdersResponse, GetEngineSubaccountProductOrdersParams, GetEngineSubaccountProductOrdersResponse, GetEngineSubaccountFeeRatesParams, GetEngineSubaccountFeeRatesResponse, GetEngineMarketLiquidityParams, GetEngineMarketLiquidityResponse, GetEngineMarketPriceParams, GetEngineMarketPriceResponse, GetEngineMarketPricesParams, GetEngineMarketPricesResponse, GetEngineMaxOrderSizeParams, GetEngineMaxOrderSizeResponse, GetEngineMaxWithdrawableParams, GetEngineMaxWithdrawableResponse, GetEngineMaxMintNlpAmountParams, GetEngineMaxMintNlpAmountResponse, GetEngineLinkedSignerParams, GetEngineLinkedSignerResponse, GetEngineInsuranceResponse } from './types/clientQueryTypes.cjs';
4
3
  import { EngineServerStatusResponse } from './types/serverQueryTypes.cjs';
4
+ import { GetEngineContractsResponse, GetEngineSubaccountSummaryParams, GetEngineSubaccountSummaryResponse, GetEngineIsolatedPositionsParams, GetEngineIsolatedPositionsResponse, GetEngineEstimatedSubaccountSummaryParams, GetEngineSymbolsParams, EngineSymbolsResponse, GetEngineAllMarketsResponse, GetEngineHealthGroupsResponse, GetEngineOrderParams, GetEngineOrderResponse, ValidateEngineOrderParams, ValidateEngineOrderResponse, ValidateSignedEngineOrderParams, GetEngineSubaccountOrdersParams, GetEngineSubaccountOrdersResponse, GetEngineSubaccountProductOrdersParams, GetEngineSubaccountProductOrdersResponse, GetEngineSubaccountFeeRatesParams, GetEngineSubaccountFeeRatesResponse, GetEngineMarketLiquidityParams, GetEngineMarketLiquidityResponse, GetEngineMarketPriceParams, GetEngineMarketPriceResponse, GetEngineMarketPricesParams, GetEngineMarketPricesResponse, GetEngineMaxOrderSizeParams, GetEngineMaxOrderSizeResponse, GetEngineMaxWithdrawableParams, GetEngineMaxWithdrawableResponse, GetEngineMaxMintNlpAmountParams, GetEngineMaxMintNlpAmountResponse, GetEngineMaxBurnNlpAmountParams, GetEngineMaxBurnNlpAmountResponse, GetEngineLinkedSignerParams, GetEngineLinkedSignerResponse, GetEngineInsuranceResponse, GetEngineNlpLockedBalancesParams, GetEngineNlpLockedBalancesResponse } from './types/clientQueryTypes.cjs';
5
5
  import 'axios';
6
6
  import './types/serverExecuteTypes.cjs';
7
- import '@nadohq/utils';
8
7
  import './types/serverQueryModelTypes.cjs';
9
8
 
10
9
  declare class EngineQueryClient extends EngineBaseClient {
@@ -53,10 +52,6 @@ declare class EngineQueryClient extends EngineBaseClient {
53
52
  * Retrieves all health groups (linked spot & perp products) from the engine
54
53
  */
55
54
  getHealthGroups(): Promise<GetEngineHealthGroupsResponse>;
56
- /**
57
- * Retrieves min deposit rates for all spot products from the engine
58
- */
59
- getMinDepositRates(): Promise<GetEngineMinDepositRatesResponse>;
60
55
  /**
61
56
  * Retrieves an order from the offchain engine
62
57
  *
@@ -121,6 +116,12 @@ declare class EngineQueryClient extends EngineBaseClient {
121
116
  * @param params
122
117
  */
123
118
  getMaxMintNlpAmount(params: GetEngineMaxMintNlpAmountParams): Promise<GetEngineMaxMintNlpAmountResponse>;
119
+ /**
120
+ * Retrieves the max amount of NLP that can be burned.
121
+ *
122
+ * @param params
123
+ */
124
+ getMaxBurnNlpAmount(params: GetEngineMaxBurnNlpAmountParams): Promise<GetEngineMaxBurnNlpAmountResponse>;
124
125
  /**
125
126
  * Gets the currently linked signer for the subaccount
126
127
  * @param params
@@ -133,11 +134,11 @@ declare class EngineQueryClient extends EngineBaseClient {
133
134
  */
134
135
  getInsurance(): Promise<GetEngineInsuranceResponse>;
135
136
  /**
136
- * Gets the orderbook contract address for a given product
137
- * @param productId
138
- * @returns
137
+ * Retrieves the NLP locked and unlocked balances for a subaccount.
138
+ *
139
+ * @param params
139
140
  */
140
- getOrderbookAddress(productId: number): Promise<string>;
141
+ getNlpLockedBalances(params: GetEngineNlpLockedBalancesParams): Promise<GetEngineNlpLockedBalancesResponse>;
141
142
  }
142
143
 
143
144
  export { EngineQueryClient };
@@ -1,10 +1,9 @@
1
- import { MarketWithProduct } from '@nadohq/contracts';
1
+ import { MarketWithProduct } from '@nadohq/shared';
2
2
  import { EngineBaseClient } from './EngineBaseClient.js';
3
- import { GetEngineContractsResponse, GetEngineSubaccountSummaryParams, GetEngineSubaccountSummaryResponse, GetEngineIsolatedPositionsParams, GetEngineIsolatedPositionsResponse, GetEngineEstimatedSubaccountSummaryParams, GetEngineSymbolsParams, EngineSymbolsResponse, GetEngineAllMarketsResponse, GetEngineHealthGroupsResponse, GetEngineMinDepositRatesResponse, GetEngineOrderParams, GetEngineOrderResponse, ValidateEngineOrderParams, ValidateEngineOrderResponse, ValidateSignedEngineOrderParams, GetEngineSubaccountOrdersParams, GetEngineSubaccountOrdersResponse, GetEngineSubaccountProductOrdersParams, GetEngineSubaccountProductOrdersResponse, GetEngineSubaccountFeeRatesParams, GetEngineSubaccountFeeRatesResponse, GetEngineMarketLiquidityParams, GetEngineMarketLiquidityResponse, GetEngineMarketPriceParams, GetEngineMarketPriceResponse, GetEngineMarketPricesParams, GetEngineMarketPricesResponse, GetEngineMaxOrderSizeParams, GetEngineMaxOrderSizeResponse, GetEngineMaxWithdrawableParams, GetEngineMaxWithdrawableResponse, GetEngineMaxMintNlpAmountParams, GetEngineMaxMintNlpAmountResponse, GetEngineLinkedSignerParams, GetEngineLinkedSignerResponse, GetEngineInsuranceResponse } from './types/clientQueryTypes.js';
4
3
  import { EngineServerStatusResponse } from './types/serverQueryTypes.js';
4
+ import { GetEngineContractsResponse, GetEngineSubaccountSummaryParams, GetEngineSubaccountSummaryResponse, GetEngineIsolatedPositionsParams, GetEngineIsolatedPositionsResponse, GetEngineEstimatedSubaccountSummaryParams, GetEngineSymbolsParams, EngineSymbolsResponse, GetEngineAllMarketsResponse, GetEngineHealthGroupsResponse, GetEngineOrderParams, GetEngineOrderResponse, ValidateEngineOrderParams, ValidateEngineOrderResponse, ValidateSignedEngineOrderParams, GetEngineSubaccountOrdersParams, GetEngineSubaccountOrdersResponse, GetEngineSubaccountProductOrdersParams, GetEngineSubaccountProductOrdersResponse, GetEngineSubaccountFeeRatesParams, GetEngineSubaccountFeeRatesResponse, GetEngineMarketLiquidityParams, GetEngineMarketLiquidityResponse, GetEngineMarketPriceParams, GetEngineMarketPriceResponse, GetEngineMarketPricesParams, GetEngineMarketPricesResponse, GetEngineMaxOrderSizeParams, GetEngineMaxOrderSizeResponse, GetEngineMaxWithdrawableParams, GetEngineMaxWithdrawableResponse, GetEngineMaxMintNlpAmountParams, GetEngineMaxMintNlpAmountResponse, GetEngineMaxBurnNlpAmountParams, GetEngineMaxBurnNlpAmountResponse, GetEngineLinkedSignerParams, GetEngineLinkedSignerResponse, GetEngineInsuranceResponse, GetEngineNlpLockedBalancesParams, GetEngineNlpLockedBalancesResponse } from './types/clientQueryTypes.js';
5
5
  import 'axios';
6
6
  import './types/serverExecuteTypes.js';
7
- import '@nadohq/utils';
8
7
  import './types/serverQueryModelTypes.js';
9
8
 
10
9
  declare class EngineQueryClient extends EngineBaseClient {
@@ -53,10 +52,6 @@ declare class EngineQueryClient extends EngineBaseClient {
53
52
  * Retrieves all health groups (linked spot & perp products) from the engine
54
53
  */
55
54
  getHealthGroups(): Promise<GetEngineHealthGroupsResponse>;
56
- /**
57
- * Retrieves min deposit rates for all spot products from the engine
58
- */
59
- getMinDepositRates(): Promise<GetEngineMinDepositRatesResponse>;
60
55
  /**
61
56
  * Retrieves an order from the offchain engine
62
57
  *
@@ -121,6 +116,12 @@ declare class EngineQueryClient extends EngineBaseClient {
121
116
  * @param params
122
117
  */
123
118
  getMaxMintNlpAmount(params: GetEngineMaxMintNlpAmountParams): Promise<GetEngineMaxMintNlpAmountResponse>;
119
+ /**
120
+ * Retrieves the max amount of NLP that can be burned.
121
+ *
122
+ * @param params
123
+ */
124
+ getMaxBurnNlpAmount(params: GetEngineMaxBurnNlpAmountParams): Promise<GetEngineMaxBurnNlpAmountResponse>;
124
125
  /**
125
126
  * Gets the currently linked signer for the subaccount
126
127
  * @param params
@@ -133,11 +134,11 @@ declare class EngineQueryClient extends EngineBaseClient {
133
134
  */
134
135
  getInsurance(): Promise<GetEngineInsuranceResponse>;
135
136
  /**
136
- * Gets the orderbook contract address for a given product
137
- * @param productId
138
- * @returns
137
+ * Retrieves the NLP locked and unlocked balances for a subaccount.
138
+ *
139
+ * @param params
139
140
  */
140
- getOrderbookAddress(productId: number): Promise<string>;
141
+ getNlpLockedBalances(params: GetEngineNlpLockedBalancesParams): Promise<GetEngineNlpLockedBalancesResponse>;
141
142
  }
142
143
 
143
144
  export { EngineQueryClient };
@@ -1,20 +1,20 @@
1
1
  // src/EngineQueryClient.ts
2
- import {
3
- encodeSignedOrder,
4
- subaccountToHex
5
- } from "@nadohq/contracts";
6
2
  import {
7
3
  addDecimals,
4
+ encodeSignedOrder,
5
+ getOrderVerifyingAddress,
8
6
  mapValues,
9
7
  removeDecimals,
8
+ subaccountToHex,
10
9
  toBigDecimal,
11
10
  toIntegerString
12
- } from "@nadohq/utils";
11
+ } from "@nadohq/shared";
13
12
  import { EngineBaseClient } from "./EngineBaseClient.js";
14
13
  import { mapProductEngineType } from "./utils/productEngineTypeMappers.js";
15
14
  import {
16
15
  mapEngineMarketPrice,
17
16
  mapEngineServerIsolatedPositions,
17
+ mapEngineServerNlpLockedBalances,
18
18
  mapEngineServerOrder,
19
19
  mapEngineServerPerpProduct,
20
20
  mapEngineServerSpotProduct,
@@ -30,8 +30,7 @@ var EngineQueryClient = class extends EngineBaseClient {
30
30
  const baseResponse = await this.query("contracts", {});
31
31
  return {
32
32
  chainId: Number(baseResponse.chain_id),
33
- endpointAddr: baseResponse.endpoint_addr,
34
- orderbookAddrs: baseResponse.book_addrs
33
+ endpointAddr: baseResponse.endpoint_addr
35
34
  };
36
35
  }
37
36
  /**
@@ -163,20 +162,6 @@ var EngineQueryClient = class extends EngineBaseClient {
163
162
  )
164
163
  };
165
164
  }
166
- /**
167
- * Retrieves min deposit rates for all spot products from the engine
168
- */
169
- async getMinDepositRates() {
170
- const baseResponse = await this.query("min_deposit_rates", {});
171
- return {
172
- minDepositRates: mapValues(baseResponse.min_deposit_rates, (m) => {
173
- return {
174
- productId: m.product_id,
175
- minDepositRate: removeDecimals(m.min_deposit_rate_x18)
176
- };
177
- })
178
- };
179
- }
180
165
  /**
181
166
  * Retrieves an order from the offchain engine
182
167
  *
@@ -199,7 +184,7 @@ var EngineQueryClient = class extends EngineBaseClient {
199
184
  order: params.order,
200
185
  signature: await this.sign(
201
186
  "place_order",
202
- params.orderbookAddr,
187
+ getOrderVerifyingAddress(params.productId),
203
188
  params.chainId,
204
189
  params.order
205
190
  )
@@ -297,7 +282,8 @@ var EngineQueryClient = class extends EngineBaseClient {
297
282
  return acc;
298
283
  },
299
284
  {}
300
- )
285
+ ),
286
+ feeTier: baseResponse.fee_tier
301
287
  };
302
288
  }
303
289
  /**
@@ -349,8 +335,14 @@ var EngineQueryClient = class extends EngineBaseClient {
349
335
  subaccountOwner: params.subaccountOwner,
350
336
  subaccountName: params.subaccountName
351
337
  }),
338
+ // Backend expects string variants of booleans
352
339
  spot_leverage: params.spotLeverage != null ? String(params.spotLeverage) : null,
353
- reduce_only: params.reduceOnly != null ? String(params.reduceOnly) : null
340
+ reduce_only: params.reduceOnly != null ? String(params.reduceOnly) : null,
341
+ isolated: params.isolated != null ? String(params.isolated) : null,
342
+ borrow_margin: (
343
+ // This field is only relevant for isolated orders
344
+ params.isolated && params.isoBorrowMargin != null ? String(params.isoBorrowMargin) : null
345
+ )
354
346
  });
355
347
  return toBigDecimal(baseResponse.max_order_size);
356
348
  }
@@ -384,6 +376,20 @@ var EngineQueryClient = class extends EngineBaseClient {
384
376
  });
385
377
  return toBigDecimal(baseResponse.max_quote_amount);
386
378
  }
379
+ /**
380
+ * Retrieves the max amount of NLP that can be burned.
381
+ *
382
+ * @param params
383
+ */
384
+ async getMaxBurnNlpAmount(params) {
385
+ const baseResponse = await this.query("max_nlp_burnable", {
386
+ sender: subaccountToHex({
387
+ subaccountOwner: params.subaccountOwner,
388
+ subaccountName: params.subaccountName
389
+ })
390
+ });
391
+ return toBigDecimal(baseResponse.max_nlp_amount);
392
+ }
387
393
  /**
388
394
  * Gets the currently linked signer for the subaccount
389
395
  * @param params
@@ -409,13 +415,18 @@ var EngineQueryClient = class extends EngineBaseClient {
409
415
  return toBigDecimal(baseResponse.insurance);
410
416
  }
411
417
  /**
412
- * Gets the orderbook contract address for a given product
413
- * @param productId
414
- * @returns
418
+ * Retrieves the NLP locked and unlocked balances for a subaccount.
419
+ *
420
+ * @param params
415
421
  */
416
- async getOrderbookAddress(productId) {
417
- const contracts = await this.getContracts();
418
- return contracts.orderbookAddrs[productId];
422
+ async getNlpLockedBalances(params) {
423
+ const baseResponse = await this.query("nlp_locked_balances", {
424
+ subaccount: subaccountToHex({
425
+ subaccountOwner: params.subaccountOwner,
426
+ subaccountName: params.subaccountName
427
+ })
428
+ });
429
+ return mapEngineServerNlpLockedBalances(baseResponse);
419
430
  }
420
431
  };
421
432
  export {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/EngineQueryClient.ts"],"sourcesContent":["import {\n encodeSignedOrder,\n MarketWithProduct,\n subaccountToHex,\n} from '@nadohq/contracts';\nimport {\n addDecimals,\n BigDecimal,\n mapValues,\n removeDecimals,\n toBigDecimal,\n toIntegerString,\n} from '@nadohq/utils';\nimport { EngineBaseClient } from './EngineBaseClient';\nimport {\n EngineServerStatusResponse,\n EngineServerSubaccountInfoQueryParams,\n EngineSymbolsResponse,\n GetEngineAllMarketsResponse,\n GetEngineContractsResponse,\n GetEngineEstimatedSubaccountSummaryParams,\n GetEngineHealthGroupsResponse,\n GetEngineInsuranceResponse,\n GetEngineIsolatedPositionsParams,\n GetEngineIsolatedPositionsResponse,\n GetEngineLinkedSignerParams,\n GetEngineLinkedSignerResponse,\n GetEngineMarketLiquidityParams,\n GetEngineMarketLiquidityResponse,\n GetEngineMarketPriceParams,\n GetEngineMarketPriceResponse,\n GetEngineMarketPricesParams,\n GetEngineMarketPricesResponse,\n GetEngineMaxMintNlpAmountParams,\n GetEngineMaxMintNlpAmountResponse,\n GetEngineMaxOrderSizeParams,\n GetEngineMaxOrderSizeResponse,\n GetEngineMaxWithdrawableParams,\n GetEngineMaxWithdrawableResponse,\n GetEngineMinDepositRatesResponse,\n GetEngineOrderParams,\n GetEngineOrderResponse,\n GetEngineSubaccountFeeRatesParams,\n GetEngineSubaccountFeeRatesResponse,\n GetEngineSubaccountOrdersParams,\n GetEngineSubaccountOrdersResponse,\n GetEngineSubaccountProductOrdersParams,\n GetEngineSubaccountProductOrdersResponse,\n GetEngineSubaccountSummaryParams,\n GetEngineSubaccountSummaryResponse,\n GetEngineSymbolsParams,\n SubaccountOrderFeeRates,\n ValidateEngineOrderParams,\n ValidateEngineOrderResponse,\n ValidateSignedEngineOrderParams,\n} from './types';\nimport { mapProductEngineType } from './utils/productEngineTypeMappers';\nimport {\n mapEngineMarketPrice,\n mapEngineServerIsolatedPositions,\n mapEngineServerOrder,\n mapEngineServerPerpProduct,\n mapEngineServerSpotProduct,\n mapEngineServerSymbols,\n mapEngineServerTickLiquidity,\n mapSubaccountSummary,\n} from './utils/queryDataMappers';\n\nexport class EngineQueryClient extends EngineBaseClient {\n /**\n * Retrieves the set of contracts that the engine is interfacing with\n */\n async getContracts(): Promise<GetEngineContractsResponse> {\n const baseResponse = await this.query('contracts', {});\n return {\n chainId: Number(baseResponse.chain_id),\n endpointAddr: baseResponse.endpoint_addr,\n orderbookAddrs: baseResponse.book_addrs,\n };\n }\n\n /**\n * Retrieves current engine status\n */\n async getStatus(): Promise<EngineServerStatusResponse> {\n return this.query('status', {});\n }\n\n /**\n * Retrieves a subaccount summary reflective of the state within the offchain engine. This adheres to the\n * same return interface as the contract version\n *\n * @param params\n */\n async getSubaccountSummary(\n params: GetEngineSubaccountSummaryParams,\n ): Promise<GetEngineSubaccountSummaryResponse> {\n const subaccount = subaccountToHex({\n subaccountOwner: params.subaccountOwner,\n subaccountName: params.subaccountName,\n });\n const baseResponse = await this.query('subaccount_info', {\n subaccount,\n });\n\n return mapSubaccountSummary(baseResponse);\n }\n\n /**\n * Retrieves a list of isolated positions\n *\n * @param params\n */\n async getIsolatedPositions(\n params: GetEngineIsolatedPositionsParams,\n ): Promise<GetEngineIsolatedPositionsResponse> {\n const subaccount = subaccountToHex({\n subaccountOwner: params.subaccountOwner,\n subaccountName: params.subaccountName,\n });\n const baseResponse = await this.query('isolated_positions', {\n subaccount,\n });\n\n return mapEngineServerIsolatedPositions(baseResponse);\n }\n\n /**\n * Retrieves an estimated subaccount summary with the applied transactions\n *\n * @param params\n */\n async getEstimatedSubaccountSummary(\n params: GetEngineEstimatedSubaccountSummaryParams,\n ): Promise<GetEngineSubaccountSummaryResponse> {\n const subaccount = subaccountToHex({\n subaccountOwner: params.subaccountOwner,\n subaccountName: params.subaccountName,\n });\n const queryParams: EngineServerSubaccountInfoQueryParams = {\n subaccount: subaccount,\n txns: params.txs.map(\n (\n tx,\n ): NonNullable<\n EngineServerSubaccountInfoQueryParams['txns']\n >[number] => {\n switch (tx.type) {\n case 'apply_delta':\n return {\n apply_delta: {\n product_id: tx.tx.productId,\n subaccount,\n amount_delta: toIntegerString(tx.tx.amountDelta),\n v_quote_delta: toIntegerString(tx.tx.vQuoteDelta),\n },\n };\n }\n },\n ),\n };\n const baseResponse = await this.query('subaccount_info', {\n subaccount: queryParams.subaccount,\n txns: JSON.stringify(queryParams.txns),\n });\n\n return mapSubaccountSummary(baseResponse);\n }\n\n /**\n * Retrieves symbols and product info\n *\n * @param params\n */\n async getSymbols(\n params: GetEngineSymbolsParams,\n ): Promise<EngineSymbolsResponse> {\n const baseResponse = await this.query('symbols', {\n product_ids: params.productIds,\n product_type:\n params.productType != null\n ? mapProductEngineType(params.productType)\n : undefined,\n });\n return mapEngineServerSymbols(baseResponse);\n }\n\n /**\n * Retrieves all market states as per the offchain engine. Same return interface as contracts\n */\n async getAllMarkets(): Promise<GetEngineAllMarketsResponse> {\n const markets: MarketWithProduct[] = [];\n\n const baseResponse = await this.query('all_products', {});\n baseResponse.spot_products.forEach((spotProduct) => {\n markets.push(mapEngineServerSpotProduct(spotProduct));\n });\n baseResponse.perp_products.forEach((perpProduct) => {\n markets.push(mapEngineServerPerpProduct(perpProduct));\n });\n\n return markets;\n }\n\n /**\n * Retrieves all markets by chain id.\n */\n async getEdgeAllMarkets(): Promise<Record<number, MarketWithProduct[]>> {\n const baseResponse = await this.query('edge_all_products', {});\n\n return mapValues(baseResponse.edge_all_products, (allProducts) => {\n const markets: MarketWithProduct[] = [];\n\n allProducts.spot_products.forEach((spotProduct) => {\n markets.push(mapEngineServerSpotProduct(spotProduct));\n });\n\n allProducts.perp_products.forEach((perpProduct) => {\n markets.push(mapEngineServerPerpProduct(perpProduct));\n });\n\n return markets;\n });\n }\n\n /**\n * Retrieves all health groups (linked spot & perp products) from the engine\n */\n async getHealthGroups(): Promise<GetEngineHealthGroupsResponse> {\n const baseResponse = await this.query('health_groups', {});\n\n return {\n healthGroups: baseResponse.health_groups.map(\n ([spotProductId, perpProductId]) => {\n return {\n spotProductId,\n perpProductId,\n };\n },\n ),\n };\n }\n\n /**\n * Retrieves min deposit rates for all spot products from the engine\n */\n async getMinDepositRates(): Promise<GetEngineMinDepositRatesResponse> {\n const baseResponse = await this.query('min_deposit_rates', {});\n\n return {\n minDepositRates: mapValues(baseResponse.min_deposit_rates, (m) => {\n return {\n productId: m.product_id,\n minDepositRate: removeDecimals(m.min_deposit_rate_x18),\n };\n }),\n };\n }\n\n /**\n * Retrieves an order from the offchain engine\n *\n * @param params\n */\n async getOrder(\n params: GetEngineOrderParams,\n ): Promise<GetEngineOrderResponse> {\n const baseResponse = await this.query('order', {\n digest: params.digest,\n product_id: params.productId,\n });\n\n return mapEngineServerOrder(baseResponse);\n }\n\n /**\n * Signs and validates with the engine that the order is valid to be submitted (i.e. does not violate health reqs)\n *\n * @param params\n */\n async validateOrderParams(\n params: ValidateEngineOrderParams,\n ): Promise<ValidateEngineOrderResponse> {\n const signedOrder = {\n order: params.order,\n signature: await this.sign(\n 'place_order',\n params.orderbookAddr,\n params.chainId,\n params.order,\n ),\n };\n return this.validateSignedOrderParams({\n signedOrder,\n productId: params.productId,\n });\n }\n\n /**\n * Validates an existing signed order with the engine as a pre-check for health\n *\n * @param params\n */\n async validateSignedOrderParams(\n params: ValidateSignedEngineOrderParams,\n ): Promise<ValidateEngineOrderResponse> {\n const baseResponse = await this.query('validate_order', {\n product_id: params.productId,\n order: encodeSignedOrder(params.signedOrder),\n });\n\n return {\n productId: baseResponse.product_id,\n valid: baseResponse.valid,\n };\n }\n\n /**\n * Get all subaccount orders from the engine, per product ID\n * @param params\n */\n async getSubaccountOrders(\n params: GetEngineSubaccountOrdersParams,\n ): Promise<GetEngineSubaccountOrdersResponse> {\n const baseResponse = await this.query('subaccount_orders', {\n sender: subaccountToHex({\n subaccountOwner: params.subaccountOwner,\n subaccountName: params.subaccountName,\n }),\n product_id: params.productId,\n });\n\n return {\n orders: baseResponse.orders.map(mapEngineServerOrder),\n productId: params.productId,\n };\n }\n\n /**\n * Get all subaccount orders from the engine, for multiple products\n * @param params\n */\n async getSubaccountMultiProductOrders(\n params: GetEngineSubaccountProductOrdersParams,\n ): Promise<GetEngineSubaccountProductOrdersResponse> {\n const baseResponse = await this.query('orders', {\n sender: subaccountToHex({\n subaccountOwner: params.subaccountOwner,\n subaccountName: params.subaccountName,\n }),\n product_ids: params.productIds,\n });\n\n return {\n productOrders: baseResponse.product_orders.map((orders) => {\n return {\n orders: orders.orders.map(mapEngineServerOrder),\n productId: orders.product_id,\n };\n }),\n };\n }\n\n /**\n * Gets maker & taker fee rates for order fees\n * @param params\n */\n async getSubaccountFeeRates(\n params: GetEngineSubaccountFeeRatesParams,\n ): Promise<GetEngineSubaccountFeeRatesResponse> {\n const baseResponse = await this.query('fee_rates', {\n sender: subaccountToHex({\n subaccountOwner: params.subaccountOwner,\n subaccountName: params.subaccountName,\n }),\n });\n\n return {\n healthCheckSequencerFee: toBigDecimal(\n baseResponse.health_check_sequencer_fee,\n ),\n liquidationSequencerFee: toBigDecimal(\n baseResponse.liquidation_sequencer_fee,\n ),\n takerSequencerFee: toBigDecimal(baseResponse.taker_sequencer_fee),\n orders: baseResponse.taker_fee_rates_x18.reduce(\n (acc, takerRateX18, currIndex) => {\n acc[currIndex] = {\n taker: removeDecimals(takerRateX18),\n maker: removeDecimals(baseResponse.maker_fee_rates_x18[currIndex]),\n };\n return acc;\n },\n {} as Record<number, SubaccountOrderFeeRates>,\n ),\n withdrawal: baseResponse.withdraw_sequencer_fees.reduce(\n (acc, productFee, currIndex) => {\n acc[currIndex] = toBigDecimal(productFee);\n return acc;\n },\n {} as Record<number, BigDecimal>,\n ),\n };\n }\n\n /**\n * Gets \"price ticks\" for a given market, useful for constructing liquidity levels at each price\n * @param params\n */\n async getMarketLiquidity(\n params: GetEngineMarketLiquidityParams,\n ): Promise<GetEngineMarketLiquidityResponse> {\n const baseResponse = await this.query('market_liquidity', {\n product_id: params.productId,\n depth: params.depth,\n });\n return {\n asks: baseResponse.asks.map(mapEngineServerTickLiquidity),\n bids: baseResponse.bids.map(mapEngineServerTickLiquidity),\n };\n }\n\n /**\n * Retrieves the latest price for a given market\n * @param params\n */\n async getMarketPrice(\n params: GetEngineMarketPriceParams,\n ): Promise<GetEngineMarketPriceResponse> {\n const baseResponse = await this.query('market_price', {\n product_id: params.productId,\n });\n return mapEngineMarketPrice(baseResponse);\n }\n\n /**\n * Retrieves the latest prices for provided markets\n * @param params\n */\n async getMarketPrices(\n params: GetEngineMarketPricesParams,\n ): Promise<GetEngineMarketPricesResponse> {\n const baseResponse = await this.query('market_prices', {\n product_ids: params.productIds,\n });\n return {\n marketPrices: baseResponse.market_prices.map(mapEngineMarketPrice),\n };\n }\n\n /**\n * Retrieves the estimated max order size for a product\n * @param params\n */\n async getMaxOrderSize(\n params: GetEngineMaxOrderSizeParams,\n ): Promise<GetEngineMaxOrderSizeResponse> {\n const baseResponse = await this.query('max_order_size', {\n direction: params.side,\n price_x18: toIntegerString(addDecimals(params.price)),\n product_id: params.productId,\n sender: subaccountToHex({\n subaccountOwner: params.subaccountOwner,\n subaccountName: params.subaccountName,\n }),\n spot_leverage:\n params.spotLeverage != null ? String(params.spotLeverage) : null,\n reduce_only: params.reduceOnly != null ? String(params.reduceOnly) : null,\n });\n\n return toBigDecimal(baseResponse.max_order_size);\n }\n\n /**\n * Retrieves the estimated max withdrawal size for a product\n * @param params\n */\n async getMaxWithdrawable(\n params: GetEngineMaxWithdrawableParams,\n ): Promise<GetEngineMaxWithdrawableResponse> {\n const baseResponse = await this.query('max_withdrawable', {\n product_id: params.productId,\n sender: subaccountToHex({\n subaccountOwner: params.subaccountOwner,\n subaccountName: params.subaccountName,\n }),\n spot_leverage:\n params.spotLeverage != null ? String(params.spotLeverage) : null,\n });\n\n return toBigDecimal(baseResponse.max_withdrawable);\n }\n\n /**\n * Retrieves the estimated max quote amount for minting NLP.\n *\n * @param params\n */\n async getMaxMintNlpAmount(\n params: GetEngineMaxMintNlpAmountParams,\n ): Promise<GetEngineMaxMintNlpAmountResponse> {\n const baseResponse = await this.query('max_nlp_mintable', {\n sender: subaccountToHex({\n subaccountOwner: params.subaccountOwner,\n subaccountName: params.subaccountName,\n }),\n spot_leverage:\n params.spotLeverage != null ? String(params.spotLeverage) : null,\n });\n\n return toBigDecimal(baseResponse.max_quote_amount);\n }\n\n /**\n * Gets the currently linked signer for the subaccount\n * @param params\n * @returns\n */\n public async getLinkedSigner(\n params: GetEngineLinkedSignerParams,\n ): Promise<GetEngineLinkedSignerResponse> {\n const baseResponse = await this.query('linked_signer', {\n subaccount: subaccountToHex({\n subaccountOwner: params.subaccountOwner,\n subaccountName: params.subaccountName,\n }),\n });\n\n return {\n signer: baseResponse.linked_signer,\n };\n }\n\n /**\n * Gets the insurance funds in USDC.\n * @returns\n */\n public async getInsurance(): Promise<GetEngineInsuranceResponse> {\n const baseResponse = await this.query('insurance', {});\n\n return toBigDecimal(baseResponse.insurance);\n }\n\n /**\n * Gets the orderbook contract address for a given product\n * @param productId\n * @returns\n */\n public async getOrderbookAddress(productId: number): Promise<string> {\n const contracts = await this.getContracts();\n return contracts.orderbookAddrs[productId];\n }\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EAEA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,wBAAwB;AA2CjC,SAAS,4BAA4B;AACrC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEA,IAAM,oBAAN,cAAgC,iBAAiB;AAAA;AAAA;AAAA;AAAA,EAItD,MAAM,eAAoD;AACxD,UAAM,eAAe,MAAM,KAAK,MAAM,aAAa,CAAC,CAAC;AACrD,WAAO;AAAA,MACL,SAAS,OAAO,aAAa,QAAQ;AAAA,MACrC,cAAc,aAAa;AAAA,MAC3B,gBAAgB,aAAa;AAAA,IAC/B;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,YAAiD;AACrD,WAAO,KAAK,MAAM,UAAU,CAAC,CAAC;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,qBACJ,QAC6C;AAC7C,UAAM,aAAa,gBAAgB;AAAA,MACjC,iBAAiB,OAAO;AAAA,MACxB,gBAAgB,OAAO;AAAA,IACzB,CAAC;AACD,UAAM,eAAe,MAAM,KAAK,MAAM,mBAAmB;AAAA,MACvD;AAAA,IACF,CAAC;AAED,WAAO,qBAAqB,YAAY;AAAA,EAC1C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,qBACJ,QAC6C;AAC7C,UAAM,aAAa,gBAAgB;AAAA,MACjC,iBAA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AO,gBAAgB,OAAO,OAAO,OAAO,YAAY,IAAI;AAAA,IAChE,CAAC;AAED,WAAO,aAAa,aAAa,gBAAgB;AAAA,EACnD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,oBACJ,QAC4C;AAC5C,UAAM,eAAe,MAAM,KAAK,MAAM,oBAAoB;AAAA,MACxD,QAAQ,gBAAgB;AAAA,QACtB,iBAAiB,OAAO;AAAA,QACxB,gBAAgB,OAAO;AAAA,MACzB,CAAC;AAAA,MACD,eACE,OAAO,gBAAgB,OAAO,OAAO,OAAO,YAAY,IAAI;AAAA,IAChE,CAAC;AAED,WAAO,aAAa,aAAa,gBAAgB;AAAA,EACnD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAa,gBACX,QACwC;AACxC,UAAM,eAAe,MAAM,KAAK,MAAM,iBAAiB;AAAA,MACrD,YAAY,gBAAgB;AAAA,QAC1B,iBAAiB,OAAO;AAAA,QACxB,gBAAgB,OAAO;AAAA,MACzB,CAAC;AAAA,IACH,CAAC;AAED,WAAO;AAAA,MACL,QAAQ,aAAa;AAAA,IACvB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAa,eAAoD;AAC/D,UAAM,eAAe,MAAM,KAAK,MAAM,aAAa,CAAC,CAAC;AAErD,WAAO,aAAa,aAAa,SAAS;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAa,oBAAoB,WAAoC;AACnE,UAAM,YAAY,MAAM,KAAK,aAAa;AAC1C,WAAO,UAAU,eAAe,SAAS;AAAA,EAC3C;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/EngineQueryClient.ts"],"sourcesContent":["import {\n addDecimals,\n BigDecimal,\n encodeSignedOrder,\n getOrderVerifyingAddress,\n mapValues,\n MarketWithProduct,\n removeDecimals,\n subaccountToHex,\n toBigDecimal,\n toIntegerString,\n} from '@nadohq/shared';\nimport { EngineBaseClient } from './EngineBaseClient';\nimport {\n EngineServerStatusResponse,\n EngineServerSubaccountInfoQueryParams,\n EngineSymbolsResponse,\n GetEngineAllMarketsResponse,\n GetEngineContractsResponse,\n GetEngineEstimatedSubaccountSummaryParams,\n GetEngineHealthGroupsResponse,\n GetEngineInsuranceResponse,\n GetEngineIsolatedPositionsParams,\n GetEngineIsolatedPositionsResponse,\n GetEngineLinkedSignerParams,\n GetEngineLinkedSignerResponse,\n GetEngineMarketLiquidityParams,\n GetEngineMarketLiquidityResponse,\n GetEngineMarketPriceParams,\n GetEngineMarketPriceResponse,\n GetEngineMarketPricesParams,\n GetEngineMarketPricesResponse,\n GetEngineMaxBurnNlpAmountParams,\n GetEngineMaxBurnNlpAmountResponse,\n GetEngineMaxMintNlpAmountParams,\n GetEngineMaxMintNlpAmountResponse,\n GetEngineMaxOrderSizeParams,\n GetEngineMaxOrderSizeResponse,\n GetEngineMaxWithdrawableParams,\n GetEngineMaxWithdrawableResponse,\n GetEngineNlpLockedBalancesParams,\n GetEngineNlpLockedBalancesResponse,\n GetEngineOrderParams,\n GetEngineOrderResponse,\n GetEngineSubaccountFeeRatesParams,\n GetEngineSubaccountFeeRatesResponse,\n GetEngineSubaccountOrdersParams,\n GetEngineSubaccountOrdersResponse,\n GetEngineSubaccountProductOrdersParams,\n GetEngineSubaccountProductOrdersResponse,\n GetEngineSubaccountSummaryParams,\n GetEngineSubaccountSummaryResponse,\n GetEngineSymbolsParams,\n SubaccountOrderFeeRates,\n ValidateEngineOrderParams,\n ValidateEngineOrderResponse,\n ValidateSignedEngineOrderParams,\n} from './types';\nimport { mapProductEngineType } from './utils/productEngineTypeMappers';\nimport {\n mapEngineMarketPrice,\n mapEngineServerIsolatedPositions,\n mapEngineServerNlpLockedBalances,\n mapEngineServerOrder,\n mapEngineServerPerpProduct,\n mapEngineServerSpotProduct,\n mapEngineServerSymbols,\n mapEngineServerTickLiquidity,\n mapSubaccountSummary,\n} from './utils/queryDataMappers';\n\nexport class EngineQueryClient extends EngineBaseClient {\n /**\n * Retrieves the set of contracts that the engine is interfacing with\n */\n async getContracts(): Promise<GetEngineContractsResponse> {\n const baseResponse = await this.query('contracts', {});\n return {\n chainId: Number(baseResponse.chain_id),\n endpointAddr: baseResponse.endpoint_addr,\n };\n }\n\n /**\n * Retrieves current engine status\n */\n async getStatus(): Promise<EngineServerStatusResponse> {\n return this.query('status', {});\n }\n\n /**\n * Retrieves a subaccount summary reflective of the state within the offchain engine. This adheres to the\n * same return interface as the contract version\n *\n * @param params\n */\n async getSubaccountSummary(\n params: GetEngineSubaccountSummaryParams,\n ): Promise<GetEngineSubaccountSummaryResponse> {\n const subaccount = subaccountToHex({\n subaccountOwner: params.subaccountOwner,\n subaccountName: params.subaccountName,\n });\n const baseResponse = await this.query('subaccount_info', {\n subaccount,\n });\n\n return mapSubaccountSummary(baseResponse);\n }\n\n /**\n * Retrieves a list of isolated positions\n *\n * @param params\n */\n async getIsolatedPositions(\n params: GetEngineIsolatedPositionsParams,\n ): Promise<GetEngineIsolatedPositionsResponse> {\n const subaccount = subaccountToHex({\n subaccountOwner: params.subaccountOwner,\n subaccountName: params.subaccountName,\n });\n const baseResponse = await this.query('isolated_positions', {\n subaccount,\n });\n\n return mapEngineServerIsolatedPositions(baseResponse);\n }\n\n /**\n * Retrieves an estimated subaccount summary with the applied transactions\n *\n * @param params\n */\n async getEstimatedSubaccountSummary(\n params: GetEngineEstimatedSubaccountSummaryParams,\n ): Promise<GetEngineSubaccountSummaryResponse> {\n const subaccount = subaccountToHex({\n subaccountOwner: params.subaccountOwner,\n subaccountName: params.subaccountName,\n });\n const queryParams: EngineServerSubaccountInfoQueryParams = {\n subaccount: subaccount,\n txns: params.txs.map(\n (\n tx,\n ): NonNullable<\n EngineServerSubaccountInfoQueryParams['txns']\n >[number] => {\n switch (tx.type) {\n case 'apply_delta':\n return {\n apply_delta: {\n product_id: tx.tx.productId,\n subaccount,\n amount_delta: toIntegerString(tx.tx.amountDelta),\n v_quote_delta: toIntegerString(tx.tx.vQuoteDelta),\n },\n };\n }\n },\n ),\n };\n const baseResponse = await this.query('subaccount_info', {\n subaccount: queryParams.subaccount,\n txns: JSON.stringify(queryParams.txns),\n });\n\n return mapSubaccountSummary(baseResponse);\n }\n\n /**\n * Retrieves symbols and product info\n *\n * @param params\n */\n async getSymbols(\n params: GetEngineSymbolsParams,\n ): Promise<EngineSymbolsResponse> {\n const baseResponse = await this.query('symbols', {\n product_ids: params.productIds,\n product_type:\n params.productType != null\n ? mapProductEngineType(params.productType)\n : undefined,\n });\n return mapEngineServerSymbols(baseResponse);\n }\n\n /**\n * Retrieves all market states as per the offchain engine. Same return interface as contracts\n */\n async getAllMarkets(): Promise<GetEngineAllMarketsResponse> {\n const markets: MarketWithProduct[] = [];\n\n const baseResponse = await this.query('all_products', {});\n baseResponse.spot_products.forEach((spotProduct) => {\n markets.push(mapEngineServerSpotProduct(spotProduct));\n });\n baseResponse.perp_products.forEach((perpProduct) => {\n markets.push(mapEngineServerPerpProduct(perpProduct));\n });\n\n return markets;\n }\n\n /**\n * Retrieves all markets by chain id.\n */\n async getEdgeAllMarkets(): Promise<Record<number, MarketWithProduct[]>> {\n const baseResponse = await this.query('edge_all_products', {});\n\n return mapValues(baseResponse.edge_all_products, (allProducts) => {\n const markets: MarketWithProduct[] = [];\n\n allProducts.spot_products.forEach((spotProduct) => {\n markets.push(mapEngineServerSpotProduct(spotProduct));\n });\n\n allProducts.perp_products.forEach((perpProduct) => {\n markets.push(mapEngineServerPerpProduct(perpProduct));\n });\n\n return markets;\n });\n }\n\n /**\n * Retrieves all health groups (linked spot & perp products) from the engine\n */\n async getHealthGroups(): Promise<GetEngineHealthGroupsResponse> {\n const baseResponse = await this.query('health_groups', {});\n\n return {\n healthGroups: baseResponse.health_groups.map(\n ([spotProductId, perpProductId]) => {\n return {\n spotProductId,\n perpProductId,\n };\n },\n ),\n };\n }\n\n /**\n * Retrieves an order from the offchain engine\n *\n * @param params\n */\n async getOrder(\n params: GetEngineOrderParams,\n ): Promise<GetEngineOrderResponse> {\n const baseResponse = await this.query('order', {\n digest: params.digest,\n product_id: params.productId,\n });\n\n return mapEngineServerOrder(baseResponse);\n }\n\n /**\n * Signs and validates with the engine that the order is valid to be submitted (i.e. does not violate health reqs)\n *\n * @param params\n */\n async validateOrderParams(\n params: ValidateEngineOrderParams,\n ): Promise<ValidateEngineOrderResponse> {\n const signedOrder = {\n order: params.order,\n signature: await this.sign(\n 'place_order',\n getOrderVerifyingAddress(params.productId),\n params.chainId,\n params.order,\n ),\n };\n return this.validateSignedOrderParams({\n signedOrder,\n productId: params.productId,\n });\n }\n\n /**\n * Validates an existing signed order with the engine as a pre-check for health\n *\n * @param params\n */\n async validateSignedOrderParams(\n params: ValidateSignedEngineOrderParams,\n ): Promise<ValidateEngineOrderResponse> {\n const baseResponse = await this.query('validate_order', {\n product_id: params.productId,\n order: encodeSignedOrder(params.signedOrder),\n });\n\n return {\n productId: baseResponse.product_id,\n valid: baseResponse.valid,\n };\n }\n\n /**\n * Get all subaccount orders from the engine, per product ID\n * @param params\n */\n async getSubaccountOrders(\n params: GetEngineSubaccountOrdersParams,\n ): Promise<GetEngineSubaccountOrdersResponse> {\n const baseResponse = await this.query('subaccount_orders', {\n sender: subaccountToHex({\n subaccountOwner: params.subaccountOwner,\n subaccountName: params.subaccountName,\n }),\n product_id: params.productId,\n });\n\n return {\n orders: baseResponse.orders.map(mapEngineServerOrder),\n productId: params.productId,\n };\n }\n\n /**\n * Get all subaccount orders from the engine, for multiple products\n * @param params\n */\n async getSubaccountMultiProductOrders(\n params: GetEngineSubaccountProductOrdersParams,\n ): Promise<GetEngineSubaccountProductOrdersResponse> {\n const baseResponse = await this.query('orders', {\n sender: subaccountToHex({\n subaccountOwner: params.subaccountOwner,\n subaccountName: params.subaccountName,\n }),\n product_ids: params.productIds,\n });\n\n return {\n productOrders: baseResponse.product_orders.map((orders) => {\n return {\n orders: orders.orders.map(mapEngineServerOrder),\n productId: orders.product_id,\n };\n }),\n };\n }\n\n /**\n * Gets maker & taker fee rates for order fees\n * @param params\n */\n async getSubaccountFeeRates(\n params: GetEngineSubaccountFeeRatesParams,\n ): Promise<GetEngineSubaccountFeeRatesResponse> {\n const baseResponse = await this.query('fee_rates', {\n sender: subaccountToHex({\n subaccountOwner: params.subaccountOwner,\n subaccountName: params.subaccountName,\n }),\n });\n\n return {\n healthCheckSequencerFee: toBigDecimal(\n baseResponse.health_check_sequencer_fee,\n ),\n liquidationSequencerFee: toBigDecimal(\n baseResponse.liquidation_sequencer_fee,\n ),\n takerSequencerFee: toBigDecimal(baseResponse.taker_sequencer_fee),\n orders: baseResponse.taker_fee_rates_x18.reduce(\n (acc, takerRateX18, currIndex) => {\n acc[currIndex] = {\n taker: removeDecimals(takerRateX18),\n maker: removeDecimals(baseResponse.maker_fee_rates_x18[currIndex]),\n };\n return acc;\n },\n {} as Record<number, SubaccountOrderFeeRates>,\n ),\n withdrawal: baseResponse.withdraw_sequencer_fees.reduce(\n (acc, productFee, currIndex) => {\n acc[currIndex] = toBigDecimal(productFee);\n return acc;\n },\n {} as Record<number, BigDecimal>,\n ),\n feeTier: baseResponse.fee_tier,\n };\n }\n\n /**\n * Gets \"price ticks\" for a given market, useful for constructing liquidity levels at each price\n * @param params\n */\n async getMarketLiquidity(\n params: GetEngineMarketLiquidityParams,\n ): Promise<GetEngineMarketLiquidityResponse> {\n const baseResponse = await this.query('market_liquidity', {\n product_id: params.productId,\n depth: params.depth,\n });\n return {\n asks: baseResponse.asks.map(mapEngineServerTickLiquidity),\n bids: baseResponse.bids.map(mapEngineServerTickLiquidity),\n };\n }\n\n /**\n * Retrieves the latest price for a given market\n * @param params\n */\n async getMarketPrice(\n params: GetEngineMarketPriceParams,\n ): Promise<GetEngineMarketPriceResponse> {\n const baseResponse = await this.query('market_price', {\n product_id: params.productId,\n });\n return mapEngineMarketPrice(baseResponse);\n }\n\n /**\n * Retrieves the latest prices for provided markets\n * @param params\n */\n async getMarketPrices(\n params: GetEngineMarketPricesParams,\n ): Promise<GetEngineMarketPricesResponse> {\n const baseResponse = await this.query('market_prices', {\n product_ids: params.productIds,\n });\n return {\n marketPrices: baseResponse.market_prices.map(mapEngineMarketPrice),\n };\n }\n\n /**\n * Retrieves the estimated max order size for a product\n * @param params\n */\n async getMaxOrderSize(\n params: GetEngineMaxOrderSizeParams,\n ): Promise<GetEngineMaxOrderSizeResponse> {\n const baseResponse = await this.query('max_order_size', {\n direction: params.side,\n price_x18: toIntegerString(addDecimals(params.price)),\n product_id: params.productId,\n sender: subaccountToHex({\n subaccountOwner: params.subaccountOwner,\n subaccountName: params.subaccountName,\n }),\n // Backend expects string variants of booleans\n spot_leverage:\n params.spotLeverage != null ? String(params.spotLeverage) : null,\n reduce_only: params.reduceOnly != null ? String(params.reduceOnly) : null,\n isolated: params.isolated != null ? String(params.isolated) : null,\n borrow_margin:\n // This field is only relevant for isolated orders\n params.isolated && params.isoBorrowMargin != null\n ? String(params.isoBorrowMargin)\n : null,\n });\n\n return toBigDecimal(baseResponse.max_order_size);\n }\n\n /**\n * Retrieves the estimated max withdrawal size for a product\n * @param params\n */\n async getMaxWithdrawable(\n params: GetEngineMaxWithdrawableParams,\n ): Promise<GetEngineMaxWithdrawableResponse> {\n const baseResponse = await this.query('max_withdrawable', {\n product_id: params.productId,\n sender: subaccountToHex({\n subaccountOwner: params.subaccountOwner,\n subaccountName: params.subaccountName,\n }),\n spot_leverage:\n params.spotLeverage != null ? String(params.spotLeverage) : null,\n });\n\n return toBigDecimal(baseResponse.max_withdrawable);\n }\n\n /**\n * Retrieves the estimated max quote amount for minting NLP.\n *\n * @param params\n */\n async getMaxMintNlpAmount(\n params: GetEngineMaxMintNlpAmountParams,\n ): Promise<GetEngineMaxMintNlpAmountResponse> {\n const baseResponse = await this.query('max_nlp_mintable', {\n sender: subaccountToHex({\n subaccountOwner: params.subaccountOwner,\n subaccountName: params.subaccountName,\n }),\n spot_leverage:\n params.spotLeverage != null ? String(params.spotLeverage) : null,\n });\n\n return toBigDecimal(baseResponse.max_quote_amount);\n }\n\n /**\n * Retrieves the max amount of NLP that can be burned.\n *\n * @param params\n */\n async getMaxBurnNlpAmount(\n params: GetEngineMaxBurnNlpAmountParams,\n ): Promise<GetEngineMaxBurnNlpAmountResponse> {\n const baseResponse = await this.query('max_nlp_burnable', {\n sender: subaccountToHex({\n subaccountOwner: params.subaccountOwner,\n subaccountName: params.subaccountName,\n }),\n });\n\n return toBigDecimal(baseResponse.max_nlp_amount);\n }\n\n /**\n * Gets the currently linked signer for the subaccount\n * @param params\n * @returns\n */\n public async getLinkedSigner(\n params: GetEngineLinkedSignerParams,\n ): Promise<GetEngineLinkedSignerResponse> {\n const baseResponse = await this.query('linked_signer', {\n subaccount: subaccountToHex({\n subaccountOwner: params.subaccountOwner,\n subaccountName: params.subaccountName,\n }),\n });\n\n return {\n signer: baseResponse.linked_signer,\n };\n }\n\n /**\n * Gets the insurance funds in USDC.\n * @returns\n */\n public async getInsurance(): Promise<GetEngineInsuranceResponse> {\n const baseResponse = await this.query('insurance', {});\n\n return toBigDecimal(baseResponse.insurance);\n }\n\n /**\n * Retrieves the NLP locked and unlocked balances for a subaccount.\n *\n * @param params\n */\n async getNlpLockedBalances(\n params: GetEngineNlpLockedBalancesParams,\n ): Promise<GetEngineNlpLockedBalancesResponse> {\n const baseResponse = await this.query('nlp_locked_balances', {\n subaccount: subaccountToHex({\n subaccountOwner: params.subaccountOwner,\n subaccountName: params.subaccountName,\n }),\n });\n\n return mapEngineServerNlpLockedBalances(baseResponse);\n }\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,wBAAwB;AA8CjC,SAAS,4BAA4B;AACrC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEA,IAAM,oBAAN,cAAgC,iBAAiB;AAA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CAAC;AAED,WAAO,aAAa,aAAa,cAAc;AAAA,EACjD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAa,gBACX,QACwC;AACxC,UAAM,eAAe,MAAM,KAAK,MAAM,iBAAiB;AAAA,MACrD,YAAY,gBAAgB;AAAA,QAC1B,iBAAiB,OAAO;AAAA,QACxB,gBAAgB,OAAO;AAAA,MACzB,CAAC;AAAA,IACH,CAAC;AAED,WAAO;AAAA,MACL,QAAQ,aAAa;AAAA,IACvB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAa,eAAoD;AAC/D,UAAM,eAAe,MAAM,KAAK,MAAM,aAAa,CAAC,CAAC;AAErD,WAAO,aAAa,aAAa,SAAS;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,qBACJ,QAC6C;AAC7C,UAAM,eAAe,MAAM,KAAK,MAAM,uBAAuB;AAAA,MAC3D,YAAY,gBAAgB;AAAA,QAC1B,iBAAiB,OAAO;AAAA,QACxB,gBAAgB,OAAO;AAAA,MACzB,CAAC;AAAA,IACH,CAAC;AAED,WAAO,iCAAiC,YAAY;AAAA,EACtD;AACF;","names":[]}
@@ -30,8 +30,6 @@ var EngineWebClient = class extends import_EngineBaseClient.EngineBaseClient {
30
30
  */
31
31
  async getIpBlockStatus() {
32
32
  return this.axiosInstance.get(`${this.opts.url}/ip`, {
33
- // Allow all statuses
34
- validateStatus: () => true,
35
33
  // IP checks go through Cloudflare, which uses allow-origin as *, so withCredentials needs to be false
36
34
  withCredentials: false
37
35
  }).then((res) => {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/EngineWebClient.ts"],"sourcesContent":["import { EngineBaseClient } from './EngineBaseClient';\nimport {\n EngineServerIpBlockResponse,\n GetEngineIpBlockStatusResponse,\n GetEngineTimeResponse,\n} from './types';\n\n/**\n * Queries that talk directly to web, _not_ the engine. Placing here in the `engine-client` as we don't have enough\n * use cases to justify a separate package\n */\nexport class EngineWebClient extends EngineBaseClient {\n /**\n * Determines the IP block status for the current client\n */\n async getIpBlockStatus(): Promise<GetEngineIpBlockStatusResponse> {\n return (\n this.axiosInstance\n // Use the /time endpoint and listen to 403 responses\n .get(`${this.opts.url}/ip`, {\n // Allow all statuses\n validateStatus: () => true,\n // IP checks go through Cloudflare, which uses allow-origin as *, so withCredentials needs to be false\n withCredentials: false,\n })\n .then((res) => {\n if (res.status !== 403) {\n return null;\n }\n const resData = res.data as EngineServerIpBlockResponse;\n\n if (!resData.blocked) {\n return null;\n }\n\n return resData.reason === 'ip_query_only' ? 'query_only' : 'blocked';\n })\n );\n }\n\n /**\n * Determines whether a client needs to complete the cloudflare JS challenge to interact with the API\n *\n * @return true if the client needs to complete the JS challenge at '/challenge', false otherwise\n */\n async getRequiresCloudflareAuth(): Promise<boolean> {\n // We use a generic endpoint and check for the CF challenge header\n // Note: this uses a CORS set to the relevant frontend endpoint (ex. testnet.vertexprotocol.com) so it will NOT\n // work from other domains\n return this.axiosInstance\n .get(`${this.opts.url}/cf-check`, {\n // Allow all statuses\n validateStatus: () => true,\n })\n .then((res) => {\n if (res.status !== 403) {\n return false;\n }\n\n return res.headers['cf-mitigated'] === 'challenge';\n });\n }\n\n /**\n * Retrieves current server epoch in milliseconds\n */\n async getTime(): Promise<GetEngineTimeResponse> {\n return this.axiosInstance\n .get(`${this.opts.url}/time`)\n .then((res) => res.data as GetEngineTimeResponse);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8BAAiC;AAW1B,IAAM,kBAAN,cAA8B,yCAAiB;AAAA;AAAA;AAAA;AAAA,EAIpD,MAAM,mBAA4D;AAChE,WACE,KAAK,cAEF,IAAI,GAAG,KAAK,KAAK,GAAG,OAAO;AAAA;AAAA,MAE1B,gBAAgB,MAAM;AAAA;AAAA,MAEtB,iBAAiB;AAAA,IACnB,CAAC,EACA,KAAK,CAAC,QAAQ;AACb,UAAI,IAAI,WAAW,KAAK;AACtB,eAAO;AAAA,MACT;AACA,YAAM,UAAU,IAAI;AAEpB,UAAI,CAAC,QAAQ,SAAS;AACpB,eAAO;AAAA,MACT;AAEA,aAAO,QAAQ,WAAW,kBAAkB,eAAe;AAAA,IAC7D,CAAC;AAAA,EAEP;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,4BAA8C;AAIlD,WAAO,KAAK,cACT,IAAI,GAAG,KAAK,KAAK,GAAG,aAAa;AAAA;AAAA,MAEhC,gBAAgB,MAAM;AAAA,IACxB,CAAC,EACA,KAAK,CAAC,QAAQ;AACb,UAAI,IAAI,WAAW,KAAK;AACtB,eAAO;AAAA,MACT;AAEA,aAAO,IAAI,QAAQ,cAAc,MAAM;AAAA,IACzC,CAAC;AAAA,EACL;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,UAA0C;AAC9C,WAAO,KAAK,cACT,IAAI,GAAG,KAAK,KAAK,GAAG,OAAO,EAC3B,KAAK,CAAC,QAAQ,IAAI,IAA6B;AAAA,EACpD;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/EngineWebClient.ts"],"sourcesContent":["import { EngineBaseClient } from './EngineBaseClient';\nimport {\n EngineServerIpBlockResponse,\n GetEngineIpBlockStatusResponse,\n GetEngineTimeResponse,\n} from './types';\n\n/**\n * Queries that talk directly to web, _not_ the engine. Placing here in the `engine-client` as we don't have enough\n * use cases to justify a separate package\n */\nexport class EngineWebClient extends EngineBaseClient {\n /**\n * Determines the IP block status for the current client\n */\n async getIpBlockStatus(): Promise<GetEngineIpBlockStatusResponse> {\n return (\n this.axiosInstance\n // Use the /time endpoint and listen to 403 responses\n .get(`${this.opts.url}/ip`, {\n // IP checks go through Cloudflare, which uses allow-origin as *, so withCredentials needs to be false\n withCredentials: false,\n })\n .then((res) => {\n if (res.status !== 403) {\n return null;\n }\n const resData = res.data as EngineServerIpBlockResponse;\n\n if (!resData.blocked) {\n return null;\n }\n\n return resData.reason === 'ip_query_only' ? 'query_only' : 'blocked';\n })\n );\n }\n\n /**\n * Determines whether a client needs to complete the cloudflare JS challenge to interact with the API\n *\n * @return true if the client needs to complete the JS challenge at '/challenge', false otherwise\n */\n async getRequiresCloudflareAuth(): Promise<boolean> {\n // We use a generic endpoint and check for the CF challenge header\n // Note: this uses a CORS set to the relevant frontend endpoint (ex. testnet.vertexprotocol.com) so it will NOT\n // work from other domains\n return this.axiosInstance\n .get(`${this.opts.url}/cf-check`, {\n // Allow all statuses\n validateStatus: () => true,\n })\n .then((res) => {\n if (res.status !== 403) {\n return false;\n }\n\n return res.headers['cf-mitigated'] === 'challenge';\n });\n }\n\n /**\n * Retrieves current server epoch in milliseconds\n */\n async getTime(): Promise<GetEngineTimeResponse> {\n return this.axiosInstance\n .get(`${this.opts.url}/time`)\n .then((res) => res.data as GetEngineTimeResponse);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8BAAiC;AAW1B,IAAM,kBAAN,cAA8B,yCAAiB;AAAA;AAAA;AAAA;AAAA,EAIpD,MAAM,mBAA4D;AAChE,WACE,KAAK,cAEF,IAAI,GAAG,KAAK,KAAK,GAAG,OAAO;AAAA;AAAA,MAE1B,iBAAiB;AAAA,IACnB,CAAC,EACA,KAAK,CAAC,QAAQ;AACb,UAAI,IAAI,WAAW,KAAK;AACtB,eAAO;AAAA,MACT;AACA,YAAM,UAAU,IAAI;AAEpB,UAAI,CAAC,QAAQ,SAAS;AACpB,eAAO;AAAA,MACT;AAEA,aAAO,QAAQ,WAAW,kBAAkB,eAAe;AAAA,IAC7D,CAAC;AAAA,EAEP;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,4BAA8C;AAIlD,WAAO,KAAK,cACT,IAAI,GAAG,KAAK,KAAK,GAAG,aAAa;AAAA;AAAA,MAEhC,gBAAgB,MAAM;AAAA,IACxB,CAAC,EACA,KAAK,CAAC,QAAQ;AACb,UAAI,IAAI,WAAW,KAAK;AACtB,eAAO;AAAA,MACT;AAEA,aAAO,IAAI,QAAQ,cAAc,MAAM;AAAA,IACzC,CAAC;AAAA,EACL;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,UAA0C;AAC9C,WAAO,KAAK,cACT,IAAI,GAAG,KAAK,KAAK,GAAG,OAAO,EAC3B,KAAK,CAAC,QAAQ,IAAI,IAA6B;AAAA,EACpD;AACF;","names":[]}
@@ -1,11 +1,10 @@
1
1
  import { EngineBaseClient } from './EngineBaseClient.cjs';
2
2
  import { GetEngineIpBlockStatusResponse, GetEngineTimeResponse } from './types/clientQueryTypes.cjs';
3
- import '@nadohq/contracts';
3
+ import '@nadohq/shared';
4
4
  import 'axios';
5
5
  import './types/serverExecuteTypes.cjs';
6
6
  import './types/serverQueryTypes.cjs';
7
7
  import './types/serverQueryModelTypes.cjs';
8
- import '@nadohq/utils';
9
8
 
10
9
  /**
11
10
  * Queries that talk directly to web, _not_ the engine. Placing here in the `engine-client` as we don't have enough
@@ -1,11 +1,10 @@
1
1
  import { EngineBaseClient } from './EngineBaseClient.js';
2
2
  import { GetEngineIpBlockStatusResponse, GetEngineTimeResponse } from './types/clientQueryTypes.js';
3
- import '@nadohq/contracts';
3
+ import '@nadohq/shared';
4
4
  import 'axios';
5
5
  import './types/serverExecuteTypes.js';
6
6
  import './types/serverQueryTypes.js';
7
7
  import './types/serverQueryModelTypes.js';
8
- import '@nadohq/utils';
9
8
 
10
9
  /**
11
10
  * Queries that talk directly to web, _not_ the engine. Placing here in the `engine-client` as we don't have enough
@@ -6,8 +6,6 @@ var EngineWebClient = class extends EngineBaseClient {
6
6
  */
7
7
  async getIpBlockStatus() {
8
8
  return this.axiosInstance.get(`${this.opts.url}/ip`, {
9
- // Allow all statuses
10
- validateStatus: () => true,
11
9
  // IP checks go through Cloudflare, which uses allow-origin as *, so withCredentials needs to be false
12
10
  withCredentials: false
13
11
  }).then((res) => {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/EngineWebClient.ts"],"sourcesContent":["import { EngineBaseClient } from './EngineBaseClient';\nimport {\n EngineServerIpBlockResponse,\n GetEngineIpBlockStatusResponse,\n GetEngineTimeResponse,\n} from './types';\n\n/**\n * Queries that talk directly to web, _not_ the engine. Placing here in the `engine-client` as we don't have enough\n * use cases to justify a separate package\n */\nexport class EngineWebClient extends EngineBaseClient {\n /**\n * Determines the IP block status for the current client\n */\n async getIpBlockStatus(): Promise<GetEngineIpBlockStatusResponse> {\n return (\n this.axiosInstance\n // Use the /time endpoint and listen to 403 responses\n .get(`${this.opts.url}/ip`, {\n // Allow all statuses\n validateStatus: () => true,\n // IP checks go through Cloudflare, which uses allow-origin as *, so withCredentials needs to be false\n withCredentials: false,\n })\n .then((res) => {\n if (res.status !== 403) {\n return null;\n }\n const resData = res.data as EngineServerIpBlockResponse;\n\n if (!resData.blocked) {\n return null;\n }\n\n return resData.reason === 'ip_query_only' ? 'query_only' : 'blocked';\n })\n );\n }\n\n /**\n * Determines whether a client needs to complete the cloudflare JS challenge to interact with the API\n *\n * @return true if the client needs to complete the JS challenge at '/challenge', false otherwise\n */\n async getRequiresCloudflareAuth(): Promise<boolean> {\n // We use a generic endpoint and check for the CF challenge header\n // Note: this uses a CORS set to the relevant frontend endpoint (ex. testnet.vertexprotocol.com) so it will NOT\n // work from other domains\n return this.axiosInstance\n .get(`${this.opts.url}/cf-check`, {\n // Allow all statuses\n validateStatus: () => true,\n })\n .then((res) => {\n if (res.status !== 403) {\n return false;\n }\n\n return res.headers['cf-mitigated'] === 'challenge';\n });\n }\n\n /**\n * Retrieves current server epoch in milliseconds\n */\n async getTime(): Promise<GetEngineTimeResponse> {\n return this.axiosInstance\n .get(`${this.opts.url}/time`)\n .then((res) => res.data as GetEngineTimeResponse);\n }\n}\n"],"mappings":";AAAA,SAAS,wBAAwB;AAW1B,IAAM,kBAAN,cAA8B,iBAAiB;AAAA;AAAA;AAAA;AAAA,EAIpD,MAAM,mBAA4D;AAChE,WACE,KAAK,cAEF,IAAI,GAAG,KAAK,KAAK,GAAG,OAAO;AAAA;AAAA,MAE1B,gBAAgB,MAAM;AAAA;AAAA,MAEtB,iBAAiB;AAAA,IACnB,CAAC,EACA,KAAK,CAAC,QAAQ;AACb,UAAI,IAAI,WAAW,KAAK;AACtB,eAAO;AAAA,MACT;AACA,YAAM,UAAU,IAAI;AAEpB,UAAI,CAAC,QAAQ,SAAS;AACpB,eAAO;AAAA,MACT;AAEA,aAAO,QAAQ,WAAW,kBAAkB,eAAe;AAAA,IAC7D,CAAC;AAAA,EAEP;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,4BAA8C;AAIlD,WAAO,KAAK,cACT,IAAI,GAAG,KAAK,KAAK,GAAG,aAAa;AAAA;AAAA,MAEhC,gBAAgB,MAAM;AAAA,IACxB,CAAC,EACA,KAAK,CAAC,QAAQ;AACb,UAAI,IAAI,WAAW,KAAK;AACtB,eAAO;AAAA,MACT;AAEA,aAAO,IAAI,QAAQ,cAAc,MAAM;AAAA,IACzC,CAAC;AAAA,EACL;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,UAA0C;AAC9C,WAAO,KAAK,cACT,IAAI,GAAG,KAAK,KAAK,GAAG,OAAO,EAC3B,KAAK,CAAC,QAAQ,IAAI,IAA6B;AAAA,EACpD;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/EngineWebClient.ts"],"sourcesContent":["import { EngineBaseClient } from './EngineBaseClient';\nimport {\n EngineServerIpBlockResponse,\n GetEngineIpBlockStatusResponse,\n GetEngineTimeResponse,\n} from './types';\n\n/**\n * Queries that talk directly to web, _not_ the engine. Placing here in the `engine-client` as we don't have enough\n * use cases to justify a separate package\n */\nexport class EngineWebClient extends EngineBaseClient {\n /**\n * Determines the IP block status for the current client\n */\n async getIpBlockStatus(): Promise<GetEngineIpBlockStatusResponse> {\n return (\n this.axiosInstance\n // Use the /time endpoint and listen to 403 responses\n .get(`${this.opts.url}/ip`, {\n // IP checks go through Cloudflare, which uses allow-origin as *, so withCredentials needs to be false\n withCredentials: false,\n })\n .then((res) => {\n if (res.status !== 403) {\n return null;\n }\n const resData = res.data as EngineServerIpBlockResponse;\n\n if (!resData.blocked) {\n return null;\n }\n\n return resData.reason === 'ip_query_only' ? 'query_only' : 'blocked';\n })\n );\n }\n\n /**\n * Determines whether a client needs to complete the cloudflare JS challenge to interact with the API\n *\n * @return true if the client needs to complete the JS challenge at '/challenge', false otherwise\n */\n async getRequiresCloudflareAuth(): Promise<boolean> {\n // We use a generic endpoint and check for the CF challenge header\n // Note: this uses a CORS set to the relevant frontend endpoint (ex. testnet.vertexprotocol.com) so it will NOT\n // work from other domains\n return this.axiosInstance\n .get(`${this.opts.url}/cf-check`, {\n // Allow all statuses\n validateStatus: () => true,\n })\n .then((res) => {\n if (res.status !== 403) {\n return false;\n }\n\n return res.headers['cf-mitigated'] === 'challenge';\n });\n }\n\n /**\n * Retrieves current server epoch in milliseconds\n */\n async getTime(): Promise<GetEngineTimeResponse> {\n return this.axiosInstance\n .get(`${this.opts.url}/time`)\n .then((res) => res.data as GetEngineTimeResponse);\n }\n}\n"],"mappings":";AAAA,SAAS,wBAAwB;AAW1B,IAAM,kBAAN,cAA8B,iBAAiB;AAAA;AAAA;AAAA;AAAA,EAIpD,MAAM,mBAA4D;AAChE,WACE,KAAK,cAEF,IAAI,GAAG,KAAK,KAAK,GAAG,OAAO;AAAA;AAAA,MAE1B,iBAAiB;AAAA,IACnB,CAAC,EACA,KAAK,CAAC,QAAQ;AACb,UAAI,IAAI,WAAW,KAAK;AACtB,eAAO;AAAA,MACT;AACA,YAAM,UAAU,IAAI;AAEpB,UAAI,CAAC,QAAQ,SAAS;AACpB,eAAO;AAAA,MACT;AAEA,aAAO,QAAQ,WAAW,kBAAkB,eAAe;AAAA,IAC7D,CAAC;AAAA,EAEP;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,4BAA8C;AAIlD,WAAO,KAAK,cACT,IAAI,GAAG,KAAK,KAAK,GAAG,aAAa;AAAA;AAAA,MAEhC,gBAAgB,MAAM;AAAA,IACxB,CAAC,EACA,KAAK,CAAC,QAAQ;AACb,UAAI,IAAI,WAAW,KAAK;AACtB,eAAO;AAAA,MACT;AAEA,aAAO,IAAI,QAAQ,cAAc,MAAM;AAAA,IACzC,CAAC;AAAA,EACL;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,UAA0C;AAC9C,WAAO,KAAK,cACT,IAAI,GAAG,KAAK,KAAK,GAAG,OAAO,EAC3B,KAAK,CAAC,QAAQ,IAAI,IAA6B;AAAA,EACpD;AACF;","names":[]}
@@ -27,18 +27,18 @@ __export(endpoints_exports, {
27
27
  module.exports = __toCommonJS(endpoints_exports);
28
28
  var ENGINE_CLIENT_ENDPOINTS = {
29
29
  local: "http://localhost:80",
30
- arbitrumTestnet: "https://gateway.sepolia-test.vertexprotocol.com/v1",
31
- arbitrum: "https://gateway.prod.vertexprotocol.com/v1"
30
+ arbitrum: "https://gateway.prod.vertexprotocol.com/v1",
31
+ inkTestnet: "https://gateway.test.nado-backend.xyz/v1"
32
32
  };
33
33
  var ENGINE_WS_CLIENT_ENDPOINTS = {
34
34
  local: "ws://localhost:80",
35
- arbitrumTestnet: "wss://gateway.sepolia-test.vertexprotocol.com/v1/ws",
36
- arbitrum: "wss://gateway.prod.vertexprotocol.com/v1/ws"
35
+ arbitrum: "wss://gateway.prod.vertexprotocol.com/v1/ws",
36
+ inkTestnet: "wss://gateway.test.nado-backend.xyz/v1/ws"
37
37
  };
38
38
  var ENGINE_WS_SUBSCRIPTION_CLIENT_ENDPOINTS = {
39
39
  local: "ws://localhost:80",
40
- arbitrumTestnet: "wss://gateway.sepolia-test.vertexprotocol.com/v1/subscribe",
41
- arbitrum: "wss://gateway.prod.vertexprotocol.com/v1/subscribe"
40
+ arbitrum: "wss://gateway.prod.vertexprotocol.com/v1/subscribe",
41
+ inkTestnet: "wss://gateway.test.nado-backend.xyz/v1/subscribe"
42
42
  };
43
43
  // Annotate the CommonJS export names for ESM import in node:
44
44
  0 && (module.exports = {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/endpoints.ts"],"sourcesContent":["import { ChainEnv } from '@nadohq/contracts';\n\nexport const ENGINE_CLIENT_ENDPOINTS: Record<ChainEnv, string> = {\n local: 'http://localhost:80',\n arbitrumTestnet: 'https://gateway.sepolia-test.vertexprotocol.com/v1',\n arbitrum: 'https://gateway.prod.vertexprotocol.com/v1',\n};\n\nexport const ENGINE_WS_CLIENT_ENDPOINTS: Record<ChainEnv, string> = {\n local: 'ws://localhost:80',\n arbitrumTestnet: 'wss://gateway.sepolia-test.vertexprotocol.com/v1/ws',\n arbitrum: 'wss://gateway.prod.vertexprotocol.com/v1/ws',\n};\n\nexport const ENGINE_WS_SUBSCRIPTION_CLIENT_ENDPOINTS: Record<ChainEnv, string> =\n {\n local: 'ws://localhost:80',\n arbitrumTestnet:\n 'wss://gateway.sepolia-test.vertexprotocol.com/v1/subscribe',\n arbitrum: 'wss://gateway.prod.vertexprotocol.com/v1/subscribe',\n };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEO,IAAM,0BAAoD;AAAA,EAC/D,OAAO;AAAA,EACP,iBAAiB;AAAA,EACjB,UAAU;AACZ;AAEO,IAAM,6BAAuD;AAAA,EAClE,OAAO;AAAA,EACP,iBAAiB;AAAA,EACjB,UAAU;AACZ;AAEO,IAAM,0CACX;AAAA,EACE,OAAO;AAAA,EACP,iBACE;AAAA,EACF,UAAU;AACZ;","names":[]}
1
+ {"version":3,"sources":["../src/endpoints.ts"],"sourcesContent":["import { ChainEnv } from '@nadohq/shared';\n\nexport const ENGINE_CLIENT_ENDPOINTS: Record<ChainEnv, string> = {\n local: 'http://localhost:80',\n arbitrum: 'https://gateway.prod.vertexprotocol.com/v1',\n inkTestnet: 'https://gateway.test.nado-backend.xyz/v1',\n};\n\nexport const ENGINE_WS_CLIENT_ENDPOINTS: Record<ChainEnv, string> = {\n local: 'ws://localhost:80',\n arbitrum: 'wss://gateway.prod.vertexprotocol.com/v1/ws',\n inkTestnet: 'wss://gateway.test.nado-backend.xyz/v1/ws',\n};\n\nexport const ENGINE_WS_SUBSCRIPTION_CLIENT_ENDPOINTS: Record<ChainEnv, string> =\n {\n local: 'ws://localhost:80',\n arbitrum: 'wss://gateway.prod.vertexprotocol.com/v1/subscribe',\n inkTestnet: 'wss://gateway.test.nado-backend.xyz/v1/subscribe',\n };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEO,IAAM,0BAAoD;AAAA,EAC/D,OAAO;AAAA,EACP,UAAU;AAAA,EACV,YAAY;AACd;AAEO,IAAM,6BAAuD;AAAA,EAClE,OAAO;AAAA,EACP,UAAU;AAAA,EACV,YAAY;AACd;AAEO,IAAM,0CACX;AAAA,EACE,OAAO;AAAA,EACP,UAAU;AAAA,EACV,YAAY;AACd;","names":[]}
@@ -1,4 +1,4 @@
1
- import { ChainEnv } from '@nadohq/contracts';
1
+ import { ChainEnv } from '@nadohq/shared';
2
2
 
3
3
  declare const ENGINE_CLIENT_ENDPOINTS: Record<ChainEnv, string>;
4
4
  declare const ENGINE_WS_CLIENT_ENDPOINTS: Record<ChainEnv, string>;
@@ -1,4 +1,4 @@
1
- import { ChainEnv } from '@nadohq/contracts';
1
+ import { ChainEnv } from '@nadohq/shared';
2
2
 
3
3
  declare const ENGINE_CLIENT_ENDPOINTS: Record<ChainEnv, string>;
4
4
  declare const ENGINE_WS_CLIENT_ENDPOINTS: Record<ChainEnv, string>;