@usherlabs/cex-broker 0.2.49 → 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 +7747 -883
  2. package/dist/commands/cex-canonical-orderbook-export.js.map +41 -10
  3. package/dist/commands/cli.js +127 -34
  4. package/dist/commands/market-data-vendor-backfill.js +8284 -6391
  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 +45 -5
  18. package/dist/helpers/market-data-vendor-backfill/manifests.d.ts +31 -1083
  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/helpers/trace-context.d.ts +8 -0
  23. package/dist/index.js +128 -35
  24. package/dist/index.js.map +7 -6
  25. package/dist/market-data-preparation/fixtures/{conformance-v2.json → conformance-v3.json} +257 -60
  26. package/dist/market-data-preparation/policies/capability-policy.json +15 -4
  27. package/dist/market-data-preparation/policies/resource-policy.json +3 -3
  28. package/dist/market-data-preparation/policies/source-tape-capability-v1.json +35 -0
  29. package/dist/market-data-preparation/schema-manifest.json +30 -10
  30. package/dist/market-data-preparation/schemas/canonical-orderbook-export-request-v1.schema.json +5 -1
  31. package/dist/market-data-preparation/schemas/{canonical-orderbook-export-result-v1.schema.json → canonical-orderbook-export-result-v2.schema.json} +20 -6
  32. package/dist/market-data-preparation/schemas/order-book-depth-summary-parquet-projection-v1.schema.json +256 -0
  33. package/dist/market-data-preparation/schemas/order-book-levels-parquet-projection-v1.schema.json +220 -0
  34. package/dist/market-data-preparation/schemas/{preparation-product-pin-v1.schema.json → preparation-product-pin-v2.schema.json} +59 -9
  35. package/dist/market-data-preparation/schemas/promotion-receipt-v1.schema.json +5 -1
  36. package/dist/market-data-preparation/schemas/source-forensics-ledger-v1.schema.json +463 -0
  37. package/dist/market-data-preparation/schemas/source-qualification-record-v1.schema.json +394 -0
  38. package/dist/market-data-preparation.d.ts +7 -0
  39. package/dist/market-data-preparation.js +35443 -25203
  40. package/dist/market-data-preparation.js.map +118 -78
  41. package/dist/market-data-vendor-backfill.d.ts +8 -5
  42. package/dist/market-data-vendor-backfill.js +19444 -15553
  43. package/dist/market-data-vendor-backfill.js.map +65 -60
  44. package/package.json +1 -5
  45. package/dist/market-data-preparation/policies/capability-policy-v1.json +0 -28
  46. package/dist/market-data-vendor-backfill/fixtures/conformance-v1.json +0 -448
  47. package/dist/market-data-vendor-backfill/policies/capability-policy-v2.json +0 -28
  48. package/dist/market-data-vendor-backfill/policies/capability-policy.json +0 -28
  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
@@ -0,0 +1,43 @@
1
+ import { type ReconstructionObservationSink, type RequiredClockSourceForensicsLedgerWire, type RequiredClockSourceQualificationRecordWire, type SourceObjectInspection } from "../market-data-source-forensics";
2
+ import { type MarketDataVendorBackfillRequest, type ProviderCapability, type ProviderObjectEvidence } from "../market-data-vendor-backfill/contracts";
3
+ export declare const MARKET_DATA_REQUIRED_CLOCK_QUALIFICATION_OPERATION_ID: "market-data-required-clock-qualification/v1";
4
+ export type RequiredClockQualificationAdapter = {
5
+ capabilityFor(request: MarketDataVendorBackfillRequest): ProviderCapability | undefined;
6
+ acquire(request: MarketDataVendorBackfillRequest, capability: ProviderCapability, credential: {
7
+ apiKey: string;
8
+ }): Promise<unknown>;
9
+ };
10
+ export type RequiredClockQualificationAdapterFactory = (observer: ReconstructionObservationSink) => RequiredClockQualificationAdapter;
11
+ export type MarketDataRequiredClockQualificationInvocation = {
12
+ operation_id: typeof MARKET_DATA_REQUIRED_CLOCK_QUALIFICATION_OPERATION_ID;
13
+ attempt_id: string;
14
+ request: unknown;
15
+ required_clock: unknown;
16
+ artifacts: {
17
+ ledger_file_name: string;
18
+ qualification_record_file_name: string;
19
+ };
20
+ };
21
+ export type MarketDataRequiredClockQualificationInput = {
22
+ invocation: MarketDataRequiredClockQualificationInvocation;
23
+ attempt_root: string;
24
+ created_at: string;
25
+ credential: {
26
+ api_key: string;
27
+ };
28
+ dependencies?: {
29
+ adapter_factory?: RequiredClockQualificationAdapterFactory;
30
+ inspect_source_object?: (identity: string, attempt: number) => SourceObjectInspection | Promise<SourceObjectInspection>;
31
+ };
32
+ };
33
+ export type MarketDataRequiredClockQualificationResult = {
34
+ operation_id: typeof MARKET_DATA_REQUIRED_CLOCK_QUALIFICATION_OPERATION_ID;
35
+ normalized_invocation_sha256: string;
36
+ ledger: RequiredClockSourceForensicsLedgerWire;
37
+ qualification: RequiredClockSourceQualificationRecordWire;
38
+ source_dataset_evidence: {
39
+ objects: ProviderObjectEvidence[];
40
+ vendor_semantic_digest: string;
41
+ } | null;
42
+ };
43
+ export declare function runMarketDataRequiredClockQualification(input: MarketDataRequiredClockQualificationInput): Promise<MarketDataRequiredClockQualificationResult>;
@@ -0,0 +1,19 @@
1
+ import type { MarketDataSourceTapeDependencies } from "./source-tape-operation";
2
+ export type MarketDataSourceTapeDependencyConfiguration = {
3
+ attemptRoot: string;
4
+ archiveForwarder: {
5
+ url: string;
6
+ authToken?: string;
7
+ };
8
+ clickHouse: {
9
+ url: string;
10
+ username?: string;
11
+ password?: string;
12
+ };
13
+ };
14
+ type MarketDataSourceTapeDependencyRuntime = {
15
+ exporterExecutablePath: string;
16
+ nodeExecutablePath: string;
17
+ };
18
+ export declare function createMarketDataSourceTapeDependenciesForRuntime(configuration: MarketDataSourceTapeDependencyConfiguration, runtime: MarketDataSourceTapeDependencyRuntime): MarketDataSourceTapeDependencies;
19
+ export {};
@@ -0,0 +1,109 @@
1
+ import { type ReconstructionObservationSink, type SourceForensicsLedgerWire, type SourceObjectInspection, type SourceTapeQualificationRecordWire } from "../market-data-source-forensics";
2
+ import type { ArchiveQueryClient } from "../market-data-vendor-backfill/archive-reader";
3
+ import { type ArchiveSelectionWire, type CanonicalScopeWire, type ForwarderBatch, type MarketDataVendorBackfillRequest, type ProviderCapability } from "../market-data-vendor-backfill/contracts";
4
+ import { createSourceTapeArchiveSink, SOURCE_TAPE_SANDBOX_TARGET, type SourceTapeArchiveSinkResult } from "../source-tape";
5
+ import { promoteAndExportSourceTapeSandbox, type SourceTapeExportResult, type SourceTapeSandboxEvidence } from "../source-tape-sandbox";
6
+ import { type CanonicalOrderBookExportResultWire } from "./contracts";
7
+ export declare const MARKET_DATA_SOURCE_TAPE_OPERATION_ID: "market-data-source-tape/v1";
8
+ type PolicyPin = {
9
+ policy_id: string;
10
+ policy_sha256: string;
11
+ };
12
+ export type MarketDataSourceTapeInvocation = {
13
+ operation_id: typeof MARKET_DATA_SOURCE_TAPE_OPERATION_ID;
14
+ attempt_id: string;
15
+ request_id: string;
16
+ scope: CanonicalScopeWire & {
17
+ exchange: "okx";
18
+ trading_pair: "ARB-USDC" | "ARB-USDT";
19
+ market_type: "spot";
20
+ feed: "ORDERBOOK";
21
+ };
22
+ window: {
23
+ start_at: string;
24
+ end_at: string;
25
+ };
26
+ depth: 100;
27
+ target: typeof SOURCE_TAPE_SANDBOX_TARGET;
28
+ production_authorization_id: string;
29
+ expected_canonical_schema: {
30
+ schema_id: string;
31
+ schema_sha256: string;
32
+ };
33
+ product_pins: {
34
+ source_tape_capability: PolicyPin;
35
+ resource_policy: PolicyPin;
36
+ adapter_policy: PolicyPin;
37
+ acquisition_policy: PolicyPin;
38
+ };
39
+ artifacts: {
40
+ ledger_file_name: string;
41
+ qualification_record_file_name: string;
42
+ exporter_result_file_name: string;
43
+ };
44
+ };
45
+ export type SourceTapeAdapter = {
46
+ capabilityFor(request: MarketDataVendorBackfillRequest): ProviderCapability | undefined;
47
+ acquire(request: MarketDataVendorBackfillRequest, capability: ProviderCapability, credential: {
48
+ apiKey: string;
49
+ }): Promise<unknown>;
50
+ };
51
+ export type MarketDataSourceTapeDependencies = {
52
+ forwarder: {
53
+ preflight(input: {
54
+ authorizationId: string;
55
+ target: {
56
+ environment: string;
57
+ cluster: string;
58
+ };
59
+ }): Promise<{
60
+ forwarderIdentity: {
61
+ environment: string;
62
+ cluster: string;
63
+ };
64
+ authorization: {
65
+ authorizationId: string;
66
+ scope: "production";
67
+ environment: string;
68
+ cluster: string;
69
+ expiresAt: string;
70
+ credentialValidated: true;
71
+ };
72
+ }>;
73
+ submit(batch: ForwarderBatch): Promise<{
74
+ ok: boolean;
75
+ inserted: number;
76
+ }>;
77
+ };
78
+ archive_query: ArchiveQueryClient;
79
+ archive: {
80
+ resolveSelection(request: MarketDataVendorBackfillRequest): Promise<ArchiveSelectionWire>;
81
+ };
82
+ exporter: {
83
+ export(request: Parameters<Parameters<typeof promoteAndExportSourceTapeSandbox>[0]["exporter"]["export"]>[0]): Promise<SourceTapeExportResult & {
84
+ result: CanonicalOrderBookExportResultWire;
85
+ }>;
86
+ };
87
+ adapter_factory?: (observer: ReconstructionObservationSink, sink: ReturnType<typeof createSourceTapeArchiveSink>) => SourceTapeAdapter;
88
+ inspect_source_object?: (identity: string, attempt: number) => SourceObjectInspection | Promise<SourceObjectInspection>;
89
+ };
90
+ export type MarketDataSourceTapeInput = {
91
+ invocation: MarketDataSourceTapeInvocation;
92
+ attempt_root: string;
93
+ created_at: string;
94
+ credential: {
95
+ api_key: string;
96
+ };
97
+ dependencies: MarketDataSourceTapeDependencies;
98
+ };
99
+ export type MarketDataSourceTapeResult = {
100
+ operation_id: typeof MARKET_DATA_SOURCE_TAPE_OPERATION_ID;
101
+ normalized_invocation_sha256: string;
102
+ ledger: SourceForensicsLedgerWire;
103
+ qualification: SourceTapeQualificationRecordWire;
104
+ sink_result: SourceTapeArchiveSinkResult | null;
105
+ sandbox_evidence: SourceTapeSandboxEvidence | null;
106
+ exporter_result: CanonicalOrderBookExportResultWire | null;
107
+ };
108
+ export declare function runMarketDataSourceTape(input: MarketDataSourceTapeInput): Promise<MarketDataSourceTapeResult>;
109
+ export {};
@@ -0,0 +1,400 @@
1
+ import { SOURCE_FORENSICS_LEDGER_SCHEMA_ID, SOURCE_QUALIFICATION_RECORD_SCHEMA_ID } from "./market-data-preparation/contracts";
2
+ import type { CanonicalScopeWire, LowercaseUuid, RequiredClockWire, Sha256Hex } from "./market-data-vendor-backfill/contracts";
3
+ import type { PolicyPin } from "./market-data-vendor-backfill/manifests";
4
+ export declare const SOURCE_FORENSICS_MAX_RECORDS = 100000;
5
+ export declare const SOURCE_FORENSICS_MAX_CANONICAL_JSON_BYTES = 67108864;
6
+ export declare const SOURCE_FORENSICS_RECORD_KINDS: readonly ["sequence_discontinuity", "unanchored_target_interval", "stale_target_interval", "future_state_interval", "provider_object_checksum_conflict"];
7
+ export declare const SOURCE_FORENSICS_CLASSIFICATIONS: readonly ["stable_object_corruption", "mutable_provider_bytes", "provider_row_loss", "object_boundary_order_defect", "valid_inactive_market_state", "unresolved"];
8
+ export declare const SOURCE_FORENSICS_OPERATION_KINDS: readonly ["required_clock_qualification", "source_tape"];
9
+ export type SourceForensicsRecordKind = (typeof SOURCE_FORENSICS_RECORD_KINDS)[number];
10
+ export type SourceForensicsClassification = (typeof SOURCE_FORENSICS_CLASSIFICATIONS)[number];
11
+ export type SourceObjectEvidence = {
12
+ identity: string;
13
+ checksums: Sha256Hex[];
14
+ attempt_count: number;
15
+ quarantined: boolean;
16
+ };
17
+ export type SourceAnchorEvidence = {
18
+ event_time_ms: number;
19
+ sequence: string;
20
+ object_identity: string;
21
+ object_checksum: Sha256Hex;
22
+ };
23
+ export type SourceTargetInterval = {
24
+ start_target_time_ms: number;
25
+ end_target_time_ms_exclusive: number;
26
+ target_count: number;
27
+ };
28
+ export type SourceLagDistribution = {
29
+ lag_1000_ms: number;
30
+ lag_2000_ms: number;
31
+ lag_5000_ms: number;
32
+ lag_10000_ms: number;
33
+ lag_30000_ms: number;
34
+ lag_60000_ms: number;
35
+ };
36
+ export type SourceForensicsRecordWire = {
37
+ record_sha256: Sha256Hex;
38
+ kind: SourceForensicsRecordKind;
39
+ scope: CanonicalScopeWire;
40
+ provider_objects: SourceObjectEvidence[];
41
+ previous_anchor: SourceAnchorEvidence | null;
42
+ next_anchor: SourceAnchorEvidence | null;
43
+ target_interval: SourceTargetInterval | null;
44
+ lag_distribution: SourceLagDistribution | null;
45
+ sequence: null | {
46
+ expected_previous: string;
47
+ observed_previous: string;
48
+ observed_final: string;
49
+ event_time_ms: number;
50
+ };
51
+ classification: SourceForensicsClassification | null;
52
+ adapter_version: string;
53
+ };
54
+ export declare const SOURCE_TARGET_DISPOSITIONS: readonly ["fresh_within_bound", "valid_inactive_market_state", "disqualifying"];
55
+ export type SourceTargetDisposition = (typeof SOURCE_TARGET_DISPOSITIONS)[number];
56
+ export type SourceTargetDispositionWire = {
57
+ target_id: LowercaseUuid;
58
+ target_time_ms: number;
59
+ disposition: SourceTargetDisposition;
60
+ source_time_ms: number | null;
61
+ asof_age_ms: number | null;
62
+ record_sha256s: Sha256Hex[];
63
+ };
64
+ export type SourceInventoryInterval = {
65
+ start_time_ms: number;
66
+ end_time_ms_exclusive: number;
67
+ };
68
+ type SourceForensicsSummary = {
69
+ retained_record_count: number;
70
+ total_record_count: number;
71
+ omitted_record_count: number;
72
+ affected_target_count: number;
73
+ unresolved_record_count: number;
74
+ };
75
+ type SourceForensicsLedgerBase = {
76
+ schema_id: typeof SOURCE_FORENSICS_LEDGER_SCHEMA_ID;
77
+ ledger_sha256: Sha256Hex;
78
+ operation_kind: (typeof SOURCE_FORENSICS_OPERATION_KINDS)[number];
79
+ normalized_invocation_sha256: Sha256Hex;
80
+ request_id: LowercaseUuid;
81
+ scope: CanonicalScopeWire;
82
+ window: SourceInventoryInterval;
83
+ effective_policies: {
84
+ capability_policy: PolicyPin;
85
+ resource_policy: PolicyPin;
86
+ adapter_policy: PolicyPin;
87
+ acquisition_policy: PolicyPin;
88
+ };
89
+ provider_object_inventory: {
90
+ expected_identities: string[];
91
+ observed_identities: string[];
92
+ expected_selected_intervals: SourceInventoryInterval[];
93
+ observed_selected_intervals: SourceInventoryInterval[];
94
+ complete: boolean;
95
+ };
96
+ provider_objects: SourceObjectEvidence[];
97
+ records: SourceForensicsRecordWire[];
98
+ summary: SourceForensicsSummary;
99
+ limits: {
100
+ max_records: typeof SOURCE_FORENSICS_MAX_RECORDS;
101
+ max_canonical_json_bytes: typeof SOURCE_FORENSICS_MAX_CANONICAL_JSON_BYTES;
102
+ };
103
+ complete: boolean;
104
+ incomplete_reason: "forensics_evidence_bound_exceeded" | null;
105
+ };
106
+ export type RequiredClockSourceForensicsLedgerWire = SourceForensicsLedgerBase & {
107
+ operation_kind: "required_clock_qualification";
108
+ required_clock: {
109
+ clock_id: LowercaseUuid;
110
+ clock_sha256: Sha256Hex;
111
+ event_count: number;
112
+ };
113
+ target_dispositions: SourceTargetDispositionWire[];
114
+ summary: SourceForensicsSummary & {
115
+ disposition_complete: boolean;
116
+ fresh_target_count: number;
117
+ inactive_target_count: number;
118
+ disqualifying_target_count: number;
119
+ omitted_target_disposition_count: number;
120
+ };
121
+ };
122
+ export type SourceTapeForensicsLedgerWire = SourceForensicsLedgerBase & {
123
+ operation_kind: "source_tape";
124
+ source_tape: {
125
+ product_id: "market-data-source-tape";
126
+ product_version: "market-data-source-tape/v1";
127
+ state_count: number;
128
+ };
129
+ };
130
+ export type SourceForensicsLedgerWire = RequiredClockSourceForensicsLedgerWire | SourceTapeForensicsLedgerWire;
131
+ type SourceQualificationLedgerDescriptor = {
132
+ schema_id: typeof SOURCE_FORENSICS_LEDGER_SCHEMA_ID;
133
+ file_name: string;
134
+ sha256: Sha256Hex;
135
+ bytes: number;
136
+ retained_record_count: number;
137
+ total_record_count: number;
138
+ omitted_record_count: number;
139
+ complete: boolean;
140
+ };
141
+ type SourceQualificationRecordBase = {
142
+ schema_id: typeof SOURCE_QUALIFICATION_RECORD_SCHEMA_ID;
143
+ record_sha256: Sha256Hex;
144
+ created_at: string;
145
+ operation_kind: (typeof SOURCE_FORENSICS_OPERATION_KINDS)[number];
146
+ normalized_invocation_sha256: Sha256Hex;
147
+ request_id: LowercaseUuid;
148
+ scope: CanonicalScopeWire;
149
+ ledger: SourceQualificationLedgerDescriptor;
150
+ source_reconstruction_accepted: boolean;
151
+ source_event_enumeration_eligible: boolean;
152
+ };
153
+ export type RequiredClockSourceQualificationRecordWire = SourceQualificationRecordBase & {
154
+ operation_kind: "required_clock_qualification";
155
+ ledger: SourceQualificationLedgerDescriptor & {
156
+ disposition_complete: boolean;
157
+ fresh_target_count: number;
158
+ inactive_target_count: number;
159
+ disqualifying_target_count: number;
160
+ omitted_target_disposition_count: number;
161
+ };
162
+ qualified: boolean;
163
+ source_partition_complete: boolean;
164
+ outcome: {
165
+ status: "success";
166
+ reason: "required_clock_qualification_completed";
167
+ partial_evidence: SourceEvidenceDescriptor[];
168
+ exporter_result: null;
169
+ } | {
170
+ status: "failure";
171
+ reason: (typeof REQUIRED_CLOCK_QUALIFICATION_FAILURE_REASONS)[number];
172
+ partial_evidence: SourceEvidenceDescriptor[];
173
+ exporter_result: null;
174
+ };
175
+ };
176
+ export declare const REQUIRED_CLOCK_QUALIFICATION_FAILURE_REASONS: readonly ["required_clock_input_invalid", "required_clock_capability_unsupported", "required_clock_credentials_missing", "required_clock_acquisition_failed", "required_clock_reconstruction_failed", "required_clock_classification_failed", "required_clock_evidence_incomplete", "required_clock_internal_failure"];
177
+ export declare const SOURCE_TAPE_FAILURE_REASONS: readonly ["source_tape_input_invalid", "source_tape_capability_unsupported", "source_tape_credentials_missing", "source_tape_acquisition_failed", "source_tape_reconstruction_failed", "source_tape_inventory_incomplete", "source_tape_archive_failed", "source_tape_promotion_failed", "source_tape_selection_failed", "source_tape_export_failed", "source_tape_internal_failure"];
178
+ type SourceTapeQualificationSuccessOutcome = {
179
+ status: "success";
180
+ reason: "source_tape_prepared";
181
+ partial_evidence: SourceEvidenceDescriptor[];
182
+ exporter_result: SourceTapeExporterResultDescriptor;
183
+ };
184
+ type SourceTapeQualificationFailureOutcome = {
185
+ status: "failure";
186
+ reason: (typeof SOURCE_TAPE_FAILURE_REASONS)[number];
187
+ partial_evidence: SourceEvidenceDescriptor[];
188
+ exporter_result: null;
189
+ };
190
+ export type SourceTapeQualificationRecordWire = SourceQualificationRecordBase & {
191
+ operation_kind: "source_tape";
192
+ ledger: SourceQualificationLedgerDescriptor & {
193
+ state_count: number;
194
+ };
195
+ source_tape_eligible: boolean;
196
+ } & ({
197
+ initializer: SourceTapeInitializerDescriptor;
198
+ outcome: SourceTapeQualificationSuccessOutcome;
199
+ } | {
200
+ initializer: SourceTapeInitializerDescriptor | null;
201
+ outcome: SourceTapeQualificationFailureOutcome;
202
+ });
203
+ export type SourceTapeInitializerDescriptor = {
204
+ canonical_snapshot_id: Sha256Hex;
205
+ source_time_ms: number;
206
+ sequence: string;
207
+ semantic_stream_position: 0;
208
+ };
209
+ export type SourceEvidenceDescriptor = {
210
+ kind: "ledger" | "provider_inventory" | "selection" | "promotion_receipt" | "export_result";
211
+ file_name: string;
212
+ sha256: Sha256Hex;
213
+ bytes: number;
214
+ };
215
+ export type SourceTapeExporterResultDescriptor = {
216
+ schema_id: "https://schemas.usher.so/cex-canonical-orderbook-export-result/v2";
217
+ file_name: string;
218
+ sha256: Sha256Hex;
219
+ bytes: number;
220
+ result_sha256: Sha256Hex;
221
+ };
222
+ export type SourceQualificationRecordWire = RequiredClockSourceQualificationRecordWire | SourceTapeQualificationRecordWire;
223
+ export declare const sourceForensicsLedgerCodec: {
224
+ decode(value: unknown, context?: {
225
+ requiredClock: RequiredClockWire;
226
+ }): SourceForensicsLedgerWire;
227
+ };
228
+ export declare const sourceQualificationRecordCodec: {
229
+ decode(value: unknown): SourceQualificationRecordWire;
230
+ };
231
+ export declare function finalizeSourceForensicsLedger(content: Omit<RequiredClockSourceForensicsLedgerWire, "ledger_sha256"> | Omit<SourceTapeForensicsLedgerWire, "ledger_sha256">): SourceForensicsLedgerWire;
232
+ export declare function finalizeSourceQualificationRecord(content: Omit<RequiredClockSourceQualificationRecordWire, "record_sha256"> | Omit<SourceTapeQualificationRecordWire, "record_sha256">): SourceQualificationRecordWire;
233
+ export type ReconstructionObservation = {
234
+ type: "provider_object_boundary";
235
+ object: SourceObjectEvidence;
236
+ } | {
237
+ type: "snapshot_anchor" | "reanchor";
238
+ anchor: SourceAnchorEvidence;
239
+ } | {
240
+ type: "sequence_discontinuity";
241
+ sequence: NonNullable<SourceForensicsRecordWire["sequence"]>;
242
+ object: SourceObjectEvidence;
243
+ } | {
244
+ type: "required_clock_sample";
245
+ target_time_ms: number;
246
+ source_time_ms: number | null;
247
+ lag_ms: number | null;
248
+ status: "covered" | "unanchored" | "stale" | "future";
249
+ object: SourceObjectEvidence | null;
250
+ } | {
251
+ type: "invalidation";
252
+ event_time_ms: number;
253
+ reason: string;
254
+ } | {
255
+ type: "provider_object_checksum_conflict";
256
+ object: SourceObjectEvidence;
257
+ affected_target_times_ms: readonly number[];
258
+ };
259
+ export interface ReconstructionObservationSink {
260
+ observe(observation: ReconstructionObservation): void;
261
+ }
262
+ export declare const NOOP_RECONSTRUCTION_OBSERVER: ReconstructionObservationSink;
263
+ type LedgerContext = {
264
+ schema_id: typeof SOURCE_FORENSICS_LEDGER_SCHEMA_ID;
265
+ operation_kind?: "required_clock_qualification" | "source_tape";
266
+ normalized_invocation_sha256?: Sha256Hex;
267
+ idempotency_key?: Sha256Hex;
268
+ request_id: LowercaseUuid;
269
+ scope: CanonicalScopeWire;
270
+ window?: SourceInventoryInterval;
271
+ required_clock?: RequiredClockSourceForensicsLedgerWire["required_clock"];
272
+ source_tape?: SourceTapeForensicsLedgerWire["source_tape"];
273
+ effective_policies: SourceForensicsLedgerBase["effective_policies"];
274
+ adapter_version: string;
275
+ required_clock_targets?: readonly {
276
+ target_id: LowercaseUuid;
277
+ target_time_ms: number;
278
+ }[];
279
+ expected_provider_object_identities: readonly string[];
280
+ expected_selected_intervals?: readonly SourceInventoryInterval[];
281
+ redact_values?: ReadonlySet<string>;
282
+ };
283
+ /**
284
+ * Streaming qualification sink. It coalesces target intervals as observations
285
+ * arrive and never retains more derived records than the configured cap.
286
+ */
287
+ export declare class BoundedSourceForensicsSink implements ReconstructionObservationSink {
288
+ private readonly context;
289
+ private readonly testingLimits;
290
+ private readonly records;
291
+ private readonly providerObjects;
292
+ private readonly affectedTargets;
293
+ private readonly targetObservations;
294
+ private previousAnchor;
295
+ private pendingGapRecord;
296
+ private lastOmittedRecord;
297
+ private totalRecordCount;
298
+ private omittedRecordCount;
299
+ private sourceTapeStateCount;
300
+ constructor(context: LedgerContext, testingLimits?: {
301
+ maxRetainedRecords?: number;
302
+ maxCanonicalJsonBytes?: number;
303
+ });
304
+ setSourceTapeStateCount(stateCount: number): void;
305
+ observe(observation: ReconstructionObservation): void;
306
+ classifyRecord(selector: {
307
+ kind: SourceForensicsRecordKind;
308
+ target_time_ms: number;
309
+ object_identity: string;
310
+ }, classification: SourceForensicsClassification): void;
311
+ pendingClassificationRequests(): Array<{
312
+ record_key: string;
313
+ object_identities: string[];
314
+ }>;
315
+ applyRecordClassification(input: {
316
+ record_key: string;
317
+ classification: SourceForensicsClassification;
318
+ objects: SourceObjectEvidence[];
319
+ }): void;
320
+ private get retainedLimit();
321
+ private sanitize;
322
+ private retainObject;
323
+ private sanitizeAnchor;
324
+ private interval;
325
+ private markAffected;
326
+ private mergeAdjacent;
327
+ private append;
328
+ private accept;
329
+ finish(): SourceForensicsLedgerWire;
330
+ }
331
+ export declare function classifySourceObjectEvidence(input: {
332
+ checksums: readonly string[];
333
+ schemaValid: boolean;
334
+ sequenceValid: boolean;
335
+ missingRows: boolean;
336
+ completeSnapshotDefect: boolean;
337
+ alternateOrderingClosesGap: boolean;
338
+ staleWithValidPriorState: boolean;
339
+ }): SourceForensicsClassification;
340
+ export type SourceObjectInspection = {
341
+ checksum: Sha256Hex;
342
+ schemaValid: boolean;
343
+ sequenceValid: boolean;
344
+ missingRows: boolean;
345
+ completeSnapshotDefect: boolean;
346
+ alternateOrderingClosesGap: boolean;
347
+ staleWithValidPriorState: boolean;
348
+ };
349
+ /**
350
+ * Runs the qualification-only, bounded source inspection. The callback may
351
+ * inspect licensed bytes, but this return value deliberately retains only safe
352
+ * identities, checksums and closed predicates. It cannot repair reconstruction
353
+ * or make an interval acceptance-eligible.
354
+ */
355
+ export declare function classifyImplicatedSourceObjects(input: {
356
+ originalIdentity: string;
357
+ adjacentIdentities: readonly string[];
358
+ maxAttempts: number;
359
+ inspect(identity: string, attempt: number): SourceObjectInspection | Promise<SourceObjectInspection>;
360
+ }): Promise<{
361
+ classification: SourceForensicsClassification;
362
+ objects: SourceObjectEvidence[];
363
+ acceptanceEligible: false;
364
+ }>;
365
+ export declare function classifySourceForensicsRecordsDeduplicated(input: {
366
+ requests: readonly {
367
+ record_key: string;
368
+ object_identities: readonly string[];
369
+ }[];
370
+ maxAttempts: number;
371
+ inspect(identity: string, attempt: number): SourceObjectInspection | Promise<SourceObjectInspection>;
372
+ }): Promise<Array<{
373
+ record_key: string;
374
+ classification: SourceForensicsClassification;
375
+ objects: SourceObjectEvidence[];
376
+ }>>;
377
+ export declare function evaluateSourceQualificationGates(ledgerInput: SourceForensicsLedgerWire, sourceReconstructionAccepted: boolean): {
378
+ operation_kind: "required_clock_qualification";
379
+ qualified: boolean;
380
+ source_partition_complete: boolean;
381
+ source_event_enumeration_eligible: boolean;
382
+ } | {
383
+ operation_kind: "source_tape";
384
+ source_event_enumeration_eligible: boolean;
385
+ source_tape_eligible: boolean;
386
+ };
387
+ export declare function commitSourceQualificationEvidence(input: {
388
+ outputDirectory: string;
389
+ ledgerFileName: string;
390
+ qualificationFileName: string;
391
+ ledger: SourceForensicsLedgerWire;
392
+ createdAt: string;
393
+ sourceAccepted: boolean;
394
+ requiredClock?: RequiredClockWire;
395
+ requiredClockFailureReason?: (typeof REQUIRED_CLOCK_QUALIFICATION_FAILURE_REASONS)[number];
396
+ sourceTapeInitializer?: SourceTapeInitializerDescriptor;
397
+ sourceTapeOutcome?: SourceTapeQualificationRecordWire["outcome"];
398
+ cleanupLicensedPayloads?: () => void | Promise<void>;
399
+ }): Promise<SourceQualificationRecordWire>;
400
+ export {};
@@ -1,5 +1,5 @@
1
1
  export declare const CONFORMANCE_FIXTURES: Readonly<{
2
- fixture_id: "market-data-vendor-backfill-conformance/v1";
2
+ fixture_id: "market-data-vendor-backfill-conformance/v2";
3
3
  documents: {
4
4
  required_clock: import("./contracts").RequiredClockWire;
5
5
  archive_selection: import("./contracts").ArchiveSelectionWire;
@@ -45,18 +45,17 @@ export declare const CONFORMANCE_FIXTURES: Readonly<{
45
45
  };
46
46
  product_pins: {
47
47
  capability_policy: {
48
- policy_id: "market-data-vendor-backfill-capabilities/v1";
48
+ policy_id: "market-data-vendor-backfill-capabilities/v3";
49
49
  policy_sha256: string;
50
50
  };
51
51
  resource_policy: {
52
- policy_id: "market-data-vendor-backfill-resources/v1";
52
+ policy_id: "market-data-vendor-backfill-resources/v2";
53
53
  policy_sha256: string;
54
54
  };
55
55
  };
56
56
  production_authorization_id: string;
57
57
  };
58
58
  promotion_receipt: import("./contracts").PromotionReceiptWire;
59
- result: import("./contracts").BackfillJobResultWire;
60
59
  };
61
60
  identities: {
62
61
  idempotency_key: string;
@@ -65,7 +64,6 @@ export declare const CONFORMANCE_FIXTURES: Readonly<{
65
64
  selection_sha256: string;
66
65
  promotion_identity_sha256: string;
67
66
  receipt_id: string;
68
- result_sha256: string;
69
67
  capability_policy_sha256: string;
70
68
  resource_policy_sha256: string;
71
69
  };