solforge 0.2.11 → 0.2.13

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 (175) hide show
  1. package/package.json +4 -8
  2. package/docs/API.md +0 -379
  3. package/docs/CONFIGURATION.md +0 -407
  4. package/docs/bun-single-file-executable.md +0 -585
  5. package/docs/cli-plan.md +0 -154
  6. package/docs/data-indexing-plan.md +0 -214
  7. package/docs/gui-roadmap.md +0 -202
  8. package/scripts/decode-b58.ts +0 -10
  9. package/scripts/install.sh +0 -112
  10. package/server/index.ts +0 -5
  11. package/server/lib/base58.ts +0 -33
  12. package/server/lib/faucet.ts +0 -110
  13. package/server/lib/instruction-parser.ts +0 -328
  14. package/server/lib/parsers/spl-associated-token-account.ts +0 -50
  15. package/server/lib/parsers/spl-token.ts +0 -340
  16. package/server/lib/spl-token.ts +0 -57
  17. package/server/methods/TEMPLATE.md +0 -117
  18. package/server/methods/account/get-account-info.ts +0 -86
  19. package/server/methods/account/get-balance.ts +0 -23
  20. package/server/methods/account/get-multiple-accounts.ts +0 -84
  21. package/server/methods/account/get-parsed-account-info.ts +0 -17
  22. package/server/methods/account/index.ts +0 -12
  23. package/server/methods/account/parsers/index.ts +0 -52
  24. package/server/methods/account/parsers/loader-upgradeable.ts +0 -79
  25. package/server/methods/account/parsers/spl-token.ts +0 -256
  26. package/server/methods/account/parsers/system.ts +0 -4
  27. package/server/methods/account/request-airdrop.ts +0 -271
  28. package/server/methods/admin/adopt-mint-authority.ts +0 -94
  29. package/server/methods/admin/clone-program-accounts.ts +0 -55
  30. package/server/methods/admin/clone-program.ts +0 -152
  31. package/server/methods/admin/clone-token-accounts.ts +0 -117
  32. package/server/methods/admin/clone-token-mint.ts +0 -82
  33. package/server/methods/admin/create-mint.ts +0 -114
  34. package/server/methods/admin/create-token-account.ts +0 -137
  35. package/server/methods/admin/helpers.ts +0 -70
  36. package/server/methods/admin/index.ts +0 -10
  37. package/server/methods/admin/list-mints.ts +0 -21
  38. package/server/methods/admin/load-program.ts +0 -52
  39. package/server/methods/admin/mint-to.ts +0 -266
  40. package/server/methods/block/get-block-height.ts +0 -5
  41. package/server/methods/block/get-block.ts +0 -31
  42. package/server/methods/block/get-blocks-with-limit.ts +0 -19
  43. package/server/methods/block/get-latest-blockhash.ts +0 -12
  44. package/server/methods/block/get-slot.ts +0 -5
  45. package/server/methods/block/index.ts +0 -6
  46. package/server/methods/block/is-blockhash-valid.ts +0 -19
  47. package/server/methods/epoch/get-cluster-nodes.ts +0 -17
  48. package/server/methods/epoch/get-epoch-info.ts +0 -16
  49. package/server/methods/epoch/get-epoch-schedule.ts +0 -15
  50. package/server/methods/epoch/get-highest-snapshot-slot.ts +0 -9
  51. package/server/methods/epoch/get-leader-schedule.ts +0 -8
  52. package/server/methods/epoch/get-max-retransmit-slot.ts +0 -9
  53. package/server/methods/epoch/get-max-shred-insert-slot.ts +0 -9
  54. package/server/methods/epoch/get-slot-leader.ts +0 -6
  55. package/server/methods/epoch/get-slot-leaders.ts +0 -9
  56. package/server/methods/epoch/get-stake-activation.ts +0 -9
  57. package/server/methods/epoch/get-stake-minimum-delegation.ts +0 -9
  58. package/server/methods/epoch/get-vote-accounts.ts +0 -19
  59. package/server/methods/epoch/index.ts +0 -13
  60. package/server/methods/epoch/minimum-ledger-slot.ts +0 -5
  61. package/server/methods/fee/get-fee-calculator-for-blockhash.ts +0 -12
  62. package/server/methods/fee/get-fee-for-message.ts +0 -8
  63. package/server/methods/fee/get-fee-rate-governor.ts +0 -16
  64. package/server/methods/fee/get-fees.ts +0 -14
  65. package/server/methods/fee/get-recent-prioritization-fees.ts +0 -22
  66. package/server/methods/fee/index.ts +0 -5
  67. package/server/methods/get-address-lookup-table.ts +0 -27
  68. package/server/methods/index.ts +0 -265
  69. package/server/methods/performance/get-recent-performance-samples.ts +0 -25
  70. package/server/methods/performance/get-transaction-count.ts +0 -5
  71. package/server/methods/performance/index.ts +0 -2
  72. package/server/methods/program/get-block-commitment.ts +0 -9
  73. package/server/methods/program/get-block-production.ts +0 -14
  74. package/server/methods/program/get-block-time.ts +0 -21
  75. package/server/methods/program/get-blocks.ts +0 -11
  76. package/server/methods/program/get-first-available-block.ts +0 -9
  77. package/server/methods/program/get-genesis-hash.ts +0 -6
  78. package/server/methods/program/get-identity.ts +0 -6
  79. package/server/methods/program/get-inflation-governor.ts +0 -15
  80. package/server/methods/program/get-inflation-rate.ts +0 -10
  81. package/server/methods/program/get-inflation-reward.ts +0 -12
  82. package/server/methods/program/get-largest-accounts.ts +0 -8
  83. package/server/methods/program/get-parsed-program-accounts.ts +0 -12
  84. package/server/methods/program/get-parsed-token-accounts-by-delegate.ts +0 -12
  85. package/server/methods/program/get-parsed-token-accounts-by-owner.ts +0 -12
  86. package/server/methods/program/get-program-accounts.ts +0 -221
  87. package/server/methods/program/get-supply.ts +0 -13
  88. package/server/methods/program/get-token-account-balance.ts +0 -60
  89. package/server/methods/program/get-token-accounts-by-delegate.ts +0 -82
  90. package/server/methods/program/get-token-accounts-by-owner.ts +0 -416
  91. package/server/methods/program/get-token-largest-accounts.ts +0 -81
  92. package/server/methods/program/get-token-supply.ts +0 -39
  93. package/server/methods/program/index.ts +0 -21
  94. package/server/methods/solforge/index.ts +0 -158
  95. package/server/methods/system/get-health.ts +0 -5
  96. package/server/methods/system/get-minimum-balance-for-rent-exemption.ts +0 -13
  97. package/server/methods/system/get-version.ts +0 -9
  98. package/server/methods/system/index.ts +0 -3
  99. package/server/methods/transaction/get-confirmed-transaction.ts +0 -11
  100. package/server/methods/transaction/get-parsed-transaction.ts +0 -17
  101. package/server/methods/transaction/get-signature-statuses.ts +0 -79
  102. package/server/methods/transaction/get-signatures-for-address.ts +0 -41
  103. package/server/methods/transaction/get-transaction.ts +0 -639
  104. package/server/methods/transaction/index.ts +0 -7
  105. package/server/methods/transaction/inner-instructions.test.ts +0 -104
  106. package/server/methods/transaction/send-transaction.ts +0 -469
  107. package/server/methods/transaction/simulate-transaction.ts +0 -57
  108. package/server/rpc-server.ts +0 -521
  109. package/server/types.ts +0 -109
  110. package/server/ws-server.ts +0 -178
  111. package/src/api-server-entry.ts +0 -109
  112. package/src/cli/bootstrap.ts +0 -67
  113. package/src/cli/commands/airdrop.ts +0 -37
  114. package/src/cli/commands/config.ts +0 -39
  115. package/src/cli/commands/mint.ts +0 -187
  116. package/src/cli/commands/program-clone.ts +0 -122
  117. package/src/cli/commands/program-load.ts +0 -64
  118. package/src/cli/commands/rpc-start.ts +0 -49
  119. package/src/cli/commands/token-adopt-authority.ts +0 -37
  120. package/src/cli/commands/token-clone.ts +0 -112
  121. package/src/cli/commands/token-create.ts +0 -81
  122. package/src/cli/main.ts +0 -152
  123. package/src/cli/run-solforge.ts +0 -112
  124. package/src/cli/setup-utils.ts +0 -54
  125. package/src/cli/setup-wizard.ts +0 -258
  126. package/src/cli/utils/args.ts +0 -15
  127. package/src/commands/add-program.ts +0 -333
  128. package/src/commands/init.ts +0 -122
  129. package/src/commands/list.ts +0 -136
  130. package/src/commands/mint.ts +0 -287
  131. package/src/commands/start.ts +0 -881
  132. package/src/commands/status.ts +0 -99
  133. package/src/commands/stop.ts +0 -405
  134. package/src/config/index.ts +0 -146
  135. package/src/config/manager.ts +0 -157
  136. package/src/db/index.ts +0 -83
  137. package/src/db/schema/accounts.ts +0 -23
  138. package/src/db/schema/address-signatures.ts +0 -31
  139. package/src/db/schema/index.ts +0 -6
  140. package/src/db/schema/meta-kv.ts +0 -9
  141. package/src/db/schema/transactions.ts +0 -36
  142. package/src/db/schema/tx-account-states.ts +0 -23
  143. package/src/db/schema/tx-accounts.ts +0 -33
  144. package/src/db/tx-store.ts +0 -264
  145. package/src/gui/public/app.css +0 -1556
  146. package/src/gui/public/build/main.css +0 -1569
  147. package/src/gui/public/build/main.js +0 -303
  148. package/src/gui/public/build/main.js.txt +0 -231
  149. package/src/gui/public/index.html +0 -19
  150. package/src/gui/server.ts +0 -296
  151. package/src/gui/src/api.ts +0 -127
  152. package/src/gui/src/app.tsx +0 -441
  153. package/src/gui/src/components/airdrop-mint-form.tsx +0 -246
  154. package/src/gui/src/components/clone-program-modal.tsx +0 -202
  155. package/src/gui/src/components/clone-token-modal.tsx +0 -230
  156. package/src/gui/src/components/modal.tsx +0 -134
  157. package/src/gui/src/components/programs-panel.tsx +0 -124
  158. package/src/gui/src/components/status-panel.tsx +0 -136
  159. package/src/gui/src/components/tokens-panel.tsx +0 -122
  160. package/src/gui/src/hooks/use-interval.ts +0 -17
  161. package/src/gui/src/index.css +0 -557
  162. package/src/gui/src/main.tsx +0 -17
  163. package/src/index.ts +0 -216
  164. package/src/migrations-bundled.ts +0 -23
  165. package/src/rpc/start.ts +0 -44
  166. package/src/services/api-server.ts +0 -504
  167. package/src/services/port-manager.ts +0 -174
  168. package/src/services/process-registry.ts +0 -153
  169. package/src/services/program-cloner.ts +0 -317
  170. package/src/services/token-cloner.ts +0 -811
  171. package/src/services/validator.ts +0 -293
  172. package/src/types/config.ts +0 -110
  173. package/src/utils/shell.ts +0 -110
  174. package/src/utils/token-loader.ts +0 -115
  175. /package/{start.js → start.cjs} +0 -0
@@ -1,104 +0,0 @@
1
- import { test, expect } from "bun:test";
2
- import {
3
- Keypair,
4
- LAMPORTS_PER_SOL,
5
- TransactionMessage,
6
- VersionedTransaction,
7
- PublicKey,
8
- } from "@solana/web3.js";
9
- import {
10
- getAssociatedTokenAddress,
11
- createAssociatedTokenAccountInstruction,
12
- } from "@solana/spl-token";
13
- import { LiteSVMRpcServer } from "../../rpc-server";
14
-
15
- type RpcResp<T = unknown> = {
16
- jsonrpc: "2.0";
17
- id: number;
18
- result?: T;
19
- error?: { code: number; message: string; data?: unknown };
20
- };
21
-
22
- function jsonReq(method: string, params?: unknown) {
23
- return {
24
- jsonrpc: "2.0",
25
- id: Math.floor(Math.random() * 1e9),
26
- method,
27
- params,
28
- };
29
- }
30
-
31
- test("captures inner instructions for ATA create (CPI)", async () => {
32
- const server = new LiteSVMRpcServer();
33
- async function call<T = unknown>(
34
- method: string,
35
- params?: unknown,
36
- ): Promise<RpcResp<T>> {
37
- return (await server.handleRequest(jsonReq(method, params))) as RpcResp<T>;
38
- }
39
-
40
- // Payer + airdrop
41
- const payer = Keypair.generate();
42
- const recip = Keypair.generate();
43
- await call("requestAirdrop", [
44
- payer.publicKey.toBase58(),
45
- 1 * LAMPORTS_PER_SOL,
46
- ]);
47
-
48
- // Create a test mint via admin helper
49
- const mintResp = await call<{ mint: string }>("solforgeCreateMint", [
50
- null,
51
- 6,
52
- null,
53
- ]);
54
- expect(mintResp.error).toBeUndefined();
55
- const mint = new PublicKey(mintResp.result?.mint);
56
-
57
- // Build 1 ATA instruction that triggers CPIs into system + token
58
- const bh = await call<{ value: { blockhash: string } }>(
59
- "getLatestBlockhash",
60
- [],
61
- );
62
- const ata = await getAssociatedTokenAddress(mint, recip.publicKey, false);
63
- const ix = createAssociatedTokenAccountInstruction(
64
- payer.publicKey,
65
- ata,
66
- recip.publicKey,
67
- mint,
68
- );
69
- const msg = new TransactionMessage({
70
- payerKey: payer.publicKey,
71
- recentBlockhash: bh.result?.value.blockhash,
72
- instructions: [ix],
73
- }).compileToLegacyMessage();
74
- const tx = new VersionedTransaction(msg);
75
- tx.sign([payer]);
76
-
77
- const sigResp = await call<string>("sendTransaction", [
78
- Buffer.from(tx.serialize()).toString("base64"),
79
- ]);
80
- expect(sigResp.error).toBeUndefined();
81
- const sig = sigResp.result;
82
-
83
- const txResp = await call<unknown>("getTransaction", [
84
- sig,
85
- { encoding: "json" },
86
- ]);
87
- expect(txResp.error).toBeUndefined();
88
- type TxResp = {
89
- transaction: { message: { instructions: unknown[] } };
90
- meta: { innerInstructions: unknown[]; logMessages?: string[] };
91
- };
92
- const tr = txResp.result as TxResp;
93
-
94
- // At least one top-level instruction
95
- expect(Array.isArray(tr.transaction.message.instructions)).toBe(true);
96
- expect(tr.transaction.message.instructions.length).toBe(1);
97
-
98
- // Check inner instructions captured or (worst case) logs exist
99
- const ii = tr.meta.innerInstructions;
100
- const logs = tr.meta.logMessages || [];
101
- expect(Array.isArray(ii)).toBe(true);
102
- // At minimum, either we have structured inner ixs, or logs were captured
103
- expect(ii.length > 0 || logs.length > 0).toBe(true);
104
- });
@@ -1,469 +0,0 @@
1
- import {
2
- ACCOUNT_SIZE,
3
- AccountLayout,
4
- MINT_SIZE,
5
- MintLayout,
6
- TOKEN_2022_PROGRAM_ID,
7
- TOKEN_PROGRAM_ID,
8
- } from "@solana/spl-token";
9
- import { PublicKey, VersionedTransaction } from "@solana/web3.js";
10
- import type { RpcMethodHandler } from "../../types";
11
-
12
- export const sendTransaction: RpcMethodHandler = (id, params, context) => {
13
- const [encodedTx] = params;
14
- try {
15
- const txData = Buffer.from(encodedTx, "base64");
16
- const tx = VersionedTransaction.deserialize(txData);
17
-
18
- // Snapshot pre balances
19
- const msg = tx.message as unknown as {
20
- staticAccountKeys?: unknown[];
21
- accountKeys?: unknown[];
22
- };
23
- const rawKeys: unknown[] = Array.isArray(msg.staticAccountKeys)
24
- ? msg.staticAccountKeys
25
- : Array.isArray(msg.accountKeys)
26
- ? msg.accountKeys
27
- : [];
28
- const staticKeys = rawKeys
29
- .map((k) => {
30
- try {
31
- return typeof k === "string" ? new PublicKey(k) : (k as PublicKey);
32
- } catch {
33
- return undefined;
34
- }
35
- })
36
- .filter(Boolean) as PublicKey[];
37
- // Pre snapshots and balances
38
- const preBalances = staticKeys.map((pk) => {
39
- try {
40
- return Number(context.svm.getBalance(pk));
41
- } catch {
42
- return 0;
43
- }
44
- });
45
- const preAccountStates = staticKeys.map((pk) => {
46
- try {
47
- const addr = pk.toBase58();
48
- const acc = context.svm.getAccount(pk);
49
- if (!acc) return { address: addr, pre: null } as const;
50
- return {
51
- address: addr,
52
- pre: {
53
- lamports: Number(acc.lamports || 0n),
54
- ownerProgram: new PublicKey(acc.owner).toBase58(),
55
- executable: !!acc.executable,
56
- rentEpoch: Number(acc.rentEpoch || 0),
57
- dataLen: acc.data?.length ?? 0,
58
- dataBase64: undefined,
59
- lastSlot: Number(context.slot),
60
- },
61
- } as const;
62
- } catch {
63
- return { address: pk.toBase58(), pre: null } as const;
64
- }
65
- });
66
- try {
67
- if (process.env.DEBUG_TX_CAPTURE === "1") {
68
- console.debug(
69
- `[tx-capture] pre snapshots: keys=${staticKeys.length} captured=${preAccountStates.length}`,
70
- );
71
- }
72
- } catch {}
73
-
74
- // Collect SPL token accounts from instructions for pre/post token balance snapshots
75
- const msgAny = msg as unknown as {
76
- compiledInstructions?: unknown[];
77
- instructions?: unknown[];
78
- };
79
- const compiled: unknown[] = Array.isArray(msgAny.compiledInstructions)
80
- ? msgAny.compiledInstructions
81
- : Array.isArray(msgAny.instructions)
82
- ? msgAny.instructions
83
- : [];
84
- const tokenProgramIds = new Set([
85
- TOKEN_PROGRAM_ID.toBase58(),
86
- TOKEN_2022_PROGRAM_ID.toBase58(),
87
- ]);
88
- const tokenAccountSet = new Set<string>();
89
- // 1) Collect from compiled ixs (best-effort)
90
- for (const ci of compiled) {
91
- try {
92
- const rec = ci as Record<string, unknown>;
93
- const pidIdx =
94
- typeof rec.programIdIndex === "number"
95
- ? rec.programIdIndex
96
- : undefined;
97
- const pid = pidIdx != null ? staticKeys[pidIdx]?.toBase58() : undefined;
98
- if (!pid || !tokenProgramIds.has(pid)) continue;
99
- const accSrc = Array.isArray(rec.accountKeyIndexes)
100
- ? (rec.accountKeyIndexes as unknown[])
101
- : Array.isArray(rec.accounts)
102
- ? (rec.accounts as unknown[])
103
- : [];
104
- const accIdxs: number[] = accSrc.filter(
105
- (v): v is number => typeof v === "number",
106
- );
107
- for (const ix of accIdxs) {
108
- const addr = staticKeys[ix]?.toBase58();
109
- if (addr) tokenAccountSet.add(addr);
110
- }
111
- } catch {}
112
- }
113
- // 2) Also collect from all static keys that are SPL token accounts pre-send
114
- for (const pk of staticKeys) {
115
- try {
116
- const acc = context.svm.getAccount(pk);
117
- if (!acc) continue;
118
- const ownerStr = new PublicKey(acc.owner).toBase58();
119
- if (
120
- tokenProgramIds.has(ownerStr) &&
121
- (acc.data?.length ?? 0) >= ACCOUNT_SIZE
122
- ) {
123
- tokenAccountSet.add(pk.toBase58());
124
- }
125
- } catch {}
126
- }
127
- // Pre token balances
128
- const preTokenBalances: unknown[] = [];
129
- const ataToInfo = new Map<
130
- string,
131
- {
132
- mint?: string;
133
- owner?: string;
134
- amount: bigint;
135
- accountIndex: number;
136
- decimals?: number;
137
- }
138
- >();
139
- const missingPre = new Set<string>();
140
- for (const addr of tokenAccountSet) {
141
- try {
142
- const pk = new PublicKey(addr);
143
- const idx = staticKeys.findIndex((k) => k.equals(pk));
144
- const acc = context.svm.getAccount(pk);
145
- if (!acc || (acc.data?.length ?? 0) < ACCOUNT_SIZE) {
146
- // Track placeholder; we'll fill mint/owner/decimals after send
147
- ataToInfo.set(addr, { amount: 0n, accountIndex: idx >= 0 ? idx : 0 });
148
- missingPre.add(addr);
149
- continue;
150
- }
151
- const decAcc = AccountLayout.decode(Buffer.from(acc.data));
152
- const mintPk = new PublicKey(decAcc.mint);
153
- const mintAcc = context.svm.getAccount(mintPk);
154
- let decimals = 0;
155
- if (mintAcc && (mintAcc.data?.length ?? 0) >= MINT_SIZE) {
156
- const m = MintLayout.decode(
157
- Buffer.from(mintAcc.data).slice(0, MINT_SIZE),
158
- );
159
- decimals = Number(m.decimals ?? 0);
160
- }
161
- const ownerPk = new PublicKey(decAcc.owner);
162
- const amt = BigInt(decAcc.amount.toString());
163
- ataToInfo.set(addr, {
164
- mint: mintPk.toBase58(),
165
- owner: ownerPk.toBase58(),
166
- amount: amt,
167
- accountIndex: idx >= 0 ? idx : 0,
168
- decimals,
169
- });
170
- const uiAmount = Number(amt) / 10 ** decimals;
171
- preTokenBalances.push({
172
- accountIndex: idx >= 0 ? idx : 0,
173
- mint: mintPk.toBase58(),
174
- owner: ownerPk.toBase58(),
175
- uiTokenAmount: {
176
- amount: amt.toString(),
177
- decimals,
178
- uiAmount,
179
- uiAmountString: String(uiAmount),
180
- },
181
- });
182
- } catch {}
183
- }
184
-
185
- const result = context.svm.sendTransaction(tx);
186
-
187
- try {
188
- const rawErr = (result as { err?: unknown }).err;
189
- const maybeErr =
190
- typeof rawErr === "function" ? (rawErr as () => unknown)() : rawErr;
191
- if (maybeErr) {
192
- return context.createErrorResponse(
193
- id,
194
- -32003,
195
- "Transaction failed",
196
- maybeErr,
197
- );
198
- }
199
- } catch {}
200
-
201
- const signature = tx.signatures[0]
202
- ? context.encodeBase58(tx.signatures[0])
203
- : context.encodeBase58(new Uint8Array(64).fill(0));
204
- context.notifySignature(signature);
205
- // Snapshot post balances and capture logs for rich view
206
- const postBalances = staticKeys.map((pk) => {
207
- try {
208
- return Number(context.svm.getBalance(pk));
209
- } catch {
210
- return 0;
211
- }
212
- });
213
- const postAccountStates = staticKeys.map((pk) => {
214
- try {
215
- const addr = pk.toBase58();
216
- const acc = context.svm.getAccount(pk);
217
- if (!acc) return { address: addr, post: null } as const;
218
- return {
219
- address: addr,
220
- post: {
221
- lamports: Number(acc.lamports || 0n),
222
- ownerProgram: new PublicKey(acc.owner).toBase58(),
223
- executable: !!acc.executable,
224
- rentEpoch: Number(acc.rentEpoch || 0),
225
- dataLen: acc.data?.length ?? 0,
226
- dataBase64: undefined,
227
- lastSlot: Number(context.slot),
228
- },
229
- } as const;
230
- } catch {
231
- return { address: pk.toBase58(), post: null } as const;
232
- }
233
- });
234
- try {
235
- if (process.env.DEBUG_TX_CAPTURE === "1") {
236
- console.debug(
237
- `[tx-capture] post snapshots: keys=${staticKeys.length} captured=${postAccountStates.length}`,
238
- );
239
- }
240
- } catch {}
241
- // Post token balances (scan token accounts among static keys)
242
- const postTokenBalances: unknown[] = [];
243
- for (const addr of tokenAccountSet) {
244
- try {
245
- const pk = new PublicKey(addr);
246
- const idx = staticKeys.findIndex((k) => k.equals(pk));
247
- const acc = context.svm.getAccount(pk);
248
- if (!acc || (acc.data?.length ?? 0) < ACCOUNT_SIZE) continue;
249
- const decAcc = AccountLayout.decode(Buffer.from(acc.data));
250
- const mintPk = new PublicKey(decAcc.mint);
251
- const ownerPk = new PublicKey(decAcc.owner);
252
- const mintAcc = context.svm.getAccount(mintPk);
253
- let decimals = 0;
254
- if (mintAcc && (mintAcc.data?.length ?? 0) >= MINT_SIZE) {
255
- const m = MintLayout.decode(
256
- Buffer.from(mintAcc.data).slice(0, MINT_SIZE),
257
- );
258
- decimals = Number(m.decimals ?? 0);
259
- }
260
- const amt = BigInt(decAcc.amount.toString());
261
- const uiAmount = Number(amt) / 10 ** decimals;
262
- postTokenBalances.push({
263
- accountIndex:
264
- idx >= 0 ? idx : (ataToInfo.get(addr)?.accountIndex ?? 0),
265
- mint: mintPk.toBase58(),
266
- owner: ownerPk.toBase58(),
267
- uiTokenAmount: {
268
- amount: amt.toString(),
269
- decimals,
270
- uiAmount,
271
- uiAmountString: String(uiAmount),
272
- },
273
- });
274
- // Add missing pre entry as zero if account was unfunded before
275
- if (missingPre.has(addr)) {
276
- const preUi = 0;
277
- preTokenBalances.push({
278
- accountIndex:
279
- idx >= 0 ? idx : (ataToInfo.get(addr)?.accountIndex ?? 0),
280
- mint: mintPk.toBase58(),
281
- owner: ownerPk.toBase58(),
282
- uiTokenAmount: {
283
- amount: "0",
284
- decimals,
285
- uiAmount: preUi,
286
- uiAmountString: String(preUi),
287
- },
288
- });
289
- }
290
- } catch {}
291
- }
292
- let logs: string[] = [];
293
- let innerInstructions: unknown[] = [];
294
- let computeUnits: number | null = null;
295
- let returnData: { programId: string; dataBase64: string } | null = null;
296
- try {
297
- const DBG = process.env.DEBUG_TX_CAPTURE === "1";
298
- // biome-ignore lint/suspicious/noExplicitAny: Result shape depends on litesvm version; guarded access
299
- const r: any = result as any;
300
- // Logs can be on TransactionMetadata or in meta() for failures
301
- try {
302
- if (typeof r?.logs === "function") logs = r.logs();
303
- } catch {}
304
- let metaObj: unknown | undefined;
305
- // Success shape: methods on result
306
- if (
307
- typeof r?.innerInstructions === "function" ||
308
- typeof r?.computeUnitsConsumed === "function" ||
309
- typeof r?.returnData === "function"
310
- ) {
311
- metaObj = r;
312
- }
313
- // Failed shape: meta() returns TransactionMetadata
314
- if (!metaObj && typeof r?.meta === "function") {
315
- try {
316
- metaObj = r.meta();
317
- if (!logs.length && typeof metaObj?.logs === "function") {
318
- logs = metaObj.logs();
319
- }
320
- } catch (e) {
321
- if (DBG)
322
- console.debug("[tx-capture] meta() threw while extracting:", e);
323
- }
324
- }
325
- // Extract richer metadata from whichever object exposes it
326
- if (metaObj) {
327
- try {
328
- const inner = (
329
- metaObj as { innerInstructions?: () => unknown } | undefined
330
- )?.innerInstructions?.();
331
- if (Array.isArray(inner)) {
332
- innerInstructions = inner.map((group, index: number) => {
333
- const instructions = Array.isArray(group)
334
- ? (group as unknown[])
335
- .map((ii) => {
336
- try {
337
- const inst = (
338
- ii as { instruction?: () => unknown }
339
- ).instruction?.();
340
- const accSrc = (
341
- inst as { accounts?: () => unknown } | undefined
342
- )?.accounts?.();
343
- const accIdxs: number[] = Array.isArray(accSrc)
344
- ? (accSrc as unknown[]).filter(
345
- (v): v is number => typeof v === "number",
346
- )
347
- : [];
348
- const dataVal = (
349
- inst as { data?: () => unknown } | undefined
350
- )?.data?.();
351
- const dataBytes: Uint8Array =
352
- dataVal instanceof Uint8Array
353
- ? dataVal
354
- : new Uint8Array();
355
- return {
356
- programIdIndex: Number(
357
- (
358
- inst as
359
- | { programIdIndex?: () => unknown }
360
- | undefined
361
- )?.programIdIndex?.() ?? 0,
362
- ),
363
- accounts: accIdxs,
364
- data: context.encodeBase58(dataBytes),
365
- stackHeight: Number(
366
- (
367
- ii as { stackHeight?: () => unknown }
368
- ).stackHeight?.() ?? 0,
369
- ),
370
- };
371
- } catch {
372
- return null;
373
- }
374
- })
375
- .filter(Boolean)
376
- : [];
377
- return { index, instructions };
378
- });
379
- }
380
- } catch (e) {
381
- if (DBG)
382
- console.debug(
383
- "[tx-capture] innerInstructions extraction failed:",
384
- e,
385
- );
386
- }
387
- try {
388
- const cu = (
389
- metaObj as { computeUnitsConsumed?: () => unknown } | undefined
390
- )?.computeUnitsConsumed?.();
391
- if (typeof cu === "bigint") computeUnits = Number(cu);
392
- } catch (e) {
393
- if (DBG)
394
- console.debug(
395
- "[tx-capture] computeUnitsConsumed extraction failed:",
396
- e,
397
- );
398
- }
399
- try {
400
- const rd = (
401
- metaObj as { returnData?: () => unknown } | undefined
402
- )?.returnData?.();
403
- if (rd) {
404
- const pid = new PublicKey(rd.programId()).toBase58();
405
- const dataB64 = Buffer.from(rd.data()).toString("base64");
406
- returnData = { programId: pid, dataBase64: dataB64 };
407
- }
408
- } catch (e) {
409
- if (DBG)
410
- console.debug("[tx-capture] returnData extraction failed:", e);
411
- }
412
- } else if (DBG) {
413
- console.debug("[tx-capture] no metadata object found on result shape");
414
- }
415
- } catch {}
416
- try {
417
- if (process.env.DEBUG_TX_CAPTURE === "1") {
418
- console.debug(
419
- `[tx-capture] sendTransaction meta: logs=${logs.length} innerGroups=${Array.isArray(innerInstructions) ? innerInstructions.length : 0} computeUnits=${computeUnits} returnData=${returnData ? "yes" : "no"}`,
420
- );
421
- }
422
- } catch {}
423
- context.recordTransaction(signature, tx, {
424
- logs,
425
- fee: 5000,
426
- blockTime: Math.floor(Date.now() / 1000),
427
- preBalances,
428
- postBalances,
429
- preTokenBalances,
430
- postTokenBalances,
431
- innerInstructions,
432
- computeUnits,
433
- returnData,
434
- accountStates: (() => {
435
- try {
436
- const byAddr = new Map<string, { pre?: unknown; post?: unknown }>();
437
- for (const s of preAccountStates)
438
- byAddr.set(s.address, { pre: s.pre || null });
439
- for (const s of postAccountStates) {
440
- const e = byAddr.get(s.address) || {};
441
- e.post = s.post || null;
442
- byAddr.set(s.address, e);
443
- }
444
- return Array.from(byAddr.entries()).map(([address, v]) => ({
445
- address,
446
- pre: v.pre || null,
447
- post: v.post || null,
448
- }));
449
- } catch {
450
- return [] as Array<{
451
- address: string;
452
- pre?: unknown;
453
- post?: unknown;
454
- }>;
455
- }
456
- })(),
457
- });
458
-
459
- return context.createSuccessResponse(id, signature);
460
- } catch (error: unknown) {
461
- const message = error instanceof Error ? error.message : String(error);
462
- return context.createErrorResponse(
463
- id,
464
- -32003,
465
- "Transaction failed",
466
- message,
467
- );
468
- }
469
- };
@@ -1,57 +0,0 @@
1
- import { VersionedTransaction } from "@solana/web3.js";
2
- import type { RpcMethodHandler } from "../../types";
3
-
4
- export const simulateTransaction: RpcMethodHandler = (id, params, context) => {
5
- const [encodedTx] = params;
6
- try {
7
- const txData = Buffer.from(encodedTx, "base64");
8
- const tx = VersionedTransaction.deserialize(txData);
9
- const result = context.svm.simulateTransaction(tx);
10
-
11
- if ("err" in result) {
12
- const errorMeta = result.meta();
13
- // To maximize client compatibility, report err as null and return logs
14
- // (Some clients fail to deserialize unknown enum variants or numeric codes.)
15
- return context.createSuccessResponse(id, {
16
- context: { slot: Number(context.slot) },
17
- value: {
18
- err: null,
19
- logs: errorMeta.logs(),
20
- accounts: null,
21
- unitsConsumed: Number(errorMeta.computeUnitsConsumed()),
22
- returnData: null,
23
- },
24
- });
25
- }
26
-
27
- const meta = result.meta();
28
- const returnData = meta.returnData();
29
-
30
- return context.createSuccessResponse(id, {
31
- context: { slot: Number(context.slot) },
32
- value: {
33
- err: null,
34
- logs: meta.logs(),
35
- accounts: null,
36
- unitsConsumed: Number(meta.computeUnitsConsumed()),
37
- returnData: returnData
38
- ? {
39
- programId: context.encodeBase58(returnData.programId()),
40
- data: [
41
- Buffer.from(returnData.data()).toString("base64"),
42
- "base64",
43
- ],
44
- }
45
- : null,
46
- },
47
- });
48
- } catch (error: unknown) {
49
- const message = error instanceof Error ? error.message : String(error);
50
- return context.createErrorResponse(
51
- id,
52
- -32003,
53
- "Simulation failed",
54
- message,
55
- );
56
- }
57
- };