@nadohq/indexer-client 0.1.0-alpha.3 → 0.1.0-alpha.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/dist/IndexerBaseClient.cjs +73 -62
  2. package/dist/IndexerBaseClient.cjs.map +1 -1
  3. package/dist/IndexerBaseClient.d.cts +8 -4
  4. package/dist/IndexerBaseClient.d.ts +8 -4
  5. package/dist/IndexerBaseClient.js +26 -14
  6. package/dist/IndexerBaseClient.js.map +1 -1
  7. package/dist/IndexerClient.cjs +17 -16
  8. package/dist/IndexerClient.cjs.map +1 -1
  9. package/dist/IndexerClient.d.cts +2 -3
  10. package/dist/IndexerClient.d.ts +2 -3
  11. package/dist/IndexerClient.js +6 -3
  12. package/dist/IndexerClient.js.map +1 -1
  13. package/dist/dataMappers.cjs +119 -109
  14. package/dist/dataMappers.cjs.map +1 -1
  15. package/dist/dataMappers.d.cts +5 -5
  16. package/dist/dataMappers.d.ts +5 -5
  17. package/dist/dataMappers.js +26 -18
  18. package/dist/dataMappers.js.map +1 -1
  19. package/dist/endpoints.cjs +2 -2
  20. package/dist/endpoints.cjs.map +1 -1
  21. package/dist/endpoints.d.cts +1 -1
  22. package/dist/endpoints.d.ts +1 -1
  23. package/dist/endpoints.js +2 -2
  24. package/dist/endpoints.js.map +1 -1
  25. package/dist/index.cjs +6 -4
  26. package/dist/index.cjs.map +1 -1
  27. package/dist/index.d.cts +10 -11
  28. package/dist/index.d.ts +10 -11
  29. package/dist/index.js +3 -2
  30. package/dist/index.js.map +1 -1
  31. package/dist/types/clientTypes.cjs.map +1 -1
  32. package/dist/types/clientTypes.d.cts +62 -13
  33. package/dist/types/clientTypes.d.ts +62 -13
  34. package/dist/types/index.cjs +11 -11
  35. package/dist/types/index.cjs.map +1 -1
  36. package/dist/types/index.d.cts +6 -7
  37. package/dist/types/index.d.ts +6 -7
  38. package/dist/types/index.js +5 -5
  39. package/dist/types/index.js.map +1 -1
  40. package/dist/types/paginatedEventsTypes.cjs.map +1 -1
  41. package/dist/types/paginatedEventsTypes.d.cts +6 -7
  42. package/dist/types/paginatedEventsTypes.d.ts +6 -7
  43. package/dist/types/serverModelTypes.cjs.map +1 -1
  44. package/dist/types/serverModelTypes.d.cts +8 -4
  45. package/dist/types/serverModelTypes.d.ts +8 -4
  46. package/dist/types/serverTypes.cjs.map +1 -1
  47. package/dist/types/serverTypes.d.cts +28 -5
  48. package/dist/types/serverTypes.d.ts +28 -5
  49. package/dist/utils/index.d.cts +2 -3
  50. package/dist/utils/index.d.ts +2 -3
  51. package/dist/utils/indexerBalanceValue.cjs.map +1 -1
  52. package/dist/utils/indexerBalanceValue.d.cts +2 -3
  53. package/dist/utils/indexerBalanceValue.d.ts +2 -3
  54. package/dist/utils/indexerBalanceValue.js.map +1 -1
  55. package/package.json +4 -5
  56. package/src/IndexerBaseClient.ts +41 -20
  57. package/src/IndexerClient.ts +9 -6
  58. package/src/dataMappers.ts +33 -21
  59. package/src/endpoints.ts +2 -2
  60. package/src/index.ts +3 -2
  61. package/src/types/clientTypes.ts +73 -14
  62. package/src/types/index.ts +5 -5
  63. package/src/types/paginatedEventsTypes.ts +2 -3
  64. package/src/types/serverModelTypes.ts +8 -4
  65. package/src/types/serverTypes.ts +38 -5
  66. package/src/utils/indexerBalanceValue.ts +1 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/IndexerClient.ts"],"sourcesContent":["import {\n ProductEngineType,\n QUOTE_PRODUCT_ID,\n subaccountFromHex,\n NLP_PRODUCT_ID,\n} from '@nadohq/contracts';\nimport { toBigDecimal, toIntegerString } from '@nadohq/utils';\n\nimport { IndexerBaseClient } from './IndexerBaseClient';\nimport {\n BaseIndexerPaginatedEvent,\n CollateralEventType,\n GetIndexerPaginatedInterestFundingPaymentsResponse,\n GetIndexerPaginatedLeaderboardParams,\n GetIndexerPaginatedLeaderboardResponse,\n GetIndexerPaginatedOrdersParams,\n GetIndexerPaginatedOrdersResponse,\n GetIndexerSubaccountCollateralEventsParams,\n GetIndexerSubaccountCollateralEventsResponse,\n GetIndexerSubaccountInterestFundingPaymentsParams,\n GetIndexerSubaccountLiquidationEventsParams,\n GetIndexerSubaccountLiquidationEventsResponse,\n GetIndexerSubaccountMatchEventParams,\n GetIndexerSubaccountMatchEventsResponse,\n GetIndexerSubaccountSettlementEventsParams,\n GetIndexerSubaccountSettlementEventsResponse,\n GetIndexerSubaccountNlpEventsParams,\n GetIndexerSubaccountNlpEventsResponse,\n IndexerCollateralEvent,\n IndexerEventPerpStateSnapshot,\n IndexerEventSpotStateSnapshot,\n IndexerEventWithTx,\n IndexerLiquidationEvent,\n IndexerSettlementEvent,\n IndexerNlpEvent,\n PaginatedIndexerEventsResponse,\n} from './types';\n\n/**\n * Indexer client providing paginated queries for historical data from the Nado indexer service\n */\nexport class IndexerClient extends IndexerBaseClient {\n async getPaginatedSubaccountMatchEvents(\n params: GetIndexerSubaccountMatchEventParams,\n ): Promise<GetIndexerSubaccountMatchEventsResponse> {\n const {\n startCursor,\n maxTimestampInclusive,\n limit: requestedLimit,\n subaccountName,\n subaccountOwner,\n isolated,\n productIds,\n } = params;\n\n const limit = requestedLimit + 1;\n const events = await this.getMatchEvents({\n startCursor,\n maxTimestampInclusive,\n limit,\n subaccount: { subaccountName, subaccountOwner },\n productIds,\n isolated,\n });\n\n return this.getPaginationEventsResponse(events, requestedLimit);\n }\n\n async getPaginatedSubaccountNlpEvents(\n params: GetIndexerSubaccountNlpEventsParams,\n ): Promise<GetIndexerSubaccountNlpEventsResponse> {\n const {\n startCursor,\n maxTimestampInclusive,\n limit: requestedLimit,\n subaccountName,\n subaccountOwner,\n } = params;\n\n // There are 2 events per mint/burn for spot - one associated with the NLP product & the other with the primary quote\n const limit = requestedLimit + 1;\n const baseResponse = await this.getEvents({\n startCursor,\n maxTimestampInclusive,\n eventTypes: ['mint_nlp', 'burn_nlp'],\n limit: {\n type: 'txs',\n value: limit,\n },\n subaccount: { subaccountName, subaccountOwner },\n });\n\n // Now aggregate results by the submission index, use map to maintain insertion order\n const eventsBySubmissionIdx = new Map<string, IndexerNlpEvent>();\n\n baseResponse.forEach((event) => {\n const mappedEvent = (() => {\n const existingEvent = eventsBySubmissionIdx.get(event.submissionIndex);\n if (existingEvent) {\n return existingEvent;\n }\n\n const newEvent: IndexerNlpEvent = {\n nlpDelta: toBigDecimal(0),\n primaryQuoteDelta: toBigDecimal(0),\n timestamp: event.timestamp,\n submissionIndex: event.submissionIndex,\n tx: event.tx,\n ...subaccountFromHex(event.subaccount),\n };\n eventsBySubmissionIdx.set(event.submissionIndex, newEvent);\n\n return newEvent;\n })();\n\n const balanceDelta = event.state.postBalance.amount.minus(\n event.state.preBalance.amount,\n );\n\n const productId = event.state.market.productId;\n if (productId === QUOTE_PRODUCT_ID) {\n mappedEvent.primaryQuoteDelta = balanceDelta;\n } else if (productId === NLP_PRODUCT_ID) {\n mappedEvent.nlpDelta = balanceDelta;\n } else {\n throw Error(`Invalid product ID for NLP event ${productId}`);\n }\n });\n\n // Force cast to get rid of the `Partial`\n const events = Array.from(eventsBySubmissionIdx.values());\n return this.getPaginationEventsResponse(events, requestedLimit);\n }\n\n async getPaginatedSubaccountCollateralEvents(\n params: GetIndexerSubaccountCollateralEventsParams,\n ): Promise<GetIndexerSubaccountCollateralEventsResponse> {\n const {\n startCursor,\n maxTimestampInclusive,\n limit: requestedLimit,\n subaccountName,\n subaccountOwner,\n eventTypes,\n isolated,\n } = params;\n\n const limit = requestedLimit + 1;\n const baseResponse = await this.getEvents({\n startCursor,\n maxTimestampInclusive,\n eventTypes: eventTypes ?? [\n 'deposit_collateral',\n 'withdraw_collateral',\n 'transfer_quote',\n ],\n limit: {\n type: 'txs',\n value: limit,\n },\n subaccount: { subaccountName, subaccountOwner },\n isolated,\n });\n\n const events = baseResponse.map((event): IndexerCollateralEvent => {\n if (event.state.type !== ProductEngineType.SPOT) {\n throw Error('Incorrect event state for collateral event');\n }\n\n return {\n timestamp: event.timestamp,\n // This cast is safe as the query param restricts to collateral events\n eventType: event.eventType as CollateralEventType,\n submissionIndex: event.submissionIndex,\n snapshot: event.state,\n amount: event.state.postBalance.amount.minus(\n event.state.preBalance.amount,\n ),\n newAmount: event.state.postBalance.amount,\n tx: event.tx,\n ...subaccountFromHex(event.subaccount),\n };\n });\n\n return this.getPaginationEventsResponse(events, requestedLimit);\n }\n\n async getPaginatedSubaccountOrders(\n params: GetIndexerPaginatedOrdersParams,\n ): Promise<GetIndexerPaginatedOrdersResponse> {\n const {\n startCursor,\n maxTimestampInclusive,\n limit: requestedLimit,\n subaccountName,\n subaccountOwner,\n productIds,\n isolated,\n } = params;\n\n const limit = requestedLimit + 1;\n const baseResponse = await this.getOrders({\n startCursor,\n maxTimestampInclusive,\n subaccount: { subaccountName, subaccountOwner },\n limit,\n productIds,\n isolated,\n });\n\n // Same pagination meta logic as events, but duplicate for now as this return type is slightly different\n const truncatedOrders = baseResponse.slice(0, requestedLimit);\n const hasMore = baseResponse.length > truncatedOrders.length;\n return {\n meta: {\n hasMore,\n nextCursor: baseResponse[truncatedOrders.length]?.submissionIndex,\n },\n orders: truncatedOrders,\n };\n }\n\n async getPaginatedSubaccountSettlementEvents(\n params: GetIndexerSubaccountSettlementEventsParams,\n ): Promise<GetIndexerSubaccountSettlementEventsResponse> {\n const {\n startCursor,\n maxTimestampInclusive,\n limit: requestedLimit,\n subaccountName,\n subaccountOwner,\n } = params;\n\n // Each settlement has a quote & perp balance change, so 2 events per settlement tx\n const limit = requestedLimit + 1;\n const baseResponse = await this.getEvents({\n startCursor,\n maxTimestampInclusive,\n eventTypes: ['settle_pnl'],\n limit: {\n type: 'txs',\n value: limit,\n },\n subaccount: { subaccountName, subaccountOwner },\n });\n\n const events = baseResponse\n .map((event): IndexerSettlementEvent | undefined => {\n if (event.state.market.productId === QUOTE_PRODUCT_ID) {\n return;\n }\n if (event.state.type !== ProductEngineType.PERP) {\n throw Error('Incorrect event state for settlement event');\n }\n\n return {\n timestamp: event.timestamp,\n submissionIndex: event.submissionIndex,\n snapshot: event.state,\n // Spot quote delta = -vQuote delta\n quoteDelta: event.state.preBalance.vQuoteBalance.minus(\n event.state.postBalance.vQuoteBalance,\n ),\n isolated: event.isolated,\n tx: event.tx,\n ...subaccountFromHex(event.subaccount),\n };\n })\n .filter((event): event is IndexerSettlementEvent => !!event);\n\n return this.getPaginationEventsResponse(events, requestedLimit);\n }\n\n async getPaginatedSubaccountLiquidationEvents(\n params: GetIndexerSubaccountLiquidationEventsParams,\n ): Promise<GetIndexerSubaccountLiquidationEventsResponse> {\n const {\n startCursor,\n maxTimestampInclusive,\n limit: requestedLimit,\n subaccountName,\n subaccountOwner,\n } = params;\n\n // There is 1 event emitted per product, including quote\n // However, if the balance change is 0, then the liquidation did not touch the product\n // A tx operates on a given health group, so only a spot & its associated perp can be actually liquidated within a single tx\n // with an associated quote balance change\n const limit = requestedLimit + 1;\n const baseResponse = await this.getEvents({\n startCursor,\n maxTimestampInclusive,\n eventTypes: ['liquidate_subaccount'],\n limit: {\n type: 'txs',\n value: limit,\n },\n subaccount: { subaccountName, subaccountOwner },\n });\n\n // Now aggregate results by the submission index, use map to maintain insertion order\n const eventsBySubmissionIdx = new Map<\n string,\n Partial<IndexerLiquidationEvent>\n >();\n\n baseResponse.forEach((event) => {\n const mappedEvent = (() => {\n const existingEvent = eventsBySubmissionIdx.get(event.submissionIndex);\n if (existingEvent) {\n return existingEvent;\n }\n\n const newEvent: Partial<IndexerLiquidationEvent> = {\n perp: undefined,\n spot: undefined,\n quote: undefined,\n timestamp: event.timestamp,\n submissionIndex: event.submissionIndex,\n };\n\n return newEvent;\n })();\n\n // The original balance is the negated delta\n const balanceDelta = event.state.postBalance.amount.minus(\n event.state.preBalance.amount,\n );\n\n // Event without balance change - not part of this liq\n // However, we could have zero balance changes for the quote product if this was a partial liquidation\n if (\n balanceDelta.isZero() &&\n event.state.market.productId !== QUOTE_PRODUCT_ID\n ) {\n return;\n }\n\n if (event.state.type === ProductEngineType.PERP) {\n mappedEvent.perp = {\n amountLiquidated: balanceDelta.negated(),\n // This cast is safe because we're checking for event.state.type\n indexerEvent:\n event as IndexerEventWithTx<IndexerEventPerpStateSnapshot>,\n };\n } else if (event.state.market.productId === QUOTE_PRODUCT_ID) {\n mappedEvent.quote = {\n balanceDelta,\n indexerEvent:\n event as IndexerEventWithTx<IndexerEventSpotStateSnapshot>,\n };\n } else {\n mappedEvent.spot = {\n amountLiquidated: balanceDelta.negated(),\n indexerEvent:\n event as IndexerEventWithTx<IndexerEventSpotStateSnapshot>,\n };\n }\n\n eventsBySubmissionIdx.set(event.submissionIndex, mappedEvent);\n });\n\n // Force cast to get rid of the `Partial`\n const events = Array.from(\n eventsBySubmissionIdx.values(),\n ) as IndexerLiquidationEvent[];\n return this.getPaginationEventsResponse(events, requestedLimit);\n }\n\n /**\n * Get all interest funding payments for a given subaccount with the standard pagination response\n * This is a simple wrapper over the underlying `getInterestFundingPayments` function. Very little\n * additional processing is needed because the endpoint is well structured for pagination\n *\n * @param params\n */\n async getPaginatedSubaccountInterestFundingPayments(\n params: GetIndexerSubaccountInterestFundingPaymentsParams,\n ): Promise<GetIndexerPaginatedInterestFundingPaymentsResponse> {\n const {\n limit,\n productIds,\n startCursor,\n maxTimestampInclusive,\n subaccountName,\n subaccountOwner,\n } = params;\n const baseResponse = await this.getInterestFundingPayments({\n limit,\n productIds,\n startCursor,\n maxTimestampInclusive,\n subaccount: {\n subaccountName,\n subaccountOwner,\n },\n });\n\n return {\n ...baseResponse,\n meta: {\n hasMore: baseResponse.nextCursor != null,\n nextCursor: baseResponse.nextCursor ?? undefined,\n },\n };\n }\n\n /**\n * Paginated leaderboard query that paginates on rank number.\n *\n * @param params\n */\n async getPaginatedLeaderboard(\n params: GetIndexerPaginatedLeaderboardParams,\n ): Promise<GetIndexerPaginatedLeaderboardResponse> {\n const requestedLimit = params.limit;\n\n const baseResponse = await this.getLeaderboard({\n contestId: params.contestId,\n rankType: params.rankType,\n // Query for 1 more result for proper pagination\n limit: requestedLimit + 1,\n // Start cursor is the next rank number\n startCursor: params.startCursor,\n });\n\n // Next cursor is the rank number of the (requestedLimit+1)th item\n const nextCursor =\n params.rankType === 'pnl'\n ? baseResponse.participants[requestedLimit]?.pnlRank\n : baseResponse.participants[requestedLimit]?.roiRank;\n\n return {\n ...baseResponse,\n // Truncate the response to the requested limit\n participants: baseResponse.participants.slice(0, requestedLimit),\n meta: {\n hasMore: baseResponse.participants.length > requestedLimit,\n nextCursor:\n nextCursor !== undefined ? toIntegerString(nextCursor) : undefined,\n },\n };\n }\n\n /**\n * A util function to generate the standard pagination response for events\n * @param events\n * @param requestedLimit given by consumers of the SDK\n * @private\n */\n private getPaginationEventsResponse<T extends BaseIndexerPaginatedEvent>(\n events: T[],\n requestedLimit: number,\n ): PaginatedIndexerEventsResponse<T> {\n const truncatedEvents = events.slice(0, requestedLimit);\n const hasMore = events.length > truncatedEvents.length;\n\n return {\n events: truncatedEvents,\n meta: {\n hasMore,\n // We want the NEXT available cursor, so we use the first event after the truncation cutoff\n // If len(events) === len(truncatedEvents), there are no more entries and this is undefined\n nextCursor: events[truncatedEvents.length]?.submissionIndex,\n },\n };\n }\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,cAAc,uBAAuB;AAE9C,SAAS,yBAAyB;AAiC3B,IAAM,gBAAN,cAA4B,kBAAkB;AAAA,EACnD,MAAM,kCACJ,QACkD;AAClD,UAAM;AAAA,MACJ;AAAA,MACA;AAAA,MACA,OAAO;AAAA,MACP;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,IAAI;AAEJ,UAAM,QAAQ,iBAAiB;AAC/B,UAAM,SAAS,MAAM,KAAK,eAAe;AAAA,MACvC;AAAA,MACA;AAAA,MACA;AAAA,MACA,YAAY,EAAE,gBAAgB,gBAAgB;AAAA,MAC9C;AAAA,MACA;AAAA,IACF,CAAC;AAED,WAAO,KAAK,4BAA4B,QAAQ,c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nC,UAAM,kBAAkB,OAAO,MAAM,GAAG,cAAc;AACtD,UAAM,UAAU,OAAO,SAAS,gBAAgB;AAEhD,WAAO;AAAA,MACL,QAAQ;AAAA,MACR,MAAM;AAAA,QACJ;AAAA;AAAA;AAAA,QAGA,YAAY,OAAO,gBAAgB,MAAM,GAAG;AAAA,MAC9C;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/IndexerClient.ts"],"sourcesContent":["import {\n NLP_PRODUCT_ID,\n ProductEngineType,\n QUOTE_PRODUCT_ID,\n subaccountFromHex,\n toBigDecimal,\n toIntegerString,\n} from '@nadohq/shared';\n\nimport { IndexerBaseClient } from './IndexerBaseClient';\nimport {\n BaseIndexerPaginatedEvent,\n CollateralEventType,\n GetIndexerPaginatedInterestFundingPaymentsResponse,\n GetIndexerPaginatedLeaderboardParams,\n GetIndexerPaginatedLeaderboardResponse,\n GetIndexerPaginatedOrdersParams,\n GetIndexerPaginatedOrdersResponse,\n GetIndexerSubaccountCollateralEventsParams,\n GetIndexerSubaccountCollateralEventsResponse,\n GetIndexerSubaccountInterestFundingPaymentsParams,\n GetIndexerSubaccountLiquidationEventsParams,\n GetIndexerSubaccountLiquidationEventsResponse,\n GetIndexerSubaccountMatchEventParams,\n GetIndexerSubaccountMatchEventsResponse,\n GetIndexerSubaccountNlpEventsParams,\n GetIndexerSubaccountNlpEventsResponse,\n GetIndexerSubaccountSettlementEventsParams,\n GetIndexerSubaccountSettlementEventsResponse,\n IndexerCollateralEvent,\n IndexerEventPerpStateSnapshot,\n IndexerEventSpotStateSnapshot,\n IndexerEventWithTx,\n IndexerLiquidationEvent,\n IndexerNlpEvent,\n IndexerSettlementEvent,\n PaginatedIndexerEventsResponse,\n} from './types';\n\n/**\n * Indexer client providing paginated queries for historical data from the Nado indexer service\n */\nexport class IndexerClient extends IndexerBaseClient {\n async getPaginatedSubaccountMatchEvents(\n params: GetIndexerSubaccountMatchEventParams,\n ): Promise<GetIndexerSubaccountMatchEventsResponse> {\n const {\n startCursor,\n maxTimestampInclusive,\n limit: requestedLimit,\n subaccountName,\n subaccountOwner,\n isolated,\n productIds,\n } = params;\n\n const limit = requestedLimit + 1;\n const events = await this.getMatchEvents({\n startCursor,\n maxTimestampInclusive,\n limit,\n subaccount: { subaccountName, subaccountOwner },\n productIds,\n isolated,\n });\n\n return this.getPaginationEventsResponse(events, requestedLimit);\n }\n\n async getPaginatedSubaccountNlpEvents(\n params: GetIndexerSubaccountNlpEventsParams,\n ): Promise<GetIndexerSubaccountNlpEventsResponse> {\n const {\n startCursor,\n maxTimestampInclusive,\n limit: requestedLimit,\n subaccountName,\n subaccountOwner,\n } = params;\n\n // There are 2 events per mint/burn for spot - one associated with the NLP product & the other with the primary quote\n const limit = requestedLimit + 1;\n const baseResponse = await this.getEvents({\n startCursor,\n maxTimestampInclusive,\n eventTypes: ['mint_nlp', 'burn_nlp'],\n limit: {\n type: 'txs',\n value: limit,\n },\n subaccount: { subaccountName, subaccountOwner },\n });\n\n // Now aggregate results by the submission index, use map to maintain insertion order\n const eventsBySubmissionIdx = new Map<string, IndexerNlpEvent>();\n\n baseResponse.forEach((event) => {\n const mappedEvent = (() => {\n const existingEvent = eventsBySubmissionIdx.get(event.submissionIndex);\n if (existingEvent) {\n return existingEvent;\n }\n\n const newEvent: IndexerNlpEvent = {\n nlpDelta: toBigDecimal(0),\n primaryQuoteDelta: toBigDecimal(0),\n timestamp: event.timestamp,\n submissionIndex: event.submissionIndex,\n tx: event.tx,\n ...subaccountFromHex(event.subaccount),\n };\n eventsBySubmissionIdx.set(event.submissionIndex, newEvent);\n\n return newEvent;\n })();\n\n const balanceDelta = event.state.postBalance.amount.minus(\n event.state.preBalance.amount,\n );\n\n const productId = event.state.market.productId;\n if (productId === QUOTE_PRODUCT_ID) {\n mappedEvent.primaryQuoteDelta = balanceDelta;\n } else if (productId === NLP_PRODUCT_ID) {\n mappedEvent.nlpDelta = balanceDelta;\n } else {\n throw Error(`Invalid product ID for NLP event ${productId}`);\n }\n });\n\n // Force cast to get rid of the `Partial`\n const events = Array.from(eventsBySubmissionIdx.values());\n return this.getPaginationEventsResponse(events, requestedLimit);\n }\n\n async getPaginatedSubaccountCollateralEvents(\n params: GetIndexerSubaccountCollateralEventsParams,\n ): Promise<GetIndexerSubaccountCollateralEventsResponse> {\n const {\n startCursor,\n maxTimestampInclusive,\n limit: requestedLimit,\n subaccountName,\n subaccountOwner,\n eventTypes,\n isolated,\n } = params;\n\n const limit = requestedLimit + 1;\n const baseResponse = await this.getEvents({\n startCursor,\n maxTimestampInclusive,\n eventTypes: eventTypes ?? [\n 'deposit_collateral',\n 'withdraw_collateral',\n 'transfer_quote',\n ],\n limit: {\n type: 'txs',\n value: limit,\n },\n subaccount: { subaccountName, subaccountOwner },\n isolated,\n });\n\n const events = baseResponse.map((event): IndexerCollateralEvent => {\n if (event.state.type !== ProductEngineType.SPOT) {\n throw Error('Incorrect event state for collateral event');\n }\n\n return {\n timestamp: event.timestamp,\n // This cast is safe as the query param restricts to collateral events\n eventType: event.eventType as CollateralEventType,\n submissionIndex: event.submissionIndex,\n snapshot: event.state,\n amount: event.state.postBalance.amount.minus(\n event.state.preBalance.amount,\n ),\n newAmount: event.state.postBalance.amount,\n tx: event.tx,\n ...subaccountFromHex(event.subaccount),\n };\n });\n\n return this.getPaginationEventsResponse(events, requestedLimit);\n }\n\n async getPaginatedSubaccountOrders(\n params: GetIndexerPaginatedOrdersParams,\n ): Promise<GetIndexerPaginatedOrdersResponse> {\n const {\n startCursor,\n maxTimestampInclusive,\n limit: requestedLimit,\n subaccountName,\n subaccountOwner,\n productIds,\n triggerTypes,\n isolated,\n } = params;\n\n const limit = requestedLimit + 1;\n const baseResponse = await this.getOrders({\n startCursor,\n maxTimestampInclusive,\n subaccount: { subaccountName, subaccountOwner },\n limit,\n productIds,\n triggerTypes,\n isolated,\n });\n\n // Same pagination meta logic as events, but duplicate for now as this return type is slightly different\n const truncatedOrders = baseResponse.slice(0, requestedLimit);\n const hasMore = baseResponse.length > truncatedOrders.length;\n return {\n meta: {\n hasMore,\n nextCursor: baseResponse[truncatedOrders.length]?.submissionIndex,\n },\n orders: truncatedOrders,\n };\n }\n\n async getPaginatedSubaccountSettlementEvents(\n params: GetIndexerSubaccountSettlementEventsParams,\n ): Promise<GetIndexerSubaccountSettlementEventsResponse> {\n const {\n startCursor,\n maxTimestampInclusive,\n limit: requestedLimit,\n subaccountName,\n subaccountOwner,\n } = params;\n\n // Each settlement has a quote & perp balance change, so 2 events per settlement tx\n const limit = requestedLimit + 1;\n const baseResponse = await this.getEvents({\n startCursor,\n maxTimestampInclusive,\n eventTypes: ['settle_pnl'],\n limit: {\n type: 'txs',\n value: limit,\n },\n subaccount: { subaccountName, subaccountOwner },\n });\n\n const events = baseResponse\n .map((event): IndexerSettlementEvent | undefined => {\n if (event.state.market.productId === QUOTE_PRODUCT_ID) {\n return;\n }\n if (event.state.type !== ProductEngineType.PERP) {\n throw Error('Incorrect event state for settlement event');\n }\n\n return {\n timestamp: event.timestamp,\n submissionIndex: event.submissionIndex,\n snapshot: event.state,\n // Spot quote delta = -vQuote delta\n quoteDelta: event.state.preBalance.vQuoteBalance.minus(\n event.state.postBalance.vQuoteBalance,\n ),\n isolated: event.isolated,\n tx: event.tx,\n ...subaccountFromHex(event.subaccount),\n };\n })\n .filter((event): event is IndexerSettlementEvent => !!event);\n\n return this.getPaginationEventsResponse(events, requestedLimit);\n }\n\n async getPaginatedSubaccountLiquidationEvents(\n params: GetIndexerSubaccountLiquidationEventsParams,\n ): Promise<GetIndexerSubaccountLiquidationEventsResponse> {\n const {\n startCursor,\n maxTimestampInclusive,\n limit: requestedLimit,\n subaccountName,\n subaccountOwner,\n } = params;\n\n // There is 1 event emitted per product, including quote\n // However, if the balance change is 0, then the liquidation did not touch the product\n // A tx operates on a given health group, so only a spot & its associated perp can be actually liquidated within a single tx\n // with an associated quote balance change\n const limit = requestedLimit + 1;\n const baseResponse = await this.getEvents({\n startCursor,\n maxTimestampInclusive,\n eventTypes: ['liquidate_subaccount'],\n limit: {\n type: 'txs',\n value: limit,\n },\n subaccount: { subaccountName, subaccountOwner },\n });\n\n // Now aggregate results by the submission index, use map to maintain insertion order\n const eventsBySubmissionIdx = new Map<\n string,\n Partial<IndexerLiquidationEvent>\n >();\n\n baseResponse.forEach((event) => {\n const mappedEvent = (() => {\n const existingEvent = eventsBySubmissionIdx.get(event.submissionIndex);\n if (existingEvent) {\n return existingEvent;\n }\n\n const newEvent: Partial<IndexerLiquidationEvent> = {\n perp: undefined,\n spot: undefined,\n quote: undefined,\n timestamp: event.timestamp,\n submissionIndex: event.submissionIndex,\n };\n\n return newEvent;\n })();\n\n // The original balance is the negated delta\n const balanceDelta = event.state.postBalance.amount.minus(\n event.state.preBalance.amount,\n );\n\n // Event without balance change - not part of this liq\n // However, we could have zero balance changes for the quote product if this was a partial liquidation\n if (\n balanceDelta.isZero() &&\n event.state.market.productId !== QUOTE_PRODUCT_ID\n ) {\n return;\n }\n\n if (event.state.type === ProductEngineType.PERP) {\n mappedEvent.perp = {\n amountLiquidated: balanceDelta.negated(),\n // This cast is safe because we're checking for event.state.type\n indexerEvent:\n event as IndexerEventWithTx<IndexerEventPerpStateSnapshot>,\n };\n } else if (event.state.market.productId === QUOTE_PRODUCT_ID) {\n mappedEvent.quote = {\n balanceDelta,\n indexerEvent:\n event as IndexerEventWithTx<IndexerEventSpotStateSnapshot>,\n };\n } else {\n mappedEvent.spot = {\n amountLiquidated: balanceDelta.negated(),\n indexerEvent:\n event as IndexerEventWithTx<IndexerEventSpotStateSnapshot>,\n };\n }\n\n eventsBySubmissionIdx.set(event.submissionIndex, mappedEvent);\n });\n\n // Force cast to get rid of the `Partial`\n const events = Array.from(\n eventsBySubmissionIdx.values(),\n ) as IndexerLiquidationEvent[];\n return this.getPaginationEventsResponse(events, requestedLimit);\n }\n\n /**\n * Get all interest funding payments for a given subaccount with the standard pagination response\n * This is a simple wrapper over the underlying `getInterestFundingPayments` function. Very little\n * additional processing is needed because the endpoint is well structured for pagination\n *\n * @param params\n */\n async getPaginatedSubaccountInterestFundingPayments(\n params: GetIndexerSubaccountInterestFundingPaymentsParams,\n ): Promise<GetIndexerPaginatedInterestFundingPaymentsResponse> {\n const {\n limit,\n productIds,\n startCursor,\n maxTimestampInclusive,\n subaccountName,\n subaccountOwner,\n } = params;\n const baseResponse = await this.getInterestFundingPayments({\n limit,\n productIds,\n startCursor,\n maxTimestampInclusive,\n subaccount: {\n subaccountName,\n subaccountOwner,\n },\n });\n\n return {\n ...baseResponse,\n meta: {\n hasMore: baseResponse.nextCursor != null,\n nextCursor: baseResponse.nextCursor ?? undefined,\n },\n };\n }\n\n /**\n * Paginated leaderboard query that paginates on rank number.\n *\n * @param params\n */\n async getPaginatedLeaderboard(\n params: GetIndexerPaginatedLeaderboardParams,\n ): Promise<GetIndexerPaginatedLeaderboardResponse> {\n const requestedLimit = params.limit;\n\n const baseResponse = await this.getLeaderboard({\n contestId: params.contestId,\n rankType: params.rankType,\n // Query for 1 more result for proper pagination\n limit: requestedLimit + 1,\n // Start cursor is the next rank number\n startCursor: params.startCursor,\n });\n\n // Next cursor is the rank number of the (requestedLimit+1)th item\n const nextCursor =\n params.rankType === 'pnl'\n ? baseResponse.participants[requestedLimit]?.pnlRank\n : baseResponse.participants[requestedLimit]?.roiRank;\n\n return {\n ...baseResponse,\n // Truncate the response to the requested limit\n participants: baseResponse.participants.slice(0, requestedLimit),\n meta: {\n hasMore: baseResponse.participants.length > requestedLimit,\n nextCursor:\n nextCursor !== undefined ? toIntegerString(nextCursor) : undefined,\n },\n };\n }\n\n /**\n * A util function to generate the standard pagination response for events\n * @param events\n * @param requestedLimit given by consumers of the SDK\n * @private\n */\n private getPaginationEventsResponse<T extends BaseIndexerPaginatedEvent>(\n events: T[],\n requestedLimit: number,\n ): PaginatedIndexerEventsResponse<T> {\n const truncatedEvents = events.slice(0, requestedLimit);\n const hasMore = events.length > truncatedEvents.length;\n\n return {\n events: truncatedEvents,\n meta: {\n hasMore,\n // We want the NEXT available cursor, so we use the first event after the truncation cutoff\n // If len(events) === len(truncatedEvents), there are no more entries and this is undefined\n nextCursor: events[truncatedEvents.length]?.submissionIndex,\n },\n };\n }\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,yBAAyB;AAiC3B,IAAM,gBAAN,cAA4B,kBAAkB;AAAA,EACnD,MAAM,kCACJ,QACkD;AAClD,UAAM;AAAA,MACJ;AAAA,MACA;AAAA,MACA,OAAO;AAAA,MACP;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,IAAI;AAEJ,UAAM,QAAQ,iBAAiB;AAC/B,UAAM,SAAS,MAAM,KAAK,eAAe;AAAA,MACvC;AAAA,MACA;AAAA,MACA;AAAA,MACA,YAAY,EAAE,gBAAgB,gBAAgB;AAAA,MAC9C;AAAA,MACA;AAAA,IACF,CAAC;AAED,WAAO,KAAK,4BAA4B,QAAQ,cAAc;AAAA,EAChE;AAAA,EAEA,MAAM,gCACJ,QACgD;AAChD,UAAM;AAAA,MACJ;AAAA,MACA;AAAA,MACA,OAAO;AAAA,MACP;AAAA,MACA;AAAA,IACF,IAAI;AAGJ,UAAM,QAAQ,iBAAiB;AAC/B,UAAM,eAAe,MAAM,KAAK,UAAU;AAAA,MACxC;AAAA,MACA;AAAA,MACA,YAAY,CAAC,YAAY,UAAU;AAAA,MACnC,OAAO;AAAA,QACL,MAAM;AAAA,QACN,OAAO;AAAA,MACT;AAAA,MACA,YAAY,EAAE,gBAAgB,gBAAgB;AAAA,IAChD,CAAC;AAGD,UAAM,wBAAwB,oBAAI,IAA6B;AAE/D,iBAAa,QAAQ,CAAC,UAAU;AAC9B,YAAM,eAAe,MAAM;AACzB,cAAM,gBAAgB,sBAAsB,IAAI,MAAM,eAAe;AACrE,YAAI,eAAe;AACjB,iBAAO;AAAA,QACT;AAEA,cAAM,WAA4B;AAAA,UAChC,UAAU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AAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,wBACJ,QACiD;AACjD,UAAM,iBAAiB,OAAO;AAE9B,UAAM,eAAe,MAAM,KAAK,eAAe;AAAA,MAC7C,WAAW,OAAO;AAAA,MAClB,UAAU,OAAO;AAAA;AAAA,MAEjB,OAAO,iBAAiB;AAAA;AAAA,MAExB,aAAa,OAAO;AAAA,IACtB,CAAC;AAGD,UAAM,aACJ,OAAO,aAAa,QAChB,aAAa,aAAa,cAAc,GAAG,UAC3C,aAAa,aAAa,cAAc,GAAG;AAEjD,WAAO;AAAA,MACL,GAAG;AAAA;AAAA,MAEH,cAAc,aAAa,aAAa,MAAM,GAAG,cAAc;AAAA,MAC/D,MAAM;AAAA,QACJ,SAAS,aAAa,aAAa,SAAS;AAAA,QAC5C,YACE,eAAe,SAAY,gBAAgB,UAAU,IAAI;AAAA,MAC7D;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQQ,4BACN,QACA,gBACmC;AACnC,UAAM,kBAAkB,OAAO,MAAM,GAAG,cAAc;AACtD,UAAM,UAAU,OAAO,SAAS,gBAAgB;AAEhD,WAAO;AAAA,MACL,QAAQ;AAAA,MACR,MAAM;AAAA,QACJ;AAAA;AAAA;AAAA,QAGA,YAAY,OAAO,gBAAgB,MAAM,GAAG;AAAA,MAC9C;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
@@ -36,16 +36,16 @@ __export(dataMappers_exports, {
36
36
  mapIndexerProductPayment: () => mapIndexerProductPayment,
37
37
  mapIndexerServerBalance: () => mapIndexerServerBalance,
38
38
  mapIndexerServerProduct: () => mapIndexerServerProduct,
39
+ mapIndexerV2Ticker: () => mapIndexerV2Ticker,
39
40
  mapSnapshotsIntervalToServerParams: () => mapSnapshotsIntervalToServerParams
40
41
  });
41
42
  module.exports = __toCommonJS(dataMappers_exports);
42
- var import_contracts = require("@nadohq/contracts");
43
43
  var import_engine_client = require("@nadohq/engine-client");
44
- var import_utils = require("@nadohq/utils");
44
+ var import_shared = require("@nadohq/shared");
45
45
  function mapSnapshotsIntervalToServerParams(params) {
46
46
  return {
47
47
  count: params.limit,
48
- max_time: params.maxTimeInclusive ? (0, import_utils.toIntegerString)(params.maxTimeInclusive) : void 0,
48
+ max_time: params.maxTimeInclusive ? (0, import_shared.toIntegerString)(params.maxTimeInclusive) : void 0,
49
49
  granularity: params.granularity
50
50
  };
51
51
  }
@@ -58,45 +58,41 @@ function mapIndexerServerProduct(product) {
58
58
  function mapIndexerServerBalance(balance) {
59
59
  if ("spot" in balance) {
60
60
  return {
61
- amount: (0, import_utils.toBigDecimal)(balance.spot.balance.amount),
61
+ amount: (0, import_shared.toBigDecimal)(balance.spot.balance.amount),
62
62
  productId: balance.spot.product_id,
63
- type: import_contracts.ProductEngineType.SPOT
63
+ type: import_shared.ProductEngineType.SPOT
64
64
  };
65
65
  }
66
66
  return {
67
- amount: (0, import_utils.toBigDecimal)(balance.perp.balance.amount),
67
+ amount: (0, import_shared.toBigDecimal)(balance.perp.balance.amount),
68
68
  productId: balance.perp.product_id,
69
- type: import_contracts.ProductEngineType.PERP,
70
- vQuoteBalance: (0, import_utils.toBigDecimal)(balance.perp.balance.v_quote_balance)
69
+ type: import_shared.ProductEngineType.PERP,
70
+ vQuoteBalance: (0, import_shared.toBigDecimal)(balance.perp.balance.v_quote_balance)
71
71
  };
72
72
  }
73
73
  function mapIndexerOrder(order) {
74
- const expiration = (0, import_utils.toBigDecimal)(order.expiration);
75
- const expirationEncodedData = (0, import_contracts.parseRawExpirationTimestamp)(order.expiration);
74
+ const appendix = (0, import_shared.unpackOrderAppendix)(order.appendix);
76
75
  return {
77
- amount: (0, import_utils.toBigDecimal)(order.amount),
76
+ amount: (0, import_shared.toBigDecimal)(order.amount),
78
77
  digest: order.digest,
79
- isolated: order.isolated,
80
- rawExpiration: expiration,
81
- isReduceOnly: expirationEncodedData.reduceOnly,
82
- expiration: expirationEncodedData.expirationTime,
83
- orderType: expirationEncodedData.type,
84
- nonce: (0, import_utils.toBigDecimal)(order.nonce),
85
- recvTimeSeconds: (0, import_contracts.getRecvTimeFromOrderNonce)(order.nonce) / 1e3,
86
- price: (0, import_utils.removeDecimals)(order.price_x18),
78
+ expiration: Number(order.expiration),
79
+ appendix,
80
+ nonce: (0, import_shared.toBigDecimal)(order.nonce),
81
+ recvTimeSeconds: (0, import_shared.getRecvTimeFromOrderNonce)(order.nonce) / 1e3,
82
+ price: (0, import_shared.removeDecimals)(order.price_x18),
87
83
  productId: order.product_id,
88
84
  subaccount: order.subaccount,
89
85
  submissionIndex: order.submission_idx,
90
- baseFilled: (0, import_utils.toBigDecimal)(order.base_filled),
91
- quoteFilled: (0, import_utils.toBigDecimal)(order.quote_filled),
92
- totalFee: (0, import_utils.toBigDecimal)(order.fee)
86
+ baseFilled: (0, import_shared.toBigDecimal)(order.base_filled),
87
+ quoteFilled: (0, import_shared.toBigDecimal)(order.quote_filled),
88
+ totalFee: (0, import_shared.toBigDecimal)(order.fee)
93
89
  };
94
90
  }
95
91
  function mapIndexerEvent(event) {
96
92
  const eventState = (() => {
97
93
  if ("spot" in event.pre_balance) {
98
94
  return {
99
- type: import_contracts.ProductEngineType.SPOT,
95
+ type: import_shared.ProductEngineType.SPOT,
100
96
  market: mapIndexerServerProduct(event.product),
101
97
  preBalance: mapIndexerServerBalance(
102
98
  event.pre_balance
@@ -107,7 +103,7 @@ function mapIndexerEvent(event) {
107
103
  };
108
104
  }
109
105
  return {
110
- type: import_contracts.ProductEngineType.PERP,
106
+ type: import_shared.ProductEngineType.PERP,
111
107
  market: mapIndexerServerProduct(event.product),
112
108
  preBalance: mapIndexerServerBalance(
113
109
  event.pre_balance
@@ -126,18 +122,19 @@ function mapIndexerEvent(event) {
126
122
  subaccount: event.subaccount,
127
123
  submissionIndex: event.submission_idx,
128
124
  trackedVars: {
129
- netEntryCumulative: (0, import_utils.toBigDecimal)(event.net_entry_cumulative),
130
- netEntryUnrealized: (0, import_utils.toBigDecimal)(event.net_entry_unrealized),
131
- netFundingCumulative: (0, import_utils.toBigDecimal)(event.net_funding_cumulative),
132
- netFundingUnrealized: (0, import_utils.toBigDecimal)(event.net_funding_unrealized),
133
- netInterestCumulative: (0, import_utils.toBigDecimal)(event.net_interest_cumulative),
134
- netInterestUnrealized: (0, import_utils.toBigDecimal)(event.net_interest_unrealized)
125
+ netEntryCumulative: (0, import_shared.toBigDecimal)(event.net_entry_cumulative),
126
+ netEntryUnrealized: (0, import_shared.toBigDecimal)(event.net_entry_unrealized),
127
+ netFundingCumulative: (0, import_shared.toBigDecimal)(event.net_funding_cumulative),
128
+ netFundingUnrealized: (0, import_shared.toBigDecimal)(event.net_funding_unrealized),
129
+ netInterestCumulative: (0, import_shared.toBigDecimal)(event.net_interest_cumulative),
130
+ netInterestUnrealized: (0, import_shared.toBigDecimal)(event.net_interest_unrealized),
131
+ quoteVolumeCumulative: (0, import_shared.toBigDecimal)(event.quote_volume_cumulative)
135
132
  }
136
133
  };
137
134
  }
138
135
  function mapIndexerEventWithTx(event, tx) {
139
136
  return {
140
- timestamp: (0, import_utils.toBigDecimal)(tx.timestamp),
137
+ timestamp: (0, import_shared.toBigDecimal)(tx.timestamp),
141
138
  tx: tx.tx,
142
139
  ...mapIndexerEvent(event)
143
140
  };
@@ -151,11 +148,11 @@ function mapIndexerMatchEventBalances(eventBalances) {
151
148
  function mapIndexerProductPayment(payment) {
152
149
  return {
153
150
  submissionIndex: payment.idx,
154
- timestamp: (0, import_utils.toBigDecimal)(payment.timestamp),
155
- paymentAmount: (0, import_utils.toBigDecimal)(payment.amount),
156
- balanceAmount: (0, import_utils.toBigDecimal)(payment.balance_amount),
157
- annualPaymentRate: (0, import_utils.removeDecimals)(payment.rate_x18),
158
- oraclePrice: (0, import_utils.removeDecimals)(payment.oracle_price_x18),
151
+ timestamp: (0, import_shared.toBigDecimal)(payment.timestamp),
152
+ paymentAmount: (0, import_shared.toBigDecimal)(payment.amount),
153
+ balanceAmount: (0, import_shared.toBigDecimal)(payment.balance_amount),
154
+ annualPaymentRate: (0, import_shared.removeDecimals)(payment.rate_x18),
155
+ oraclePrice: (0, import_shared.removeDecimals)(payment.oracle_price_x18),
159
156
  isolated: payment.isolated,
160
157
  productId: payment.product_id,
161
158
  isolatedProductId: payment.isolated_product_id
@@ -163,16 +160,16 @@ function mapIndexerProductPayment(payment) {
163
160
  }
164
161
  function mapIndexerPerpPrices(perpPrices) {
165
162
  return {
166
- indexPrice: (0, import_utils.removeDecimals)(perpPrices.index_price_x18),
167
- markPrice: (0, import_utils.removeDecimals)(perpPrices.mark_price_x18),
168
- updateTime: (0, import_utils.toBigDecimal)(perpPrices.update_time),
163
+ indexPrice: (0, import_shared.removeDecimals)(perpPrices.index_price_x18),
164
+ markPrice: (0, import_shared.removeDecimals)(perpPrices.mark_price_x18),
165
+ updateTime: (0, import_shared.toBigDecimal)(perpPrices.update_time),
169
166
  productId: perpPrices.product_id
170
167
  };
171
168
  }
172
169
  function mapIndexerFundingRate(fundingRate) {
173
170
  return {
174
- fundingRate: (0, import_utils.removeDecimals)(fundingRate.funding_rate_x18),
175
- updateTime: (0, import_utils.toBigDecimal)(fundingRate.update_time),
171
+ fundingRate: (0, import_shared.removeDecimals)(fundingRate.funding_rate_x18),
172
+ updateTime: (0, import_shared.toBigDecimal)(fundingRate.update_time),
176
173
  productId: fundingRate.product_id
177
174
  };
178
175
  }
@@ -181,124 +178,136 @@ function mapIndexerMakerStatistics(maker) {
181
178
  address: maker.address,
182
179
  snapshots: maker.data.map((makerData) => {
183
180
  return {
184
- timestamp: (0, import_utils.toBigDecimal)(makerData.timestamp),
185
- makerFee: (0, import_utils.toBigDecimal)(makerData.maker_fee),
186
- uptime: (0, import_utils.toBigDecimal)(makerData.uptime),
187
- sumQMin: (0, import_utils.toBigDecimal)(makerData.sum_q_min),
188
- qScore: (0, import_utils.toBigDecimal)(makerData.q_score),
189
- makerShare: (0, import_utils.toBigDecimal)(makerData.maker_share),
190
- expectedMakerReward: (0, import_utils.toBigDecimal)(makerData.expected_maker_reward)
181
+ timestamp: (0, import_shared.toBigDecimal)(makerData.timestamp),
182
+ makerFee: (0, import_shared.toBigDecimal)(makerData.maker_fee),
183
+ uptime: (0, import_shared.toBigDecimal)(makerData.uptime),
184
+ sumQMin: (0, import_shared.toBigDecimal)(makerData.sum_q_min),
185
+ qScore: (0, import_shared.toBigDecimal)(makerData.q_score),
186
+ makerShare: (0, import_shared.toBigDecimal)(makerData.maker_share),
187
+ expectedMakerReward: (0, import_shared.toBigDecimal)(makerData.expected_maker_reward)
191
188
  };
192
189
  })
193
190
  };
194
191
  }
195
192
  function mapIndexerLeaderboardPosition(position) {
196
193
  return {
197
- subaccount: (0, import_contracts.subaccountFromHex)(position.subaccount),
194
+ subaccount: (0, import_shared.subaccountFromHex)(position.subaccount),
198
195
  contestId: position.contest_id,
199
- pnl: (0, import_utils.toBigDecimal)(position.pnl),
200
- pnlRank: (0, import_utils.toBigDecimal)(position.pnl_rank),
201
- percentRoi: (0, import_utils.toBigDecimal)(position.roi),
202
- roiRank: (0, import_utils.toBigDecimal)(position.roi_rank),
203
- accountValue: (0, import_utils.toBigDecimal)(position.account_value),
204
- volume: position.volume ? (0, import_utils.toBigDecimal)(position.volume) : void 0,
205
- updateTime: (0, import_utils.toBigDecimal)(position.update_time)
196
+ pnl: (0, import_shared.toBigDecimal)(position.pnl),
197
+ pnlRank: (0, import_shared.toBigDecimal)(position.pnl_rank),
198
+ percentRoi: (0, import_shared.toBigDecimal)(position.roi),
199
+ roiRank: (0, import_shared.toBigDecimal)(position.roi_rank),
200
+ accountValue: (0, import_shared.toBigDecimal)(position.account_value),
201
+ volume: position.volume ? (0, import_shared.toBigDecimal)(position.volume) : void 0,
202
+ updateTime: (0, import_shared.toBigDecimal)(position.update_time)
206
203
  };
207
204
  }
208
205
  function mapIndexerLeaderboardRegistration(registration) {
209
206
  return {
210
- subaccount: (0, import_contracts.subaccountFromHex)(registration.subaccount),
207
+ subaccount: (0, import_shared.subaccountFromHex)(registration.subaccount),
211
208
  contestId: registration.contest_id,
212
- updateTime: (0, import_utils.toBigDecimal)(registration.update_time)
209
+ updateTime: (0, import_shared.toBigDecimal)(registration.update_time)
213
210
  };
214
211
  }
215
212
  function mapIndexerLeaderboardContest(contest) {
216
213
  return {
217
214
  contestId: contest.contest_id,
218
- startTime: (0, import_utils.toBigDecimal)(contest.start_time),
219
- endTime: (0, import_utils.toBigDecimal)(contest.end_time),
220
- period: (0, import_utils.toBigDecimal)(contest.threshold),
221
- totalParticipants: (0, import_utils.toBigDecimal)(contest.count),
222
- minRequiredAccountValue: (0, import_utils.toBigDecimal)(contest.threshold),
223
- minRequiredVolume: (0, import_utils.toBigDecimal)(contest.volume_threshold),
215
+ startTime: (0, import_shared.toBigDecimal)(contest.start_time),
216
+ endTime: (0, import_shared.toBigDecimal)(contest.end_time),
217
+ period: (0, import_shared.toBigDecimal)(contest.threshold),
218
+ totalParticipants: (0, import_shared.toBigDecimal)(contest.count),
219
+ minRequiredAccountValue: (0, import_shared.toBigDecimal)(contest.threshold),
220
+ minRequiredVolume: (0, import_shared.toBigDecimal)(contest.volume_threshold),
224
221
  requiredProductIds: contest.product_ids,
225
222
  active: contest.active,
226
- lastUpdated: (0, import_utils.toBigDecimal)(contest.last_updated)
223
+ lastUpdated: (0, import_shared.toBigDecimal)(contest.last_updated)
227
224
  };
228
225
  }
229
226
  function mapIndexerCandlesticks(candlestick) {
230
227
  return {
231
- close: (0, import_utils.removeDecimals)(candlestick.close_x18),
232
- high: (0, import_utils.removeDecimals)(candlestick.high_x18),
233
- low: (0, import_utils.removeDecimals)(candlestick.low_x18),
234
- open: (0, import_utils.removeDecimals)(candlestick.open_x18),
235
- time: (0, import_utils.toBigDecimal)(candlestick.timestamp),
236
- volume: (0, import_utils.toBigDecimal)(candlestick.volume)
228
+ close: (0, import_shared.removeDecimals)(candlestick.close_x18),
229
+ high: (0, import_shared.removeDecimals)(candlestick.high_x18),
230
+ low: (0, import_shared.removeDecimals)(candlestick.low_x18),
231
+ open: (0, import_shared.removeDecimals)(candlestick.open_x18),
232
+ time: (0, import_shared.toBigDecimal)(candlestick.timestamp),
233
+ volume: (0, import_shared.toBigDecimal)(candlestick.volume)
237
234
  };
238
235
  }
239
236
  function mapIndexerMarketSnapshot(snapshot) {
240
237
  return {
241
- timestamp: (0, import_utils.toBigDecimal)(snapshot.timestamp),
242
- cumulativeUsers: (0, import_utils.toBigDecimal)(snapshot.cumulative_users),
243
- dailyActiveUsers: (0, import_utils.toBigDecimal)(snapshot.daily_active_users),
244
- tvl: (0, import_utils.toBigDecimal)(snapshot.tvl),
245
- borrowRates: (0, import_utils.mapValues)(
238
+ timestamp: (0, import_shared.toBigDecimal)(snapshot.timestamp),
239
+ cumulativeUsers: (0, import_shared.toBigDecimal)(snapshot.cumulative_users),
240
+ dailyActiveUsers: (0, import_shared.toBigDecimal)(snapshot.daily_active_users),
241
+ tvl: (0, import_shared.toBigDecimal)(snapshot.tvl),
242
+ borrowRates: (0, import_shared.mapValues)(
246
243
  snapshot.borrow_rates,
247
- (value) => (0, import_utils.removeDecimals)(value)
244
+ (value) => (0, import_shared.removeDecimals)(value)
248
245
  ),
249
- cumulativeLiquidationAmounts: (0, import_utils.mapValues)(
246
+ cumulativeLiquidationAmounts: (0, import_shared.mapValues)(
250
247
  snapshot.cumulative_liquidation_amounts,
251
- import_utils.toBigDecimal
248
+ import_shared.toBigDecimal
252
249
  ),
253
- cumulativeMakerFees: (0, import_utils.mapValues)(
250
+ cumulativeMakerFees: (0, import_shared.mapValues)(
254
251
  snapshot.cumulative_maker_fees,
255
- import_utils.toBigDecimal
252
+ import_shared.toBigDecimal
256
253
  ),
257
- cumulativeSequencerFees: (0, import_utils.mapValues)(
254
+ cumulativeSequencerFees: (0, import_shared.mapValues)(
258
255
  snapshot.cumulative_sequencer_fees,
259
- import_utils.toBigDecimal
256
+ import_shared.toBigDecimal
260
257
  ),
261
- cumulativeTakerFees: (0, import_utils.mapValues)(
258
+ cumulativeTakerFees: (0, import_shared.mapValues)(
262
259
  snapshot.cumulative_taker_fees,
263
- import_utils.toBigDecimal
260
+ import_shared.toBigDecimal
264
261
  ),
265
- cumulativeTrades: (0, import_utils.mapValues)(snapshot.cumulative_trades, import_utils.toBigDecimal),
266
- cumulativeVolumes: (0, import_utils.mapValues)(snapshot.cumulative_volumes, import_utils.toBigDecimal),
267
- depositRates: (0, import_utils.mapValues)(
262
+ cumulativeTrades: (0, import_shared.mapValues)(snapshot.cumulative_trades, import_shared.toBigDecimal),
263
+ cumulativeVolumes: (0, import_shared.mapValues)(snapshot.cumulative_volumes, import_shared.toBigDecimal),
264
+ depositRates: (0, import_shared.mapValues)(
268
265
  snapshot.deposit_rates,
269
- (value) => (0, import_utils.removeDecimals)(value)
266
+ (value) => (0, import_shared.removeDecimals)(value)
270
267
  ),
271
- fundingRates: (0, import_utils.mapValues)(
268
+ fundingRates: (0, import_shared.mapValues)(
272
269
  snapshot.funding_rates,
273
- (value) => (0, import_utils.removeDecimals)(value)
270
+ (value) => (0, import_shared.removeDecimals)(value)
274
271
  ),
275
- openInterestsQuote: (0, import_utils.mapValues)(snapshot.open_interests, import_utils.toBigDecimal),
276
- totalBorrows: (0, import_utils.mapValues)(snapshot.total_borrows, import_utils.toBigDecimal),
277
- totalDeposits: (0, import_utils.mapValues)(snapshot.total_deposits, import_utils.toBigDecimal),
278
- cumulativeTradeSizes: (0, import_utils.mapValues)(
272
+ openInterestsQuote: (0, import_shared.mapValues)(snapshot.open_interests, import_shared.toBigDecimal),
273
+ totalBorrows: (0, import_shared.mapValues)(snapshot.total_borrows, import_shared.toBigDecimal),
274
+ totalDeposits: (0, import_shared.mapValues)(snapshot.total_deposits, import_shared.toBigDecimal),
275
+ cumulativeTradeSizes: (0, import_shared.mapValues)(
279
276
  snapshot.cumulative_trade_sizes,
280
- import_utils.toBigDecimal
277
+ import_shared.toBigDecimal
281
278
  ),
282
- cumulativeInflows: (0, import_utils.mapValues)(snapshot.cumulative_inflows, import_utils.toBigDecimal),
283
- cumulativeOutflows: (0, import_utils.mapValues)(snapshot.cumulative_outflows, import_utils.toBigDecimal),
284
- oraclePrices: (0, import_utils.mapValues)(
279
+ cumulativeInflows: (0, import_shared.mapValues)(snapshot.cumulative_inflows, import_shared.toBigDecimal),
280
+ cumulativeOutflows: (0, import_shared.mapValues)(snapshot.cumulative_outflows, import_shared.toBigDecimal),
281
+ oraclePrices: (0, import_shared.mapValues)(
285
282
  snapshot.oracle_prices,
286
- (value) => (0, import_utils.removeDecimals)(value)
283
+ (value) => (0, import_shared.removeDecimals)(value)
287
284
  )
288
285
  };
289
286
  }
290
287
  function mapIndexerNlpSnapshot(snapshot) {
291
288
  return {
292
289
  submissionIndex: snapshot.submission_idx,
293
- timestamp: (0, import_utils.toBigDecimal)(snapshot.timestamp),
294
- cumulativeBurnAmountUsdc: (0, import_utils.toBigDecimal)(snapshot.cumulative_burn_usdc),
295
- cumulativeMintAmountUsdc: (0, import_utils.toBigDecimal)(snapshot.cumulative_mint_usdc),
296
- cumulativePnl: (0, import_utils.toBigDecimal)(snapshot.cumulative_pnl),
297
- cumulativeTrades: (0, import_utils.toBigDecimal)(snapshot.cumulative_trades),
298
- cumulativeVolume: (0, import_utils.toBigDecimal)(snapshot.cumulative_volume),
299
- depositors: (0, import_utils.toBigDecimal)(snapshot.depositors),
300
- oraclePrice: (0, import_utils.removeDecimals)(snapshot.oracle_price_x18),
301
- tvl: (0, import_utils.toBigDecimal)(snapshot.tvl)
290
+ timestamp: (0, import_shared.toBigDecimal)(snapshot.timestamp),
291
+ cumulativeBurnAmountQuote: (0, import_shared.toBigDecimal)(snapshot.cumulative_burn_quote),
292
+ cumulativeMintAmountQuote: (0, import_shared.toBigDecimal)(snapshot.cumulative_mint_quote),
293
+ cumulativePnl: (0, import_shared.toBigDecimal)(snapshot.cumulative_pnl),
294
+ cumulativeTrades: (0, import_shared.toBigDecimal)(snapshot.cumulative_trades),
295
+ cumulativeVolume: (0, import_shared.toBigDecimal)(snapshot.cumulative_volume),
296
+ depositors: (0, import_shared.toBigDecimal)(snapshot.depositors),
297
+ oraclePrice: (0, import_shared.removeDecimals)(snapshot.oracle_price_x18),
298
+ tvl: (0, import_shared.toBigDecimal)(snapshot.tvl)
299
+ };
300
+ }
301
+ function mapIndexerV2Ticker(ticker) {
302
+ return {
303
+ productId: ticker.product_id,
304
+ tickerId: ticker.ticker_id,
305
+ baseCurrency: ticker.base_currency,
306
+ quoteCurrency: ticker.quote_currency,
307
+ lastPrice: ticker.last_price,
308
+ baseVolume: ticker.base_volume,
309
+ quoteVolume: ticker.quote_volume,
310
+ priceChangePercent24h: ticker.price_change_percent_24h
302
311
  };
303
312
  }
304
313
  // Annotate the CommonJS export names for ESM import in node:
@@ -319,6 +328,7 @@ function mapIndexerNlpSnapshot(snapshot) {
319
328
  mapIndexerProductPayment,
320
329
  mapIndexerServerBalance,
321
330
  mapIndexerServerProduct,
331
+ mapIndexerV2Ticker,
322
332
  mapSnapshotsIntervalToServerParams
323
333
  });
324
334
  //# sourceMappingURL=dataMappers.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/dataMappers.ts"],"sourcesContent":["import {\n getRecvTimeFromOrderNonce,\n Market,\n parseRawExpirationTimestamp,\n PerpMarket,\n ProductEngineType,\n SpotMarket,\n subaccountFromHex,\n} from '@nadohq/contracts';\nimport {\n mapEngineServerPerpProduct,\n mapEngineServerSpotProduct,\n} from '@nadohq/engine-client';\nimport {\n mapValues,\n removeDecimals,\n toBigDecimal,\n toIntegerString,\n} from '@nadohq/utils';\nimport {\n Candlestick,\n IndexerEvent,\n IndexerEventWithTx,\n IndexerFundingRate,\n IndexerLeaderboardContest,\n IndexerLeaderboardParticipant,\n IndexerLeaderboardRegistration,\n IndexerMaker,\n IndexerMarketSnapshot,\n IndexerMatchEventBalances,\n IndexerOrder,\n IndexerPerpBalance,\n IndexerPerpPrices,\n IndexerProductPayment,\n IndexerServerBalance,\n IndexerServerCandlestick,\n IndexerServerEvent,\n IndexerServerFundingRate,\n IndexerServerLeaderboardContest,\n IndexerServerLeaderboardPosition,\n IndexerServerLeaderboardRegistration,\n IndexerServerMaker,\n IndexerServerMarketSnapshot,\n IndexerServerMatchEventBalances,\n IndexerServerOrder,\n IndexerServerPerpPrices,\n IndexerServerProduct,\n IndexerServerProductPayment,\n IndexerServerSnapshotsInterval,\n IndexerServerTx,\n IndexerServerNlpSnapshot,\n IndexerSnapshotsIntervalParams,\n IndexerSpotBalance,\n IndexerNlpSnapshot,\n} from './types';\n\nexport function mapSnapshotsIntervalToServerParams(\n params: IndexerSnapshotsIntervalParams,\n): IndexerServerSnapshotsInterval {\n return {\n count: params.limit,\n max_time: params.maxTimeInclusive\n ? toIntegerString(params.maxTimeInclusive)\n : undefined,\n granularity: params.granularity,\n };\n}\n\nexport function mapIndexerServerProduct(product: IndexerServerProduct): Market {\n if ('spot' in product) {\n return mapEngineServerSpotProduct(product.spot);\n }\n return mapEngineServerPerpProduct(product.perp);\n}\n\nexport function mapIndexerServerBalance(\n balance: IndexerServerBalance,\n): IndexerSpotBalance | IndexerPerpBalance {\n if ('spot' in balance) {\n return {\n amount: toBigDecimal(balance.spot.balance.amount),\n productId: balance.spot.product_id,\n type: ProductEngineType.SPOT,\n };\n }\n return {\n amount: toBigDecimal(balance.perp.balance.amount),\n productId: balance.perp.product_id,\n type: ProductEngineType.PERP,\n vQuoteBalance: toBigDecimal(balance.perp.balance.v_quote_balance),\n };\n}\n\nexport function mapIndexerOrder(order: IndexerServerOrder): IndexerOrder {\n const expiration = toBigDecimal(order.expiration);\n const expirationEncodedData = parseRawExpirationTimestamp(order.expiration);\n return {\n amount: toBigDecimal(order.amount),\n digest: order.digest,\n isolated: order.isolated,\n rawExpiration: expiration,\n isReduceOnly: expirationEncodedData.reduceOnly,\n expiration: expirationEncodedData.expirationTime,\n orderType: expirationEncodedData.type,\n nonce: toBigDecimal(order.nonce),\n recvTimeSeconds: getRecvTimeFromOrderNonce(order.nonce) / 1000,\n price: removeDecimals(order.price_x18),\n productId: order.product_id,\n subaccount: order.subaccount,\n submissionIndex: order.submission_idx,\n baseFilled: toBigDecimal(order.base_filled),\n quoteFilled: toBigDecimal(order.quote_filled),\n totalFee: toBigDecimal(order.fee),\n };\n}\n\nexport function mapIndexerEvent(event: IndexerServerEvent): IndexerEvent {\n const eventState: IndexerEvent['state'] = (() => {\n // Assume backend data is consistent\n if ('spot' in event.pre_balance) {\n return {\n type: ProductEngineType.SPOT,\n market: mapIndexerServerProduct(event.product) as SpotMarket,\n preBalance: mapIndexerServerBalance(\n event.pre_balance,\n ) as IndexerSpotBalance,\n postBalance: mapIndexerServerBalance(\n event.post_balance,\n ) as IndexerSpotBalance,\n };\n }\n return {\n type: ProductEngineType.PERP,\n market: mapIndexerServerProduct(event.product) as PerpMarket,\n preBalance: mapIndexerServerBalance(\n event.pre_balance,\n ) as IndexerPerpBalance,\n postBalance: mapIndexerServerBalance(\n event.post_balance,\n ) as IndexerPerpBalance,\n };\n })();\n\n return {\n eventType: event.event_type,\n productId: event.product_id,\n isolated: event.isolated,\n isolatedProductId: event.isolated_product_id,\n state: eventState,\n subaccount: event.subaccount,\n submissionIndex: event.submission_idx,\n trackedVars: {\n netEntryCumulative: toBigDecimal(event.net_entry_cumulative),\n netEntryUnrealized: toBigDecimal(event.net_entry_unrealized),\n netFundingCumulative: toBigDecimal(event.net_funding_cumulative),\n netFundingUnrealized: toBigDecimal(event.net_funding_unrealized),\n netInterestCumulative: toBigDecimal(event.net_interest_cumulative),\n netInterestUnrealized: toBigDecimal(event.net_interest_unrealized),\n },\n };\n}\n\nexport function mapIndexerEventWithTx(\n event: IndexerServerEvent,\n tx: IndexerServerTx,\n): IndexerEventWithTx {\n return {\n timestamp: toBigDecimal(tx.timestamp),\n tx: tx.tx,\n ...mapIndexerEvent(event),\n };\n}\n\nexport function mapIndexerMatchEventBalances(\n eventBalances: IndexerServerMatchEventBalances,\n): IndexerMatchEventBalances {\n return {\n base: mapIndexerServerBalance(eventBalances.base),\n quote: eventBalances.quote\n ? (mapIndexerServerBalance(eventBalances.quote) as IndexerSpotBalance)\n : undefined,\n };\n}\n\nexport function mapIndexerProductPayment(\n payment: IndexerServerProductPayment,\n): IndexerProductPayment {\n return {\n submissionIndex: payment.idx,\n timestamp: toBigDecimal(payment.timestamp),\n paymentAmount: toBigDecimal(payment.amount),\n balanceAmount: toBigDecimal(payment.balance_amount),\n annualPaymentRate: removeDecimals(payment.rate_x18),\n oraclePrice: removeDecimals(payment.oracle_price_x18),\n isolated: payment.isolated,\n productId: payment.product_id,\n isolatedProductId: payment.isolated_product_id,\n };\n}\n\nexport function mapIndexerPerpPrices(\n perpPrices: IndexerServerPerpPrices,\n): IndexerPerpPrices {\n return {\n indexPrice: removeDecimals(perpPrices.index_price_x18),\n markPrice: removeDecimals(perpPrices.mark_price_x18),\n updateTime: toBigDecimal(perpPrices.update_time),\n productId: perpPrices.product_id,\n };\n}\n\nexport function mapIndexerFundingRate(\n fundingRate: IndexerServerFundingRate,\n): IndexerFundingRate {\n return {\n fundingRate: removeDecimals(fundingRate.funding_rate_x18),\n updateTime: toBigDecimal(fundingRate.update_time),\n productId: fundingRate.product_id,\n };\n}\n\nexport function mapIndexerMakerStatistics(\n maker: IndexerServerMaker,\n): IndexerMaker {\n return {\n address: maker.address,\n snapshots: maker.data.map((makerData) => {\n return {\n timestamp: toBigDecimal(makerData.timestamp),\n makerFee: toBigDecimal(makerData.maker_fee),\n uptime: toBigDecimal(makerData.uptime),\n sumQMin: toBigDecimal(makerData.sum_q_min),\n qScore: toBigDecimal(makerData.q_score),\n makerShare: toBigDecimal(makerData.maker_share),\n expectedMakerReward: toBigDecimal(makerData.expected_maker_reward),\n };\n }),\n };\n}\n\nexport function mapIndexerLeaderboardPosition(\n position: IndexerServerLeaderboardPosition,\n): IndexerLeaderboardParticipant {\n return {\n subaccount: subaccountFromHex(position.subaccount),\n contestId: position.contest_id,\n pnl: toBigDecimal(position.pnl),\n pnlRank: toBigDecimal(position.pnl_rank),\n percentRoi: toBigDecimal(position.roi),\n roiRank: toBigDecimal(position.roi_rank),\n accountValue: toBigDecimal(position.account_value),\n volume: position.volume ? toBigDecimal(position.volume) : undefined,\n updateTime: toBigDecimal(position.update_time),\n };\n}\n\nexport function mapIndexerLeaderboardRegistration(\n registration: IndexerServerLeaderboardRegistration,\n): IndexerLeaderboardRegistration {\n return {\n subaccount: subaccountFromHex(registration.subaccount),\n contestId: registration.contest_id,\n updateTime: toBigDecimal(registration.update_time),\n };\n}\n\nexport function mapIndexerLeaderboardContest(\n contest: IndexerServerLeaderboardContest,\n): IndexerLeaderboardContest {\n return {\n contestId: contest.contest_id,\n startTime: toBigDecimal(contest.start_time),\n endTime: toBigDecimal(contest.end_time),\n period: toBigDecimal(contest.threshold),\n totalParticipants: toBigDecimal(contest.count),\n minRequiredAccountValue: toBigDecimal(contest.threshold),\n minRequiredVolume: toBigDecimal(contest.volume_threshold),\n requiredProductIds: contest.product_ids,\n active: contest.active,\n lastUpdated: toBigDecimal(contest.last_updated),\n };\n}\n\nexport function mapIndexerCandlesticks(\n candlestick: IndexerServerCandlestick,\n): Candlestick {\n return {\n close: removeDecimals(candlestick.close_x18),\n high: removeDecimals(candlestick.high_x18),\n low: removeDecimals(candlestick.low_x18),\n open: removeDecimals(candlestick.open_x18),\n time: toBigDecimal(candlestick.timestamp),\n volume: toBigDecimal(candlestick.volume),\n };\n}\n\nexport function mapIndexerMarketSnapshot(\n snapshot: IndexerServerMarketSnapshot,\n): IndexerMarketSnapshot {\n return {\n timestamp: toBigDecimal(snapshot.timestamp),\n cumulativeUsers: toBigDecimal(snapshot.cumulative_users),\n dailyActiveUsers: toBigDecimal(snapshot.daily_active_users),\n tvl: toBigDecimal(snapshot.tvl),\n borrowRates: mapValues(snapshot.borrow_rates, (value) =>\n removeDecimals(value),\n ),\n cumulativeLiquidationAmounts: mapValues(\n snapshot.cumulative_liquidation_amounts,\n toBigDecimal,\n ),\n cumulativeMakerFees: mapValues(\n snapshot.cumulative_maker_fees,\n toBigDecimal,\n ),\n cumulativeSequencerFees: mapValues(\n snapshot.cumulative_sequencer_fees,\n toBigDecimal,\n ),\n cumulativeTakerFees: mapValues(\n snapshot.cumulative_taker_fees,\n toBigDecimal,\n ),\n cumulativeTrades: mapValues(snapshot.cumulative_trades, toBigDecimal),\n cumulativeVolumes: mapValues(snapshot.cumulative_volumes, toBigDecimal),\n depositRates: mapValues(snapshot.deposit_rates, (value) =>\n removeDecimals(value),\n ),\n fundingRates: mapValues(snapshot.funding_rates, (value) =>\n removeDecimals(value),\n ),\n openInterestsQuote: mapValues(snapshot.open_interests, toBigDecimal),\n totalBorrows: mapValues(snapshot.total_borrows, toBigDecimal),\n totalDeposits: mapValues(snapshot.total_deposits, toBigDecimal),\n cumulativeTradeSizes: mapValues(\n snapshot.cumulative_trade_sizes,\n toBigDecimal,\n ),\n cumulativeInflows: mapValues(snapshot.cumulative_inflows, toBigDecimal),\n cumulativeOutflows: mapValues(snapshot.cumulative_outflows, toBigDecimal),\n oraclePrices: mapValues(snapshot.oracle_prices, (value) =>\n removeDecimals(value),\n ),\n };\n}\n\nexport function mapIndexerNlpSnapshot(\n snapshot: IndexerServerNlpSnapshot,\n): IndexerNlpSnapshot {\n return {\n submissionIndex: snapshot.submission_idx,\n timestamp: toBigDecimal(snapshot.timestamp),\n cumulativeBurnAmountUsdc: toBigDecimal(snapshot.cumulative_burn_usdc),\n cumulativeMintAmountUsdc: toBigDecimal(snapshot.cumulative_mint_usdc),\n cumulativePnl: toBigDecimal(snapshot.cumulative_pnl),\n cumulativeTrades: toBigDecimal(snapshot.cumulative_trades),\n cumulativeVolume: toBigDecimal(snapshot.cumulative_volume),\n depositors: toBigDecimal(snapshot.depositors),\n oraclePrice: removeDecimals(snapshot.oracle_price_x18),\n tvl: toBigDecimal(snapshot.tvl),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA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;AAAA,MAAU,SAAS;AAAA,MAAe,CAAC,cAC/C,6BAAe,KAAK;AAAA,IACtB;AAAA,EACF;AACF;AAEO,SAAS,sBACd,UACoB;AACpB,SAAO;AAAA,IACL,iBAAiB,SAAS;AAAA,IAC1B,eAAW,2BAAa,SAAS,SAAS;AAAA,IAC1C,8BAA0B,2BAAa,SAAS,oBAAoB;AAAA,IACpE,8BAA0B,2BAAa,SAAS,oBAAoB;AAAA,IACpE,mBAAe,2BAAa,SAAS,cAAc;AAAA,IACnD,sBAAkB,2BAAa,SAAS,iBAAiB;AAAA,IACzD,sBAAkB,2BAAa,SAAS,iBAAiB;AAAA,IACzD,gBAAY,2BAAa,SAAS,UAAU;AAAA,IAC5C,iBAAa,6BAAe,SAAS,gBAAgB;AAAA,IACrD,SAAK,2BAAa,SAAS,GAAG;AAAA,EAChC;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/dataMappers.ts"],"sourcesContent":["import {\n mapEngineServerPerpProduct,\n mapEngineServerSpotProduct,\n} from '@nadohq/engine-client';\nimport {\n getRecvTimeFromOrderNonce,\n mapValues,\n Market,\n PerpMarket,\n ProductEngineType,\n removeDecimals,\n SpotMarket,\n subaccountFromHex,\n toBigDecimal,\n toIntegerString,\n unpackOrderAppendix,\n} from '@nadohq/shared';\nimport {\n Candlestick,\n IndexerEvent,\n IndexerEventWithTx,\n IndexerFundingRate,\n IndexerLeaderboardContest,\n IndexerLeaderboardParticipant,\n IndexerLeaderboardRegistration,\n IndexerMaker,\n IndexerMarketSnapshot,\n IndexerMatchEventBalances,\n IndexerNlpSnapshot,\n IndexerOrder,\n IndexerPerpBalance,\n IndexerPerpPrices,\n IndexerProductPayment,\n IndexerServerBalance,\n IndexerServerCandlestick,\n IndexerServerEvent,\n IndexerServerFundingRate,\n IndexerServerLeaderboardContest,\n IndexerServerLeaderboardPosition,\n IndexerServerLeaderboardRegistration,\n IndexerServerMaker,\n IndexerServerMarketSnapshot,\n IndexerServerMatchEventBalances,\n IndexerServerNlpSnapshot,\n IndexerServerOrder,\n IndexerServerPerpPrices,\n IndexerServerProduct,\n IndexerServerProductPayment,\n IndexerServerSnapshotsInterval,\n IndexerServerTx,\n IndexerServerV2TickerResponse,\n IndexerSnapshotsIntervalParams,\n IndexerSpotBalance,\n IndexerV2TickerResponse,\n} from './types';\n\nexport function mapSnapshotsIntervalToServerParams(\n params: IndexerSnapshotsIntervalParams,\n): IndexerServerSnapshotsInterval {\n return {\n count: params.limit,\n max_time: params.maxTimeInclusive\n ? toIntegerString(params.maxTimeInclusive)\n : undefined,\n granularity: params.granularity,\n };\n}\n\nexport function mapIndexerServerProduct(product: IndexerServerProduct): Market {\n if ('spot' in product) {\n return mapEngineServerSpotProduct(product.spot);\n }\n return mapEngineServerPerpProduct(product.perp);\n}\n\nexport function mapIndexerServerBalance(\n balance: IndexerServerBalance,\n): IndexerSpotBalance | IndexerPerpBalance {\n if ('spot' in balance) {\n return {\n amount: toBigDecimal(balance.spot.balance.amount),\n productId: balance.spot.product_id,\n type: ProductEngineType.SPOT,\n };\n }\n return {\n amount: toBigDecimal(balance.perp.balance.amount),\n productId: balance.perp.product_id,\n type: ProductEngineType.PERP,\n vQuoteBalance: toBigDecimal(balance.perp.balance.v_quote_balance),\n };\n}\n\nexport function mapIndexerOrder(order: IndexerServerOrder): IndexerOrder {\n const appendix = unpackOrderAppendix(order.appendix);\n return {\n amount: toBigDecimal(order.amount),\n digest: order.digest,\n expiration: Number(order.expiration),\n appendix,\n nonce: toBigDecimal(order.nonce),\n recvTimeSeconds: getRecvTimeFromOrderNonce(order.nonce) / 1000,\n price: removeDecimals(order.price_x18),\n productId: order.product_id,\n subaccount: order.subaccount,\n submissionIndex: order.submission_idx,\n baseFilled: toBigDecimal(order.base_filled),\n quoteFilled: toBigDecimal(order.quote_filled),\n totalFee: toBigDecimal(order.fee),\n };\n}\n\nexport function mapIndexerEvent(event: IndexerServerEvent): IndexerEvent {\n const eventState: IndexerEvent['state'] = (() => {\n // Assume backend data is consistent\n if ('spot' in event.pre_balance) {\n return {\n type: ProductEngineType.SPOT,\n market: mapIndexerServerProduct(event.product) as SpotMarket,\n preBalance: mapIndexerServerBalance(\n event.pre_balance,\n ) as IndexerSpotBalance,\n postBalance: mapIndexerServerBalance(\n event.post_balance,\n ) as IndexerSpotBalance,\n };\n }\n return {\n type: ProductEngineType.PERP,\n market: mapIndexerServerProduct(event.product) as PerpMarket,\n preBalance: mapIndexerServerBalance(\n event.pre_balance,\n ) as IndexerPerpBalance,\n postBalance: mapIndexerServerBalance(\n event.post_balance,\n ) as IndexerPerpBalance,\n };\n })();\n\n return {\n eventType: event.event_type,\n productId: event.product_id,\n isolated: event.isolated,\n isolatedProductId: event.isolated_product_id,\n state: eventState,\n subaccount: event.subaccount,\n submissionIndex: event.submission_idx,\n trackedVars: {\n netEntryCumulative: toBigDecimal(event.net_entry_cumulative),\n netEntryUnrealized: toBigDecimal(event.net_entry_unrealized),\n netFundingCumulative: toBigDecimal(event.net_funding_cumulative),\n netFundingUnrealized: toBigDecimal(event.net_funding_unrealized),\n netInterestCumulative: toBigDecimal(event.net_interest_cumulative),\n netInterestUnrealized: toBigDecimal(event.net_interest_unrealized),\n quoteVolumeCumulative: toBigDecimal(event.quote_volume_cumulative),\n },\n };\n}\n\nexport function mapIndexerEventWithTx(\n event: IndexerServerEvent,\n tx: IndexerServerTx,\n): IndexerEventWithTx {\n return {\n timestamp: toBigDecimal(tx.timestamp),\n tx: tx.tx,\n ...mapIndexerEvent(event),\n };\n}\n\nexport function mapIndexerMatchEventBalances(\n eventBalances: IndexerServerMatchEventBalances,\n): IndexerMatchEventBalances {\n return {\n base: mapIndexerServerBalance(eventBalances.base),\n quote: eventBalances.quote\n ? (mapIndexerServerBalance(eventBalances.quote) as IndexerSpotBalance)\n : undefined,\n };\n}\n\nexport function mapIndexerProductPayment(\n payment: IndexerServerProductPayment,\n): IndexerProductPayment {\n return {\n submissionIndex: payment.idx,\n timestamp: toBigDecimal(payment.timestamp),\n paymentAmount: toBigDecimal(payment.amount),\n balanceAmount: toBigDecimal(payment.balance_amount),\n annualPaymentRate: removeDecimals(payment.rate_x18),\n oraclePrice: removeDecimals(payment.oracle_price_x18),\n isolated: payment.isolated,\n productId: payment.product_id,\n isolatedProductId: payment.isolated_product_id,\n };\n}\n\nexport function mapIndexerPerpPrices(\n perpPrices: IndexerServerPerpPrices,\n): IndexerPerpPrices {\n return {\n indexPrice: removeDecimals(perpPrices.index_price_x18),\n markPrice: removeDecimals(perpPrices.mark_price_x18),\n updateTime: toBigDecimal(perpPrices.update_time),\n productId: perpPrices.product_id,\n };\n}\n\nexport function mapIndexerFundingRate(\n fundingRate: IndexerServerFundingRate,\n): IndexerFundingRate {\n return {\n fundingRate: removeDecimals(fundingRate.funding_rate_x18),\n updateTime: toBigDecimal(fundingRate.update_time),\n productId: fundingRate.product_id,\n };\n}\n\nexport function mapIndexerMakerStatistics(\n maker: IndexerServerMaker,\n): IndexerMaker {\n return {\n address: maker.address,\n snapshots: maker.data.map((makerData) => {\n return {\n timestamp: toBigDecimal(makerData.timestamp),\n makerFee: toBigDecimal(makerData.maker_fee),\n uptime: toBigDecimal(makerData.uptime),\n sumQMin: toBigDecimal(makerData.sum_q_min),\n qScore: toBigDecimal(makerData.q_score),\n makerShare: toBigDecimal(makerData.maker_share),\n expectedMakerReward: toBigDecimal(makerData.expected_maker_reward),\n };\n }),\n };\n}\n\nexport function mapIndexerLeaderboardPosition(\n position: IndexerServerLeaderboardPosition,\n): IndexerLeaderboardParticipant {\n return {\n subaccount: subaccountFromHex(position.subaccount),\n contestId: position.contest_id,\n pnl: toBigDecimal(position.pnl),\n pnlRank: toBigDecimal(position.pnl_rank),\n percentRoi: toBigDecimal(position.roi),\n roiRank: toBigDecimal(position.roi_rank),\n accountValue: toBigDecimal(position.account_value),\n volume: position.volume ? toBigDecimal(position.volume) : undefined,\n updateTime: toBigDecimal(position.update_time),\n };\n}\n\nexport function mapIndexerLeaderboardRegistration(\n registration: IndexerServerLeaderboardRegistration,\n): IndexerLeaderboardRegistration {\n return {\n subaccount: subaccountFromHex(registration.subaccount),\n contestId: registration.contest_id,\n updateTime: toBigDecimal(registration.update_time),\n };\n}\n\nexport function mapIndexerLeaderboardContest(\n contest: IndexerServerLeaderboardContest,\n): IndexerLeaderboardContest {\n return {\n contestId: contest.contest_id,\n startTime: toBigDecimal(contest.start_time),\n endTime: toBigDecimal(contest.end_time),\n period: toBigDecimal(contest.threshold),\n totalParticipants: toBigDecimal(contest.count),\n minRequiredAccountValue: toBigDecimal(contest.threshold),\n minRequiredVolume: toBigDecimal(contest.volume_threshold),\n requiredProductIds: contest.product_ids,\n active: contest.active,\n lastUpdated: toBigDecimal(contest.last_updated),\n };\n}\n\nexport function mapIndexerCandlesticks(\n candlestick: IndexerServerCandlestick,\n): Candlestick {\n return {\n close: removeDecimals(candlestick.close_x18),\n high: removeDecimals(candlestick.high_x18),\n low: removeDecimals(candlestick.low_x18),\n open: removeDecimals(candlestick.open_x18),\n time: toBigDecimal(candlestick.timestamp),\n volume: toBigDecimal(candlestick.volume),\n };\n}\n\nexport function mapIndexerMarketSnapshot(\n snapshot: IndexerServerMarketSnapshot,\n): IndexerMarketSnapshot {\n return {\n timestamp: toBigDecimal(snapshot.timestamp),\n cumulativeUsers: toBigDecimal(snapshot.cumulative_users),\n dailyActiveUsers: toBigDecimal(snapshot.daily_active_users),\n tvl: toBigDecimal(snapshot.tvl),\n borrowRates: mapValues(snapshot.borrow_rates, (value) =>\n removeDecimals(value),\n ),\n cumulativeLiquidationAmounts: mapValues(\n snapshot.cumulative_liquidation_amounts,\n toBigDecimal,\n ),\n cumulativeMakerFees: mapValues(\n snapshot.cumulative_maker_fees,\n toBigDecimal,\n ),\n cumulativeSequencerFees: mapValues(\n snapshot.cumulative_sequencer_fees,\n toBigDecimal,\n ),\n cumulativeTakerFees: mapValues(\n snapshot.cumulative_taker_fees,\n toBigDecimal,\n ),\n cumulativeTrades: mapValues(snapshot.cumulative_trades, toBigDecimal),\n cumulativeVolumes: mapValues(snapshot.cumulative_volumes, toBigDecimal),\n depositRates: mapValues(snapshot.deposit_rates, (value) =>\n removeDecimals(value),\n ),\n fundingRates: mapValues(snapshot.funding_rates, (value) =>\n removeDecimals(value),\n ),\n openInterestsQuote: mapValues(snapshot.open_interests, toBigDecimal),\n totalBorrows: mapValues(snapshot.total_borrows, toBigDecimal),\n totalDeposits: mapValues(snapshot.total_deposits, toBigDecimal),\n cumulativeTradeSizes: mapValues(\n snapshot.cumulative_trade_sizes,\n toBigDecimal,\n ),\n cumulativeInflows: mapValues(snapshot.cumulative_inflows, toBigDecimal),\n cumulativeOutflows: mapValues(snapshot.cumulative_outflows, toBigDecimal),\n oraclePrices: mapValues(snapshot.oracle_prices, (value) =>\n removeDecimals(value),\n ),\n };\n}\n\nexport function mapIndexerNlpSnapshot(\n snapshot: IndexerServerNlpSnapshot,\n): IndexerNlpSnapshot {\n return {\n submissionIndex: snapshot.submission_idx,\n timestamp: toBigDecimal(snapshot.timestamp),\n cumulativeBurnAmountQuote: toBigDecimal(snapshot.cumulative_burn_quote),\n cumulativeMintAmountQuote: toBigDecimal(snapshot.cumulative_mint_quote),\n cumulativePnl: toBigDecimal(snapshot.cumulative_pnl),\n cumulativeTrades: toBigDecimal(snapshot.cumulative_trades),\n cumulativeVolume: toBigDecimal(snapshot.cumulative_volume),\n depositors: toBigDecimal(snapshot.depositors),\n oraclePrice: removeDecimals(snapshot.oracle_price_x18),\n tvl: toBigDecimal(snapshot.tvl),\n };\n}\n\nexport function mapIndexerV2Ticker(\n ticker: IndexerServerV2TickerResponse,\n): IndexerV2TickerResponse {\n return {\n productId: ticker.product_id,\n tickerId: ticker.ticker_id,\n baseCurrency: ticker.base_currency,\n quoteCurrency: ticker.quote_currency,\n lastPrice: ticker.last_price,\n baseVolume: ticker.base_volume,\n quoteVolume: ticker.quote_volume,\n priceChangePercent24h: ticker.price_change_percent_24h,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA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AAA,MAAe,CAAC,cAC/C,8BAAe,KAAK;AAAA,IACtB;AAAA,EACF;AACF;AAEO,SAAS,sBACd,UACoB;AACpB,SAAO;AAAA,IACL,iBAAiB,SAAS;AAAA,IAC1B,eAAW,4BAAa,SAAS,SAAS;AAAA,IAC1C,+BAA2B,4BAAa,SAAS,qBAAqB;AAAA,IACtE,+BAA2B,4BAAa,SAAS,qBAAqB;AAAA,IACtE,mBAAe,4BAAa,SAAS,cAAc;AAAA,IACnD,sBAAkB,4BAAa,SAAS,iBAAiB;AAAA,IACzD,sBAAkB,4BAAa,SAAS,iBAAiB;AAAA,IACzD,gBAAY,4BAAa,SAAS,UAAU;AAAA,IAC5C,iBAAa,8BAAe,SAAS,gBAAgB;AAAA,IACrD,SAAK,4BAAa,SAAS,GAAG;AAAA,EAChC;AACF;AAEO,SAAS,mBACd,QACyB;AACzB,SAAO;AAAA,IACL,WAAW,OAAO;AAAA,IAClB,UAAU,OAAO;AAAA,IACjB,cAAc,OAAO;AAAA,IACrB,eAAe,OAAO;AAAA,IACtB,WAAW,OAAO;AAAA,IAClB,YAAY,OAAO;AAAA,IACnB,aAAa,OAAO;AAAA,IACpB,uBAAuB,OAAO;AAAA,EAChC;AACF;","names":[]}
@@ -1,8 +1,7 @@
1
- import { Market } from '@nadohq/contracts';
2
- import { IndexerSnapshotsIntervalParams, IndexerSpotBalance, IndexerPerpBalance, IndexerOrder, IndexerEvent, IndexerEventWithTx, IndexerMatchEventBalances, IndexerProductPayment, IndexerPerpPrices, IndexerFundingRate, IndexerMaker, IndexerLeaderboardParticipant, IndexerLeaderboardRegistration, IndexerLeaderboardContest, Candlestick, IndexerMarketSnapshot, IndexerNlpSnapshot } from './types/clientTypes.cjs';
3
- import { IndexerServerPerpPrices, IndexerServerFundingRate } from './types/serverTypes.cjs';
1
+ import { Market } from '@nadohq/shared';
2
+ import { IndexerSnapshotsIntervalParams, IndexerSpotBalance, IndexerPerpBalance, IndexerOrder, IndexerEvent, IndexerEventWithTx, IndexerMatchEventBalances, IndexerProductPayment, IndexerPerpPrices, IndexerFundingRate, IndexerMaker, IndexerLeaderboardParticipant, IndexerLeaderboardRegistration, IndexerLeaderboardContest, Candlestick, IndexerMarketSnapshot, IndexerNlpSnapshot, IndexerV2TickerResponse } from './types/clientTypes.cjs';
4
3
  import { IndexerServerSnapshotsInterval, IndexerServerProduct, IndexerServerBalance, IndexerServerOrder, IndexerServerEvent, IndexerServerTx, IndexerServerMatchEventBalances, IndexerServerProductPayment, IndexerServerMaker, IndexerServerLeaderboardPosition, IndexerServerLeaderboardRegistration, IndexerServerLeaderboardContest, IndexerServerCandlestick, IndexerServerMarketSnapshot, IndexerServerNlpSnapshot } from './types/serverModelTypes.cjs';
5
- import '@nadohq/utils';
4
+ import { IndexerServerPerpPrices, IndexerServerFundingRate, IndexerServerV2TickerResponse } from './types/serverTypes.cjs';
6
5
  import 'viem';
7
6
  import './types/CandlestickPeriod.cjs';
8
7
  import './types/IndexerEventType.cjs';
@@ -27,5 +26,6 @@ declare function mapIndexerLeaderboardContest(contest: IndexerServerLeaderboardC
27
26
  declare function mapIndexerCandlesticks(candlestick: IndexerServerCandlestick): Candlestick;
28
27
  declare function mapIndexerMarketSnapshot(snapshot: IndexerServerMarketSnapshot): IndexerMarketSnapshot;
29
28
  declare function mapIndexerNlpSnapshot(snapshot: IndexerServerNlpSnapshot): IndexerNlpSnapshot;
29
+ declare function mapIndexerV2Ticker(ticker: IndexerServerV2TickerResponse): IndexerV2TickerResponse;
30
30
 
31
- export { mapIndexerCandlesticks, mapIndexerEvent, mapIndexerEventWithTx, mapIndexerFundingRate, mapIndexerLeaderboardContest, mapIndexerLeaderboardPosition, mapIndexerLeaderboardRegistration, mapIndexerMakerStatistics, mapIndexerMarketSnapshot, mapIndexerMatchEventBalances, mapIndexerNlpSnapshot, mapIndexerOrder, mapIndexerPerpPrices, mapIndexerProductPayment, mapIndexerServerBalance, mapIndexerServerProduct, mapSnapshotsIntervalToServerParams };
31
+ export { mapIndexerCandlesticks, mapIndexerEvent, mapIndexerEventWithTx, mapIndexerFundingRate, mapIndexerLeaderboardContest, mapIndexerLeaderboardPosition, mapIndexerLeaderboardRegistration, mapIndexerMakerStatistics, mapIndexerMarketSnapshot, mapIndexerMatchEventBalances, mapIndexerNlpSnapshot, mapIndexerOrder, mapIndexerPerpPrices, mapIndexerProductPayment, mapIndexerServerBalance, mapIndexerServerProduct, mapIndexerV2Ticker, mapSnapshotsIntervalToServerParams };
@@ -1,8 +1,7 @@
1
- import { Market } from '@nadohq/contracts';
2
- import { IndexerSnapshotsIntervalParams, IndexerSpotBalance, IndexerPerpBalance, IndexerOrder, IndexerEvent, IndexerEventWithTx, IndexerMatchEventBalances, IndexerProductPayment, IndexerPerpPrices, IndexerFundingRate, IndexerMaker, IndexerLeaderboardParticipant, IndexerLeaderboardRegistration, IndexerLeaderboardContest, Candlestick, IndexerMarketSnapshot, IndexerNlpSnapshot } from './types/clientTypes.js';
3
- import { IndexerServerPerpPrices, IndexerServerFundingRate } from './types/serverTypes.js';
1
+ import { Market } from '@nadohq/shared';
2
+ import { IndexerSnapshotsIntervalParams, IndexerSpotBalance, IndexerPerpBalance, IndexerOrder, IndexerEvent, IndexerEventWithTx, IndexerMatchEventBalances, IndexerProductPayment, IndexerPerpPrices, IndexerFundingRate, IndexerMaker, IndexerLeaderboardParticipant, IndexerLeaderboardRegistration, IndexerLeaderboardContest, Candlestick, IndexerMarketSnapshot, IndexerNlpSnapshot, IndexerV2TickerResponse } from './types/clientTypes.js';
4
3
  import { IndexerServerSnapshotsInterval, IndexerServerProduct, IndexerServerBalance, IndexerServerOrder, IndexerServerEvent, IndexerServerTx, IndexerServerMatchEventBalances, IndexerServerProductPayment, IndexerServerMaker, IndexerServerLeaderboardPosition, IndexerServerLeaderboardRegistration, IndexerServerLeaderboardContest, IndexerServerCandlestick, IndexerServerMarketSnapshot, IndexerServerNlpSnapshot } from './types/serverModelTypes.js';
5
- import '@nadohq/utils';
4
+ import { IndexerServerPerpPrices, IndexerServerFundingRate, IndexerServerV2TickerResponse } from './types/serverTypes.js';
6
5
  import 'viem';
7
6
  import './types/CandlestickPeriod.js';
8
7
  import './types/IndexerEventType.js';
@@ -27,5 +26,6 @@ declare function mapIndexerLeaderboardContest(contest: IndexerServerLeaderboardC
27
26
  declare function mapIndexerCandlesticks(candlestick: IndexerServerCandlestick): Candlestick;
28
27
  declare function mapIndexerMarketSnapshot(snapshot: IndexerServerMarketSnapshot): IndexerMarketSnapshot;
29
28
  declare function mapIndexerNlpSnapshot(snapshot: IndexerServerNlpSnapshot): IndexerNlpSnapshot;
29
+ declare function mapIndexerV2Ticker(ticker: IndexerServerV2TickerResponse): IndexerV2TickerResponse;
30
30
 
31
- export { mapIndexerCandlesticks, mapIndexerEvent, mapIndexerEventWithTx, mapIndexerFundingRate, mapIndexerLeaderboardContest, mapIndexerLeaderboardPosition, mapIndexerLeaderboardRegistration, mapIndexerMakerStatistics, mapIndexerMarketSnapshot, mapIndexerMatchEventBalances, mapIndexerNlpSnapshot, mapIndexerOrder, mapIndexerPerpPrices, mapIndexerProductPayment, mapIndexerServerBalance, mapIndexerServerProduct, mapSnapshotsIntervalToServerParams };
31
+ export { mapIndexerCandlesticks, mapIndexerEvent, mapIndexerEventWithTx, mapIndexerFundingRate, mapIndexerLeaderboardContest, mapIndexerLeaderboardPosition, mapIndexerLeaderboardRegistration, mapIndexerMakerStatistics, mapIndexerMarketSnapshot, mapIndexerMatchEventBalances, mapIndexerNlpSnapshot, mapIndexerOrder, mapIndexerPerpPrices, mapIndexerProductPayment, mapIndexerServerBalance, mapIndexerServerProduct, mapIndexerV2Ticker, mapSnapshotsIntervalToServerParams };