@secondlayer/subgraphs 3.23.0 → 3.23.2

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.
@@ -1,4 +1,5 @@
1
1
  import { AbiContract as AbiContract2 } from "@secondlayer/stacks/clarity";
2
+ import { AssetIdentifier } from "@secondlayer/stacks/filters";
2
3
  /**
3
4
  * How long a read stays valid.
4
5
  *
@@ -147,38 +148,38 @@ interface FactoryScope {
147
148
  /** FT event filters */
148
149
  interface FtTransferFilter extends TraitScope {
149
150
  type: "ft_transfer";
150
- assetIdentifier?: string;
151
+ assetIdentifier?: AssetIdentifier;
151
152
  sender?: string;
152
153
  recipient?: string;
153
154
  minAmount?: bigint;
154
155
  }
155
156
  interface FtMintFilter extends TraitScope {
156
157
  type: "ft_mint";
157
- assetIdentifier?: string;
158
+ assetIdentifier?: AssetIdentifier;
158
159
  recipient?: string;
159
160
  minAmount?: bigint;
160
161
  }
161
162
  interface FtBurnFilter extends TraitScope {
162
163
  type: "ft_burn";
163
- assetIdentifier?: string;
164
+ assetIdentifier?: AssetIdentifier;
164
165
  sender?: string;
165
166
  minAmount?: bigint;
166
167
  }
167
168
  /** NFT event filters */
168
169
  interface NftTransferFilter extends TraitScope {
169
170
  type: "nft_transfer";
170
- assetIdentifier?: string;
171
+ assetIdentifier?: AssetIdentifier;
171
172
  sender?: string;
172
173
  recipient?: string;
173
174
  }
174
175
  interface NftMintFilter extends TraitScope {
175
176
  type: "nft_mint";
176
- assetIdentifier?: string;
177
+ assetIdentifier?: AssetIdentifier;
177
178
  recipient?: string;
178
179
  }
179
180
  interface NftBurnFilter extends TraitScope {
180
181
  type: "nft_burn";
181
- assetIdentifier?: string;
182
+ assetIdentifier?: AssetIdentifier;
182
183
  sender?: string;
183
184
  }
184
185
  /**
@@ -276,7 +277,10 @@ type PrintField = ColumnType | {
276
277
  interface PrintEventFilter extends TraitScope, FactoryScope {
277
278
  type: "print_event";
278
279
  /** One contract id, or a set of them (max 20). Supports `*` wildcards.
279
- * Mutually exclusive with `trait`. */
280
+ * COMPOSES with `trait` — the matcher ANDs them, so the pair means
281
+ * "contracts conforming to this trait, narrowed to these ids". (The Index
282
+ * read API refuses the combination, but that is its query planner's
283
+ * constraint, not a semantic one.) */
280
284
  contractId?: string | readonly string[];
281
285
  topic?: string;
282
286
  /**
@@ -308,27 +312,6 @@ interface TxMeta {
308
312
  type RowValue = string | number | bigint | boolean | null | undefined | Record<string, unknown> | unknown[];
309
313
  /** Value or computed function that receives existing row */
310
314
  type ComputedValue = RowValue | ((existing: Record<string, unknown> | null) => unknown);
311
- interface BlockMeta {
312
- height: number;
313
- hash: string;
314
- timestamp: number;
315
- burnBlockHeight: number;
316
- /**
317
- * Nakamoto StacksBlockId — the identifier `?tip=` accepts, and the only way
318
- * to pin a read-only call to THIS block. Null on rows ingested before it
319
- * was persisted; `ctx.client.readOnly` refuses to run rather than silently
320
- * reading at the node's tip.
321
- */
322
- indexBlockHash?: string | null;
323
- }
324
- interface TxMeta2 {
325
- txId: string;
326
- sender: string;
327
- type: string;
328
- status: string;
329
- contractId?: string | null;
330
- functionName?: string | null;
331
- }
332
315
  interface MatchedTx {
333
316
  tx: TxRecord;
334
317
  events: EventRecord[];
@@ -354,6 +337,27 @@ type EventRecord = {
354
337
  event_index: number
355
338
  data: unknown
356
339
  };
340
+ interface BlockMeta {
341
+ height: number;
342
+ hash: string;
343
+ timestamp: number;
344
+ burnBlockHeight: number;
345
+ /**
346
+ * Nakamoto StacksBlockId — the identifier `?tip=` accepts, and the only way
347
+ * to pin a read-only call to THIS block. Null on rows ingested before it
348
+ * was persisted; `ctx.client.readOnly` refuses to run rather than silently
349
+ * reading at the node's tip.
350
+ */
351
+ indexBlockHash?: string | null;
352
+ }
353
+ interface TxMeta2 {
354
+ txId: string;
355
+ sender: string;
356
+ type: string;
357
+ status: string;
358
+ contractId?: string | null;
359
+ functionName?: string | null;
360
+ }
357
361
  /**
358
362
  * Build a typed event payload based on the source filter type.
359
363
  * Returns the payload the handler will receive.
@@ -2,7 +2,7 @@ import { createRequire } from "node:module";
2
2
  var __require = /* @__PURE__ */ createRequire(import.meta.url);
3
3
 
4
4
  // src/runtime/context.ts
5
- import { logger } from "@secondlayer/shared/logger";
5
+ import { logger as logger2 } from "@secondlayer/shared/logger";
6
6
  import { formatUnits } from "@secondlayer/stacks/utils";
7
7
  import { sql } from "kysely";
8
8
 
@@ -147,6 +147,7 @@ function generateSubgraphSQL(def, schemaNameOverride) {
147
147
 
148
148
  // src/runtime/chain-read.ts
149
149
  import { getSourceDb } from "@secondlayer/shared/db";
150
+ import { logger } from "@secondlayer/shared/logger";
150
151
  import { http, createPublicClient } from "@secondlayer/stacks";
151
152
  import {
152
153
  ContractResponseError,
@@ -232,6 +233,14 @@ function createChainReadClient(ctx) {
232
233
  const pinnedTo = constant ? null : ctx.indexBlockHash;
233
234
  const cached = await db.selectFrom("chain_read_cache").select("result_hex").where("contract_id", "=", contractId).where("function_name", "=", fn.name).where("args_hash", "=", argsHash).where((eb) => pinnedTo === null ? eb("index_block_hash", "is", null) : eb("index_block_hash", "=", pinnedTo)).executeTakeFirst();
234
235
  const resultHex = cached?.result_hex ?? await gate.run(async () => {
236
+ if (!ctx.indexBlockHash) {
237
+ logger.warn("Chain read is not pinned to a block (no index_block_hash)", {
238
+ contractId,
239
+ functionName: fn.name,
240
+ blockHeight: ctx.blockHeight,
241
+ note: 'cache: "contract-constant" asserts this value cannot change; the node answered at its own tip'
242
+ });
243
+ }
235
244
  const value2 = await readContract(nodeClient(rpcUrl), {
236
245
  contract: contractId,
237
246
  functionName: fn.name,
@@ -346,7 +355,7 @@ class SubgraphContext {
346
355
  data: { ...key, ...row, ...meta, _upsert_keys: keyColumns }
347
356
  });
348
357
  } else {
349
- logger.warn("upsert called without matching uniqueKeys constraint, using fallback", {
358
+ logger2.warn("upsert called without matching uniqueKeys constraint, using fallback", {
350
359
  table,
351
360
  keys: keyColumns
352
361
  });
@@ -906,7 +915,7 @@ function decodeFunctionArgs(args) {
906
915
 
907
916
  // src/runtime/runner.ts
908
917
  import { getErrorMessage } from "@secondlayer/shared";
909
- import { logger as logger2 } from "@secondlayer/shared/logger";
918
+ import { logger as logger3 } from "@secondlayer/shared/logger";
910
919
  import {
911
920
  clarityValueToJS,
912
921
  deserializeCV as deserializeCV3,
@@ -1257,7 +1266,7 @@ async function runHandlers(subgraph, matched, ctx, opts) {
1257
1266
  units.sort((a, b) => (a.tx.tx_index ?? 0) - (b.tx.tx_index ?? 0) || (a.event?.event_index ?? -1) - (b.event?.event_index ?? -1));
1258
1267
  for (const { tx, event, sourceName } of units) {
1259
1268
  if (errors >= threshold) {
1260
- logger2.error("Subgraph error threshold reached, skipping remaining events", {
1269
+ logger3.error("Subgraph error threshold reached, skipping remaining events", {
1261
1270
  subgraph: subgraph.name,
1262
1271
  errors,
1263
1272
  threshold
@@ -1266,7 +1275,7 @@ async function runHandlers(subgraph, matched, ctx, opts) {
1266
1275
  }
1267
1276
  const handler = subgraph.handlers[sourceName] ?? subgraph.handlers["*"] ?? null;
1268
1277
  if (!handler) {
1269
- logger2.warn("No handler found for source", {
1278
+ logger3.warn("No handler found for source", {
1270
1279
  subgraph: subgraph.name,
1271
1280
  sourceName,
1272
1281
  txId: tx.tx_id
@@ -1323,7 +1332,7 @@ async function runHandlers(subgraph, matched, ctx, opts) {
1323
1332
  const verdict = validatePrintPayload(filter.prints, printPayload.topic ?? "", printPayload.data ?? {});
1324
1333
  if (!verdict.ok) {
1325
1334
  skipped++;
1326
- logger2.warn("Print payload does not match declared prints schema", {
1335
+ logger3.warn("Print payload does not match declared prints schema", {
1327
1336
  subgraph: subgraph.name,
1328
1337
  sourceName,
1329
1338
  topic: printPayload.topic,
@@ -1338,7 +1347,7 @@ async function runHandlers(subgraph, matched, ctx, opts) {
1338
1347
  } catch (err) {
1339
1348
  ctx.rollbackTo(checkpoint);
1340
1349
  errors++;
1341
- logger2.error("Subgraph handler error", {
1350
+ logger3.error("Subgraph handler error", {
1342
1351
  subgraph: subgraph.name,
1343
1352
  sourceName,
1344
1353
  txId: tx.tx_id,
@@ -1459,5 +1468,5 @@ export {
1459
1468
  buildEvent
1460
1469
  };
1461
1470
 
1462
- //# debugId=FEF5AC4898A3E56764756E2164756E21
1471
+ //# debugId=723A35E8C93CB61C64756E2164756E21
1463
1472
  //# sourceMappingURL=index.js.map