@nadohq/engine-client 0.15.0 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/EngineBaseClient-DOOXIhnZ.d.ts +75 -0
- package/dist/EngineBaseClient-DOOXIhnZ.d.ts.map +1 -0
- package/dist/EngineBaseClient-L1ue7jBx.d.cts +75 -0
- package/dist/EngineBaseClient-L1ue7jBx.d.cts.map +1 -0
- package/dist/EngineBaseClient-Uc1D8ftx.cjs +150 -0
- package/dist/EngineBaseClient-Uc1D8ftx.cjs.map +1 -0
- package/dist/EngineBaseClient.cjs +3 -167
- package/dist/EngineBaseClient.d.cts +2 -75
- package/dist/EngineBaseClient.d.ts +2 -75
- package/dist/EngineBaseClient.js +112 -131
- package/dist/EngineBaseClient.js.map +1 -1
- package/dist/EngineClient.cjs +13 -38
- package/dist/EngineClient.cjs.map +1 -1
- package/dist/EngineClient.d.cts +8 -18
- package/dist/EngineClient.d.cts.map +1 -0
- package/dist/EngineClient.d.ts +8 -18
- package/dist/EngineClient.d.ts.map +1 -0
- package/dist/EngineClient.js +9 -11
- package/dist/EngineClient.js.map +1 -1
- package/dist/EngineExecuteBuilder-VLrEndhv.d.cts +105 -0
- package/dist/EngineExecuteBuilder-VLrEndhv.d.cts.map +1 -0
- package/dist/EngineExecuteBuilder-t8EQ5Rmp.d.ts +105 -0
- package/dist/EngineExecuteBuilder-t8EQ5Rmp.d.ts.map +1 -0
- package/dist/EngineExecuteBuilder.cjs +232 -277
- package/dist/EngineExecuteBuilder.cjs.map +1 -1
- package/dist/EngineExecuteBuilder.d.cts +2 -108
- package/dist/EngineExecuteBuilder.d.ts +2 -108
- package/dist/EngineExecuteBuilder.js +230 -256
- package/dist/EngineExecuteBuilder.js.map +1 -1
- package/dist/EngineExecuteClient-0EBoXRd7.d.ts +24 -0
- package/dist/EngineExecuteClient-0EBoXRd7.d.ts.map +1 -0
- package/dist/EngineExecuteClient-BGlNK5Le.d.cts +24 -0
- package/dist/EngineExecuteClient-BGlNK5Le.d.cts.map +1 -0
- package/dist/EngineExecuteClient.cjs +57 -110
- package/dist/EngineExecuteClient.cjs.map +1 -1
- package/dist/EngineExecuteClient.d.cts +2 -28
- package/dist/EngineExecuteClient.d.ts +2 -28
- package/dist/EngineExecuteClient.js +54 -83
- package/dist/EngineExecuteClient.js.map +1 -1
- package/dist/EngineQueryClient-C_7p1oRx.d.cts +147 -0
- package/dist/EngineQueryClient-C_7p1oRx.d.cts.map +1 -0
- package/dist/EngineQueryClient-DQwCRaYl.d.ts +147 -0
- package/dist/EngineQueryClient-DQwCRaYl.d.ts.map +1 -0
- package/dist/EngineQueryClient.cjs +354 -448
- package/dist/EngineQueryClient.cjs.map +1 -1
- package/dist/EngineQueryClient.d.cts +2 -149
- package/dist/EngineQueryClient.d.ts +2 -149
- package/dist/EngineQueryClient.js +351 -441
- package/dist/EngineQueryClient.js.map +1 -1
- package/dist/EngineServerFailureError-CDabRrF4.d.ts +11 -0
- package/dist/EngineServerFailureError-CDabRrF4.d.ts.map +1 -0
- package/dist/EngineServerFailureError-DpPY0--L.d.cts +11 -0
- package/dist/EngineServerFailureError-DpPY0--L.d.cts.map +1 -0
- package/dist/EngineWebClient-CEwqgd4t.d.ts +35 -0
- package/dist/EngineWebClient-CEwqgd4t.d.ts.map +1 -0
- package/dist/EngineWebClient-DajZqKAQ.d.cts +35 -0
- package/dist/EngineWebClient-DajZqKAQ.d.cts.map +1 -0
- package/dist/EngineWebClient.cjs +49 -86
- package/dist/EngineWebClient.cjs.map +1 -1
- package/dist/EngineWebClient.d.cts +2 -39
- package/dist/EngineWebClient.d.ts +2 -39
- package/dist/EngineWebClient.js +47 -60
- package/dist/EngineWebClient.js.map +1 -1
- package/dist/clientExecuteTypes-BlJOgCL_.d.cts +91 -0
- package/dist/clientExecuteTypes-BlJOgCL_.d.cts.map +1 -0
- package/dist/clientExecuteTypes-CJ08_c4q.d.ts +91 -0
- package/dist/clientExecuteTypes-CJ08_c4q.d.ts.map +1 -0
- package/dist/clientQueryTypes-DlTtS_mX.d.cts +221 -0
- package/dist/clientQueryTypes-DlTtS_mX.d.cts.map +1 -0
- package/dist/clientQueryTypes-DuRgEeBT.d.ts +221 -0
- package/dist/clientQueryTypes-DuRgEeBT.d.ts.map +1 -0
- package/dist/endpoints.cjs +19 -45
- package/dist/endpoints.cjs.map +1 -1
- package/dist/endpoints.d.cts +4 -2
- package/dist/endpoints.d.cts.map +1 -0
- package/dist/endpoints.d.ts +4 -2
- package/dist/endpoints.d.ts.map +1 -0
- package/dist/endpoints.js +16 -18
- package/dist/endpoints.js.map +1 -1
- package/dist/index-CmCelmEL.d.cts +1 -0
- package/dist/index-D0E78WnU.d.ts +1 -0
- package/dist/index.cjs +26 -31
- package/dist/index.d.cts +12 -20
- package/dist/index.d.ts +12 -20
- package/dist/index.js +8 -6
- package/dist/queryDataMappers-BguxA579.d.ts +21 -0
- package/dist/queryDataMappers-BguxA579.d.ts.map +1 -0
- package/dist/queryDataMappers-DO9yWdLo.d.cts +21 -0
- package/dist/queryDataMappers-DO9yWdLo.d.cts.map +1 -0
- package/dist/serverExecuteTypes-CgbHjnWM.d.ts +92 -0
- package/dist/serverExecuteTypes-CgbHjnWM.d.ts.map +1 -0
- package/dist/serverExecuteTypes-DejTR8Is.d.cts +92 -0
- package/dist/serverExecuteTypes-DejTR8Is.d.cts.map +1 -0
- package/dist/serverQueryModelTypes-85xnbU-a.d.cts +98 -0
- package/dist/serverQueryModelTypes-85xnbU-a.d.cts.map +1 -0
- package/dist/serverQueryModelTypes-CENoy5Hm.d.ts +98 -0
- package/dist/serverQueryModelTypes-CENoy5Hm.d.ts.map +1 -0
- package/dist/serverQueryTypes-B3vC8vxT.d.ts +301 -0
- package/dist/serverQueryTypes-B3vC8vxT.d.ts.map +1 -0
- package/dist/serverQueryTypes-Dva9R2tV.d.cts +301 -0
- package/dist/serverQueryTypes-Dva9R2tV.d.cts.map +1 -0
- package/dist/serverSubscriptionEventTypes-BMUrTkTg.d.cts +135 -0
- package/dist/serverSubscriptionEventTypes-BMUrTkTg.d.cts.map +1 -0
- package/dist/serverSubscriptionEventTypes-UCYAjmt7.d.ts +135 -0
- package/dist/serverSubscriptionEventTypes-UCYAjmt7.d.ts.map +1 -0
- package/dist/serverSubscriptionTypes-BSuYa6z_.d.cts +82 -0
- package/dist/serverSubscriptionTypes-BSuYa6z_.d.cts.map +1 -0
- package/dist/serverSubscriptionTypes-DoMWeKgY.d.ts +82 -0
- package/dist/serverSubscriptionTypes-DoMWeKgY.d.ts.map +1 -0
- package/dist/types/EngineServerFailureError.cjs +9 -33
- package/dist/types/EngineServerFailureError.cjs.map +1 -1
- package/dist/types/EngineServerFailureError.d.cts +2 -11
- package/dist/types/EngineServerFailureError.d.ts +2 -11
- package/dist/types/EngineServerFailureError.js +8 -8
- package/dist/types/EngineServerFailureError.js.map +1 -1
- package/dist/types/clientExecuteTypes.cjs +0 -19
- package/dist/types/clientExecuteTypes.d.cts +2 -91
- package/dist/types/clientExecuteTypes.d.ts +2 -91
- package/dist/types/clientExecuteTypes.js +1 -1
- package/dist/types/clientQueryTypes.cjs +0 -19
- package/dist/types/clientQueryTypes.d.cts +2 -220
- package/dist/types/clientQueryTypes.d.ts +2 -220
- package/dist/types/clientQueryTypes.js +1 -1
- package/dist/types/index.cjs +5 -39
- package/dist/types/index.d.cts +9 -10
- package/dist/types/index.d.ts +9 -10
- package/dist/types/index.js +3 -10
- package/dist/types/serverExecuteTypes.cjs +0 -19
- package/dist/types/serverExecuteTypes.d.cts +2 -93
- package/dist/types/serverExecuteTypes.d.ts +2 -93
- package/dist/types/serverExecuteTypes.js +1 -1
- package/dist/types/serverQueryModelTypes.cjs +0 -19
- package/dist/types/serverQueryModelTypes.d.cts +2 -96
- package/dist/types/serverQueryModelTypes.d.ts +2 -96
- package/dist/types/serverQueryModelTypes.js +1 -1
- package/dist/types/serverQueryTypes.cjs +12 -36
- package/dist/types/serverQueryTypes.cjs.map +1 -1
- package/dist/types/serverQueryTypes.d.cts +2 -310
- package/dist/types/serverQueryTypes.d.ts +2 -310
- package/dist/types/serverQueryTypes.js +11 -11
- package/dist/types/serverQueryTypes.js.map +1 -1
- package/dist/types/serverSubscriptionEventTypes.cjs +0 -19
- package/dist/types/serverSubscriptionEventTypes.d.cts +2 -135
- package/dist/types/serverSubscriptionEventTypes.d.ts +2 -135
- package/dist/types/serverSubscriptionEventTypes.js +1 -1
- package/dist/types/serverSubscriptionTypes.cjs +0 -19
- package/dist/types/serverSubscriptionTypes.d.cts +2 -80
- package/dist/types/serverSubscriptionTypes.d.ts +2 -80
- package/dist/types/serverSubscriptionTypes.js +1 -1
- package/dist/utils/index.cjs +14 -25
- package/dist/utils/index.d.cts +2 -6
- package/dist/utils/index.d.ts +2 -6
- package/dist/utils/index.js +2 -3
- package/dist/utils/productEngineTypeMappers.cjs +16 -44
- package/dist/utils/productEngineTypeMappers.cjs.map +1 -1
- package/dist/utils/productEngineTypeMappers.d.cts +5 -3
- package/dist/utils/productEngineTypeMappers.d.cts.map +1 -0
- package/dist/utils/productEngineTypeMappers.d.ts +5 -3
- package/dist/utils/productEngineTypeMappers.d.ts.map +1 -0
- package/dist/utils/productEngineTypeMappers.js +12 -17
- package/dist/utils/productEngineTypeMappers.js.map +1 -1
- package/dist/utils/queryDataMappers.cjs +204 -292
- package/dist/utils/queryDataMappers.cjs.map +1 -1
- package/dist/utils/queryDataMappers.d.cts +2 -20
- package/dist/utils/queryDataMappers.d.ts +2 -20
- package/dist/utils/queryDataMappers.js +190 -264
- package/dist/utils/queryDataMappers.js.map +1 -1
- package/package.json +9 -9
- package/dist/EngineBaseClient.cjs.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/types/clientExecuteTypes.cjs.map +0 -1
- package/dist/types/clientExecuteTypes.js.map +0 -1
- package/dist/types/clientQueryTypes.cjs.map +0 -1
- package/dist/types/clientQueryTypes.js.map +0 -1
- package/dist/types/index.cjs.map +0 -1
- package/dist/types/index.js.map +0 -1
- package/dist/types/serverExecuteTypes.cjs.map +0 -1
- package/dist/types/serverExecuteTypes.js.map +0 -1
- package/dist/types/serverQueryModelTypes.cjs.map +0 -1
- package/dist/types/serverQueryModelTypes.js.map +0 -1
- package/dist/types/serverSubscriptionEventTypes.cjs.map +0 -1
- package/dist/types/serverSubscriptionEventTypes.js.map +0 -1
- package/dist/types/serverSubscriptionTypes.cjs.map +0 -1
- package/dist/types/serverSubscriptionTypes.js.map +0 -1
- package/dist/utils/index.cjs.map +0 -1
- package/dist/utils/index.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/EngineQueryClient.ts"],"sourcesContent":["import {\n addDecimals,\n encodeSignedOrder,\n getOrderVerifyingAddress,\n mapValues,\n MarketWithProduct,\n removeDecimals,\n subaccountToHex,\n toBigNumber,\n toIntegerString,\n} from '@nadohq/shared';\nimport BigNumber from 'bignumber.js';\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 GetEngineNlpPoolInfoResponse,\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 mapEngineServerNlpPoolInfo,\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 // Backend expects string variants of booleans\n pre_state:\n params.preState !== undefined ? String(params.preState) : undefined,\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: toBigNumber(\n baseResponse.health_check_sequencer_fee,\n ),\n liquidationSequencerFee: toBigNumber(\n baseResponse.liquidation_sequencer_fee,\n ),\n takerSequencerFee: toBigNumber(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] = toBigNumber(productFee);\n return acc;\n },\n {} as Record<number, BigNumber>,\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 avg_price_x18:\n params.avgPrice != null\n ? toIntegerString(addDecimals(params.avgPrice))\n : null,\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 toBigNumber(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 toBigNumber(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 toBigNumber(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 toBigNumber(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 USDT.\n * @returns\n */\n public async getInsurance(): Promise<GetEngineInsuranceResponse> {\n const baseResponse = await this.query('insurance', {});\n\n return toBigNumber(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 /**\n * Retrieves information about all NLP sub-pools\n */\n async getNlpPoolInfo(): Promise<GetEngineNlpPoolInfoResponse> {\n const baseResponse = await this.query('nlp_pool_info', {});\n return mapEngineServerNlpPoolInfo(baseResponse);\n }\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,wBAAwB;AA+CjC,SAAS,4BAA4B;AACrC;AAAA,EACE;AAAA,EACA;AAAA,EACA;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,IAC7B;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,YAAiD;AACrD,WAAO,KAAK,MAAM,UAAU,CAAC,CAAC;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA;AAAA;A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;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,YAAY,aAAa,SAAS;AAAA,EAC3C;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;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,iBAAwD;AAC5D,UAAM,eAAe,MAAM,KAAK,MAAM,iBAAiB,CAAC,CAAC;AACzD,WAAO,2BAA2B,YAAY;AAAA,EAChD;AACF;","names":[]}
|
|
1
|
+
{"version":3,"file":"EngineQueryClient.js","names":[],"sources":["../src/EngineQueryClient.ts"],"sourcesContent":["import {\n addDecimals,\n encodeSignedOrder,\n getOrderVerifyingAddress,\n mapValues,\n MarketWithProduct,\n removeDecimals,\n subaccountToHex,\n toBigNumber,\n toIntegerString,\n} from '@nadohq/shared';\nimport BigNumber from 'bignumber.js';\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 GetEngineNlpPoolInfoResponse,\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 mapEngineServerNlpPoolInfo,\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 // Backend expects string variants of booleans\n pre_state:\n params.preState !== undefined ? String(params.preState) : undefined,\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: toBigNumber(\n baseResponse.health_check_sequencer_fee,\n ),\n liquidationSequencerFee: toBigNumber(\n baseResponse.liquidation_sequencer_fee,\n ),\n takerSequencerFee: toBigNumber(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] = toBigNumber(productFee);\n return acc;\n },\n {} as Record<number, BigNumber>,\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 avg_price_x18:\n params.avgPrice != null\n ? toIntegerString(addDecimals(params.avgPrice))\n : null,\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 toBigNumber(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 toBigNumber(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 toBigNumber(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 toBigNumber(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 USDT.\n * @returns\n */\n public async getInsurance(): Promise<GetEngineInsuranceResponse> {\n const baseResponse = await this.query('insurance', {});\n\n return toBigNumber(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 /**\n * Retrieves information about all NLP sub-pools\n */\n async getNlpPoolInfo(): Promise<GetEngineNlpPoolInfoResponse> {\n const baseResponse = await this.query('nlp_pool_info', {});\n return mapEngineServerNlpPoolInfo(baseResponse);\n }\n}\n"],"mappings":";;;;;AAyEA,IAAa,oBAAb,cAAuC,iBAAiB;;;;CAItD,MAAM,eAAoD;EACxD,MAAM,eAAe,MAAM,KAAK,MAAM,aAAa,CAAC,CAAC;EACrD,OAAO;GACL,SAAS,OAAO,aAAa,QAAQ;GACrC,cAAc,aAAa;EAC7B;CACF;;;;CAKA,MAAM,YAAiD;EACrD,OAAO,KAAK,MAAM,UAAU,CAAC,CAAC;CAChC;;;;;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ACJ,QAC4C;EAU5C,OAAO,aAAY,MATQ,KAAK,MAAM,oBAAoB;GACxD,QAAQ,gBAAgB;IACtB,iBAAiB,OAAO;IACxB,gBAAgB,OAAO;GACzB,CAAC;GACD,eACE,OAAO,gBAAgB,OAAO,OAAO,OAAO,YAAY,IAAI;EAChE,CAAC,GAE+B,gBAAgB;CAClD;;;;;;CAOA,MAAM,oBACJ,QAC4C;EAQ5C,OAAO,aAAY,MAPQ,KAAK,MAAM,oBAAoB,EACxD,QAAQ,gBAAgB;GACtB,iBAAiB,OAAO;GACxB,gBAAgB,OAAO;EACzB,CAAC,EACH,CAAC,GAE+B,cAAc;CAChD;;;;;;CAOA,MAAa,gBACX,QACwC;EAQxC,OAAO,EACL,SAAQ,MARiB,KAAK,MAAM,iBAAiB,EACrD,YAAY,gBAAgB;GAC1B,iBAAiB,OAAO;GACxB,gBAAgB,OAAO;EACzB,CAAC,EACH,CAAC,GAGsB,cACvB;CACF;;;;;CAMA,MAAa,eAAoD;EAG/D,OAAO,aAAY,MAFQ,KAAK,MAAM,aAAa,CAAC,CAAC,GAErB,SAAS;CAC3C;;;;;;CAOA,MAAM,qBACJ,QAC6C;EAQ7C,OAAO,iCAAiC,MAPb,KAAK,MAAM,uBAAuB,EAC3D,YAAY,gBAAgB;GAC1B,iBAAiB,OAAO;GACxB,gBAAgB,OAAO;EACzB,CAAC,EACH,CAAC,CAEmD;CACtD;;;;CAKA,MAAM,iBAAwD;EAE5D,OAAO,2BAA2B,MADP,KAAK,MAAM,iBAAiB,CAAC,CAAC,CACX;CAChD;AACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { B as EngineServerQueryFailureResponse } from "./serverQueryTypes-B3vC8vxT.js";
|
|
2
|
+
import { r as EngineServerExecuteFailureResult } from "./serverExecuteTypes-CgbHjnWM.js";
|
|
3
|
+
|
|
4
|
+
//#region src/types/EngineServerFailureError.d.ts
|
|
5
|
+
declare class EngineServerFailureError extends Error {
|
|
6
|
+
readonly responseData: EngineServerQueryFailureResponse | EngineServerExecuteFailureResult;
|
|
7
|
+
constructor(responseData: EngineServerQueryFailureResponse | EngineServerExecuteFailureResult);
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
export { EngineServerFailureError as t };
|
|
11
|
+
//# sourceMappingURL=EngineServerFailureError-CDabRrF4.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EngineServerFailureError-CDabRrF4.d.ts","names":[],"sources":["../src/types/src/types/EngineServerFailureError.ts"],"mappings":";;;;cAGa,wBAAA,SAAiC,KAAA;EAAA,SAEjC,YAAA,EACL,gCAAA,GACA,gCAAA;cAFK,YAAA,EACL,gCAAA,GACA,gCAAA;AAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { B as EngineServerQueryFailureResponse } from "./serverQueryTypes-Dva9R2tV.cjs";
|
|
2
|
+
import { r as EngineServerExecuteFailureResult } from "./serverExecuteTypes-DejTR8Is.cjs";
|
|
3
|
+
|
|
4
|
+
//#region src/types/EngineServerFailureError.d.ts
|
|
5
|
+
declare class EngineServerFailureError extends Error {
|
|
6
|
+
readonly responseData: EngineServerQueryFailureResponse | EngineServerExecuteFailureResult;
|
|
7
|
+
constructor(responseData: EngineServerQueryFailureResponse | EngineServerExecuteFailureResult);
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
export { EngineServerFailureError as t };
|
|
11
|
+
//# sourceMappingURL=EngineServerFailureError-DpPY0--L.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EngineServerFailureError-DpPY0--L.d.cts","names":[],"sources":["../src/types/src/types/EngineServerFailureError.ts"],"mappings":";;;;cAGa,wBAAA,SAAiC,KAAA;EAAA,SAEjC,YAAA,EACL,gCAAA,GACA,gCAAA;cAFK,YAAA,EACL,gCAAA,GACA,gCAAA;AAAA"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { X as GetEngineTimeResponse, d as GetEngineCountryCodeResponse, h as GetEngineIpBlockStatusResponse } from "./clientQueryTypes-DuRgEeBT.js";
|
|
2
|
+
import { t as EngineBaseClient } from "./EngineBaseClient-DOOXIhnZ.js";
|
|
3
|
+
|
|
4
|
+
//#region src/EngineWebClient.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Queries that talk directly to web, _not_ the engine. Placing here in the `engine-client` as we don't have enough
|
|
7
|
+
* use cases to justify a separate package
|
|
8
|
+
*/
|
|
9
|
+
declare class EngineWebClient extends EngineBaseClient {
|
|
10
|
+
/**
|
|
11
|
+
* Determines the IP block status for the current client
|
|
12
|
+
*/
|
|
13
|
+
getIpBlockStatus(): Promise<GetEngineIpBlockStatusResponse>;
|
|
14
|
+
/**
|
|
15
|
+
* Retrieves the caller's country code as detected by the gateway, sourced
|
|
16
|
+
* from the `x-nado-country` response header on `/ip`. Returns `null` when
|
|
17
|
+
* the gateway does not provide it (e.g. local environments).
|
|
18
|
+
*
|
|
19
|
+
* Useful for region-based UI gating such as geoblocking trading competitions.
|
|
20
|
+
*/
|
|
21
|
+
getCountryCode(): Promise<GetEngineCountryCodeResponse>;
|
|
22
|
+
/**
|
|
23
|
+
* Determines whether a client needs to complete the cloudflare JS challenge to interact with the API
|
|
24
|
+
*
|
|
25
|
+
* @return true if the client needs to complete the JS challenge at '/challenge', false otherwise
|
|
26
|
+
*/
|
|
27
|
+
getRequiresCloudflareAuth(): Promise<boolean>;
|
|
28
|
+
/**
|
|
29
|
+
* Retrieves current server epoch in milliseconds
|
|
30
|
+
*/
|
|
31
|
+
getTime(): Promise<GetEngineTimeResponse>;
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
export { EngineWebClient as t };
|
|
35
|
+
//# sourceMappingURL=EngineWebClient-CEwqgd4t.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EngineWebClient-CEwqgd4t.d.ts","names":[],"sources":["../src/src/EngineWebClient.ts"],"mappings":";;;;;;;AAcA;cAAa,eAAA,SAAwB,gBAAA;;;;EAI7B,gBAAA,CAAA,GAAoB,OAAA,CAAQ,8BAAA;EA8BV;;;;;;;EAAlB,cAAA,CAAA,GAAkB,OAAA,CAAQ,4BAAA;EA9B1B;;;;;EA6CA,yBAAA,CAAA,GAA6B,OAAA;EAA7B;;;EAqBA,OAAA,CAAA,GAAW,OAAA,CAAQ,qBAAA;AAAA"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { X as GetEngineTimeResponse, d as GetEngineCountryCodeResponse, h as GetEngineIpBlockStatusResponse } from "./clientQueryTypes-DlTtS_mX.cjs";
|
|
2
|
+
import { t as EngineBaseClient } from "./EngineBaseClient-L1ue7jBx.cjs";
|
|
3
|
+
|
|
4
|
+
//#region src/EngineWebClient.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Queries that talk directly to web, _not_ the engine. Placing here in the `engine-client` as we don't have enough
|
|
7
|
+
* use cases to justify a separate package
|
|
8
|
+
*/
|
|
9
|
+
declare class EngineWebClient extends EngineBaseClient {
|
|
10
|
+
/**
|
|
11
|
+
* Determines the IP block status for the current client
|
|
12
|
+
*/
|
|
13
|
+
getIpBlockStatus(): Promise<GetEngineIpBlockStatusResponse>;
|
|
14
|
+
/**
|
|
15
|
+
* Retrieves the caller's country code as detected by the gateway, sourced
|
|
16
|
+
* from the `x-nado-country` response header on `/ip`. Returns `null` when
|
|
17
|
+
* the gateway does not provide it (e.g. local environments).
|
|
18
|
+
*
|
|
19
|
+
* Useful for region-based UI gating such as geoblocking trading competitions.
|
|
20
|
+
*/
|
|
21
|
+
getCountryCode(): Promise<GetEngineCountryCodeResponse>;
|
|
22
|
+
/**
|
|
23
|
+
* Determines whether a client needs to complete the cloudflare JS challenge to interact with the API
|
|
24
|
+
*
|
|
25
|
+
* @return true if the client needs to complete the JS challenge at '/challenge', false otherwise
|
|
26
|
+
*/
|
|
27
|
+
getRequiresCloudflareAuth(): Promise<boolean>;
|
|
28
|
+
/**
|
|
29
|
+
* Retrieves current server epoch in milliseconds
|
|
30
|
+
*/
|
|
31
|
+
getTime(): Promise<GetEngineTimeResponse>;
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
export { EngineWebClient as t };
|
|
35
|
+
//# sourceMappingURL=EngineWebClient-DajZqKAQ.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EngineWebClient-DajZqKAQ.d.cts","names":[],"sources":["../src/src/EngineWebClient.ts"],"mappings":";;;;;;;AAcA;cAAa,eAAA,SAAwB,gBAAA;;;;EAI7B,gBAAA,CAAA,GAAoB,OAAA,CAAQ,8BAAA;EA8BV;;;;;;;EAAlB,cAAA,CAAA,GAAkB,OAAA,CAAQ,4BAAA;EA9B1B;;;;;EA6CA,yBAAA,CAAA,GAA6B,OAAA;EAA7B;;;EAqBA,OAAA,CAAA,GAAW,OAAA,CAAQ,qBAAA;AAAA"}
|
package/dist/EngineWebClient.cjs
CHANGED
|
@@ -1,89 +1,52 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_EngineBaseClient = require("./EngineBaseClient-Uc1D8ftx.cjs");
|
|
3
|
+
//#region src/EngineWebClient.ts
|
|
4
|
+
const COUNTRY_HEADER = "x-nado-country";
|
|
5
|
+
/**
|
|
6
|
+
* Queries that talk directly to web, _not_ the engine. Placing here in the `engine-client` as we don't have enough
|
|
7
|
+
* use cases to justify a separate package
|
|
8
|
+
*/
|
|
9
|
+
var EngineWebClient = class extends require_EngineBaseClient.EngineBaseClient {
|
|
10
|
+
/**
|
|
11
|
+
* Determines the IP block status for the current client
|
|
12
|
+
*/
|
|
13
|
+
async getIpBlockStatus() {
|
|
14
|
+
return this.axiosInstance.get(`${this.opts.url}/ip`, { withCredentials: false }).then((res) => {
|
|
15
|
+
if (res.status !== 403) return null;
|
|
16
|
+
const resData = res.data;
|
|
17
|
+
if (!resData.blocked) return null;
|
|
18
|
+
return resData.reason === "ip_query_only" ? "query_only" : "blocked";
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Retrieves the caller's country code as detected by the gateway, sourced
|
|
23
|
+
* from the `x-nado-country` response header on `/ip`. Returns `null` when
|
|
24
|
+
* the gateway does not provide it (e.g. local environments).
|
|
25
|
+
*
|
|
26
|
+
* Useful for region-based UI gating such as geoblocking trading competitions.
|
|
27
|
+
*/
|
|
28
|
+
async getCountryCode() {
|
|
29
|
+
return (await this.axiosInstance.get(`${this.opts.url}/ip`, { withCredentials: false })).headers?.[COUNTRY_HEADER] ?? null;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Determines whether a client needs to complete the cloudflare JS challenge to interact with the API
|
|
33
|
+
*
|
|
34
|
+
* @return true if the client needs to complete the JS challenge at '/challenge', false otherwise
|
|
35
|
+
*/
|
|
36
|
+
async getRequiresCloudflareAuth() {
|
|
37
|
+
return this.axiosInstance.get(`${this.opts.url}/cf-check`, { validateStatus: () => true }).then((res) => {
|
|
38
|
+
if (res.status !== 403) return false;
|
|
39
|
+
return res.headers["cf-mitigated"] === "challenge";
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Retrieves current server epoch in milliseconds
|
|
44
|
+
*/
|
|
45
|
+
async getTime() {
|
|
46
|
+
return this.axiosInstance.get(`${this.opts.url}/time`).then((res) => res.data);
|
|
47
|
+
}
|
|
9
48
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
49
|
+
//#endregion
|
|
50
|
+
exports.EngineWebClient = EngineWebClient;
|
|
19
51
|
|
|
20
|
-
// src/EngineWebClient.ts
|
|
21
|
-
var EngineWebClient_exports = {};
|
|
22
|
-
__export(EngineWebClient_exports, {
|
|
23
|
-
EngineWebClient: () => EngineWebClient
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(EngineWebClient_exports);
|
|
26
|
-
var import_EngineBaseClient = require("./EngineBaseClient.cjs");
|
|
27
|
-
var COUNTRY_HEADER = "x-nado-country";
|
|
28
|
-
var EngineWebClient = class extends import_EngineBaseClient.EngineBaseClient {
|
|
29
|
-
/**
|
|
30
|
-
* Determines the IP block status for the current client
|
|
31
|
-
*/
|
|
32
|
-
async getIpBlockStatus() {
|
|
33
|
-
return this.axiosInstance.get(`${this.opts.url}/ip`, {
|
|
34
|
-
// IP checks go through Cloudflare, which uses allow-origin as *, so withCredentials needs to be false
|
|
35
|
-
withCredentials: false
|
|
36
|
-
}).then((res) => {
|
|
37
|
-
if (res.status !== 403) {
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
const resData = res.data;
|
|
41
|
-
if (!resData.blocked) {
|
|
42
|
-
return null;
|
|
43
|
-
}
|
|
44
|
-
return resData.reason === "ip_query_only" ? "query_only" : "blocked";
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Retrieves the caller's country code as detected by the gateway, sourced
|
|
49
|
-
* from the `x-nado-country` response header on `/ip`. Returns `null` when
|
|
50
|
-
* the gateway does not provide it (e.g. local environments).
|
|
51
|
-
*
|
|
52
|
-
* Useful for region-based UI gating such as geoblocking trading competitions.
|
|
53
|
-
*/
|
|
54
|
-
async getCountryCode() {
|
|
55
|
-
const res = await this.axiosInstance.get(`${this.opts.url}/ip`, {
|
|
56
|
-
// IP checks go through Cloudflare, which uses allow-origin as *, so withCredentials needs to be false
|
|
57
|
-
withCredentials: false
|
|
58
|
-
});
|
|
59
|
-
const rawCountry = res.headers?.[COUNTRY_HEADER];
|
|
60
|
-
return rawCountry ?? null;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Determines whether a client needs to complete the cloudflare JS challenge to interact with the API
|
|
64
|
-
*
|
|
65
|
-
* @return true if the client needs to complete the JS challenge at '/challenge', false otherwise
|
|
66
|
-
*/
|
|
67
|
-
async getRequiresCloudflareAuth() {
|
|
68
|
-
return this.axiosInstance.get(`${this.opts.url}/cf-check`, {
|
|
69
|
-
// Allow all statuses
|
|
70
|
-
validateStatus: () => true
|
|
71
|
-
}).then((res) => {
|
|
72
|
-
if (res.status !== 403) {
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
return res.headers["cf-mitigated"] === "challenge";
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Retrieves current server epoch in milliseconds
|
|
80
|
-
*/
|
|
81
|
-
async getTime() {
|
|
82
|
-
return this.axiosInstance.get(`${this.opts.url}/time`).then((res) => res.data);
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
86
|
-
0 && (module.exports = {
|
|
87
|
-
EngineWebClient
|
|
88
|
-
});
|
|
89
52
|
//# sourceMappingURL=EngineWebClient.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/EngineWebClient.ts"],"sourcesContent":["import { EngineBaseClient } from './EngineBaseClient';\nimport {\n EngineServerIpBlockResponse,\n GetEngineCountryCodeResponse,\n GetEngineIpBlockStatusResponse,\n GetEngineTimeResponse,\n} from './types';\n\nconst COUNTRY_HEADER = 'x-nado-country';\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 /ip 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 * Retrieves the caller's country code as detected by the gateway, sourced\n * from the `x-nado-country` response header on `/ip`. Returns `null` when\n * the gateway does not provide it (e.g. local environments).\n *\n * Useful for region-based UI gating such as geoblocking trading competitions.\n */\n async getCountryCode(): Promise<GetEngineCountryCodeResponse> {\n const res = await this.axiosInstance.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\n const rawCountry = res.headers?.[COUNTRY_HEADER] as string | undefined;\n return rawCountry ?? null;\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":"
|
|
1
|
+
{"version":3,"file":"EngineWebClient.cjs","names":["EngineBaseClient"],"sources":["../src/EngineWebClient.ts"],"sourcesContent":["import { EngineBaseClient } from './EngineBaseClient';\nimport {\n EngineServerIpBlockResponse,\n GetEngineCountryCodeResponse,\n GetEngineIpBlockStatusResponse,\n GetEngineTimeResponse,\n} from './types';\n\nconst COUNTRY_HEADER = 'x-nado-country';\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 /ip 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 * Retrieves the caller's country code as detected by the gateway, sourced\n * from the `x-nado-country` response header on `/ip`. Returns `null` when\n * the gateway does not provide it (e.g. local environments).\n *\n * Useful for region-based UI gating such as geoblocking trading competitions.\n */\n async getCountryCode(): Promise<GetEngineCountryCodeResponse> {\n const res = await this.axiosInstance.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\n const rawCountry = res.headers?.[COUNTRY_HEADER] as string | undefined;\n return rawCountry ?? null;\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":";;;AAQA,MAAM,iBAAiB;;;;;AAMvB,IAAa,kBAAb,cAAqCA,yBAAAA,iBAAiB;;;;CAIpD,MAAM,mBAA4D;EAChE,OACE,KAAK,cAEF,IAAI,GAAG,KAAK,KAAK,IAAI,MAAM,EAE1B,iBAAiB,MACnB,CAAC,EACA,MAAM,QAAQ;GACb,IAAI,IAAI,WAAW,KACjB,OAAO;GAET,MAAM,UAAU,IAAI;GAEpB,IAAI,CAAC,QAAQ,SACX,OAAO;GAGT,OAAO,QAAQ,WAAW,kBAAkB,eAAe;EAC7D,CAAC;CAEP;;;;;;;;CASA,MAAM,iBAAwD;EAO5D,QADmB,MALD,KAAK,cAAc,IAAI,GAAG,KAAK,KAAK,IAAI,MAAM,EAE9D,iBAAiB,MACnB,CAAC,GAEsB,UAAU,mBACZ;CACvB;;;;;;CAOA,MAAM,4BAA8C;EAIlD,OAAO,KAAK,cACT,IAAI,GAAG,KAAK,KAAK,IAAI,YAAY,EAEhC,sBAAsB,KACxB,CAAC,EACA,MAAM,QAAQ;GACb,IAAI,IAAI,WAAW,KACjB,OAAO;GAGT,OAAO,IAAI,QAAQ,oBAAoB;EACzC,CAAC;CACL;;;;CAKA,MAAM,UAA0C;EAC9C,OAAO,KAAK,cACT,IAAI,GAAG,KAAK,KAAK,IAAI,MAAM,EAC3B,MAAM,QAAQ,IAAI,IAA6B;CACpD;AACF"}
|
|
@@ -1,39 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import '@nadohq/shared';
|
|
4
|
-
import 'axios';
|
|
5
|
-
import './types/serverExecuteTypes.cjs';
|
|
6
|
-
import './types/serverQueryTypes.cjs';
|
|
7
|
-
import './types/serverQueryModelTypes.cjs';
|
|
8
|
-
import 'bignumber.js';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Queries that talk directly to web, _not_ the engine. Placing here in the `engine-client` as we don't have enough
|
|
12
|
-
* use cases to justify a separate package
|
|
13
|
-
*/
|
|
14
|
-
declare class EngineWebClient extends EngineBaseClient {
|
|
15
|
-
/**
|
|
16
|
-
* Determines the IP block status for the current client
|
|
17
|
-
*/
|
|
18
|
-
getIpBlockStatus(): Promise<GetEngineIpBlockStatusResponse>;
|
|
19
|
-
/**
|
|
20
|
-
* Retrieves the caller's country code as detected by the gateway, sourced
|
|
21
|
-
* from the `x-nado-country` response header on `/ip`. Returns `null` when
|
|
22
|
-
* the gateway does not provide it (e.g. local environments).
|
|
23
|
-
*
|
|
24
|
-
* Useful for region-based UI gating such as geoblocking trading competitions.
|
|
25
|
-
*/
|
|
26
|
-
getCountryCode(): Promise<GetEngineCountryCodeResponse>;
|
|
27
|
-
/**
|
|
28
|
-
* Determines whether a client needs to complete the cloudflare JS challenge to interact with the API
|
|
29
|
-
*
|
|
30
|
-
* @return true if the client needs to complete the JS challenge at '/challenge', false otherwise
|
|
31
|
-
*/
|
|
32
|
-
getRequiresCloudflareAuth(): Promise<boolean>;
|
|
33
|
-
/**
|
|
34
|
-
* Retrieves current server epoch in milliseconds
|
|
35
|
-
*/
|
|
36
|
-
getTime(): Promise<GetEngineTimeResponse>;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export { EngineWebClient };
|
|
1
|
+
import { t as EngineWebClient } from "./EngineWebClient-DajZqKAQ.cjs";
|
|
2
|
+
export { EngineWebClient };
|
|
@@ -1,39 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import '@nadohq/shared';
|
|
4
|
-
import 'axios';
|
|
5
|
-
import './types/serverExecuteTypes.js';
|
|
6
|
-
import './types/serverQueryTypes.js';
|
|
7
|
-
import './types/serverQueryModelTypes.js';
|
|
8
|
-
import 'bignumber.js';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Queries that talk directly to web, _not_ the engine. Placing here in the `engine-client` as we don't have enough
|
|
12
|
-
* use cases to justify a separate package
|
|
13
|
-
*/
|
|
14
|
-
declare class EngineWebClient extends EngineBaseClient {
|
|
15
|
-
/**
|
|
16
|
-
* Determines the IP block status for the current client
|
|
17
|
-
*/
|
|
18
|
-
getIpBlockStatus(): Promise<GetEngineIpBlockStatusResponse>;
|
|
19
|
-
/**
|
|
20
|
-
* Retrieves the caller's country code as detected by the gateway, sourced
|
|
21
|
-
* from the `x-nado-country` response header on `/ip`. Returns `null` when
|
|
22
|
-
* the gateway does not provide it (e.g. local environments).
|
|
23
|
-
*
|
|
24
|
-
* Useful for region-based UI gating such as geoblocking trading competitions.
|
|
25
|
-
*/
|
|
26
|
-
getCountryCode(): Promise<GetEngineCountryCodeResponse>;
|
|
27
|
-
/**
|
|
28
|
-
* Determines whether a client needs to complete the cloudflare JS challenge to interact with the API
|
|
29
|
-
*
|
|
30
|
-
* @return true if the client needs to complete the JS challenge at '/challenge', false otherwise
|
|
31
|
-
*/
|
|
32
|
-
getRequiresCloudflareAuth(): Promise<boolean>;
|
|
33
|
-
/**
|
|
34
|
-
* Retrieves current server epoch in milliseconds
|
|
35
|
-
*/
|
|
36
|
-
getTime(): Promise<GetEngineTimeResponse>;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export { EngineWebClient };
|
|
1
|
+
import { t as EngineWebClient } from "./EngineWebClient-CEwqgd4t.js";
|
|
2
|
+
export { EngineWebClient };
|
package/dist/EngineWebClient.js
CHANGED
|
@@ -1,64 +1,51 @@
|
|
|
1
|
-
// src/EngineWebClient.ts
|
|
2
1
|
import { EngineBaseClient } from "./EngineBaseClient.js";
|
|
3
|
-
|
|
2
|
+
//#region src/EngineWebClient.ts
|
|
3
|
+
const COUNTRY_HEADER = "x-nado-country";
|
|
4
|
+
/**
|
|
5
|
+
* Queries that talk directly to web, _not_ the engine. Placing here in the `engine-client` as we don't have enough
|
|
6
|
+
* use cases to justify a separate package
|
|
7
|
+
*/
|
|
4
8
|
var EngineWebClient = class extends EngineBaseClient {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
async getRequiresCloudflareAuth() {
|
|
44
|
-
return this.axiosInstance.get(`${this.opts.url}/cf-check`, {
|
|
45
|
-
// Allow all statuses
|
|
46
|
-
validateStatus: () => true
|
|
47
|
-
}).then((res) => {
|
|
48
|
-
if (res.status !== 403) {
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
return res.headers["cf-mitigated"] === "challenge";
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Retrieves current server epoch in milliseconds
|
|
56
|
-
*/
|
|
57
|
-
async getTime() {
|
|
58
|
-
return this.axiosInstance.get(`${this.opts.url}/time`).then((res) => res.data);
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
export {
|
|
62
|
-
EngineWebClient
|
|
9
|
+
/**
|
|
10
|
+
* Determines the IP block status for the current client
|
|
11
|
+
*/
|
|
12
|
+
async getIpBlockStatus() {
|
|
13
|
+
return this.axiosInstance.get(`${this.opts.url}/ip`, { withCredentials: false }).then((res) => {
|
|
14
|
+
if (res.status !== 403) return null;
|
|
15
|
+
const resData = res.data;
|
|
16
|
+
if (!resData.blocked) return null;
|
|
17
|
+
return resData.reason === "ip_query_only" ? "query_only" : "blocked";
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Retrieves the caller's country code as detected by the gateway, sourced
|
|
22
|
+
* from the `x-nado-country` response header on `/ip`. Returns `null` when
|
|
23
|
+
* the gateway does not provide it (e.g. local environments).
|
|
24
|
+
*
|
|
25
|
+
* Useful for region-based UI gating such as geoblocking trading competitions.
|
|
26
|
+
*/
|
|
27
|
+
async getCountryCode() {
|
|
28
|
+
return (await this.axiosInstance.get(`${this.opts.url}/ip`, { withCredentials: false })).headers?.[COUNTRY_HEADER] ?? null;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Determines whether a client needs to complete the cloudflare JS challenge to interact with the API
|
|
32
|
+
*
|
|
33
|
+
* @return true if the client needs to complete the JS challenge at '/challenge', false otherwise
|
|
34
|
+
*/
|
|
35
|
+
async getRequiresCloudflareAuth() {
|
|
36
|
+
return this.axiosInstance.get(`${this.opts.url}/cf-check`, { validateStatus: () => true }).then((res) => {
|
|
37
|
+
if (res.status !== 403) return false;
|
|
38
|
+
return res.headers["cf-mitigated"] === "challenge";
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Retrieves current server epoch in milliseconds
|
|
43
|
+
*/
|
|
44
|
+
async getTime() {
|
|
45
|
+
return this.axiosInstance.get(`${this.opts.url}/time`).then((res) => res.data);
|
|
46
|
+
}
|
|
63
47
|
};
|
|
48
|
+
//#endregion
|
|
49
|
+
export { EngineWebClient };
|
|
50
|
+
|
|
64
51
|
//# sourceMappingURL=EngineWebClient.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/EngineWebClient.ts"],"sourcesContent":["import { EngineBaseClient } from './EngineBaseClient';\nimport {\n EngineServerIpBlockResponse,\n GetEngineCountryCodeResponse,\n GetEngineIpBlockStatusResponse,\n GetEngineTimeResponse,\n} from './types';\n\nconst COUNTRY_HEADER = 'x-nado-country';\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 /ip 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 * Retrieves the caller's country code as detected by the gateway, sourced\n * from the `x-nado-country` response header on `/ip`. Returns `null` when\n * the gateway does not provide it (e.g. local environments).\n *\n * Useful for region-based UI gating such as geoblocking trading competitions.\n */\n async getCountryCode(): Promise<GetEngineCountryCodeResponse> {\n const res = await this.axiosInstance.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\n const rawCountry = res.headers?.[COUNTRY_HEADER] as string | undefined;\n return rawCountry ?? null;\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":"
|
|
1
|
+
{"version":3,"file":"EngineWebClient.js","names":[],"sources":["../src/EngineWebClient.ts"],"sourcesContent":["import { EngineBaseClient } from './EngineBaseClient';\nimport {\n EngineServerIpBlockResponse,\n GetEngineCountryCodeResponse,\n GetEngineIpBlockStatusResponse,\n GetEngineTimeResponse,\n} from './types';\n\nconst COUNTRY_HEADER = 'x-nado-country';\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 /ip 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 * Retrieves the caller's country code as detected by the gateway, sourced\n * from the `x-nado-country` response header on `/ip`. Returns `null` when\n * the gateway does not provide it (e.g. local environments).\n *\n * Useful for region-based UI gating such as geoblocking trading competitions.\n */\n async getCountryCode(): Promise<GetEngineCountryCodeResponse> {\n const res = await this.axiosInstance.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\n const rawCountry = res.headers?.[COUNTRY_HEADER] as string | undefined;\n return rawCountry ?? null;\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":";;AAQA,MAAM,iBAAiB;;;;;AAMvB,IAAa,kBAAb,cAAqC,iBAAiB;;;;CAIpD,MAAM,mBAA4D;EAChE,OACE,KAAK,cAEF,IAAI,GAAG,KAAK,KAAK,IAAI,MAAM,EAE1B,iBAAiB,MACnB,CAAC,EACA,MAAM,QAAQ;GACb,IAAI,IAAI,WAAW,KACjB,OAAO;GAET,MAAM,UAAU,IAAI;GAEpB,IAAI,CAAC,QAAQ,SACX,OAAO;GAGT,OAAO,QAAQ,WAAW,kBAAkB,eAAe;EAC7D,CAAC;CAEP;;;;;;;;CASA,MAAM,iBAAwD;EAO5D,QADmB,MALD,KAAK,cAAc,IAAI,GAAG,KAAK,KAAK,IAAI,MAAM,EAE9D,iBAAiB,MACnB,CAAC,GAEsB,UAAU,mBACZ;CACvB;;;;;;CAOA,MAAM,4BAA8C;EAIlD,OAAO,KAAK,cACT,IAAI,GAAG,KAAK,KAAK,IAAI,YAAY,EAEhC,sBAAsB,KACxB,CAAC,EACA,MAAM,QAAQ;GACb,IAAI,IAAI,WAAW,KACjB,OAAO;GAGT,OAAO,IAAI,QAAQ,oBAAoB;EACzC,CAAC;CACL;;;;CAKA,MAAM,UAA0C;EAC9C,OAAO,KAAK,cACT,IAAI,GAAG,KAAK,KAAK,IAAI,MAAM,EAC3B,MAAM,QAAQ,IAAI,IAA6B;CACpD;AACF"}
|