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