@secondlayer/subgraphs 6.3.6 → 6.5.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/README.md +1 -0
- package/dist/index.d.ts +200 -119
- package/dist/index.js +761 -21
- package/dist/index.js.map +9 -6
- package/dist/runtime/emitter.js +1 -1
- package/dist/runtime/emitter.js.map +2 -2
- package/dist/runtime/replay.d.ts +32 -13
- package/dist/runtime/replay.js +723 -22
- package/dist/runtime/replay.js.map +8 -5
- package/dist/schema/index.d.ts +43 -36
- package/dist/schema/index.js +307 -6
- package/dist/schema/index.js.map +6 -5
- package/dist/testing/index.d.ts +105 -105
- package/dist/testing/index.js +867 -84
- package/dist/testing/index.js.map +9 -6
- package/dist/types.d.ts +31 -31
- package/dist/types.js +1 -1
- package/dist/types.js.map +1 -1
- package/dist/validate.d.ts +27 -27
- package/dist/validate.js +1 -1
- package/dist/validate.js.map +2 -2
- package/dist/verification.d.ts +441 -0
- package/dist/verification.js +282 -0
- package/dist/verification.js.map +10 -0
- package/dist/verify/index.d.ts +475 -0
- package/dist/verify/index.js +3341 -0
- package/dist/verify/index.js.map +27 -0
- package/package.json +13 -3
|
@@ -0,0 +1,475 @@
|
|
|
1
|
+
import { BlockVerification, ProofSource, VerifyCheckpoint } from "@secondlayer/verify";
|
|
2
|
+
import { AbiContract as AbiContract2 } from "@secondlayer/stacks/clarity";
|
|
3
|
+
import { AssetIdentifier } from "@secondlayer/stacks/filters";
|
|
4
|
+
/**
|
|
5
|
+
* How long a read stays valid.
|
|
6
|
+
*
|
|
7
|
+
* - `per-block` (default): pinned to the block being processed, cached under
|
|
8
|
+
* its `index_block_hash`. Sound for any read-only function — reindexing the
|
|
9
|
+
* same block always returns the same value, and a reorg-replaced block has a
|
|
10
|
+
* different id so it can't inherit the orphaned answer.
|
|
11
|
+
* - `contract-constant`: the caller asserts the value cannot change for this
|
|
12
|
+
* contract and these args (SIP-010 `get-decimals`/`get-symbol`), so it is
|
|
13
|
+
* resolved ONCE instead of once per block. This is the mode that makes a
|
|
14
|
+
* backfill affordable — under `per-block` every block is a distinct key and
|
|
15
|
+
* therefore a distinct RPC. Declaring it on a value that does change pins the
|
|
16
|
+
* first answer forever, so it is opt-in and never inferred.
|
|
17
|
+
*/
|
|
18
|
+
type ChainReadCacheMode = "per-block" | "contract-constant";
|
|
19
|
+
type ChainReadOptions = {
|
|
20
|
+
cache?: ChainReadCacheMode;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* `ChainReadClient` with the ABI generic erased. Structurally cheap, so the
|
|
24
|
+
* base `SubgraphContext` can carry it; `TypedSubgraphContext` uses the real
|
|
25
|
+
* one and handlers get full inference.
|
|
26
|
+
*/
|
|
27
|
+
interface ErasedChainReadClient {
|
|
28
|
+
contract(contractId: string, abi: unknown, options?: ChainReadOptions): {
|
|
29
|
+
read: Record<string, (args?: Record<string, unknown>) => Promise<unknown>>;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/** Supported column types for subgraph schemas */
|
|
33
|
+
type ColumnType = "text" | "uint" | "int" | "principal" | "boolean" | "timestamp" | "jsonb";
|
|
34
|
+
/** Column definition in a subgraph table */
|
|
35
|
+
interface SubgraphColumn {
|
|
36
|
+
type: ColumnType;
|
|
37
|
+
nullable?: boolean;
|
|
38
|
+
indexed?: boolean;
|
|
39
|
+
search?: boolean;
|
|
40
|
+
default?: string | number | boolean;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Table definition within a subgraph schema.
|
|
44
|
+
*
|
|
45
|
+
* The array fields are `readonly` so a schema literal can be hoisted out of
|
|
46
|
+
* the `defineSubgraph()` call with `as const` (or {@link defineSchema}) and
|
|
47
|
+
* still typecheck — `as const` produces `readonly [readonly ["holder"]]`,
|
|
48
|
+
* which a mutable `string[][]` rejects. Without that, extracting a helper
|
|
49
|
+
* that takes `ctx` meant losing the entire typed surface, which is why the
|
|
50
|
+
* shipped starter reached for `ctx: any`.
|
|
51
|
+
*/
|
|
52
|
+
interface SubgraphTable {
|
|
53
|
+
columns: Record<string, SubgraphColumn>;
|
|
54
|
+
/** Composite indexes (each entry is an array of column names) */
|
|
55
|
+
indexes?: readonly (readonly string[])[];
|
|
56
|
+
/** Unique key constraints (each entry is an array of column names). Required for upsert. */
|
|
57
|
+
uniqueKeys?: readonly (readonly string[])[];
|
|
58
|
+
}
|
|
59
|
+
/** Subgraph schema — maps table names to table definitions */
|
|
60
|
+
type SubgraphSchema = Record<string, SubgraphTable>;
|
|
61
|
+
/** STX event filters */
|
|
62
|
+
interface StxTransferFilter {
|
|
63
|
+
type: "stx_transfer";
|
|
64
|
+
sender?: string;
|
|
65
|
+
recipient?: string;
|
|
66
|
+
minAmount?: bigint;
|
|
67
|
+
maxAmount?: bigint;
|
|
68
|
+
}
|
|
69
|
+
interface StxMintFilter {
|
|
70
|
+
type: "stx_mint";
|
|
71
|
+
recipient?: string;
|
|
72
|
+
minAmount?: bigint;
|
|
73
|
+
}
|
|
74
|
+
interface StxBurnFilter {
|
|
75
|
+
type: "stx_burn";
|
|
76
|
+
sender?: string;
|
|
77
|
+
minAmount?: bigint;
|
|
78
|
+
}
|
|
79
|
+
interface StxLockFilter {
|
|
80
|
+
type: "stx_lock";
|
|
81
|
+
lockedAddress?: string;
|
|
82
|
+
minAmount?: bigint;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Restrict a source to contracts conforming to a trait/standard (e.g. "sip-010")
|
|
86
|
+
* instead of a fixed contract — resolved from the contract registry at match time,
|
|
87
|
+
* as-of each processed block. Lets a source index "all SIP-010 tokens" etc.
|
|
88
|
+
*/
|
|
89
|
+
type TraitScope = {
|
|
90
|
+
trait?: string;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Scope a source to a DYNAMIC address set discovered from another source's
|
|
94
|
+
* events, instead of a fixed contract list.
|
|
95
|
+
*
|
|
96
|
+
* The standard shape it unlocks: a router plus pools created after you
|
|
97
|
+
* deploy. `contractId` arrays cover a set you know at authoring time; a
|
|
98
|
+
* factory covers the set that grows. It is deliberately NOT tied to contract
|
|
99
|
+
* deployment — the address can come from any field of any event, so it also
|
|
100
|
+
* covers launchpad-minted tokens, DAO extension allowlists, and registry
|
|
101
|
+
* entries.
|
|
102
|
+
*
|
|
103
|
+
* ```ts
|
|
104
|
+
* sources: {
|
|
105
|
+
* registry: {
|
|
106
|
+
* type: "print_event",
|
|
107
|
+
* contractId: REGISTRY,
|
|
108
|
+
* topic: "pool-created",
|
|
109
|
+
* prints: { "pool-created": { pool: "principal" } },
|
|
110
|
+
* },
|
|
111
|
+
* swaps: {
|
|
112
|
+
* type: "print_event",
|
|
113
|
+
* topic: "swap",
|
|
114
|
+
* // every pool the registry has ever announced, including new ones
|
|
115
|
+
* factory: { from: "registry", field: "data.pool" },
|
|
116
|
+
* },
|
|
117
|
+
* }
|
|
118
|
+
* ```
|
|
119
|
+
*
|
|
120
|
+
* Two guarantees the runtime provides:
|
|
121
|
+
* - **Same-block ordering** — a contract discovered in block N receives its
|
|
122
|
+
* own block-N events. Discovery runs before matching, within the block.
|
|
123
|
+
* - **Reorg-scoped** — the discovered set is stamped with the block that
|
|
124
|
+
* revealed it and rolled back with everything else on a fork, so an address
|
|
125
|
+
* announced on an orphaned chain does not linger forever.
|
|
126
|
+
*/
|
|
127
|
+
interface FactoryScope {
|
|
128
|
+
factory?: {
|
|
129
|
+
/** Source name whose events reveal the addresses. */
|
|
130
|
+
from: string;
|
|
131
|
+
/** Dotted path to the address on that source's payload
|
|
132
|
+
* (e.g. `"data.pool"`, `"contractId"`, `"data.token.id"`). */
|
|
133
|
+
field: string;
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
/** FT event filters */
|
|
137
|
+
interface FtTransferFilter extends TraitScope {
|
|
138
|
+
type: "ft_transfer";
|
|
139
|
+
assetIdentifier?: AssetIdentifier;
|
|
140
|
+
sender?: string;
|
|
141
|
+
recipient?: string;
|
|
142
|
+
minAmount?: bigint;
|
|
143
|
+
}
|
|
144
|
+
interface FtMintFilter extends TraitScope {
|
|
145
|
+
type: "ft_mint";
|
|
146
|
+
assetIdentifier?: AssetIdentifier;
|
|
147
|
+
recipient?: string;
|
|
148
|
+
minAmount?: bigint;
|
|
149
|
+
}
|
|
150
|
+
interface FtBurnFilter extends TraitScope {
|
|
151
|
+
type: "ft_burn";
|
|
152
|
+
assetIdentifier?: AssetIdentifier;
|
|
153
|
+
sender?: string;
|
|
154
|
+
minAmount?: bigint;
|
|
155
|
+
}
|
|
156
|
+
/** NFT event filters */
|
|
157
|
+
interface NftTransferFilter extends TraitScope {
|
|
158
|
+
type: "nft_transfer";
|
|
159
|
+
assetIdentifier?: AssetIdentifier;
|
|
160
|
+
sender?: string;
|
|
161
|
+
recipient?: string;
|
|
162
|
+
}
|
|
163
|
+
interface NftMintFilter extends TraitScope {
|
|
164
|
+
type: "nft_mint";
|
|
165
|
+
assetIdentifier?: AssetIdentifier;
|
|
166
|
+
recipient?: string;
|
|
167
|
+
}
|
|
168
|
+
interface NftBurnFilter extends TraitScope {
|
|
169
|
+
type: "nft_burn";
|
|
170
|
+
assetIdentifier?: AssetIdentifier;
|
|
171
|
+
sender?: string;
|
|
172
|
+
}
|
|
173
|
+
/** Contract event filters */
|
|
174
|
+
interface ContractCallFilter extends TraitScope, FactoryScope {
|
|
175
|
+
type: "contract_call";
|
|
176
|
+
/**
|
|
177
|
+
* One contract id, or a SET of them (max 20) — the standard DeFi shape is
|
|
178
|
+
* a router plus N pools, which used to cost N near-identical sources and
|
|
179
|
+
* handlers. Payload types are identical per `type`, so one handler serves
|
|
180
|
+
* the set and `event.contractId` disambiguates.
|
|
181
|
+
*
|
|
182
|
+
* Supports `*` wildcards (e.g. `"SP1ABC….pool-*"`). Mutually exclusive
|
|
183
|
+
* with `trait`, which resolves its own set per block.
|
|
184
|
+
*/
|
|
185
|
+
contractId?: string | readonly string[];
|
|
186
|
+
functionName?: string;
|
|
187
|
+
caller?: string;
|
|
188
|
+
/**
|
|
189
|
+
* Contract ABI (pass it `as const`) used to type `event.input` — the named,
|
|
190
|
+
* decoded function arguments. Dev-provided; serialized into the deployed
|
|
191
|
+
* definition and used at runtime to decode args by name. Omit to keep
|
|
192
|
+
* `event.args` as a positional `unknown[]`.
|
|
193
|
+
*
|
|
194
|
+
* Required whenever `functionName` is set. `secondlayer subgraphs deploy`
|
|
195
|
+
* fills it in from the deployed contract for a single concrete
|
|
196
|
+
* `contractId`; pass it yourself for wildcard, multi-contract or trait
|
|
197
|
+
* sources, or a local deploy (`normalizeAbi()` from
|
|
198
|
+
* `@secondlayer/stacks/clarity`).
|
|
199
|
+
*/
|
|
200
|
+
abi?: AbiContract2;
|
|
201
|
+
}
|
|
202
|
+
interface ContractDeployFilter {
|
|
203
|
+
type: "contract_deploy";
|
|
204
|
+
deployer?: string;
|
|
205
|
+
contractName?: string;
|
|
206
|
+
}
|
|
207
|
+
interface NestedContractCallFilter extends TraitScope, FactoryScope {
|
|
208
|
+
type: "nested_contract_call";
|
|
209
|
+
contractId?: string | readonly string[];
|
|
210
|
+
functionName?: string;
|
|
211
|
+
caller?: string;
|
|
212
|
+
sender?: string;
|
|
213
|
+
}
|
|
214
|
+
interface VarSetFilter extends TraitScope, FactoryScope {
|
|
215
|
+
type: "var_set";
|
|
216
|
+
contractId?: string | readonly string[];
|
|
217
|
+
varName?: string;
|
|
218
|
+
}
|
|
219
|
+
interface MapWriteFilter extends TraitScope, FactoryScope {
|
|
220
|
+
type: "map_set" | "map_insert" | "map_delete";
|
|
221
|
+
contractId?: string | readonly string[];
|
|
222
|
+
map?: string;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* One declared field of a print payload.
|
|
226
|
+
*
|
|
227
|
+
* A bare {@link ColumnType} is a required scalar (`amount: "uint"`). The
|
|
228
|
+
* composite forms exist because real print payloads are not flat: BNS-V2
|
|
229
|
+
* emits `name` as a NESTED tuple, and a `prints` vocabulary that could only
|
|
230
|
+
* say `"jsonb"` is why a handler reading flat `data.name` type-checked,
|
|
231
|
+
* deployed, and then decoded to null on every event.
|
|
232
|
+
*
|
|
233
|
+
* - `{ type: F, optional: true }` — the KEY becomes optional on `event.data`
|
|
234
|
+
* (mirrors `always_present: false` in the inferred schema).
|
|
235
|
+
* - `{ tuple: { … } }` — a nested tuple, typed all the way down.
|
|
236
|
+
* - `{ list: F }` — a list of `F`.
|
|
237
|
+
*/
|
|
238
|
+
type PrintField = ColumnType | {
|
|
239
|
+
type: PrintField;
|
|
240
|
+
optional: true;
|
|
241
|
+
} | {
|
|
242
|
+
tuple: Record<string, PrintField>;
|
|
243
|
+
} | {
|
|
244
|
+
list: PrintField;
|
|
245
|
+
};
|
|
246
|
+
/**
|
|
247
|
+
* Per-topic field schema for a print_event source. When declared, the handler's
|
|
248
|
+
* `event` is a discriminated union keyed by `topic` and `event.data` is typed
|
|
249
|
+
* per topic. Nested tuples, lists, and optional fields — see {@link PrintField}.
|
|
250
|
+
*
|
|
251
|
+
* Also opts the source into RUNTIME validation: a payload that does not match
|
|
252
|
+
* is skipped and logged rather than written as nulls.
|
|
253
|
+
*/
|
|
254
|
+
type PrintEventPrints = Record<string, Record<string, PrintField>>;
|
|
255
|
+
type PrintEventFields = FactoryScope & {
|
|
256
|
+
type: "print_event";
|
|
257
|
+
topic?: string;
|
|
258
|
+
};
|
|
259
|
+
/**
|
|
260
|
+
* Pinned to one or more contract ids with no trait — `prints` is required so
|
|
261
|
+
* `event.data` is typed and empty-table handlers cannot typecheck.
|
|
262
|
+
*/
|
|
263
|
+
type PinnedPrintEventFilter = PrintEventFields & {
|
|
264
|
+
contractId: string | readonly string[];
|
|
265
|
+
trait?: undefined;
|
|
266
|
+
prints: PrintEventPrints;
|
|
267
|
+
};
|
|
268
|
+
/**
|
|
269
|
+
* Trait-scoped print source (optionally narrowed by contractId). No single
|
|
270
|
+
* schema — `prints` stays optional.
|
|
271
|
+
*/
|
|
272
|
+
type TraitPrintEventFilter = PrintEventFields & {
|
|
273
|
+
contractId?: string | readonly string[];
|
|
274
|
+
trait: string;
|
|
275
|
+
prints?: PrintEventPrints;
|
|
276
|
+
};
|
|
277
|
+
/**
|
|
278
|
+
* Unpinned / factory-only print source (no contractId). `prints` optional.
|
|
279
|
+
*/
|
|
280
|
+
type UnpinnedPrintEventFilter = PrintEventFields & {
|
|
281
|
+
contractId?: undefined;
|
|
282
|
+
trait?: string;
|
|
283
|
+
prints?: PrintEventPrints;
|
|
284
|
+
};
|
|
285
|
+
/**
|
|
286
|
+
* Print-event filter. Pinned sources (contractId set, no trait) require
|
|
287
|
+
* `prints`; trait and unpinned sources may omit it.
|
|
288
|
+
*/
|
|
289
|
+
type PrintEventFilter = PinnedPrintEventFilter | TraitPrintEventFilter | UnpinnedPrintEventFilter;
|
|
290
|
+
/** All subgraph filter types — discriminated on `type` */
|
|
291
|
+
type SubgraphFilter = StxTransferFilter | StxMintFilter | StxBurnFilter | StxLockFilter | FtTransferFilter | FtMintFilter | FtBurnFilter | NftTransferFilter | NftMintFilter | NftBurnFilter | ContractCallFilter | ContractDeployFilter | PrintEventFilter | NestedContractCallFilter | VarSetFilter | MapWriteFilter;
|
|
292
|
+
/** Transaction metadata available in handlers */
|
|
293
|
+
interface TxMeta {
|
|
294
|
+
txId: string;
|
|
295
|
+
sender: string;
|
|
296
|
+
type: string;
|
|
297
|
+
status: string;
|
|
298
|
+
contractId?: string | null;
|
|
299
|
+
functionName?: string | null;
|
|
300
|
+
}
|
|
301
|
+
/** Context passed to subgraph handlers during event processing */
|
|
302
|
+
interface SubgraphContext {
|
|
303
|
+
block: {
|
|
304
|
+
height: number;
|
|
305
|
+
hash: string;
|
|
306
|
+
timestamp: number;
|
|
307
|
+
burnBlockHeight: number;
|
|
308
|
+
/** Nakamoto StacksBlockId, when the block row carries one. */
|
|
309
|
+
indexBlockHash?: string | null;
|
|
310
|
+
};
|
|
311
|
+
tx: TxMeta;
|
|
312
|
+
/**
|
|
313
|
+
* Read-only contract calls pinned to this block. Cached, so the same
|
|
314
|
+
* (contract, function, args) is fetched once per block rather than once
|
|
315
|
+
* per event.
|
|
316
|
+
*
|
|
317
|
+
* Erased here on purpose: this interface is compared structurally wherever
|
|
318
|
+
* a subgraph definition is passed around, and carrying an ABI-generic
|
|
319
|
+
* method pushes those comparisons past TS's instantiation depth. Handlers
|
|
320
|
+
* receive `TypedSubgraphContext`, which exposes the fully typed version.
|
|
321
|
+
*/
|
|
322
|
+
client: ErasedChainReadClient;
|
|
323
|
+
insert(table: string, row: Record<string, unknown>): void;
|
|
324
|
+
update(table: string, where: Record<string, unknown>, set: Record<string, unknown>): void;
|
|
325
|
+
upsert(table: string, key: Record<string, unknown>, row: Record<string, unknown>): void;
|
|
326
|
+
delete(table: string, where: Record<string, unknown>): void;
|
|
327
|
+
/**
|
|
328
|
+
* Atomic counter update — the blessed accumulator primitive. Applies
|
|
329
|
+
* `col = COALESCE(col, 0) + delta` per column (insert-or-add); deltas may
|
|
330
|
+
* be negative. Requires a uniqueKeys constraint matching `key`. Prefer
|
|
331
|
+
* this over read-modify-write handlers for running totals.
|
|
332
|
+
*/
|
|
333
|
+
increment(table: string, key: Record<string, unknown>, deltas: Record<string, bigint | number>): void;
|
|
334
|
+
findOne(table: string, where: Record<string, unknown>): Promise<Record<string, unknown> | null>;
|
|
335
|
+
findMany(table: string, where: Record<string, unknown>): Promise<Record<string, unknown>[]>;
|
|
336
|
+
}
|
|
337
|
+
/** Handler function that processes events and writes to the subgraph */
|
|
338
|
+
type SubgraphHandler = (event: Record<string, unknown>, ctx: SubgraphContext) => Promise<void> | void;
|
|
339
|
+
/** Complete subgraph definition */
|
|
340
|
+
interface SubgraphDefinition {
|
|
341
|
+
/** Unique subgraph name (lowercase, alphanumeric + hyphens) */
|
|
342
|
+
name: string;
|
|
343
|
+
/** Human description */
|
|
344
|
+
description?: string;
|
|
345
|
+
/** Block height to start indexing from (default: 1) */
|
|
346
|
+
startBlock?: number;
|
|
347
|
+
/** 'concurrent' = tip-first: live at tip now, history backfills behind.
|
|
348
|
+
* Requires order-tolerant handlers. Default 'blocking'. */
|
|
349
|
+
backfillMode?: "blocking" | "concurrent";
|
|
350
|
+
/** Named source filters — keys become handler keys */
|
|
351
|
+
sources: Record<string, SubgraphFilter>;
|
|
352
|
+
/** Tables in this subgraph */
|
|
353
|
+
schema: SubgraphSchema;
|
|
354
|
+
/** Handler functions, one per source, keyed by source name */
|
|
355
|
+
handlers: Record<string, SubgraphHandler>;
|
|
356
|
+
}
|
|
357
|
+
type ReplayStep = "pin" | "blocks" | "txs" | "inputs" | "handlers" | "rows";
|
|
358
|
+
interface ReplayFailure {
|
|
359
|
+
step: ReplayStep;
|
|
360
|
+
message: string;
|
|
361
|
+
height?: number;
|
|
362
|
+
table?: string;
|
|
363
|
+
key?: Record<string, unknown>;
|
|
364
|
+
/** The source could not serve the input: unchecked, not disproven. */
|
|
365
|
+
unavailable?: boolean;
|
|
366
|
+
}
|
|
367
|
+
interface ReplayResult {
|
|
368
|
+
ok: boolean;
|
|
369
|
+
/** Set when the range starts after startBlock and a handler read or merged earlier rows. */
|
|
370
|
+
inconclusive?: string;
|
|
371
|
+
from: number;
|
|
372
|
+
to: number;
|
|
373
|
+
blocks: number;
|
|
374
|
+
txs: number;
|
|
375
|
+
/** Named writes to the subgraph's contracts. */
|
|
376
|
+
writes: number;
|
|
377
|
+
/** Events offered to a handler. */
|
|
378
|
+
events: number;
|
|
379
|
+
handlerErrors: number;
|
|
380
|
+
/** MARF proofs the walk took (one per window top below the checkpoint). */
|
|
381
|
+
marfProofs: number;
|
|
382
|
+
/** The memory store at `to`. */
|
|
383
|
+
tables: Map<string, Record<string, unknown>[]>;
|
|
384
|
+
notes: string[];
|
|
385
|
+
/** The first entry is the first broken link. */
|
|
386
|
+
failures: ReplayFailure[];
|
|
387
|
+
}
|
|
388
|
+
interface ReplayOptions {
|
|
389
|
+
/** Needs `getStateWrites`: the names are what feed the handlers. */
|
|
390
|
+
source: ProofSource;
|
|
391
|
+
/** The bundled ESM as stored in `handler_code`. */
|
|
392
|
+
handlerCode: string;
|
|
393
|
+
from: number;
|
|
394
|
+
to: number;
|
|
395
|
+
/** Defaults to `MAINNET_CHECKPOINT`. */
|
|
396
|
+
checkpoint?: VerifyCheckpoint;
|
|
397
|
+
/** Defaults to the definition's `startBlock`. */
|
|
398
|
+
startBlock?: number;
|
|
399
|
+
onProgress?: (height: number) => void;
|
|
400
|
+
}
|
|
401
|
+
/** Verify blocks 512 at a time: the top by one MARF jump, the rest by parent links. */
|
|
402
|
+
declare const REPLAY_WINDOW = 512;
|
|
403
|
+
/**
|
|
404
|
+
* The contracts a state subgraph's writes come from, or an error when a
|
|
405
|
+
* source does not fix one: completeness would need every contract's writes.
|
|
406
|
+
*/
|
|
407
|
+
declare function replayContracts(def: Pick<SubgraphDefinition, "sources">): string[] | {
|
|
408
|
+
error: string;
|
|
409
|
+
};
|
|
410
|
+
type PinCheck = {
|
|
411
|
+
status: "ok";
|
|
412
|
+
notes: string[];
|
|
413
|
+
} | {
|
|
414
|
+
status: "unchecked";
|
|
415
|
+
notes: string[];
|
|
416
|
+
} | {
|
|
417
|
+
status: "failed";
|
|
418
|
+
failure: ReplayFailure;
|
|
419
|
+
notes: string[];
|
|
420
|
+
};
|
|
421
|
+
/**
|
|
422
|
+
* The served pin against the served bundle: the preimage must hash to the
|
|
423
|
+
* pin, and name this handler code, this schema and this startBlock. A runtime
|
|
424
|
+
* other than this package's is a note: rows can still match.
|
|
425
|
+
*/
|
|
426
|
+
declare function checkPin(served: {
|
|
427
|
+
pin: string | null;
|
|
428
|
+
pinPreimage: string | null;
|
|
429
|
+
handlerCode: string;
|
|
430
|
+
}, def: SubgraphDefinition): PinCheck;
|
|
431
|
+
/** Seams for tests: the block verifier and the burn height hint. */
|
|
432
|
+
interface ReplayDeps {
|
|
433
|
+
verify(height: number): Promise<BlockVerification>;
|
|
434
|
+
/** The source's (unproven) burn height for a consensus hash. */
|
|
435
|
+
burnHeightHint(consensusHash: string): Promise<number>;
|
|
436
|
+
}
|
|
437
|
+
/** The replay loop over an injected verifier. */
|
|
438
|
+
declare function replayBlocks(deps: ReplayDeps, opts: Omit<ReplayOptions, "source" | "checkpoint"> & {
|
|
439
|
+
bitcoinCheckpoint?: number;
|
|
440
|
+
}): Promise<ReplayResult>;
|
|
441
|
+
/** Verify every block in `[from, to]` from the checkpoint and recompute the subgraph's tables. */
|
|
442
|
+
declare function replaySubgraph(opts: ReplayOptions): Promise<ReplayResult>;
|
|
443
|
+
/**
|
|
444
|
+
* Evaluate a bundled handler (ESM, as stored in `handler_code`) inside a
|
|
445
|
+
* fresh deterministic realm and return its definition with every handler
|
|
446
|
+
* wrapped to receive the {@link deterministicContext} facade.
|
|
447
|
+
*/
|
|
448
|
+
declare function loadDeterministicDefinition(handlerCode: string): Promise<SubgraphDefinition>;
|
|
449
|
+
type Row = Record<string, unknown>;
|
|
450
|
+
interface TableComparison {
|
|
451
|
+
table: string;
|
|
452
|
+
/** Replayed rows the served table holds identically. */
|
|
453
|
+
equal: number;
|
|
454
|
+
/** Replayed keys the served table re-created after `to`: not checked. */
|
|
455
|
+
superseded: number;
|
|
456
|
+
/** sha256 over the sorted canonical replayed rows in the window, hex. */
|
|
457
|
+
digest: string;
|
|
458
|
+
/** The same digest over the served rows in the window. */
|
|
459
|
+
servedDigest: string;
|
|
460
|
+
}
|
|
461
|
+
interface RowComparison {
|
|
462
|
+
failures: ReplayFailure[];
|
|
463
|
+
tables: TableComparison[];
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* Compare the replayed tables with the served ones over `[from, to]` on
|
|
467
|
+
* `_block_height`. Keyed tables (first `uniqueKeys` tuple) compare row by
|
|
468
|
+
* row; unkeyed tables as multisets.
|
|
469
|
+
*/
|
|
470
|
+
declare function compareRows(schema: SubgraphSchema, replayed: {
|
|
471
|
+
from: number;
|
|
472
|
+
to: number;
|
|
473
|
+
tables: Map<string, Row[]>;
|
|
474
|
+
}, served: Map<string, Row[]>): RowComparison;
|
|
475
|
+
export { PinCheck, REPLAY_WINDOW, ReplayDeps, ReplayFailure, ReplayOptions, ReplayResult, ReplayStep, RowComparison, TableComparison, checkPin, compareRows, loadDeterministicDefinition, replayBlocks, replayContracts, replaySubgraph };
|