@secondlayer/subgraphs 3.16.0 → 3.17.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.
@@ -628,13 +628,16 @@ function resolveBlockSource(subgraph) {
628
628
  }
629
629
 
630
630
  // src/runtime/trigger-evaluator.ts
631
+ import { getSourceDb as getSourceDb2 } from "@secondlayer/shared/db";
631
632
  import { resolveTraitContractIds } from "@secondlayer/shared/db/queries/contracts";
632
633
  var TX_LEVEL_TRIGGER_TYPES = new Set(["contract_call", "contract_deploy"]);
634
+ var SETTLEMENT_TRIGGER_TYPE = "sbtc_withdrawal_swept_confirmed";
633
635
  var SBTC_TRIGGER_TYPES = new Set([
634
636
  "sbtc_deposit",
635
637
  "sbtc_withdrawal_create",
636
638
  "sbtc_withdrawal_accept",
637
- "sbtc_withdrawal_reject"
639
+ "sbtc_withdrawal_reject",
640
+ SETTLEMENT_TRIGGER_TYPE
638
641
  ]);
639
642
  function isSbtcTriggerType(type) {
640
643
  return SBTC_TRIGGER_TYPES.has(type);
@@ -698,10 +701,11 @@ function referencedTraits(chainSubs) {
698
701
  }
699
702
  return [...traits];
700
703
  }
701
- async function buildTraitContracts(db, chainSubs, asOfBlock) {
704
+ async function buildTraitContracts(chainSubs, asOfBlock, opts) {
705
+ const sourceDb = opts?.sourceDb ?? getSourceDb2();
702
706
  const resolved = new Map;
703
707
  for (const trait of referencedTraits(chainSubs)) {
704
- const ids = await resolveTraitContractIds(db, trait, asOfBlock);
708
+ const ids = await resolveTraitContractIds(sourceDb, trait, asOfBlock);
705
709
  resolved.set(trait, new Set(ids));
706
710
  }
707
711
  return resolved;
@@ -872,7 +876,7 @@ async function replayChainSubscription(db, sub, input) {
872
876
  for (let from = input.fromBlock;from <= input.toBlock; from += CHAIN_REPLAY_BATCH) {
873
877
  const to = Math.min(from + CHAIN_REPLAY_BATCH - 1, input.toBlock);
874
878
  const blocks = await source.loadBlockRange(from, to);
875
- const traitContracts = await buildTraitContracts(db, [sub], to);
879
+ const traitContracts = await buildTraitContracts([sub], to);
876
880
  for (let h = from;h <= to; h++) {
877
881
  const bd = blocks.get(h);
878
882
  if (!bd)
@@ -900,5 +904,5 @@ export {
900
904
  replaySubscription
901
905
  };
902
906
 
903
- //# debugId=52B7573F1126A78F64756E2164756E21
907
+ //# debugId=CB4A2ECFD309F74564756E2164756E21
904
908
  //# sourceMappingURL=replay.js.map
@@ -3,14 +3,14 @@
3
3
  "sources": ["../src/runtime/source-matcher.ts", "../src/runtime/replay.ts", "../src/schema/utils.ts", "../src/runtime/block-source.ts", "../src/runtime/batch-loader.ts", "../src/runtime/reconstruct.ts", "../src/runtime/trigger-evaluator.ts"],
4
4
  "sourcesContent": [
5
5
  "import type { SubgraphFilter } from \"../types.ts\";\n\nexport interface MatchedTx {\n\ttx: TxRecord;\n\tevents: EventRecord[];\n\t/** Source object key — used for handler dispatch */\n\tsourceName: string;\n}\n\ntype TxRecord = {\n\ttx_id: string;\n\ttype: string;\n\tsender: string;\n\tstatus: string;\n\t/** Position within the block — the runner sorts dispatch into chain order. */\n\ttx_index?: number;\n\tcontract_id?: string | null;\n\tfunction_name?: string | null;\n\tfunction_args?: unknown | null;\n\traw_result?: string | null;\n};\n\ntype EventRecord = {\n\tid: string;\n\ttx_id: string;\n\ttype: string;\n\tevent_index: number;\n\tdata: unknown;\n};\n\n// ── Wildcard matching (shared with v1) ──────────────────────────────\n\nconst patternCache = new Map<string, RegExp>();\n\nfunction matchPattern(value: string, pattern: string): boolean {\n\tif (!pattern.includes(\"*\")) return value === pattern;\n\tlet re = patternCache.get(pattern);\n\tif (!re) {\n\t\tconst regex = pattern\n\t\t\t.replace(/[.+^${}()|[\\]\\\\]/g, \"\\\\$&\")\n\t\t\t.replace(/\\*/g, \".*\");\n\t\tre = new RegExp(`^${regex}$`);\n\t\tpatternCache.set(pattern, re);\n\t}\n\treturn re.test(value);\n}\n\n// Trait → set of conforming contract IDs, resolved per block by the caller\n// (block-processor) from the contract registry. Kept as injected data so this\n// module stays pure/sync/DB-less.\nexport type TraitContracts = Map<string, ReadonlySet<string>>;\nconst EMPTY_SET: ReadonlySet<string> = new Set();\n\n/**\n * True when a filter's optional `trait` admits this contract: no trait → always\n * allowed; trait set → the contract must be in the resolved conforming set.\n */\nfunction traitAllows(\n\tfilter: SubgraphFilter,\n\tcontractId: string | undefined | null,\n\ttraitContracts: TraitContracts,\n): boolean {\n\tconst trait = (filter as { trait?: string }).trait;\n\tif (!trait) return true;\n\tif (!contractId) return false;\n\treturn (traitContracts.get(trait) ?? EMPTY_SET).has(contractId);\n}\n\n/** Extract the contract id from an asset identifier (`<contract>::<token>`). */\nfunction assetContract(assetId: string | undefined): string | undefined {\n\treturn assetId?.split(\"::\")[0];\n}\n\n// ── Per-filter-type matchers ────────────────────────────────────────\n\nfunction matchFilter(\n\tfilter: SubgraphFilter,\n\ttransactions: TxRecord[],\n\teventsByTx: Map<string, EventRecord[]>,\n\ttraitContracts: TraitContracts,\n): { tx: TxRecord; events: EventRecord[] }[] {\n\tconst results: { tx: TxRecord; events: EventRecord[] }[] = [];\n\n\tswitch (filter.type) {\n\t\t// ── STX events ──\n\t\tcase \"stx_transfer\":\n\t\tcase \"stx_mint\":\n\t\tcase \"stx_burn\":\n\t\tcase \"stx_lock\": {\n\t\t\tconst eventType = `${filter.type}_event`;\n\t\t\tfor (const tx of transactions) {\n\t\t\t\tconst txEvents = eventsByTx.get(tx.tx_id) ?? [];\n\t\t\t\tconst matched = txEvents.filter((e) => e.type === eventType);\n\t\t\t\tif (matched.length === 0) continue;\n\n\t\t\t\t// Apply address filters\n\t\t\t\tconst filtered = matched.filter((e) => {\n\t\t\t\t\tconst data = e.data as Record<string, unknown> | null;\n\t\t\t\t\tif (!data) return false;\n\t\t\t\t\tif (\"sender\" in filter && filter.sender) {\n\t\t\t\t\t\tif (!matchPattern(data.sender as string, filter.sender))\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t\tif (\"recipient\" in filter && filter.recipient) {\n\t\t\t\t\t\tif (!matchPattern(data.recipient as string, filter.recipient))\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t\tif (\"lockedAddress\" in filter && filter.lockedAddress) {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t!matchPattern(data.locked_address as string, filter.lockedAddress)\n\t\t\t\t\t\t)\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t\t// Amount filters\n\t\t\t\t\tif (\"minAmount\" in filter && filter.minAmount !== undefined) {\n\t\t\t\t\t\tconst amount = BigInt(\n\t\t\t\t\t\t\t(data.amount ?? data.locked_amount ?? \"0\") as string,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif (amount < filter.minAmount) return false;\n\t\t\t\t\t}\n\t\t\t\t\tif (\n\t\t\t\t\t\t\"maxAmount\" in filter &&\n\t\t\t\t\t\t(filter as { maxAmount?: bigint }).maxAmount !== undefined\n\t\t\t\t\t) {\n\t\t\t\t\t\tconst amount = BigInt((data.amount ?? \"0\") as string);\n\t\t\t\t\t\tif (amount > (filter as { maxAmount: bigint }).maxAmount)\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t\treturn true;\n\t\t\t\t});\n\n\t\t\t\tif (filtered.length > 0) {\n\t\t\t\t\tresults.push({ tx, events: filtered });\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\n\t\t// ── FT events ──\n\t\tcase \"ft_transfer\":\n\t\tcase \"ft_mint\":\n\t\tcase \"ft_burn\": {\n\t\t\tconst eventType = `${filter.type}_event`;\n\t\t\tfor (const tx of transactions) {\n\t\t\t\tconst txEvents = eventsByTx.get(tx.tx_id) ?? [];\n\t\t\t\tconst matched = txEvents.filter((e) => {\n\t\t\t\t\tif (e.type !== eventType) return false;\n\t\t\t\t\tconst data = e.data as Record<string, unknown> | null;\n\t\t\t\t\tif (!data) return false;\n\n\t\t\t\t\t// Asset identifier filter\n\t\t\t\t\tif (filter.assetIdentifier) {\n\t\t\t\t\t\tconst assetId = data.asset_identifier as string | undefined;\n\t\t\t\t\t\tif (!assetId || !matchPattern(assetId, filter.assetIdentifier))\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t\t// Trait scope — the asset's contract must conform.\n\t\t\t\t\tif (\n\t\t\t\t\t\t!traitAllows(\n\t\t\t\t\t\t\tfilter,\n\t\t\t\t\t\t\tassetContract(data.asset_identifier as string | undefined),\n\t\t\t\t\t\t\ttraitContracts,\n\t\t\t\t\t\t)\n\t\t\t\t\t)\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t// Address filters\n\t\t\t\t\tif (\"sender\" in filter && filter.sender) {\n\t\t\t\t\t\tif (!matchPattern(data.sender as string, filter.sender))\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t\tif (\"recipient\" in filter && filter.recipient) {\n\t\t\t\t\t\tif (!matchPattern(data.recipient as string, filter.recipient))\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t\t// Amount filter\n\t\t\t\t\tif (filter.minAmount !== undefined) {\n\t\t\t\t\t\tconst amount = BigInt((data.amount ?? \"0\") as string);\n\t\t\t\t\t\tif (amount < filter.minAmount) return false;\n\t\t\t\t\t}\n\t\t\t\t\treturn true;\n\t\t\t\t});\n\n\t\t\t\tif (matched.length > 0) {\n\t\t\t\t\tresults.push({ tx, events: matched });\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\n\t\t// ── NFT events ──\n\t\tcase \"nft_transfer\":\n\t\tcase \"nft_mint\":\n\t\tcase \"nft_burn\": {\n\t\t\tconst eventType = `${filter.type}_event`;\n\t\t\tfor (const tx of transactions) {\n\t\t\t\tconst txEvents = eventsByTx.get(tx.tx_id) ?? [];\n\t\t\t\tconst matched = txEvents.filter((e) => {\n\t\t\t\t\tif (e.type !== eventType) return false;\n\t\t\t\t\tconst data = e.data as Record<string, unknown> | null;\n\t\t\t\t\tif (!data) return false;\n\n\t\t\t\t\tif (filter.assetIdentifier) {\n\t\t\t\t\t\tconst assetId = data.asset_identifier as string | undefined;\n\t\t\t\t\t\tif (!assetId || !matchPattern(assetId, filter.assetIdentifier))\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t\tif (\n\t\t\t\t\t\t!traitAllows(\n\t\t\t\t\t\t\tfilter,\n\t\t\t\t\t\t\tassetContract(data.asset_identifier as string | undefined),\n\t\t\t\t\t\t\ttraitContracts,\n\t\t\t\t\t\t)\n\t\t\t\t\t)\n\t\t\t\t\t\treturn false;\n\t\t\t\t\tif (\"sender\" in filter && filter.sender) {\n\t\t\t\t\t\tif (!matchPattern(data.sender as string, filter.sender))\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t\tif (\"recipient\" in filter && filter.recipient) {\n\t\t\t\t\t\tif (!matchPattern(data.recipient as string, filter.recipient))\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t\treturn true;\n\t\t\t\t});\n\n\t\t\t\tif (matched.length > 0) {\n\t\t\t\t\tresults.push({ tx, events: matched });\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\n\t\t// ── Contract call ──\n\t\tcase \"contract_call\": {\n\t\t\tfor (const tx of transactions) {\n\t\t\t\tif (tx.type !== \"contract_call\") continue;\n\n\t\t\t\t// Contract filter\n\t\t\t\tif (filter.contractId) {\n\t\t\t\t\tif (\n\t\t\t\t\t\t!tx.contract_id ||\n\t\t\t\t\t\t!matchPattern(tx.contract_id, filter.contractId)\n\t\t\t\t\t)\n\t\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\t// Function filter\n\t\t\t\tif (filter.functionName) {\n\t\t\t\t\tif (\n\t\t\t\t\t\t!tx.function_name ||\n\t\t\t\t\t\t!matchPattern(tx.function_name, filter.functionName)\n\t\t\t\t\t)\n\t\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\t// Caller filter\n\t\t\t\tif (filter.caller) {\n\t\t\t\t\tif (!matchPattern(tx.sender, filter.caller)) continue;\n\t\t\t\t}\n\t\t\t\t// Trait scope — the called contract must conform.\n\t\t\t\tif (!traitAllows(filter, tx.contract_id, traitContracts)) continue;\n\n\t\t\t\tconst txEvents = eventsByTx.get(tx.tx_id) ?? [];\n\t\t\t\tresults.push({ tx, events: txEvents });\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\n\t\t// ── Contract deploy ──\n\t\tcase \"contract_deploy\": {\n\t\t\tfor (const tx of transactions) {\n\t\t\t\tif (tx.type !== \"smart_contract\") continue;\n\n\t\t\t\tif (filter.deployer) {\n\t\t\t\t\tif (!matchPattern(tx.sender, filter.deployer)) continue;\n\t\t\t\t}\n\t\t\t\tif (filter.contractName) {\n\t\t\t\t\tconst name = tx.contract_id?.split(\".\")[1] ?? \"\";\n\t\t\t\t\tif (!matchPattern(name, filter.contractName)) continue;\n\t\t\t\t}\n\n\t\t\t\tconst txEvents = eventsByTx.get(tx.tx_id) ?? [];\n\t\t\t\tresults.push({ tx, events: txEvents });\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\n\t\t// ── Print event ──\n\t\tcase \"print_event\": {\n\t\t\tfor (const tx of transactions) {\n\t\t\t\tconst txEvents = eventsByTx.get(tx.tx_id) ?? [];\n\t\t\t\tconst matched = txEvents.filter((e) => {\n\t\t\t\t\tif (e.type !== \"smart_contract_event\" && e.type !== \"contract_event\")\n\t\t\t\t\t\treturn false;\n\t\t\t\t\tconst data = e.data as Record<string, unknown> | null;\n\t\t\t\t\tif (!data) return false;\n\t\t\t\t\tif (data.topic !== \"print\") return false;\n\n\t\t\t\t\t// Contract filter — events store the contract under either\n\t\t\t\t\t// `contract_identifier` (legacy smart_contract_event payload)\n\t\t\t\t\t// or `contract_id` (current contract_event payload). Mirror\n\t\t\t\t\t// the streams query which checks both shapes.\n\t\t\t\t\tconst printContractId =\n\t\t\t\t\t\t(data.contract_identifier as string | undefined) ??\n\t\t\t\t\t\t(data.contract_id as string | undefined);\n\t\t\t\t\tif (filter.contractId) {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t!printContractId ||\n\t\t\t\t\t\t\t!matchPattern(printContractId, filter.contractId)\n\t\t\t\t\t\t)\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t\tif (!traitAllows(filter, printContractId, traitContracts))\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t// Topic filter — check the decoded Clarity value's topic field\n\t\t\t\t\t// At this stage data.value is still raw hex; topic filtering happens\n\t\t\t\t\t// after decode in the runner. For now, skip topic filtering here.\n\t\t\t\t\t// The runner will filter by topic after decoding.\n\t\t\t\t\treturn true;\n\t\t\t\t});\n\n\t\t\t\tif (matched.length > 0) {\n\t\t\t\t\tresults.push({ tx, events: matched });\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn results;\n}\n\n/**\n * Match named filters against a block's transactions and events.\n * Returns matches with sourceName = the object key from sources.\n */\nexport function matchSources(\n\tsources: Record<string, SubgraphFilter>,\n\ttransactions: TxRecord[],\n\tevents: EventRecord[],\n\ttraitContracts: TraitContracts = new Map(),\n): MatchedTx[] {\n\t// Index events by txId\n\tconst eventsByTx = new Map<string, EventRecord[]>();\n\tfor (const event of events) {\n\t\tconst list = eventsByTx.get(event.tx_id) ?? [];\n\t\tlist.push(event);\n\t\teventsByTx.set(event.tx_id, list);\n\t}\n\n\tconst seen = new Set<string>();\n\tconst results: MatchedTx[] = [];\n\n\tfor (const [sourceName, filter] of Object.entries(sources)) {\n\t\tconst matches = matchFilter(\n\t\t\tfilter,\n\t\t\ttransactions,\n\t\t\teventsByTx,\n\t\t\ttraitContracts,\n\t\t);\n\t\tfor (const match of matches) {\n\t\t\tconst dedupeKey = `${match.tx.tx_id}:${sourceName}`;\n\t\t\tif (!seen.has(dedupeKey)) {\n\t\t\t\tseen.add(dedupeKey);\n\t\t\t\tresults.push({ ...match, sourceName });\n\t\t\t}\n\t\t}\n\t}\n\n\treturn results;\n}\n",
6
- "import { createHash } from \"node:crypto\";\nimport { type Database, getTargetDb } from \"@secondlayer/shared/db\";\nimport type { Subscription } from \"@secondlayer/shared/db\";\nimport { getSubscription } from \"@secondlayer/shared/db/queries/subscriptions\";\nimport { logger } from \"@secondlayer/shared/logger\";\nimport { type Kysely, sql } from \"kysely\";\nimport { pgSchemaName as defaultSchemaName } from \"../schema/utils.ts\";\nimport { PublicApiBlockSource, buildHttpClient } from \"./block-source.ts\";\nimport {\n\tbuildSourcesMap,\n\tbuildTraitContracts,\n\temitChainOutbox,\n\tevaluateBlock,\n\treferencedEventTypes,\n} from \"./trigger-evaluator.ts\";\n\n/**\n * Replay historical subgraph rows as new outbox entries for a single\n * subscription. Rows are marked `is_replay=TRUE` so the emitter can\n * prioritize live deliveries (90/10 split) and the delivery log can\n * tag replays distinctly.\n *\n * Idempotency: `replayId` is deterministic over `(subscription_id,\n * fromBlock, toBlock)`, so re-running the same replay range is a no-op\n * thanks to the unique `(subscription_id, dedup_key)` constraint. A\n * user who actually wants to re-deliver the same range passes a\n * distinct `replayIdSuffix` (e.g. a timestamp) to get a fresh key.\n */\n\nconst BATCH_SIZE = 500;\n\nfunction replayDedupKey(\n\tsubgraphName: string,\n\ttableName: string,\n\trow: Record<string, unknown>,\n\treplayId: string,\n): string {\n\tconst canonical = `replay:${replayId}:${subgraphName}:${tableName}:${stableStringify(row)}`;\n\treturn createHash(\"sha256\").update(canonical).digest(\"hex\").slice(0, 32);\n}\n\nfunction stableStringify(obj: Record<string, unknown>): string {\n\tconst keys = Object.keys(obj).sort();\n\treturn JSON.stringify(\n\t\tkeys.reduce<Record<string, unknown>>((acc, k) => {\n\t\t\tacc[k] = obj[k];\n\t\t\treturn acc;\n\t\t}, {}),\n\t);\n}\n\nexport interface ReplayInput {\n\taccountId: string;\n\tsubscriptionId: string;\n\tfromBlock: number;\n\ttoBlock: number;\n\t/** Force re-delivery by appending a unique suffix to the replay id. */\n\treplayIdSuffix?: string;\n}\n\nfunction deterministicReplayId(\n\tsubscriptionId: string,\n\tfromBlock: number,\n\ttoBlock: number,\n\tsuffix?: string,\n): string {\n\tconst canonical = `${subscriptionId}:${fromBlock}:${toBlock}${suffix ? `:${suffix}` : \"\"}`;\n\treturn createHash(\"sha256\").update(canonical).digest(\"hex\").slice(0, 16);\n}\n\nexport interface ReplayResult {\n\treplayId: string;\n\tenqueuedCount: number;\n\tscannedCount: number;\n}\n\nasync function resolveSchemaName(\n\tdb: Kysely<Database>,\n\tsubgraphName: string,\n): Promise<string> {\n\tconst row = await db\n\t\t.selectFrom(\"subgraphs\")\n\t\t.select(\"schema_name\")\n\t\t.where(\"name\", \"=\", subgraphName)\n\t\t.executeTakeFirst();\n\tif (!row) {\n\t\tthrow new Error(\n\t\t\t`Subgraph \"${subgraphName}\" not registered — cannot replay its rows. Deploy the subgraph first.`,\n\t\t);\n\t}\n\treturn row.schema_name ?? defaultSchemaName(subgraphName);\n}\n\nexport async function replaySubscription(\n\tinput: ReplayInput,\n): Promise<ReplayResult> {\n\tif (input.fromBlock > input.toBlock) {\n\t\tthrow new Error(\"fromBlock must be <= toBlock\");\n\t}\n\tif (input.toBlock - input.fromBlock > 100_000) {\n\t\tthrow new Error(\"replay range exceeds 100k blocks\");\n\t}\n\n\tconst db = getTargetDb();\n\tconst sub = await getSubscription(db, input.accountId, input.subscriptionId);\n\tif (!sub) throw new Error(\"Subscription not found\");\n\n\t// Chain subs have no processed table — they react to raw chain events. Replay\n\t// re-runs the pure matcher over the canonical block range instead of scanning\n\t// rows.\n\tif (sub.kind === \"chain\") {\n\t\treturn replayChainSubscription(db, sub, input);\n\t}\n\n\tconst subgraphName = sub.subgraph_name;\n\tconst tableName = sub.table_name;\n\tif (sub.kind !== \"subgraph\" || !subgraphName || !tableName) {\n\t\tthrow new Error(\n\t\t\t\"replay is only supported for subgraph or chain subscriptions\",\n\t\t);\n\t}\n\n\tconst schema = await resolveSchemaName(db, subgraphName);\n\tconst replayId = deterministicReplayId(\n\t\tsub.id,\n\t\tinput.fromBlock,\n\t\tinput.toBlock,\n\t\tinput.replayIdSuffix,\n\t);\n\n\tlet scanned = 0;\n\tlet enqueued = 0;\n\tlet offset = 0;\n\n\twhile (true) {\n\t\tconst { rows } = await sql<\n\t\t\tRecord<string, unknown>\n\t\t>`SELECT * FROM ${sql.raw(`\"${schema}\".\"${tableName}\"`)}\n\t\t\tWHERE _block_height >= ${sql.lit(input.fromBlock)}\n\t\t\t\tAND _block_height <= ${sql.lit(input.toBlock)}\n\t\t\tORDER BY _block_height, _created_at\n\t\t\tLIMIT ${sql.lit(BATCH_SIZE)} OFFSET ${sql.lit(offset)}`.execute(db);\n\n\t\tif (rows.length === 0) break;\n\t\tscanned += rows.length;\n\n\t\tconst inserts = rows.map((row) => ({\n\t\t\tsubscription_id: sub.id,\n\t\t\tsubgraph_name: subgraphName,\n\t\t\ttable_name: tableName,\n\t\t\tblock_height: Number(row._block_height),\n\t\t\ttx_id: (row._tx_id as string | undefined) ?? null,\n\t\t\trow_pk: {\n\t\t\t\tblockHeight: Number(row._block_height),\n\t\t\t\ttxId: row._tx_id ?? \"\",\n\t\t\t\treplayId,\n\t\t\t},\n\t\t\tevent_type: `${subgraphName}.${tableName}.replay`,\n\t\t\tpayload: row,\n\t\t\tdedup_key: replayDedupKey(subgraphName, tableName, row, replayId),\n\t\t\tis_replay: true,\n\t\t}));\n\n\t\tconst result = await db\n\t\t\t.insertInto(\"subscription_outbox\")\n\t\t\t.values(inserts)\n\t\t\t.onConflict((oc) =>\n\t\t\t\toc.columns([\"subscription_id\", \"dedup_key\"]).doNothing(),\n\t\t\t)\n\t\t\t.executeTakeFirst();\n\t\tenqueued += Number(result.numInsertedOrUpdatedRows ?? 0);\n\n\t\tif (rows.length < BATCH_SIZE) break;\n\t\toffset += BATCH_SIZE;\n\t}\n\n\tlogger.info(\"Replay enqueued\", {\n\t\tsubscription: sub.name,\n\t\treplayId,\n\t\tscanned,\n\t\tenqueued,\n\t\tfromBlock: input.fromBlock,\n\t\ttoBlock: input.toBlock,\n\t});\n\n\treturn { replayId, enqueuedCount: enqueued, scannedCount: scanned };\n}\n\nconst CHAIN_REPLAY_BATCH = 200;\n\n/**\n * Replay a chain subscription by re-running the pure matcher over a historical\n * canonical block range and emitting fresh apply rows. Unlike subgraph replay\n * there is no processed table to scan — the matcher is range-driven, so we\n * reload canonical blocks off the public Index/Streams clock and re-match.\n *\n * Rows are emitted with `is_replay=TRUE` and replay-namespaced dedup keys, and —\n * critically — this never advances `trigger_evaluator_state`: replay is\n * historical and must not move the live forward cursor.\n */\nasync function replayChainSubscription(\n\tdb: Kysely<Database>,\n\tsub: Subscription,\n\tinput: ReplayInput,\n): Promise<ReplayResult> {\n\tconst replayId = deterministicReplayId(\n\t\tsub.id,\n\t\tinput.fromBlock,\n\t\tinput.toBlock,\n\t\tinput.replayIdSuffix,\n\t);\n\n\tconst { sources, keyMeta } = buildSourcesMap([sub]);\n\tconst source = new PublicApiBlockSource(\n\t\tbuildHttpClient(),\n\t\treferencedEventTypes([sub]),\n\t);\n\n\tlet scanned = 0;\n\tlet enqueued = 0;\n\tfor (\n\t\tlet from = input.fromBlock;\n\t\tfrom <= input.toBlock;\n\t\tfrom += CHAIN_REPLAY_BATCH\n\t) {\n\t\tconst to = Math.min(from + CHAIN_REPLAY_BATCH - 1, input.toBlock);\n\t\tconst blocks = await source.loadBlockRange(from, to);\n\t\t// Trait membership only grows; resolve once per batch as of its top height.\n\t\tconst traitContracts = await buildTraitContracts(db, [sub], to);\n\t\tfor (let h = from; h <= to; h++) {\n\t\t\tconst bd = blocks.get(h);\n\t\t\tif (!bd) continue;\n\t\t\tscanned++;\n\t\t\tconst matches = evaluateBlock(bd, sources, traitContracts);\n\t\t\tif (matches.length === 0) continue;\n\t\t\tenqueued += await emitChainOutbox(\n\t\t\t\tdb,\n\t\t\t\tmatches,\n\t\t\t\tkeyMeta,\n\t\t\t\th,\n\t\t\t\tbd.block.hash,\n\t\t\t\t{\n\t\t\t\t\treplayId,\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\t}\n\n\tlogger.info(\"Chain replay enqueued\", {\n\t\tsubscription: sub.name,\n\t\treplayId,\n\t\tscanned,\n\t\tenqueued,\n\t\tfromBlock: input.fromBlock,\n\t\ttoBlock: input.toBlock,\n\t});\n\n\treturn { replayId, enqueuedCount: enqueued, scannedCount: scanned };\n}\n",
6
+ "import { createHash } from \"node:crypto\";\nimport { type Database, getTargetDb } from \"@secondlayer/shared/db\";\nimport type { Subscription } from \"@secondlayer/shared/db\";\nimport { getSubscription } from \"@secondlayer/shared/db/queries/subscriptions\";\nimport { logger } from \"@secondlayer/shared/logger\";\nimport { type Kysely, sql } from \"kysely\";\nimport { pgSchemaName as defaultSchemaName } from \"../schema/utils.ts\";\nimport { PublicApiBlockSource, buildHttpClient } from \"./block-source.ts\";\nimport {\n\tbuildSourcesMap,\n\tbuildTraitContracts,\n\temitChainOutbox,\n\tevaluateBlock,\n\treferencedEventTypes,\n} from \"./trigger-evaluator.ts\";\n\n/**\n * Replay historical subgraph rows as new outbox entries for a single\n * subscription. Rows are marked `is_replay=TRUE` so the emitter can\n * prioritize live deliveries (90/10 split) and the delivery log can\n * tag replays distinctly.\n *\n * Idempotency: `replayId` is deterministic over `(subscription_id,\n * fromBlock, toBlock)`, so re-running the same replay range is a no-op\n * thanks to the unique `(subscription_id, dedup_key)` constraint. A\n * user who actually wants to re-deliver the same range passes a\n * distinct `replayIdSuffix` (e.g. a timestamp) to get a fresh key.\n */\n\nconst BATCH_SIZE = 500;\n\nfunction replayDedupKey(\n\tsubgraphName: string,\n\ttableName: string,\n\trow: Record<string, unknown>,\n\treplayId: string,\n): string {\n\tconst canonical = `replay:${replayId}:${subgraphName}:${tableName}:${stableStringify(row)}`;\n\treturn createHash(\"sha256\").update(canonical).digest(\"hex\").slice(0, 32);\n}\n\nfunction stableStringify(obj: Record<string, unknown>): string {\n\tconst keys = Object.keys(obj).sort();\n\treturn JSON.stringify(\n\t\tkeys.reduce<Record<string, unknown>>((acc, k) => {\n\t\t\tacc[k] = obj[k];\n\t\t\treturn acc;\n\t\t}, {}),\n\t);\n}\n\nexport interface ReplayInput {\n\taccountId: string;\n\tsubscriptionId: string;\n\tfromBlock: number;\n\ttoBlock: number;\n\t/** Force re-delivery by appending a unique suffix to the replay id. */\n\treplayIdSuffix?: string;\n}\n\nfunction deterministicReplayId(\n\tsubscriptionId: string,\n\tfromBlock: number,\n\ttoBlock: number,\n\tsuffix?: string,\n): string {\n\tconst canonical = `${subscriptionId}:${fromBlock}:${toBlock}${suffix ? `:${suffix}` : \"\"}`;\n\treturn createHash(\"sha256\").update(canonical).digest(\"hex\").slice(0, 16);\n}\n\nexport interface ReplayResult {\n\treplayId: string;\n\tenqueuedCount: number;\n\tscannedCount: number;\n}\n\nasync function resolveSchemaName(\n\tdb: Kysely<Database>,\n\tsubgraphName: string,\n): Promise<string> {\n\tconst row = await db\n\t\t.selectFrom(\"subgraphs\")\n\t\t.select(\"schema_name\")\n\t\t.where(\"name\", \"=\", subgraphName)\n\t\t.executeTakeFirst();\n\tif (!row) {\n\t\tthrow new Error(\n\t\t\t`Subgraph \"${subgraphName}\" not registered — cannot replay its rows. Deploy the subgraph first.`,\n\t\t);\n\t}\n\treturn row.schema_name ?? defaultSchemaName(subgraphName);\n}\n\nexport async function replaySubscription(\n\tinput: ReplayInput,\n): Promise<ReplayResult> {\n\tif (input.fromBlock > input.toBlock) {\n\t\tthrow new Error(\"fromBlock must be <= toBlock\");\n\t}\n\tif (input.toBlock - input.fromBlock > 100_000) {\n\t\tthrow new Error(\"replay range exceeds 100k blocks\");\n\t}\n\n\tconst db = getTargetDb();\n\tconst sub = await getSubscription(db, input.accountId, input.subscriptionId);\n\tif (!sub) throw new Error(\"Subscription not found\");\n\n\t// Chain subs have no processed table — they react to raw chain events. Replay\n\t// re-runs the pure matcher over the canonical block range instead of scanning\n\t// rows.\n\tif (sub.kind === \"chain\") {\n\t\treturn replayChainSubscription(db, sub, input);\n\t}\n\n\tconst subgraphName = sub.subgraph_name;\n\tconst tableName = sub.table_name;\n\tif (sub.kind !== \"subgraph\" || !subgraphName || !tableName) {\n\t\tthrow new Error(\n\t\t\t\"replay is only supported for subgraph or chain subscriptions\",\n\t\t);\n\t}\n\n\tconst schema = await resolveSchemaName(db, subgraphName);\n\tconst replayId = deterministicReplayId(\n\t\tsub.id,\n\t\tinput.fromBlock,\n\t\tinput.toBlock,\n\t\tinput.replayIdSuffix,\n\t);\n\n\tlet scanned = 0;\n\tlet enqueued = 0;\n\tlet offset = 0;\n\n\twhile (true) {\n\t\tconst { rows } = await sql<\n\t\t\tRecord<string, unknown>\n\t\t>`SELECT * FROM ${sql.raw(`\"${schema}\".\"${tableName}\"`)}\n\t\t\tWHERE _block_height >= ${sql.lit(input.fromBlock)}\n\t\t\t\tAND _block_height <= ${sql.lit(input.toBlock)}\n\t\t\tORDER BY _block_height, _created_at\n\t\t\tLIMIT ${sql.lit(BATCH_SIZE)} OFFSET ${sql.lit(offset)}`.execute(db);\n\n\t\tif (rows.length === 0) break;\n\t\tscanned += rows.length;\n\n\t\tconst inserts = rows.map((row) => ({\n\t\t\tsubscription_id: sub.id,\n\t\t\tsubgraph_name: subgraphName,\n\t\t\ttable_name: tableName,\n\t\t\tblock_height: Number(row._block_height),\n\t\t\ttx_id: (row._tx_id as string | undefined) ?? null,\n\t\t\trow_pk: {\n\t\t\t\tblockHeight: Number(row._block_height),\n\t\t\t\ttxId: row._tx_id ?? \"\",\n\t\t\t\treplayId,\n\t\t\t},\n\t\t\tevent_type: `${subgraphName}.${tableName}.replay`,\n\t\t\tpayload: row,\n\t\t\tdedup_key: replayDedupKey(subgraphName, tableName, row, replayId),\n\t\t\tis_replay: true,\n\t\t}));\n\n\t\tconst result = await db\n\t\t\t.insertInto(\"subscription_outbox\")\n\t\t\t.values(inserts)\n\t\t\t.onConflict((oc) =>\n\t\t\t\toc.columns([\"subscription_id\", \"dedup_key\"]).doNothing(),\n\t\t\t)\n\t\t\t.executeTakeFirst();\n\t\tenqueued += Number(result.numInsertedOrUpdatedRows ?? 0);\n\n\t\tif (rows.length < BATCH_SIZE) break;\n\t\toffset += BATCH_SIZE;\n\t}\n\n\tlogger.info(\"Replay enqueued\", {\n\t\tsubscription: sub.name,\n\t\treplayId,\n\t\tscanned,\n\t\tenqueued,\n\t\tfromBlock: input.fromBlock,\n\t\ttoBlock: input.toBlock,\n\t});\n\n\treturn { replayId, enqueuedCount: enqueued, scannedCount: scanned };\n}\n\nconst CHAIN_REPLAY_BATCH = 200;\n\n/**\n * Replay a chain subscription by re-running the pure matcher over a historical\n * canonical block range and emitting fresh apply rows. Unlike subgraph replay\n * there is no processed table to scan — the matcher is range-driven, so we\n * reload canonical blocks off the public Index/Streams clock and re-match.\n *\n * Rows are emitted with `is_replay=TRUE` and replay-namespaced dedup keys, and —\n * critically — this never advances `trigger_evaluator_state`: replay is\n * historical and must not move the live forward cursor.\n */\nasync function replayChainSubscription(\n\tdb: Kysely<Database>,\n\tsub: Subscription,\n\tinput: ReplayInput,\n): Promise<ReplayResult> {\n\tconst replayId = deterministicReplayId(\n\t\tsub.id,\n\t\tinput.fromBlock,\n\t\tinput.toBlock,\n\t\tinput.replayIdSuffix,\n\t);\n\n\tconst { sources, keyMeta } = buildSourcesMap([sub]);\n\tconst source = new PublicApiBlockSource(\n\t\tbuildHttpClient(),\n\t\treferencedEventTypes([sub]),\n\t);\n\n\tlet scanned = 0;\n\tlet enqueued = 0;\n\tfor (\n\t\tlet from = input.fromBlock;\n\t\tfrom <= input.toBlock;\n\t\tfrom += CHAIN_REPLAY_BATCH\n\t) {\n\t\tconst to = Math.min(from + CHAIN_REPLAY_BATCH - 1, input.toBlock);\n\t\tconst blocks = await source.loadBlockRange(from, to);\n\t\t// Trait membership only grows; resolve once per batch as of its top height.\n\t\tconst traitContracts = await buildTraitContracts([sub], to);\n\t\tfor (let h = from; h <= to; h++) {\n\t\t\tconst bd = blocks.get(h);\n\t\t\tif (!bd) continue;\n\t\t\tscanned++;\n\t\t\tconst matches = evaluateBlock(bd, sources, traitContracts);\n\t\t\tif (matches.length === 0) continue;\n\t\t\tenqueued += await emitChainOutbox(\n\t\t\t\tdb,\n\t\t\t\tmatches,\n\t\t\t\tkeyMeta,\n\t\t\t\th,\n\t\t\t\tbd.block.hash,\n\t\t\t\t{\n\t\t\t\t\treplayId,\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\t}\n\n\tlogger.info(\"Chain replay enqueued\", {\n\t\tsubscription: sub.name,\n\t\treplayId,\n\t\tscanned,\n\t\tenqueued,\n\t\tfromBlock: input.fromBlock,\n\t\ttoBlock: input.toBlock,\n\t});\n\n\treturn { replayId, enqueuedCount: enqueued, scannedCount: scanned };\n}\n",
7
7
  "// Re-export canonical pgSchemaName from shared\nexport { pgSchemaName } from \"@secondlayer/shared/db/queries/subgraphs\";\n",
8
8
  "import { getSourceDb } from \"@secondlayer/shared/db\";\nimport type { Transaction } from \"@secondlayer/shared/db\";\nimport {\n\ttype IndexEventRow,\n\tIndexHttpClient,\n\ttype IndexTransactionRow,\n} from \"@secondlayer/shared/index-http\";\nimport { logger } from \"@secondlayer/shared/logger\";\nimport type { SubgraphDefinition, SubgraphFilter } from \"../types.ts\";\nimport { type BlockData, loadBlockRange } from \"./batch-loader.ts\";\nimport {\n\treconstructBlock,\n\treconstructEvent,\n\treconstructTransaction,\n\treconstructTxFromEventRow,\n} from \"./reconstruct.ts\";\n\n/**\n * Where the subgraph runtime reads canonical chain data. Today it taps the\n * indexer Postgres directly (`PostgresBlockSource`); the re-point adds a\n * `PublicApiBlockSource` that consumes the Streams clock + Index data over\n * HTTP. `matchSources` / handlers / flush / outbox are unchanged — only the\n * loader + tip swap behind this seam.\n */\nexport interface BlockSource {\n\t/** Highest canonical block height available to process. */\n\tgetTip(): Promise<number>;\n\t/** Canonical block data for [fromHeight, toHeight], keyed by height. */\n\tloadBlockRange(\n\t\tfromHeight: number,\n\t\ttoHeight: number,\n\t): Promise<Map<number, BlockData>>;\n\t/** Sparse-scan probe: lowest height in (afterHeight, untilHeight] holding\n\t * an event this source's subgraph could match, or null when the rest of\n\t * the range is empty. Optional — only event-scoped sources support it. */\n\tnextDataHeight?(\n\t\tafterHeight: number,\n\t\tuntilHeight: number,\n\t): Promise<number | null>;\n}\n\n/** A (decoded event type, optional contract scope) pair the sparse probe\n * checks. Contract scoping is what makes token-subgraph reindexes leap over\n * everything that isn't their token. */\nexport type SparseProbeTarget = { eventType: string; contractId?: string };\n\n/** Sparse scanning is sound only when EVERY source is an event-type filter —\n * a contract_call/contract_deploy source matches transactions, which the\n * event probe can't see. */\nexport function canSparseScan(subgraph: SubgraphDefinition): boolean {\n\tif (Array.isArray(subgraph.sources)) return false;\n\tconst filters = sourceFilters(subgraph);\n\tif (filters.length === 0) return false;\n\treturn filters.every((f) => Boolean(EVENT_FILTER_TO_INDEX_TYPE[f.type]));\n}\n\n/** Probe targets for a subgraph's filters: decoded type + contract scope when\n * the filter pins one (assetIdentifier \"SP….contract::asset\" or contractId). */\nexport function sparseProbeTargets(\n\tsubgraph: SubgraphDefinition,\n): SparseProbeTarget[] {\n\tconst targets = new Map<string, SparseProbeTarget>();\n\tfor (const f of sourceFilters(subgraph)) {\n\t\tconst eventType = EVENT_FILTER_TO_INDEX_TYPE[f.type];\n\t\tif (!eventType) continue;\n\t\tconst scoped = f as { assetIdentifier?: string; contractId?: string };\n\t\tconst contractId =\n\t\t\tscoped.contractId ?? scoped.assetIdentifier?.split(\"::\")[0];\n\t\tconst key = `${eventType}|${contractId ?? \"\"}`;\n\t\ttargets.set(key, { eventType, ...(contractId ? { contractId } : {}) });\n\t}\n\treturn [...targets.values()];\n}\n\n/** Reads directly from the shared indexer Postgres (the original behavior). */\nexport class PostgresBlockSource implements BlockSource {\n\tasync getTip(): Promise<number> {\n\t\tconst progress = await getSourceDb()\n\t\t\t.selectFrom(\"index_progress\")\n\t\t\t.selectAll()\n\t\t\t.where(\"network\", \"=\", process.env.NETWORK ?? \"mainnet\")\n\t\t\t.executeTakeFirst();\n\t\treturn progress ? Number(progress.highest_seen_block) : 0;\n\t}\n\n\tloadBlockRange(\n\t\tfromHeight: number,\n\t\ttoHeight: number,\n\t): Promise<Map<number, BlockData>> {\n\t\treturn loadBlockRange(getSourceDb(), fromHeight, toHeight);\n\t}\n}\n\n// Subgraph source filter types that map to a decoded Index event_type. The\n// `_event` suffix is the runtime's raw form; print is keyed `print_event`.\nconst EVENT_FILTER_TO_INDEX_TYPE: Record<string, string> = {\n\tstx_transfer: \"stx_transfer\",\n\tstx_mint: \"stx_mint\",\n\tstx_burn: \"stx_burn\",\n\tstx_lock: \"stx_lock\",\n\tft_transfer: \"ft_transfer\",\n\tft_mint: \"ft_mint\",\n\tft_burn: \"ft_burn\",\n\tnft_transfer: \"nft_transfer\",\n\tnft_mint: \"nft_mint\",\n\tnft_burn: \"nft_burn\",\n\tprint_event: \"print\",\n};\n\n// Tx-level source types — matched against /v1/index/transactions, not events.\nconst TX_SOURCE_TYPES = new Set([\"contract_call\", \"contract_deploy\"]);\nconst ALL_INDEX_EVENT_TYPES = [\n\t...new Set(Object.values(EVENT_FILTER_TO_INDEX_TYPE)),\n];\n\nfunction sourceFilters(subgraph: SubgraphDefinition): SubgraphFilter[] {\n\tconst sources = subgraph.sources;\n\treturn Array.isArray(sources)\n\t\t? (sources as SubgraphFilter[])\n\t\t: Object.values(sources as Record<string, SubgraphFilter>);\n}\n\n/**\n * True when any source matches transactions (contract_call / contract_deploy):\n * the handler receives the full tx, so the loader must fetch real transactions.\n * Event-only subgraphs skip walkTransactions and synthesize the tx from joined\n * event context instead (the ~37x reindex over-fetch; see indexing-speed plan).\n */\nexport function needsTransactionData(subgraph: SubgraphDefinition): boolean {\n\treturn sourceFilters(subgraph).some((f) => TX_SOURCE_TYPES.has(f.type));\n}\n\n/** Build the (few) event-bearing txs from joined event context, one per tx_id —\n * the event-only replacement for draining every transaction in the range. */\nfunction synthesizeTxsFromEvents(events: IndexEventRow[]): Transaction[] {\n\tconst byId = new Map<string, Transaction>();\n\tfor (const e of events) {\n\t\tif (!byId.has(e.tx_id)) byId.set(e.tx_id, reconstructTxFromEventRow(e));\n\t}\n\treturn [...byId.values()];\n}\n\n/**\n * The Index event_types the loader must fetch for a set of source filter types.\n * A contract_call/contract_deploy source matches a tx and hands its FULL event\n * set to the handler, so when one is present we fetch every event type (the\n * matched tx's events must be complete); otherwise just the referenced types.\n * Shared by the subgraph loader and the chain-trigger evaluator.\n */\nexport function indexEventTypesForFilterTypes(filterTypes: string[]): string[] {\n\tif (filterTypes.some((t) => TX_SOURCE_TYPES.has(t))) {\n\t\treturn ALL_INDEX_EVENT_TYPES;\n\t}\n\tconst types = new Set<string>();\n\tfor (const t of filterTypes) {\n\t\tconst indexType = EVENT_FILTER_TO_INDEX_TYPE[t];\n\t\tif (indexType) types.add(indexType);\n\t}\n\treturn [...types];\n}\n\nfunction referencedIndexEventTypes(subgraph: SubgraphDefinition): string[] {\n\treturn indexEventTypesForFilterTypes(\n\t\tsourceFilters(subgraph).map((f) => f.type),\n\t);\n}\n\n/**\n * streams-index eligibility: every source must be a known event-type or\n * contract_call/contract_deploy filter (no array-style sources, which leak the\n * unreconstructable `_eventId`). Trait scope IS allowed — trait resolution\n * reads the contract registry on the platform DB (`targetDb`), which the\n * processor always holds, so it's source-independent. Everything else stays on\n * the DB tap.\n */\nexport function isStreamsIndexEligible(subgraph: SubgraphDefinition): boolean {\n\tif (Array.isArray(subgraph.sources)) return false;\n\tconst filters = sourceFilters(subgraph);\n\tif (filters.length === 0) return false;\n\tfor (const f of filters) {\n\t\tconst known =\n\t\t\tEVENT_FILTER_TO_INDEX_TYPE[f.type] || TX_SOURCE_TYPES.has(f.type);\n\t\tif (!known) return false;\n\t}\n\treturn true;\n}\n\n/** Streams clock + Index data plane, reconstructed into raw BlockData rows. */\nexport class PublicApiBlockSource implements BlockSource {\n\tconstructor(\n\t\tprivate readonly http: IndexHttpClient,\n\t\tprivate readonly eventTypes: string[],\n\t\t/** When set, enables the sparse-scan probe (event-scoped subgraphs). */\n\t\tprivate readonly probeTargets?: SparseProbeTarget[],\n\t\t/** False for event-only subgraphs → skip walkTransactions, synthesize the\n\t\t * tx from joined event context. Defaults true (safe / unchanged). */\n\t\tprivate readonly needsTransactions = true,\n\t) {}\n\n\t/** Lowest height in (after, until] any probe target hits, or null. */\n\tasync nextDataHeight(\n\t\tafterHeight: number,\n\t\tuntilHeight: number,\n\t): Promise<number | null> {\n\t\tif (!this.probeTargets?.length) return afterHeight + 1;\n\t\tconst hits = await Promise.all(\n\t\t\tthis.probeTargets.map((t) =>\n\t\t\t\tthis.http.firstEventHeight(\n\t\t\t\t\tt.eventType,\n\t\t\t\t\tafterHeight + 1,\n\t\t\t\t\tuntilHeight,\n\t\t\t\t\tt.contractId,\n\t\t\t\t),\n\t\t\t),\n\t\t);\n\t\tconst found = hits.filter((h): h is number => h !== null);\n\t\treturn found.length ? Math.min(...found) : null;\n\t}\n\n\tgetTip(): Promise<number> {\n\t\t// Bound advancement to what the Index data plane can serve — never\n\t\t// process past it even if the Streams clock is ahead.\n\t\treturn this.http.getIndexTip();\n\t}\n\n\tasync loadBlockRange(\n\t\tfromHeight: number,\n\t\ttoHeight: number,\n\t): Promise<Map<number, BlockData>> {\n\t\t// Event-only subgraphs join tx context onto events (withTx) and skip the\n\t\t// walkTransactions over-fetch entirely; tx-level sources fetch real txs.\n\t\tconst withTx = !this.needsTransactions;\n\t\tconst [blocks, txRows, eventLists] = await Promise.all([\n\t\t\tthis.http.walkBlocks(fromHeight, toHeight),\n\t\t\tthis.needsTransactions\n\t\t\t\t? this.http.walkTransactions(fromHeight, toHeight)\n\t\t\t\t: Promise.resolve<IndexTransactionRow[]>([]),\n\t\t\tPromise.all(\n\t\t\t\tthis.eventTypes.map((t) =>\n\t\t\t\t\tthis.http.walkEvents(t, fromHeight, toHeight, withTx),\n\t\t\t\t),\n\t\t\t),\n\t\t]);\n\n\t\tconst map = new Map<number, BlockData>();\n\t\t// Seed every canonical height (incl. empty blocks) so catch-up doesn't\n\t\t// file them as gaps.\n\t\tfor (const b of blocks) {\n\t\t\tmap.set(b.block_height, {\n\t\t\t\tblock: reconstructBlock(b),\n\t\t\t\ttxs: [],\n\t\t\t\tevents: [],\n\t\t\t});\n\t\t}\n\t\t// For event-only subgraphs, materialize only the event-bearing txs from\n\t\t// joined event context instead of every transaction in the range.\n\t\tconst txs = this.needsTransactions\n\t\t\t? txRows.map(reconstructTransaction)\n\t\t\t: synthesizeTxsFromEvents(eventLists.flat());\n\t\tfor (const t of txs) {\n\t\t\tmap.get(t.block_height)?.txs.push(t);\n\t\t}\n\t\tfor (const list of eventLists) {\n\t\t\tfor (const e of list) {\n\t\t\t\tmap.get(e.block_height)?.events.push(reconstructEvent(e));\n\t\t\t}\n\t\t}\n\t\t// Canonical ordering — multi-type event walks merge here.\n\t\tfor (const bd of map.values()) {\n\t\t\tbd.txs.sort((a, b) => a.tx_index - b.tx_index);\n\t\t\tbd.events.sort((a, b) => a.event_index - b.event_index);\n\t\t}\n\t\treturn map;\n\t}\n}\n\n/**\n * Wraps a primary source and falls back to a secondary, per call, when the\n * primary throws. Use it to make the HTTP (Streams+Index) plane a SOFT dependency:\n * if api is unavailable, the processor reads the Postgres tap and keeps advancing\n * instead of stalling. Safe to mix mid-stream — both taps read the same canonical\n * chain at the same heights and the cursor is forward-only. Stateless (no breaker)\n * so it's failover-safe across replicas; the primary is retried every call and\n * resumes transparently once healthy.\n */\nexport class FallbackBlockSource implements BlockSource {\n\tconstructor(\n\t\tprivate readonly primary: BlockSource,\n\t\tprivate readonly fallback: BlockSource,\n\t) {}\n\n\tasync getTip(): Promise<number> {\n\t\ttry {\n\t\t\treturn await this.primary.getTip();\n\t\t} catch (err) {\n\t\t\tlogger.warn(\"block source primary getTip failed — using DB tap\", {\n\t\t\t\terror: err instanceof Error ? err.message : String(err),\n\t\t\t});\n\t\t\treturn this.fallback.getTip();\n\t\t}\n\t}\n\n\tasync loadBlockRange(\n\t\tfromHeight: number,\n\t\ttoHeight: number,\n\t): Promise<Map<number, BlockData>> {\n\t\ttry {\n\t\t\treturn await this.primary.loadBlockRange(fromHeight, toHeight);\n\t\t} catch (err) {\n\t\t\tlogger.warn(\"block source primary loadBlockRange failed — using DB tap\", {\n\t\t\t\tfrom: fromHeight,\n\t\t\t\tto: toHeight,\n\t\t\t\terror: err instanceof Error ? err.message : String(err),\n\t\t\t});\n\t\t\treturn this.fallback.loadBlockRange(fromHeight, toHeight);\n\t\t}\n\t}\n\n\t/** Probe via the primary only; a probe failure just means \"no skip\" —\n\t * the caller falls back to plain batch advancement. */\n\tasync nextDataHeight(\n\t\tafterHeight: number,\n\t\tuntilHeight: number,\n\t): Promise<number | null> {\n\t\tif (!this.primary.nextDataHeight) return afterHeight + 1;\n\t\ttry {\n\t\t\treturn await this.primary.nextDataHeight(afterHeight, untilHeight);\n\t\t} catch {\n\t\t\treturn afterHeight + 1;\n\t\t}\n\t}\n}\n\nconst postgresBlockSource = new PostgresBlockSource();\n\n/**\n * HTTP (Streams+Index) chain source for a set of decoded event types, wrapped so\n * it falls back to the Postgres tap when api is down. Used by the chain-trigger\n * evaluator (which isn't subgraph-scoped, so it can't go through resolveBlockSource).\n */\nexport function buildChainBlockSource(eventTypes: string[]): BlockSource {\n\treturn new FallbackBlockSource(\n\t\tnew PublicApiBlockSource(buildHttpClient(), eventTypes),\n\t\tpostgresBlockSource,\n\t);\n}\n\nexport function buildHttpClient(): IndexHttpClient {\n\tconst baseUrl =\n\t\tprocess.env.SUBGRAPH_INDEX_API_URL ??\n\t\tprocess.env.STREAMS_API_URL ??\n\t\t\"http://api:3800\";\n\treturn new IndexHttpClient({\n\t\tindexBaseUrl: baseUrl,\n\t\tstreamsBaseUrl: baseUrl,\n\t\tstreamsApiKey:\n\t\t\tprocess.env.STREAMS_INTERNAL_API_KEY ?? \"sk-sl_streams_decode_internal\",\n\t});\n}\n\n/**\n * Resolve the block source for a subgraph. `SUBGRAPH_SOURCE=streams-index`\n * opts eligible subgraphs onto the public Streams clock + Index data; everything\n * else (and the default) stays on the Postgres tap.\n */\nexport function resolveBlockSource(subgraph?: SubgraphDefinition): BlockSource {\n\tif (\n\t\tprocess.env.SUBGRAPH_SOURCE === \"streams-index\" &&\n\t\tsubgraph &&\n\t\tisStreamsIndexEligible(subgraph)\n\t) {\n\t\t// Soft-depend on api: fall back to the Postgres tap per-call if the HTTP\n\t\t// plane is down, so the processor keeps advancing instead of stalling.\n\t\treturn new FallbackBlockSource(\n\t\t\tnew PublicApiBlockSource(\n\t\t\t\tbuildHttpClient(),\n\t\t\t\treferencedIndexEventTypes(subgraph),\n\t\t\t\tcanSparseScan(subgraph) ? sparseProbeTargets(subgraph) : undefined,\n\t\t\t\tneedsTransactionData(subgraph),\n\t\t\t),\n\t\t\tpostgresBlockSource,\n\t\t);\n\t}\n\tif (process.env.SUBGRAPH_SOURCE === \"streams-index\" && subgraph) {\n\t\tlogger.debug(\"Subgraph not streams-index eligible, using DB tap\", {\n\t\t\tsubgraph: subgraph.name,\n\t\t});\n\t}\n\treturn postgresBlockSource;\n}\n",
9
9
  "import type {\n\tBlock,\n\tDatabase,\n\tEvent,\n\tTransaction,\n} from \"@secondlayer/shared/db\";\nimport type { Kysely } from \"kysely\";\n\nexport interface BlockData {\n\tblock: Block;\n\ttxs: Transaction[];\n\tevents: Event[];\n}\n\n/**\n * Load a range of blocks with their transactions and events in 3 parallel queries.\n * Returns a Map keyed by block height. Non-canonical blocks are excluded.\n */\nexport async function loadBlockRange(\n\tdb: Kysely<Database>,\n\tfromHeight: number,\n\ttoHeight: number,\n): Promise<Map<number, BlockData>> {\n\tconst [blocks, txs, events] = await Promise.all([\n\t\tdb\n\t\t\t.selectFrom(\"blocks\")\n\t\t\t.selectAll()\n\t\t\t.where(\"height\", \">=\", fromHeight)\n\t\t\t.where(\"height\", \"<=\", toHeight)\n\t\t\t.where(\"canonical\", \"=\", true)\n\t\t\t.execute(),\n\t\tdb\n\t\t\t.selectFrom(\"transactions\")\n\t\t\t.selectAll()\n\t\t\t.where(\"block_height\", \">=\", fromHeight)\n\t\t\t.where(\"block_height\", \"<=\", toHeight)\n\t\t\t.execute(),\n\t\tdb\n\t\t\t.selectFrom(\"events\")\n\t\t\t.selectAll()\n\t\t\t.where(\"block_height\", \">=\", fromHeight)\n\t\t\t.where(\"block_height\", \"<=\", toHeight)\n\t\t\t.execute(),\n\t]);\n\n\t// Index by block height (coerce to number — bigint columns may return as string or number)\n\tconst txsByHeight = new Map<number, Transaction[]>();\n\tfor (const tx of txs) {\n\t\tconst h = Number(tx.block_height);\n\t\tconst list = txsByHeight.get(h) ?? [];\n\t\tlist.push(tx);\n\t\ttxsByHeight.set(h, list);\n\t}\n\n\tconst eventsByHeight = new Map<number, Event[]>();\n\tfor (const evt of events) {\n\t\tconst h = Number(evt.block_height);\n\t\tconst list = eventsByHeight.get(h) ?? [];\n\t\tlist.push(evt);\n\t\teventsByHeight.set(h, list);\n\t}\n\n\tconst result = new Map<number, BlockData>();\n\tfor (const block of blocks) {\n\t\tconst h = Number(block.height);\n\t\tresult.set(h, {\n\t\t\tblock,\n\t\t\ttxs: txsByHeight.get(h) ?? [],\n\t\t\tevents: eventsByHeight.get(h) ?? [],\n\t\t});\n\t}\n\n\treturn result;\n}\n\n/**\n * Compute average events per block from a loaded batch.\n * Used for adaptive batch sizing.\n */\nexport function avgEventsPerBlock(batch: Map<number, BlockData>): number {\n\tif (batch.size === 0) return 0;\n\tlet totalEvents = 0;\n\tfor (const data of batch.values()) {\n\t\ttotalEvents += data.events.length;\n\t}\n\treturn totalEvents / batch.size;\n}\n",
10
10
  "import type { Block, Event, Transaction } from \"@secondlayer/shared/db\";\nimport type {\n\tIndexBlockRow,\n\tIndexEventRow,\n\tIndexTransactionRow,\n} from \"@secondlayer/shared/index-http\";\n\nexport type {\n\tIndexBlockRow,\n\tIndexEventRow,\n\tIndexTransactionRow,\n} from \"@secondlayer/shared/index-http\";\n\n/**\n * Reconstruct the raw `blocks`/`events` row shapes the subgraph runtime expects\n * (the shapes `matchSources` + the handler runner read) from the decoded,\n * flattened rows the public Index API serves. This is what lets\n * `PublicApiBlockSource` feed the EXISTING pipeline byte-identically to the\n * Postgres tap.\n *\n * Two shape gaps the Index API can't avoid, handled here:\n * - Index event rows are flat (`event_type: \"ft_transfer\"`, columns\n * `sender`/`amount`/…); the runtime expects the node's nested `data` keyed by\n * a suffixed `type` (`ft_transfer_event`), with print under `contract_event`.\n * - nft/print Clarity values: the runtime decodes from the canonical hex\n * (`raw_value`), so we place the Index hex there. (The node's verbose\n * serde-tagged `value`, e.g. `{UInt:223}`, is not reproducible from hex and\n * is no longer read — see the nft tokenId normalization in runner.ts.)\n */\n\n/** ISO `block_time` (or null) → unix-seconds integer the runtime expects. */\nfunction isoToUnixSeconds(iso: string | null): number {\n\tif (!iso) return 0;\n\treturn Math.floor(new Date(iso).getTime() / 1000);\n}\n\nexport function reconstructBlock(b: IndexBlockRow): Block {\n\treturn {\n\t\theight: b.block_height,\n\t\thash: b.block_hash,\n\t\tparent_hash: b.parent_hash,\n\t\tburn_block_height: b.burn_block_height,\n\t\tburn_block_hash: b.burn_block_hash,\n\t\ttimestamp: isoToUnixSeconds(b.block_time),\n\t\t// Index serves canonical rows only.\n\t\tcanonical: true,\n\t\tcreated_at: new Date(0),\n\t} as Block;\n}\n\nexport function reconstructTransaction(t: IndexTransactionRow): Transaction {\n\treturn {\n\t\ttx_id: t.tx_id,\n\t\tblock_height: t.block_height,\n\t\ttx_index: t.tx_index,\n\t\ttype: t.tx_type,\n\t\tsender: t.sender,\n\t\tstatus: t.status,\n\t\tcontract_id:\n\t\t\tt.contract_call?.contract_id ?? t.smart_contract?.contract_id ?? null,\n\t\tfunction_name: t.contract_call?.function_name ?? null,\n\t\t// Raw hex ClarityValues — the runner decodes them via its own deserializeCV\n\t\t// path, identical to the DB tap.\n\t\tfunction_args: t.contract_call?.function_args_hex ?? [],\n\t\traw_result: t.contract_call?.result_hex ?? null,\n\t\traw_tx: \"\",\n\t\tcreated_at: new Date(0),\n\t} as Transaction;\n}\n\n/**\n * Build a minimal canonical Transaction from an event row's joined tx context\n * (`tx_context=true` on /v1/index/events). For event-only subgraphs this lets\n * the loader materialize only the txs that actually carry a matched event,\n * instead of draining every transaction in the range (the ~37x reindex\n * over-fetch — see docs/sprints/indexing-speed/plan.md). `function_args` /\n * `raw_result` are empty: an event source never reads them (contract_call-only).\n */\nexport function reconstructTxFromEventRow(e: IndexEventRow): Transaction {\n\treturn {\n\t\ttx_id: e.tx_id,\n\t\tblock_height: e.block_height,\n\t\ttx_index: e.tx_index ?? 0,\n\t\ttype: e.tx_type ?? \"\",\n\t\tsender: e.tx_sender ?? \"\",\n\t\tstatus: e.tx_status ?? \"success\",\n\t\tcontract_id: e.tx_contract_id ?? null,\n\t\tfunction_name: e.tx_function_name ?? null,\n\t\tfunction_args: [],\n\t\traw_result: null,\n\t\traw_tx: \"\",\n\t\tcreated_at: new Date(0),\n\t} as Transaction;\n}\n\nexport function reconstructEvent(e: IndexEventRow): Event {\n\tconst base = {\n\t\t// Synthetic, deterministic id. The runtime only reads `id` for error logs\n\t\t// and the `*`-wildcard payload (which is streams-index-ineligible).\n\t\tid: `${e.tx_id}#${e.event_index}`,\n\t\ttx_id: e.tx_id,\n\t\tblock_height: e.block_height,\n\t\tevent_index: e.event_index,\n\t\tcreated_at: new Date(0),\n\t};\n\n\tswitch (e.event_type) {\n\t\tcase \"ft_transfer\":\n\t\tcase \"ft_mint\":\n\t\tcase \"ft_burn\":\n\t\t\treturn {\n\t\t\t\t...base,\n\t\t\t\ttype: `${e.event_type}_event`,\n\t\t\t\tdata: {\n\t\t\t\t\tasset_identifier: e.asset_identifier,\n\t\t\t\t\tsender: e.sender,\n\t\t\t\t\trecipient: e.recipient,\n\t\t\t\t\tamount: e.amount,\n\t\t\t\t},\n\t\t\t} as Event;\n\n\t\tcase \"nft_transfer\":\n\t\tcase \"nft_mint\":\n\t\tcase \"nft_burn\":\n\t\t\treturn {\n\t\t\t\t...base,\n\t\t\t\ttype: `${e.event_type}_event`,\n\t\t\t\tdata: {\n\t\t\t\t\tasset_identifier: e.asset_identifier,\n\t\t\t\t\tsender: e.sender,\n\t\t\t\t\trecipient: e.recipient,\n\t\t\t\t\t// Canonical hex → runner decodes tokenId from raw_value.\n\t\t\t\t\traw_value: e.value,\n\t\t\t\t},\n\t\t\t} as Event;\n\n\t\tcase \"stx_transfer\":\n\t\tcase \"stx_mint\":\n\t\tcase \"stx_burn\":\n\t\t\treturn {\n\t\t\t\t...base,\n\t\t\t\ttype: `${e.event_type}_event`,\n\t\t\t\tdata: {\n\t\t\t\t\tsender: e.sender,\n\t\t\t\t\trecipient: e.recipient,\n\t\t\t\t\tamount: e.amount,\n\t\t\t\t\t// Raw stx_transfer always carries memo (\"\" when empty); Index\n\t\t\t\t\t// returns null for empty — default to \"\" to match the DB tap.\n\t\t\t\t\t...(e.event_type === \"stx_transfer\" ? { memo: e.memo ?? \"\" } : {}),\n\t\t\t\t},\n\t\t\t} as Event;\n\n\t\tcase \"stx_lock\":\n\t\t\treturn {\n\t\t\t\t...base,\n\t\t\t\ttype: \"stx_lock_event\",\n\t\t\t\tdata: {\n\t\t\t\t\tlocked_address: e.sender,\n\t\t\t\t\tlocked_amount: e.amount,\n\t\t\t\t\tunlock_height: e.payload.unlock_height,\n\t\t\t\t},\n\t\t\t} as Event;\n\n\t\tcase \"print\":\n\t\t\treturn {\n\t\t\t\t...base,\n\t\t\t\ttype: \"contract_event\",\n\t\t\t\tdata: {\n\t\t\t\t\ttopic: e.payload.topic,\n\t\t\t\t\t// Matcher + runner read `contract_identifier` (the raw node field).\n\t\t\t\t\tcontract_identifier: e.contract_id,\n\t\t\t\t\tvalue: e.payload.value,\n\t\t\t\t\traw_value: e.payload.raw_value,\n\t\t\t\t},\n\t\t\t} as Event;\n\t}\n}\n",
11
- "import type {\n\tChainApplyEnvelope,\n\tSbtcDepositEvent,\n\tSbtcWithdrawalEvent,\n} from \"@secondlayer/shared\";\nimport type {\n\tDatabase,\n\tInsertSubscriptionOutbox,\n\tSbtcEventTopic,\n\tSbtcEventsTable,\n\tSubscription,\n} from \"@secondlayer/shared/db\";\nimport { resolveTraitContractIds } from \"@secondlayer/shared/db/queries/contracts\";\nimport type { ChainTrigger } from \"@secondlayer/shared/schemas/subscriptions\";\nimport type { Kysely, Selectable } from \"kysely\";\nimport type { SubgraphFilter } from \"../types.ts\";\nimport type { BlockData } from \"./batch-loader.ts\";\nimport { indexEventTypesForFilterTypes } from \"./block-source.ts\";\nimport {\n\ttype MatchedTx,\n\ttype TraitContracts,\n\tmatchSources,\n} from \"./source-matcher.ts\";\n\n/** Trigger types that match a whole transaction (not an individual event). */\nconst TX_LEVEL_TRIGGER_TYPES = new Set([\"contract_call\", \"contract_deploy\"]);\n\n/**\n * sBTC trigger types — matched via the `sbtc_events` table, NOT via\n * `decoded_events`. Excluded from the chain-event sources map so the\n * `matchSources` engine never sees them; `emitSbtcOutbox` handles them\n * with a dedicated query + match loop.\n */\nconst SBTC_TRIGGER_TYPES = new Set([\n\t\"sbtc_deposit\",\n\t\"sbtc_withdrawal_create\",\n\t\"sbtc_withdrawal_accept\",\n\t\"sbtc_withdrawal_reject\",\n]);\n\nfunction isSbtcTriggerType(type: string): boolean {\n\treturn SBTC_TRIGGER_TYPES.has(type);\n}\n\nconst SBTC_TRIGGER_TO_TOPIC: Record<string, SbtcEventTopic> = {\n\tsbtc_deposit: \"completed-deposit\",\n\tsbtc_withdrawal_create: \"withdrawal-create\",\n\tsbtc_withdrawal_accept: \"withdrawal-accept\",\n\tsbtc_withdrawal_reject: \"withdrawal-reject\",\n};\n\n/**\n * Pure matching core for direct chain-level subscriptions. A single evaluator\n * loop serves ALL chain subscriptions: it reads canonical blocks off the public\n * Index/Streams clock (via `PublicApiBlockSource`), runs the same\n * `matchSources` engine the subgraph runtime uses, and routes matches back to\n * the originating subscription. Everything here is pure/sync (DB only for trait\n * resolution) so it's trivially testable.\n *\n * Source keys are `\"{subscriptionId}#{triggerIndex}\"` — `matchSources` echoes\n * the key as `MatchedTx.sourceName`, letting the emitter recover which\n * subscription (and which trigger) matched. `keyMeta` carries the readable\n * trigger type for the outbox `event_type` / payload.\n */\n\nexport interface TriggerKeyMeta {\n\tsubscriptionId: string;\n\ttriggerIndex: number;\n\ttriggerType: ChainTrigger[\"type\"];\n}\n\nexport interface ChainSourcesMap {\n\tsources: Record<string, SubgraphFilter>;\n\tkeyMeta: Map<string, TriggerKeyMeta>;\n}\n\nfunction sourceKey(subscriptionId: string, triggerIndex: number): string {\n\treturn `${subscriptionId}#${triggerIndex}`;\n}\n\nfunction toAmount(v: string | number | undefined): bigint | undefined {\n\treturn v === undefined ? undefined : BigInt(v);\n}\n\n/**\n * Convert a stored `ChainTrigger` (JSON; amounts as string/number) to the\n * runtime `SubgraphFilter` the matcher expects (amounts as bigint). Field names\n * are identical across the two shapes, so this is a copy plus amount coercion.\n */\nexport function chainTriggerToFilter(trigger: ChainTrigger): SubgraphFilter {\n\tconst t = trigger as ChainTrigger & {\n\t\tminAmount?: string | number;\n\t\tmaxAmount?: string | number;\n\t};\n\t// Spread copies all set keys; amounts (string|number) are then overwritten\n\t// with bigint where present. An absent optional amount isn't in the spread,\n\t// so there's nothing to strip.\n\tconst filter = { ...trigger } as Record<string, unknown>;\n\tconst minAmount = toAmount(t.minAmount);\n\tconst maxAmount = toAmount(t.maxAmount);\n\tif (minAmount !== undefined) filter.minAmount = minAmount;\n\tif (maxAmount !== undefined) filter.maxAmount = maxAmount;\n\treturn filter as unknown as SubgraphFilter;\n}\n\nfunction triggersOf(sub: Subscription): ChainTrigger[] {\n\treturn (sub.triggers ?? []) as ChainTrigger[];\n}\n\n/** Build the `matchSources` input from every active chain subscription. */\nexport function buildSourcesMap(chainSubs: Subscription[]): ChainSourcesMap {\n\tconst sources: Record<string, SubgraphFilter> = {};\n\tconst keyMeta = new Map<string, TriggerKeyMeta>();\n\tfor (const sub of chainSubs) {\n\t\ttriggersOf(sub).forEach((trigger, triggerIndex) => {\n\t\t\t// sBTC triggers are handled by emitSbtcOutbox — skip them here so\n\t\t\t// matchSources never tries to find sbtc_events in decoded_events.\n\t\t\tif (isSbtcTriggerType(trigger.type)) return;\n\t\t\tconst key = sourceKey(sub.id, triggerIndex);\n\t\t\tsources[key] = chainTriggerToFilter(trigger);\n\t\t\tkeyMeta.set(key, {\n\t\t\t\tsubscriptionId: sub.id,\n\t\t\t\ttriggerIndex,\n\t\t\t\ttriggerType: trigger.type,\n\t\t\t});\n\t\t});\n\t}\n\treturn { sources, keyMeta };\n}\n\n/** The Index event types the loader must fetch to satisfy all chain triggers. */\nexport function referencedEventTypes(chainSubs: Subscription[]): string[] {\n\tconst filterTypes = new Set<string>();\n\tfor (const sub of chainSubs) {\n\t\tfor (const trigger of triggersOf(sub)) {\n\t\t\t// sBTC events live in sbtc_events, not in the Index event stream.\n\t\t\tif (!isSbtcTriggerType(trigger.type)) filterTypes.add(trigger.type);\n\t\t}\n\t}\n\treturn indexEventTypesForFilterTypes([...filterTypes]);\n}\n\n/** Distinct traits referenced across all chain triggers. */\nexport function referencedTraits(chainSubs: Subscription[]): string[] {\n\tconst traits = new Set<string>();\n\tfor (const sub of chainSubs) {\n\t\tfor (const trigger of triggersOf(sub)) {\n\t\t\tconst trait = (trigger as { trait?: string }).trait;\n\t\t\tif (trait) traits.add(trait);\n\t\t}\n\t}\n\treturn [...traits];\n}\n\n/**\n * Resolve each referenced trait to its conforming contract-id set as of\n * `asOfBlock`, from the contract registry (`CONTRACT_REGISTRY_ENABLED` populates\n * it). Empty map when no trigger is trait-scoped → no DB work. Membership only\n * grows, so the evaluator resolves this once per batch, not per block.\n */\nexport async function buildTraitContracts(\n\tdb: Kysely<Database>,\n\tchainSubs: Subscription[],\n\tasOfBlock: number,\n): Promise<TraitContracts> {\n\tconst resolved: TraitContracts = new Map();\n\tfor (const trait of referencedTraits(chainSubs)) {\n\t\tconst ids = await resolveTraitContractIds(db, trait, asOfBlock);\n\t\tresolved.set(trait, new Set(ids));\n\t}\n\treturn resolved;\n}\n\n/** Run the matcher for one block. Thin wrapper for symmetry/testability. */\nexport function evaluateBlock(\n\tblock: BlockData,\n\tsources: Record<string, SubgraphFilter>,\n\ttraitContracts: TraitContracts,\n): MatchedTx[] {\n\treturn matchSources(sources, block.txs, block.events, traitContracts);\n}\n\n// ── Outbox emission ─────────────────────────────────────────────────────────\n\n// Apply-envelope shape is single-sourced as `ChainApplyEnvelope` in\n// `@secondlayer/shared` (shared with the SDK consumer); reorg emits a matching\n// `ChainReorgRollbackEnvelope`, see `handleChainReorg`.\n\n/**\n * Stable dedup identity for a chain delivery — (subscription, tx, event,\n * block_hash). A tx-level match (contract_call/deploy) has no event, so\n * `eventIndex = -1`. `block_hash` is included so a tx that survives a reorg\n * (same tx_id, NEW canonical block) re-delivers an `apply` after its rollback,\n * instead of being suppressed forever; re-processing the SAME canonical block is\n * still idempotent (same hash → same key).\n */\nfunction chainDedupKey(\n\tsubscriptionId: string,\n\ttxId: string,\n\teventIndex: number,\n\tblockHash: string,\n\treplayId?: string,\n): string {\n\tconst base = `chain:${subscriptionId}:${txId}:${eventIndex}:${blockHash}`;\n\t// Replay keys are namespaced so a re-delivery doesn't collide with the\n\t// already-emitted live apply row (whose outbox entry may be long gone), while\n\t// re-running the SAME replay range stays idempotent (same replayId → same key).\n\treturn replayId ? `replay:${replayId}:${base}` : base;\n}\n\nfunction applyRow(\n\tmeta: TriggerKeyMeta,\n\tblockHeight: number,\n\tblockHash: string,\n\ttxId: string,\n\teventIndex: number,\n\tevent: Record<string, unknown>,\n\treplayId?: string,\n): InsertSubscriptionOutbox {\n\tconst payload: ChainApplyEnvelope = {\n\t\taction: \"apply\",\n\t\tblock_hash: blockHash,\n\t\tblock_height: blockHeight,\n\t\ttx_id: txId,\n\t\tcanonical: true,\n\t\ttrigger: meta.triggerType,\n\t\tevent,\n\t};\n\treturn {\n\t\tsubscription_id: meta.subscriptionId,\n\t\tkind: \"chain\",\n\t\tsubgraph_name: null,\n\t\ttable_name: null,\n\t\tblock_height: blockHeight,\n\t\ttx_id: txId,\n\t\trow_pk: { tx_id: txId, event_index: eventIndex },\n\t\tevent_type: `chain.${meta.triggerType}.apply`,\n\t\tpayload,\n\t\tdedup_key: chainDedupKey(\n\t\t\tmeta.subscriptionId,\n\t\t\ttxId,\n\t\t\teventIndex,\n\t\t\tblockHash,\n\t\t\treplayId,\n\t\t),\n\t\t...(replayId ? { is_replay: true } : {}),\n\t};\n}\n\n/**\n * Turn one block's matches into `subscription_outbox` rows (apply envelope). For\n * tx-level triggers (contract_call/deploy) we emit ONE row per matched tx\n * (`event_index = -1`); for event-level triggers, one row per matched event.\n * The `(subscription_id, dedup_key)` unique constraint makes re-processing a\n * block idempotent, so the emitter never double-delivers. Returns rows written.\n */\nexport async function emitChainOutbox(\n\tdb: Kysely<Database>,\n\tmatches: MatchedTx[],\n\tkeyMeta: Map<string, TriggerKeyMeta>,\n\tblockHeight: number,\n\tblockHash: string,\n\topts?: { replayId?: string },\n): Promise<number> {\n\tconst replayId = opts?.replayId;\n\tconst rows: InsertSubscriptionOutbox[] = [];\n\tfor (const match of matches) {\n\t\tconst meta = keyMeta.get(match.sourceName);\n\t\tif (!meta) continue;\n\t\tconst txId = match.tx.tx_id;\n\t\tif (TX_LEVEL_TRIGGER_TYPES.has(meta.triggerType)) {\n\t\t\trows.push(\n\t\t\t\tapplyRow(\n\t\t\t\t\tmeta,\n\t\t\t\t\tblockHeight,\n\t\t\t\t\tblockHash,\n\t\t\t\t\ttxId,\n\t\t\t\t\t-1,\n\t\t\t\t\t{\n\t\t\t\t\t\ttx_id: txId,\n\t\t\t\t\t\ttype: match.tx.type,\n\t\t\t\t\t\tsender: match.tx.sender,\n\t\t\t\t\t\tstatus: match.tx.status,\n\t\t\t\t\t\tcontract_id: match.tx.contract_id ?? null,\n\t\t\t\t\t\tfunction_name: match.tx.function_name ?? null,\n\t\t\t\t\t\tfunction_args: match.tx.function_args ?? null,\n\t\t\t\t\t\tresult_hex: match.tx.raw_result ?? null,\n\t\t\t\t\t},\n\t\t\t\t\treplayId,\n\t\t\t\t),\n\t\t\t);\n\t\t} else {\n\t\t\tfor (const event of match.events) {\n\t\t\t\trows.push(\n\t\t\t\t\tapplyRow(\n\t\t\t\t\t\tmeta,\n\t\t\t\t\t\tblockHeight,\n\t\t\t\t\t\tblockHash,\n\t\t\t\t\t\ttxId,\n\t\t\t\t\t\tevent.event_index,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttx_id: txId,\n\t\t\t\t\t\t\ttype: event.type,\n\t\t\t\t\t\t\tevent_index: event.event_index,\n\t\t\t\t\t\t\tdata: event.data,\n\t\t\t\t\t\t},\n\t\t\t\t\t\treplayId,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\tif (rows.length === 0) return 0;\n\t// Net-inserted (not built) so callers count genuinely new deliveries — a\n\t// re-processed block or a re-run replay returns 0.\n\tconst result = await db\n\t\t.insertInto(\"subscription_outbox\")\n\t\t.values(rows)\n\t\t.onConflict((oc) =>\n\t\t\toc.columns([\"subscription_id\", \"dedup_key\"]).doNothing(),\n\t\t)\n\t\t.executeTakeFirst();\n\treturn Number(result.numInsertedOrUpdatedRows ?? 0);\n}\n\n// ── sBTC event matching ──────────────────────────────────────────────────────\n\ntype SbtcRow = Selectable<SbtcEventsTable>;\n\nasync function loadSbtcEventsForBlock(\n\tdb: Kysely<Database>,\n\tblockHeight: number,\n\ttopics: SbtcEventTopic[],\n): Promise<SbtcRow[]> {\n\tif (topics.length === 0) return [];\n\treturn db\n\t\t.selectFrom(\"sbtc_events\")\n\t\t.selectAll()\n\t\t.where(\"block_height\", \"=\", blockHeight)\n\t\t.where(\"canonical\", \"=\", true)\n\t\t.where(\"topic\", \"in\", topics)\n\t\t.execute();\n}\n\nfunction toAmountBigInt(v: string | number | undefined): bigint | undefined {\n\treturn v === undefined ? undefined : BigInt(v);\n}\n\nfunction matchSbtcTrigger(trigger: ChainTrigger, row: SbtcRow): boolean {\n\tconst expectedTopic = SBTC_TRIGGER_TO_TOPIC[trigger.type];\n\tif (!expectedTopic || row.topic !== expectedTopic) return false;\n\n\tif (trigger.type === \"sbtc_deposit\") {\n\t\tif (trigger.sender && row.sender !== trigger.sender) return false;\n\t\tif (trigger.bitcoinTxid && row.bitcoin_txid !== trigger.bitcoinTxid)\n\t\t\treturn false;\n\t\tif (trigger.requestId !== undefined && row.request_id !== trigger.requestId)\n\t\t\treturn false;\n\t\tconst min = toAmountBigInt(trigger.minAmount);\n\t\tconst max = toAmountBigInt(trigger.maxAmount);\n\t\tif (min !== undefined || max !== undefined) {\n\t\t\tif (row.amount === null) return false;\n\t\t\tconst amt = BigInt(row.amount);\n\t\t\tif (min !== undefined && amt < min) return false;\n\t\t\tif (max !== undefined && amt > max) return false;\n\t\t}\n\t\treturn true;\n\t}\n\n\tif (trigger.type === \"sbtc_withdrawal_create\") {\n\t\tif (trigger.sender && row.sender !== trigger.sender) return false;\n\t\tif (trigger.requestId !== undefined && row.request_id !== trigger.requestId)\n\t\t\treturn false;\n\t\tconst min = toAmountBigInt(trigger.minAmount);\n\t\tconst max = toAmountBigInt(trigger.maxAmount);\n\t\tif (min !== undefined || max !== undefined) {\n\t\t\tif (row.amount === null) return false;\n\t\t\tconst amt = BigInt(row.amount);\n\t\t\tif (min !== undefined && amt < min) return false;\n\t\t\tif (max !== undefined && amt > max) return false;\n\t\t}\n\t\treturn true;\n\t}\n\n\tif (trigger.type === \"sbtc_withdrawal_accept\") {\n\t\tif (trigger.requestId !== undefined && row.request_id !== trigger.requestId)\n\t\t\treturn false;\n\t\tif (trigger.sweepTxid && row.sweep_txid !== trigger.sweepTxid) return false;\n\t\treturn true;\n\t}\n\n\tif (trigger.type === \"sbtc_withdrawal_reject\") {\n\t\tif (trigger.requestId !== undefined && row.request_id !== trigger.requestId)\n\t\t\treturn false;\n\t\treturn true;\n\t}\n\n\treturn false;\n}\n\nfunction buildSbtcEventPayload(\n\ttriggerType: ChainTrigger[\"type\"],\n\trow: SbtcRow,\n): SbtcDepositEvent | SbtcWithdrawalEvent {\n\tif (triggerType === \"sbtc_deposit\") {\n\t\treturn {\n\t\t\ttopic: \"completed-deposit\",\n\t\t\trequest_id: row.request_id ?? 0,\n\t\t\tsender: row.sender,\n\t\t\tamount: row.amount ?? \"0\",\n\t\t\tbitcoin_txid: row.bitcoin_txid,\n\t\t\tblock_height: row.block_height,\n\t\t\ttx_id: row.tx_id,\n\t\t} satisfies SbtcDepositEvent;\n\t}\n\treturn {\n\t\ttopic: row.topic as\n\t\t\t| \"withdrawal-create\"\n\t\t\t| \"withdrawal-accept\"\n\t\t\t| \"withdrawal-reject\",\n\t\trequest_id: row.request_id ?? 0,\n\t\tsender: row.sender,\n\t\tamount: row.amount,\n\t\tsweep_txid: row.sweep_txid,\n\t\tsettlement_confirmed: false,\n\t\tblock_height: row.block_height,\n\t\ttx_id: row.tx_id,\n\t} satisfies SbtcWithdrawalEvent;\n}\n\n/**\n * Match active sBTC chain subscriptions against `sbtc_events` for one block\n * and write apply-envelope rows to `subscription_outbox`. Runs alongside\n * `emitChainOutbox` (which handles decoded_events). Same dedup-key scheme —\n * re-processing the same block is idempotent.\n */\nexport async function emitSbtcOutbox(\n\tdb: Kysely<Database>,\n\tchainSubs: Subscription[],\n\tblockHeight: number,\n\tblockHash: string,\n\topts?: { replayId?: string },\n): Promise<number> {\n\tconst sbtcSubs = chainSubs.filter((sub) =>\n\t\ttriggersOf(sub).some((t) => isSbtcTriggerType(t.type)),\n\t);\n\tif (sbtcSubs.length === 0) return 0;\n\n\tconst neededTopics = new Set<SbtcEventTopic>();\n\tfor (const sub of sbtcSubs) {\n\t\tfor (const trigger of triggersOf(sub)) {\n\t\t\tconst topic = SBTC_TRIGGER_TO_TOPIC[trigger.type];\n\t\t\tif (topic) neededTopics.add(topic);\n\t\t}\n\t}\n\n\tconst sbtcRows = await loadSbtcEventsForBlock(db, blockHeight, [\n\t\t...neededTopics,\n\t]);\n\tif (sbtcRows.length === 0) return 0;\n\n\tconst replayId = opts?.replayId;\n\tconst outboxRows: InsertSubscriptionOutbox[] = [];\n\n\tfor (const sub of sbtcSubs) {\n\t\ttriggersOf(sub).forEach((trigger, triggerIndex) => {\n\t\t\tif (!isSbtcTriggerType(trigger.type)) return;\n\t\t\tconst meta: TriggerKeyMeta = {\n\t\t\t\tsubscriptionId: sub.id,\n\t\t\t\ttriggerIndex,\n\t\t\t\ttriggerType: trigger.type,\n\t\t\t};\n\t\t\tfor (const row of sbtcRows) {\n\t\t\t\tif (!matchSbtcTrigger(trigger, row)) continue;\n\t\t\t\tconst event = buildSbtcEventPayload(trigger.type, row);\n\t\t\t\toutboxRows.push(\n\t\t\t\t\tapplyRow(\n\t\t\t\t\t\tmeta,\n\t\t\t\t\t\tblockHeight,\n\t\t\t\t\t\tblockHash,\n\t\t\t\t\t\trow.tx_id,\n\t\t\t\t\t\trow.event_index,\n\t\t\t\t\t\tevent as unknown as Record<string, unknown>,\n\t\t\t\t\t\treplayId,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t});\n\t}\n\n\tif (outboxRows.length === 0) return 0;\n\tconst result = await db\n\t\t.insertInto(\"subscription_outbox\")\n\t\t.values(outboxRows)\n\t\t.onConflict((oc) =>\n\t\t\toc.columns([\"subscription_id\", \"dedup_key\"]).doNothing(),\n\t\t)\n\t\t.executeTakeFirst();\n\treturn Number(result.numInsertedOrUpdatedRows ?? 0);\n}\n"
11
+ "import type {\n\tChainApplyEnvelope,\n\tSbtcDepositEvent,\n\tSbtcWithdrawalEvent,\n\tSbtcWithdrawalSweptConfirmedEvent,\n} from \"@secondlayer/shared\";\nimport type {\n\tDatabase,\n\tInsertSubscriptionOutbox,\n\tSbtcEventTopic,\n\tSbtcEventsTable,\n\tSubscription,\n} from \"@secondlayer/shared/db\";\nimport { getSourceDb } from \"@secondlayer/shared/db\";\nimport { resolveTraitContractIds } from \"@secondlayer/shared/db/queries/contracts\";\nimport type { ChainTrigger } from \"@secondlayer/shared/schemas/subscriptions\";\nimport type { Kysely, Selectable } from \"kysely\";\nimport type { SubgraphFilter } from \"../types.ts\";\nimport type { BlockData } from \"./batch-loader.ts\";\nimport { indexEventTypesForFilterTypes } from \"./block-source.ts\";\nimport {\n\ttype MatchedTx,\n\ttype TraitContracts,\n\tmatchSources,\n} from \"./source-matcher.ts\";\n\n/** Trigger types that match a whole transaction (not an individual event). */\nconst TX_LEVEL_TRIGGER_TYPES = new Set([\"contract_call\", \"contract_deploy\"]);\n\n/** Fired on a Bitcoin confirmation, async to Stacks blocks — handled by the\n * scan-based `emitSbtcSettlementOutbox`, NOT the per-block path. Listed in\n * SBTC_TRIGGER_TYPES so the per-block matcher skips it, but deliberately absent\n * from SBTC_TRIGGER_TO_TOPIC (it has no `sbtc_events` topic). */\nconst SETTLEMENT_TRIGGER_TYPE = \"sbtc_withdrawal_swept_confirmed\";\n\n/**\n * sBTC trigger types — matched via the `sbtc_events` table, NOT via\n * `decoded_events`. Excluded from the chain-event sources map so the\n * `matchSources` engine never sees them; `emitSbtcOutbox` handles them\n * with a dedicated query + match loop.\n */\nconst SBTC_TRIGGER_TYPES = new Set([\n\t\"sbtc_deposit\",\n\t\"sbtc_withdrawal_create\",\n\t\"sbtc_withdrawal_accept\",\n\t\"sbtc_withdrawal_reject\",\n\tSETTLEMENT_TRIGGER_TYPE,\n]);\n\nfunction isSbtcTriggerType(type: string): boolean {\n\treturn SBTC_TRIGGER_TYPES.has(type);\n}\n\nconst SBTC_TRIGGER_TO_TOPIC: Record<string, SbtcEventTopic> = {\n\tsbtc_deposit: \"completed-deposit\",\n\tsbtc_withdrawal_create: \"withdrawal-create\",\n\tsbtc_withdrawal_accept: \"withdrawal-accept\",\n\tsbtc_withdrawal_reject: \"withdrawal-reject\",\n};\n\n/**\n * Pure matching core for direct chain-level subscriptions. A single evaluator\n * loop serves ALL chain subscriptions: it reads canonical blocks off the public\n * Index/Streams clock (via `PublicApiBlockSource`), runs the same\n * `matchSources` engine the subgraph runtime uses, and routes matches back to\n * the originating subscription. Everything here is pure/sync (DB only for trait\n * resolution) so it's trivially testable.\n *\n * Source keys are `\"{subscriptionId}#{triggerIndex}\"` — `matchSources` echoes\n * the key as `MatchedTx.sourceName`, letting the emitter recover which\n * subscription (and which trigger) matched. `keyMeta` carries the readable\n * trigger type for the outbox `event_type` / payload.\n */\n\nexport interface TriggerKeyMeta {\n\tsubscriptionId: string;\n\ttriggerIndex: number;\n\ttriggerType: ChainTrigger[\"type\"];\n}\n\nexport interface ChainSourcesMap {\n\tsources: Record<string, SubgraphFilter>;\n\tkeyMeta: Map<string, TriggerKeyMeta>;\n}\n\nfunction sourceKey(subscriptionId: string, triggerIndex: number): string {\n\treturn `${subscriptionId}#${triggerIndex}`;\n}\n\nfunction toAmount(v: string | number | undefined): bigint | undefined {\n\treturn v === undefined ? undefined : BigInt(v);\n}\n\n/**\n * Convert a stored `ChainTrigger` (JSON; amounts as string/number) to the\n * runtime `SubgraphFilter` the matcher expects (amounts as bigint). Field names\n * are identical across the two shapes, so this is a copy plus amount coercion.\n */\nexport function chainTriggerToFilter(trigger: ChainTrigger): SubgraphFilter {\n\tconst t = trigger as ChainTrigger & {\n\t\tminAmount?: string | number;\n\t\tmaxAmount?: string | number;\n\t};\n\t// Spread copies all set keys; amounts (string|number) are then overwritten\n\t// with bigint where present. An absent optional amount isn't in the spread,\n\t// so there's nothing to strip.\n\tconst filter = { ...trigger } as Record<string, unknown>;\n\tconst minAmount = toAmount(t.minAmount);\n\tconst maxAmount = toAmount(t.maxAmount);\n\tif (minAmount !== undefined) filter.minAmount = minAmount;\n\tif (maxAmount !== undefined) filter.maxAmount = maxAmount;\n\treturn filter as unknown as SubgraphFilter;\n}\n\nfunction triggersOf(sub: Subscription): ChainTrigger[] {\n\treturn (sub.triggers ?? []) as ChainTrigger[];\n}\n\n/** Build the `matchSources` input from every active chain subscription. */\nexport function buildSourcesMap(chainSubs: Subscription[]): ChainSourcesMap {\n\tconst sources: Record<string, SubgraphFilter> = {};\n\tconst keyMeta = new Map<string, TriggerKeyMeta>();\n\tfor (const sub of chainSubs) {\n\t\ttriggersOf(sub).forEach((trigger, triggerIndex) => {\n\t\t\t// sBTC triggers are handled by emitSbtcOutbox — skip them here so\n\t\t\t// matchSources never tries to find sbtc_events in decoded_events.\n\t\t\tif (isSbtcTriggerType(trigger.type)) return;\n\t\t\tconst key = sourceKey(sub.id, triggerIndex);\n\t\t\tsources[key] = chainTriggerToFilter(trigger);\n\t\t\tkeyMeta.set(key, {\n\t\t\t\tsubscriptionId: sub.id,\n\t\t\t\ttriggerIndex,\n\t\t\t\ttriggerType: trigger.type,\n\t\t\t});\n\t\t});\n\t}\n\treturn { sources, keyMeta };\n}\n\n/** The Index event types the loader must fetch to satisfy all chain triggers. */\nexport function referencedEventTypes(chainSubs: Subscription[]): string[] {\n\tconst filterTypes = new Set<string>();\n\tfor (const sub of chainSubs) {\n\t\tfor (const trigger of triggersOf(sub)) {\n\t\t\t// sBTC events live in sbtc_events, not in the Index event stream.\n\t\t\tif (!isSbtcTriggerType(trigger.type)) filterTypes.add(trigger.type);\n\t\t}\n\t}\n\treturn indexEventTypesForFilterTypes([...filterTypes]);\n}\n\n/** Distinct traits referenced across all chain triggers. */\nexport function referencedTraits(chainSubs: Subscription[]): string[] {\n\tconst traits = new Set<string>();\n\tfor (const sub of chainSubs) {\n\t\tfor (const trigger of triggersOf(sub)) {\n\t\t\tconst trait = (trigger as { trait?: string }).trait;\n\t\t\tif (trait) traits.add(trait);\n\t\t}\n\t}\n\treturn [...traits];\n}\n\n/**\n * Resolve each referenced trait to its conforming contract-id set as of\n * `asOfBlock`, from the contract registry (`CONTRACT_REGISTRY_ENABLED` populates\n * it). Empty map when no trigger is trait-scoped → no DB work. Membership only\n * grows, so the evaluator resolves this once per batch, not per block.\n */\nexport async function buildTraitContracts(\n\tchainSubs: Subscription[],\n\tasOfBlock: number,\n\topts?: { sourceDb?: Kysely<Database> },\n): Promise<TraitContracts> {\n\t// `contracts` is a SOURCE-plane table; the evaluator/replay run on the TARGET\n\t// handle (an empty same-named copy exists there post-split). Read the registry\n\t// from the source plane — reading off the target silently resolved zero trait\n\t// members, so trait-scoped subscriptions never matched. Same class of bug as\n\t// the old emitSbtcOutbox sbtc_events read.\n\tconst sourceDb = opts?.sourceDb ?? getSourceDb();\n\tconst resolved: TraitContracts = new Map();\n\tfor (const trait of referencedTraits(chainSubs)) {\n\t\tconst ids = await resolveTraitContractIds(sourceDb, trait, asOfBlock);\n\t\tresolved.set(trait, new Set(ids));\n\t}\n\treturn resolved;\n}\n\n/** Run the matcher for one block. Thin wrapper for symmetry/testability. */\nexport function evaluateBlock(\n\tblock: BlockData,\n\tsources: Record<string, SubgraphFilter>,\n\ttraitContracts: TraitContracts,\n): MatchedTx[] {\n\treturn matchSources(sources, block.txs, block.events, traitContracts);\n}\n\n// ── Outbox emission ─────────────────────────────────────────────────────────\n\n// Apply-envelope shape is single-sourced as `ChainApplyEnvelope` in\n// `@secondlayer/shared` (shared with the SDK consumer); reorg emits a matching\n// `ChainReorgRollbackEnvelope`, see `handleChainReorg`.\n\n/**\n * Stable dedup identity for a chain delivery — (subscription, tx, event,\n * block_hash). A tx-level match (contract_call/deploy) has no event, so\n * `eventIndex = -1`. `block_hash` is included so a tx that survives a reorg\n * (same tx_id, NEW canonical block) re-delivers an `apply` after its rollback,\n * instead of being suppressed forever; re-processing the SAME canonical block is\n * still idempotent (same hash → same key).\n */\nfunction chainDedupKey(\n\tsubscriptionId: string,\n\ttxId: string,\n\teventIndex: number,\n\tblockHash: string,\n\treplayId?: string,\n): string {\n\tconst base = `chain:${subscriptionId}:${txId}:${eventIndex}:${blockHash}`;\n\t// Replay keys are namespaced so a re-delivery doesn't collide with the\n\t// already-emitted live apply row (whose outbox entry may be long gone), while\n\t// re-running the SAME replay range stays idempotent (same replayId → same key).\n\treturn replayId ? `replay:${replayId}:${base}` : base;\n}\n\nfunction applyRow(\n\tmeta: TriggerKeyMeta,\n\tblockHeight: number,\n\tblockHash: string,\n\ttxId: string,\n\teventIndex: number,\n\tevent: Record<string, unknown>,\n\treplayId?: string,\n): InsertSubscriptionOutbox {\n\tconst payload: ChainApplyEnvelope = {\n\t\taction: \"apply\",\n\t\tblock_hash: blockHash,\n\t\tblock_height: blockHeight,\n\t\ttx_id: txId,\n\t\tcanonical: true,\n\t\ttrigger: meta.triggerType,\n\t\tevent,\n\t};\n\treturn {\n\t\tsubscription_id: meta.subscriptionId,\n\t\tkind: \"chain\",\n\t\tsubgraph_name: null,\n\t\ttable_name: null,\n\t\tblock_height: blockHeight,\n\t\ttx_id: txId,\n\t\trow_pk: { tx_id: txId, event_index: eventIndex },\n\t\tevent_type: `chain.${meta.triggerType}.apply`,\n\t\tpayload,\n\t\tdedup_key: chainDedupKey(\n\t\t\tmeta.subscriptionId,\n\t\t\ttxId,\n\t\t\teventIndex,\n\t\t\tblockHash,\n\t\t\treplayId,\n\t\t),\n\t\t...(replayId ? { is_replay: true } : {}),\n\t};\n}\n\n/**\n * Turn one block's matches into `subscription_outbox` rows (apply envelope). For\n * tx-level triggers (contract_call/deploy) we emit ONE row per matched tx\n * (`event_index = -1`); for event-level triggers, one row per matched event.\n * The `(subscription_id, dedup_key)` unique constraint makes re-processing a\n * block idempotent, so the emitter never double-delivers. Returns rows written.\n */\nexport async function emitChainOutbox(\n\tdb: Kysely<Database>,\n\tmatches: MatchedTx[],\n\tkeyMeta: Map<string, TriggerKeyMeta>,\n\tblockHeight: number,\n\tblockHash: string,\n\topts?: { replayId?: string },\n): Promise<number> {\n\tconst replayId = opts?.replayId;\n\tconst rows: InsertSubscriptionOutbox[] = [];\n\tfor (const match of matches) {\n\t\tconst meta = keyMeta.get(match.sourceName);\n\t\tif (!meta) continue;\n\t\tconst txId = match.tx.tx_id;\n\t\tif (TX_LEVEL_TRIGGER_TYPES.has(meta.triggerType)) {\n\t\t\trows.push(\n\t\t\t\tapplyRow(\n\t\t\t\t\tmeta,\n\t\t\t\t\tblockHeight,\n\t\t\t\t\tblockHash,\n\t\t\t\t\ttxId,\n\t\t\t\t\t-1,\n\t\t\t\t\t{\n\t\t\t\t\t\ttx_id: txId,\n\t\t\t\t\t\ttype: match.tx.type,\n\t\t\t\t\t\tsender: match.tx.sender,\n\t\t\t\t\t\tstatus: match.tx.status,\n\t\t\t\t\t\tcontract_id: match.tx.contract_id ?? null,\n\t\t\t\t\t\tfunction_name: match.tx.function_name ?? null,\n\t\t\t\t\t\tfunction_args: match.tx.function_args ?? null,\n\t\t\t\t\t\tresult_hex: match.tx.raw_result ?? null,\n\t\t\t\t\t},\n\t\t\t\t\treplayId,\n\t\t\t\t),\n\t\t\t);\n\t\t} else {\n\t\t\tfor (const event of match.events) {\n\t\t\t\trows.push(\n\t\t\t\t\tapplyRow(\n\t\t\t\t\t\tmeta,\n\t\t\t\t\t\tblockHeight,\n\t\t\t\t\t\tblockHash,\n\t\t\t\t\t\ttxId,\n\t\t\t\t\t\tevent.event_index,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttx_id: txId,\n\t\t\t\t\t\t\ttype: event.type,\n\t\t\t\t\t\t\tevent_index: event.event_index,\n\t\t\t\t\t\t\tdata: event.data,\n\t\t\t\t\t\t},\n\t\t\t\t\t\treplayId,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\tif (rows.length === 0) return 0;\n\t// Net-inserted (not built) so callers count genuinely new deliveries — a\n\t// re-processed block or a re-run replay returns 0.\n\tconst result = await db\n\t\t.insertInto(\"subscription_outbox\")\n\t\t.values(rows)\n\t\t.onConflict((oc) =>\n\t\t\toc.columns([\"subscription_id\", \"dedup_key\"]).doNothing(),\n\t\t)\n\t\t.executeTakeFirst();\n\treturn Number(result.numInsertedOrUpdatedRows ?? 0);\n}\n\n// ── sBTC event matching ──────────────────────────────────────────────────────\n\ntype SbtcRow = Selectable<SbtcEventsTable>;\n\nasync function loadSbtcEventsForBlock(\n\tdb: Kysely<Database>,\n\tblockHeight: number,\n\ttopics: SbtcEventTopic[],\n): Promise<SbtcRow[]> {\n\tif (topics.length === 0) return [];\n\treturn db\n\t\t.selectFrom(\"sbtc_events\")\n\t\t.selectAll()\n\t\t.where(\"block_height\", \"=\", blockHeight)\n\t\t.where(\"canonical\", \"=\", true)\n\t\t.where(\"topic\", \"in\", topics)\n\t\t.execute();\n}\n\nfunction toAmountBigInt(v: string | number | undefined): bigint | undefined {\n\treturn v === undefined ? undefined : BigInt(v);\n}\n\nfunction matchSbtcTrigger(trigger: ChainTrigger, row: SbtcRow): boolean {\n\tconst expectedTopic = SBTC_TRIGGER_TO_TOPIC[trigger.type];\n\tif (!expectedTopic || row.topic !== expectedTopic) return false;\n\n\tif (trigger.type === \"sbtc_deposit\") {\n\t\tif (trigger.sender && row.sender !== trigger.sender) return false;\n\t\tif (trigger.bitcoinTxid && row.bitcoin_txid !== trigger.bitcoinTxid)\n\t\t\treturn false;\n\t\tif (trigger.requestId !== undefined && row.request_id !== trigger.requestId)\n\t\t\treturn false;\n\t\tconst min = toAmountBigInt(trigger.minAmount);\n\t\tconst max = toAmountBigInt(trigger.maxAmount);\n\t\tif (min !== undefined || max !== undefined) {\n\t\t\tif (row.amount === null) return false;\n\t\t\tconst amt = BigInt(row.amount);\n\t\t\tif (min !== undefined && amt < min) return false;\n\t\t\tif (max !== undefined && amt > max) return false;\n\t\t}\n\t\treturn true;\n\t}\n\n\tif (trigger.type === \"sbtc_withdrawal_create\") {\n\t\tif (trigger.sender && row.sender !== trigger.sender) return false;\n\t\tif (trigger.requestId !== undefined && row.request_id !== trigger.requestId)\n\t\t\treturn false;\n\t\tconst min = toAmountBigInt(trigger.minAmount);\n\t\tconst max = toAmountBigInt(trigger.maxAmount);\n\t\tif (min !== undefined || max !== undefined) {\n\t\t\tif (row.amount === null) return false;\n\t\t\tconst amt = BigInt(row.amount);\n\t\t\tif (min !== undefined && amt < min) return false;\n\t\t\tif (max !== undefined && amt > max) return false;\n\t\t}\n\t\treturn true;\n\t}\n\n\tif (trigger.type === \"sbtc_withdrawal_accept\") {\n\t\tif (trigger.requestId !== undefined && row.request_id !== trigger.requestId)\n\t\t\treturn false;\n\t\tif (trigger.sweepTxid && row.sweep_txid !== trigger.sweepTxid) return false;\n\t\treturn true;\n\t}\n\n\tif (trigger.type === \"sbtc_withdrawal_reject\") {\n\t\tif (trigger.requestId !== undefined && row.request_id !== trigger.requestId)\n\t\t\treturn false;\n\t\treturn true;\n\t}\n\n\treturn false;\n}\n\nfunction buildSbtcEventPayload(\n\ttriggerType: ChainTrigger[\"type\"],\n\trow: SbtcRow,\n): SbtcDepositEvent | SbtcWithdrawalEvent {\n\tif (triggerType === \"sbtc_deposit\") {\n\t\treturn {\n\t\t\ttopic: \"completed-deposit\",\n\t\t\trequest_id: row.request_id ?? 0,\n\t\t\tsender: row.sender,\n\t\t\tamount: row.amount ?? \"0\",\n\t\t\tbitcoin_txid: row.bitcoin_txid,\n\t\t\tblock_height: row.block_height,\n\t\t\ttx_id: row.tx_id,\n\t\t} satisfies SbtcDepositEvent;\n\t}\n\treturn {\n\t\ttopic: row.topic as\n\t\t\t| \"withdrawal-create\"\n\t\t\t| \"withdrawal-accept\"\n\t\t\t| \"withdrawal-reject\",\n\t\trequest_id: row.request_id ?? 0,\n\t\tsender: row.sender,\n\t\tamount: row.amount,\n\t\tsweep_txid: row.sweep_txid,\n\t\tsettlement_confirmed: false,\n\t\tblock_height: row.block_height,\n\t\ttx_id: row.tx_id,\n\t} satisfies SbtcWithdrawalEvent;\n}\n\n/**\n * Match active sBTC chain subscriptions against `sbtc_events` for one block\n * and write apply-envelope rows to `subscription_outbox`. Runs alongside\n * `emitChainOutbox` (which handles decoded_events). Same dedup-key scheme —\n * re-processing the same block is idempotent.\n */\nexport async function emitSbtcOutbox(\n\tdb: Kysely<Database>,\n\tchainSubs: Subscription[],\n\tblockHeight: number,\n\tblockHash: string,\n\topts?: { replayId?: string; sourceDb?: Kysely<Database> },\n): Promise<number> {\n\tconst sbtcSubs = chainSubs.filter((sub) =>\n\t\ttriggersOf(sub).some((t) => isSbtcTriggerType(t.type)),\n\t);\n\tif (sbtcSubs.length === 0) return 0;\n\n\tconst neededTopics = new Set<SbtcEventTopic>();\n\tfor (const sub of sbtcSubs) {\n\t\tfor (const trigger of triggersOf(sub)) {\n\t\t\tconst topic = SBTC_TRIGGER_TO_TOPIC[trigger.type];\n\t\t\tif (topic) neededTopics.add(topic);\n\t\t}\n\t}\n\n\t// `sbtc_events` is a SOURCE-plane table; the evaluator runs on the TARGET\n\t// handle (where an empty same-named table exists post-split). Read the decoded\n\t// rows from the source plane explicitly — reading off `db` here silently\n\t// matched zero rows under the live split, so sBTC webhooks never fired.\n\tconst sbtcRows = await loadSbtcEventsForBlock(\n\t\topts?.sourceDb ?? getSourceDb(),\n\t\tblockHeight,\n\t\t[...neededTopics],\n\t);\n\tif (sbtcRows.length === 0) return 0;\n\n\tconst replayId = opts?.replayId;\n\tconst outboxRows: InsertSubscriptionOutbox[] = [];\n\n\tfor (const sub of sbtcSubs) {\n\t\ttriggersOf(sub).forEach((trigger, triggerIndex) => {\n\t\t\tif (!isSbtcTriggerType(trigger.type)) return;\n\t\t\tconst meta: TriggerKeyMeta = {\n\t\t\t\tsubscriptionId: sub.id,\n\t\t\t\ttriggerIndex,\n\t\t\t\ttriggerType: trigger.type,\n\t\t\t};\n\t\t\tfor (const row of sbtcRows) {\n\t\t\t\tif (!matchSbtcTrigger(trigger, row)) continue;\n\t\t\t\tconst event = buildSbtcEventPayload(trigger.type, row);\n\t\t\t\toutboxRows.push(\n\t\t\t\t\tapplyRow(\n\t\t\t\t\t\tmeta,\n\t\t\t\t\t\tblockHeight,\n\t\t\t\t\t\tblockHash,\n\t\t\t\t\t\trow.tx_id,\n\t\t\t\t\t\trow.event_index,\n\t\t\t\t\t\tevent as unknown as Record<string, unknown>,\n\t\t\t\t\t\treplayId,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t});\n\t}\n\n\tif (outboxRows.length === 0) return 0;\n\tconst result = await db\n\t\t.insertInto(\"subscription_outbox\")\n\t\t.values(outboxRows)\n\t\t.onConflict((oc) =>\n\t\t\toc.columns([\"subscription_id\", \"dedup_key\"]).doNothing(),\n\t\t)\n\t\t.executeTakeFirst();\n\treturn Number(result.numInsertedOrUpdatedRows ?? 0);\n}\n\n/**\n * Emit the `sbtc_withdrawal_swept_confirmed` webhook. Unlike the per-block sBTC\n * path, this fires on a BITCOIN confirmation (async to Stacks blocks), so it\n * scans `sbtc_settlements` on its own cadence rather than per Stacks block.\n *\n * - Reads/advances a dedicated `last_settlement_scan_at` watermark on `db` (the\n * target/control plane). Null cursor → fast-forward to `now`, emit nothing\n * (forward-only, no historical backfill — mirrors the block cursor).\n * - Scans confirmed settlements with `confirmed_at > cursor` from the SOURCE\n * plane (`sbtc_settlements` is source), joined to the Stacks accept event +\n * block for the envelope anchor.\n * - Per-sub forward-only (`confirmed_at > sub.created_at`) + optional\n * requestId/sweepTxid filters; dedup on `(subscription_id, sweep_txid)` so a\n * reorg→un-confirm→re-confirm never double-fires.\n */\nexport async function emitSbtcSettlementOutbox(\n\tdb: Kysely<Database>,\n\tchainSubs: Subscription[],\n\topts?: { sourceDb?: Kysely<Database>; now?: Date },\n): Promise<number> {\n\tconst settlementSubs = chainSubs.filter((sub) =>\n\t\ttriggersOf(sub).some((t) => t.type === SETTLEMENT_TRIGGER_TYPE),\n\t);\n\tif (settlementSubs.length === 0) return 0;\n\n\tconst now = opts?.now ?? new Date();\n\tconst state = await db\n\t\t.selectFrom(\"trigger_evaluator_state\")\n\t\t.select(\"last_settlement_scan_at\")\n\t\t.where(\"id\", \"=\", true)\n\t\t.executeTakeFirst();\n\n\t// Uninitialized → fast-forward, emit nothing (forward-only).\n\tconst cursor = state?.last_settlement_scan_at ?? null;\n\tif (cursor === null) {\n\t\tawait db\n\t\t\t.updateTable(\"trigger_evaluator_state\")\n\t\t\t.set({ last_settlement_scan_at: now })\n\t\t\t.where(\"id\", \"=\", true)\n\t\t\t.execute();\n\t\treturn 0;\n\t}\n\n\tconst sourceDb = opts?.sourceDb ?? getSourceDb();\n\tconst rows = await sourceDb\n\t\t.selectFrom(\"sbtc_settlements as s\")\n\t\t.innerJoin(\"sbtc_events as e\", (join) =>\n\t\t\tjoin\n\t\t\t\t.onRef(\"e.sweep_txid\", \"=\", \"s.sweep_txid\")\n\t\t\t\t.on(\"e.topic\", \"=\", \"withdrawal-accept\")\n\t\t\t\t.on(\"e.canonical\", \"=\", true),\n\t\t)\n\t\t.innerJoin(\"blocks as b\", (join) =>\n\t\t\tjoin\n\t\t\t\t.onRef(\"b.height\", \"=\", \"e.block_height\")\n\t\t\t\t.on(\"b.canonical\", \"=\", true),\n\t\t)\n\t\t.where(\"s.settlement_confirmed\", \"=\", true)\n\t\t.where(\"s.confirmed_at\", \">\", cursor)\n\t\t.select([\n\t\t\t\"s.sweep_txid\",\n\t\t\t\"s.request_id\",\n\t\t\t\"s.btc_confirmations\",\n\t\t\t\"s.block_height as btc_block_height\",\n\t\t\t\"s.confirmed_at\",\n\t\t\t\"e.tx_id\",\n\t\t\t\"e.block_height as stacks_block_height\",\n\t\t\t\"e.amount\",\n\t\t\t\"e.sender\",\n\t\t\t\"b.hash as block_hash\",\n\t\t])\n\t\t.execute();\n\n\tif (rows.length === 0) return 0;\n\n\tconst outboxRows: InsertSubscriptionOutbox[] = [];\n\tlet maxConfirmedAt = cursor;\n\tfor (const row of rows) {\n\t\tconst confirmedAt = row.confirmed_at;\n\t\tif (confirmedAt && confirmedAt > maxConfirmedAt)\n\t\t\tmaxConfirmedAt = confirmedAt;\n\t\tif (!confirmedAt) continue;\n\t\tfor (const sub of settlementSubs) {\n\t\t\t// Forward-only: a sub only receives settlements confirmed after it existed.\n\t\t\tif (confirmedAt <= sub.created_at) continue;\n\t\t\tconst trigger = triggersOf(sub).find(\n\t\t\t\t(t) => t.type === SETTLEMENT_TRIGGER_TYPE,\n\t\t\t);\n\t\t\tif (!trigger || trigger.type !== SETTLEMENT_TRIGGER_TYPE) continue;\n\t\t\tif (\n\t\t\t\ttrigger.requestId !== undefined &&\n\t\t\t\ttrigger.requestId !== Number(row.request_id)\n\t\t\t) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (\n\t\t\t\ttrigger.sweepTxid !== undefined &&\n\t\t\t\ttrigger.sweepTxid !== row.sweep_txid\n\t\t\t) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\toutboxRows.push(settlementApplyRow(sub.id, row));\n\t\t}\n\t}\n\n\tif (outboxRows.length > 0) {\n\t\tawait db\n\t\t\t.insertInto(\"subscription_outbox\")\n\t\t\t.values(outboxRows)\n\t\t\t.onConflict((oc) =>\n\t\t\t\toc.columns([\"subscription_id\", \"dedup_key\"]).doNothing(),\n\t\t\t)\n\t\t\t.execute();\n\t}\n\n\t// Advance the watermark past every settlement scanned this pass (even ones\n\t// filtered out per-sub — they're in the past for any future subscriber).\n\tawait db\n\t\t.updateTable(\"trigger_evaluator_state\")\n\t\t.set({ last_settlement_scan_at: maxConfirmedAt })\n\t\t.where(\"id\", \"=\", true)\n\t\t.execute();\n\n\treturn outboxRows.length;\n}\n\ntype SettlementScanRow = {\n\tsweep_txid: string;\n\trequest_id: number;\n\tbtc_confirmations: number;\n\tbtc_block_height: number | null;\n\tconfirmed_at: Date | null;\n\ttx_id: string;\n\tstacks_block_height: number;\n\tamount: string | null;\n\tsender: string | null;\n\tblock_hash: string;\n};\n\nfunction settlementApplyRow(\n\tsubscriptionId: string,\n\trow: SettlementScanRow,\n): InsertSubscriptionOutbox {\n\tconst event: SbtcWithdrawalSweptConfirmedEvent = {\n\t\ttopic: \"withdrawal-swept-confirmed\",\n\t\trequest_id: Number(row.request_id),\n\t\tsweep_txid: row.sweep_txid,\n\t\tbtc_confirmations: row.btc_confirmations,\n\t\tbtc_block_height: row.btc_block_height,\n\t\tconfirmed_at: row.confirmed_at ? row.confirmed_at.toISOString() : null,\n\t\tamount: row.amount,\n\t\tsender: row.sender,\n\t};\n\tconst payload: ChainApplyEnvelope = {\n\t\taction: \"apply\",\n\t\tblock_hash: row.block_hash,\n\t\tblock_height: Number(row.stacks_block_height),\n\t\ttx_id: row.tx_id,\n\t\tcanonical: true,\n\t\ttrigger: SETTLEMENT_TRIGGER_TYPE,\n\t\tevent,\n\t};\n\treturn {\n\t\tsubscription_id: subscriptionId,\n\t\tkind: \"chain\",\n\t\tsubgraph_name: null,\n\t\ttable_name: null,\n\t\tblock_height: Number(row.stacks_block_height),\n\t\ttx_id: row.tx_id,\n\t\trow_pk: { sweep_txid: row.sweep_txid },\n\t\tevent_type: `chain.${SETTLEMENT_TRIGGER_TYPE}.apply`,\n\t\tpayload,\n\t\t// Settlement fires on a Bitcoin confirmation, not a Stacks block — dedup on\n\t\t// the sweep so a reorg→un-confirm→re-confirm cycle never re-delivers.\n\t\tdedup_key: `settlement:${subscriptionId}:${row.sweep_txid}`,\n\t};\n}\n"
12
12
  ],
13
- "mappings": ";;;;AAgCA,IAAM,eAAe,IAAI;AAEzB,SAAS,YAAY,CAAC,OAAe,SAA0B;AAAA,EAC9D,IAAI,CAAC,QAAQ,SAAS,GAAG;AAAA,IAAG,OAAO,UAAU;AAAA,EAC7C,IAAI,KAAK,aAAa,IAAI,OAAO;AAAA,EACjC,IAAI,CAAC,IAAI;AAAA,IACR,MAAM,QAAQ,QACZ,QAAQ,qBAAqB,MAAM,EACnC,QAAQ,OAAO,IAAI;AAAA,IACrB,KAAK,IAAI,OAAO,IAAI,QAAQ;AAAA,IAC5B,aAAa,IAAI,SAAS,EAAE;AAAA,EAC7B;AAAA,EACA,OAAO,GAAG,KAAK,KAAK;AAAA;AAOrB,IAAM,YAAiC,IAAI;AAM3C,SAAS,WAAW,CACnB,QACA,YACA,gBACU;AAAA,EACV,MAAM,QAAS,OAA8B;AAAA,EAC7C,IAAI,CAAC;AAAA,IAAO,OAAO;AAAA,EACnB,IAAI,CAAC;AAAA,IAAY,OAAO;AAAA,EACxB,QAAQ,eAAe,IAAI,KAAK,KAAK,WAAW,IAAI,UAAU;AAAA;AAI/D,SAAS,a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,cAAc;AAAA,MACzD,IAAI,QAAQ,WAAW;AAAA,QAAG;AAAA,MAC1B,YAAY,MAAM,gBACjB,IACA,SACA,SACA,GACA,GAAG,MAAM,MACT;AAAA,QACC;AAAA,MACD,CACD;AAAA,IACD;AAAA,EACD;AAAA,EAEA,QAAO,KAAK,yBAAyB;AAAA,IACpC,cAAc,IAAI;AAAA,IAClB;AAAA,IACA;AAAA,IACA;AAAA,IACA,WAAW,MAAM;AAAA,IACjB,SAAS,MAAM;AAAA,EAChB,CAAC;AAAA,EAED,OAAO,EAAE,UAAU,eAAe,UAAU,cAAc,QAAQ;AAAA;",
14
+ "debugId": "CB4A2ECFD309F74564756E2164756E21",
15
15
  "names": []
16
16
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@secondlayer/subgraphs",
3
- "version": "3.16.0",
3
+ "version": "3.17.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -45,9 +45,7 @@
45
45
  "import": "./dist/src/runtime/emitter.js"
46
46
  }
47
47
  },
48
- "files": [
49
- "dist"
50
- ],
48
+ "files": ["dist"],
51
49
  "scripts": {
52
50
  "build": "bunup",
53
51
  "dev": "bunup --watch",
@@ -56,7 +54,7 @@
56
54
  "prepublishOnly": "bun run build"
57
55
  },
58
56
  "dependencies": {
59
- "@secondlayer/shared": "^6.37.0",
57
+ "@secondlayer/shared": "^6.38.0",
60
58
  "@secondlayer/stacks": "^2.3.0",
61
59
  "kysely": "0.28.15",
62
60
  "zod": "^4.3.6"