@usherlabs/cex-broker 0.2.52 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. package/dist/commands/cli.js +364 -71
  2. package/dist/index.js +365 -72
  3. package/dist/index.js.map +14 -13
  4. package/package.json +5 -28
  5. package/dist/commands/cex-canonical-orderbook-export.d.ts +0 -23
  6. package/dist/commands/cex-canonical-orderbook-export.js +0 -34275
  7. package/dist/commands/cex-canonical-orderbook-export.js.map +0 -266
  8. package/dist/commands/market-data-vendor-backfill.d.ts +0 -24
  9. package/dist/commands/market-data-vendor-backfill.js +0 -34930
  10. package/dist/commands/market-data-vendor-backfill.js.map +0 -268
  11. package/dist/handlers/execute-action/context.d.ts +0 -50
  12. package/dist/handlers/execute-action/deposit.d.ts +0 -2
  13. package/dist/handlers/execute-action/handler.d.ts +0 -19
  14. package/dist/handlers/execute-action/index.d.ts +0 -10
  15. package/dist/handlers/execute-action/internal-transfer.d.ts +0 -2
  16. package/dist/handlers/execute-action/order-book-call.d.ts +0 -3
  17. package/dist/handlers/execute-action/orders.d.ts +0 -2
  18. package/dist/handlers/execute-action/pass-through.d.ts +0 -2
  19. package/dist/handlers/execute-action/perp-config.d.ts +0 -2
  20. package/dist/handlers/execute-action/registry.d.ts +0 -5
  21. package/dist/handlers/execute-action/treasury-call.d.ts +0 -2
  22. package/dist/handlers/execute-action/withdraw.d.ts +0 -2
  23. package/dist/handlers/subscribe/broker-lifecycle.d.ts +0 -13
  24. package/dist/handlers/subscribe/handler.d.ts +0 -20
  25. package/dist/handlers/subscribe/index.d.ts +0 -2
  26. package/dist/handlers/types.d.ts +0 -23
  27. package/dist/helpers/account-balance-archive-poller.d.ts +0 -19
  28. package/dist/helpers/auth.d.ts +0 -5
  29. package/dist/helpers/balance-update-archive-consumer.d.ts +0 -16
  30. package/dist/helpers/binance-user-data-normalization.d.ts +0 -3
  31. package/dist/helpers/binance-user-data-stream.d.ts +0 -58
  32. package/dist/helpers/broker-execution-archive/capture.d.ts +0 -41
  33. package/dist/helpers/broker-execution-archive/index.d.ts +0 -7
  34. package/dist/helpers/broker-execution-archive/journal-export.d.ts +0 -20
  35. package/dist/helpers/broker-execution-archive/loss-journal.d.ts +0 -36
  36. package/dist/helpers/broker-execution-archive/redact.d.ts +0 -7
  37. package/dist/helpers/broker-execution-archive/rows.d.ts +0 -134
  38. package/dist/helpers/broker-execution-archive/types.d.ts +0 -26
  39. package/dist/helpers/broker-execution-archive/withdrawal-observation-tracker.d.ts +0 -23
  40. package/dist/helpers/broker-execution-archive/writer.d.ts +0 -105
  41. package/dist/helpers/broker.d.ts +0 -38
  42. package/dist/helpers/canonical-orderbook-export/exact-selection.d.ts +0 -21
  43. package/dist/helpers/canonical-orderbook-export/exporter.d.ts +0 -26
  44. package/dist/helpers/canonical-orderbook-export/parquet-projection.d.ts +0 -19
  45. package/dist/helpers/constants.d.ts +0 -36
  46. package/dist/helpers/deposit-archive-poller.d.ts +0 -66
  47. package/dist/helpers/deposit.d.ts +0 -5
  48. package/dist/helpers/exchange-credentials.d.ts +0 -10
  49. package/dist/helpers/fill-archive-poller.d.ts +0 -42
  50. package/dist/helpers/grpc/broker.d.ts +0 -5
  51. package/dist/helpers/grpc/callbacks.d.ts +0 -9
  52. package/dist/helpers/grpc/payload.d.ts +0 -9
  53. package/dist/helpers/grpc/status.d.ts +0 -8
  54. package/dist/helpers/index.d.ts +0 -44
  55. package/dist/helpers/logger.d.ts +0 -13
  56. package/dist/helpers/market-data-archive/canonical-orderbook.d.ts +0 -20
  57. package/dist/helpers/market-data-archive/capture-context.d.ts +0 -53
  58. package/dist/helpers/market-data-archive/capture-contract.d.ts +0 -30
  59. package/dist/helpers/market-data-archive/capture.d.ts +0 -22
  60. package/dist/helpers/market-data-archive/index.d.ts +0 -13
  61. package/dist/helpers/market-data-archive/legacy-migration.d.ts +0 -37
  62. package/dist/helpers/market-data-archive/ohlcv-bar-tracker.d.ts +0 -11
  63. package/dist/helpers/market-data-archive/ohlcv-bootstrap.d.ts +0 -1
  64. package/dist/helpers/market-data-archive/ohlcv-history.d.ts +0 -8
  65. package/dist/helpers/market-data-archive/orderbook-depth.d.ts +0 -5
  66. package/dist/helpers/market-data-archive/orderbook-sampler.d.ts +0 -12
  67. package/dist/helpers/market-data-archive/parse-stream.d.ts +0 -26
  68. package/dist/helpers/market-data-archive/rows.d.ts +0 -14
  69. package/dist/helpers/market-data-archive/types.d.ts +0 -83
  70. package/dist/helpers/market-data-preparation/conformance-fixtures.d.ts +0 -128
  71. package/dist/helpers/market-data-preparation/contracts.d.ts +0 -2970
  72. package/dist/helpers/market-data-preparation/file-job.d.ts +0 -38
  73. package/dist/helpers/market-data-preparation/required-clock-qualification.d.ts +0 -43
  74. package/dist/helpers/market-data-preparation/source-tape-dependencies.d.ts +0 -19
  75. package/dist/helpers/market-data-preparation/source-tape-operation.d.ts +0 -109
  76. package/dist/helpers/market-data-source-forensics.d.ts +0 -400
  77. package/dist/helpers/market-data-vendor-backfill/archive-reader.d.ts +0 -26
  78. package/dist/helpers/market-data-vendor-backfill/batching.d.ts +0 -10
  79. package/dist/helpers/market-data-vendor-backfill/conformance-fixtures.d.ts +0 -78
  80. package/dist/helpers/market-data-vendor-backfill/contracts.d.ts +0 -358
  81. package/dist/helpers/market-data-vendor-backfill/core.d.ts +0 -101
  82. package/dist/helpers/market-data-vendor-backfill/cryptohftdata.d.ts +0 -118
  83. package/dist/helpers/market-data-vendor-backfill/forwarder-client.d.ts +0 -25
  84. package/dist/helpers/market-data-vendor-backfill/identity.d.ts +0 -10
  85. package/dist/helpers/market-data-vendor-backfill/manifests.d.ts +0 -61
  86. package/dist/helpers/market-data-vendor-backfill/promotion.d.ts +0 -10
  87. package/dist/helpers/market-data-vendor-backfill/qualification.d.ts +0 -20
  88. package/dist/helpers/market-data-vendor-backfill/selection.d.ts +0 -30
  89. package/dist/helpers/market-data-vendor-backfill/semantic-verification.d.ts +0 -25
  90. package/dist/helpers/market-type.d.ts +0 -16
  91. package/dist/helpers/order-activity-tracker.d.ts +0 -22
  92. package/dist/helpers/order-book.d.ts +0 -79
  93. package/dist/helpers/order-telemetry.d.ts +0 -50
  94. package/dist/helpers/otel.d.ts +0 -83
  95. package/dist/helpers/passive-order.d.ts +0 -8
  96. package/dist/helpers/public-market-data-feed/identity.d.ts +0 -12
  97. package/dist/helpers/public-market-data-feed/index.d.ts +0 -5
  98. package/dist/helpers/public-market-data-feed/orderbook-coalescing-evidence.d.ts +0 -79
  99. package/dist/helpers/public-market-data-feed/orderbook-profile.d.ts +0 -54
  100. package/dist/helpers/public-market-data-feed/subscriber-buffer.d.ts +0 -31
  101. package/dist/helpers/public-market-data-feed/supervisor.d.ts +0 -82
  102. package/dist/helpers/shared/errors.d.ts +0 -14
  103. package/dist/helpers/shared/guards.d.ts +0 -2
  104. package/dist/helpers/source-tape-sandbox.d.ts +0 -82
  105. package/dist/helpers/source-tape.d.ts +0 -165
  106. package/dist/helpers/stream-health-publisher.d.ts +0 -41
  107. package/dist/helpers/trace-context.d.ts +0 -8
  108. package/dist/helpers/transfer-network.d.ts +0 -12
  109. package/dist/helpers/travel-rule-deposit-reconciler.d.ts +0 -159
  110. package/dist/helpers/travel-rule.d.ts +0 -75
  111. package/dist/helpers/treasury-discovery.d.ts +0 -17
  112. package/dist/helpers/user-asset-archive-poller.d.ts +0 -19
  113. package/dist/helpers/user-data-stream-supervisor.d.ts +0 -27
  114. package/dist/helpers/verity.d.ts +0 -5
  115. package/dist/index.d.ts +0 -56
  116. package/dist/market-data-preparation/fixtures/conformance-v3.json +0 -621
  117. package/dist/market-data-preparation/policies/capability-policy.json +0 -39
  118. package/dist/market-data-preparation/policies/resource-policy.json +0 -16
  119. package/dist/market-data-preparation/policies/source-tape-capability-v1.json +0 -35
  120. package/dist/market-data-preparation/schema-manifest.json +0 -66
  121. package/dist/market-data-preparation/schemas/archive-selection-v1.schema.json +0 -224
  122. package/dist/market-data-preparation/schemas/backfill-request-v1.schema.json +0 -166
  123. package/dist/market-data-preparation/schemas/backfill-result-v2.schema.json +0 -212
  124. package/dist/market-data-preparation/schemas/canonical-orderbook-export-request-v1.schema.json +0 -61
  125. package/dist/market-data-preparation/schemas/canonical-orderbook-export-result-v2.schema.json +0 -252
  126. package/dist/market-data-preparation/schemas/order-book-depth-summary-parquet-projection-v1.schema.json +0 -256
  127. package/dist/market-data-preparation/schemas/order-book-levels-parquet-projection-v1.schema.json +0 -220
  128. package/dist/market-data-preparation/schemas/preparation-product-pin-v2.schema.json +0 -176
  129. package/dist/market-data-preparation/schemas/promotion-receipt-v1.schema.json +0 -175
  130. package/dist/market-data-preparation/schemas/required-clock-v1.schema.json +0 -47
  131. package/dist/market-data-preparation/schemas/source-forensics-ledger-v1.schema.json +0 -463
  132. package/dist/market-data-preparation/schemas/source-qualification-record-v1.schema.json +0 -394
  133. package/dist/market-data-preparation.d.ts +0 -11
  134. package/dist/market-data-preparation.js +0 -37488
  135. package/dist/market-data-preparation.js.map +0 -277
  136. package/dist/market-data-vendor-backfill.d.ts +0 -21
  137. package/dist/market-data-vendor-backfill.js +0 -22463
  138. package/dist/market-data-vendor-backfill.js.map +0 -199
  139. package/dist/proto/node.descriptor.d.ts +0 -127
  140. package/dist/proto-loader-options.d.ts +0 -7
  141. package/dist/proto-package-definition.d.ts +0 -2
  142. package/dist/schemas/action-payloads.d.ts +0 -88
  143. package/dist/server.d.ts +0 -10
  144. package/dist/types.d.ts +0 -100
@@ -1,82 +0,0 @@
1
- import type { Metadata } from "@grpc/grpc-js";
2
- import type { Exchange } from "@usherlabs/ccxt";
3
- import { type BrokerPoolEntry } from "../broker";
4
- import type { BrokerExecutionArchiver } from "../broker-execution-archive";
5
- import { type OhlcvArchiveInput, type OhlcvBarTracker, type OrderbookArchiveInput, type TickerArchiveInput, type TradesArchiveInput } from "../market-data-archive";
6
- import { type BrokerMarketType } from "../market-type";
7
- import type { OtelMetrics } from "../otel";
8
- import { type PublicFeedName } from "./identity";
9
- import { type OrderBookAcquisitionProfile, type OrderBookAcquisitionProfileInput } from "./orderbook-profile";
10
- import { type PublicFeedFrame, type PublicFeedSubscriberBufferOptions } from "./subscriber-buffer";
11
- export type PublicFeedArchiveContext = {
12
- deploymentId: string;
13
- exchange: string;
14
- symbol: string;
15
- assetType: BrokerMarketType;
16
- accountSelector?: string;
17
- };
18
- export interface PublicMarketDataArchiveSink {
19
- orderbook(input: OrderbookArchiveInput, options: {
20
- sampledOut: boolean;
21
- }): void;
22
- ticker(input: TickerArchiveInput): void;
23
- trades(input: TradesArchiveInput): void;
24
- ohlcv(tracker: OhlcvBarTracker, input: OhlcvArchiveInput): void;
25
- ohlcvBootstrap(tracker: OhlcvBarTracker, input: OhlcvArchiveInput): void;
26
- }
27
- type Metrics = Pick<OtelMetrics, "recordCounter"> & Partial<Pick<OtelMetrics, "recordGauge">>;
28
- export type PublicMarketDataFeedSupervisorOptions = {
29
- brokers: Record<string, BrokerPoolEntry>;
30
- brokerArchiver?: BrokerExecutionArchiver;
31
- otelMetrics?: OtelMetrics;
32
- archiveSink?: PublicMarketDataArchiveSink;
33
- metrics?: Metrics;
34
- bufferLimits?: PublicFeedSubscriberBufferOptions;
35
- retirementTimeoutMs?: number;
36
- createRequestBroker?: (exchange: string, metadata: Metadata | undefined) => Exchange | null;
37
- createPublicBroker?: (exchange: string) => Exchange | null;
38
- resolveOrderBookProfile?: (input: OrderBookAcquisitionProfileInput) => OrderBookAcquisitionProfile;
39
- enabledOrderBookProfileIds?: ReadonlySet<string>;
40
- observer?: PublicMarketDataFeedObserver;
41
- };
42
- export type PublicFeedObservation = {
43
- key: string;
44
- exchange: string;
45
- feed: PublicFeedName;
46
- marketType: BrokerMarketType;
47
- profile?: string;
48
- subscriberCount: number;
49
- };
50
- export interface PublicMarketDataFeedObserver {
51
- workerStarted?(observation: PublicFeedObservation): void;
52
- subscriberAttached?(observation: PublicFeedObservation): void;
53
- physicalFrame?(observation: PublicFeedObservation): void;
54
- archiveDecision?(observation: PublicFeedObservation): void;
55
- delivered?(observation: PublicFeedObservation): void;
56
- overflow?(observation: PublicFeedObservation): void;
57
- workerRetired?(observation: PublicFeedObservation): void;
58
- }
59
- export type PublicFeedSubscribeOptions = {
60
- exchange: string;
61
- symbol: string;
62
- marketType?: string;
63
- feed: PublicFeedName;
64
- depthLimit?: number;
65
- timeframe?: string;
66
- bootstrapLimit?: number;
67
- metadata?: Metadata;
68
- };
69
- export interface PublicMarketDataSubscription extends AsyncIterable<PublicFeedFrame> {
70
- readonly key: string;
71
- readonly acquisitionProfileId?: string;
72
- close(): void;
73
- }
74
- /** Owns one physical public CCXT watch/archive path per canonical runtime key. */
75
- export declare class PublicMarketDataFeedSupervisor {
76
- #private;
77
- private readonly options;
78
- constructor(options: PublicMarketDataFeedSupervisorOptions);
79
- subscribe(input: PublicFeedSubscribeOptions): Promise<PublicMarketDataSubscription>;
80
- close(): Promise<void>;
81
- }
82
- export {};
@@ -1,14 +0,0 @@
1
- export declare const REDACTED_ERROR_MESSAGE = "redacted_error";
2
- export declare function getErrorMessage(error: unknown): string;
3
- /** Constructor/class name of a caught error (ccxt classes like InsufficientFunds,
4
- * BadSymbol, OrderNotFound carry the actionable signal). The generic `Error` name
5
- * adds nothing, so it is dropped; returns undefined for non-Error values. */
6
- export declare function errorClassName(error: unknown): string | undefined;
7
- /** Sanitized, single-line, length-capped detail for a caught error: the venue
8
- * error class, optional primitive code, and message. It never includes a stack
9
- * or attached payload. */
10
- export declare function sanitizeErrorDetail(error: unknown, options?: {
11
- includeCode?: boolean;
12
- }): string;
13
- export declare function safeLogError(context: string, error: unknown): void;
14
- export declare function safeLogRedactedError(context: string, error: unknown): void;
@@ -1,2 +0,0 @@
1
- export declare function isRecord(value: unknown): value is Record<string, unknown>;
2
- export declare function asRecord<T extends Record<string, unknown> = Record<string, unknown>>(value: unknown): T | undefined;
@@ -1,82 +0,0 @@
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>;
@@ -1,165 +0,0 @@
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[];
@@ -1,41 +0,0 @@
1
- export type StreamHealthState = "connecting" | "connected" | "disconnected" | "error";
2
- export type StreamHealthFailureKind = "none" | "auth_failed" | "transport_error" | "remote_closed" | "protocol_error" | "backpressure" | "unsupported_connector" | "shutdown";
3
- export type StreamHealthSnapshot = {
4
- exchange: string;
5
- accountSelector: string;
6
- accountRole?: string;
7
- streamKind: "user_data";
8
- accountScope: "spot";
9
- registryStatus: "active" | "retired";
10
- retiredAt: string | null;
11
- state: StreamHealthState;
12
- stateChangedAt: string;
13
- lastConnectedAt: string | null;
14
- lastAuthenticatedAt: string | null;
15
- lastReceivedAt: string | null;
16
- connectAttemptCount: string;
17
- reconnectCount: string;
18
- errorCount: string;
19
- lastFailureKind: StreamHealthFailureKind;
20
- lastFailureReason: string;
21
- trafficMode: "event_driven" | "continuous" | "unknown";
22
- sourceWatermark: string | null;
23
- };
24
- export type StreamHealthPublisherOptions = {
25
- deploymentId: string;
26
- statePath: string;
27
- forwarderUrl: string;
28
- forwarderAuthToken?: string;
29
- heartbeatIntervalMs?: number;
30
- forwarderTimeoutMs?: number;
31
- post?: (body: string) => Promise<void>;
32
- };
33
- /** A whole health batch is persisted before POST so retries are exact replays. */
34
- export declare class StreamHealthPublisher {
35
- #private;
36
- constructor(options: StreamHealthPublisherOptions);
37
- start(): void;
38
- publish(snapshots: readonly StreamHealthSnapshot[]): void;
39
- close(snapshots: readonly StreamHealthSnapshot[], timeoutMs?: number): Promise<void>;
40
- }
41
- export declare function streamHealthPublisherConfigFromEnv(env?: NodeJS.ProcessEnv): StreamHealthPublisherOptions;
@@ -1,8 +0,0 @@
1
- import type { Metadata } from "@grpc/grpc-js";
2
- /** gRPC metadata key for lightweight operational correlation with callers. */
3
- export declare const TRACE_METADATA_KEY = "x-trace-id";
4
- /**
5
- * Returns a validated caller correlation ID without mutating inbound metadata.
6
- * Invalid values are deliberately discarded before they can reach telemetry.
7
- */
8
- export declare function extractTraceId(metadata: Metadata): string | undefined;
@@ -1,12 +0,0 @@
1
- import type { Exchange } from "@usherlabs/ccxt";
2
- export type TransferNetworkResolution = {
3
- operatorAlias: string;
4
- brokerNetworkId: string;
5
- exchangeNetworkId: string;
6
- networkKey: string | null;
7
- };
8
- export declare function buildTransferNetworkEvidence(currencyInfo: Record<string, unknown>): {
9
- networks: Record<string, unknown>;
10
- aliases: Record<string, TransferNetworkResolution>;
11
- };
12
- export declare function resolveTransferNetwork(broker: Exchange, assetCode: string, operatorAlias: string): Promise<TransferNetworkResolution>;
@@ -1,159 +0,0 @@
1
- import type { PolicyConfig, TravelRuleDepositConfig, TravelRuleDepositQuestionnaire } from "../types";
2
- import type { BrokerPoolEntry } from "./broker";
3
- import type { OtelMetrics } from "./otel";
4
- /**
5
- * Auto-clear reconciler for Binance travel-rule-frozen DEPOSITS.
6
- *
7
- * Under the AUSTRAC travel rule Binance credits an inbound deposit but holds it
8
- * in `getUserAsset.freeze` (invisible to free+locked balances) until a per-deposit
9
- * questionnaire is answered. This reconciler polls `localentity/deposit/history`
10
- * for such frozen deposits and submits the questionnaire — but only for deposits
11
- * whose on-chain sender is PROVEN (via `eth_getTransactionByHash`) to be one of
12
- * our configured originator wallets. Everything else is left frozen and surfaced.
13
- *
14
- * Compliance invariant: a deposit is NEVER auto-declared unless its origin is
15
- * proven ours. Undeclared origin, unresolvable sender, entity drift, or any
16
- * uncertainty all fail closed (skip + surface), never "declare anyway".
17
- *
18
- * This runs entirely broker-internal (not through the gRPC verity path), so
19
- * provide-info carries no verity proof — acceptable for a compliance attestation
20
- * that is not a trading action; see the plan's edge-case notes.
21
- */
22
- export type LocalEntityDeposit = {
23
- tranId: string;
24
- coin: string;
25
- amount: string;
26
- network: string;
27
- txId: string;
28
- travelRuleStatus: string;
29
- requireQuestionnaire: boolean;
30
- raw: Record<string, unknown>;
31
- };
32
- /**
33
- * Parses one raw `localentity/deposit/history` row. Returns null when the row
34
- * lacks a tranId (the only id valid for provide-info — the `capital/deposit/hisrec`
35
- * id is a different id space and yields "Deposit request not found").
36
- */
37
- export declare function parseLocalEntityDeposit(raw: Record<string, unknown>): LocalEntityDeposit | null;
38
- /**
39
- * Resolves the on-chain sender (`tx.from`) of a deposit's transaction hash via a
40
- * JSON-RPC `eth_getTransactionByHash`. Returns the lowercased sender, or null
41
- * when the hash is not a well-formed EVM tx hash or the tx is not found (pruned
42
- * node / reorg / not yet mined) — both of which mean the origin is UNPROVEN and
43
- * the caller must skip rather than assume.
44
- *
45
- * `tx.from` is the EOA that signed the deposit transaction. For our funding
46
- * churn (owner wallet → Binance via a direct ERC20 transfer) that equals the
47
- * token originator. A transfer routed through a contract could differ; hardening
48
- * to the ERC20 Transfer event's `from` is possible later if that case arises.
49
- *
50
- * Uses `node:https` rather than the global `fetch`: inside the Gramine SGX
51
- * enclave undici (which backs global fetch) fails to establish outbound
52
- * connections — the same failure mode as the enclave's dead Binance user-data
53
- * WebSocket — while the ccxt HTTP path (node http/https) works. Using node's
54
- * request keeps this on the transport that is proven to work in the enclave.
55
- */
56
- export declare function resolveOnChainSender(rpcUrl: string, txHash: string, timeoutMs?: number): Promise<string | null>;
57
- /** Binance rate-limit signals (-1003 / HTTP 429 / DDoS guard). */
58
- export declare function isRateLimitError(error: unknown): boolean;
59
- /**
60
- * A provide-info call that Binance treats as already-satisfied. Re-submitting a
61
- * tranId that was already provided (a manual release, or a reconciler restart)
62
- * must be idempotent, so these responses/errors count as success.
63
- */
64
- export declare function isAlreadyProvidedError(error: unknown): boolean;
65
- export type ReconcilerAccountState = {
66
- submittedTranIds: Set<string>;
67
- surfacedFailed: Set<string>;
68
- backoffUntil: Map<string, number>;
69
- rateLimitedUntil: number;
70
- };
71
- export declare function createAccountState(): ReconcilerAccountState;
72
- export type ReconcileOutcome = {
73
- kind: "submitted";
74
- deposit: LocalEntityDeposit;
75
- sender: string;
76
- } | {
77
- kind: "already-provided";
78
- deposit: LocalEntityDeposit;
79
- sender: string;
80
- } | {
81
- kind: "undeclared-origin";
82
- deposit: LocalEntityDeposit;
83
- sender: string;
84
- } | {
85
- kind: "unproven-origin";
86
- deposit: LocalEntityDeposit;
87
- error?: string;
88
- } | {
89
- kind: "entity-drift";
90
- deposit: LocalEntityDeposit;
91
- country: string | null;
92
- } | {
93
- kind: "failed-terminal";
94
- deposit: LocalEntityDeposit;
95
- } | {
96
- kind: "submit-error";
97
- deposit: LocalEntityDeposit;
98
- error: string;
99
- } | {
100
- kind: "poll-error";
101
- error: string;
102
- };
103
- export type ReconcileAccountReport = {
104
- accountLabel: string;
105
- frozenDeposits: LocalEntityDeposit[];
106
- outcomes: ReconcileOutcome[];
107
- hadActionableWork: boolean;
108
- };
109
- export type ReconcileAccountDeps = {
110
- accountLabel: string;
111
- depositConfig: TravelRuleDepositConfig;
112
- expectedCountry: string;
113
- failureBackoffMs: number;
114
- rateLimitCooldownMs: number;
115
- now: number;
116
- state: ReconcilerAccountState;
117
- fetchDepositHistory: () => Promise<Array<Record<string, unknown>>>;
118
- fetchQuestionnaireCountry: () => Promise<string | null>;
119
- resolveSender: (network: string, txId: string) => Promise<string | null>;
120
- submitProvideInfo: (tranId: string, questionnaire: TravelRuleDepositQuestionnaire) => Promise<Record<string, unknown>>;
121
- resolveQuestionnaire: (config: TravelRuleDepositConfig, sender: string) => TravelRuleDepositQuestionnaire | null;
122
- };
123
- /**
124
- * Reconciles a single account once. Pure orchestration: all I/O is injected so
125
- * the compliance invariants (never submit an unproven/undeclared/entity-drifted
126
- * deposit) are unit-testable without a network. Fetch/poll errors are captured
127
- * as outcomes rather than thrown so one bad account never stalls the loop.
128
- */
129
- export declare function reconcileAccountOnce(deps: ReconcileAccountDeps): Promise<ReconcileAccountReport>;
130
- export type TravelRuleDepositReconcilerConfig = {
131
- rpcUrlsByNetwork: Record<string, string>;
132
- pollIntervalActiveMs: number;
133
- pollIntervalIdleMs: number;
134
- expectedQuestionnaireCountry: string;
135
- failureBackoffMs: number;
136
- rateLimitCooldownMs: number;
137
- };
138
- /**
139
- * Builds reconciler config from the environment. RPC URLs are read from
140
- * `TRAVEL_RULE_RPC_URL_<NETWORK>` vars (network suffix must match Binance's
141
- * network code, e.g. `TRAVEL_RULE_RPC_URL_ARBITRUM`). These are intentionally NOT
142
- * `CEX_BROKER_`-prefixed so the credential env scan ignores them. Cadence and the
143
- * expected questionnaire country are overridable but default to the AU rollout.
144
- */
145
- export declare function loadTravelRuleDepositReconcilerConfigFromEnv(env: Record<string, string | undefined>): TravelRuleDepositReconcilerConfig;
146
- export declare class TravelRuleDepositReconciler {
147
- #private;
148
- private readonly params;
149
- constructor(params: {
150
- policy: PolicyConfig;
151
- brokers: Record<string, BrokerPoolEntry>;
152
- config: TravelRuleDepositReconcilerConfig;
153
- metrics?: OtelMetrics;
154
- });
155
- /** True when at least one exchange has deposit auto-clear enabled in policy. */
156
- static hasEnabledExchange(policy: PolicyConfig): boolean;
157
- start(): void;
158
- stop(): void;
159
- }
@@ -1,75 +0,0 @@
1
- import type { Exchange } from "@usherlabs/ccxt";
2
- import Joi from "joi";
3
- import type { PolicyConfig, TravelRuleDepositConfig, TravelRuleDepositQuestionnaire, TravelRuleQuestionnaire } from "../types";
4
- export declare const australiaQuestionnaireSchema: Joi.ObjectSchema<any>;
5
- export type TravelRuleDecision = {
6
- mode: "standard";
7
- } | {
8
- mode: "localentity";
9
- questionnaire: TravelRuleQuestionnaire;
10
- } | {
11
- mode: "denied";
12
- error: string;
13
- };
14
- /**
15
- * Decides whether a withdrawal must use Binance's travel-rule endpoint.
16
- *
17
- * Travel rule is opt-in per exchange via the `enabled` flag, so a non-AU account
18
- * keeps using the standard endpoint. When enabled, the destination address must
19
- * have a configured questionnaire; if it does not we fail closed rather than fall
20
- * back to the standard endpoint (which would just reproduce the -4104 rejection).
21
- */
22
- export declare function resolveTravelRuleDecision(policy: PolicyConfig, exchange: string, recipientAddress: string): TravelRuleDecision;
23
- /**
24
- * Registers Binance's `localentity/withdraw/apply` endpoint on the exchange
25
- * instance. No-op for non-Binance exchanges. Idempotent — ccxt just reassigns
26
- * the generated implicit method if called again.
27
- */
28
- export declare function registerBinanceTravelRuleWithdrawEndpoint(exchange: Exchange): void;
29
- export declare const australiaDepositQuestionnaireSchema: Joi.ObjectSchema<any>;
30
- /**
31
- * Returns the enabled deposit travel-rule config for an exchange, or null when
32
- * the feature is absent or disabled. Gated solely by `deposits.enabled` (not the
33
- * entry's withdraw `enabled` flag): when null the reconciler does nothing for the
34
- * exchange, preserving exact pre-feature behavior.
35
- */
36
- export declare function getEnabledTravelRuleDepositConfig(policy: PolicyConfig, exchange: string): TravelRuleDepositConfig | null;
37
- /**
38
- * Looks up the questionnaire for a PROVEN on-chain sender. Matching is
39
- * case-insensitive. Returns null when the sender is not a declared originator —
40
- * the reconciler must then leave the deposit frozen and surface an anomaly
41
- * rather than attest an origin it cannot prove is ours.
42
- */
43
- export declare function resolveDepositOriginatorQuestionnaire(config: TravelRuleDepositConfig, senderAddress: string): TravelRuleDepositQuestionnaire | null;
44
- /**
45
- * Registers Binance's localentity deposit endpoints used by the reconciler:
46
- * the two read endpoints (deposit history + questionnaire requirements) and the
47
- * provide-info write. No-op for non-Binance exchanges. Idempotent.
48
- *
49
- * `localentity/deposit/provide-info` must be signed with the questionnaire JSON
50
- * RAW (unencoded) — see the @usherlabs/ccxt patch (`binance.sign` rawencode
51
- * branch). Signing it url-encoded yields Binance error -1022. The two GETs carry
52
- * only simple params and sign fine either way.
53
- *
54
- * provide-info is a 600-weight UID-limited write (same class as
55
- * capital/withdraw/apply), so it carries ccxt-binance's `4.0002` cost encoding
56
- * (`.0002` = charge the UID limiter) rather than a naive `1`, which would
57
- * under-throttle the write and invite -1003 once attestation is active.
58
- */
59
- export declare function registerBinanceTravelRuleDepositEndpoints(exchange: Exchange): void;
60
- type LocalEntityWithdrawArgs = {
61
- code: string;
62
- amount: number;
63
- address: string;
64
- network: string;
65
- questionnaire: TravelRuleQuestionnaire;
66
- params?: Record<string, string | number>;
67
- };
68
- /**
69
- * Mirrors ccxt's `binance.withdraw` currency/network/precision handling, but
70
- * targets the travel-rule endpoint and attaches the questionnaire. ccxt's
71
- * `urlencode` applies `encodeURIComponent` to the value, satisfying Binance's
72
- * requirement that the questionnaire JSON be URL-encoded in the request body.
73
- */
74
- export declare function withdrawViaLocalEntity(broker: Exchange, args: LocalEntityWithdrawArgs): Promise<import("@usherlabs/ccxt").Transaction>;
75
- export {};
@@ -1,17 +0,0 @@
1
- import type { Exchange } from "@usherlabs/ccxt";
2
- export type ExchangeWithDiscovery = Exchange & {
3
- has?: Record<string, unknown>;
4
- markets?: Record<string, unknown>;
5
- currencies?: Record<string, unknown>;
6
- fetchMarkets?: (...args: unknown[]) => Promise<unknown>;
7
- fetchCurrencies?: (...args: unknown[]) => Promise<Record<string, unknown>>;
8
- fetchDeposits?: (code?: string, since?: number, limit?: number, params?: Record<string, unknown>) => Promise<Array<Record<string, unknown>>>;
9
- };
10
- export declare function callArgs(args: unknown[] | undefined, params: Record<string, unknown> | undefined): unknown[];
11
- export declare function handleTreasuryDiscoveryCall(broker: Exchange, functionName: string, args: unknown[], params: Record<string, unknown>): Promise<{
12
- handled: true;
13
- result: unknown;
14
- } | {
15
- handled: false;
16
- }>;
17
- export declare function fetchCurrencyMetadata(broker: Exchange, assetCode: string): Promise<Record<string, unknown> | undefined>;