@secondlayer/subgraphs 7.2.0 → 7.3.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.
@@ -17,7 +17,7 @@ import { createHash } from "node:crypto";
17
17
  // package.json
18
18
  var package_default = {
19
19
  name: "@secondlayer/subgraphs",
20
- version: "7.2.0",
20
+ version: "7.3.0",
21
21
  description: "Describe the Stacks data you want as one TypeScript file; it fills itself and survives reorgs.",
22
22
  license: "MIT",
23
23
  repository: {
@@ -77,7 +77,7 @@ var package_default = {
77
77
  prepublishOnly: "bun run build"
78
78
  },
79
79
  dependencies: {
80
- "@secondlayer/shared": "^13.1.0",
80
+ "@secondlayer/shared": "^13.2.0",
81
81
  "@secondlayer/stacks": "^6.4.0",
82
82
  "@secondlayer/verify": "^0.6.0",
83
83
  esbuild: "^0.28.2",
@@ -1166,6 +1166,8 @@ function databaseChainDataReader(db) {
1166
1166
  };
1167
1167
  }
1168
1168
  var THROUGH_TIP = Number.MAX_SAFE_INTEGER;
1169
+ var TRAIT_REFRESH_MS = 5000;
1170
+ var TRAIT_OVERLAP_MS = 5 * 60000;
1169
1171
  var traitCaches = new WeakMap;
1170
1172
  function traitCacheFor(client) {
1171
1173
  let cache = traitCaches.get(client);
@@ -1200,7 +1202,8 @@ function oneWithdrawalPerSweep(rows) {
1200
1202
  }
1201
1203
  return [...bySweep.values()];
1202
1204
  }
1203
- function hostedChainDataReader(client) {
1205
+ function hostedChainDataReader(client, opts = {}) {
1206
+ const now = opts.now ?? Date.now;
1204
1207
  return {
1205
1208
  async sbtcEvents(fromHeight, toHeight, topics) {
1206
1209
  if (topics.length === 0)
@@ -1211,19 +1214,34 @@ function hostedChainDataReader(client) {
1211
1214
  async traitContractIds(trait, asOfBlock) {
1212
1215
  const cache = traitCacheFor(client);
1213
1216
  let entry = cache.get(trait);
1214
- if (!entry || asOfBlock > entry.coveredThrough) {
1215
- const rows = await client.listContractsByTrait(trait);
1216
- const members = rows.map((r) => ({
1217
- contractId: r.contract_id,
1218
- blockHeight: Number(r.block_height)
1219
- }));
1217
+ const due = !entry || asOfBlock > entry.checkedThrough && now() - entry.fetchedAt >= TRAIT_REFRESH_MS;
1218
+ if (due) {
1219
+ const since = entry?.classifiedThrough == null ? undefined : new Date(entry.classifiedThrough - TRAIT_OVERLAP_MS);
1220
+ const rows = await client.listContractsByTrait(trait, since ? { classifiedAfter: since } : undefined);
1221
+ const members = entry?.members ?? new Map;
1222
+ let classifiedThrough = entry?.classifiedThrough ?? null;
1223
+ for (const r of rows) {
1224
+ members.set(r.contract_id, Number(r.block_height));
1225
+ if (r.classified_at) {
1226
+ classifiedThrough = Math.max(classifiedThrough ?? 0, new Date(r.classified_at).getTime());
1227
+ }
1228
+ }
1220
1229
  entry = {
1221
1230
  members,
1222
- coveredThrough: Math.max(asOfBlock, ...members.map((m) => m.blockHeight))
1231
+ classifiedThrough,
1232
+ checkedThrough: asOfBlock,
1233
+ fetchedAt: now()
1223
1234
  };
1224
1235
  cache.set(trait, entry);
1225
1236
  }
1226
- return entry.members.filter((m) => m.blockHeight <= asOfBlock).map((m) => m.contractId);
1237
+ if (!entry)
1238
+ return [];
1239
+ const ids = [];
1240
+ for (const [contractId, height] of entry.members) {
1241
+ if (height <= asOfBlock)
1242
+ ids.push(contractId);
1243
+ }
1244
+ return ids;
1227
1245
  },
1228
1246
  async settlementsConfirmedAfter(after) {
1229
1247
  const withdrawals = oneWithdrawalPerSweep(await client.fetchSettledWithdrawals(after));
@@ -2085,5 +2103,5 @@ export {
2085
2103
  replayWebhook
2086
2104
  };
2087
2105
 
2088
- //# debugId=719BB77ECD650B4564756E2164756E21
2106
+ //# debugId=E8EBA7C326C2348864756E2164756E21
2089
2107
  //# sourceMappingURL=replay.js.map