@secondlayer/shared 7.8.0 → 7.10.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 (52) hide show
  1. package/dist/src/archive/derived-stage-report.d.ts +99 -0
  2. package/dist/src/archive/derived-stage-report.js +64 -0
  3. package/dist/src/archive/derived-stage-report.js.map +10 -0
  4. package/dist/src/archive/disk-guard.d.ts +46 -0
  5. package/dist/src/archive/disk-guard.js +69 -0
  6. package/dist/src/archive/disk-guard.js.map +10 -0
  7. package/dist/src/archive/per-height-digest.d.ts +99 -0
  8. package/dist/src/archive/per-height-digest.js +194 -0
  9. package/dist/src/archive/per-height-digest.js.map +11 -0
  10. package/dist/src/archive/range-digest.d.ts +96 -0
  11. package/dist/src/archive/semantic-digest-builder.d.ts +1183 -0
  12. package/dist/src/archive/semantic-digest-builder.js +302 -0
  13. package/dist/src/archive/semantic-digest-builder.js.map +11 -0
  14. package/dist/src/archive/semantic-digest.d.ts +131 -0
  15. package/dist/src/archive/semantic-digest.js +143 -0
  16. package/dist/src/archive/semantic-digest.js.map +10 -0
  17. package/dist/src/coverage/index.d.ts +1670 -0
  18. package/dist/src/coverage/index.js +1483 -0
  19. package/dist/src/coverage/index.js.map +23 -0
  20. package/dist/src/db/index.d.ts +105 -1
  21. package/dist/src/db/index.js +31 -1
  22. package/dist/src/db/index.js.map +6 -5
  23. package/dist/src/db/queries/chain-reorgs.d.ts +96 -0
  24. package/dist/src/db/queries/chain-reorgs.js +30 -1
  25. package/dist/src/db/queries/chain-reorgs.js.map +6 -5
  26. package/dist/src/db/queries/contracts.d.ts +96 -0
  27. package/dist/src/db/queries/instance.d.ts +1127 -0
  28. package/dist/src/db/queries/instance.js +92 -0
  29. package/dist/src/db/queries/instance.js.map +10 -0
  30. package/dist/src/db/queries/integrity.d.ts +96 -0
  31. package/dist/src/db/queries/subgraph-gaps.d.ts +96 -0
  32. package/dist/src/db/queries/subgraph-operations.d.ts +96 -0
  33. package/dist/src/db/queries/subgraphs.d.ts +99 -1
  34. package/dist/src/db/queries/subgraphs.js +52 -23
  35. package/dist/src/db/queries/subgraphs.js.map +7 -7
  36. package/dist/src/db/queries/subscriptions.d.ts +96 -0
  37. package/dist/src/db/queries/subscriptions.js +47 -31
  38. package/dist/src/db/queries/subscriptions.js.map +5 -5
  39. package/dist/src/db/schema.d.ts +97 -1
  40. package/dist/src/index.d.ts +109 -1
  41. package/dist/src/index.js +52 -1
  42. package/dist/src/index.js.map +7 -6
  43. package/dist/src/node/client.d.ts +11 -1
  44. package/dist/src/node/client.js +42 -4
  45. package/dist/src/node/client.js.map +3 -3
  46. package/dist/src/node/local-client.d.ts +96 -0
  47. package/dist/src/node/nakamoto.d.ts +22 -7
  48. package/dist/src/node/nakamoto.js +46 -5
  49. package/dist/src/node/nakamoto.js.map +3 -3
  50. package/migrations/0115_instances.ts +33 -0
  51. package/migrations/0116_coverage_schema.ts +163 -0
  52. package/package.json +29 -1
@@ -0,0 +1,1183 @@
1
+ import { ColumnType, Generated } from "kysely";
2
+ /**
3
+ * Coverage-kernel constraints. SQL CHECKs in migration 0116 must stay
4
+ * identical — property tests treat this file as the spec.
5
+ */
6
+ declare const STAGE_KINDS: readonly ["raw", "decode", "subgraph", "queue"];
7
+ type StageKind = (typeof STAGE_KINDS)[number];
8
+ declare const NATIVE_CLOCKS: readonly ["block", "cursor", "queue"];
9
+ type NativeClock = (typeof NATIVE_CLOCKS)[number];
10
+ declare const REPAIR_MODES: readonly ["range_safe", "full_reindex", "archive_replay", "none"];
11
+ type RepairMode = (typeof REPAIR_MODES)[number];
12
+ declare const RUN_STATUSES: readonly ["pending", "running", "complete", "syncing", "lagging", "gap", "stale", "failed", "unverified_import", "unanchored", "source_unavailable", "out_of_scope", "disabled", "halted"];
13
+ type RunStatus = (typeof RUN_STATUSES)[number];
14
+ declare const FAILURE_UNITS: readonly ["block", "range", "cursor", "queue"];
15
+ type FailureUnit = (typeof FAILURE_UNITS)[number];
16
+ declare const FAILURE_CLASSES: readonly ["omission", "version", "digest_mismatch", "crash", "reorg", "source_gap", "handler", "timeout", "unknown"];
17
+ type FailureClass = (typeof FAILURE_CLASSES)[number];
18
+ declare const RETRY_STATES: readonly ["open", "retrying", "halted", "resolved"];
19
+ type RetryState = (typeof RETRY_STATES)[number];
20
+ interface BlocksTable {
21
+ height: number;
22
+ hash: string;
23
+ parent_hash: string;
24
+ burn_block_height: number;
25
+ burn_block_hash: ColumnType<string | null, string | null | undefined, string | null>;
26
+ /** Nakamoto StacksBlockId. Null on rows ingested before it was persisted. */
27
+ index_block_hash: ColumnType<string | null, string | null | undefined, string | null>;
28
+ timestamp: number;
29
+ canonical: Generated<boolean>;
30
+ created_at: Generated<Date>;
31
+ }
32
+ interface TransactionsTable {
33
+ tx_id: string;
34
+ block_height: number;
35
+ tx_index: Generated<number>;
36
+ type: string;
37
+ sender: string;
38
+ status: string;
39
+ contract_id: string | null;
40
+ function_name: string | null;
41
+ function_args: Generated<unknown | null>;
42
+ raw_result: Generated<string | null>;
43
+ raw_tx: string;
44
+ created_at: Generated<Date>;
45
+ }
46
+ interface EventsTable {
47
+ id: Generated<string>;
48
+ tx_id: string;
49
+ block_height: number;
50
+ event_index: number;
51
+ type: string;
52
+ data: unknown;
53
+ created_at: Generated<Date>;
54
+ }
55
+ interface TransactionsArchiveTable {
56
+ archive_id: Generated<string>;
57
+ tx_id: string;
58
+ block_height: number;
59
+ tx_index: number;
60
+ type: string;
61
+ sender: string;
62
+ status: string;
63
+ contract_id: string | null;
64
+ function_name: string | null;
65
+ function_args: unknown | null;
66
+ raw_result: string | null;
67
+ raw_tx: string;
68
+ created_at: Date;
69
+ orphaned_block_hash: string | null;
70
+ archived_at: Generated<Date>;
71
+ }
72
+ interface EventsArchiveTable {
73
+ archive_id: Generated<string>;
74
+ id: string;
75
+ tx_id: string;
76
+ block_height: number;
77
+ event_index: number;
78
+ type: string;
79
+ data: unknown;
80
+ created_at: Date;
81
+ orphaned_block_hash: string | null;
82
+ archived_at: Generated<Date>;
83
+ }
84
+ interface DeadLetterEventsTable {
85
+ id: Generated<string>;
86
+ block_height: number;
87
+ tx_id: string;
88
+ event_index: number;
89
+ event_type: string;
90
+ data: unknown;
91
+ reason: string;
92
+ created_at: Generated<Date>;
93
+ }
94
+ interface MempoolTransactionsTable {
95
+ seq: Generated<string>;
96
+ tx_id: string;
97
+ raw_tx: string;
98
+ type: string;
99
+ sender: string;
100
+ contract_id: string | null;
101
+ function_name: string | null;
102
+ function_args: unknown | null;
103
+ received_at: Generated<Date>;
104
+ }
105
+ interface IndexProgressTable {
106
+ network: string;
107
+ last_indexed_block: Generated<number>;
108
+ last_contiguous_block: Generated<number>;
109
+ highest_seen_block: Generated<number>;
110
+ updated_at: Generated<Date>;
111
+ }
112
+ interface SubgraphsTable {
113
+ id: Generated<string>;
114
+ name: string;
115
+ version: Generated<string>;
116
+ status: Generated<string>;
117
+ definition: Record<string, unknown>;
118
+ schema_hash: string;
119
+ handler_path: string;
120
+ schema_name: string | null;
121
+ start_block: Generated<number>;
122
+ last_processed_block: Generated<number>;
123
+ reindex_from_block: number | null;
124
+ reindex_to_block: number | null;
125
+ last_error: string | null;
126
+ last_error_at: Date | null;
127
+ total_processed: Generated<number>;
128
+ total_errors: Generated<number>;
129
+ account_id: string;
130
+ handler_code: string | null;
131
+ source_code: string | null;
132
+ project_id: string | null;
133
+ visibility: Generated<string>;
134
+ /** Paid (wallet-ghost) deploys expire unless renewed or claimed; NULL = no expiry. */
135
+ expires_at: Date | null;
136
+ /** (event type, contract) probe pairs persisted at deploy for weight classification. */
137
+ sparse_probe_targets: unknown | null;
138
+ database_url_enc: ColumnType<Buffer | null, Buffer | null | undefined, Buffer | null>;
139
+ sandbox_workers: Generated<boolean>;
140
+ created_at: Generated<Date>;
141
+ updated_at: Generated<Date>;
142
+ }
143
+ interface ContractsTable {
144
+ contract_id: string;
145
+ deployer: string;
146
+ block_height: number;
147
+ canonical: Generated<boolean>;
148
+ abi: unknown | null;
149
+ declared_traits: Generated<string[]>;
150
+ inferred_standards: Generated<string[]>;
151
+ abi_status: Generated<string>;
152
+ abi_fetched_at: Date | null;
153
+ created_at: Generated<Date>;
154
+ }
155
+ interface SubgraphGapsTable {
156
+ id: Generated<string>;
157
+ subgraph_id: string;
158
+ subgraph_name: string;
159
+ gap_start: number;
160
+ gap_end: number;
161
+ reason: string;
162
+ detected_at: Generated<Date>;
163
+ resolved_at: Date | null;
164
+ }
165
+ type SubgraphOperationKind = "reindex" | "backfill";
166
+ type SubgraphOperationStatus = "queued" | "running" | "completed" | "failed" | "cancelled";
167
+ interface SubgraphOperationsTable {
168
+ id: Generated<string>;
169
+ subgraph_id: string;
170
+ subgraph_name: string;
171
+ account_id: string | null;
172
+ kind: ColumnType<SubgraphOperationKind, SubgraphOperationKind, SubgraphOperationKind>;
173
+ status: ColumnType<SubgraphOperationStatus, SubgraphOperationStatus | undefined, SubgraphOperationStatus>;
174
+ from_block: number | null;
175
+ to_block: number | null;
176
+ cancel_requested: Generated<boolean>;
177
+ locked_by: string | null;
178
+ locked_until: Date | null;
179
+ started_at: Date | null;
180
+ finished_at: Date | null;
181
+ processed_blocks: number | null;
182
+ error: string | null;
183
+ created_at: Generated<Date>;
184
+ updated_at: Generated<Date>;
185
+ /** 'light' (contract-scoped sparse) | 'heavy' (broad). Claim budgets heavy. */
186
+ weight: Generated<string>;
187
+ /** Candidate-event denominator computed at enqueue (sparse ops only). */
188
+ estimated_events: string | number | bigint | null;
189
+ /** Events processed so far — written by the progress flush. */
190
+ processed_events: string | number | bigint | null;
191
+ /** Backfill ops' own crash checkpoint — advanced conditionally in-tx with
192
+ * each written block; replays skip at/below it. NULL for reindex ops
193
+ * (those checkpoint on subgraphs.last_processed_block). */
194
+ cursor_block: string | number | bigint | null;
195
+ }
196
+ interface ApiKeysTable {
197
+ id: Generated<string>;
198
+ key_hash: string;
199
+ key_prefix: string;
200
+ name: string | null;
201
+ status: Generated<string>;
202
+ rate_limit: Generated<number>;
203
+ ip_address: string;
204
+ account_id: string;
205
+ product: Generated<"account" | "streams" | "index">;
206
+ tier: "free" | "build" | "scale" | "enterprise" | null;
207
+ last_used_at: Date | null;
208
+ revoked_at: Date | null;
209
+ created_at: Generated<Date>;
210
+ }
211
+ /** Singleton self-host / publisher identity. Network is immutable. */
212
+ interface InstancesTable {
213
+ id: Generated<string>;
214
+ network: string;
215
+ created_at: Generated<Date>;
216
+ }
217
+ interface AccountsTable {
218
+ id: Generated<string>;
219
+ /** NULL for unclaimed ghost accounts (anonymous self-serve keys). */
220
+ email: string | null;
221
+ /** True for anonymous self-serve accounts until claimed via magic link. */
222
+ ghost: Generated<boolean>;
223
+ /** Stacks principal owning a wallet-ghost account (x402-paid deploys). */
224
+ wallet_principal: string | null;
225
+ plan: Generated<string>;
226
+ display_name: string | null;
227
+ bio: string | null;
228
+ avatar_url: string | null;
229
+ slug: string | null;
230
+ stripe_customer_id: string | null;
231
+ /** Opt-out toggle for the subgraph reindex-completion email. Defaults true. */
232
+ notify_reindex_complete: Generated<boolean>;
233
+ created_at: Generated<Date>;
234
+ }
235
+ interface SessionsTable {
236
+ id: Generated<string>;
237
+ token_hash: string;
238
+ token_prefix: string;
239
+ account_id: string;
240
+ ip_address: string;
241
+ expires_at: Generated<Date>;
242
+ revoked_at: Date | null;
243
+ last_used_at: Date | null;
244
+ created_at: Generated<Date>;
245
+ }
246
+ /**
247
+ * One-time claim tokens for ghost accounts. The raw token only ever appears in
248
+ * the claim URL returned at mint time; we store its sha256. A used token marks
249
+ * the account as claimed (or merged into an existing account).
250
+ */
251
+ interface ClaimTokensTable {
252
+ id: Generated<string>;
253
+ account_id: string;
254
+ token_hash: string;
255
+ created_at: Generated<Date>;
256
+ expires_at: Date;
257
+ used_at: Date | null;
258
+ }
259
+ interface MagicLinksTable {
260
+ id: Generated<string>;
261
+ email: string;
262
+ token: string;
263
+ code: string | null;
264
+ expires_at: Date;
265
+ used_at: Date | null;
266
+ failed_attempts: Generated<number>;
267
+ created_at: Generated<Date>;
268
+ }
269
+ interface UsageDailyTable {
270
+ account_id: string;
271
+ tenant_id: string | null;
272
+ date: string;
273
+ api_requests: Generated<number>;
274
+ deliveries: Generated<number>;
275
+ streams_events_returned: Generated<number>;
276
+ index_decoded_events_returned: Generated<number>;
277
+ }
278
+ interface UsageSnapshotsTable {
279
+ id: Generated<string>;
280
+ account_id: string;
281
+ measured_at: Generated<Date>;
282
+ storage_bytes: Generated<number>;
283
+ }
284
+ interface AccountInsightsTable {
285
+ id: Generated<string>;
286
+ account_id: string;
287
+ category: string;
288
+ insight_type: string;
289
+ resource_id: string | null;
290
+ severity: string;
291
+ title: string;
292
+ body: string;
293
+ data: unknown;
294
+ dismissed_at: Date | null;
295
+ expires_at: Date | null;
296
+ created_at: Generated<Date>;
297
+ }
298
+ interface AccountAgentRunsTable {
299
+ id: Generated<string>;
300
+ account_id: string;
301
+ started_at: Generated<Date>;
302
+ completed_at: Date | null;
303
+ status: Generated<string>;
304
+ input_tokens: Generated<number>;
305
+ output_tokens: Generated<number>;
306
+ cost_usd: Generated<number>;
307
+ insights_created: Generated<number>;
308
+ error: string | null;
309
+ }
310
+ interface SubgraphProcessingStatsTable {
311
+ id: Generated<string>;
312
+ subgraph_name: string;
313
+ api_key_id: string | null;
314
+ bucket_start: Date | null;
315
+ bucket_end: Date | null;
316
+ blocks_processed: number | null;
317
+ total_time_ms: number | null;
318
+ handler_time_ms: number | null;
319
+ flush_time_ms: number | null;
320
+ max_block_time_ms: number | null;
321
+ max_handler_time_ms: number | null;
322
+ avg_ops_per_block: number | null;
323
+ is_catchup: Generated<boolean>;
324
+ created_at: Generated<Date>;
325
+ }
326
+ interface SubgraphTableSnapshotsTable {
327
+ id: Generated<string>;
328
+ subgraph_name: string;
329
+ api_key_id: string | null;
330
+ table_name: string;
331
+ row_count: number | null;
332
+ created_at: Generated<Date>;
333
+ }
334
+ interface SubgraphHealthSnapshotsTable {
335
+ id: Generated<string>;
336
+ subgraph_id: string;
337
+ total_processed: number;
338
+ total_errors: number;
339
+ last_processed_block: number | null;
340
+ captured_at: Generated<Date>;
341
+ }
342
+ interface SubgraphUsageDailyTable {
343
+ subgraph_id: string;
344
+ date: string;
345
+ query_count: Generated<number>;
346
+ }
347
+ interface ProjectsTable {
348
+ id: Generated<string>;
349
+ name: string;
350
+ slug: string;
351
+ account_id: string;
352
+ settings: Generated<Record<string, unknown>>;
353
+ network: Generated<string>;
354
+ node_rpc: string | null;
355
+ created_at: Generated<Date>;
356
+ updated_at: Generated<Date>;
357
+ }
358
+ interface TeamMembersTable {
359
+ id: Generated<string>;
360
+ project_id: string;
361
+ account_id: string;
362
+ role: Generated<string>;
363
+ invited_by: string | null;
364
+ created_at: Generated<Date>;
365
+ }
366
+ interface TeamInvitationsTable {
367
+ id: Generated<string>;
368
+ project_id: string;
369
+ email: string;
370
+ role: Generated<string>;
371
+ token: string;
372
+ invited_by: string | null;
373
+ expires_at: Date;
374
+ accepted_at: Date | null;
375
+ created_at: Generated<Date>;
376
+ }
377
+ interface ProcessedStripeEventsTable {
378
+ event_id: string;
379
+ event_type: string;
380
+ processed_at: Generated<Date>;
381
+ }
382
+ interface DecodedEventsTable {
383
+ cursor: string;
384
+ block_height: number;
385
+ tx_id: string;
386
+ tx_index: number;
387
+ event_index: number;
388
+ event_type: string;
389
+ microblock_hash: string | null;
390
+ canonical: Generated<boolean>;
391
+ contract_id: string | null;
392
+ sender: string | null;
393
+ recipient: string | null;
394
+ amount: string | null;
395
+ asset_identifier: string | null;
396
+ value: string | null;
397
+ memo: string | null;
398
+ /** Decoded payload for event types that don't fit the flat columns
399
+ * (e.g. `print`: { topic, value, raw_value }). Null for transfer types. */
400
+ payload: unknown | null;
401
+ source_cursor: string;
402
+ created_at: Generated<Date>;
403
+ }
404
+ interface DecoderCheckpointsTable {
405
+ decoder_name: string;
406
+ last_cursor: string | null;
407
+ updated_at: Generated<Date>;
408
+ }
409
+ interface ChainReorgsTable {
410
+ id: Generated<string>;
411
+ detected_at: Generated<Date>;
412
+ fork_point_height: number;
413
+ old_index_block_hash: string | null;
414
+ new_index_block_hash: string | null;
415
+ orphaned_from_height: number;
416
+ orphaned_from_event_index: number;
417
+ orphaned_to_height: number;
418
+ orphaned_to_event_index: number;
419
+ new_canonical_height: number;
420
+ new_canonical_event_index: number;
421
+ created_at: Generated<Date>;
422
+ }
423
+ type Pox4FunctionName = "stack-stx" | "delegate-stx" | "stack-extend" | "stack-increase" | "revoke-delegate-stx" | "delegate-stack-stx" | "delegate-stack-extend" | "delegate-stack-increase" | "stack-aggregation-commit" | "stack-aggregation-commit-indexed" | "stack-aggregation-increase" | "set-signer-key-authorization";
424
+ interface Pox4CallsTable {
425
+ cursor: string;
426
+ block_height: number;
427
+ block_time: Date;
428
+ burn_block_height: number;
429
+ tx_id: string;
430
+ tx_index: number;
431
+ function_name: Pox4FunctionName;
432
+ caller: string;
433
+ stacker: string | null;
434
+ delegate_to: string | null;
435
+ amount_ustx: string | null;
436
+ lock_period: number | null;
437
+ pox_addr_version: number | null;
438
+ pox_addr_hashbytes: string | null;
439
+ pox_addr_btc: string | null;
440
+ start_cycle: number | null;
441
+ end_cycle: number | null;
442
+ signer_key: string | null;
443
+ signer_signature: string | null;
444
+ auth_id: string | null;
445
+ max_amount: string | null;
446
+ reward_cycle: number | null;
447
+ aggregated_amount_ustx: string | null;
448
+ aggregated_signer_index: number | null;
449
+ auth_period: number | null;
450
+ auth_topic: string | null;
451
+ auth_allowed: boolean | null;
452
+ result_ok: boolean;
453
+ result_raw: string;
454
+ canonical: Generated<boolean>;
455
+ source_cursor: string;
456
+ created_at: Generated<Date>;
457
+ }
458
+ interface Pox4CyclesDailyTable {
459
+ date: string;
460
+ reward_cycle: number;
461
+ total_stacked_ustx: Generated<string>;
462
+ solo_stackers: Generated<number>;
463
+ delegated_principals: Generated<number>;
464
+ unique_pools: Generated<number>;
465
+ unique_signers: Generated<number>;
466
+ calls_today: Generated<number>;
467
+ updated_at: Generated<Date>;
468
+ }
469
+ interface Pox4SignersDailyTable {
470
+ date: string;
471
+ reward_cycle: number;
472
+ signer_key: string;
473
+ weight_ustx: Generated<string>;
474
+ stacker_count: Generated<number>;
475
+ aggregation_calls: Generated<number>;
476
+ updated_at: Generated<Date>;
477
+ }
478
+ type Pox5EventTopic = "set-bond-admin" | "set-pause-admin" | "pause-rewards" | "setup-bond" | "add-to-allowlist" | "register-for-bond" | "update-bond-registration" | "register-signer" | "stake" | "stake-update" | "announce-l1-early-exit" | "unstake-sbtc" | "unstake" | "calculate-rewards" | "bond-distribution" | "claim-rewards" | "claim-staker-rewards-for-signer" | "grant-signer-key" | "revoke-signer-grant";
479
+ interface Pox5EventsTable {
480
+ cursor: string;
481
+ block_height: number;
482
+ block_time: Date;
483
+ tx_id: string;
484
+ tx_index: number;
485
+ event_index: number;
486
+ topic: Pox5EventTopic;
487
+ staker: string | null;
488
+ signer: string | null;
489
+ signer_manager: string | null;
490
+ bond_index: number | null;
491
+ amount_ustx: string | null;
492
+ amount_sats: string | null;
493
+ reward_cycle: number | null;
494
+ first_reward_cycle: number | null;
495
+ unlock_cycle: number | null;
496
+ unlock_burn_height: number | null;
497
+ is_l1_lock: boolean | null;
498
+ signer_key: string | null;
499
+ data: unknown;
500
+ canonical: Generated<boolean>;
501
+ source_cursor: string;
502
+ created_at: Generated<Date>;
503
+ }
504
+ interface BurnBlockRewardsTable {
505
+ cursor: string;
506
+ burn_block_height: number;
507
+ burn_block_hash: string;
508
+ reward_index: number;
509
+ recipient_btc: string;
510
+ amount_sats: string;
511
+ burn_amount: Generated<string>;
512
+ created_at: Generated<Date>;
513
+ }
514
+ interface BurnBlockRewardSlotsTable {
515
+ cursor: string;
516
+ burn_block_height: number;
517
+ burn_block_hash: string;
518
+ slot_index: number;
519
+ holder_btc: string;
520
+ created_at: Generated<Date>;
521
+ }
522
+ type SbtcEventTopic = "completed-deposit" | "withdrawal-create" | "withdrawal-accept" | "withdrawal-reject" | "key-rotation" | "update-protocol-contract";
523
+ interface SbtcEventsTable {
524
+ cursor: string;
525
+ block_height: number;
526
+ block_time: Date;
527
+ tx_id: string;
528
+ tx_index: number;
529
+ event_index: number;
530
+ topic: SbtcEventTopic;
531
+ request_id: number | null;
532
+ amount: string | null;
533
+ sender: string | null;
534
+ recipient_btc_version: number | null;
535
+ recipient_btc_hashbytes: string | null;
536
+ bitcoin_txid: string | null;
537
+ output_index: number | null;
538
+ sweep_txid: string | null;
539
+ burn_hash: string | null;
540
+ burn_height: number | null;
541
+ signer_bitmap: string | null;
542
+ max_fee: string | null;
543
+ fee: string | null;
544
+ block_height_at_request: number | null;
545
+ governance_contract_type: number | null;
546
+ governance_new_contract: string | null;
547
+ signer_aggregate_pubkey: string | null;
548
+ signer_threshold: number | null;
549
+ signer_address: string | null;
550
+ signer_keys_count: number | null;
551
+ canonical: Generated<boolean>;
552
+ source_cursor: string;
553
+ created_at: Generated<Date>;
554
+ }
555
+ type SbtcTokenEventType = "transfer" | "mint" | "burn";
556
+ interface SbtcTokenEventsTable {
557
+ cursor: string;
558
+ block_height: number;
559
+ block_time: Date;
560
+ tx_id: string;
561
+ tx_index: number;
562
+ event_index: number;
563
+ event_type: SbtcTokenEventType;
564
+ sender: string | null;
565
+ recipient: string | null;
566
+ amount: string;
567
+ memo: string | null;
568
+ canonical: Generated<boolean>;
569
+ source_cursor: string;
570
+ created_at: Generated<Date>;
571
+ }
572
+ /**
573
+ * BTC L1 settlement status for sBTC withdrawal sweeps. Filled by the indexer's
574
+ * settlement-confirmer worker, which polls our own bitcoind for confirmations of
575
+ * each `withdrawal-accept`'s `sweep_txid` and surfaces real settlement on the
576
+ * withdrawal lifecycle (the API's `settlement.{btc_confirmations,
577
+ * settlement_confirmed}` placeholder). Keyed on `sweep_txid` (not `request_id`):
578
+ * a request can produce more than one sweep over its life (RBF/rebroadcast), so
579
+ * each broadcast keeps its own confirmation history.
580
+ */
581
+ interface SbtcSettlementsTable {
582
+ sweep_txid: string;
583
+ request_id: number;
584
+ btc_confirmations: Generated<number>;
585
+ settlement_confirmed: Generated<boolean>;
586
+ /** Confirming Bitcoin block — null while the sweep is unconfirmed. */
587
+ block_hash: string | null;
588
+ block_height: number | null;
589
+ first_seen_at: Generated<Date>;
590
+ last_checked_at: Generated<Date>;
591
+ /** Set once, when `settlement_confirmed` first flips true. */
592
+ confirmed_at: Date | null;
593
+ updated_at: Generated<Date>;
594
+ }
595
+ interface SbtcSupplySnapshotsTable {
596
+ date: string;
597
+ total_supply: Generated<string>;
598
+ mints_today: Generated<string>;
599
+ burns_today: Generated<string>;
600
+ deposit_count: Generated<number>;
601
+ withdrawal_create_count: Generated<number>;
602
+ withdrawal_accept_count: Generated<number>;
603
+ withdrawal_reject_count: Generated<number>;
604
+ updated_at: Generated<Date>;
605
+ }
606
+ type BnsNameEventTopic = "new-name" | "transfer-name" | "renew-name" | "burn-name" | "new-airdrop";
607
+ interface BnsNameEventsTable {
608
+ cursor: string;
609
+ block_height: number;
610
+ block_time: Date;
611
+ tx_id: string;
612
+ tx_index: number;
613
+ event_index: number;
614
+ topic: BnsNameEventTopic;
615
+ namespace: string;
616
+ name: string;
617
+ fqn: string;
618
+ owner: string | null;
619
+ bns_id: string;
620
+ registered_at: number | null;
621
+ imported_at: number | null;
622
+ renewal_height: number | null;
623
+ stx_burn: string | null;
624
+ preordered_by: string | null;
625
+ hashed_salted_fqn_preorder: string | null;
626
+ canonical: Generated<boolean>;
627
+ source_cursor: string;
628
+ created_at: Generated<Date>;
629
+ }
630
+ type BnsNamespaceEventStatus = "launch" | "transfer-manager" | "freeze-manager" | "update-price-manager" | "freeze-price-manager" | "turn-off-manager-transfers";
631
+ interface BnsNamespaceEventsTable {
632
+ cursor: string;
633
+ block_height: number;
634
+ block_time: Date;
635
+ tx_id: string;
636
+ tx_index: number;
637
+ event_index: number;
638
+ status: BnsNamespaceEventStatus;
639
+ namespace: string;
640
+ manager: string | null;
641
+ manager_frozen: boolean | null;
642
+ manager_transfers_disabled: boolean | null;
643
+ price_function: string | null;
644
+ price_frozen: boolean | null;
645
+ lifetime: number | null;
646
+ revealed_at: number | null;
647
+ launched_at: number | null;
648
+ canonical: Generated<boolean>;
649
+ source_cursor: string;
650
+ created_at: Generated<Date>;
651
+ }
652
+ type BnsMarketplaceAction = "list-in-ustx" | "unlist-in-ustx" | "buy-in-ustx";
653
+ interface BnsMarketplaceEventsTable {
654
+ cursor: string;
655
+ block_height: number;
656
+ block_time: Date;
657
+ tx_id: string;
658
+ tx_index: number;
659
+ event_index: number;
660
+ action: BnsMarketplaceAction;
661
+ bns_id: string;
662
+ price_ustx: string | null;
663
+ commission: string | null;
664
+ canonical: Generated<boolean>;
665
+ source_cursor: string;
666
+ created_at: Generated<Date>;
667
+ }
668
+ interface BnsNamesTable {
669
+ fqn: string;
670
+ namespace: string;
671
+ name: string;
672
+ owner: string;
673
+ bns_id: string;
674
+ registered_at: number | null;
675
+ renewal_height: number | null;
676
+ last_event_cursor: string;
677
+ last_event_at: Date;
678
+ updated_at: Generated<Date>;
679
+ }
680
+ interface BnsNamespacesTable {
681
+ namespace: string;
682
+ manager: string | null;
683
+ manager_frozen: Generated<boolean>;
684
+ price_frozen: Generated<boolean>;
685
+ lifetime: number | null;
686
+ launched_at: number | null;
687
+ last_event_cursor: string;
688
+ last_event_at: Date;
689
+ name_count: Generated<number>;
690
+ updated_at: Generated<Date>;
691
+ }
692
+ /**
693
+ * Memoized `ctx.client.readOnly()` results. Keyed on `index_block_hash` so a
694
+ * reorg-replaced block never inherits the orphaned fork's answer; a NULL
695
+ * `index_block_hash` marks a caller-declared contract-constant value, cached
696
+ * once per contract+args instead of once per block.
697
+ */
698
+ interface ChainReadCacheTable {
699
+ id: Generated<number>;
700
+ contract_id: string;
701
+ function_name: string;
702
+ args_hash: string;
703
+ index_block_hash: string | null;
704
+ block_height: ColumnType<number | null, number | null | undefined, number | null>;
705
+ result_hex: string;
706
+ created_at: Generated<Date>;
707
+ }
708
+ /**
709
+ * A block that arrived for a height we already hold, staged until a later
710
+ * block's `parent_hash` says which of the two the chain kept. See migration
711
+ * 0112 — adopting on first sight picked the losing fork twice.
712
+ */
713
+ interface PendingForkBlocksTable {
714
+ height: number;
715
+ block_hash: string;
716
+ parent_hash: string;
717
+ /** The canonical hash we held at this height when the contender arrived. */
718
+ incumbent_hash: string;
719
+ /** The raw observer payload, replayed verbatim if this fork wins. */
720
+ payload: ColumnType<unknown, unknown, unknown>;
721
+ received_at: Generated<Date>;
722
+ }
723
+ type ObserverJournalStatus = "received" | "processed" | "failed";
724
+ /**
725
+ * Exact observer callback receipt. `raw_body` is immutable evidence; the
726
+ * processing columns are updated only after the current derived-state write
727
+ * succeeds or fails.
728
+ */
729
+ interface ObserverJournalTable {
730
+ sequence: Generated<string>;
731
+ network: string;
732
+ path: string;
733
+ source: string | null;
734
+ received_at: Generated<Date>;
735
+ raw_body: ColumnType<Buffer, Buffer, Buffer>;
736
+ raw_body_sha256: string;
737
+ status: ColumnType<ObserverJournalStatus, ObserverJournalStatus | undefined, ObserverJournalStatus>;
738
+ semantic_sha256: string | null;
739
+ block_height: number | null;
740
+ block_hash: string | null;
741
+ burn_block_height: number | null;
742
+ burn_block_hash: string | null;
743
+ result: unknown | null;
744
+ error: string | null;
745
+ processed_at: Date | null;
746
+ }
747
+ /** Declared coverage stage. Identity is the `id` string (`raw`, `decode:stx`, …). */
748
+ interface StageRegistryTable {
749
+ id: string;
750
+ kind: StageKind;
751
+ depends_on: string | null;
752
+ native_clock: NativeClock;
753
+ producer_version: string;
754
+ repair_mode: RepairMode;
755
+ enabled: Generated<boolean>;
756
+ created_at: Generated<Date>;
757
+ }
758
+ /** One versioned sweep of a stage. */
759
+ interface StageRunsTable {
760
+ id: Generated<string>;
761
+ stage_id: string;
762
+ code_hash: string;
763
+ config_hash: string;
764
+ handler_hash: string | null;
765
+ target_height: number | null;
766
+ target_cursor: string | null;
767
+ status: RunStatus;
768
+ complete_through: number | null;
769
+ started_at: Generated<Date>;
770
+ finished_at: Date | null;
771
+ }
772
+ /** Per-block acknowledgement. Unique on (stage, height, hash). */
773
+ interface StageBlockReceiptsTable {
774
+ id: Generated<string>;
775
+ stage_id: string;
776
+ run_id: string | null;
777
+ block_height: number;
778
+ block_hash: string;
779
+ input_count: number;
780
+ input_digest: string;
781
+ effect_digest: string;
782
+ finalized: Generated<boolean>;
783
+ compacted_at: Date | null;
784
+ created_at: Generated<Date>;
785
+ }
786
+ /** Compacted finalized range. Only sealed after receipts in the range finalize. */
787
+ interface CoverageSegmentsTable {
788
+ id: Generated<string>;
789
+ stage_id: string;
790
+ from_height: number;
791
+ to_height: number;
792
+ chain_digest: string;
793
+ input_digest: string;
794
+ output_digest: string;
795
+ sealed_at: Generated<Date>;
796
+ }
797
+ /** Exact unit or range that failed, plus retry/retention state. */
798
+ interface StageFailuresTable {
799
+ id: Generated<string>;
800
+ stage_id: string;
801
+ run_id: string | null;
802
+ unit_kind: FailureUnit;
803
+ from_height: number | null;
804
+ to_height: number | null;
805
+ class: FailureClass;
806
+ retry_state: RetryState;
807
+ retry_count: Generated<number>;
808
+ last_error: string | null;
809
+ created_at: Generated<Date>;
810
+ resolved_at: Date | null;
811
+ retain_until: Generated<Date>;
812
+ }
813
+ interface Database {
814
+ blocks: BlocksTable;
815
+ transactions: TransactionsTable;
816
+ events: EventsTable;
817
+ transactions_archive: TransactionsArchiveTable;
818
+ events_archive: EventsArchiveTable;
819
+ dead_letter_events: DeadLetterEventsTable;
820
+ mempool_transactions: MempoolTransactionsTable;
821
+ index_progress: IndexProgressTable;
822
+ contracts: ContractsTable;
823
+ subgraphs: SubgraphsTable;
824
+ api_keys: ApiKeysTable;
825
+ instances: InstancesTable;
826
+ accounts: AccountsTable;
827
+ sessions: SessionsTable;
828
+ magic_links: MagicLinksTable;
829
+ claim_tokens: ClaimTokensTable;
830
+ usage_daily: UsageDailyTable;
831
+ usage_snapshots: UsageSnapshotsTable;
832
+ account_insights: AccountInsightsTable;
833
+ account_agent_runs: AccountAgentRunsTable;
834
+ subgraph_health_snapshots: SubgraphHealthSnapshotsTable;
835
+ subgraph_processing_stats: SubgraphProcessingStatsTable;
836
+ subgraph_table_snapshots: SubgraphTableSnapshotsTable;
837
+ subgraph_gaps: SubgraphGapsTable;
838
+ subgraph_operations: SubgraphOperationsTable;
839
+ subgraph_usage_daily: SubgraphUsageDailyTable;
840
+ projects: ProjectsTable;
841
+ team_members: TeamMembersTable;
842
+ team_invitations: TeamInvitationsTable;
843
+ processed_stripe_events: ProcessedStripeEventsTable;
844
+ tenants: TenantsTable;
845
+ tenant_usage_monthly: TenantUsageMonthlyTable;
846
+ tenant_compute_addons: TenantComputeAddonsTable;
847
+ account_spend_caps: AccountSpendCapsTable;
848
+ account_credits: AccountCreditsTable;
849
+ provisioning_audit_log: ProvisioningAuditLogTable;
850
+ subscriptions: SubscriptionsTable;
851
+ subscription_outbox: SubscriptionOutboxTable;
852
+ subscription_deliveries: SubscriptionDeliveriesTable;
853
+ trigger_evaluator_state: TriggerEvaluatorStateTable;
854
+ decoded_events: DecodedEventsTable;
855
+ decoder_checkpoints: DecoderCheckpointsTable;
856
+ chain_reorgs: ChainReorgsTable;
857
+ pox4_calls: Pox4CallsTable;
858
+ pox4_cycles_daily: Pox4CyclesDailyTable;
859
+ pox4_signers_daily: Pox4SignersDailyTable;
860
+ pox5_events: Pox5EventsTable;
861
+ burn_block_rewards: BurnBlockRewardsTable;
862
+ burn_block_reward_slots: BurnBlockRewardSlotsTable;
863
+ sbtc_events: SbtcEventsTable;
864
+ sbtc_token_events: SbtcTokenEventsTable;
865
+ sbtc_settlements: SbtcSettlementsTable;
866
+ sbtc_supply_snapshots: SbtcSupplySnapshotsTable;
867
+ bns_name_events: BnsNameEventsTable;
868
+ bns_namespace_events: BnsNamespaceEventsTable;
869
+ bns_marketplace_events: BnsMarketplaceEventsTable;
870
+ bns_names: BnsNamesTable;
871
+ bns_namespaces: BnsNamespacesTable;
872
+ service_heartbeats: ServiceHeartbeatsTable;
873
+ x402_payments: X402PaymentsTable;
874
+ x402_balances: X402BalancesTable;
875
+ chain_read_cache: ChainReadCacheTable;
876
+ pending_fork_blocks: PendingForkBlocksTable;
877
+ observer_journal: ObserverJournalTable;
878
+ stage_registry: StageRegistryTable;
879
+ stage_runs: StageRunsTable;
880
+ stage_block_receipts: StageBlockReceiptsTable;
881
+ coverage_segments: CoverageSegmentsTable;
882
+ stage_failures: StageFailuresTable;
883
+ }
884
+ /** Prepaid x402 credit — one running USD-micros balance per payer principal. */
885
+ interface X402BalancesTable {
886
+ principal: string;
887
+ balance_usd_micros: Generated<string | number | bigint>;
888
+ /** Month bucket ("YYYY-MM") the spend counter applies to. */
889
+ spent_month: string | null;
890
+ spent_month_usd_micros: Generated<string | number | bigint>;
891
+ updated_at: Generated<Date>;
892
+ }
893
+ interface ServiceHeartbeatsTable {
894
+ name: string;
895
+ updated_at: Generated<Date>;
896
+ }
897
+ /** x402 pay-per-request ledger (control plane). One row per settled payment,
898
+ * keyed by challenge nonce + settled txid. `state` tracks confirmed-tier
899
+ * settlement and post-serve reorg reversal. */
900
+ interface X402PaymentsTable {
901
+ id: Generated<string>;
902
+ nonce: string;
903
+ txid: string;
904
+ asset: string;
905
+ amount: string;
906
+ payer: string;
907
+ surface: string;
908
+ state: Generated<"pending" | "confirmed" | "reverted">;
909
+ created_at: Generated<Date>;
910
+ updated_at: Generated<Date>;
911
+ /** "payment" = per-call settle; "deposit" = prepaid balance top-up. */
912
+ kind: Generated<string>;
913
+ /** Linked claimed account once the paying wallet is attached (continuity). */
914
+ account_id: string | null;
915
+ /** USD-micros to credit on confirmation, for deposit rows the reconciler
916
+ * settles asynchronously. NULL for per-call settles (credit nothing). */
917
+ credit_usd_micros: string | null;
918
+ /** Idempotency key: stamped exactly once when this row's credit is applied.
919
+ * NULL means never credited (or not a credit-bearing row). Pre-migration
920
+ * non-pending deposit rows are backfilled to a non-null sentinel so the
921
+ * reconciler's heal path can never double-credit them. */
922
+ credited_at: Generated<Date> | null;
923
+ }
924
+ type TenantStatus = "provisioning" | "active" | "limit_warning" | "paused_limit" | "suspended" | "error" | "deleted";
925
+ interface TenantsTable {
926
+ id: Generated<string>;
927
+ account_id: string;
928
+ slug: string;
929
+ status: ColumnType<TenantStatus, TenantStatus | undefined, TenantStatus>;
930
+ plan: string;
931
+ cpus: ColumnType<number, number | string, number | string>;
932
+ memory_mb: number;
933
+ storage_limit_mb: number;
934
+ storage_used_mb: number | null;
935
+ pg_container_id: string | null;
936
+ api_container_id: string | null;
937
+ processor_container_id: string | null;
938
+ target_database_url_enc: Buffer;
939
+ tenant_jwt_secret_enc: Buffer;
940
+ anon_key_enc: Buffer;
941
+ service_key_enc: Buffer;
942
+ api_url_internal: string;
943
+ api_url_public: string;
944
+ suspended_at: Date | null;
945
+ last_health_check_at: Date | null;
946
+ last_active_at: Generated<Date>;
947
+ service_gen: Generated<number>;
948
+ anon_gen: Generated<number>;
949
+ project_id: string | null;
950
+ created_at: Generated<Date>;
951
+ updated_at: Generated<Date>;
952
+ }
953
+ interface TenantUsageMonthlyTable {
954
+ id: Generated<string>;
955
+ tenant_id: string;
956
+ period_month: Date;
957
+ storage_peak_mb: Generated<number>;
958
+ storage_avg_mb: Generated<number>;
959
+ storage_last_mb: Generated<number>;
960
+ measurements: Generated<number>;
961
+ first_at: Generated<Date>;
962
+ last_at: Generated<Date>;
963
+ }
964
+ interface TenantComputeAddonsTable {
965
+ id: Generated<string>;
966
+ tenant_id: string;
967
+ memory_mb_delta: Generated<number>;
968
+ cpu_delta: Generated<number | string>;
969
+ storage_mb_delta: Generated<number>;
970
+ effective_from: Generated<Date>;
971
+ effective_until: Date | null;
972
+ stripe_subscription_item_id: string | null;
973
+ created_at: Generated<Date>;
974
+ }
975
+ interface AccountSpendCapsTable {
976
+ account_id: string;
977
+ monthly_cap_cents: number | null;
978
+ compute_cap_cents: number | null;
979
+ storage_cap_cents: number | null;
980
+ alert_threshold_pct: Generated<number>;
981
+ alert_sent_at: Date | null;
982
+ frozen_at: Date | null;
983
+ updated_at: Generated<Date>;
984
+ }
985
+ /** Prepaid dev credits — card-funded balance per account (peer to x402_balances). */
986
+ interface AccountCreditsTable {
987
+ account_id: string;
988
+ balance_usd_micros: Generated<string | number | bigint>;
989
+ /** Month bucket ("YYYY-MM") the spend counter applies to. */
990
+ spent_month: string | null;
991
+ spent_month_usd_micros: Generated<string | number | bigint>;
992
+ updated_at: Generated<Date>;
993
+ }
994
+ type ProvisioningAuditEvent = "provision.start" | "provision.success" | "provision.failure" | "suspend" | "resume" | "resize" | "keys.rotate" | "bastion.key.upload" | "bastion.key.revoke" | "teardown";
995
+ type ProvisioningAuditStatus = "ok" | "error";
996
+ interface ProvisioningAuditLogTable {
997
+ id: Generated<string>;
998
+ tenant_id: string | null;
999
+ tenant_slug: string | null;
1000
+ account_id: string | null;
1001
+ actor: string;
1002
+ event: ProvisioningAuditEvent;
1003
+ status: ProvisioningAuditStatus;
1004
+ detail: unknown | null;
1005
+ error: string | null;
1006
+ created_at: Generated<Date>;
1007
+ }
1008
+ type SubscriptionStatus = "active" | "paused" | "error";
1009
+ /** Polymorphic subscription mode: `subgraph` reacts to processed table rows;
1010
+ * `chain` reacts to raw chain events matched directly off the Index/Streams
1011
+ * clock (no subgraph). See migration 0088. */
1012
+ type SubscriptionKind = "subgraph" | "chain";
1013
+ type SubscriptionFormat = "standard-webhooks" | "inngest" | "trigger" | "cloudflare" | "cloudevents" | "raw";
1014
+ type SubscriptionRuntime = "inngest" | "trigger" | "cloudflare" | "node";
1015
+ interface SubscriptionsTable {
1016
+ id: Generated<string>;
1017
+ account_id: string;
1018
+ project_id: string | null;
1019
+ name: string;
1020
+ status: ColumnType<SubscriptionStatus, SubscriptionStatus | undefined, SubscriptionStatus>;
1021
+ kind: ColumnType<SubscriptionKind, SubscriptionKind | undefined, SubscriptionKind>;
1022
+ /** Null for chain subscriptions (CHECK subscriptions_kind_shape). */
1023
+ subgraph_name: string | null;
1024
+ /** Null for chain subscriptions (CHECK subscriptions_kind_shape). */
1025
+ table_name: string | null;
1026
+ /** Chain-trigger filter array (the `SubgraphFilter` shape, JSON). Null for
1027
+ * subgraph subscriptions. Typed loosely here to avoid a shared→subgraphs
1028
+ * import cycle; the Zod schema in schemas/subscriptions.ts owns the shape. */
1029
+ triggers: unknown | null;
1030
+ filter: Generated<unknown>;
1031
+ format: ColumnType<SubscriptionFormat, SubscriptionFormat | undefined, SubscriptionFormat>;
1032
+ runtime: SubscriptionRuntime | null;
1033
+ url: string;
1034
+ signing_secret_enc: Buffer;
1035
+ auth_config: Generated<unknown>;
1036
+ max_retries: Generated<number>;
1037
+ timeout_ms: Generated<number>;
1038
+ concurrency: Generated<number>;
1039
+ circuit_failures: Generated<number>;
1040
+ circuit_opened_at: Date | null;
1041
+ last_delivery_at: Date | null;
1042
+ last_success_at: Date | null;
1043
+ last_error: string | null;
1044
+ created_at: Generated<Date>;
1045
+ updated_at: Generated<Date>;
1046
+ }
1047
+ type OutboxStatus = "pending" | "delivered" | "dead";
1048
+ interface SubscriptionOutboxTable {
1049
+ id: Generated<string>;
1050
+ subscription_id: string;
1051
+ kind: ColumnType<SubscriptionKind, SubscriptionKind | undefined, SubscriptionKind>;
1052
+ /** Null for chain-subscription rows. */
1053
+ subgraph_name: string | null;
1054
+ /** Null for chain-subscription rows. */
1055
+ table_name: string | null;
1056
+ block_height: number | bigint;
1057
+ tx_id: string | null;
1058
+ row_pk: unknown;
1059
+ event_type: string;
1060
+ payload: unknown;
1061
+ dedup_key: string;
1062
+ attempt: Generated<number>;
1063
+ next_attempt_at: Generated<Date>;
1064
+ status: ColumnType<OutboxStatus, OutboxStatus | undefined, OutboxStatus>;
1065
+ is_replay: Generated<boolean>;
1066
+ delivered_at: Date | null;
1067
+ failed_at: Date | null;
1068
+ locked_by: string | null;
1069
+ locked_until: Date | null;
1070
+ created_at: Generated<Date>;
1071
+ }
1072
+ interface SubscriptionDeliveriesTable {
1073
+ id: Generated<string>;
1074
+ /** Nullable after migration 0077 — outbox row may be cleaned up while
1075
+ * delivery telemetry is retained. */
1076
+ outbox_id: string | null;
1077
+ subscription_id: string;
1078
+ attempt: number;
1079
+ status_code: number | null;
1080
+ response_headers: unknown | null;
1081
+ response_body: string | null;
1082
+ error_message: string | null;
1083
+ duration_ms: number | null;
1084
+ dispatched_at: Generated<Date>;
1085
+ }
1086
+ /** Single-row (id always TRUE) high-water mark for the chain-trigger evaluator.
1087
+ * One loop serves all chain subscriptions, so the cursor is global. */
1088
+ interface TriggerEvaluatorStateTable {
1089
+ id: Generated<boolean>;
1090
+ last_processed_block: ColumnType<bigint, bigint | number | undefined, bigint | number>;
1091
+ /** Watermark for the async sBTC settlement-confirmed webhook scan; null until
1092
+ * the evaluator fast-forwards it on first run. */
1093
+ last_settlement_scan_at: ColumnType<Date | null, Date | null | undefined, Date | null>;
1094
+ updated_at: Generated<Date>;
1095
+ }
1096
+ /**
1097
+ * v1 canonical byte encoding for chain identity — the shape that lets
1098
+ * independently-run runtimes agree on the same block.
1099
+ *
1100
+ * The exact-body digest (`sha256:parquet-object`) proves capture fidelity to one
1101
+ * source: replay the same bytes, get the same rows. It cannot prove two nodes
1102
+ * observed the same chain, because their Parquet encoders legally differ in
1103
+ * column padding, compression, JSON key order, and null placement — two
1104
+ * operators processing the same block can ship byte-different Parquets that
1105
+ * carry identical content.
1106
+ *
1107
+ * The semantic digest is the shape that lets independent runtimes agree. Every
1108
+ * value on a block/transaction/event is normalized into a canonical byte string
1109
+ * by rules that MUST NOT change without a version bump. Two v1 computations
1110
+ * over the same range agree, or one is wrong about the chain — never about
1111
+ * formatting.
1112
+ *
1113
+ * Encoding rules (v1):
1114
+ * - Fields join with `\x1f` (ASCII US, unit separator — cannot legally
1115
+ * appear in any chain value; a printable delimiter risks collision with
1116
+ * contract-emitted strings).
1117
+ * - Null encodes as `\x00` (single NUL). Distinct from empty string `""`.
1118
+ * - Integers encode as their base-10 string. bigint → decimal string.
1119
+ * - JSON payload columns (function_args, event data) encode as canonical
1120
+ * JSON: object keys sorted lexicographically, no whitespace, bigint →
1121
+ * quoted decimal string, non-finite numbers rejected.
1122
+ * - Field order per record type is fixed and never reordered.
1123
+ * - Digest = sha256(bytes), lowercase hex.
1124
+ *
1125
+ * Rollup rules (v1) — order MUST match the archive's stream order or an
1126
+ * honest re-will disagree with the manifest:
1127
+ * - blocks: (height asc)
1128
+ * - transactions: (block_height asc, tx_index asc, tx_id asc)
1129
+ * - events: (block_height asc, event_index asc, tx_id asc)
1130
+ * Per-partition rollup is `sha256(concat(row_digest_bytes))` in stream order.
1131
+ *
1132
+ * Test vectors under `packages/shared/src/archive/__fixtures__/semantic-digest/`
1133
+ * pin the encoding. Any change to bytes must bump the spec version.
1134
+ */
1135
+ declare const SEMANTIC_DIGEST_SPEC_V1: "sha256:semantic-v1";
1136
+ type SemanticDigestSpec = typeof SEMANTIC_DIGEST_SPEC_V1;
1137
+ /**
1138
+ * Per-partition digest record — the shape that lands in the snapshot manifest.
1139
+ * Complements the existing `sha256:parquet-object` per-partition digest by
1140
+ * proving semantic identity independent of file encoding.
1141
+ */
1142
+ interface PartitionSemanticDigest {
1143
+ dataset: "blocks" | "transactions" | "events";
1144
+ from_block: number;
1145
+ to_block: number;
1146
+ row_count: number;
1147
+ digest: string | null;
1148
+ digest_spec: SemanticDigestSpec;
1149
+ }
1150
+ import { Kysely } from "kysely";
1151
+ /**
1152
+ * Compute per-partition semantic-v1 digests directly from a database — the same
1153
+ * bytes an exporter would produce, without writing Parquet. Callers: the CLI
1154
+ * verifier's `--semantic` pass, and (in future) the node replay auditor.
1155
+ *
1156
+ * SQL and ordering MUST match the archive exporter's stream (see
1157
+ * `packages/indexer/src/archive/export-snapshot.ts`). If either drifts, an
1158
+ * honest re-computation will disagree with the manifest even though both are
1159
+ * correct — and there is no way to tell which is wrong. Any change here needs
1160
+ * a matching change there.
1161
+ */
1162
+ type CanonicalDataset = "blocks" | "transactions" | "events";
1163
+ interface StreamOptions {
1164
+ batchRows?: number;
1165
+ }
1166
+ /**
1167
+ * Compute one partition's semantic-v1 digest. Empty ranges return `null` — an
1168
+ * empty range has no digest, distinct from "digest of zero rows" which would
1169
+ * compare equal across datasets.
1170
+ */
1171
+ declare function computePartitionSemanticDigest(db: Kysely<Database>, dataset: CanonicalDataset, fromBlock: number, toBlock: number, options?: StreamOptions): Promise<PartitionSemanticDigest>;
1172
+ type PartitionSemanticComparison = {
1173
+ dataset: CanonicalDataset
1174
+ from_block: number
1175
+ to_block: number
1176
+ status: "match" | "digest-mismatch" | "count-mismatch" | "missing-locally"
1177
+ expected_digest: string | null
1178
+ actual_digest: string | null
1179
+ expected_rows: number
1180
+ actual_rows: number
1181
+ };
1182
+ declare function comparePartitionSemanticDigests(local: readonly PartitionSemanticDigest[], reference: readonly PartitionSemanticDigest[]): PartitionSemanticComparison[];
1183
+ export { computePartitionSemanticDigest, comparePartitionSemanticDigests, PartitionSemanticComparison, CanonicalDataset };