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,122 +1,122 @@
1
- import { writeFileSync, existsSync } from "fs";
2
- import { resolve } from "path";
3
1
  import chalk from "chalk";
2
+ import { existsSync, writeFileSync } from "node:fs";
4
3
  import inquirer from "inquirer";
4
+ import { resolve } from "node:path";
5
5
  import type { Config } from "../types/config.js";
6
6
 
7
7
  const defaultConfig: Config = {
8
- name: "my-localnet",
9
- description: "Local Solana development environment",
10
- tokens: [
11
- {
12
- symbol: "USDC",
13
- mainnetMint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
14
- recipients: [],
15
- mintAmount: 1000000,
16
- cloneMetadata: true,
17
- },
18
- ],
19
- programs: [],
20
- localnet: {
21
- airdropAmount: 100,
22
- faucetAccounts: [],
23
- port: 8899,
24
- faucetPort: 9900,
25
- reset: false,
26
- logLevel: "info",
27
- bindAddress: "127.0.0.1",
28
- quiet: false,
29
- rpc: "https://api.mainnet-beta.solana.com",
30
- limitLedgerSize: 100000,
31
- },
8
+ name: "my-localnet",
9
+ description: "Local Solana development environment",
10
+ tokens: [
11
+ {
12
+ symbol: "USDC",
13
+ mainnetMint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
14
+ recipients: [],
15
+ mintAmount: 1000000,
16
+ cloneMetadata: true,
17
+ },
18
+ ],
19
+ programs: [],
20
+ localnet: {
21
+ airdropAmount: 100,
22
+ faucetAccounts: [],
23
+ port: 8899,
24
+ faucetPort: 9900,
25
+ reset: false,
26
+ logLevel: "info",
27
+ bindAddress: "127.0.0.1",
28
+ quiet: false,
29
+ rpc: "https://api.mainnet-beta.solana.com",
30
+ limitLedgerSize: 100000,
31
+ },
32
32
  };
33
33
 
34
34
  export async function initCommand(): Promise<void> {
35
- const configPath = resolve(process.cwd(), "sf.config.json");
35
+ const configPath = resolve(process.cwd(), "sf.config.json");
36
36
 
37
- // Check if config already exists
38
- if (existsSync(configPath)) {
39
- const { overwrite } = await inquirer.prompt([
40
- {
41
- type: "confirm",
42
- name: "overwrite",
43
- message: "sf.config.json already exists. Overwrite?",
44
- default: false,
45
- },
46
- ]);
37
+ // Check if config already exists
38
+ if (existsSync(configPath)) {
39
+ const { overwrite } = await inquirer.prompt([
40
+ {
41
+ type: "confirm",
42
+ name: "overwrite",
43
+ message: "sf.config.json already exists. Overwrite?",
44
+ default: false,
45
+ },
46
+ ]);
47
47
 
48
- if (!overwrite) {
49
- console.log(chalk.yellow("āš ļø Initialization cancelled"));
50
- return;
51
- }
52
- }
48
+ if (!overwrite) {
49
+ console.log(chalk.yellow("āš ļø Initialization cancelled"));
50
+ return;
51
+ }
52
+ }
53
53
 
54
- // Gather basic configuration
55
- const answers = await inquirer.prompt([
56
- {
57
- type: "input",
58
- name: "name",
59
- message: "Project name:",
60
- default: "my-localnet",
61
- },
62
- {
63
- type: "input",
64
- name: "description",
65
- message: "Description:",
66
- default: "Local Solana development environment",
67
- },
68
- {
69
- type: "number",
70
- name: "port",
71
- message: "RPC port:",
72
- default: 8899,
73
- },
74
- {
75
- type: "confirm",
76
- name: "includeUsdc",
77
- message: "Include USDC token?",
78
- default: true,
79
- },
80
- ]);
54
+ // Gather basic configuration
55
+ const answers = await inquirer.prompt([
56
+ {
57
+ type: "input",
58
+ name: "name",
59
+ message: "Project name:",
60
+ default: "my-localnet",
61
+ },
62
+ {
63
+ type: "input",
64
+ name: "description",
65
+ message: "Description:",
66
+ default: "Local Solana development environment",
67
+ },
68
+ {
69
+ type: "number",
70
+ name: "port",
71
+ message: "RPC port:",
72
+ default: 8899,
73
+ },
74
+ {
75
+ type: "confirm",
76
+ name: "includeUsdc",
77
+ message: "Include USDC token?",
78
+ default: true,
79
+ },
80
+ ]);
81
81
 
82
- // Build config
83
- const config: Config = {
84
- ...defaultConfig,
85
- name: answers.name,
86
- description: answers.description,
87
- localnet: {
88
- ...defaultConfig.localnet,
89
- port: answers.port,
90
- },
91
- };
82
+ // Build config
83
+ const config: Config = {
84
+ ...defaultConfig,
85
+ name: answers.name,
86
+ description: answers.description,
87
+ localnet: {
88
+ ...defaultConfig.localnet,
89
+ port: answers.port,
90
+ },
91
+ };
92
92
 
93
- if (!answers.includeUsdc) {
94
- config.tokens = [];
95
- }
93
+ if (!answers.includeUsdc) {
94
+ config.tokens = [];
95
+ }
96
96
 
97
- try {
98
- // Write config file
99
- writeFileSync(configPath, JSON.stringify(config, null, 2));
97
+ try {
98
+ // Write config file
99
+ writeFileSync(configPath, JSON.stringify(config, null, 2));
100
100
 
101
- console.log(chalk.green("āœ… sf.config.json created successfully!"));
102
- console.log(chalk.gray(`šŸ“„ Config saved to: ${configPath}`));
103
- console.log();
104
- console.log(chalk.blue("Next steps:"));
105
- console.log(
106
- chalk.gray("1. Edit sf.config.json to add your tokens and programs")
107
- );
108
- console.log(chalk.gray("2. Run `solforge start` to launch your localnet"));
109
- console.log();
110
- console.log(
111
- chalk.yellow(
112
- "šŸ’” Tip: Check configs/example.sf.config.json for more examples"
113
- )
114
- );
115
- } catch (error) {
116
- console.error(chalk.red("āŒ Failed to create sf.config.json"));
117
- console.error(
118
- chalk.red(error instanceof Error ? error.message : String(error))
119
- );
120
- process.exit(1);
121
- }
101
+ console.log(chalk.green("āœ… sf.config.json created successfully!"));
102
+ console.log(chalk.gray(`šŸ“„ Config saved to: ${configPath}`));
103
+ console.log();
104
+ console.log(chalk.blue("Next steps:"));
105
+ console.log(
106
+ chalk.gray("1. Edit sf.config.json to add your tokens and programs"),
107
+ );
108
+ console.log(chalk.gray("2. Run `solforge start` to launch your localnet"));
109
+ console.log();
110
+ console.log(
111
+ chalk.yellow(
112
+ "šŸ’” Tip: Check configs/example.sf.config.json for more examples",
113
+ ),
114
+ );
115
+ } catch (error) {
116
+ console.error(chalk.red("āŒ Failed to create sf.config.json"));
117
+ console.error(
118
+ chalk.red(error instanceof Error ? error.message : String(error)),
119
+ );
120
+ process.exit(1);
121
+ }
122
122
  }
@@ -1,136 +1,136 @@
1
1
  import chalk from "chalk";
2
- import { processRegistry } from "../services/process-registry.js";
3
2
  import type { RunningValidator } from "../services/process-registry.js";
3
+ import { processRegistry } from "../services/process-registry.js";
4
4
 
5
5
  export async function listCommand(): Promise<void> {
6
- console.log(chalk.blue("šŸ“‹ Listing running validators...\n"));
7
-
8
- // Clean up dead processes first
9
- await processRegistry.cleanup();
10
-
11
- const validators = processRegistry.getRunning();
12
-
13
- if (validators.length === 0) {
14
- console.log(chalk.yellow("āš ļø No running validators found"));
15
- console.log(chalk.gray("šŸ’” Use `solforge start` to start a validator"));
16
- return;
17
- }
18
-
19
- // Verify each validator is actually still running
20
- const activeValidators: RunningValidator[] = [];
21
- for (const validator of validators) {
22
- const isRunning = await processRegistry.isProcessRunning(validator.pid);
23
- if (isRunning) {
24
- activeValidators.push({ ...validator, status: "running" });
25
- } else {
26
- processRegistry.updateStatus(validator.id, "stopped");
27
- }
28
- }
29
-
30
- if (activeValidators.length === 0) {
31
- console.log(
32
- chalk.yellow(
33
- "āš ļø No active validators found (all processes have stopped)"
34
- )
35
- );
36
- console.log(chalk.gray("šŸ’” Use `solforge start` to start a validator"));
37
- return;
38
- }
39
-
40
- console.log(
41
- chalk.green(
42
- `āœ… Found ${activeValidators.length} running validator${
43
- activeValidators.length > 1 ? "s" : ""
44
- }\n`
45
- )
46
- );
47
-
48
- // Display validators in a table format
49
- displayValidatorsTable(activeValidators);
50
-
51
- console.log(
52
- chalk.gray("\nšŸ’” Use `solforge stop <id>` to stop a specific validator")
53
- );
54
- console.log(
55
- chalk.gray("šŸ’” Use `solforge stop --all` to stop all validators")
56
- );
6
+ console.log(chalk.blue("šŸ“‹ Listing running validators...\n"));
7
+
8
+ // Clean up dead processes first
9
+ await processRegistry.cleanup();
10
+
11
+ const validators = processRegistry.getRunning();
12
+
13
+ if (validators.length === 0) {
14
+ console.log(chalk.yellow("āš ļø No running validators found"));
15
+ console.log(chalk.gray("šŸ’” Use `solforge start` to start a validator"));
16
+ return;
17
+ }
18
+
19
+ // Verify each validator is actually still running
20
+ const activeValidators: RunningValidator[] = [];
21
+ for (const validator of validators) {
22
+ const isRunning = await processRegistry.isProcessRunning(validator.pid);
23
+ if (isRunning) {
24
+ activeValidators.push({ ...validator, status: "running" });
25
+ } else {
26
+ processRegistry.updateStatus(validator.id, "stopped");
27
+ }
28
+ }
29
+
30
+ if (activeValidators.length === 0) {
31
+ console.log(
32
+ chalk.yellow(
33
+ "āš ļø No active validators found (all processes have stopped)",
34
+ ),
35
+ );
36
+ console.log(chalk.gray("šŸ’” Use `solforge start` to start a validator"));
37
+ return;
38
+ }
39
+
40
+ console.log(
41
+ chalk.green(
42
+ `āœ… Found ${activeValidators.length} running validator${
43
+ activeValidators.length > 1 ? "s" : ""
44
+ }\n`,
45
+ ),
46
+ );
47
+
48
+ // Display validators in a table format
49
+ displayValidatorsTable(activeValidators);
50
+
51
+ console.log(
52
+ chalk.gray("\nšŸ’” Use `solforge stop <id>` to stop a specific validator"),
53
+ );
54
+ console.log(
55
+ chalk.gray("šŸ’” Use `solforge stop --all` to stop all validators"),
56
+ );
57
57
  }
58
58
 
59
59
  function displayValidatorsTable(validators: RunningValidator[]): void {
60
- // Calculate column widths
61
- const maxIdWidth = Math.max(2, ...validators.map((v) => v.id.length));
62
- const maxNameWidth = Math.max(4, ...validators.map((v) => v.name.length));
63
- const maxPidWidth = Math.max(
64
- 3,
65
- ...validators.map((v) => v.pid.toString().length)
66
- );
67
- const maxPortWidth = 9; // "8899/9900" format
68
- const maxUptimeWidth = 7;
69
-
70
- // Header
71
- const header =
72
- chalk.bold("ID".padEnd(maxIdWidth)) +
73
- " | " +
74
- chalk.bold("Name".padEnd(maxNameWidth)) +
75
- " | " +
76
- chalk.bold("PID".padEnd(maxPidWidth)) +
77
- " | " +
78
- chalk.bold("RPC/Faucet".padEnd(maxPortWidth)) +
79
- " | " +
80
- chalk.bold("Uptime".padEnd(maxUptimeWidth)) +
81
- " | " +
82
- chalk.bold("Status");
83
-
84
- console.log(header);
85
- console.log("-".repeat(header.length - 20)); // Subtract ANSI codes length
86
-
87
- // Rows
88
- validators.forEach((validator) => {
89
- const uptime = formatUptime(validator.startTime);
90
- const ports = `${validator.rpcPort}/${validator.faucetPort}`;
91
- const status =
92
- validator.status === "running" ? chalk.green("ā—") : chalk.red("ā—");
93
-
94
- const row =
95
- validator.id.padEnd(maxIdWidth) +
96
- " | " +
97
- validator.name.padEnd(maxNameWidth) +
98
- " | " +
99
- validator.pid.toString().padEnd(maxPidWidth) +
100
- " | " +
101
- ports.padEnd(maxPortWidth) +
102
- " | " +
103
- uptime.padEnd(maxUptimeWidth) +
104
- " | " +
105
- status;
106
-
107
- console.log(row);
108
- });
109
-
110
- console.log(); // Empty line
111
-
112
- // URLs section
113
- console.log(chalk.cyan("🌐 Connection URLs:"));
114
- validators.forEach((validator) => {
115
- console.log(chalk.gray(` ${validator.name} (${validator.id}):`));
116
- console.log(chalk.gray(` RPC: ${validator.rpcUrl}`));
117
- console.log(chalk.gray(` Faucet: ${validator.faucetUrl}`));
118
- });
60
+ // Calculate column widths
61
+ const maxIdWidth = Math.max(2, ...validators.map((v) => v.id.length));
62
+ const maxNameWidth = Math.max(4, ...validators.map((v) => v.name.length));
63
+ const maxPidWidth = Math.max(
64
+ 3,
65
+ ...validators.map((v) => v.pid.toString().length),
66
+ );
67
+ const maxPortWidth = 9; // "8899/9900" format
68
+ const maxUptimeWidth = 7;
69
+
70
+ // Header
71
+ const header =
72
+ chalk.bold("ID".padEnd(maxIdWidth)) +
73
+ " | " +
74
+ chalk.bold("Name".padEnd(maxNameWidth)) +
75
+ " | " +
76
+ chalk.bold("PID".padEnd(maxPidWidth)) +
77
+ " | " +
78
+ chalk.bold("RPC/Faucet".padEnd(maxPortWidth)) +
79
+ " | " +
80
+ chalk.bold("Uptime".padEnd(maxUptimeWidth)) +
81
+ " | " +
82
+ chalk.bold("Status");
83
+
84
+ console.log(header);
85
+ console.log("-".repeat(header.length - 20)); // Subtract ANSI codes length
86
+
87
+ // Rows
88
+ validators.forEach((validator) => {
89
+ const uptime = formatUptime(validator.startTime);
90
+ const ports = `${validator.rpcPort}/${validator.faucetPort}`;
91
+ const status =
92
+ validator.status === "running" ? chalk.green("ā—") : chalk.red("ā—");
93
+
94
+ const row =
95
+ validator.id.padEnd(maxIdWidth) +
96
+ " | " +
97
+ validator.name.padEnd(maxNameWidth) +
98
+ " | " +
99
+ validator.pid.toString().padEnd(maxPidWidth) +
100
+ " | " +
101
+ ports.padEnd(maxPortWidth) +
102
+ " | " +
103
+ uptime.padEnd(maxUptimeWidth) +
104
+ " | " +
105
+ status;
106
+
107
+ console.log(row);
108
+ });
109
+
110
+ console.log(); // Empty line
111
+
112
+ // URLs section
113
+ console.log(chalk.cyan("🌐 Connection URLs:"));
114
+ validators.forEach((validator) => {
115
+ console.log(chalk.gray(` ${validator.name} (${validator.id}):`));
116
+ console.log(chalk.gray(` RPC: ${validator.rpcUrl}`));
117
+ console.log(chalk.gray(` Faucet: ${validator.faucetUrl}`));
118
+ });
119
119
  }
120
120
 
121
121
  function formatUptime(startTime: Date): string {
122
- const now = new Date();
123
- const uptimeMs = now.getTime() - startTime.getTime();
124
- const uptimeSeconds = Math.floor(uptimeMs / 1000);
125
-
126
- if (uptimeSeconds < 60) {
127
- return `${uptimeSeconds}s`;
128
- } else if (uptimeSeconds < 3600) {
129
- const minutes = Math.floor(uptimeSeconds / 60);
130
- return `${minutes}m`;
131
- } else {
132
- const hours = Math.floor(uptimeSeconds / 3600);
133
- const minutes = Math.floor((uptimeSeconds % 3600) / 60);
134
- return `${hours}h${minutes}m`;
135
- }
122
+ const now = new Date();
123
+ const uptimeMs = now.getTime() - startTime.getTime();
124
+ const uptimeSeconds = Math.floor(uptimeMs / 1000);
125
+
126
+ if (uptimeSeconds < 60) {
127
+ return `${uptimeSeconds}s`;
128
+ } else if (uptimeSeconds < 3600) {
129
+ const minutes = Math.floor(uptimeSeconds / 60);
130
+ return `${minutes}m`;
131
+ } else {
132
+ const hours = Math.floor(uptimeSeconds / 3600);
133
+ const minutes = Math.floor((uptimeSeconds % 3600) / 60);
134
+ return `${hours}h${minutes}m`;
135
+ }
136
136
  }