@secondlayer/shared 6.8.1 → 6.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 (36) hide show
  1. package/dist/src/db/index.d.ts +47 -1
  2. package/dist/src/db/index.js +42 -3
  3. package/dist/src/db/index.js.map +3 -3
  4. package/dist/src/db/queries/chain-reorgs.d.ts +36 -0
  5. package/dist/src/db/queries/chain-reorgs.js +41 -3
  6. package/dist/src/db/queries/chain-reorgs.js.map +3 -3
  7. package/dist/src/db/queries/contracts.d.ts +783 -0
  8. package/dist/src/db/queries/contracts.js +90 -0
  9. package/dist/src/db/queries/contracts.js.map +11 -0
  10. package/dist/src/db/queries/integrity.d.ts +36 -0
  11. package/dist/src/db/queries/subgraph-gaps.d.ts +36 -0
  12. package/dist/src/db/queries/subgraph-operations.d.ts +36 -0
  13. package/dist/src/db/queries/subgraphs.d.ts +58 -1
  14. package/dist/src/db/queries/subgraphs.js +390 -6
  15. package/dist/src/db/queries/subgraphs.js.map +9 -4
  16. package/dist/src/db/queries/subscriptions.d.ts +36 -0
  17. package/dist/src/db/schema.d.ts +40 -1
  18. package/dist/src/index.d.ts +55 -1
  19. package/dist/src/index.js +45 -4
  20. package/dist/src/index.js.map +4 -4
  21. package/dist/src/node/client.d.ts +2 -0
  22. package/dist/src/node/client.js +11 -1
  23. package/dist/src/node/client.js.map +3 -3
  24. package/dist/src/node/local-client.d.ts +36 -0
  25. package/dist/src/schemas/index.d.ts +8 -0
  26. package/dist/src/schemas/index.js +4 -2
  27. package/dist/src/schemas/index.js.map +3 -3
  28. package/dist/src/schemas/subgraphs.d.ts +8 -0
  29. package/dist/src/schemas/subgraphs.js +4 -2
  30. package/dist/src/schemas/subgraphs.js.map +3 -3
  31. package/migrations/0066_public_l2_decoded_events.ts +4 -2
  32. package/migrations/0067_product_usage_counters.ts +4 -2
  33. package/migrations/0081_subgraphs_database_url_enc.ts +16 -0
  34. package/migrations/0082_contracts_registry.ts +44 -0
  35. package/migrations/0083_burnchain_rewards.ts +63 -0
  36. package/package.json +6 -2
@@ -0,0 +1,783 @@
1
+ import { Kysely } from "kysely";
2
+ import { ColumnType, Generated, Selectable } from "kysely";
3
+ interface BlocksTable {
4
+ height: number;
5
+ hash: string;
6
+ parent_hash: string;
7
+ burn_block_height: number;
8
+ burn_block_hash: ColumnType<string | null, string | null | undefined, string | null>;
9
+ timestamp: number;
10
+ canonical: Generated<boolean>;
11
+ created_at: Generated<Date>;
12
+ }
13
+ interface TransactionsTable {
14
+ tx_id: string;
15
+ block_height: number;
16
+ tx_index: Generated<number>;
17
+ type: string;
18
+ sender: string;
19
+ status: string;
20
+ contract_id: string | null;
21
+ function_name: string | null;
22
+ function_args: Generated<unknown | null>;
23
+ raw_result: Generated<string | null>;
24
+ raw_tx: string;
25
+ created_at: Generated<Date>;
26
+ }
27
+ interface EventsTable {
28
+ id: Generated<string>;
29
+ tx_id: string;
30
+ block_height: number;
31
+ event_index: number;
32
+ type: string;
33
+ data: unknown;
34
+ created_at: Generated<Date>;
35
+ }
36
+ interface IndexProgressTable {
37
+ network: string;
38
+ last_indexed_block: Generated<number>;
39
+ last_contiguous_block: Generated<number>;
40
+ highest_seen_block: Generated<number>;
41
+ updated_at: Generated<Date>;
42
+ }
43
+ interface SubgraphsTable {
44
+ id: Generated<string>;
45
+ name: string;
46
+ version: Generated<string>;
47
+ status: Generated<string>;
48
+ definition: Record<string, unknown>;
49
+ schema_hash: string;
50
+ handler_path: string;
51
+ schema_name: string | null;
52
+ start_block: Generated<number>;
53
+ last_processed_block: Generated<number>;
54
+ reindex_from_block: number | null;
55
+ reindex_to_block: number | null;
56
+ last_error: string | null;
57
+ last_error_at: Date | null;
58
+ total_processed: Generated<number>;
59
+ total_errors: Generated<number>;
60
+ account_id: string;
61
+ handler_code: string | null;
62
+ source_code: string | null;
63
+ project_id: string | null;
64
+ database_url_enc: ColumnType<Buffer | null, Buffer | null | undefined, Buffer | null>;
65
+ created_at: Generated<Date>;
66
+ updated_at: Generated<Date>;
67
+ }
68
+ interface ContractsTable {
69
+ contract_id: string;
70
+ deployer: string;
71
+ block_height: number;
72
+ canonical: Generated<boolean>;
73
+ abi: unknown | null;
74
+ declared_traits: Generated<string[]>;
75
+ inferred_standards: Generated<string[]>;
76
+ abi_status: Generated<string>;
77
+ abi_fetched_at: Date | null;
78
+ created_at: Generated<Date>;
79
+ }
80
+ interface SubgraphGapsTable {
81
+ id: Generated<string>;
82
+ subgraph_id: string;
83
+ subgraph_name: string;
84
+ gap_start: number;
85
+ gap_end: number;
86
+ reason: string;
87
+ detected_at: Generated<Date>;
88
+ resolved_at: Date | null;
89
+ }
90
+ type SubgraphOperationKind = "reindex" | "backfill";
91
+ type SubgraphOperationStatus = "queued" | "running" | "completed" | "failed" | "cancelled";
92
+ interface SubgraphOperationsTable {
93
+ id: Generated<string>;
94
+ subgraph_id: string;
95
+ subgraph_name: string;
96
+ account_id: string | null;
97
+ kind: ColumnType<SubgraphOperationKind, SubgraphOperationKind, SubgraphOperationKind>;
98
+ status: ColumnType<SubgraphOperationStatus, SubgraphOperationStatus | undefined, SubgraphOperationStatus>;
99
+ from_block: number | null;
100
+ to_block: number | null;
101
+ cancel_requested: Generated<boolean>;
102
+ locked_by: string | null;
103
+ locked_until: Date | null;
104
+ started_at: Date | null;
105
+ finished_at: Date | null;
106
+ processed_blocks: number | null;
107
+ error: string | null;
108
+ created_at: Generated<Date>;
109
+ updated_at: Generated<Date>;
110
+ }
111
+ interface ApiKeysTable {
112
+ id: Generated<string>;
113
+ key_hash: string;
114
+ key_prefix: string;
115
+ name: string | null;
116
+ status: Generated<string>;
117
+ rate_limit: Generated<number>;
118
+ ip_address: string;
119
+ account_id: string;
120
+ product: Generated<"account" | "streams" | "index">;
121
+ tier: "free" | "build" | "scale" | "enterprise" | null;
122
+ last_used_at: Date | null;
123
+ revoked_at: Date | null;
124
+ created_at: Generated<Date>;
125
+ }
126
+ interface AccountsTable {
127
+ id: Generated<string>;
128
+ email: string;
129
+ plan: Generated<string>;
130
+ display_name: string | null;
131
+ bio: string | null;
132
+ avatar_url: string | null;
133
+ slug: string | null;
134
+ stripe_customer_id: string | null;
135
+ created_at: Generated<Date>;
136
+ }
137
+ interface SessionsTable {
138
+ id: Generated<string>;
139
+ token_hash: string;
140
+ token_prefix: string;
141
+ account_id: string;
142
+ ip_address: string;
143
+ expires_at: Generated<Date>;
144
+ revoked_at: Date | null;
145
+ last_used_at: Date | null;
146
+ created_at: Generated<Date>;
147
+ }
148
+ interface MagicLinksTable {
149
+ id: Generated<string>;
150
+ email: string;
151
+ token: string;
152
+ code: string | null;
153
+ expires_at: Date;
154
+ used_at: Date | null;
155
+ failed_attempts: Generated<number>;
156
+ created_at: Generated<Date>;
157
+ }
158
+ interface UsageDailyTable {
159
+ account_id: string;
160
+ tenant_id: string | null;
161
+ date: string;
162
+ api_requests: Generated<number>;
163
+ deliveries: Generated<number>;
164
+ streams_events_returned: Generated<number>;
165
+ index_decoded_events_returned: Generated<number>;
166
+ }
167
+ interface UsageSnapshotsTable {
168
+ id: Generated<string>;
169
+ account_id: string;
170
+ measured_at: Generated<Date>;
171
+ storage_bytes: Generated<number>;
172
+ }
173
+ interface AccountInsightsTable {
174
+ id: Generated<string>;
175
+ account_id: string;
176
+ category: string;
177
+ insight_type: string;
178
+ resource_id: string | null;
179
+ severity: string;
180
+ title: string;
181
+ body: string;
182
+ data: unknown;
183
+ dismissed_at: Date | null;
184
+ expires_at: Date | null;
185
+ created_at: Generated<Date>;
186
+ }
187
+ interface AccountAgentRunsTable {
188
+ id: Generated<string>;
189
+ account_id: string;
190
+ started_at: Generated<Date>;
191
+ completed_at: Date | null;
192
+ status: Generated<string>;
193
+ input_tokens: Generated<number>;
194
+ output_tokens: Generated<number>;
195
+ cost_usd: Generated<number>;
196
+ insights_created: Generated<number>;
197
+ error: string | null;
198
+ }
199
+ interface SubgraphProcessingStatsTable {
200
+ id: Generated<string>;
201
+ subgraph_name: string;
202
+ api_key_id: string | null;
203
+ bucket_start: Date | null;
204
+ bucket_end: Date | null;
205
+ blocks_processed: number | null;
206
+ total_time_ms: number | null;
207
+ handler_time_ms: number | null;
208
+ flush_time_ms: number | null;
209
+ max_block_time_ms: number | null;
210
+ max_handler_time_ms: number | null;
211
+ avg_ops_per_block: number | null;
212
+ is_catchup: Generated<boolean>;
213
+ created_at: Generated<Date>;
214
+ }
215
+ interface SubgraphTableSnapshotsTable {
216
+ id: Generated<string>;
217
+ subgraph_name: string;
218
+ api_key_id: string | null;
219
+ table_name: string;
220
+ row_count: number | null;
221
+ created_at: Generated<Date>;
222
+ }
223
+ interface SubgraphHealthSnapshotsTable {
224
+ id: Generated<string>;
225
+ subgraph_id: string;
226
+ total_processed: number;
227
+ total_errors: number;
228
+ last_processed_block: number | null;
229
+ captured_at: Generated<Date>;
230
+ }
231
+ interface SubgraphUsageDailyTable {
232
+ subgraph_id: string;
233
+ date: string;
234
+ query_count: Generated<number>;
235
+ }
236
+ interface ProjectsTable {
237
+ id: Generated<string>;
238
+ name: string;
239
+ slug: string;
240
+ account_id: string;
241
+ settings: Generated<Record<string, unknown>>;
242
+ network: Generated<string>;
243
+ node_rpc: string | null;
244
+ created_at: Generated<Date>;
245
+ updated_at: Generated<Date>;
246
+ }
247
+ interface TeamMembersTable {
248
+ id: Generated<string>;
249
+ project_id: string;
250
+ account_id: string;
251
+ role: Generated<string>;
252
+ invited_by: string | null;
253
+ created_at: Generated<Date>;
254
+ }
255
+ interface TeamInvitationsTable {
256
+ id: Generated<string>;
257
+ project_id: string;
258
+ email: string;
259
+ role: Generated<string>;
260
+ token: string;
261
+ invited_by: string | null;
262
+ expires_at: Date;
263
+ accepted_at: Date | null;
264
+ created_at: Generated<Date>;
265
+ }
266
+ interface ChatSessionsTable {
267
+ id: Generated<string>;
268
+ account_id: string;
269
+ title: string | null;
270
+ summary: unknown | null;
271
+ created_at: Generated<Date>;
272
+ updated_at: Generated<Date>;
273
+ }
274
+ interface ChatMessagesTable {
275
+ id: Generated<string>;
276
+ chat_session_id: string;
277
+ role: string;
278
+ parts: unknown;
279
+ metadata: unknown | null;
280
+ created_at: Generated<Date>;
281
+ }
282
+ interface ProcessedStripeEventsTable {
283
+ event_id: string;
284
+ event_type: string;
285
+ processed_at: Generated<Date>;
286
+ }
287
+ interface DecodedEventsTable {
288
+ cursor: string;
289
+ block_height: number;
290
+ tx_id: string;
291
+ tx_index: number;
292
+ event_index: number;
293
+ event_type: string;
294
+ microblock_hash: string | null;
295
+ canonical: Generated<boolean>;
296
+ contract_id: string | null;
297
+ sender: string | null;
298
+ recipient: string | null;
299
+ amount: string | null;
300
+ asset_identifier: string | null;
301
+ value: string | null;
302
+ memo: string | null;
303
+ /** Decoded payload for event types that don't fit the flat columns
304
+ * (e.g. `print`: { topic, value, raw_value }). Null for transfer types. */
305
+ payload: unknown | null;
306
+ source_cursor: string;
307
+ created_at: Generated<Date>;
308
+ }
309
+ interface L2DecoderCheckpointsTable {
310
+ decoder_name: string;
311
+ last_cursor: string | null;
312
+ updated_at: Generated<Date>;
313
+ }
314
+ interface ChainReorgsTable {
315
+ id: Generated<string>;
316
+ detected_at: Generated<Date>;
317
+ fork_point_height: number;
318
+ old_index_block_hash: string | null;
319
+ new_index_block_hash: string | null;
320
+ orphaned_from_height: number;
321
+ orphaned_from_event_index: number;
322
+ orphaned_to_height: number;
323
+ orphaned_to_event_index: number;
324
+ new_canonical_height: number;
325
+ new_canonical_event_index: number;
326
+ created_at: Generated<Date>;
327
+ }
328
+ 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";
329
+ interface Pox4CallsTable {
330
+ cursor: string;
331
+ block_height: number;
332
+ block_time: Date;
333
+ burn_block_height: number;
334
+ tx_id: string;
335
+ tx_index: number;
336
+ function_name: Pox4FunctionName;
337
+ caller: string;
338
+ stacker: string | null;
339
+ delegate_to: string | null;
340
+ amount_ustx: string | null;
341
+ lock_period: number | null;
342
+ pox_addr_version: number | null;
343
+ pox_addr_hashbytes: string | null;
344
+ pox_addr_btc: string | null;
345
+ start_cycle: number | null;
346
+ end_cycle: number | null;
347
+ signer_key: string | null;
348
+ signer_signature: string | null;
349
+ auth_id: string | null;
350
+ max_amount: string | null;
351
+ reward_cycle: number | null;
352
+ aggregated_amount_ustx: string | null;
353
+ aggregated_signer_index: number | null;
354
+ auth_period: number | null;
355
+ auth_topic: string | null;
356
+ auth_allowed: boolean | null;
357
+ result_ok: boolean;
358
+ result_raw: string;
359
+ canonical: Generated<boolean>;
360
+ source_cursor: string;
361
+ created_at: Generated<Date>;
362
+ }
363
+ interface Pox4CyclesDailyTable {
364
+ date: string;
365
+ reward_cycle: number;
366
+ total_stacked_ustx: Generated<string>;
367
+ solo_stackers: Generated<number>;
368
+ delegated_principals: Generated<number>;
369
+ unique_pools: Generated<number>;
370
+ unique_signers: Generated<number>;
371
+ calls_today: Generated<number>;
372
+ updated_at: Generated<Date>;
373
+ }
374
+ interface Pox4SignersDailyTable {
375
+ date: string;
376
+ reward_cycle: number;
377
+ signer_key: string;
378
+ weight_ustx: Generated<string>;
379
+ stacker_count: Generated<number>;
380
+ aggregation_calls: Generated<number>;
381
+ updated_at: Generated<Date>;
382
+ }
383
+ interface BurnBlockRewardsTable {
384
+ cursor: string;
385
+ burn_block_height: number;
386
+ burn_block_hash: string;
387
+ reward_index: number;
388
+ recipient_btc: string;
389
+ amount_sats: string;
390
+ burn_amount: Generated<string>;
391
+ canonical: Generated<boolean>;
392
+ created_at: Generated<Date>;
393
+ }
394
+ interface BurnBlockRewardSlotsTable {
395
+ cursor: string;
396
+ burn_block_height: number;
397
+ burn_block_hash: string;
398
+ slot_index: number;
399
+ holder_btc: string;
400
+ canonical: Generated<boolean>;
401
+ created_at: Generated<Date>;
402
+ }
403
+ type SbtcEventTopic = "completed-deposit" | "withdrawal-create" | "withdrawal-accept" | "withdrawal-reject" | "key-rotation" | "update-protocol-contract";
404
+ interface SbtcEventsTable {
405
+ cursor: string;
406
+ block_height: number;
407
+ block_time: Date;
408
+ tx_id: string;
409
+ tx_index: number;
410
+ event_index: number;
411
+ topic: SbtcEventTopic;
412
+ request_id: number | null;
413
+ amount: string | null;
414
+ sender: string | null;
415
+ recipient_btc_version: number | null;
416
+ recipient_btc_hashbytes: string | null;
417
+ bitcoin_txid: string | null;
418
+ output_index: number | null;
419
+ sweep_txid: string | null;
420
+ burn_hash: string | null;
421
+ burn_height: number | null;
422
+ signer_bitmap: string | null;
423
+ max_fee: string | null;
424
+ fee: string | null;
425
+ block_height_at_request: number | null;
426
+ governance_contract_type: number | null;
427
+ governance_new_contract: string | null;
428
+ signer_aggregate_pubkey: string | null;
429
+ signer_threshold: number | null;
430
+ signer_address: string | null;
431
+ signer_keys_count: number | null;
432
+ canonical: Generated<boolean>;
433
+ source_cursor: string;
434
+ created_at: Generated<Date>;
435
+ }
436
+ type SbtcTokenEventType = "transfer" | "mint" | "burn";
437
+ interface SbtcTokenEventsTable {
438
+ cursor: string;
439
+ block_height: number;
440
+ block_time: Date;
441
+ tx_id: string;
442
+ tx_index: number;
443
+ event_index: number;
444
+ event_type: SbtcTokenEventType;
445
+ sender: string | null;
446
+ recipient: string | null;
447
+ amount: string;
448
+ memo: string | null;
449
+ canonical: Generated<boolean>;
450
+ source_cursor: string;
451
+ created_at: Generated<Date>;
452
+ }
453
+ interface SbtcSupplySnapshotsTable {
454
+ date: string;
455
+ total_supply: Generated<string>;
456
+ mints_today: Generated<string>;
457
+ burns_today: Generated<string>;
458
+ deposit_count: Generated<number>;
459
+ withdrawal_create_count: Generated<number>;
460
+ withdrawal_accept_count: Generated<number>;
461
+ withdrawal_reject_count: Generated<number>;
462
+ updated_at: Generated<Date>;
463
+ }
464
+ type BnsNameEventTopic = "new-name" | "transfer-name" | "renew-name" | "burn-name" | "new-airdrop";
465
+ interface BnsNameEventsTable {
466
+ cursor: string;
467
+ block_height: number;
468
+ block_time: Date;
469
+ tx_id: string;
470
+ tx_index: number;
471
+ event_index: number;
472
+ topic: BnsNameEventTopic;
473
+ namespace: string;
474
+ name: string;
475
+ fqn: string;
476
+ owner: string | null;
477
+ bns_id: string;
478
+ registered_at: number | null;
479
+ imported_at: number | null;
480
+ renewal_height: number | null;
481
+ stx_burn: string | null;
482
+ preordered_by: string | null;
483
+ hashed_salted_fqn_preorder: string | null;
484
+ canonical: Generated<boolean>;
485
+ source_cursor: string;
486
+ created_at: Generated<Date>;
487
+ }
488
+ type BnsNamespaceEventStatus = "launch" | "transfer-manager" | "freeze-manager" | "update-price-manager" | "freeze-price-manager" | "turn-off-manager-transfers";
489
+ interface BnsNamespaceEventsTable {
490
+ cursor: string;
491
+ block_height: number;
492
+ block_time: Date;
493
+ tx_id: string;
494
+ tx_index: number;
495
+ event_index: number;
496
+ status: BnsNamespaceEventStatus;
497
+ namespace: string;
498
+ manager: string | null;
499
+ manager_frozen: boolean | null;
500
+ manager_transfers_disabled: boolean | null;
501
+ price_function: string | null;
502
+ price_frozen: boolean | null;
503
+ lifetime: number | null;
504
+ revealed_at: number | null;
505
+ launched_at: number | null;
506
+ canonical: Generated<boolean>;
507
+ source_cursor: string;
508
+ created_at: Generated<Date>;
509
+ }
510
+ type BnsMarketplaceAction = "list-in-ustx" | "unlist-in-ustx" | "buy-in-ustx";
511
+ interface BnsMarketplaceEventsTable {
512
+ cursor: string;
513
+ block_height: number;
514
+ block_time: Date;
515
+ tx_id: string;
516
+ tx_index: number;
517
+ event_index: number;
518
+ action: BnsMarketplaceAction;
519
+ bns_id: string;
520
+ price_ustx: string | null;
521
+ commission: string | null;
522
+ canonical: Generated<boolean>;
523
+ source_cursor: string;
524
+ created_at: Generated<Date>;
525
+ }
526
+ interface BnsNamesTable {
527
+ fqn: string;
528
+ namespace: string;
529
+ name: string;
530
+ owner: string;
531
+ bns_id: string;
532
+ registered_at: number | null;
533
+ renewal_height: number | null;
534
+ last_event_cursor: string;
535
+ last_event_at: Date;
536
+ updated_at: Generated<Date>;
537
+ }
538
+ interface BnsNamespacesTable {
539
+ namespace: string;
540
+ manager: string | null;
541
+ manager_frozen: Generated<boolean>;
542
+ price_frozen: Generated<boolean>;
543
+ lifetime: number | null;
544
+ launched_at: number | null;
545
+ last_event_cursor: string;
546
+ last_event_at: Date;
547
+ name_count: Generated<number>;
548
+ updated_at: Generated<Date>;
549
+ }
550
+ interface Database {
551
+ blocks: BlocksTable;
552
+ transactions: TransactionsTable;
553
+ events: EventsTable;
554
+ index_progress: IndexProgressTable;
555
+ contracts: ContractsTable;
556
+ subgraphs: SubgraphsTable;
557
+ api_keys: ApiKeysTable;
558
+ accounts: AccountsTable;
559
+ sessions: SessionsTable;
560
+ magic_links: MagicLinksTable;
561
+ usage_daily: UsageDailyTable;
562
+ usage_snapshots: UsageSnapshotsTable;
563
+ account_insights: AccountInsightsTable;
564
+ account_agent_runs: AccountAgentRunsTable;
565
+ subgraph_health_snapshots: SubgraphHealthSnapshotsTable;
566
+ subgraph_processing_stats: SubgraphProcessingStatsTable;
567
+ subgraph_table_snapshots: SubgraphTableSnapshotsTable;
568
+ subgraph_gaps: SubgraphGapsTable;
569
+ subgraph_operations: SubgraphOperationsTable;
570
+ subgraph_usage_daily: SubgraphUsageDailyTable;
571
+ projects: ProjectsTable;
572
+ team_members: TeamMembersTable;
573
+ team_invitations: TeamInvitationsTable;
574
+ chat_sessions: ChatSessionsTable;
575
+ chat_messages: ChatMessagesTable;
576
+ processed_stripe_events: ProcessedStripeEventsTable;
577
+ tenants: TenantsTable;
578
+ tenant_usage_monthly: TenantUsageMonthlyTable;
579
+ tenant_compute_addons: TenantComputeAddonsTable;
580
+ account_spend_caps: AccountSpendCapsTable;
581
+ provisioning_audit_log: ProvisioningAuditLogTable;
582
+ subscriptions: SubscriptionsTable;
583
+ subscription_outbox: SubscriptionOutboxTable;
584
+ subscription_deliveries: SubscriptionDeliveriesTable;
585
+ decoded_events: DecodedEventsTable;
586
+ l2_decoder_checkpoints: L2DecoderCheckpointsTable;
587
+ chain_reorgs: ChainReorgsTable;
588
+ pox4_calls: Pox4CallsTable;
589
+ pox4_cycles_daily: Pox4CyclesDailyTable;
590
+ pox4_signers_daily: Pox4SignersDailyTable;
591
+ burn_block_rewards: BurnBlockRewardsTable;
592
+ burn_block_reward_slots: BurnBlockRewardSlotsTable;
593
+ sbtc_events: SbtcEventsTable;
594
+ sbtc_token_events: SbtcTokenEventsTable;
595
+ sbtc_supply_snapshots: SbtcSupplySnapshotsTable;
596
+ bns_name_events: BnsNameEventsTable;
597
+ bns_namespace_events: BnsNamespaceEventsTable;
598
+ bns_marketplace_events: BnsMarketplaceEventsTable;
599
+ bns_names: BnsNamesTable;
600
+ bns_namespaces: BnsNamespacesTable;
601
+ service_heartbeats: ServiceHeartbeatsTable;
602
+ }
603
+ interface ServiceHeartbeatsTable {
604
+ name: string;
605
+ updated_at: Generated<Date>;
606
+ }
607
+ type TenantStatus = "provisioning" | "active" | "limit_warning" | "paused_limit" | "suspended" | "error" | "deleted";
608
+ interface TenantsTable {
609
+ id: Generated<string>;
610
+ account_id: string;
611
+ slug: string;
612
+ status: ColumnType<TenantStatus, TenantStatus | undefined, TenantStatus>;
613
+ plan: string;
614
+ cpus: ColumnType<number, number | string, number | string>;
615
+ memory_mb: number;
616
+ storage_limit_mb: number;
617
+ storage_used_mb: number | null;
618
+ pg_container_id: string | null;
619
+ api_container_id: string | null;
620
+ processor_container_id: string | null;
621
+ target_database_url_enc: Buffer;
622
+ tenant_jwt_secret_enc: Buffer;
623
+ anon_key_enc: Buffer;
624
+ service_key_enc: Buffer;
625
+ api_url_internal: string;
626
+ api_url_public: string;
627
+ suspended_at: Date | null;
628
+ last_health_check_at: Date | null;
629
+ last_active_at: Generated<Date>;
630
+ service_gen: Generated<number>;
631
+ anon_gen: Generated<number>;
632
+ project_id: string | null;
633
+ created_at: Generated<Date>;
634
+ updated_at: Generated<Date>;
635
+ }
636
+ interface TenantUsageMonthlyTable {
637
+ id: Generated<string>;
638
+ tenant_id: string;
639
+ period_month: Date;
640
+ storage_peak_mb: Generated<number>;
641
+ storage_avg_mb: Generated<number>;
642
+ storage_last_mb: Generated<number>;
643
+ measurements: Generated<number>;
644
+ first_at: Generated<Date>;
645
+ last_at: Generated<Date>;
646
+ }
647
+ interface TenantComputeAddonsTable {
648
+ id: Generated<string>;
649
+ tenant_id: string;
650
+ memory_mb_delta: Generated<number>;
651
+ cpu_delta: Generated<number | string>;
652
+ storage_mb_delta: Generated<number>;
653
+ effective_from: Generated<Date>;
654
+ effective_until: Date | null;
655
+ stripe_subscription_item_id: string | null;
656
+ created_at: Generated<Date>;
657
+ }
658
+ interface AccountSpendCapsTable {
659
+ account_id: string;
660
+ monthly_cap_cents: number | null;
661
+ compute_cap_cents: number | null;
662
+ storage_cap_cents: number | null;
663
+ alert_threshold_pct: Generated<number>;
664
+ alert_sent_at: Date | null;
665
+ frozen_at: Date | null;
666
+ updated_at: Generated<Date>;
667
+ }
668
+ type ProvisioningAuditEvent = "provision.start" | "provision.success" | "provision.failure" | "suspend" | "resume" | "resize" | "keys.rotate" | "bastion.key.upload" | "bastion.key.revoke" | "teardown";
669
+ type ProvisioningAuditStatus = "ok" | "error";
670
+ interface ProvisioningAuditLogTable {
671
+ id: Generated<string>;
672
+ tenant_id: string | null;
673
+ tenant_slug: string | null;
674
+ account_id: string | null;
675
+ actor: string;
676
+ event: ProvisioningAuditEvent;
677
+ status: ProvisioningAuditStatus;
678
+ detail: unknown | null;
679
+ error: string | null;
680
+ created_at: Generated<Date>;
681
+ }
682
+ type Contract = Selectable<ContractsTable>;
683
+ type SubscriptionStatus = "active" | "paused" | "error";
684
+ type SubscriptionFormat = "standard-webhooks" | "inngest" | "trigger" | "cloudflare" | "cloudevents" | "raw";
685
+ type SubscriptionRuntime = "inngest" | "trigger" | "cloudflare" | "node";
686
+ interface SubscriptionsTable {
687
+ id: Generated<string>;
688
+ account_id: string;
689
+ project_id: string | null;
690
+ name: string;
691
+ status: ColumnType<SubscriptionStatus, SubscriptionStatus | undefined, SubscriptionStatus>;
692
+ subgraph_name: string;
693
+ table_name: string;
694
+ filter: Generated<unknown>;
695
+ format: ColumnType<SubscriptionFormat, SubscriptionFormat | undefined, SubscriptionFormat>;
696
+ runtime: SubscriptionRuntime | null;
697
+ url: string;
698
+ signing_secret_enc: Buffer;
699
+ auth_config: Generated<unknown>;
700
+ max_retries: Generated<number>;
701
+ timeout_ms: Generated<number>;
702
+ concurrency: Generated<number>;
703
+ circuit_failures: Generated<number>;
704
+ circuit_opened_at: Date | null;
705
+ last_delivery_at: Date | null;
706
+ last_success_at: Date | null;
707
+ last_error: string | null;
708
+ created_at: Generated<Date>;
709
+ updated_at: Generated<Date>;
710
+ }
711
+ type OutboxStatus = "pending" | "delivered" | "dead";
712
+ interface SubscriptionOutboxTable {
713
+ id: Generated<string>;
714
+ subscription_id: string;
715
+ subgraph_name: string;
716
+ table_name: string;
717
+ block_height: number | bigint;
718
+ tx_id: string | null;
719
+ row_pk: unknown;
720
+ event_type: string;
721
+ payload: unknown;
722
+ dedup_key: string;
723
+ attempt: Generated<number>;
724
+ next_attempt_at: Generated<Date>;
725
+ status: ColumnType<OutboxStatus, OutboxStatus | undefined, OutboxStatus>;
726
+ is_replay: Generated<boolean>;
727
+ delivered_at: Date | null;
728
+ failed_at: Date | null;
729
+ locked_by: string | null;
730
+ locked_until: Date | null;
731
+ created_at: Generated<Date>;
732
+ }
733
+ interface SubscriptionDeliveriesTable {
734
+ id: Generated<string>;
735
+ /** Nullable after migration 0077 — outbox row may be cleaned up while
736
+ * delivery telemetry is retained. */
737
+ outbox_id: string | null;
738
+ subscription_id: string;
739
+ attempt: number;
740
+ status_code: number | null;
741
+ response_headers: unknown | null;
742
+ response_body: string | null;
743
+ error_message: string | null;
744
+ duration_ms: number | null;
745
+ dispatched_at: Generated<Date>;
746
+ }
747
+ /**
748
+ * Contract registry queries — backing for trait-based discovery. Populated from
749
+ * contract deploys; ABI fetched async; standards inferred by static analysis.
750
+ */
751
+ type AbiStatus = "pending" | "fetched" | "failed" | "unparseable";
752
+ /** Record a contract deploy (idempotent). ABI is fetched separately + async. */
753
+ declare function recordContractDeploy(db: Kysely<Database>, row: {
754
+ contractId: string
755
+ deployer: string
756
+ blockHeight: number
757
+ }): Promise<void>;
758
+ /** Store a fetched ABI + the traits/standards derived from it. */
759
+ declare function setContractAbi(db: Kysely<Database>, contractId: string, data: {
760
+ abi: unknown | null
761
+ status: AbiStatus
762
+ declaredTraits?: string[]
763
+ inferredStandards?: string[]
764
+ }): Promise<void>;
765
+ declare function getContract(db: Kysely<Database>, contractId: string): Promise<Contract | null>;
766
+ /** Contracts still awaiting an ABI fetch (drives the fetch/backfill worker). */
767
+ declare function listContractsPendingAbi(db: Kysely<Database>, limit?: number): Promise<Contract[]>;
768
+ type Conformance = "declared" | "inferred" | "any";
769
+ /** Discovery: contracts matching a trait/standard, by conformance source. */
770
+ declare function listContractsByTrait(db: Kysely<Database>, trait: string, opts?: {
771
+ conformance?: Conformance
772
+ limit?: number
773
+ afterId?: string
774
+ }): Promise<Contract[]>;
775
+ /**
776
+ * As-of-block trait resolution (B4): contract IDs conforming to `trait` whose
777
+ * deploy block ≤ `asOfBlock`. Lets a trait-scoped subgraph reindex a token's
778
+ * full history even if classification lagged its deploy.
779
+ */
780
+ declare function resolveTraitContractIds(db: Kysely<Database>, trait: string, asOfBlock: number): Promise<string[]>;
781
+ /** Reorg: flip contracts deployed at/above a reorged height to non-canonical. */
782
+ declare function markContractsNonCanonical(db: Kysely<Database>, fromBlockHeight: number): Promise<void>;
783
+ export { setContractAbi, resolveTraitContractIds, recordContractDeploy, markContractsNonCanonical, listContractsPendingAbi, listContractsByTrait, getContract, Conformance, AbiStatus };