solforge 0.2.4 → 0.2.6

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 (82) hide show
  1. package/README.md +471 -79
  2. package/cli.cjs +106 -78
  3. package/package.json +1 -1
  4. package/scripts/install.sh +1 -1
  5. package/scripts/postinstall.cjs +69 -61
  6. package/server/lib/base58.ts +1 -1
  7. package/server/methods/account/get-account-info.ts +3 -7
  8. package/server/methods/account/get-balance.ts +3 -7
  9. package/server/methods/account/get-multiple-accounts.ts +2 -1
  10. package/server/methods/account/get-parsed-account-info.ts +3 -7
  11. package/server/methods/account/parsers/index.ts +2 -2
  12. package/server/methods/account/parsers/loader-upgradeable.ts +14 -1
  13. package/server/methods/account/parsers/spl-token.ts +29 -10
  14. package/server/methods/account/request-airdrop.ts +44 -31
  15. package/server/methods/block/get-block.ts +3 -7
  16. package/server/methods/block/get-blocks-with-limit.ts +3 -7
  17. package/server/methods/block/is-blockhash-valid.ts +3 -7
  18. package/server/methods/get-address-lookup-table.ts +3 -7
  19. package/server/methods/program/get-program-accounts.ts +9 -9
  20. package/server/methods/program/get-token-account-balance.ts +3 -7
  21. package/server/methods/program/get-token-accounts-by-delegate.ts +4 -3
  22. package/server/methods/program/get-token-accounts-by-owner.ts +61 -35
  23. package/server/methods/program/get-token-largest-accounts.ts +3 -2
  24. package/server/methods/program/get-token-supply.ts +3 -2
  25. package/server/methods/solforge/index.ts +9 -6
  26. package/server/methods/transaction/get-parsed-transaction.ts +3 -7
  27. package/server/methods/transaction/get-signature-statuses.ts +14 -7
  28. package/server/methods/transaction/get-signatures-for-address.ts +3 -7
  29. package/server/methods/transaction/get-transaction.ts +167 -81
  30. package/server/methods/transaction/send-transaction.ts +29 -16
  31. package/server/methods/transaction/simulate-transaction.ts +3 -2
  32. package/server/rpc-server.ts +47 -34
  33. package/server/types.ts +9 -6
  34. package/server/ws-server.ts +15 -8
  35. package/src/api-server-entry.ts +91 -91
  36. package/src/cli/commands/airdrop.ts +2 -2
  37. package/src/cli/commands/config.ts +2 -2
  38. package/src/cli/commands/mint.ts +3 -3
  39. package/src/cli/commands/program-clone.ts +9 -11
  40. package/src/cli/commands/program-load.ts +3 -3
  41. package/src/cli/commands/rpc-start.ts +8 -5
  42. package/src/cli/commands/token-adopt-authority.ts +1 -1
  43. package/src/cli/commands/token-clone.ts +5 -6
  44. package/src/cli/commands/token-create.ts +5 -5
  45. package/src/cli/main.ts +38 -37
  46. package/src/cli/run-solforge.ts +20 -6
  47. package/src/cli/setup-wizard.ts +8 -6
  48. package/src/commands/add-program.ts +324 -328
  49. package/src/commands/init.ts +106 -106
  50. package/src/commands/list.ts +125 -125
  51. package/src/commands/mint.ts +247 -248
  52. package/src/commands/start.ts +837 -833
  53. package/src/commands/status.ts +80 -80
  54. package/src/commands/stop.ts +381 -382
  55. package/src/config/index.ts +33 -17
  56. package/src/config/manager.ts +150 -150
  57. package/src/db/index.ts +2 -2
  58. package/src/db/tx-store.ts +12 -8
  59. package/src/gui/public/app.css +1556 -1
  60. package/src/gui/public/build/main.css +1569 -1
  61. package/src/gui/server.ts +21 -22
  62. package/src/gui/src/api.ts +1 -1
  63. package/src/gui/src/app.tsx +96 -45
  64. package/src/gui/src/components/airdrop-mint-form.tsx +49 -19
  65. package/src/gui/src/components/clone-program-modal.tsx +31 -12
  66. package/src/gui/src/components/clone-token-modal.tsx +32 -13
  67. package/src/gui/src/components/modal.tsx +18 -11
  68. package/src/gui/src/components/programs-panel.tsx +27 -15
  69. package/src/gui/src/components/status-panel.tsx +32 -18
  70. package/src/gui/src/components/tokens-panel.tsx +25 -19
  71. package/src/gui/src/index.css +491 -463
  72. package/src/index.ts +177 -149
  73. package/src/rpc/start.ts +1 -1
  74. package/src/services/api-server.ts +494 -475
  75. package/src/services/port-manager.ts +164 -167
  76. package/src/services/process-registry.ts +144 -145
  77. package/src/services/program-cloner.ts +312 -312
  78. package/src/services/token-cloner.ts +799 -797
  79. package/src/services/validator.ts +288 -290
  80. package/src/types/config.ts +72 -72
  81. package/src/utils/shell.ts +75 -75
  82. package/src/utils/token-loader.ts +78 -78
@@ -1,337 +1,333 @@
1
1
  import chalk from "chalk";
2
+ import { existsSync } from "node:fs";
2
3
  import inquirer from "inquirer";
3
- import { existsSync } from "fs";
4
4
  import { configManager } from "../config/manager.js";
5
- import { ProgramCloner } from "../services/program-cloner.js";
6
5
  import { processRegistry } from "../services/process-registry.js";
6
+ import { ProgramCloner } from "../services/program-cloner.js";
7
7
  import type { ProgramConfig } from "../types/config.js";
8
8
 
9
9
  export async function addProgramCommand(
10
- options: {
11
- name?: string;
12
- programId?: string;
13
- interactive?: boolean;
14
- } = {}
10
+ options: { name?: string; programId?: string; interactive?: boolean } = {},
15
11
  ): Promise<void> {
16
- console.log(chalk.blue("📦 Adding program to configuration...\n"));
17
-
18
- // Check if config exists
19
- if (!existsSync("./sf.config.json")) {
20
- console.error(chalk.red("❌ No sf.config.json found in current directory"));
21
- console.log(chalk.yellow("💡 Run `solforge init` to create one"));
22
- return;
23
- }
24
-
25
- // Load current config
26
- try {
27
- await configManager.load("./sf.config.json");
28
- } catch (error) {
29
- console.error(chalk.red("❌ Failed to load sf.config.json"));
30
- console.error(
31
- chalk.red(error instanceof Error ? error.message : String(error))
32
- );
33
- return;
34
- }
35
-
36
- const config = configManager.getConfig();
37
-
38
- // Get program details
39
- let programId: string;
40
- let programName: string | undefined;
41
- let upgradeable: boolean = false;
42
-
43
- if (options.interactive !== false && !options.programId) {
44
- // Interactive mode - show common programs + custom option
45
- const { programChoice } = await inquirer.prompt([
46
- {
47
- type: "list",
48
- name: "programChoice",
49
- message: "Select a program to add:",
50
- choices: [
51
- {
52
- name: "Token Metadata Program",
53
- value: {
54
- id: "metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s",
55
- name: "Token Metadata",
56
- upgradeable: true,
57
- },
58
- },
59
- {
60
- name: "Associated Token Account Program",
61
- value: {
62
- id: "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL",
63
- name: "Associated Token Account",
64
- upgradeable: false,
65
- },
66
- },
67
- {
68
- name: "System Program",
69
- value: {
70
- id: "11111111111111111111111111111112",
71
- name: "System Program",
72
- upgradeable: false,
73
- },
74
- },
75
- {
76
- name: "Token Program",
77
- value: {
78
- id: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
79
- name: "Token Program",
80
- upgradeable: false,
81
- },
82
- },
83
- {
84
- name: "Token Program 2022",
85
- value: {
86
- id: "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb",
87
- name: "Token Program 2022",
88
- upgradeable: true,
89
- },
90
- },
91
- {
92
- name: "Rent Sysvar",
93
- value: {
94
- id: "SysvarRent111111111111111111111111111111111",
95
- name: "Rent Sysvar",
96
- upgradeable: false,
97
- },
98
- },
99
- {
100
- name: "Clock Sysvar",
101
- value: {
102
- id: "SysvarC1ock11111111111111111111111111111111",
103
- name: "Clock Sysvar",
104
- upgradeable: false,
105
- },
106
- },
107
- {
108
- name: "Jupiter V6 Program",
109
- value: {
110
- id: "JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4",
111
- name: "Jupiter V6",
112
- upgradeable: true,
113
- },
114
- },
115
- {
116
- name: "Raydium AMM Program",
117
- value: {
118
- id: "675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8",
119
- name: "Raydium AMM",
120
- upgradeable: false,
121
- },
122
- },
123
- {
124
- name: "Serum DEX Program",
125
- value: {
126
- id: "9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin",
127
- name: "Serum DEX",
128
- upgradeable: false,
129
- },
130
- },
131
- {
132
- name: "Custom (enter program ID manually)",
133
- value: "custom",
134
- },
135
- ],
136
- },
137
- ]);
138
-
139
- if (programChoice === "custom") {
140
- const answers = await inquirer.prompt([
141
- {
142
- type: "input",
143
- name: "programId",
144
- message: "Enter program ID:",
145
- validate: (input) =>
146
- input.trim().length > 0 || "Program ID is required",
147
- },
148
- {
149
- type: "input",
150
- name: "name",
151
- message: "Enter program name (optional):",
152
- default: "",
153
- },
154
- {
155
- type: "confirm",
156
- name: "upgradeable",
157
- message: "Is this an upgradeable program?",
158
- default: false,
159
- },
160
- ]);
161
-
162
- programId = answers.programId;
163
- programName = answers.name || undefined;
164
- upgradeable = answers.upgradeable;
165
- } else {
166
- programId = programChoice.id;
167
- programName = programChoice.name;
168
- upgradeable = programChoice.upgradeable;
169
- }
170
- } else {
171
- // Non-interactive mode
172
- if (!options.programId) {
173
- console.error(chalk.red("❌ Program ID is required"));
174
- console.log(
175
- chalk.gray(
176
- "💡 Use --program-id flag, or run without flags for interactive mode"
177
- )
178
- );
179
- return;
180
- }
181
-
182
- programId = options.programId;
183
- programName = options.name;
184
- // Default to false for CLI, could add --upgradeable flag later
185
- upgradeable = false;
186
- }
187
-
188
- try {
189
- // Check if program already exists in config
190
- const existingProgram = config.programs.find(
191
- (p) => p.mainnetProgramId === programId
192
- );
193
- if (existingProgram) {
194
- console.log(
195
- chalk.yellow(`⚠️ Program ${programId} already exists in configuration`)
196
- );
197
- console.log(chalk.gray(` Name: ${existingProgram.name || "unnamed"}`));
198
- return;
199
- }
200
-
201
- // Verify program exists on mainnet first
202
- console.log(chalk.gray("🔍 Verifying program exists on mainnet..."));
203
- const programCloner = new ProgramCloner();
204
- const programInfo = await programCloner.getProgramInfo(
205
- programId,
206
- "mainnet-beta"
207
- );
208
-
209
- if (!programInfo.exists) {
210
- console.error(chalk.red(`❌ Program ${programId} not found on mainnet`));
211
- return;
212
- }
213
-
214
- if (!programInfo.executable) {
215
- console.error(chalk.red(`❌ ${programId} is not an executable program`));
216
- return;
217
- }
218
-
219
- console.log(
220
- chalk.gray(` ✓ Found executable program (${programInfo.size} bytes)`)
221
- );
222
-
223
- // Create new program config
224
- const newProgram: ProgramConfig = {
225
- name: programName,
226
- mainnetProgramId: programId,
227
- upgradeable: upgradeable,
228
- cluster: "mainnet-beta",
229
- dependencies: [],
230
- };
231
-
232
- // Add to config
233
- config.programs.push(newProgram);
234
-
235
- // Save updated config
236
- await configManager.save("./sf.config.json");
237
-
238
- console.log(
239
- chalk.green(
240
- `\n✅ Successfully added ${programName || programId} to configuration!`
241
- )
242
- );
243
- console.log(chalk.cyan(`📝 Updated sf.config.json`));
244
- console.log(chalk.gray(` Program ID: ${programId}`));
245
- console.log(chalk.gray(` Upgradeable: ${upgradeable ? "Yes" : "No"}`));
246
-
247
- // Check if there are running validators
248
- await processRegistry.cleanup();
249
- const validators = processRegistry.getRunning();
250
-
251
- if (validators.length > 0) {
252
- console.log(
253
- chalk.yellow(`\n⚠️ Found ${validators.length} running validator(s)`)
254
- );
255
- console.log(
256
- chalk.gray("💡 Programs are added to genesis config and require RESET")
257
- );
258
- console.log(chalk.red(" ⚠️ RESET will WIPE all ledger data!"));
259
- console.log(
260
- chalk.gray(
261
- ` 1. Stop validators using "${config.name}": solforge stop <validator-id>`
262
- )
263
- );
264
- console.log(chalk.gray(" 2. Start with reset: solforge start"));
265
-
266
- const { shouldRestart } = await inquirer.prompt([
267
- {
268
- type: "confirm",
269
- name: "shouldRestart",
270
- message: "⚠️ Reset validators now? (This will WIPE all ledger data)",
271
- default: false,
272
- },
273
- ]);
274
-
275
- if (shouldRestart) {
276
- console.log(chalk.yellow("\n🔄 Resetting validators..."));
277
- console.log(chalk.red("⚠️ This will delete all ledger data!"));
278
-
279
- // Import the commands we need
280
- const { stopCommand } = await import("./stop.js");
281
- const { startCommand } = await import("./start.js");
282
-
283
- // Get current config for modifications
284
- const currentConfig = configManager.getConfig();
285
-
286
- // Stop validators that use this config
287
- const configName = currentConfig.name;
288
- const matchingValidators = validators.filter((v) =>
289
- v.name.startsWith(configName)
290
- );
291
-
292
- if (matchingValidators.length > 0) {
293
- console.log(
294
- chalk.gray(
295
- `🛑 Stopping ${matchingValidators.length} validator(s) using config "${configName}"...`
296
- )
297
- );
298
-
299
- for (const validator of matchingValidators) {
300
- await stopCommand(validator.id, {});
301
- }
302
- }
303
-
304
- // Wait a moment for clean shutdown
305
- await new Promise((resolve) => setTimeout(resolve, 2000));
306
-
307
- // Temporarily enable reset for this start
308
- const originalReset = currentConfig.localnet.reset;
309
- currentConfig.localnet.reset = true;
310
-
311
- console.log(
312
- chalk.cyan(
313
- "🚀 Starting validator with reset to apply program changes..."
314
- )
315
- );
316
-
317
- // Start new validator (will reset due to config)
318
- await startCommand(false);
319
-
320
- // Restore original reset setting
321
- currentConfig.localnet.reset = originalReset;
322
- await configManager.save("./sf.config.json");
323
- }
324
- } else {
325
- console.log(
326
- chalk.gray(
327
- "\n💡 Start a validator to use the new program: solforge start"
328
- )
329
- );
330
- }
331
- } catch (error) {
332
- console.error(chalk.red("❌ Failed to add program:"));
333
- console.error(
334
- chalk.red(` ${error instanceof Error ? error.message : String(error)}`)
335
- );
336
- }
12
+ console.log(chalk.blue("📦 Adding program to configuration...\n"));
13
+
14
+ // Check if config exists
15
+ if (!existsSync("./sf.config.json")) {
16
+ console.error(chalk.red("❌ No sf.config.json found in current directory"));
17
+ console.log(chalk.yellow("💡 Run `solforge init` to create one"));
18
+ return;
19
+ }
20
+
21
+ // Load current config
22
+ try {
23
+ await configManager.load("./sf.config.json");
24
+ } catch (error) {
25
+ console.error(chalk.red("❌ Failed to load sf.config.json"));
26
+ console.error(
27
+ chalk.red(error instanceof Error ? error.message : String(error)),
28
+ );
29
+ return;
30
+ }
31
+
32
+ const config = configManager.getConfig();
33
+
34
+ // Get program details
35
+ let programId: string;
36
+ let programName: string | undefined;
37
+ let upgradeable: boolean = false;
38
+
39
+ if (options.interactive !== false && !options.programId) {
40
+ // Interactive mode - show common programs + custom option
41
+ const { programChoice } = await inquirer.prompt([
42
+ {
43
+ type: "list",
44
+ name: "programChoice",
45
+ message: "Select a program to add:",
46
+ choices: [
47
+ {
48
+ name: "Token Metadata Program",
49
+ value: {
50
+ id: "metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s",
51
+ name: "Token Metadata",
52
+ upgradeable: true,
53
+ },
54
+ },
55
+ {
56
+ name: "Associated Token Account Program",
57
+ value: {
58
+ id: "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL",
59
+ name: "Associated Token Account",
60
+ upgradeable: false,
61
+ },
62
+ },
63
+ {
64
+ name: "System Program",
65
+ value: {
66
+ id: "11111111111111111111111111111112",
67
+ name: "System Program",
68
+ upgradeable: false,
69
+ },
70
+ },
71
+ {
72
+ name: "Token Program",
73
+ value: {
74
+ id: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
75
+ name: "Token Program",
76
+ upgradeable: false,
77
+ },
78
+ },
79
+ {
80
+ name: "Token Program 2022",
81
+ value: {
82
+ id: "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb",
83
+ name: "Token Program 2022",
84
+ upgradeable: true,
85
+ },
86
+ },
87
+ {
88
+ name: "Rent Sysvar",
89
+ value: {
90
+ id: "SysvarRent111111111111111111111111111111111",
91
+ name: "Rent Sysvar",
92
+ upgradeable: false,
93
+ },
94
+ },
95
+ {
96
+ name: "Clock Sysvar",
97
+ value: {
98
+ id: "SysvarC1ock11111111111111111111111111111111",
99
+ name: "Clock Sysvar",
100
+ upgradeable: false,
101
+ },
102
+ },
103
+ {
104
+ name: "Jupiter V6 Program",
105
+ value: {
106
+ id: "JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4",
107
+ name: "Jupiter V6",
108
+ upgradeable: true,
109
+ },
110
+ },
111
+ {
112
+ name: "Raydium AMM Program",
113
+ value: {
114
+ id: "675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8",
115
+ name: "Raydium AMM",
116
+ upgradeable: false,
117
+ },
118
+ },
119
+ {
120
+ name: "Serum DEX Program",
121
+ value: {
122
+ id: "9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin",
123
+ name: "Serum DEX",
124
+ upgradeable: false,
125
+ },
126
+ },
127
+ {
128
+ name: "Custom (enter program ID manually)",
129
+ value: "custom",
130
+ },
131
+ ],
132
+ },
133
+ ]);
134
+
135
+ if (programChoice === "custom") {
136
+ const answers = await inquirer.prompt([
137
+ {
138
+ type: "input",
139
+ name: "programId",
140
+ message: "Enter program ID:",
141
+ validate: (input) =>
142
+ input.trim().length > 0 || "Program ID is required",
143
+ },
144
+ {
145
+ type: "input",
146
+ name: "name",
147
+ message: "Enter program name (optional):",
148
+ default: "",
149
+ },
150
+ {
151
+ type: "confirm",
152
+ name: "upgradeable",
153
+ message: "Is this an upgradeable program?",
154
+ default: false,
155
+ },
156
+ ]);
157
+
158
+ programId = answers.programId;
159
+ programName = answers.name || undefined;
160
+ upgradeable = answers.upgradeable;
161
+ } else {
162
+ programId = programChoice.id;
163
+ programName = programChoice.name;
164
+ upgradeable = programChoice.upgradeable;
165
+ }
166
+ } else {
167
+ // Non-interactive mode
168
+ if (!options.programId) {
169
+ console.error(chalk.red("❌ Program ID is required"));
170
+ console.log(
171
+ chalk.gray(
172
+ "💡 Use --program-id flag, or run without flags for interactive mode",
173
+ ),
174
+ );
175
+ return;
176
+ }
177
+
178
+ programId = options.programId;
179
+ programName = options.name;
180
+ // Default to false for CLI, could add --upgradeable flag later
181
+ upgradeable = false;
182
+ }
183
+
184
+ try {
185
+ // Check if program already exists in config
186
+ const existingProgram = config.programs.find(
187
+ (p) => p.mainnetProgramId === programId,
188
+ );
189
+ if (existingProgram) {
190
+ console.log(
191
+ chalk.yellow(`⚠️ Program ${programId} already exists in configuration`),
192
+ );
193
+ console.log(chalk.gray(` Name: ${existingProgram.name || "unnamed"}`));
194
+ return;
195
+ }
196
+
197
+ // Verify program exists on mainnet first
198
+ console.log(chalk.gray("🔍 Verifying program exists on mainnet..."));
199
+ const programCloner = new ProgramCloner();
200
+ const programInfo = await programCloner.getProgramInfo(
201
+ programId,
202
+ "mainnet-beta",
203
+ );
204
+
205
+ if (!programInfo.exists) {
206
+ console.error(chalk.red(`❌ Program ${programId} not found on mainnet`));
207
+ return;
208
+ }
209
+
210
+ if (!programInfo.executable) {
211
+ console.error(chalk.red(`❌ ${programId} is not an executable program`));
212
+ return;
213
+ }
214
+
215
+ console.log(
216
+ chalk.gray(` ✓ Found executable program (${programInfo.size} bytes)`),
217
+ );
218
+
219
+ // Create new program config
220
+ const newProgram: ProgramConfig = {
221
+ name: programName,
222
+ mainnetProgramId: programId,
223
+ upgradeable: upgradeable,
224
+ cluster: "mainnet-beta",
225
+ dependencies: [],
226
+ };
227
+
228
+ // Add to config
229
+ config.programs.push(newProgram);
230
+
231
+ // Save updated config
232
+ await configManager.save("./sf.config.json");
233
+
234
+ console.log(
235
+ chalk.green(
236
+ `\n✅ Successfully added ${programName || programId} to configuration!`,
237
+ ),
238
+ );
239
+ console.log(chalk.cyan(`📝 Updated sf.config.json`));
240
+ console.log(chalk.gray(` Program ID: ${programId}`));
241
+ console.log(chalk.gray(` Upgradeable: ${upgradeable ? "Yes" : "No"}`));
242
+
243
+ // Check if there are running validators
244
+ await processRegistry.cleanup();
245
+ const validators = processRegistry.getRunning();
246
+
247
+ if (validators.length > 0) {
248
+ console.log(
249
+ chalk.yellow(`\n⚠️ Found ${validators.length} running validator(s)`),
250
+ );
251
+ console.log(
252
+ chalk.gray("💡 Programs are added to genesis config and require RESET"),
253
+ );
254
+ console.log(chalk.red(" ⚠️ RESET will WIPE all ledger data!"));
255
+ console.log(
256
+ chalk.gray(
257
+ ` 1. Stop validators using "${config.name}": solforge stop <validator-id>`,
258
+ ),
259
+ );
260
+ console.log(chalk.gray(" 2. Start with reset: solforge start"));
261
+
262
+ const { shouldRestart } = await inquirer.prompt([
263
+ {
264
+ type: "confirm",
265
+ name: "shouldRestart",
266
+ message: "⚠️ Reset validators now? (This will WIPE all ledger data)",
267
+ default: false,
268
+ },
269
+ ]);
270
+
271
+ if (shouldRestart) {
272
+ console.log(chalk.yellow("\n🔄 Resetting validators..."));
273
+ console.log(chalk.red("⚠️ This will delete all ledger data!"));
274
+
275
+ // Import the commands we need
276
+ const { stopCommand } = await import("./stop.js");
277
+ const { startCommand } = await import("./start.js");
278
+
279
+ // Get current config for modifications
280
+ const currentConfig = configManager.getConfig();
281
+
282
+ // Stop validators that use this config
283
+ const configName = currentConfig.name;
284
+ const matchingValidators = validators.filter((v) =>
285
+ v.name.startsWith(configName),
286
+ );
287
+
288
+ if (matchingValidators.length > 0) {
289
+ console.log(
290
+ chalk.gray(
291
+ `🛑 Stopping ${matchingValidators.length} validator(s) using config "${configName}"...`,
292
+ ),
293
+ );
294
+
295
+ for (const validator of matchingValidators) {
296
+ await stopCommand(validator.id, {});
297
+ }
298
+ }
299
+
300
+ // Wait a moment for clean shutdown
301
+ await new Promise((resolve) => setTimeout(resolve, 2000));
302
+
303
+ // Temporarily enable reset for this start
304
+ const originalReset = currentConfig.localnet.reset;
305
+ currentConfig.localnet.reset = true;
306
+
307
+ console.log(
308
+ chalk.cyan(
309
+ "🚀 Starting validator with reset to apply program changes...",
310
+ ),
311
+ );
312
+
313
+ // Start new validator (will reset due to config)
314
+ await startCommand(false);
315
+
316
+ // Restore original reset setting
317
+ currentConfig.localnet.reset = originalReset;
318
+ await configManager.save("./sf.config.json");
319
+ }
320
+ } else {
321
+ console.log(
322
+ chalk.gray(
323
+ "\n💡 Start a validator to use the new program: solforge start",
324
+ ),
325
+ );
326
+ }
327
+ } catch (error) {
328
+ console.error(chalk.red("❌ Failed to add program:"));
329
+ console.error(
330
+ chalk.red(` ${error instanceof Error ? error.message : String(error)}`),
331
+ );
332
+ }
337
333
  }