@secondlayer/shared 15.6.1 → 17.0.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.
Files changed (64) hide show
  1. package/dist/src/archive/range-digest.d.ts +2 -36
  2. package/dist/src/archive/semantic-digest-builder.d.ts +2 -36
  3. package/dist/src/classify/index.js +1 -4
  4. package/dist/src/classify/index.js.map +3 -3
  5. package/dist/src/coverage/index.d.ts +2 -36
  6. package/dist/src/crypto/secondlayer-webhook.js +1 -4
  7. package/dist/src/crypto/secondlayer-webhook.js.map +3 -3
  8. package/dist/src/db/index.d.ts +8 -152
  9. package/dist/src/db/index.js +3 -70
  10. package/dist/src/db/index.js.map +6 -6
  11. package/dist/src/db/queries/chain-reorgs.d.ts +2 -36
  12. package/dist/src/db/queries/chain-reorgs.js +3 -70
  13. package/dist/src/db/queries/chain-reorgs.js.map +6 -6
  14. package/dist/src/db/queries/contracts.d.ts +2 -36
  15. package/dist/src/db/queries/contracts.js.map +2 -2
  16. package/dist/src/db/queries/instance.d.ts +2 -36
  17. package/dist/src/db/queries/instance.js +1 -4
  18. package/dist/src/db/queries/instance.js.map +3 -3
  19. package/dist/src/db/queries/integrity.d.ts +2 -36
  20. package/dist/src/db/queries/integrity.js +1 -4
  21. package/dist/src/db/queries/integrity.js.map +3 -3
  22. package/dist/src/db/queries/subgraph-gaps.d.ts +2 -36
  23. package/dist/src/db/queries/subgraph-operations.d.ts +2 -36
  24. package/dist/src/db/queries/subgraphs.d.ts +2 -36
  25. package/dist/src/db/queries/sync-scope.d.ts +2 -36
  26. package/dist/src/db/queries/webhook-replays.d.ts +2 -36
  27. package/dist/src/db/queries/webhooks.d.ts +2 -36
  28. package/dist/src/db/schema.d.ts +3 -37
  29. package/dist/src/db/schema.js.map +2 -2
  30. package/dist/src/email/index.js +1 -4
  31. package/dist/src/email/index.js.map +3 -3
  32. package/dist/src/env.d.ts +2 -8
  33. package/dist/src/env.js +1 -5
  34. package/dist/src/env.js.map +3 -3
  35. package/dist/src/index-http.d.ts +1 -0
  36. package/dist/src/index-http.js.map +2 -2
  37. package/dist/src/index.d.ts +13 -164
  38. package/dist/src/index.js +6 -81
  39. package/dist/src/index.js.map +8 -8
  40. package/dist/src/insights/index.d.ts +2 -36
  41. package/dist/src/insights/index.js +1 -4
  42. package/dist/src/insights/index.js.map +3 -3
  43. package/dist/src/leader.js +3 -70
  44. package/dist/src/leader.js.map +6 -6
  45. package/dist/src/logger.js +1 -4
  46. package/dist/src/logger.js.map +3 -3
  47. package/dist/src/node/local-client.d.ts +2 -36
  48. package/dist/src/node/tx-summary.js +1 -4
  49. package/dist/src/node/tx-summary.js.map +3 -3
  50. package/dist/src/queue/listener.js +3 -70
  51. package/dist/src/queue/listener.js.map +6 -6
  52. package/dist/src/runtime/index.js +1 -2
  53. package/dist/src/runtime/index.js.map +3 -3
  54. package/dist/src/schemas/chain-triggers.js +2 -8
  55. package/dist/src/schemas/chain-triggers.js.map +3 -3
  56. package/dist/src/schemas/index.d.ts +1 -2
  57. package/dist/src/schemas/index.js +4 -11
  58. package/dist/src/schemas/index.js.map +4 -4
  59. package/dist/src/schemas/webhooks.d.ts +1 -2
  60. package/dist/src/schemas/webhooks.js +4 -11
  61. package/dist/src/schemas/webhooks.js.map +4 -4
  62. package/migrations/0205_sbtc_deposit_recipient.ts +75 -0
  63. package/migrations/0206_drop_pox4_calls.ts +32 -0
  64. package/package.json +2 -2
@@ -0,0 +1,75 @@
1
+ import { type Kysely, sql } from "kysely";
2
+ import { onChainPlane, onControlPlane } from "../src/db/migration-role.ts";
3
+
4
+ // `completed-deposit` prints carry no recipient, so deposits had no Stacks
5
+ // address. The recipient is the sBTC mint one event earlier in the same tx with
6
+ // the same amount (true for all 67,653 mainnet deposits at writing); the
7
+ // decoder now writes it to a new `recipient` column. `sender` stays for
8
+ // withdrawals, where it is the real sender.
9
+ //
10
+ // Chain plane: add the column, fill history from the decoded mints (~70k rows).
11
+ // Control plane: `sbtc_deposit` triggers filter on `recipient` instead of
12
+ // `sender`, and drop `requestId` (deposits have none). Each step is skipped
13
+ // when its table is absent.
14
+ async function tableExists(db: Kysely<unknown>, table: string) {
15
+ const { rows } = await sql<{ exists: boolean }>`
16
+ SELECT to_regclass(${`public.${table}`}) IS NOT NULL AS exists
17
+ `.execute(db);
18
+ return rows[0]?.exists === true;
19
+ }
20
+
21
+ export async function up(db: Kysely<unknown>): Promise<void> {
22
+ await sql`SET lock_timeout = '30s'`.execute(db);
23
+ await onChainPlane(async () => {
24
+ if (!(await tableExists(db, "sbtc_events"))) return;
25
+ await sql`ALTER TABLE sbtc_events ADD COLUMN IF NOT EXISTS recipient TEXT`.execute(
26
+ db,
27
+ );
28
+ await sql`
29
+ UPDATE sbtc_events e
30
+ SET recipient = t.recipient
31
+ FROM sbtc_token_events t
32
+ WHERE e.topic = 'completed-deposit'
33
+ AND e.recipient IS NULL
34
+ AND t.event_type = 'mint'
35
+ AND t.tx_id = e.tx_id
36
+ AND t.block_height = e.block_height
37
+ AND t.event_index = e.event_index - 1
38
+ AND t.amount = e.amount
39
+ `.execute(db);
40
+ await sql`CREATE INDEX IF NOT EXISTS sbtc_events_recipient_height_idx ON sbtc_events (recipient, block_height) WHERE recipient IS NOT NULL`.execute(
41
+ db,
42
+ );
43
+ });
44
+ await onControlPlane(async () => {
45
+ if (!(await tableExists(db, "webhooks"))) return;
46
+ await sql`
47
+ UPDATE webhooks
48
+ SET triggers = (
49
+ SELECT jsonb_agg(
50
+ CASE WHEN t->>'type' = 'sbtc_deposit'
51
+ THEN (t - 'sender' - 'requestId')
52
+ || CASE WHEN t ? 'sender'
53
+ THEN jsonb_build_object('recipient', t->'sender')
54
+ ELSE '{}'::jsonb END
55
+ ELSE t END
56
+ ORDER BY ord)
57
+ FROM jsonb_array_elements(triggers) WITH ORDINALITY AS a(t, ord)
58
+ )
59
+ WHERE jsonb_typeof(triggers) = 'array'
60
+ AND triggers @> '[{"type":"sbtc_deposit"}]'
61
+ `.execute(db);
62
+ });
63
+ }
64
+
65
+ export async function down(db: Kysely<unknown>): Promise<void> {
66
+ await onChainPlane(async () => {
67
+ if (!(await tableExists(db, "sbtc_events"))) return;
68
+ await sql`DROP INDEX IF EXISTS sbtc_events_recipient_height_idx`.execute(
69
+ db,
70
+ );
71
+ await sql`ALTER TABLE sbtc_events DROP COLUMN IF EXISTS recipient`.execute(
72
+ db,
73
+ );
74
+ });
75
+ }
@@ -0,0 +1,32 @@
1
+ import { type Kysely, sql } from "kysely";
2
+ import { onChainPlane } from "../src/db/migration-role.ts";
3
+
4
+ // The dedicated pox-4 decoder and `/v1/index/stacking` are gone: pox-4 is a
5
+ // retired contract (the chain runs pox-5), and its history stays readable
6
+ // through the generic layers (contract-calls, Streams). Drop the decoded table
7
+ // and the decoder's checkpoint row. Chain-plane only; each step is skipped
8
+ // when its table is absent.
9
+ async function tableExists(db: Kysely<unknown>, table: string) {
10
+ const { rows } = await sql<{ exists: boolean }>`
11
+ SELECT to_regclass(${`public.${table}`}) IS NOT NULL AS exists
12
+ `.execute(db);
13
+ return rows[0]?.exists === true;
14
+ }
15
+
16
+ export async function up(db: Kysely<unknown>): Promise<void> {
17
+ await sql`SET lock_timeout = '30s'`.execute(db);
18
+ await onChainPlane(async () => {
19
+ if (await tableExists(db, "pox4_calls")) {
20
+ await sql`DROP TABLE IF EXISTS pox4_calls`.execute(db);
21
+ }
22
+ if (await tableExists(db, "decoder_checkpoints")) {
23
+ await sql`DELETE FROM decoder_checkpoints WHERE decoder_name = 'decode.pox4.v1'`.execute(
24
+ db,
25
+ );
26
+ }
27
+ });
28
+ }
29
+
30
+ // No-op: nothing reads pox4_calls any more. Its rows are rebuildable from
31
+ // Streams (`contract_id=SP000000000000000000002Q6VF78.pox-4`) if ever needed.
32
+ export async function down(_db: Kysely<unknown>): Promise<void> {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@secondlayer/shared",
3
- "version": "15.6.1",
3
+ "version": "17.0.0",
4
4
  "description": "Internal building blocks shared across Secondlayer packages.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -273,7 +273,7 @@
273
273
  "prepublishOnly": "bun run build"
274
274
  },
275
275
  "dependencies": {
276
- "@secondlayer/stacks": "^6.6.1",
276
+ "@secondlayer/stacks": "^7.0.0",
277
277
  "kysely": "0.28.17",
278
278
  "kysely-postgres-js": "3.0.0",
279
279
  "postgres": "^3.4.6",