@usherlabs/cex-broker 0.2.50 → 0.2.51

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 (55) hide show
  1. package/dist/commands/cex-canonical-orderbook-export.js +7750 -920
  2. package/dist/commands/cex-canonical-orderbook-export.js.map +41 -10
  3. package/dist/commands/cli.js +3 -2
  4. package/dist/commands/market-data-vendor-backfill.js +8297 -6460
  5. package/dist/commands/market-data-vendor-backfill.js.map +16 -15
  6. package/dist/helpers/canonical-orderbook-export/parquet-projection.d.ts +19 -0
  7. package/dist/helpers/market-data-archive/canonical-orderbook.d.ts +1 -1
  8. package/dist/helpers/market-data-preparation/conformance-fixtures.d.ts +114 -2
  9. package/dist/helpers/market-data-preparation/contracts.d.ts +1298 -18
  10. package/dist/helpers/market-data-preparation/required-clock-qualification.d.ts +43 -0
  11. package/dist/helpers/market-data-preparation/source-tape-dependencies.d.ts +19 -0
  12. package/dist/helpers/market-data-preparation/source-tape-operation.d.ts +109 -0
  13. package/dist/helpers/market-data-source-forensics.d.ts +400 -0
  14. package/dist/helpers/market-data-vendor-backfill/conformance-fixtures.d.ts +3 -5
  15. package/dist/helpers/market-data-vendor-backfill/contracts.d.ts +21 -56
  16. package/dist/helpers/market-data-vendor-backfill/core.d.ts +1 -0
  17. package/dist/helpers/market-data-vendor-backfill/cryptohftdata.d.ts +44 -5
  18. package/dist/helpers/market-data-vendor-backfill/manifests.d.ts +33 -1112
  19. package/dist/helpers/market-data-vendor-backfill/promotion.d.ts +1 -0
  20. package/dist/helpers/source-tape-sandbox.d.ts +82 -0
  21. package/dist/helpers/source-tape.d.ts +165 -0
  22. package/dist/index.js +4 -3
  23. package/dist/index.js.map +3 -3
  24. package/dist/market-data-preparation/fixtures/{conformance-v2.json → conformance-v3.json} +253 -56
  25. package/dist/market-data-preparation/policies/capability-policy.json +4 -4
  26. package/dist/market-data-preparation/policies/source-tape-capability-v1.json +35 -0
  27. package/dist/market-data-preparation/schema-manifest.json +30 -10
  28. package/dist/market-data-preparation/schemas/canonical-orderbook-export-request-v1.schema.json +5 -1
  29. package/dist/market-data-preparation/schemas/{canonical-orderbook-export-result-v1.schema.json → canonical-orderbook-export-result-v2.schema.json} +20 -6
  30. package/dist/market-data-preparation/schemas/order-book-depth-summary-parquet-projection-v1.schema.json +256 -0
  31. package/dist/market-data-preparation/schemas/order-book-levels-parquet-projection-v1.schema.json +220 -0
  32. package/dist/market-data-preparation/schemas/{preparation-product-pin-v1.schema.json → preparation-product-pin-v2.schema.json} +59 -9
  33. package/dist/market-data-preparation/schemas/promotion-receipt-v1.schema.json +5 -1
  34. package/dist/market-data-preparation/schemas/source-forensics-ledger-v1.schema.json +463 -0
  35. package/dist/market-data-preparation/schemas/source-qualification-record-v1.schema.json +394 -0
  36. package/dist/market-data-preparation.d.ts +7 -0
  37. package/dist/market-data-preparation.js +35448 -25240
  38. package/dist/market-data-preparation.js.map +118 -78
  39. package/dist/market-data-vendor-backfill.d.ts +7 -4
  40. package/dist/market-data-vendor-backfill.js +19338 -15503
  41. package/dist/market-data-vendor-backfill.js.map +65 -60
  42. package/package.json +1 -5
  43. package/dist/market-data-preparation/policies/capability-policy-v1.json +0 -28
  44. package/dist/market-data-preparation/policies/resource-policy-v1.json +0 -16
  45. package/dist/market-data-vendor-backfill/fixtures/conformance-v1.json +0 -448
  46. package/dist/market-data-vendor-backfill/policies/capability-policy-v2.json +0 -39
  47. package/dist/market-data-vendor-backfill/policies/capability-policy.json +0 -28
  48. package/dist/market-data-vendor-backfill/policies/resource-policy-v2.json +0 -16
  49. package/dist/market-data-vendor-backfill/policies/resource-policy.json +0 -16
  50. package/dist/market-data-vendor-backfill/schema-manifest.json +0 -31
  51. package/dist/market-data-vendor-backfill/schemas/archive-selection.schema.json +0 -224
  52. package/dist/market-data-vendor-backfill/schemas/promotion-receipt.schema.json +0 -171
  53. package/dist/market-data-vendor-backfill/schemas/request.schema.json +0 -166
  54. package/dist/market-data-vendor-backfill/schemas/required-clock.schema.json +0 -47
  55. package/dist/market-data-vendor-backfill/schemas/result.schema.json +0 -198
@@ -1,5 +1,6 @@
1
1
  import { type BackfillArchiveRow, type PromotionReceipt, type PromotionReceiptWire } from "./contracts";
2
2
  export type StablePromotionReceipt = Omit<PromotionReceipt, "receiptId" | "verificationTimeMs">;
3
+ export declare function promotionReceiptMatchesCurrentPolicies(receipt: PromotionReceiptWire): boolean;
3
4
  export declare function promotionReceiptId(receipt: StablePromotionReceipt): string;
4
5
  type UnfinalizedPromotionReceiptWire = Omit<PromotionReceiptWire, "receipt_id" | "promotion_identity_sha256"> & Partial<Pick<PromotionReceiptWire, "receipt_id" | "promotion_identity_sha256">>;
5
6
  export declare function finalizePromotionReceipt(receipt: UnfinalizedPromotionReceiptWire): PromotionReceiptWire;
@@ -0,0 +1,82 @@
1
+ import type { ArchiveQueryClient } from "./market-data-vendor-backfill/archive-reader";
2
+ import type { ArchiveSelectionWire, ForwarderBatch, MarketDataVendorBackfillRequest, ProviderObjectEvidence } from "./market-data-vendor-backfill/contracts";
3
+ import type { CandidateVerification } from "./market-data-vendor-backfill/core";
4
+ import { SOURCE_TAPE_CONSTRUCTION_MODE, SOURCE_TAPE_SANDBOX_TARGET, type SourceTapeArchiveSinkResult } from "./source-tape";
5
+ export declare function verifySourceTapeArchive(input: {
6
+ request: MarketDataVendorBackfillRequest;
7
+ sinkResult: SourceTapeArchiveSinkResult;
8
+ client: ArchiveQueryClient;
9
+ }): Promise<CandidateVerification>;
10
+ export type SourceTapeExportArtifact = {
11
+ file_name: string;
12
+ rows: number;
13
+ bytes: number;
14
+ sha256: string;
15
+ projection_schema_id: string;
16
+ projection_schema_sha256: string;
17
+ };
18
+ export type SourceTapeExportResult = {
19
+ promotionReceiptIds: string[];
20
+ levels: SourceTapeExportArtifact;
21
+ summary: SourceTapeExportArtifact;
22
+ };
23
+ export type SourceTapeSandboxEvidence = {
24
+ schema_id: "market-data-source-tape-sandbox-evidence/v1";
25
+ archive_target: typeof SOURCE_TAPE_SANDBOX_TARGET;
26
+ construction_mode: typeof SOURCE_TAPE_CONSTRUCTION_MODE;
27
+ normal_archive_path: true;
28
+ tape_capability: {
29
+ policy_id: string;
30
+ policy_sha256: string;
31
+ };
32
+ state_count: number;
33
+ promotion: {
34
+ receipt_id: string;
35
+ promotion_identity_sha256: string;
36
+ qualification_event_id: string;
37
+ };
38
+ selection: {
39
+ selection_sha256: string;
40
+ receipt_ids: string[];
41
+ };
42
+ export: {
43
+ levels: SourceTapeExportArtifact;
44
+ summary: SourceTapeExportArtifact;
45
+ };
46
+ projection_schema_pins: readonly {
47
+ schema_id: string;
48
+ schema_sha256: string;
49
+ }[];
50
+ };
51
+ export declare function promoteAndExportSourceTapeSandbox(input: {
52
+ request: MarketDataVendorBackfillRequest;
53
+ sinkResult: SourceTapeArchiveSinkResult;
54
+ verification: CandidateVerification;
55
+ datasetObjects: ProviderObjectEvidence[];
56
+ vendorSemanticDigest: string;
57
+ verifiedAt: string;
58
+ forwarder: {
59
+ submit(batch: ForwarderBatch): Promise<{
60
+ ok: boolean;
61
+ inserted: number;
62
+ }>;
63
+ };
64
+ archive: {
65
+ resolveSelection(request: MarketDataVendorBackfillRequest): Promise<ArchiveSelectionWire>;
66
+ };
67
+ exporter: {
68
+ export(request: {
69
+ schema_id: "https://schemas.usher.so/cex-canonical-orderbook-export-request/v1";
70
+ request_id: string;
71
+ target: {
72
+ environment: string;
73
+ cluster: string;
74
+ };
75
+ selection: ArchiveSelectionWire;
76
+ depth: 100;
77
+ construction_mode: typeof SOURCE_TAPE_CONSTRUCTION_MODE;
78
+ canonical_schema_version: string;
79
+ checksum_algorithm: "sha256-canonical-json-v1";
80
+ }): Promise<SourceTapeExportResult>;
81
+ };
82
+ }): Promise<SourceTapeSandboxEvidence>;
@@ -0,0 +1,165 @@
1
+ import type { BackfillArchiveRow, ForwarderBatch } from "./market-data-vendor-backfill/contracts";
2
+ import { type PolicyNeutralCryptoHftBookState, type PolicyNeutralTapeSink } from "./market-data-vendor-backfill/cryptohftdata";
3
+ export declare const SOURCE_TAPE_CAPABILITY: Readonly<{
4
+ policy_id: string;
5
+ provider: string;
6
+ adapter_version: string;
7
+ acquisition_policy_id: string;
8
+ exchange: string;
9
+ market_type: string;
10
+ feed: string;
11
+ trading_pairs: string[];
12
+ construction_mode: string;
13
+ canonical_schema_id: string;
14
+ depth: number;
15
+ source_window_scan: string;
16
+ provider_object_inventory: string;
17
+ state_emission: string;
18
+ state_window: string;
19
+ archive_target: {
20
+ environment: string;
21
+ cluster: string;
22
+ };
23
+ archive_path: string;
24
+ submission_bounds: {
25
+ max_states_per_yield: number;
26
+ max_rows_per_batch: number;
27
+ max_bytes_per_batch: number;
28
+ max_in_flight: number;
29
+ };
30
+ clickhouse_image: string;
31
+ clickhouse_server_version: string;
32
+ projection_schema_ids: string[];
33
+ policy_sha256: string;
34
+ }>;
35
+ export declare const SOURCE_TAPE_CAPABILITY_ID: string;
36
+ export declare const SOURCE_TAPE_CONSTRUCTION_MODE: "policy_neutral_top_n_state_change_tape/v1";
37
+ export declare const SOURCE_TAPE_DEPTH: 100;
38
+ export declare const SOURCE_TAPE_MAX_STATES_PER_YIELD: 4;
39
+ export declare const SOURCE_TAPE_MAX_BATCH_ROWS = 1000;
40
+ export declare const SOURCE_TAPE_MAX_BATCH_BYTES: number;
41
+ export declare const SOURCE_TAPE_MAX_IN_FLIGHT: 1;
42
+ export declare const SOURCE_TAPE_SANDBOX_TARGET: Readonly<{
43
+ environment: "sandbox";
44
+ cluster: "cex-archive-local";
45
+ }>;
46
+ export declare const SOURCE_TAPE_PROJECTION_PINS: readonly Readonly<{
47
+ schema_id: string;
48
+ schema_sha256: string;
49
+ }>[];
50
+ export type SourceTapeProviderObjectInventory = {
51
+ expected_identities: string[];
52
+ observed_identities: string[];
53
+ complete: boolean;
54
+ };
55
+ export declare function sourceTapeCaptureBundleId(input: {
56
+ idempotencyKey: string;
57
+ tradingPair: "ARB-USDC" | "ARB-USDT";
58
+ window: {
59
+ startTimeMs: number;
60
+ endTimeMs: number;
61
+ };
62
+ expectedObjectIdentities: readonly string[];
63
+ }): string;
64
+ /**
65
+ * `production` is the stable forwarder mutation-authorization class. It is not
66
+ * an environment assertion: source-tape qualification remains sandbox-local.
67
+ */
68
+ export declare function assertSourceTapeSandboxAuthorization(input: {
69
+ requestAuthorizationId: string;
70
+ requestTarget: {
71
+ environment: string;
72
+ cluster: string;
73
+ };
74
+ preflight: {
75
+ authorizationId: string;
76
+ scope: "production";
77
+ environment: string;
78
+ cluster: string;
79
+ credentialValidated: boolean;
80
+ };
81
+ }): void;
82
+ export type SourceTapeArchiveSinkResult = {
83
+ capture_bundle_id: string;
84
+ state_count: number;
85
+ level_row_count: number;
86
+ summary_row_count: number;
87
+ forwarder_batch_count: number;
88
+ forwarder_batch_identity_sha256: string;
89
+ initializer: {
90
+ canonical_snapshot_id: string;
91
+ source_time_ms: number;
92
+ sequence: string;
93
+ semantic_stream_position: 0;
94
+ };
95
+ expected_semantic_digest: string;
96
+ first_state_descriptor_sha256: string;
97
+ last_state_descriptor_sha256: string;
98
+ provider_object_inventory_complete: true;
99
+ max_states_per_yield: typeof SOURCE_TAPE_MAX_STATES_PER_YIELD;
100
+ max_batch_rows: typeof SOURCE_TAPE_MAX_BATCH_ROWS;
101
+ max_batch_bytes: typeof SOURCE_TAPE_MAX_BATCH_BYTES;
102
+ max_in_flight_submissions: typeof SOURCE_TAPE_MAX_IN_FLIGHT;
103
+ };
104
+ export type SourceTapeSemanticStateDescriptor = {
105
+ state_kind: "initialization" | "change";
106
+ semantic_stream_position: number;
107
+ canonical_snapshot_id: string;
108
+ source_time_ms: number;
109
+ sequence: string;
110
+ canonical_rows_sha256: string;
111
+ };
112
+ export declare class SourceTapeSemanticDigestAccumulator {
113
+ private readonly hash;
114
+ private count;
115
+ constructor();
116
+ append(descriptor: SourceTapeSemanticStateDescriptor): void;
117
+ digest(): string;
118
+ }
119
+ export declare function sourceTapeSemanticStateDescriptor(input: {
120
+ stateKind: "initialization" | "change";
121
+ semanticStreamPosition: number;
122
+ rows: readonly BackfillArchiveRow[];
123
+ }): SourceTapeSemanticStateDescriptor;
124
+ export type SourceTapeArchiveSink = PolicyNeutralTapeSink & {
125
+ result(): SourceTapeArchiveSinkResult;
126
+ };
127
+ /**
128
+ * Streams canonical tape rows to the existing archive-forwarder admission
129
+ * tables. Promotion, selection and exporter-v2 finalization remain later
130
+ * gates; this sink never creates a receipt or a success manifest by itself.
131
+ */
132
+ export declare function createSourceTapeArchiveSink(input: {
133
+ captureBundleId: string;
134
+ tradingPair: "ARB-USDC" | "ARB-USDT";
135
+ window: {
136
+ startTimeMs: number;
137
+ endTimeMs: number;
138
+ };
139
+ forwarder: {
140
+ submit(batch: ForwarderBatch): Promise<{
141
+ ok: boolean;
142
+ inserted: number;
143
+ }>;
144
+ };
145
+ }): SourceTapeArchiveSink;
146
+ export declare function providerObjectInventoryIsComplete(inventory: SourceTapeProviderObjectInventory): boolean;
147
+ export declare function evaluateSourceTapeEligibility(input: {
148
+ source_enumeration_eligible: boolean;
149
+ provider_object_inventory: SourceTapeProviderObjectInventory;
150
+ tape_complete: boolean;
151
+ capability_id: string;
152
+ capability_sha256: string;
153
+ construction_mode: string;
154
+ projection_schema_pins: readonly {
155
+ schema_id: string;
156
+ schema_sha256: string;
157
+ }[];
158
+ artifact_sha256s: readonly string[];
159
+ tape_manifest_sha256: string;
160
+ }): boolean;
161
+ export declare function normalizeSourceTapeStates(input: {
162
+ tape: readonly PolicyNeutralCryptoHftBookState[];
163
+ capture_bundle_id: string;
164
+ trading_pair: "ARB-USDC" | "ARB-USDT";
165
+ }): BackfillArchiveRow[];
package/dist/index.js CHANGED
@@ -294125,7 +294125,7 @@ function commonEvidenceFields(context2, rawCapture, input) {
294125
294125
  source_time_ms: input.eventTimeMs,
294126
294126
  received_time_ms: input.receivedTimeMs,
294127
294127
  snapshot_id: input.snapshotId,
294128
- construction_mode: "sampled_top_n_snapshot",
294128
+ construction_mode: input.constructionMode,
294129
294129
  gap_policy: "record_gap",
294130
294130
  depth_limit: input.depthLimit,
294131
294131
  sequence: input.sequence,
@@ -294179,7 +294179,8 @@ function buildCanonicalOrderBookRows(input) {
294179
294179
  sequence,
294180
294180
  depthLimit: input.depthLimit,
294181
294181
  eventTimeMs,
294182
- receivedTimeMs
294182
+ receivedTimeMs,
294183
+ constructionMode: input.constructionMode ?? "sampled_top_n_snapshot"
294183
294184
  });
294184
294185
  const levels = [
294185
294186
  ["bid", bids],
@@ -313344,4 +313345,4 @@ export {
313344
313345
  CEXBroker as default
313345
313346
  };
313346
313347
 
313347
- //# debugId=B0B080620F355A6764756E2164756E21
313348
+ //# debugId=298884FD1F08284464756E2164756E21