solforge 0.2.6 → 0.2.7

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.
@@ -0,0 +1,21 @@
1
+ import { index, primaryKey, sqliteTable, text } from "drizzle-orm/sqlite-core";
2
+
3
+ export const txAccountStates = sqliteTable(
4
+ "tx_account_states",
5
+ {
6
+ signature: text("signature").notNull(),
7
+ address: text("address").notNull(),
8
+ // JSON blobs capturing minimal account snapshot
9
+ // { lamports, ownerProgram, executable, rentEpoch, dataLen, dataBase64? }
10
+ preJson: text("pre_json"),
11
+ postJson: text("post_json"),
12
+ },
13
+ (t) => ({
14
+ pk: primaryKey({ columns: [t.signature, t.address], name: "pk_tx_account_states" }),
15
+ addrIdx: index("idx_tx_account_states_address").on(t.address),
16
+ }),
17
+ );
18
+
19
+ export type TxAccountStateRow = typeof txAccountStates.$inferSelect;
20
+ export type NewTxAccountStateRow = typeof txAccountStates.$inferInsert;
21
+
@@ -4,27 +4,36 @@ import { accounts } from "./schema/accounts";
4
4
  import { addressSignatures } from "./schema/address-signatures";
5
5
  import { transactions } from "./schema/transactions";
6
6
  import { txAccounts } from "./schema/tx-accounts";
7
+ import { txAccountStates } from "./schema/tx-account-states";
7
8
 
8
9
  export type InsertTxBundle = {
9
- signature: string;
10
- slot: number;
11
- blockTime?: number;
12
- version: 0 | "legacy";
13
- fee: number;
14
- err: unknown | null;
15
- rawBase64: string;
16
- preBalances: number[];
17
- postBalances: number[];
18
- logs: string[];
19
- accounts: Array<{
20
- address: string;
21
- index: number;
22
- signer: boolean;
23
- writable: boolean;
24
- programIdIndex?: number;
25
- }>;
26
- preTokenBalances?: unknown[];
27
- postTokenBalances?: unknown[];
10
+ signature: string;
11
+ slot: number;
12
+ blockTime?: number;
13
+ version: 0 | "legacy";
14
+ fee: number;
15
+ err: unknown | null;
16
+ rawBase64: string;
17
+ preBalances: number[];
18
+ postBalances: number[];
19
+ logs: string[];
20
+ innerInstructions?: unknown[];
21
+ computeUnits?: number | bigint | null;
22
+ returnData?: { programId: string; dataBase64: string } | null;
23
+ accounts: Array<{
24
+ address: string;
25
+ index: number;
26
+ signer: boolean;
27
+ writable: boolean;
28
+ programIdIndex?: number;
29
+ }>;
30
+ preTokenBalances?: unknown[];
31
+ postTokenBalances?: unknown[];
32
+ accountStates?: Array<{
33
+ address: string;
34
+ pre?: Partial<AccountSnapshot> | null;
35
+ post?: Partial<AccountSnapshot> | null;
36
+ }>;
28
37
  };
29
38
 
30
39
  export type AccountSnapshot = {
@@ -39,57 +48,81 @@ export type AccountSnapshot = {
39
48
  };
40
49
 
41
50
  export class TxStore {
42
- async insertTransactionBundle(bundle: InsertTxBundle): Promise<void> {
43
- const errJson = bundle.err ? JSON.stringify(bundle.err) : null;
44
- await db.transaction(async (tx) => {
45
- await tx
46
- .insert(transactions)
47
- .values({
48
- signature: bundle.signature,
49
- slot: bundle.slot,
50
- blockTime: bundle.blockTime ?? null,
51
- version: String(bundle.version),
52
- errJson,
53
- fee: bundle.fee,
54
- rawBase64: bundle.rawBase64,
55
- preBalancesJson: JSON.stringify(bundle.preBalances ?? []),
56
- postBalancesJson: JSON.stringify(bundle.postBalances ?? []),
57
- logsJson: JSON.stringify(bundle.logs ?? []),
58
- preTokenBalancesJson: JSON.stringify(bundle.preTokenBalances ?? []),
59
- postTokenBalancesJson: JSON.stringify(bundle.postTokenBalances ?? []),
60
- })
61
- .onConflictDoNothing();
62
-
63
- if (Array.isArray(bundle.accounts) && bundle.accounts.length > 0) {
64
- await tx
65
- .insert(txAccounts)
66
- .values(
67
- bundle.accounts.map((a) => ({
68
- signature: bundle.signature,
69
- accountIndex: a.index,
70
- address: a.address,
71
- signer: a.signer ? 1 : 0,
72
- writable: a.writable ? 1 : 0,
73
- programIdIndex: a.programIdIndex ?? null,
74
- })),
75
- )
76
- .onConflictDoNothing();
77
-
78
- await tx
79
- .insert(addressSignatures)
80
- .values(
81
- bundle.accounts.map((a) => ({
82
- address: a.address,
83
- signature: bundle.signature,
84
- slot: bundle.slot,
85
- err: errJson ? 1 : 0,
86
- blockTime: bundle.blockTime ?? null,
87
- })),
88
- )
89
- .onConflictDoNothing();
90
- }
91
- });
92
- }
51
+ async insertTransactionBundle(bundle: InsertTxBundle): Promise<void> {
52
+ const errJson = bundle.err ? JSON.stringify(bundle.err) : null;
53
+ await db.transaction(async (tx) => {
54
+ await tx
55
+ .insert(transactions)
56
+ .values({
57
+ signature: bundle.signature,
58
+ slot: bundle.slot,
59
+ blockTime: bundle.blockTime ?? null,
60
+ version: String(bundle.version),
61
+ errJson,
62
+ fee: bundle.fee,
63
+ rawBase64: bundle.rawBase64,
64
+ preBalancesJson: JSON.stringify(bundle.preBalances ?? []),
65
+ postBalancesJson: JSON.stringify(bundle.postBalances ?? []),
66
+ logsJson: JSON.stringify(bundle.logs ?? []),
67
+ preTokenBalancesJson: JSON.stringify(bundle.preTokenBalances ?? []),
68
+ postTokenBalancesJson: JSON.stringify(bundle.postTokenBalances ?? []),
69
+ innerInstructionsJson: JSON.stringify(bundle.innerInstructions ?? []),
70
+ computeUnits:
71
+ bundle.computeUnits == null
72
+ ? null
73
+ : Number(bundle.computeUnits),
74
+ returnDataProgramId: bundle.returnData?.programId ?? null,
75
+ returnDataBase64: bundle.returnData?.dataBase64 ?? null,
76
+ })
77
+ .onConflictDoNothing();
78
+
79
+ if (Array.isArray(bundle.accounts) && bundle.accounts.length > 0) {
80
+ await tx
81
+ .insert(txAccounts)
82
+ .values(
83
+ bundle.accounts.map((a) => ({
84
+ signature: bundle.signature,
85
+ accountIndex: a.index,
86
+ address: a.address,
87
+ signer: a.signer ? 1 : 0,
88
+ writable: a.writable ? 1 : 0,
89
+ programIdIndex: a.programIdIndex ?? null,
90
+ })),
91
+ )
92
+ .onConflictDoNothing();
93
+
94
+ await tx
95
+ .insert(addressSignatures)
96
+ .values(
97
+ bundle.accounts.map((a) => ({
98
+ address: a.address,
99
+ signature: bundle.signature,
100
+ slot: bundle.slot,
101
+ err: errJson ? 1 : 0,
102
+ blockTime: bundle.blockTime ?? null,
103
+ })),
104
+ )
105
+ .onConflictDoNothing();
106
+ }
107
+
108
+ if (
109
+ Array.isArray(bundle.accountStates) &&
110
+ bundle.accountStates.length > 0
111
+ ) {
112
+ await tx
113
+ .insert(txAccountStates)
114
+ .values(
115
+ bundle.accountStates.map((s) => ({
116
+ signature: bundle.signature,
117
+ address: s.address,
118
+ preJson: s.pre ? JSON.stringify(s.pre) : null,
119
+ postJson: s.post ? JSON.stringify(s.post) : null,
120
+ })),
121
+ )
122
+ .onConflictDoNothing();
123
+ }
124
+ });
125
+ }
93
126
 
94
127
  async upsertAccounts(snapshots: AccountSnapshot[]): Promise<void> {
95
128
  if (!Array.isArray(snapshots) || snapshots.length === 0) return;
@@ -10,8 +10,14 @@ import mig0000 from "../drizzle/0000_friendly_millenium_guard.sql" with {
10
10
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
11
11
  // @ts-expect-error - Bun import attributes
12
12
  import mig0001 from "../drizzle/0001_stale_sentinels.sql" with { type: "file" };
13
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
14
+ // @ts-expect-error - Bun import attributes
15
+ import mig0002 from "../drizzle/0002_graceful_caretaker.sql" with {
16
+ type: "file",
17
+ };
13
18
 
14
19
  export const bundledMigrations: Array<{ name: string; path: string }> = [
15
- { name: "0000_friendly_millenium_guard.sql", path: mig0000 },
16
- { name: "0001_stale_sentinels.sql", path: mig0001 },
20
+ { name: "0000_friendly_millenium_guard.sql", path: mig0000 },
21
+ { name: "0001_stale_sentinels.sql", path: mig0001 },
22
+ { name: "0002_graceful_caretaker.sql", path: mig0002 },
17
23
  ];