@nadohq/engine-client 0.1.0-alpha.9 → 0.1.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.d.cts +2 -1
- package/dist/EngineBaseClient.d.ts +2 -1
- package/dist/EngineClient.d.cts +1 -0
- package/dist/EngineClient.d.ts +1 -0
- package/dist/EngineExecuteBuilder.cjs +9 -6
- package/dist/EngineExecuteBuilder.cjs.map +1 -1
- package/dist/EngineExecuteBuilder.d.cts +1 -0
- package/dist/EngineExecuteBuilder.d.ts +1 -0
- package/dist/EngineExecuteBuilder.js +9 -6
- package/dist/EngineExecuteBuilder.js.map +1 -1
- package/dist/EngineExecuteClient.cjs +6 -6
- package/dist/EngineExecuteClient.cjs.map +1 -1
- package/dist/EngineExecuteClient.d.cts +2 -1
- package/dist/EngineExecuteClient.d.ts +2 -1
- package/dist/EngineExecuteClient.js +6 -6
- package/dist/EngineExecuteClient.js.map +1 -1
- package/dist/EngineQueryClient.cjs +54 -11
- package/dist/EngineQueryClient.cjs.map +1 -1
- package/dist/EngineQueryClient.d.cts +19 -2
- package/dist/EngineQueryClient.d.ts +19 -2
- package/dist/EngineQueryClient.js +57 -12
- package/dist/EngineQueryClient.js.map +1 -1
- package/dist/EngineWebClient.d.cts +1 -0
- package/dist/EngineWebClient.d.ts +1 -0
- package/dist/endpoints.cjs +6 -6
- package/dist/endpoints.cjs.map +1 -1
- package/dist/endpoints.js +6 -6
- package/dist/endpoints.js.map +1 -1
- package/dist/index.cjs +4 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -8
- package/dist/index.d.ts +9 -8
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/types/clientExecuteTypes.cjs.map +1 -1
- package/dist/types/clientExecuteTypes.d.cts +8 -1
- package/dist/types/clientExecuteTypes.d.ts +8 -1
- package/dist/types/clientQueryTypes.cjs.map +1 -1
- package/dist/types/clientQueryTypes.d.cts +66 -33
- package/dist/types/clientQueryTypes.d.ts +66 -33
- package/dist/types/index.cjs +10 -10
- package/dist/types/index.cjs.map +1 -1
- package/dist/types/index.d.cts +6 -5
- package/dist/types/index.d.ts +6 -5
- package/dist/types/index.js +5 -5
- package/dist/types/index.js.map +1 -1
- package/dist/types/serverExecuteTypes.cjs.map +1 -1
- package/dist/types/serverExecuteTypes.d.cts +8 -1
- package/dist/types/serverExecuteTypes.d.ts +8 -1
- package/dist/types/serverQueryModelTypes.cjs.map +1 -1
- package/dist/types/serverQueryModelTypes.d.cts +24 -1
- package/dist/types/serverQueryModelTypes.d.ts +24 -1
- package/dist/types/serverQueryTypes.cjs +19 -0
- package/dist/types/serverQueryTypes.cjs.map +1 -1
- package/dist/types/serverQueryTypes.d.cts +49 -23
- package/dist/types/serverQueryTypes.d.ts +49 -23
- package/dist/types/serverQueryTypes.js +12 -0
- package/dist/types/serverQueryTypes.js.map +1 -1
- package/dist/types/serverSubscriptionEventTypes.cjs.map +1 -1
- package/dist/types/serverSubscriptionEventTypes.d.cts +7 -2
- package/dist/types/serverSubscriptionEventTypes.d.ts +7 -2
- package/dist/utils/index.d.cts +3 -2
- package/dist/utils/index.d.ts +3 -2
- package/dist/utils/queryDataMappers.cjs +95 -47
- package/dist/utils/queryDataMappers.cjs.map +1 -1
- package/dist/utils/queryDataMappers.d.cts +8 -5
- package/dist/utils/queryDataMappers.d.ts +8 -5
- package/dist/utils/queryDataMappers.js +94 -48
- package/dist/utils/queryDataMappers.js.map +1 -1
- package/package.json +13 -7
- package/src/EngineExecuteBuilder.ts +9 -6
- package/src/EngineExecuteClient.ts +7 -7
- package/src/EngineQueryClient.ts +73 -12
- package/src/endpoints.ts +6 -6
- package/src/index.ts +2 -2
- package/src/types/clientExecuteTypes.ts +9 -2
- package/src/types/clientQueryTypes.ts +76 -32
- package/src/types/index.ts +5 -5
- package/src/types/serverExecuteTypes.ts +9 -2
- package/src/types/serverQueryModelTypes.ts +25 -0
- package/src/types/serverQueryTypes.ts +74 -31
- package/src/types/serverSubscriptionEventTypes.ts +18 -25
- package/src/utils/queryDataMappers.ts +115 -49
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/queryDataMappers.ts"],"sourcesContent":["import {\n BalanceHealthContributions,\n calcTotalBorrowed,\n calcTotalDeposited,\n mapValues,\n PerpMarket,\n ProductEngineType,\n removeDecimals,\n SpotMarket,\n subaccountFromHex,\n toBigDecimal,\n unpackOrderAppendix,\n} from '@nadohq/shared';\nimport {\n EngineMarketPrice,\n EngineOrder,\n EnginePriceTickLiquidity,\n EngineServerIsolatedPositionsResponse,\n EngineServerMarketPrice,\n EngineServerOrderResponse,\n EngineServerPerpProduct,\n EngineServerPriceTickLiquidity,\n EngineServerSpotProduct,\n EngineServerSubaccountInfoResponse,\n EngineServerSymbol,\n EngineServerSymbolsResponse,\n EngineSymbol,\n EngineSymbolsResponse,\n GetEngineIsolatedPositionsResponse,\n GetEngineSubaccountSummaryResponse,\n} from '../types';\nimport { mapEngineServerProductType } from './productEngineTypeMappers';\n\nexport function mapEngineServerTickLiquidity(\n tick: EngineServerPriceTickLiquidity,\n): EnginePriceTickLiquidity {\n return {\n price: removeDecimals(tick[0]),\n liquidity: toBigDecimal(tick[1]),\n };\n}\n\nexport function mapEngineServerOrder(\n order: EngineServerOrderResponse,\n): EngineOrder {\n const subaccount = subaccountFromHex(order.sender);\n return {\n digest: order.digest,\n expiration: Number(order.expiration),\n nonce: order.nonce,\n price: removeDecimals(order.price_x18),\n productId: order.product_id,\n subaccountOwner: subaccount.subaccountOwner,\n subaccountName: subaccount.subaccountName,\n totalAmount: toBigDecimal(order.amount),\n unfilledAmount: toBigDecimal(order.unfilled_amount),\n placementTime: order.placed_at,\n appendix: unpackOrderAppendix(order.appendix),\n };\n}\n\nexport function mapEngineServerSpotProduct(\n product: EngineServerSpotProduct,\n): SpotMarket {\n return {\n type: ProductEngineType.SPOT,\n productId: product.product_id,\n minSize: toBigDecimal(product.book_info.min_size),\n priceIncrement: removeDecimals(product.book_info.price_increment_x18),\n sizeIncrement: toBigDecimal(product.book_info.size_increment),\n product: {\n productId: product.product_id,\n type: ProductEngineType.SPOT,\n totalBorrowed: calcTotalBorrowed(\n product.state.total_borrows_normalized,\n product.state.cumulative_borrows_multiplier_x18,\n ),\n totalDeposited: calcTotalDeposited(\n product.state.total_deposits_normalized,\n product.state.cumulative_deposits_multiplier_x18,\n ),\n oraclePrice: removeDecimals(product.oracle_price_x18),\n interestFloor: removeDecimals(product.config.interest_floor_x18),\n interestInflectionUtil: removeDecimals(\n product.config.interest_inflection_util_x18,\n ),\n interestLargeCap: removeDecimals(product.config.interest_large_cap_x18),\n interestSmallCap: removeDecimals(product.config.interest_small_cap_x18),\n minDepositRate: removeDecimals(product.config.min_deposit_rate_x18),\n longWeightInitial: removeDecimals(product.risk.long_weight_initial_x18),\n longWeightMaintenance: removeDecimals(\n product.risk.long_weight_maintenance_x18,\n ),\n shortWeightInitial: removeDecimals(product.risk.short_weight_initial_x18),\n shortWeightMaintenance: removeDecimals(\n product.risk.short_weight_maintenance_x18,\n ),\n tokenAddr: product.config.token,\n },\n };\n}\n\nexport function mapEngineServerPerpProduct(\n product: EngineServerPerpProduct,\n): PerpMarket {\n return {\n type: ProductEngineType.PERP,\n productId: product.product_id,\n minSize: toBigDecimal(product.book_info.min_size),\n priceIncrement: removeDecimals(product.book_info.price_increment_x18),\n sizeIncrement: toBigDecimal(product.book_info.size_increment),\n product: {\n productId: product.product_id,\n type: ProductEngineType.PERP,\n oraclePrice: removeDecimals(product.oracle_price_x18),\n longWeightInitial: removeDecimals(product.risk.long_weight_initial_x18),\n longWeightMaintenance: removeDecimals(\n product.risk.long_weight_maintenance_x18,\n ),\n shortWeightInitial: removeDecimals(product.risk.short_weight_initial_x18),\n shortWeightMaintenance: removeDecimals(\n product.risk.short_weight_maintenance_x18,\n ),\n openInterest: toBigDecimal(product.state.open_interest),\n cumulativeFundingLong: removeDecimals(\n product.state.cumulative_funding_long_x18,\n ),\n cumulativeFundingShort: removeDecimals(\n product.state.cumulative_funding_short_x18,\n ),\n },\n };\n}\n\nexport function mapEngineServerBalanceHealthContributions(\n healthContributionsForBalance: string[],\n): BalanceHealthContributions {\n return {\n initial: toBigDecimal(healthContributionsForBalance[0]),\n maintenance: toBigDecimal(healthContributionsForBalance[1]),\n unweighted: toBigDecimal(healthContributionsForBalance[2]),\n };\n}\n\nexport function mapSubaccountSummary(\n baseResponse: EngineServerSubaccountInfoResponse,\n): GetEngineSubaccountSummaryResponse {\n const balances: GetEngineSubaccountSummaryResponse['balances'] = [];\n\n baseResponse.spot_balances.forEach((spotBalance) => {\n const product = baseResponse.spot_products.find(\n (product) => product.product_id === spotBalance.product_id,\n );\n if (!product) {\n throw Error(`Could not find product ${spotBalance.product_id}`);\n }\n\n balances.push({\n amount: toBigDecimal(spotBalance.balance.amount),\n healthContributions: mapEngineServerBalanceHealthContributions(\n baseResponse.health_contributions[spotBalance.product_id],\n ),\n ...mapEngineServerSpotProduct(product).product,\n });\n });\n\n baseResponse.perp_balances.forEach((perpBalance) => {\n const product = baseResponse.perp_products.find(\n (product) => product.product_id === perpBalance.product_id,\n );\n if (!product) {\n throw Error(`Could not find product ${perpBalance.product_id}`);\n }\n\n balances.push({\n amount: toBigDecimal(perpBalance.balance.amount),\n vQuoteBalance: toBigDecimal(perpBalance.balance.v_quote_balance),\n healthContributions: mapEngineServerBalanceHealthContributions(\n baseResponse.health_contributions[perpBalance.product_id],\n ),\n ...mapEngineServerPerpProduct(product).product,\n });\n });\n\n return {\n balances: balances,\n exists: baseResponse.exists,\n health: {\n initial: {\n health: toBigDecimal(baseResponse.healths[0].health),\n assets: toBigDecimal(baseResponse.healths[0].assets),\n liabilities: toBigDecimal(baseResponse.healths[0].liabilities),\n },\n maintenance: {\n health: toBigDecimal(baseResponse.healths[1].health),\n assets: toBigDecimal(baseResponse.healths[1].assets),\n liabilities: toBigDecimal(baseResponse.healths[1].liabilities),\n },\n unweighted: {\n health: toBigDecimal(baseResponse.healths[2].health),\n assets: toBigDecimal(baseResponse.healths[2].assets),\n liabilities: toBigDecimal(baseResponse.healths[2].liabilities),\n },\n },\n };\n}\n\nexport function mapEngineServerIsolatedPositions(\n baseResponse: EngineServerIsolatedPositionsResponse,\n): GetEngineIsolatedPositionsResponse {\n return baseResponse.isolated_positions.map((position) => {\n const perpBalance = position.base_balance;\n const quoteBalance = position.quote_balance;\n\n return {\n subaccount: subaccountFromHex(position.subaccount),\n healths: {\n initial: toBigDecimal(position.healths[0].health),\n maintenance: toBigDecimal(position.healths[1].health),\n unweighted: toBigDecimal(position.healths[2].health),\n },\n baseBalance: {\n amount: toBigDecimal(perpBalance.balance.amount),\n vQuoteBalance: toBigDecimal(perpBalance.balance.v_quote_balance),\n // Health contributions === healths for an isolated position\n healthContributions: {\n initial: toBigDecimal(position.base_healths[0]),\n maintenance: toBigDecimal(position.base_healths[1]),\n unweighted: toBigDecimal(position.base_healths[2]),\n },\n ...mapEngineServerPerpProduct(position.base_product).product,\n },\n quoteBalance: {\n amount: toBigDecimal(quoteBalance.balance.amount),\n healthContributions: {\n initial: toBigDecimal(position.quote_healths[0]),\n maintenance: toBigDecimal(position.quote_healths[1]),\n unweighted: toBigDecimal(position.quote_healths[2]),\n },\n ...mapEngineServerSpotProduct(position.quote_product).product,\n },\n };\n });\n}\n\nexport function mapEngineServerSymbols(\n baseResponse: EngineServerSymbolsResponse,\n): EngineSymbolsResponse {\n const symbols: Record<string, EngineSymbol> = mapValues(\n baseResponse.symbols,\n mapEngineServerSymbol,\n );\n\n return {\n symbols,\n };\n}\n\nexport function mapEngineServerSymbol(\n engineServerSymbol: EngineServerSymbol,\n): EngineSymbol {\n return {\n type: mapEngineServerProductType(engineServerSymbol.type),\n productId: engineServerSymbol.product_id,\n symbol: engineServerSymbol.symbol,\n priceIncrement: removeDecimals(engineServerSymbol.price_increment_x18),\n sizeIncrement: toBigDecimal(engineServerSymbol.size_increment),\n minSize: toBigDecimal(engineServerSymbol.min_size),\n minDepth: removeDecimals(engineServerSymbol.min_depth_x18),\n maxSpreadRate: removeDecimals(engineServerSymbol.max_spread_rate_x18),\n makerFeeRate: removeDecimals(engineServerSymbol.maker_fee_rate_x18),\n takerFeeRate: removeDecimals(engineServerSymbol.taker_fee_rate_x18),\n longWeightInitial: removeDecimals(\n engineServerSymbol.long_weight_initial_x18,\n ),\n longWeightMaintenance: removeDecimals(\n engineServerSymbol.long_weight_maintenance_x18,\n ),\n };\n}\n\nexport function mapEngineMarketPrice(\n baseResponse: EngineServerMarketPrice,\n): EngineMarketPrice {\n return {\n ask: removeDecimals(baseResponse.ask_x18),\n bid: removeDecimals(baseResponse.bid_x18),\n productId: baseResponse.product_id,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAYO;AAmBP,sCAA2C;AAEpC,SAAS,6BACd,MAC0B;AAC1B,SAAO;AAAA,IACL,WAAO,8BAAe,KAAK,CAAC,CAAC;AAAA,IAC7B,eAAW,4BAAa,KAAK,CAAC,CAAC;AAAA,EACjC;AACF;AAEO,SAAS,qBACd,OACa;AACb,QAAM,iBAAa,iCAAkB,MAAM,MAAM;AACjD,SAAO;AAAA,IACL,QAAQ,MAAM;AAAA,IACd,YAAY,OAAO,MAAM,UAAU;AAAA,IACnC,OAAO,MAAM;AAAA,IACb,WAAO,8BAAe,MAAM,SAAS;AAAA,IACrC,WAAW,MAAM;AAAA,IACjB,iBAAiB,WAAW;AAAA,IAC5B,gBAAgB,WAAW;AAAA,IAC3B,iBAAa,4BAAa,MAAM,MAAM;AAAA,IACtC,oBAAgB,4BAAa,MAAM,eAAe;AAAA,IAClD,eAAe,MAAM;AAAA,IACrB,cAAU,mCAAoB,MAAM,QAAQ;AAAA,EAC9C;AACF;AAEO,SAAS,2BACd,SACY;AACZ,SAAO;AAAA,IACL,MAAM,gCAAkB;AAAA,IACxB,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BAAmB,QAAQ;AAAA,IACjD,cAAU,8BAAe,mBAAmB,aAAa;AAAA,IACzD,mBAAe,8BAAe,mBAAmB,mBAAmB;AAAA,IACpE,kBAAc,8BAAe,mBAAmB,kBAAkB;AAAA,IAClE,kBAAc,8BAAe,mBAAmB,kBAAkB;AAAA,IAClE,uBAAmB;AAAA,MACjB,mBAAmB;AAAA,IACrB;AAAA,IACA,2BAAuB;AAAA,MACrB,mBAAmB;AAAA,IACrB;AAAA,EACF;AACF;AAEO,SAAS,qBACd,cACmB;AACnB,SAAO;AAAA,IACL,SAAK,8BAAe,aAAa,OAAO;AAAA,IACxC,SAAK,8BAAe,aAAa,OAAO;AAAA,IACxC,WAAW,aAAa;AAAA,EAC1B;AACF;","names":["product"]}
|
|
1
|
+
{"version":3,"sources":["../../src/utils/queryDataMappers.ts"],"sourcesContent":["import {\n BalanceHealthContributions,\n calcTotalBorrowed,\n calcTotalDeposited,\n mapValues,\n PerpMarket,\n ProductEngineType,\n removeDecimals,\n SpotMarket,\n subaccountFromHex,\n toBigNumber,\n unpackOrderAppendix,\n} from '@nadohq/shared';\nimport {\n EngineMarketPrice,\n EngineNlpLockedBalance,\n EngineOrder,\n EnginePriceTickLiquidity,\n EngineServerIsolatedPositionsResponse,\n EngineServerMarketPrice,\n EngineServerNlpLockedBalancesResponse,\n EngineServerNlpPoolInfoResponse,\n EngineServerOrderResponse,\n EngineServerPerpProduct,\n EngineServerPriceTickLiquidity,\n EngineServerSpotProduct,\n EngineServerSubaccountInfoResponse,\n EngineServerSubaccountInfoState,\n EngineServerSymbol,\n EngineServerSymbolsResponse,\n EngineSymbol,\n EngineSymbolsResponse,\n GetEngineIsolatedPositionsResponse,\n GetEngineNlpLockedBalancesResponse,\n GetEngineNlpPoolInfoResponse,\n GetEngineSubaccountSummaryResponse,\n SubaccountSummaryState,\n} from '../types';\nimport { mapEngineServerProductType } from './productEngineTypeMappers';\n\nexport function mapEngineServerTickLiquidity(\n tick: EngineServerPriceTickLiquidity,\n): EnginePriceTickLiquidity {\n return {\n price: removeDecimals(tick[0]),\n liquidity: toBigNumber(tick[1]),\n };\n}\n\nexport function mapEngineServerOrder(\n order: EngineServerOrderResponse,\n): EngineOrder {\n const subaccount = subaccountFromHex(order.sender);\n return {\n digest: order.digest,\n expiration: Number(order.expiration),\n nonce: order.nonce,\n price: removeDecimals(order.price_x18),\n productId: order.product_id,\n subaccountOwner: subaccount.subaccountOwner,\n subaccountName: subaccount.subaccountName,\n totalAmount: toBigNumber(order.amount),\n unfilledAmount: toBigNumber(order.unfilled_amount),\n placementTime: order.placed_at,\n appendix: unpackOrderAppendix(order.appendix),\n };\n}\n\nexport function mapEngineServerSpotProduct(\n product: EngineServerSpotProduct,\n): SpotMarket {\n return {\n type: ProductEngineType.SPOT,\n productId: product.product_id,\n minSize: toBigNumber(product.book_info.min_size),\n priceIncrement: removeDecimals(product.book_info.price_increment_x18),\n sizeIncrement: toBigNumber(product.book_info.size_increment),\n product: {\n productId: product.product_id,\n type: ProductEngineType.SPOT,\n totalBorrowed: calcTotalBorrowed(\n product.state.total_borrows_normalized,\n product.state.cumulative_borrows_multiplier_x18,\n ),\n totalDeposited: calcTotalDeposited(\n product.state.total_deposits_normalized,\n product.state.cumulative_deposits_multiplier_x18,\n ),\n oraclePrice: removeDecimals(product.oracle_price_x18),\n interestFloor: removeDecimals(product.config.interest_floor_x18),\n interestInflectionUtil: removeDecimals(\n product.config.interest_inflection_util_x18,\n ),\n interestLargeCap: removeDecimals(product.config.interest_large_cap_x18),\n interestSmallCap: removeDecimals(product.config.interest_small_cap_x18),\n minDepositRate: removeDecimals(product.config.min_deposit_rate_x18),\n longWeightInitial: removeDecimals(product.risk.long_weight_initial_x18),\n longWeightMaintenance: removeDecimals(\n product.risk.long_weight_maintenance_x18,\n ),\n shortWeightInitial: removeDecimals(product.risk.short_weight_initial_x18),\n shortWeightMaintenance: removeDecimals(\n product.risk.short_weight_maintenance_x18,\n ),\n tokenAddr: product.config.token,\n },\n };\n}\n\nexport function mapEngineServerPerpProduct(\n product: EngineServerPerpProduct,\n): PerpMarket {\n return {\n type: ProductEngineType.PERP,\n productId: product.product_id,\n minSize: toBigNumber(product.book_info.min_size),\n priceIncrement: removeDecimals(product.book_info.price_increment_x18),\n sizeIncrement: toBigNumber(product.book_info.size_increment),\n product: {\n productId: product.product_id,\n type: ProductEngineType.PERP,\n oraclePrice: removeDecimals(product.oracle_price_x18),\n longWeightInitial: removeDecimals(product.risk.long_weight_initial_x18),\n longWeightMaintenance: removeDecimals(\n product.risk.long_weight_maintenance_x18,\n ),\n shortWeightInitial: removeDecimals(product.risk.short_weight_initial_x18),\n shortWeightMaintenance: removeDecimals(\n product.risk.short_weight_maintenance_x18,\n ),\n openInterest: toBigNumber(product.state.open_interest),\n cumulativeFundingLong: removeDecimals(\n product.state.cumulative_funding_long_x18,\n ),\n cumulativeFundingShort: removeDecimals(\n product.state.cumulative_funding_short_x18,\n ),\n },\n };\n}\n\nexport function mapEngineServerBalanceHealthContributions(\n healthContributionsForBalance: string[],\n): BalanceHealthContributions {\n return {\n initial: toBigNumber(healthContributionsForBalance[0]),\n maintenance: toBigNumber(healthContributionsForBalance[1]),\n unweighted: toBigNumber(healthContributionsForBalance[2]),\n };\n}\n\nexport function mapSubaccountSummary(\n baseResponse: EngineServerSubaccountInfoResponse,\n): GetEngineSubaccountSummaryResponse {\n return {\n exists: baseResponse.exists,\n ...mapSubaccountSummaryState(\n baseResponse,\n baseResponse.spot_products,\n baseResponse.perp_products,\n ),\n preState: baseResponse.pre_state\n ? mapSubaccountSummaryState(\n baseResponse.pre_state,\n baseResponse.spot_products,\n baseResponse.perp_products,\n )\n : undefined,\n };\n}\n\nfunction mapSubaccountSummaryState(\n state: EngineServerSubaccountInfoState,\n spotProducts: EngineServerSubaccountInfoResponse['spot_products'],\n perpProducts: EngineServerSubaccountInfoResponse['perp_products'],\n): SubaccountSummaryState {\n const balances: SubaccountSummaryState['balances'] = [];\n\n state.spot_balances.forEach((spotBalance) => {\n const product = spotProducts.find(\n (product) => product.product_id === spotBalance.product_id,\n );\n if (!product) {\n throw Error(`Could not find product ${spotBalance.product_id}`);\n }\n\n balances.push({\n amount: toBigNumber(spotBalance.balance.amount),\n healthContributions: mapEngineServerBalanceHealthContributions(\n state.health_contributions[spotBalance.product_id],\n ),\n ...mapEngineServerSpotProduct(product).product,\n });\n });\n\n state.perp_balances.forEach((perpBalance) => {\n const product = perpProducts.find(\n (product) => product.product_id === perpBalance.product_id,\n );\n if (!product) {\n throw Error(`Could not find product ${perpBalance.product_id}`);\n }\n\n balances.push({\n amount: toBigNumber(perpBalance.balance.amount),\n vQuoteBalance: toBigNumber(perpBalance.balance.v_quote_balance),\n healthContributions: mapEngineServerBalanceHealthContributions(\n state.health_contributions[perpBalance.product_id],\n ),\n ...mapEngineServerPerpProduct(product).product,\n });\n });\n\n return {\n balances,\n health: {\n initial: {\n health: toBigNumber(state.healths[0].health),\n assets: toBigNumber(state.healths[0].assets),\n liabilities: toBigNumber(state.healths[0].liabilities),\n },\n maintenance: {\n health: toBigNumber(state.healths[1].health),\n assets: toBigNumber(state.healths[1].assets),\n liabilities: toBigNumber(state.healths[1].liabilities),\n },\n unweighted: {\n health: toBigNumber(state.healths[2].health),\n assets: toBigNumber(state.healths[2].assets),\n liabilities: toBigNumber(state.healths[2].liabilities),\n },\n },\n };\n}\n\nexport function mapEngineServerIsolatedPositions(\n baseResponse: EngineServerIsolatedPositionsResponse,\n): GetEngineIsolatedPositionsResponse {\n return baseResponse.isolated_positions.map((position) => {\n const perpBalance = position.base_balance;\n const quoteBalance = position.quote_balance;\n\n return {\n subaccount: subaccountFromHex(position.subaccount),\n healths: {\n initial: toBigNumber(position.healths[0].health),\n maintenance: toBigNumber(position.healths[1].health),\n unweighted: toBigNumber(position.healths[2].health),\n },\n baseBalance: {\n amount: toBigNumber(perpBalance.balance.amount),\n vQuoteBalance: toBigNumber(perpBalance.balance.v_quote_balance),\n // Health contributions === healths for an isolated position\n healthContributions: {\n initial: toBigNumber(position.base_healths[0]),\n maintenance: toBigNumber(position.base_healths[1]),\n unweighted: toBigNumber(position.base_healths[2]),\n },\n ...mapEngineServerPerpProduct(position.base_product).product,\n },\n quoteBalance: {\n amount: toBigNumber(quoteBalance.balance.amount),\n healthContributions: {\n initial: toBigNumber(position.quote_healths[0]),\n maintenance: toBigNumber(position.quote_healths[1]),\n unweighted: toBigNumber(position.quote_healths[2]),\n },\n ...mapEngineServerSpotProduct(position.quote_product).product,\n },\n };\n });\n}\n\nexport function mapEngineServerSymbols(\n baseResponse: EngineServerSymbolsResponse,\n): EngineSymbolsResponse {\n const symbols: Record<string, EngineSymbol> = mapValues(\n baseResponse.symbols,\n mapEngineServerSymbol,\n );\n\n return {\n symbols,\n };\n}\n\nexport function mapEngineServerSymbol(\n engineServerSymbol: EngineServerSymbol,\n): EngineSymbol {\n return {\n type: mapEngineServerProductType(engineServerSymbol.type),\n productId: engineServerSymbol.product_id,\n symbol: engineServerSymbol.symbol,\n priceIncrement: removeDecimals(engineServerSymbol.price_increment_x18),\n sizeIncrement: toBigNumber(engineServerSymbol.size_increment),\n minSize: toBigNumber(engineServerSymbol.min_size),\n makerFeeRate: removeDecimals(engineServerSymbol.maker_fee_rate_x18),\n takerFeeRate: removeDecimals(engineServerSymbol.taker_fee_rate_x18),\n longWeightInitial: removeDecimals(\n engineServerSymbol.long_weight_initial_x18,\n ),\n longWeightMaintenance: removeDecimals(\n engineServerSymbol.long_weight_maintenance_x18,\n ),\n maxOpenInterest: removeDecimals(engineServerSymbol.max_open_interest_x18),\n isolatedOnly: engineServerSymbol.isolated_only,\n };\n}\n\nexport function mapEngineMarketPrice(\n baseResponse: EngineServerMarketPrice,\n): EngineMarketPrice {\n return {\n ask: removeDecimals(baseResponse.ask_x18),\n bid: removeDecimals(baseResponse.bid_x18),\n productId: baseResponse.product_id,\n };\n}\n\nexport function mapEngineServerNlpLockedBalances(\n baseResponse: EngineServerNlpLockedBalancesResponse,\n): GetEngineNlpLockedBalancesResponse {\n const lockedBalances: EngineNlpLockedBalance[] =\n baseResponse.locked_balances.map((lockedBalance) => ({\n productId: lockedBalance.balance.product_id,\n balance: toBigNumber(lockedBalance.balance.balance.amount),\n unlockedAt: lockedBalance.unlocked_at,\n }));\n\n return {\n lockedBalances,\n balanceLocked: {\n productId: baseResponse.balance_locked.product_id,\n balance: toBigNumber(baseResponse.balance_locked.balance.amount),\n },\n balanceUnlocked: {\n productId: baseResponse.balance_unlocked.product_id,\n balance: toBigNumber(baseResponse.balance_unlocked.balance.amount),\n },\n };\n}\n\nexport function mapEngineServerNlpPoolInfo(\n baseResponse: EngineServerNlpPoolInfoResponse,\n): GetEngineNlpPoolInfoResponse {\n return {\n nlpPools: baseResponse.nlp_pools.map((pool) => ({\n poolId: pool.pool_id,\n subaccountHex: pool.subaccount,\n ownerAddress: pool.owner,\n balanceWeight: removeDecimals(pool.balance_weight_x18),\n subaccountInfo: mapSubaccountSummary(pool.subaccount_info),\n openOrders: pool.open_orders.map(mapEngineServerOrder),\n })),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAYO;AA0BP,sCAA2C;AAEpC,SAAS,6BACd,MAC0B;AAC1B,SAAO;AAAA,IACL,WAAO,8BAAe,KAAK,CAAC,CAAC;AAAA,IAC7B,eAAW,2BAAY,KAAK,CAAC,CAAC;AAAA,EAChC;AACF;AAEO,SAAS,qBACd,OACa;AACb,QAAM,iBAAa,iCAAkB,MAAM,MAAM;AACjD,SAAO;AAAA,IACL,QAAQ,MAAM;AAAA,IACd,YAAY,OAAO,MAAM,UAAU;AAAA,IACnC,OAAO,MAAM;AAAA,IACb,WAAO,8BAAe,MAAM,SAAS;AAAA,IACrC,WAAW,MAAM;AAAA,IACjB,iBAAiB,WAAW;AAAA,IAC5B,gBAAgB,WAAW;AAAA,IAC3B,iBAAa,2BAAY,MA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AAA,MACf,WAAW,aAAa,iBAAiB;AAAA,MACzC,aAAS,2BAAY,aAAa,iBAAiB,QAAQ,MAAM;AAAA,IACnE;AAAA,EACF;AACF;AAEO,SAAS,2BACd,cAC8B;AAC9B,SAAO;AAAA,IACL,UAAU,aAAa,UAAU,IAAI,CAAC,UAAU;AAAA,MAC9C,QAAQ,KAAK;AAAA,MACb,eAAe,KAAK;AAAA,MACpB,cAAc,KAAK;AAAA,MACnB,mBAAe,8BAAe,KAAK,kBAAkB;AAAA,MACrD,gBAAgB,qBAAqB,KAAK,eAAe;AAAA,MACzD,YAAY,KAAK,YAAY,IAAI,oBAAoB;AAAA,IACvD,EAAE;AAAA,EACJ;AACF;","names":["product"]}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { BalanceHealthContributions, PerpMarket, SpotMarket } from '@nadohq/shared';
|
|
2
|
+
import { EngineServerMarketPrice, EngineServerIsolatedPositionsResponse, EngineServerNlpLockedBalancesResponse, EngineServerNlpPoolInfoResponse, EngineServerOrderResponse, EngineServerSymbol, EngineServerSymbolsResponse, EngineServerPriceTickLiquidity, EngineServerSubaccountInfoResponse } from '../types/serverQueryTypes.cjs';
|
|
3
|
+
import { EngineMarketPrice, GetEngineIsolatedPositionsResponse, GetEngineNlpLockedBalancesResponse, GetEngineNlpPoolInfoResponse, EngineOrder, EngineSymbol, EngineSymbolsResponse, EnginePriceTickLiquidity, GetEngineSubaccountSummaryResponse } from '../types/clientQueryTypes.cjs';
|
|
4
|
+
import { EngineServerPerpProduct, EngineServerSpotProduct } from '../types/serverQueryModelTypes.cjs';
|
|
5
|
+
import 'bignumber.js';
|
|
5
6
|
|
|
6
7
|
declare function mapEngineServerTickLiquidity(tick: EngineServerPriceTickLiquidity): EnginePriceTickLiquidity;
|
|
7
8
|
declare function mapEngineServerOrder(order: EngineServerOrderResponse): EngineOrder;
|
|
@@ -13,5 +14,7 @@ declare function mapEngineServerIsolatedPositions(baseResponse: EngineServerIsol
|
|
|
13
14
|
declare function mapEngineServerSymbols(baseResponse: EngineServerSymbolsResponse): EngineSymbolsResponse;
|
|
14
15
|
declare function mapEngineServerSymbol(engineServerSymbol: EngineServerSymbol): EngineSymbol;
|
|
15
16
|
declare function mapEngineMarketPrice(baseResponse: EngineServerMarketPrice): EngineMarketPrice;
|
|
17
|
+
declare function mapEngineServerNlpLockedBalances(baseResponse: EngineServerNlpLockedBalancesResponse): GetEngineNlpLockedBalancesResponse;
|
|
18
|
+
declare function mapEngineServerNlpPoolInfo(baseResponse: EngineServerNlpPoolInfoResponse): GetEngineNlpPoolInfoResponse;
|
|
16
19
|
|
|
17
|
-
export { mapEngineMarketPrice, mapEngineServerBalanceHealthContributions, mapEngineServerIsolatedPositions, mapEngineServerOrder, mapEngineServerPerpProduct, mapEngineServerSpotProduct, mapEngineServerSymbol, mapEngineServerSymbols, mapEngineServerTickLiquidity, mapSubaccountSummary };
|
|
20
|
+
export { mapEngineMarketPrice, mapEngineServerBalanceHealthContributions, mapEngineServerIsolatedPositions, mapEngineServerNlpLockedBalances, mapEngineServerNlpPoolInfo, mapEngineServerOrder, mapEngineServerPerpProduct, mapEngineServerSpotProduct, mapEngineServerSymbol, mapEngineServerSymbols, mapEngineServerTickLiquidity, mapSubaccountSummary };
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { BalanceHealthContributions, PerpMarket, SpotMarket } from '@nadohq/shared';
|
|
2
|
+
import { EngineServerMarketPrice, EngineServerIsolatedPositionsResponse, EngineServerNlpLockedBalancesResponse, EngineServerNlpPoolInfoResponse, EngineServerOrderResponse, EngineServerSymbol, EngineServerSymbolsResponse, EngineServerPriceTickLiquidity, EngineServerSubaccountInfoResponse } from '../types/serverQueryTypes.js';
|
|
3
|
+
import { EngineMarketPrice, GetEngineIsolatedPositionsResponse, GetEngineNlpLockedBalancesResponse, GetEngineNlpPoolInfoResponse, EngineOrder, EngineSymbol, EngineSymbolsResponse, EnginePriceTickLiquidity, GetEngineSubaccountSummaryResponse } from '../types/clientQueryTypes.js';
|
|
4
|
+
import { EngineServerPerpProduct, EngineServerSpotProduct } from '../types/serverQueryModelTypes.js';
|
|
5
|
+
import 'bignumber.js';
|
|
5
6
|
|
|
6
7
|
declare function mapEngineServerTickLiquidity(tick: EngineServerPriceTickLiquidity): EnginePriceTickLiquidity;
|
|
7
8
|
declare function mapEngineServerOrder(order: EngineServerOrderResponse): EngineOrder;
|
|
@@ -13,5 +14,7 @@ declare function mapEngineServerIsolatedPositions(baseResponse: EngineServerIsol
|
|
|
13
14
|
declare function mapEngineServerSymbols(baseResponse: EngineServerSymbolsResponse): EngineSymbolsResponse;
|
|
14
15
|
declare function mapEngineServerSymbol(engineServerSymbol: EngineServerSymbol): EngineSymbol;
|
|
15
16
|
declare function mapEngineMarketPrice(baseResponse: EngineServerMarketPrice): EngineMarketPrice;
|
|
17
|
+
declare function mapEngineServerNlpLockedBalances(baseResponse: EngineServerNlpLockedBalancesResponse): GetEngineNlpLockedBalancesResponse;
|
|
18
|
+
declare function mapEngineServerNlpPoolInfo(baseResponse: EngineServerNlpPoolInfoResponse): GetEngineNlpPoolInfoResponse;
|
|
16
19
|
|
|
17
|
-
export { mapEngineMarketPrice, mapEngineServerBalanceHealthContributions, mapEngineServerIsolatedPositions, mapEngineServerOrder, mapEngineServerPerpProduct, mapEngineServerSpotProduct, mapEngineServerSymbol, mapEngineServerSymbols, mapEngineServerTickLiquidity, mapSubaccountSummary };
|
|
20
|
+
export { mapEngineMarketPrice, mapEngineServerBalanceHealthContributions, mapEngineServerIsolatedPositions, mapEngineServerNlpLockedBalances, mapEngineServerNlpPoolInfo, mapEngineServerOrder, mapEngineServerPerpProduct, mapEngineServerSpotProduct, mapEngineServerSymbol, mapEngineServerSymbols, mapEngineServerTickLiquidity, mapSubaccountSummary };
|
|
@@ -6,14 +6,14 @@ import {
|
|
|
6
6
|
ProductEngineType,
|
|
7
7
|
removeDecimals,
|
|
8
8
|
subaccountFromHex,
|
|
9
|
-
|
|
9
|
+
toBigNumber,
|
|
10
10
|
unpackOrderAppendix
|
|
11
11
|
} from "@nadohq/shared";
|
|
12
12
|
import { mapEngineServerProductType } from "./productEngineTypeMappers.js";
|
|
13
13
|
function mapEngineServerTickLiquidity(tick) {
|
|
14
14
|
return {
|
|
15
15
|
price: removeDecimals(tick[0]),
|
|
16
|
-
liquidity:
|
|
16
|
+
liquidity: toBigNumber(tick[1])
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
19
|
function mapEngineServerOrder(order) {
|
|
@@ -26,8 +26,8 @@ function mapEngineServerOrder(order) {
|
|
|
26
26
|
productId: order.product_id,
|
|
27
27
|
subaccountOwner: subaccount.subaccountOwner,
|
|
28
28
|
subaccountName: subaccount.subaccountName,
|
|
29
|
-
totalAmount:
|
|
30
|
-
unfilledAmount:
|
|
29
|
+
totalAmount: toBigNumber(order.amount),
|
|
30
|
+
unfilledAmount: toBigNumber(order.unfilled_amount),
|
|
31
31
|
placementTime: order.placed_at,
|
|
32
32
|
appendix: unpackOrderAppendix(order.appendix)
|
|
33
33
|
};
|
|
@@ -36,9 +36,9 @@ function mapEngineServerSpotProduct(product) {
|
|
|
36
36
|
return {
|
|
37
37
|
type: ProductEngineType.SPOT,
|
|
38
38
|
productId: product.product_id,
|
|
39
|
-
minSize:
|
|
39
|
+
minSize: toBigNumber(product.book_info.min_size),
|
|
40
40
|
priceIncrement: removeDecimals(product.book_info.price_increment_x18),
|
|
41
|
-
sizeIncrement:
|
|
41
|
+
sizeIncrement: toBigNumber(product.book_info.size_increment),
|
|
42
42
|
product: {
|
|
43
43
|
productId: product.product_id,
|
|
44
44
|
type: ProductEngineType.SPOT,
|
|
@@ -74,9 +74,9 @@ function mapEngineServerPerpProduct(product) {
|
|
|
74
74
|
return {
|
|
75
75
|
type: ProductEngineType.PERP,
|
|
76
76
|
productId: product.product_id,
|
|
77
|
-
minSize:
|
|
77
|
+
minSize: toBigNumber(product.book_info.min_size),
|
|
78
78
|
priceIncrement: removeDecimals(product.book_info.price_increment_x18),
|
|
79
|
-
sizeIncrement:
|
|
79
|
+
sizeIncrement: toBigNumber(product.book_info.size_increment),
|
|
80
80
|
product: {
|
|
81
81
|
productId: product.product_id,
|
|
82
82
|
type: ProductEngineType.PERP,
|
|
@@ -89,7 +89,7 @@ function mapEngineServerPerpProduct(product) {
|
|
|
89
89
|
shortWeightMaintenance: removeDecimals(
|
|
90
90
|
product.risk.short_weight_maintenance_x18
|
|
91
91
|
),
|
|
92
|
-
openInterest:
|
|
92
|
+
openInterest: toBigNumber(product.state.open_interest),
|
|
93
93
|
cumulativeFundingLong: removeDecimals(
|
|
94
94
|
product.state.cumulative_funding_long_x18
|
|
95
95
|
),
|
|
@@ -101,62 +101,76 @@ function mapEngineServerPerpProduct(product) {
|
|
|
101
101
|
}
|
|
102
102
|
function mapEngineServerBalanceHealthContributions(healthContributionsForBalance) {
|
|
103
103
|
return {
|
|
104
|
-
initial:
|
|
105
|
-
maintenance:
|
|
106
|
-
unweighted:
|
|
104
|
+
initial: toBigNumber(healthContributionsForBalance[0]),
|
|
105
|
+
maintenance: toBigNumber(healthContributionsForBalance[1]),
|
|
106
|
+
unweighted: toBigNumber(healthContributionsForBalance[2])
|
|
107
107
|
};
|
|
108
108
|
}
|
|
109
109
|
function mapSubaccountSummary(baseResponse) {
|
|
110
|
+
return {
|
|
111
|
+
exists: baseResponse.exists,
|
|
112
|
+
...mapSubaccountSummaryState(
|
|
113
|
+
baseResponse,
|
|
114
|
+
baseResponse.spot_products,
|
|
115
|
+
baseResponse.perp_products
|
|
116
|
+
),
|
|
117
|
+
preState: baseResponse.pre_state ? mapSubaccountSummaryState(
|
|
118
|
+
baseResponse.pre_state,
|
|
119
|
+
baseResponse.spot_products,
|
|
120
|
+
baseResponse.perp_products
|
|
121
|
+
) : void 0
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
function mapSubaccountSummaryState(state, spotProducts, perpProducts) {
|
|
110
125
|
const balances = [];
|
|
111
|
-
|
|
112
|
-
const product =
|
|
126
|
+
state.spot_balances.forEach((spotBalance) => {
|
|
127
|
+
const product = spotProducts.find(
|
|
113
128
|
(product2) => product2.product_id === spotBalance.product_id
|
|
114
129
|
);
|
|
115
130
|
if (!product) {
|
|
116
131
|
throw Error(`Could not find product ${spotBalance.product_id}`);
|
|
117
132
|
}
|
|
118
133
|
balances.push({
|
|
119
|
-
amount:
|
|
134
|
+
amount: toBigNumber(spotBalance.balance.amount),
|
|
120
135
|
healthContributions: mapEngineServerBalanceHealthContributions(
|
|
121
|
-
|
|
136
|
+
state.health_contributions[spotBalance.product_id]
|
|
122
137
|
),
|
|
123
138
|
...mapEngineServerSpotProduct(product).product
|
|
124
139
|
});
|
|
125
140
|
});
|
|
126
|
-
|
|
127
|
-
const product =
|
|
141
|
+
state.perp_balances.forEach((perpBalance) => {
|
|
142
|
+
const product = perpProducts.find(
|
|
128
143
|
(product2) => product2.product_id === perpBalance.product_id
|
|
129
144
|
);
|
|
130
145
|
if (!product) {
|
|
131
146
|
throw Error(`Could not find product ${perpBalance.product_id}`);
|
|
132
147
|
}
|
|
133
148
|
balances.push({
|
|
134
|
-
amount:
|
|
135
|
-
vQuoteBalance:
|
|
149
|
+
amount: toBigNumber(perpBalance.balance.amount),
|
|
150
|
+
vQuoteBalance: toBigNumber(perpBalance.balance.v_quote_balance),
|
|
136
151
|
healthContributions: mapEngineServerBalanceHealthContributions(
|
|
137
|
-
|
|
152
|
+
state.health_contributions[perpBalance.product_id]
|
|
138
153
|
),
|
|
139
154
|
...mapEngineServerPerpProduct(product).product
|
|
140
155
|
});
|
|
141
156
|
});
|
|
142
157
|
return {
|
|
143
158
|
balances,
|
|
144
|
-
exists: baseResponse.exists,
|
|
145
159
|
health: {
|
|
146
160
|
initial: {
|
|
147
|
-
health:
|
|
148
|
-
assets:
|
|
149
|
-
liabilities:
|
|
161
|
+
health: toBigNumber(state.healths[0].health),
|
|
162
|
+
assets: toBigNumber(state.healths[0].assets),
|
|
163
|
+
liabilities: toBigNumber(state.healths[0].liabilities)
|
|
150
164
|
},
|
|
151
165
|
maintenance: {
|
|
152
|
-
health:
|
|
153
|
-
assets:
|
|
154
|
-
liabilities:
|
|
166
|
+
health: toBigNumber(state.healths[1].health),
|
|
167
|
+
assets: toBigNumber(state.healths[1].assets),
|
|
168
|
+
liabilities: toBigNumber(state.healths[1].liabilities)
|
|
155
169
|
},
|
|
156
170
|
unweighted: {
|
|
157
|
-
health:
|
|
158
|
-
assets:
|
|
159
|
-
liabilities:
|
|
171
|
+
health: toBigNumber(state.healths[2].health),
|
|
172
|
+
assets: toBigNumber(state.healths[2].assets),
|
|
173
|
+
liabilities: toBigNumber(state.healths[2].liabilities)
|
|
160
174
|
}
|
|
161
175
|
}
|
|
162
176
|
};
|
|
@@ -168,27 +182,27 @@ function mapEngineServerIsolatedPositions(baseResponse) {
|
|
|
168
182
|
return {
|
|
169
183
|
subaccount: subaccountFromHex(position.subaccount),
|
|
170
184
|
healths: {
|
|
171
|
-
initial:
|
|
172
|
-
maintenance:
|
|
173
|
-
unweighted:
|
|
185
|
+
initial: toBigNumber(position.healths[0].health),
|
|
186
|
+
maintenance: toBigNumber(position.healths[1].health),
|
|
187
|
+
unweighted: toBigNumber(position.healths[2].health)
|
|
174
188
|
},
|
|
175
189
|
baseBalance: {
|
|
176
|
-
amount:
|
|
177
|
-
vQuoteBalance:
|
|
190
|
+
amount: toBigNumber(perpBalance.balance.amount),
|
|
191
|
+
vQuoteBalance: toBigNumber(perpBalance.balance.v_quote_balance),
|
|
178
192
|
// Health contributions === healths for an isolated position
|
|
179
193
|
healthContributions: {
|
|
180
|
-
initial:
|
|
181
|
-
maintenance:
|
|
182
|
-
unweighted:
|
|
194
|
+
initial: toBigNumber(position.base_healths[0]),
|
|
195
|
+
maintenance: toBigNumber(position.base_healths[1]),
|
|
196
|
+
unweighted: toBigNumber(position.base_healths[2])
|
|
183
197
|
},
|
|
184
198
|
...mapEngineServerPerpProduct(position.base_product).product
|
|
185
199
|
},
|
|
186
200
|
quoteBalance: {
|
|
187
|
-
amount:
|
|
201
|
+
amount: toBigNumber(quoteBalance.balance.amount),
|
|
188
202
|
healthContributions: {
|
|
189
|
-
initial:
|
|
190
|
-
maintenance:
|
|
191
|
-
unweighted:
|
|
203
|
+
initial: toBigNumber(position.quote_healths[0]),
|
|
204
|
+
maintenance: toBigNumber(position.quote_healths[1]),
|
|
205
|
+
unweighted: toBigNumber(position.quote_healths[2])
|
|
192
206
|
},
|
|
193
207
|
...mapEngineServerSpotProduct(position.quote_product).product
|
|
194
208
|
}
|
|
@@ -210,10 +224,8 @@ function mapEngineServerSymbol(engineServerSymbol) {
|
|
|
210
224
|
productId: engineServerSymbol.product_id,
|
|
211
225
|
symbol: engineServerSymbol.symbol,
|
|
212
226
|
priceIncrement: removeDecimals(engineServerSymbol.price_increment_x18),
|
|
213
|
-
sizeIncrement:
|
|
214
|
-
minSize:
|
|
215
|
-
minDepth: removeDecimals(engineServerSymbol.min_depth_x18),
|
|
216
|
-
maxSpreadRate: removeDecimals(engineServerSymbol.max_spread_rate_x18),
|
|
227
|
+
sizeIncrement: toBigNumber(engineServerSymbol.size_increment),
|
|
228
|
+
minSize: toBigNumber(engineServerSymbol.min_size),
|
|
217
229
|
makerFeeRate: removeDecimals(engineServerSymbol.maker_fee_rate_x18),
|
|
218
230
|
takerFeeRate: removeDecimals(engineServerSymbol.taker_fee_rate_x18),
|
|
219
231
|
longWeightInitial: removeDecimals(
|
|
@@ -221,7 +233,9 @@ function mapEngineServerSymbol(engineServerSymbol) {
|
|
|
221
233
|
),
|
|
222
234
|
longWeightMaintenance: removeDecimals(
|
|
223
235
|
engineServerSymbol.long_weight_maintenance_x18
|
|
224
|
-
)
|
|
236
|
+
),
|
|
237
|
+
maxOpenInterest: removeDecimals(engineServerSymbol.max_open_interest_x18),
|
|
238
|
+
isolatedOnly: engineServerSymbol.isolated_only
|
|
225
239
|
};
|
|
226
240
|
}
|
|
227
241
|
function mapEngineMarketPrice(baseResponse) {
|
|
@@ -231,10 +245,42 @@ function mapEngineMarketPrice(baseResponse) {
|
|
|
231
245
|
productId: baseResponse.product_id
|
|
232
246
|
};
|
|
233
247
|
}
|
|
248
|
+
function mapEngineServerNlpLockedBalances(baseResponse) {
|
|
249
|
+
const lockedBalances = baseResponse.locked_balances.map((lockedBalance) => ({
|
|
250
|
+
productId: lockedBalance.balance.product_id,
|
|
251
|
+
balance: toBigNumber(lockedBalance.balance.balance.amount),
|
|
252
|
+
unlockedAt: lockedBalance.unlocked_at
|
|
253
|
+
}));
|
|
254
|
+
return {
|
|
255
|
+
lockedBalances,
|
|
256
|
+
balanceLocked: {
|
|
257
|
+
productId: baseResponse.balance_locked.product_id,
|
|
258
|
+
balance: toBigNumber(baseResponse.balance_locked.balance.amount)
|
|
259
|
+
},
|
|
260
|
+
balanceUnlocked: {
|
|
261
|
+
productId: baseResponse.balance_unlocked.product_id,
|
|
262
|
+
balance: toBigNumber(baseResponse.balance_unlocked.balance.amount)
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
function mapEngineServerNlpPoolInfo(baseResponse) {
|
|
267
|
+
return {
|
|
268
|
+
nlpPools: baseResponse.nlp_pools.map((pool) => ({
|
|
269
|
+
poolId: pool.pool_id,
|
|
270
|
+
subaccountHex: pool.subaccount,
|
|
271
|
+
ownerAddress: pool.owner,
|
|
272
|
+
balanceWeight: removeDecimals(pool.balance_weight_x18),
|
|
273
|
+
subaccountInfo: mapSubaccountSummary(pool.subaccount_info),
|
|
274
|
+
openOrders: pool.open_orders.map(mapEngineServerOrder)
|
|
275
|
+
}))
|
|
276
|
+
};
|
|
277
|
+
}
|
|
234
278
|
export {
|
|
235
279
|
mapEngineMarketPrice,
|
|
236
280
|
mapEngineServerBalanceHealthContributions,
|
|
237
281
|
mapEngineServerIsolatedPositions,
|
|
282
|
+
mapEngineServerNlpLockedBalances,
|
|
283
|
+
mapEngineServerNlpPoolInfo,
|
|
238
284
|
mapEngineServerOrder,
|
|
239
285
|
mapEngineServerPerpProduct,
|
|
240
286
|
mapEngineServerSpotProduct,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/queryDataMappers.ts"],"sourcesContent":["import {\n BalanceHealthContributions,\n calcTotalBorrowed,\n calcTotalDeposited,\n mapValues,\n PerpMarket,\n ProductEngineType,\n removeDecimals,\n SpotMarket,\n subaccountFromHex,\n toBigDecimal,\n unpackOrderAppendix,\n} from '@nadohq/shared';\nimport {\n EngineMarketPrice,\n EngineOrder,\n EnginePriceTickLiquidity,\n EngineServerIsolatedPositionsResponse,\n EngineServerMarketPrice,\n EngineServerOrderResponse,\n EngineServerPerpProduct,\n EngineServerPriceTickLiquidity,\n EngineServerSpotProduct,\n EngineServerSubaccountInfoResponse,\n EngineServerSymbol,\n EngineServerSymbolsResponse,\n EngineSymbol,\n EngineSymbolsResponse,\n GetEngineIsolatedPositionsResponse,\n GetEngineSubaccountSummaryResponse,\n} from '../types';\nimport { mapEngineServerProductType } from './productEngineTypeMappers';\n\nexport function mapEngineServerTickLiquidity(\n tick: EngineServerPriceTickLiquidity,\n): EnginePriceTickLiquidity {\n return {\n price: removeDecimals(tick[0]),\n liquidity: toBigDecimal(tick[1]),\n };\n}\n\nexport function mapEngineServerOrder(\n order: EngineServerOrderResponse,\n): EngineOrder {\n const subaccount = subaccountFromHex(order.sender);\n return {\n digest: order.digest,\n expiration: Number(order.expiration),\n nonce: order.nonce,\n price: removeDecimals(order.price_x18),\n productId: order.product_id,\n subaccountOwner: subaccount.subaccountOwner,\n subaccountName: subaccount.subaccountName,\n totalAmount: toBigDecimal(order.amount),\n unfilledAmount: toBigDecimal(order.unfilled_amount),\n placementTime: order.placed_at,\n appendix: unpackOrderAppendix(order.appendix),\n };\n}\n\nexport function mapEngineServerSpotProduct(\n product: EngineServerSpotProduct,\n): SpotMarket {\n return {\n type: ProductEngineType.SPOT,\n productId: product.product_id,\n minSize: toBigDecimal(product.book_info.min_size),\n priceIncrement: removeDecimals(product.book_info.price_increment_x18),\n sizeIncrement: toBigDecimal(product.book_info.size_increment),\n product: {\n productId: product.product_id,\n type: ProductEngineType.SPOT,\n totalBorrowed: calcTotalBorrowed(\n product.state.total_borrows_normalized,\n product.state.cumulative_borrows_multiplier_x18,\n ),\n totalDeposited: calcTotalDeposited(\n product.state.total_deposits_normalized,\n product.state.cumulative_deposits_multiplier_x18,\n ),\n oraclePrice: removeDecimals(product.oracle_price_x18),\n interestFloor: removeDecimals(product.config.interest_floor_x18),\n interestInflectionUtil: removeDecimals(\n product.config.interest_inflection_util_x18,\n ),\n interestLargeCap: removeDecimals(product.config.interest_large_cap_x18),\n interestSmallCap: removeDecimals(product.config.interest_small_cap_x18),\n minDepositRate: removeDecimals(product.config.min_deposit_rate_x18),\n longWeightInitial: removeDecimals(product.risk.long_weight_initial_x18),\n longWeightMaintenance: removeDecimals(\n product.risk.long_weight_maintenance_x18,\n ),\n shortWeightInitial: removeDecimals(product.risk.short_weight_initial_x18),\n shortWeightMaintenance: removeDecimals(\n product.risk.short_weight_maintenance_x18,\n ),\n tokenAddr: product.config.token,\n },\n };\n}\n\nexport function mapEngineServerPerpProduct(\n product: EngineServerPerpProduct,\n): PerpMarket {\n return {\n type: ProductEngineType.PERP,\n productId: product.product_id,\n minSize: toBigDecimal(product.book_info.min_size),\n priceIncrement: removeDecimals(product.book_info.price_increment_x18),\n sizeIncrement: toBigDecimal(product.book_info.size_increment),\n product: {\n productId: product.product_id,\n type: ProductEngineType.PERP,\n oraclePrice: removeDecimals(product.oracle_price_x18),\n longWeightInitial: removeDecimals(product.risk.long_weight_initial_x18),\n longWeightMaintenance: removeDecimals(\n product.risk.long_weight_maintenance_x18,\n ),\n shortWeightInitial: removeDecimals(product.risk.short_weight_initial_x18),\n shortWeightMaintenance: removeDecimals(\n product.risk.short_weight_maintenance_x18,\n ),\n openInterest: toBigDecimal(product.state.open_interest),\n cumulativeFundingLong: removeDecimals(\n product.state.cumulative_funding_long_x18,\n ),\n cumulativeFundingShort: removeDecimals(\n product.state.cumulative_funding_short_x18,\n ),\n },\n };\n}\n\nexport function mapEngineServerBalanceHealthContributions(\n healthContributionsForBalance: string[],\n): BalanceHealthContributions {\n return {\n initial: toBigDecimal(healthContributionsForBalance[0]),\n maintenance: toBigDecimal(healthContributionsForBalance[1]),\n unweighted: toBigDecimal(healthContributionsForBalance[2]),\n };\n}\n\nexport function mapSubaccountSummary(\n baseResponse: EngineServerSubaccountInfoResponse,\n): GetEngineSubaccountSummaryResponse {\n const balances: GetEngineSubaccountSummaryResponse['balances'] = [];\n\n baseResponse.spot_balances.forEach((spotBalance) => {\n const product = baseResponse.spot_products.find(\n (product) => product.product_id === spotBalance.product_id,\n );\n if (!product) {\n throw Error(`Could not find product ${spotBalance.product_id}`);\n }\n\n balances.push({\n amount: toBigDecimal(spotBalance.balance.amount),\n healthContributions: mapEngineServerBalanceHealthContributions(\n baseResponse.health_contributions[spotBalance.product_id],\n ),\n ...mapEngineServerSpotProduct(product).product,\n });\n });\n\n baseResponse.perp_balances.forEach((perpBalance) => {\n const product = baseResponse.perp_products.find(\n (product) => product.product_id === perpBalance.product_id,\n );\n if (!product) {\n throw Error(`Could not find product ${perpBalance.product_id}`);\n }\n\n balances.push({\n amount: toBigDecimal(perpBalance.balance.amount),\n vQuoteBalance: toBigDecimal(perpBalance.balance.v_quote_balance),\n healthContributions: mapEngineServerBalanceHealthContributions(\n baseResponse.health_contributions[perpBalance.product_id],\n ),\n ...mapEngineServerPerpProduct(product).product,\n });\n });\n\n return {\n balances: balances,\n exists: baseResponse.exists,\n health: {\n initial: {\n health: toBigDecimal(baseResponse.healths[0].health),\n assets: toBigDecimal(baseResponse.healths[0].assets),\n liabilities: toBigDecimal(baseResponse.healths[0].liabilities),\n },\n maintenance: {\n health: toBigDecimal(baseResponse.healths[1].health),\n assets: toBigDecimal(baseResponse.healths[1].assets),\n liabilities: toBigDecimal(baseResponse.healths[1].liabilities),\n },\n unweighted: {\n health: toBigDecimal(baseResponse.healths[2].health),\n assets: toBigDecimal(baseResponse.healths[2].assets),\n liabilities: toBigDecimal(baseResponse.healths[2].liabilities),\n },\n },\n };\n}\n\nexport function mapEngineServerIsolatedPositions(\n baseResponse: EngineServerIsolatedPositionsResponse,\n): GetEngineIsolatedPositionsResponse {\n return baseResponse.isolated_positions.map((position) => {\n const perpBalance = position.base_balance;\n const quoteBalance = position.quote_balance;\n\n return {\n subaccount: subaccountFromHex(position.subaccount),\n healths: {\n initial: toBigDecimal(position.healths[0].health),\n maintenance: toBigDecimal(position.healths[1].health),\n unweighted: toBigDecimal(position.healths[2].health),\n },\n baseBalance: {\n amount: toBigDecimal(perpBalance.balance.amount),\n vQuoteBalance: toBigDecimal(perpBalance.balance.v_quote_balance),\n // Health contributions === healths for an isolated position\n healthContributions: {\n initial: toBigDecimal(position.base_healths[0]),\n maintenance: toBigDecimal(position.base_healths[1]),\n unweighted: toBigDecimal(position.base_healths[2]),\n },\n ...mapEngineServerPerpProduct(position.base_product).product,\n },\n quoteBalance: {\n amount: toBigDecimal(quoteBalance.balance.amount),\n healthContributions: {\n initial: toBigDecimal(position.quote_healths[0]),\n maintenance: toBigDecimal(position.quote_healths[1]),\n unweighted: toBigDecimal(position.quote_healths[2]),\n },\n ...mapEngineServerSpotProduct(position.quote_product).product,\n },\n };\n });\n}\n\nexport function mapEngineServerSymbols(\n baseResponse: EngineServerSymbolsResponse,\n): EngineSymbolsResponse {\n const symbols: Record<string, EngineSymbol> = mapValues(\n baseResponse.symbols,\n mapEngineServerSymbol,\n );\n\n return {\n symbols,\n };\n}\n\nexport function mapEngineServerSymbol(\n engineServerSymbol: EngineServerSymbol,\n): EngineSymbol {\n return {\n type: mapEngineServerProductType(engineServerSymbol.type),\n productId: engineServerSymbol.product_id,\n symbol: engineServerSymbol.symbol,\n priceIncrement: removeDecimals(engineServerSymbol.price_increment_x18),\n sizeIncrement: toBigDecimal(engineServerSymbol.size_increment),\n minSize: toBigDecimal(engineServerSymbol.min_size),\n minDepth: removeDecimals(engineServerSymbol.min_depth_x18),\n maxSpreadRate: removeDecimals(engineServerSymbol.max_spread_rate_x18),\n makerFeeRate: removeDecimals(engineServerSymbol.maker_fee_rate_x18),\n takerFeeRate: removeDecimals(engineServerSymbol.taker_fee_rate_x18),\n longWeightInitial: removeDecimals(\n engineServerSymbol.long_weight_initial_x18,\n ),\n longWeightMaintenance: removeDecimals(\n engineServerSymbol.long_weight_maintenance_x18,\n ),\n };\n}\n\nexport function mapEngineMarketPrice(\n baseResponse: EngineServerMarketPrice,\n): EngineMarketPrice {\n return {\n ask: removeDecimals(baseResponse.ask_x18),\n bid: removeDecimals(baseResponse.bid_x18),\n productId: baseResponse.product_id,\n };\n}\n"],"mappings":";AAAA;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAmBP,SAAS,kCAAkC;AAEpC,SAAS,6BACd,MAC0B;AAC1B,SAAO;AAAA,IACL,OAAO,eAAe,KAAK,CAAC,CAAC;AAAA,IAC7B,WAAW,aAAa,KAAK,CAAC,CAAC;AAAA,EACjC;AACF;AAEO,SAAS,qBACd,OACa;AACb,QAAM,aAAa,kBAAkB,MAAM,MAAM;AACjD,SAAO;AAAA,IACL,QAAQ,MAAM;AAAA,IACd,YAAY,OAAO,MAAM,UAAU;AAAA,IACnC,OAAO,MAAM;AAAA,IACb,OAAO,eAAe,MAAM,SAAS;AAAA,IACrC,WAAW,MAAM;AAAA,IACjB,iBAAiB,WAAW;AAAA,IAC5B,gBAAgB,WAAW;AAAA,IAC3B,aAAa,aAAa,MAAM,MAAM;AAAA,IACtC,gBAAgB,aAAa,MAAM,eAAe;AAAA,IAClD,eAAe,MAAM;AAAA,IACrB,UAAU,oBAAoB,MAAM,QAAQ;AAAA,EAC9C;AACF;AAEO,SAAS,2BAC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UAAU,eAAe,mBAAmB,aAAa;AAAA,IACzD,eAAe,eAAe,mBAAmB,mBAAmB;AAAA,IACpE,cAAc,eAAe,mBAAmB,kBAAkB;AAAA,IAClE,cAAc,eAAe,mBAAmB,kBAAkB;AAAA,IAClE,mBAAmB;AAAA,MACjB,mBAAmB;AAAA,IACrB;AAAA,IACA,uBAAuB;AAAA,MACrB,mBAAmB;AAAA,IACrB;AAAA,EACF;AACF;AAEO,SAAS,qBACd,cACmB;AACnB,SAAO;AAAA,IACL,KAAK,eAAe,aAAa,OAAO;AAAA,IACxC,KAAK,eAAe,aAAa,OAAO;AAAA,IACxC,WAAW,aAAa;AAAA,EAC1B;AACF;","names":["product"]}
|
|
1
|
+
{"version":3,"sources":["../../src/utils/queryDataMappers.ts"],"sourcesContent":["import {\n BalanceHealthContributions,\n calcTotalBorrowed,\n calcTotalDeposited,\n mapValues,\n PerpMarket,\n ProductEngineType,\n removeDecimals,\n SpotMarket,\n subaccountFromHex,\n toBigNumber,\n unpackOrderAppendix,\n} from '@nadohq/shared';\nimport {\n EngineMarketPrice,\n EngineNlpLockedBalance,\n EngineOrder,\n EnginePriceTickLiquidity,\n EngineServerIsolatedPositionsResponse,\n EngineServerMarketPrice,\n EngineServerNlpLockedBalancesResponse,\n EngineServerNlpPoolInfoResponse,\n EngineServerOrderResponse,\n EngineServerPerpProduct,\n EngineServerPriceTickLiquidity,\n EngineServerSpotProduct,\n EngineServerSubaccountInfoResponse,\n EngineServerSubaccountInfoState,\n EngineServerSymbol,\n EngineServerSymbolsResponse,\n EngineSymbol,\n EngineSymbolsResponse,\n GetEngineIsolatedPositionsResponse,\n GetEngineNlpLockedBalancesResponse,\n GetEngineNlpPoolInfoResponse,\n GetEngineSubaccountSummaryResponse,\n SubaccountSummaryState,\n} from '../types';\nimport { mapEngineServerProductType } from './productEngineTypeMappers';\n\nexport function mapEngineServerTickLiquidity(\n tick: EngineServerPriceTickLiquidity,\n): EnginePriceTickLiquidity {\n return {\n price: removeDecimals(tick[0]),\n liquidity: toBigNumber(tick[1]),\n };\n}\n\nexport function mapEngineServerOrder(\n order: EngineServerOrderResponse,\n): EngineOrder {\n const subaccount = subaccountFromHex(order.sender);\n return {\n digest: order.digest,\n expiration: Number(order.expiration),\n nonce: order.nonce,\n price: removeDecimals(order.price_x18),\n productId: order.product_id,\n subaccountOwner: subaccount.subaccountOwner,\n subaccountName: subaccount.subaccountName,\n totalAmount: toBigNumber(order.amount),\n unfilledAmount: toBigNumber(order.unfilled_amount),\n placementTime: order.placed_at,\n appendix: unpackOrderAppendix(order.appendix),\n };\n}\n\nexport function mapEngineServerSpotProduct(\n product: EngineServerSpotProduct,\n): SpotMarket {\n return {\n type: ProductEngineType.SPOT,\n productId: product.product_id,\n minSize: toBigNumber(product.book_info.min_size),\n priceIncrement: removeDecimals(product.book_info.price_increment_x18),\n sizeIncrement: toBigNumber(product.book_info.size_increment),\n product: {\n productId: product.product_id,\n type: ProductEngineType.SPOT,\n totalBorrowed: calcTotalBorrowed(\n product.state.total_borrows_normalized,\n product.state.cumulative_borrows_multiplier_x18,\n ),\n totalDeposited: calcTotalDeposited(\n product.state.total_deposits_normalized,\n product.state.cumulative_deposits_multiplier_x18,\n ),\n oraclePrice: removeDecimals(product.oracle_price_x18),\n interestFloor: removeDecimals(product.config.interest_floor_x18),\n interestInflectionUtil: removeDecimals(\n product.config.interest_inflection_util_x18,\n ),\n interestLargeCap: removeDecimals(product.config.interest_large_cap_x18),\n interestSmallCap: removeDecimals(product.config.interest_small_cap_x18),\n minDepositRate: removeDecimals(product.config.min_deposit_rate_x18),\n longWeightInitial: removeDecimals(product.risk.long_weight_initial_x18),\n longWeightMaintenance: removeDecimals(\n product.risk.long_weight_maintenance_x18,\n ),\n shortWeightInitial: removeDecimals(product.risk.short_weight_initial_x18),\n shortWeightMaintenance: removeDecimals(\n product.risk.short_weight_maintenance_x18,\n ),\n tokenAddr: product.config.token,\n },\n };\n}\n\nexport function mapEngineServerPerpProduct(\n product: EngineServerPerpProduct,\n): PerpMarket {\n return {\n type: ProductEngineType.PERP,\n productId: product.product_id,\n minSize: toBigNumber(product.book_info.min_size),\n priceIncrement: removeDecimals(product.book_info.price_increment_x18),\n sizeIncrement: toBigNumber(product.book_info.size_increment),\n product: {\n productId: product.product_id,\n type: ProductEngineType.PERP,\n oraclePrice: removeDecimals(product.oracle_price_x18),\n longWeightInitial: removeDecimals(product.risk.long_weight_initial_x18),\n longWeightMaintenance: removeDecimals(\n product.risk.long_weight_maintenance_x18,\n ),\n shortWeightInitial: removeDecimals(product.risk.short_weight_initial_x18),\n shortWeightMaintenance: removeDecimals(\n product.risk.short_weight_maintenance_x18,\n ),\n openInterest: toBigNumber(product.state.open_interest),\n cumulativeFundingLong: removeDecimals(\n product.state.cumulative_funding_long_x18,\n ),\n cumulativeFundingShort: removeDecimals(\n product.state.cumulative_funding_short_x18,\n ),\n },\n };\n}\n\nexport function mapEngineServerBalanceHealthContributions(\n healthContributionsForBalance: string[],\n): BalanceHealthContributions {\n return {\n initial: toBigNumber(healthContributionsForBalance[0]),\n maintenance: toBigNumber(healthContributionsForBalance[1]),\n unweighted: toBigNumber(healthContributionsForBalance[2]),\n };\n}\n\nexport function mapSubaccountSummary(\n baseResponse: EngineServerSubaccountInfoResponse,\n): GetEngineSubaccountSummaryResponse {\n return {\n exists: baseResponse.exists,\n ...mapSubaccountSummaryState(\n baseResponse,\n baseResponse.spot_products,\n baseResponse.perp_products,\n ),\n preState: baseResponse.pre_state\n ? mapSubaccountSummaryState(\n baseResponse.pre_state,\n baseResponse.spot_products,\n baseResponse.perp_products,\n )\n : undefined,\n };\n}\n\nfunction mapSubaccountSummaryState(\n state: EngineServerSubaccountInfoState,\n spotProducts: EngineServerSubaccountInfoResponse['spot_products'],\n perpProducts: EngineServerSubaccountInfoResponse['perp_products'],\n): SubaccountSummaryState {\n const balances: SubaccountSummaryState['balances'] = [];\n\n state.spot_balances.forEach((spotBalance) => {\n const product = spotProducts.find(\n (product) => product.product_id === spotBalance.product_id,\n );\n if (!product) {\n throw Error(`Could not find product ${spotBalance.product_id}`);\n }\n\n balances.push({\n amount: toBigNumber(spotBalance.balance.amount),\n healthContributions: mapEngineServerBalanceHealthContributions(\n state.health_contributions[spotBalance.product_id],\n ),\n ...mapEngineServerSpotProduct(product).product,\n });\n });\n\n state.perp_balances.forEach((perpBalance) => {\n const product = perpProducts.find(\n (product) => product.product_id === perpBalance.product_id,\n );\n if (!product) {\n throw Error(`Could not find product ${perpBalance.product_id}`);\n }\n\n balances.push({\n amount: toBigNumber(perpBalance.balance.amount),\n vQuoteBalance: toBigNumber(perpBalance.balance.v_quote_balance),\n healthContributions: mapEngineServerBalanceHealthContributions(\n state.health_contributions[perpBalance.product_id],\n ),\n ...mapEngineServerPerpProduct(product).product,\n });\n });\n\n return {\n balances,\n health: {\n initial: {\n health: toBigNumber(state.healths[0].health),\n assets: toBigNumber(state.healths[0].assets),\n liabilities: toBigNumber(state.healths[0].liabilities),\n },\n maintenance: {\n health: toBigNumber(state.healths[1].health),\n assets: toBigNumber(state.healths[1].assets),\n liabilities: toBigNumber(state.healths[1].liabilities),\n },\n unweighted: {\n health: toBigNumber(state.healths[2].health),\n assets: toBigNumber(state.healths[2].assets),\n liabilities: toBigNumber(state.healths[2].liabilities),\n },\n },\n };\n}\n\nexport function mapEngineServerIsolatedPositions(\n baseResponse: EngineServerIsolatedPositionsResponse,\n): GetEngineIsolatedPositionsResponse {\n return baseResponse.isolated_positions.map((position) => {\n const perpBalance = position.base_balance;\n const quoteBalance = position.quote_balance;\n\n return {\n subaccount: subaccountFromHex(position.subaccount),\n healths: {\n initial: toBigNumber(position.healths[0].health),\n maintenance: toBigNumber(position.healths[1].health),\n unweighted: toBigNumber(position.healths[2].health),\n },\n baseBalance: {\n amount: toBigNumber(perpBalance.balance.amount),\n vQuoteBalance: toBigNumber(perpBalance.balance.v_quote_balance),\n // Health contributions === healths for an isolated position\n healthContributions: {\n initial: toBigNumber(position.base_healths[0]),\n maintenance: toBigNumber(position.base_healths[1]),\n unweighted: toBigNumber(position.base_healths[2]),\n },\n ...mapEngineServerPerpProduct(position.base_product).product,\n },\n quoteBalance: {\n amount: toBigNumber(quoteBalance.balance.amount),\n healthContributions: {\n initial: toBigNumber(position.quote_healths[0]),\n maintenance: toBigNumber(position.quote_healths[1]),\n unweighted: toBigNumber(position.quote_healths[2]),\n },\n ...mapEngineServerSpotProduct(position.quote_product).product,\n },\n };\n });\n}\n\nexport function mapEngineServerSymbols(\n baseResponse: EngineServerSymbolsResponse,\n): EngineSymbolsResponse {\n const symbols: Record<string, EngineSymbol> = mapValues(\n baseResponse.symbols,\n mapEngineServerSymbol,\n );\n\n return {\n symbols,\n };\n}\n\nexport function mapEngineServerSymbol(\n engineServerSymbol: EngineServerSymbol,\n): EngineSymbol {\n return {\n type: mapEngineServerProductType(engineServerSymbol.type),\n productId: engineServerSymbol.product_id,\n symbol: engineServerSymbol.symbol,\n priceIncrement: removeDecimals(engineServerSymbol.price_increment_x18),\n sizeIncrement: toBigNumber(engineServerSymbol.size_increment),\n minSize: toBigNumber(engineServerSymbol.min_size),\n makerFeeRate: removeDecimals(engineServerSymbol.maker_fee_rate_x18),\n takerFeeRate: removeDecimals(engineServerSymbol.taker_fee_rate_x18),\n longWeightInitial: removeDecimals(\n engineServerSymbol.long_weight_initial_x18,\n ),\n longWeightMaintenance: removeDecimals(\n engineServerSymbol.long_weight_maintenance_x18,\n ),\n maxOpenInterest: removeDecimals(engineServerSymbol.max_open_interest_x18),\n isolatedOnly: engineServerSymbol.isolated_only,\n };\n}\n\nexport function mapEngineMarketPrice(\n baseResponse: EngineServerMarketPrice,\n): EngineMarketPrice {\n return {\n ask: removeDecimals(baseResponse.ask_x18),\n bid: removeDecimals(baseResponse.bid_x18),\n productId: baseResponse.product_id,\n };\n}\n\nexport function mapEngineServerNlpLockedBalances(\n baseResponse: EngineServerNlpLockedBalancesResponse,\n): GetEngineNlpLockedBalancesResponse {\n const lockedBalances: EngineNlpLockedBalance[] =\n baseResponse.locked_balances.map((lockedBalance) => ({\n productId: lockedBalance.balance.product_id,\n balance: toBigNumber(lockedBalance.balance.balance.amount),\n unlockedAt: lockedBalance.unlocked_at,\n }));\n\n return {\n lockedBalances,\n balanceLocked: {\n productId: baseResponse.balance_locked.product_id,\n balance: toBigNumber(baseResponse.balance_locked.balance.amount),\n },\n balanceUnlocked: {\n productId: baseResponse.balance_unlocked.product_id,\n balance: toBigNumber(baseResponse.balance_unlocked.balance.amount),\n },\n };\n}\n\nexport function mapEngineServerNlpPoolInfo(\n baseResponse: EngineServerNlpPoolInfoResponse,\n): GetEngineNlpPoolInfoResponse {\n return {\n nlpPools: baseResponse.nlp_pools.map((pool) => ({\n poolId: pool.pool_id,\n subaccountHex: pool.subaccount,\n ownerAddress: pool.owner,\n balanceWeight: removeDecimals(pool.balance_weight_x18),\n subaccountInfo: mapSubaccountSummary(pool.subaccount_info),\n openOrders: pool.open_orders.map(mapEngineServerOrder),\n })),\n };\n}\n"],"mappings":";AAAA;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AA0BP,SAAS,kCAAkC;AAEpC,SAAS,6BACd,MAC0B;AAC1B,SAAO;AAAA,IACL,OAAO,eAAe,KAAK,CAAC,CAAC;AAAA,IAC7B,WAAW,YAAY,KAAK,CAAC,CAAC;AAAA,EAChC;AACF;AAEO,SAAS,qBACd,OACa;AACb,QAAM,aAAa,kBAAkB,MAAM,MAAM;AACjD,SAAO;AAAA,IACL,QAAQ,MAAM;AAAA,IACd,YAAY,OAAO,MAAM,UAAU;AAAA,IACnC,OAAO,MAAM;AAAA,IACb,OAAO,eAAe,MAAM,SAAS;AAAA,IACrC,WAAW,MAAM;AAAA,IACjB,iBAAiB,WAAW;AAAA,IAC5B,gBAAgB,WAAW;AAAA,IAC3B,aAAa,YAAY,MAAM,MAAM;AAAA,IACrC,gBAAgB,YAAY,MAAM,eAAe;AAAA,IACjD,eAA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UAAU,aAAa,UAAU,IAAI,CAAC,UAAU;AAAA,MAC9C,QAAQ,KAAK;AAAA,MACb,eAAe,KAAK;AAAA,MACpB,cAAc,KAAK;AAAA,MACnB,eAAe,eAAe,KAAK,kBAAkB;AAAA,MACrD,gBAAgB,qBAAqB,KAAK,eAAe;AAAA,MACzD,YAAY,KAAK,YAAY,IAAI,oBAAoB;AAAA,IACvD,EAAE;AAAA,EACJ;AACF;","names":["product"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nadohq/engine-client",
|
|
3
|
-
"version": "0.1.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"description": "> TODO: description",
|
|
@@ -36,16 +36,22 @@
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
},
|
|
39
|
+
"react-native": "./dist/index.js",
|
|
40
|
+
"main": "./dist/index.cjs",
|
|
41
|
+
"module": "./dist/index.js",
|
|
42
|
+
"types": "./dist/index.d.ts",
|
|
39
43
|
"dependencies": {
|
|
40
|
-
"@nadohq/shared": "
|
|
41
|
-
"axios": "
|
|
42
|
-
"ts-mixer": "
|
|
44
|
+
"@nadohq/shared": "0.1.0",
|
|
45
|
+
"axios": "catalog:",
|
|
46
|
+
"ts-mixer": "catalog:"
|
|
43
47
|
},
|
|
44
48
|
"peerDependencies": {
|
|
45
|
-
"
|
|
49
|
+
"bignumber.js": "catalog:",
|
|
50
|
+
"viem": "catalog:"
|
|
46
51
|
},
|
|
47
52
|
"devDependencies": {
|
|
48
|
-
"
|
|
53
|
+
"bignumber.js": "catalog:",
|
|
54
|
+
"viem": "catalog:"
|
|
49
55
|
},
|
|
50
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "be24947f588c4fcc294607e985e572c81760f45a"
|
|
51
57
|
}
|
|
@@ -138,12 +138,15 @@ export class EngineExecuteBuilder {
|
|
|
138
138
|
async buildPlaceOrdersPayload(
|
|
139
139
|
clientParams: EngineExecuteRequestParamsByType['place_orders'],
|
|
140
140
|
): Promise<EngineServerExecuteRequestByType['place_orders']> {
|
|
141
|
-
return
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
141
|
+
return {
|
|
142
|
+
orders: await Promise.all(
|
|
143
|
+
clientParams.orders.map(async (orderParams) => {
|
|
144
|
+
const payload = await this.buildPlaceOrderPayload(orderParams);
|
|
145
|
+
return payload.payload;
|
|
146
|
+
}),
|
|
147
|
+
),
|
|
148
|
+
stop_on_failure: clientParams.stopOnFailure ?? null,
|
|
149
|
+
};
|
|
147
150
|
}
|
|
148
151
|
|
|
149
152
|
/**
|
|
@@ -42,6 +42,13 @@ export class EngineExecuteClient extends EngineBaseClient {
|
|
|
42
42
|
};
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
async placeOrders(params: EngineExecuteRequestParamsByType['place_orders']) {
|
|
46
|
+
return this.execute(
|
|
47
|
+
'place_orders',
|
|
48
|
+
await this.payloadBuilder.buildPlaceOrdersPayload(params),
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
45
52
|
async cancelOrders(
|
|
46
53
|
params: EngineExecuteRequestParamsByType['cancel_orders'],
|
|
47
54
|
) {
|
|
@@ -104,11 +111,4 @@ export class EngineExecuteClient extends EngineBaseClient {
|
|
|
104
111
|
await this.payloadBuilder.buildBurnNlpPayload(params),
|
|
105
112
|
);
|
|
106
113
|
}
|
|
107
|
-
|
|
108
|
-
async placeOrders(params: EngineExecuteRequestParamsByType['place_orders']) {
|
|
109
|
-
return this.execute(
|
|
110
|
-
'place_orders',
|
|
111
|
-
await this.payloadBuilder.buildPlaceOrdersPayload(params),
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
114
|
}
|