@nadohq/indexer-client 0.1.0-alpha.1 → 0.1.0-alpha.10

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 (62) hide show
  1. package/dist/IndexerBaseClient.cjs +71 -58
  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 +23 -10
  6. package/dist/IndexerBaseClient.js.map +1 -1
  7. package/dist/IndexerClient.cjs +20 -20
  8. package/dist/IndexerClient.cjs.map +1 -1
  9. package/dist/IndexerClient.d.cts +4 -5
  10. package/dist/IndexerClient.d.ts +4 -5
  11. package/dist/IndexerClient.js +9 -9
  12. package/dist/IndexerClient.js.map +1 -1
  13. package/dist/dataMappers.cjs +107 -112
  14. package/dist/dataMappers.cjs.map +1 -1
  15. package/dist/dataMappers.d.cts +5 -6
  16. package/dist/dataMappers.d.ts +5 -6
  17. package/dist/dataMappers.js +11 -17
  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.d.cts +5 -6
  26. package/dist/index.d.ts +5 -6
  27. package/dist/types/IndexerEventType.cjs.map +1 -1
  28. package/dist/types/IndexerEventType.d.cts +1 -1
  29. package/dist/types/IndexerEventType.d.ts +1 -1
  30. package/dist/types/NadoTx.cjs.map +1 -1
  31. package/dist/types/clientTypes.cjs.map +1 -1
  32. package/dist/types/clientTypes.d.cts +16 -14
  33. package/dist/types/clientTypes.d.ts +16 -14
  34. package/dist/types/index.d.cts +5 -6
  35. package/dist/types/index.d.ts +5 -6
  36. package/dist/types/paginatedEventsTypes.cjs.map +1 -1
  37. package/dist/types/paginatedEventsTypes.d.cts +7 -8
  38. package/dist/types/paginatedEventsTypes.d.ts +7 -8
  39. package/dist/types/serverModelTypes.cjs.map +1 -1
  40. package/dist/types/serverModelTypes.d.cts +5 -5
  41. package/dist/types/serverModelTypes.d.ts +5 -5
  42. package/dist/types/serverTypes.cjs.map +1 -1
  43. package/dist/types/serverTypes.d.cts +16 -8
  44. package/dist/types/serverTypes.d.ts +16 -8
  45. package/dist/utils/index.d.cts +2 -3
  46. package/dist/utils/index.d.ts +2 -3
  47. package/dist/utils/indexerBalanceValue.cjs.map +1 -1
  48. package/dist/utils/indexerBalanceValue.d.cts +2 -3
  49. package/dist/utils/indexerBalanceValue.d.ts +2 -3
  50. package/dist/utils/indexerBalanceValue.js.map +1 -1
  51. package/package.json +4 -5
  52. package/src/IndexerBaseClient.ts +35 -16
  53. package/src/IndexerClient.ts +17 -17
  54. package/src/dataMappers.ts +16 -22
  55. package/src/endpoints.ts +2 -2
  56. package/src/types/IndexerEventType.ts +2 -2
  57. package/src/types/NadoTx.ts +1 -1
  58. package/src/types/clientTypes.ts +21 -16
  59. package/src/types/paginatedEventsTypes.ts +7 -8
  60. package/src/types/serverModelTypes.ts +4 -4
  61. package/src/types/serverTypes.ts +17 -7
  62. 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 VLP_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 GetIndexerSubaccountVlpEventsParams,\n GetIndexerSubaccountVlpEventsResponse,\n IndexerCollateralEvent,\n IndexerEventPerpStateSnapshot,\n IndexerEventSpotStateSnapshot,\n IndexerEventWithTx,\n IndexerLiquidationEvent,\n IndexerSettlementEvent,\n IndexerVlpEvent,\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 getPaginatedSubaccountVlpEvents(\n params: GetIndexerSubaccountVlpEventsParams,\n ): Promise<GetIndexerSubaccountVlpEventsResponse> {\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 VLP 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_vlp', 'burn_vlp'],\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, IndexerVlpEvent>();\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: IndexerVlpEvent = {\n vlpDelta: 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 === VLP_PRODUCT_ID) {\n mappedEvent.vlpDelta = balanceDelta;\n } else {\n throw Error(`Invalid product ID for VLP 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,cAAc;AAAA,EAChE;AAAA,EAEA,MAAM,gCACJ,Q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ACtD,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 ProductEngineType,\n QUOTE_PRODUCT_ID,\n subaccountFromHex,\n NLP_PRODUCT_ID,\n} from '@nadohq/shared';\nimport { toBigDecimal, toIntegerString } 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 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,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,aAAa,CAAC;AAAA,UACxB,mBAAmB,aAAa,CAAC;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iD;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":[]}
@@ -30,22 +30,21 @@ __export(dataMappers_exports, {
30
30
  mapIndexerMakerStatistics: () => mapIndexerMakerStatistics,
31
31
  mapIndexerMarketSnapshot: () => mapIndexerMarketSnapshot,
32
32
  mapIndexerMatchEventBalances: () => mapIndexerMatchEventBalances,
33
+ mapIndexerNlpSnapshot: () => mapIndexerNlpSnapshot,
33
34
  mapIndexerOrder: () => mapIndexerOrder,
34
35
  mapIndexerPerpPrices: () => mapIndexerPerpPrices,
35
36
  mapIndexerProductPayment: () => mapIndexerProductPayment,
36
37
  mapIndexerServerBalance: () => mapIndexerServerBalance,
37
38
  mapIndexerServerProduct: () => mapIndexerServerProduct,
38
- mapIndexerVlpSnapshot: () => mapIndexerVlpSnapshot,
39
39
  mapSnapshotsIntervalToServerParams: () => mapSnapshotsIntervalToServerParams
40
40
  });
41
41
  module.exports = __toCommonJS(dataMappers_exports);
42
- var import_contracts = require("@nadohq/contracts");
43
42
  var import_engine_client = require("@nadohq/engine-client");
44
- var import_utils = require("@nadohq/utils");
43
+ var import_shared = require("@nadohq/shared");
45
44
  function mapSnapshotsIntervalToServerParams(params) {
46
45
  return {
47
46
  count: params.limit,
48
- max_time: params.maxTimeInclusive ? (0, import_utils.toIntegerString)(params.maxTimeInclusive) : void 0,
47
+ max_time: params.maxTimeInclusive ? (0, import_shared.toIntegerString)(params.maxTimeInclusive) : void 0,
49
48
  granularity: params.granularity
50
49
  };
51
50
  }
@@ -58,45 +57,41 @@ function mapIndexerServerProduct(product) {
58
57
  function mapIndexerServerBalance(balance) {
59
58
  if ("spot" in balance) {
60
59
  return {
61
- amount: (0, import_utils.toBigDecimal)(balance.spot.balance.amount),
60
+ amount: (0, import_shared.toBigDecimal)(balance.spot.balance.amount),
62
61
  productId: balance.spot.product_id,
63
- type: import_contracts.ProductEngineType.SPOT
62
+ type: import_shared.ProductEngineType.SPOT
64
63
  };
65
64
  }
66
65
  return {
67
- amount: (0, import_utils.toBigDecimal)(balance.perp.balance.amount),
66
+ amount: (0, import_shared.toBigDecimal)(balance.perp.balance.amount),
68
67
  productId: balance.perp.product_id,
69
- type: import_contracts.ProductEngineType.PERP,
70
- vQuoteBalance: (0, import_utils.toBigDecimal)(balance.perp.balance.v_quote_balance)
68
+ type: import_shared.ProductEngineType.PERP,
69
+ vQuoteBalance: (0, import_shared.toBigDecimal)(balance.perp.balance.v_quote_balance)
71
70
  };
72
71
  }
73
72
  function mapIndexerOrder(order) {
74
- const expiration = (0, import_utils.toBigDecimal)(order.expiration);
75
- const expirationEncodedData = (0, import_contracts.parseRawExpirationTimestamp)(order.expiration);
73
+ const appendix = (0, import_shared.unpackOrderAppendix)(order.appendix);
76
74
  return {
77
- amount: (0, import_utils.toBigDecimal)(order.amount),
75
+ amount: (0, import_shared.toBigDecimal)(order.amount),
78
76
  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),
77
+ expiration: Number(order.expiration),
78
+ appendix,
79
+ nonce: (0, import_shared.toBigDecimal)(order.nonce),
80
+ recvTimeSeconds: (0, import_shared.getRecvTimeFromOrderNonce)(order.nonce) / 1e3,
81
+ price: (0, import_shared.removeDecimals)(order.price_x18),
87
82
  productId: order.product_id,
88
83
  subaccount: order.subaccount,
89
84
  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)
85
+ baseFilled: (0, import_shared.toBigDecimal)(order.base_filled),
86
+ quoteFilled: (0, import_shared.toBigDecimal)(order.quote_filled),
87
+ totalFee: (0, import_shared.toBigDecimal)(order.fee)
93
88
  };
94
89
  }
95
90
  function mapIndexerEvent(event) {
96
91
  const eventState = (() => {
97
92
  if ("spot" in event.pre_balance) {
98
93
  return {
99
- type: import_contracts.ProductEngineType.SPOT,
94
+ type: import_shared.ProductEngineType.SPOT,
100
95
  market: mapIndexerServerProduct(event.product),
101
96
  preBalance: mapIndexerServerBalance(
102
97
  event.pre_balance
@@ -107,7 +102,7 @@ function mapIndexerEvent(event) {
107
102
  };
108
103
  }
109
104
  return {
110
- type: import_contracts.ProductEngineType.PERP,
105
+ type: import_shared.ProductEngineType.PERP,
111
106
  market: mapIndexerServerProduct(event.product),
112
107
  preBalance: mapIndexerServerBalance(
113
108
  event.pre_balance
@@ -126,18 +121,18 @@ function mapIndexerEvent(event) {
126
121
  subaccount: event.subaccount,
127
122
  submissionIndex: event.submission_idx,
128
123
  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)
124
+ netEntryCumulative: (0, import_shared.toBigDecimal)(event.net_entry_cumulative),
125
+ netEntryUnrealized: (0, import_shared.toBigDecimal)(event.net_entry_unrealized),
126
+ netFundingCumulative: (0, import_shared.toBigDecimal)(event.net_funding_cumulative),
127
+ netFundingUnrealized: (0, import_shared.toBigDecimal)(event.net_funding_unrealized),
128
+ netInterestCumulative: (0, import_shared.toBigDecimal)(event.net_interest_cumulative),
129
+ netInterestUnrealized: (0, import_shared.toBigDecimal)(event.net_interest_unrealized)
135
130
  }
136
131
  };
137
132
  }
138
133
  function mapIndexerEventWithTx(event, tx) {
139
134
  return {
140
- timestamp: (0, import_utils.toBigDecimal)(tx.timestamp),
135
+ timestamp: (0, import_shared.toBigDecimal)(tx.timestamp),
141
136
  tx: tx.tx,
142
137
  ...mapIndexerEvent(event)
143
138
  };
@@ -151,11 +146,11 @@ function mapIndexerMatchEventBalances(eventBalances) {
151
146
  function mapIndexerProductPayment(payment) {
152
147
  return {
153
148
  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),
149
+ timestamp: (0, import_shared.toBigDecimal)(payment.timestamp),
150
+ paymentAmount: (0, import_shared.toBigDecimal)(payment.amount),
151
+ balanceAmount: (0, import_shared.toBigDecimal)(payment.balance_amount),
152
+ annualPaymentRate: (0, import_shared.removeDecimals)(payment.rate_x18),
153
+ oraclePrice: (0, import_shared.removeDecimals)(payment.oracle_price_x18),
159
154
  isolated: payment.isolated,
160
155
  productId: payment.product_id,
161
156
  isolatedProductId: payment.isolated_product_id
@@ -163,16 +158,16 @@ function mapIndexerProductPayment(payment) {
163
158
  }
164
159
  function mapIndexerPerpPrices(perpPrices) {
165
160
  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),
161
+ indexPrice: (0, import_shared.removeDecimals)(perpPrices.index_price_x18),
162
+ markPrice: (0, import_shared.removeDecimals)(perpPrices.mark_price_x18),
163
+ updateTime: (0, import_shared.toBigDecimal)(perpPrices.update_time),
169
164
  productId: perpPrices.product_id
170
165
  };
171
166
  }
172
167
  function mapIndexerFundingRate(fundingRate) {
173
168
  return {
174
- fundingRate: (0, import_utils.removeDecimals)(fundingRate.funding_rate_x18),
175
- updateTime: (0, import_utils.toBigDecimal)(fundingRate.update_time),
169
+ fundingRate: (0, import_shared.removeDecimals)(fundingRate.funding_rate_x18),
170
+ updateTime: (0, import_shared.toBigDecimal)(fundingRate.update_time),
176
171
  productId: fundingRate.product_id
177
172
  };
178
173
  }
@@ -181,124 +176,124 @@ function mapIndexerMakerStatistics(maker) {
181
176
  address: maker.address,
182
177
  snapshots: maker.data.map((makerData) => {
183
178
  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)
179
+ timestamp: (0, import_shared.toBigDecimal)(makerData.timestamp),
180
+ makerFee: (0, import_shared.toBigDecimal)(makerData.maker_fee),
181
+ uptime: (0, import_shared.toBigDecimal)(makerData.uptime),
182
+ sumQMin: (0, import_shared.toBigDecimal)(makerData.sum_q_min),
183
+ qScore: (0, import_shared.toBigDecimal)(makerData.q_score),
184
+ makerShare: (0, import_shared.toBigDecimal)(makerData.maker_share),
185
+ expectedMakerReward: (0, import_shared.toBigDecimal)(makerData.expected_maker_reward)
191
186
  };
192
187
  })
193
188
  };
194
189
  }
195
190
  function mapIndexerLeaderboardPosition(position) {
196
191
  return {
197
- subaccount: (0, import_contracts.subaccountFromHex)(position.subaccount),
192
+ subaccount: (0, import_shared.subaccountFromHex)(position.subaccount),
198
193
  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)
194
+ pnl: (0, import_shared.toBigDecimal)(position.pnl),
195
+ pnlRank: (0, import_shared.toBigDecimal)(position.pnl_rank),
196
+ percentRoi: (0, import_shared.toBigDecimal)(position.roi),
197
+ roiRank: (0, import_shared.toBigDecimal)(position.roi_rank),
198
+ accountValue: (0, import_shared.toBigDecimal)(position.account_value),
199
+ volume: position.volume ? (0, import_shared.toBigDecimal)(position.volume) : void 0,
200
+ updateTime: (0, import_shared.toBigDecimal)(position.update_time)
206
201
  };
207
202
  }
208
203
  function mapIndexerLeaderboardRegistration(registration) {
209
204
  return {
210
- subaccount: (0, import_contracts.subaccountFromHex)(registration.subaccount),
205
+ subaccount: (0, import_shared.subaccountFromHex)(registration.subaccount),
211
206
  contestId: registration.contest_id,
212
- updateTime: (0, import_utils.toBigDecimal)(registration.update_time)
207
+ updateTime: (0, import_shared.toBigDecimal)(registration.update_time)
213
208
  };
214
209
  }
215
210
  function mapIndexerLeaderboardContest(contest) {
216
211
  return {
217
212
  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),
213
+ startTime: (0, import_shared.toBigDecimal)(contest.start_time),
214
+ endTime: (0, import_shared.toBigDecimal)(contest.end_time),
215
+ period: (0, import_shared.toBigDecimal)(contest.threshold),
216
+ totalParticipants: (0, import_shared.toBigDecimal)(contest.count),
217
+ minRequiredAccountValue: (0, import_shared.toBigDecimal)(contest.threshold),
218
+ minRequiredVolume: (0, import_shared.toBigDecimal)(contest.volume_threshold),
224
219
  requiredProductIds: contest.product_ids,
225
220
  active: contest.active,
226
- lastUpdated: (0, import_utils.toBigDecimal)(contest.last_updated)
221
+ lastUpdated: (0, import_shared.toBigDecimal)(contest.last_updated)
227
222
  };
228
223
  }
229
224
  function mapIndexerCandlesticks(candlestick) {
230
225
  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)
226
+ close: (0, import_shared.removeDecimals)(candlestick.close_x18),
227
+ high: (0, import_shared.removeDecimals)(candlestick.high_x18),
228
+ low: (0, import_shared.removeDecimals)(candlestick.low_x18),
229
+ open: (0, import_shared.removeDecimals)(candlestick.open_x18),
230
+ time: (0, import_shared.toBigDecimal)(candlestick.timestamp),
231
+ volume: (0, import_shared.toBigDecimal)(candlestick.volume)
237
232
  };
238
233
  }
239
234
  function mapIndexerMarketSnapshot(snapshot) {
240
235
  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)(
236
+ timestamp: (0, import_shared.toBigDecimal)(snapshot.timestamp),
237
+ cumulativeUsers: (0, import_shared.toBigDecimal)(snapshot.cumulative_users),
238
+ dailyActiveUsers: (0, import_shared.toBigDecimal)(snapshot.daily_active_users),
239
+ tvl: (0, import_shared.toBigDecimal)(snapshot.tvl),
240
+ borrowRates: (0, import_shared.mapValues)(
246
241
  snapshot.borrow_rates,
247
- (value) => (0, import_utils.removeDecimals)(value)
242
+ (value) => (0, import_shared.removeDecimals)(value)
248
243
  ),
249
- cumulativeLiquidationAmounts: (0, import_utils.mapValues)(
244
+ cumulativeLiquidationAmounts: (0, import_shared.mapValues)(
250
245
  snapshot.cumulative_liquidation_amounts,
251
- import_utils.toBigDecimal
246
+ import_shared.toBigDecimal
252
247
  ),
253
- cumulativeMakerFees: (0, import_utils.mapValues)(
248
+ cumulativeMakerFees: (0, import_shared.mapValues)(
254
249
  snapshot.cumulative_maker_fees,
255
- import_utils.toBigDecimal
250
+ import_shared.toBigDecimal
256
251
  ),
257
- cumulativeSequencerFees: (0, import_utils.mapValues)(
252
+ cumulativeSequencerFees: (0, import_shared.mapValues)(
258
253
  snapshot.cumulative_sequencer_fees,
259
- import_utils.toBigDecimal
254
+ import_shared.toBigDecimal
260
255
  ),
261
- cumulativeTakerFees: (0, import_utils.mapValues)(
256
+ cumulativeTakerFees: (0, import_shared.mapValues)(
262
257
  snapshot.cumulative_taker_fees,
263
- import_utils.toBigDecimal
258
+ import_shared.toBigDecimal
264
259
  ),
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)(
260
+ cumulativeTrades: (0, import_shared.mapValues)(snapshot.cumulative_trades, import_shared.toBigDecimal),
261
+ cumulativeVolumes: (0, import_shared.mapValues)(snapshot.cumulative_volumes, import_shared.toBigDecimal),
262
+ depositRates: (0, import_shared.mapValues)(
268
263
  snapshot.deposit_rates,
269
- (value) => (0, import_utils.removeDecimals)(value)
264
+ (value) => (0, import_shared.removeDecimals)(value)
270
265
  ),
271
- fundingRates: (0, import_utils.mapValues)(
266
+ fundingRates: (0, import_shared.mapValues)(
272
267
  snapshot.funding_rates,
273
- (value) => (0, import_utils.removeDecimals)(value)
268
+ (value) => (0, import_shared.removeDecimals)(value)
274
269
  ),
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)(
270
+ openInterestsQuote: (0, import_shared.mapValues)(snapshot.open_interests, import_shared.toBigDecimal),
271
+ totalBorrows: (0, import_shared.mapValues)(snapshot.total_borrows, import_shared.toBigDecimal),
272
+ totalDeposits: (0, import_shared.mapValues)(snapshot.total_deposits, import_shared.toBigDecimal),
273
+ cumulativeTradeSizes: (0, import_shared.mapValues)(
279
274
  snapshot.cumulative_trade_sizes,
280
- import_utils.toBigDecimal
275
+ import_shared.toBigDecimal
281
276
  ),
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)(
277
+ cumulativeInflows: (0, import_shared.mapValues)(snapshot.cumulative_inflows, import_shared.toBigDecimal),
278
+ cumulativeOutflows: (0, import_shared.mapValues)(snapshot.cumulative_outflows, import_shared.toBigDecimal),
279
+ oraclePrices: (0, import_shared.mapValues)(
285
280
  snapshot.oracle_prices,
286
- (value) => (0, import_utils.removeDecimals)(value)
281
+ (value) => (0, import_shared.removeDecimals)(value)
287
282
  )
288
283
  };
289
284
  }
290
- function mapIndexerVlpSnapshot(snapshot) {
285
+ function mapIndexerNlpSnapshot(snapshot) {
291
286
  return {
292
287
  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)
288
+ timestamp: (0, import_shared.toBigDecimal)(snapshot.timestamp),
289
+ cumulativeBurnAmountUsdc: (0, import_shared.toBigDecimal)(snapshot.cumulative_burn_usdc),
290
+ cumulativeMintAmountUsdc: (0, import_shared.toBigDecimal)(snapshot.cumulative_mint_usdc),
291
+ cumulativePnl: (0, import_shared.toBigDecimal)(snapshot.cumulative_pnl),
292
+ cumulativeTrades: (0, import_shared.toBigDecimal)(snapshot.cumulative_trades),
293
+ cumulativeVolume: (0, import_shared.toBigDecimal)(snapshot.cumulative_volume),
294
+ depositors: (0, import_shared.toBigDecimal)(snapshot.depositors),
295
+ oraclePrice: (0, import_shared.removeDecimals)(snapshot.oracle_price_x18),
296
+ tvl: (0, import_shared.toBigDecimal)(snapshot.tvl)
302
297
  };
303
298
  }
304
299
  // Annotate the CommonJS export names for ESM import in node:
@@ -313,12 +308,12 @@ function mapIndexerVlpSnapshot(snapshot) {
313
308
  mapIndexerMakerStatistics,
314
309
  mapIndexerMarketSnapshot,
315
310
  mapIndexerMatchEventBalances,
311
+ mapIndexerNlpSnapshot,
316
312
  mapIndexerOrder,
317
313
  mapIndexerPerpPrices,
318
314
  mapIndexerProductPayment,
319
315
  mapIndexerServerBalance,
320
316
  mapIndexerServerProduct,
321
- mapIndexerVlpSnapshot,
322
317
  mapSnapshotsIntervalToServerParams
323
318
  });
324
319
  //# 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 IndexerServerVlpSnapshot,\n IndexerSnapshotsIntervalParams,\n IndexerSpotBalance,\n IndexerVlpSnapshot,\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 mapIndexerVlpSnapshot(\n snapshot: IndexerServerVlpSnapshot,\n): IndexerVlpSnapshot {\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;A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wBAAoB,wBAAU,SAAS,qBAAqB,yBAAY;AAAA,IACxE,kBAAc;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 IndexerSnapshotsIntervalParams,\n IndexerSpotBalance,\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 },\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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAGO;AACP,oBAYO;AAsCA,SAAS,mCACd,QACgC;AAChC,SAAO;AAAA,IACL,OAAO,OAAO;AAAA,IACd,UAAU,OAAO,uBACb,+BAAgB,OAAO,gBAAgB,IACvC;AAAA,IACJ,aAAa,OAAO;AAAA,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AAiB;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;","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, IndexerVlpSnapshot } from './types/clientTypes.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 } from './types/clientTypes.cjs';
3
3
  import { IndexerServerPerpPrices, IndexerServerFundingRate } from './types/serverTypes.cjs';
4
- import { IndexerServerSnapshotsInterval, IndexerServerProduct, IndexerServerBalance, IndexerServerOrder, IndexerServerEvent, IndexerServerTx, IndexerServerMatchEventBalances, IndexerServerProductPayment, IndexerServerMaker, IndexerServerLeaderboardPosition, IndexerServerLeaderboardRegistration, IndexerServerLeaderboardContest, IndexerServerCandlestick, IndexerServerMarketSnapshot, IndexerServerVlpSnapshot } from './types/serverModelTypes.cjs';
5
- import '@nadohq/utils';
4
+ import { IndexerServerSnapshotsInterval, IndexerServerProduct, IndexerServerBalance, IndexerServerOrder, IndexerServerEvent, IndexerServerTx, IndexerServerMatchEventBalances, IndexerServerProductPayment, IndexerServerMaker, IndexerServerLeaderboardPosition, IndexerServerLeaderboardRegistration, IndexerServerLeaderboardContest, IndexerServerCandlestick, IndexerServerMarketSnapshot, IndexerServerNlpSnapshot } from './types/serverModelTypes.cjs';
6
5
  import 'viem';
7
6
  import './types/CandlestickPeriod.cjs';
8
7
  import './types/IndexerEventType.cjs';
@@ -26,6 +25,6 @@ declare function mapIndexerLeaderboardRegistration(registration: IndexerServerLe
26
25
  declare function mapIndexerLeaderboardContest(contest: IndexerServerLeaderboardContest): IndexerLeaderboardContest;
27
26
  declare function mapIndexerCandlesticks(candlestick: IndexerServerCandlestick): Candlestick;
28
27
  declare function mapIndexerMarketSnapshot(snapshot: IndexerServerMarketSnapshot): IndexerMarketSnapshot;
29
- declare function mapIndexerVlpSnapshot(snapshot: IndexerServerVlpSnapshot): IndexerVlpSnapshot;
28
+ declare function mapIndexerNlpSnapshot(snapshot: IndexerServerNlpSnapshot): IndexerNlpSnapshot;
30
29
 
31
- export { mapIndexerCandlesticks, mapIndexerEvent, mapIndexerEventWithTx, mapIndexerFundingRate, mapIndexerLeaderboardContest, mapIndexerLeaderboardPosition, mapIndexerLeaderboardRegistration, mapIndexerMakerStatistics, mapIndexerMarketSnapshot, mapIndexerMatchEventBalances, mapIndexerOrder, mapIndexerPerpPrices, mapIndexerProductPayment, mapIndexerServerBalance, mapIndexerServerProduct, mapIndexerVlpSnapshot, mapSnapshotsIntervalToServerParams };
30
+ export { mapIndexerCandlesticks, mapIndexerEvent, mapIndexerEventWithTx, mapIndexerFundingRate, mapIndexerLeaderboardContest, mapIndexerLeaderboardPosition, mapIndexerLeaderboardRegistration, mapIndexerMakerStatistics, mapIndexerMarketSnapshot, mapIndexerMatchEventBalances, mapIndexerNlpSnapshot, mapIndexerOrder, mapIndexerPerpPrices, mapIndexerProductPayment, mapIndexerServerBalance, mapIndexerServerProduct, 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, IndexerVlpSnapshot } from './types/clientTypes.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 } from './types/clientTypes.js';
3
3
  import { IndexerServerPerpPrices, IndexerServerFundingRate } from './types/serverTypes.js';
4
- import { IndexerServerSnapshotsInterval, IndexerServerProduct, IndexerServerBalance, IndexerServerOrder, IndexerServerEvent, IndexerServerTx, IndexerServerMatchEventBalances, IndexerServerProductPayment, IndexerServerMaker, IndexerServerLeaderboardPosition, IndexerServerLeaderboardRegistration, IndexerServerLeaderboardContest, IndexerServerCandlestick, IndexerServerMarketSnapshot, IndexerServerVlpSnapshot } from './types/serverModelTypes.js';
5
- import '@nadohq/utils';
4
+ import { IndexerServerSnapshotsInterval, IndexerServerProduct, IndexerServerBalance, IndexerServerOrder, IndexerServerEvent, IndexerServerTx, IndexerServerMatchEventBalances, IndexerServerProductPayment, IndexerServerMaker, IndexerServerLeaderboardPosition, IndexerServerLeaderboardRegistration, IndexerServerLeaderboardContest, IndexerServerCandlestick, IndexerServerMarketSnapshot, IndexerServerNlpSnapshot } from './types/serverModelTypes.js';
6
5
  import 'viem';
7
6
  import './types/CandlestickPeriod.js';
8
7
  import './types/IndexerEventType.js';
@@ -26,6 +25,6 @@ declare function mapIndexerLeaderboardRegistration(registration: IndexerServerLe
26
25
  declare function mapIndexerLeaderboardContest(contest: IndexerServerLeaderboardContest): IndexerLeaderboardContest;
27
26
  declare function mapIndexerCandlesticks(candlestick: IndexerServerCandlestick): Candlestick;
28
27
  declare function mapIndexerMarketSnapshot(snapshot: IndexerServerMarketSnapshot): IndexerMarketSnapshot;
29
- declare function mapIndexerVlpSnapshot(snapshot: IndexerServerVlpSnapshot): IndexerVlpSnapshot;
28
+ declare function mapIndexerNlpSnapshot(snapshot: IndexerServerNlpSnapshot): IndexerNlpSnapshot;
30
29
 
31
- export { mapIndexerCandlesticks, mapIndexerEvent, mapIndexerEventWithTx, mapIndexerFundingRate, mapIndexerLeaderboardContest, mapIndexerLeaderboardPosition, mapIndexerLeaderboardRegistration, mapIndexerMakerStatistics, mapIndexerMarketSnapshot, mapIndexerMatchEventBalances, mapIndexerOrder, mapIndexerPerpPrices, mapIndexerProductPayment, mapIndexerServerBalance, mapIndexerServerProduct, mapIndexerVlpSnapshot, mapSnapshotsIntervalToServerParams };
30
+ export { mapIndexerCandlesticks, mapIndexerEvent, mapIndexerEventWithTx, mapIndexerFundingRate, mapIndexerLeaderboardContest, mapIndexerLeaderboardPosition, mapIndexerLeaderboardRegistration, mapIndexerMakerStatistics, mapIndexerMarketSnapshot, mapIndexerMatchEventBalances, mapIndexerNlpSnapshot, mapIndexerOrder, mapIndexerPerpPrices, mapIndexerProductPayment, mapIndexerServerBalance, mapIndexerServerProduct, mapSnapshotsIntervalToServerParams };