solforge 0.2.3 → 0.2.5

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 (43) hide show
  1. package/LICENSE +2 -2
  2. package/README.md +323 -364
  3. package/cli.cjs +126 -69
  4. package/package.json +1 -1
  5. package/scripts/install.sh +112 -0
  6. package/scripts/postinstall.cjs +66 -58
  7. package/server/methods/program/get-token-accounts-by-owner.ts +7 -2
  8. package/server/ws-server.ts +4 -1
  9. package/src/api-server-entry.ts +91 -91
  10. package/src/cli/commands/rpc-start.ts +4 -1
  11. package/src/cli/main.ts +39 -14
  12. package/src/cli/run-solforge.ts +20 -6
  13. package/src/commands/add-program.ts +324 -328
  14. package/src/commands/init.ts +106 -106
  15. package/src/commands/list.ts +125 -125
  16. package/src/commands/mint.ts +246 -246
  17. package/src/commands/start.ts +834 -831
  18. package/src/commands/status.ts +80 -80
  19. package/src/commands/stop.ts +381 -382
  20. package/src/config/manager.ts +149 -149
  21. package/src/gui/public/app.css +1556 -1
  22. package/src/gui/public/build/main.css +1569 -1
  23. package/src/gui/server.ts +20 -21
  24. package/src/gui/src/app.tsx +56 -37
  25. package/src/gui/src/components/airdrop-mint-form.tsx +17 -11
  26. package/src/gui/src/components/clone-program-modal.tsx +6 -6
  27. package/src/gui/src/components/clone-token-modal.tsx +7 -7
  28. package/src/gui/src/components/modal.tsx +13 -11
  29. package/src/gui/src/components/programs-panel.tsx +27 -15
  30. package/src/gui/src/components/status-panel.tsx +31 -17
  31. package/src/gui/src/components/tokens-panel.tsx +25 -19
  32. package/src/gui/src/index.css +491 -463
  33. package/src/index.ts +161 -146
  34. package/src/rpc/start.ts +1 -1
  35. package/src/services/api-server.ts +470 -473
  36. package/src/services/port-manager.ts +167 -167
  37. package/src/services/process-registry.ts +143 -143
  38. package/src/services/program-cloner.ts +312 -312
  39. package/src/services/token-cloner.ts +799 -797
  40. package/src/services/validator.ts +288 -288
  41. package/src/types/config.ts +71 -71
  42. package/src/utils/shell.ts +75 -75
  43. package/src/utils/token-loader.ts +77 -77
@@ -1,288 +1,288 @@
1
- import { Command } from "commander";
1
+ import { input, select } from "@inquirer/prompts";
2
+ import { Keypair, PublicKey } from "@solana/web3.js";
2
3
  import chalk from "chalk";
4
+ import { Command } from "commander";
3
5
  import { existsSync, readFileSync } from "fs";
4
6
  import { join } from "path";
5
- import { input, select } from "@inquirer/prompts";
7
+ import type { TokenConfig } from "../types/config.js";
6
8
  import { runCommand } from "../utils/shell";
7
- import { Keypair, PublicKey } from "@solana/web3.js";
8
9
  import {
9
- loadClonedTokens,
10
- findTokenBySymbol,
11
- type ClonedToken,
10
+ type ClonedToken,
11
+ findTokenBySymbol,
12
+ loadClonedTokens,
12
13
  } from "../utils/token-loader.js";
13
- import type { TokenConfig } from "../types/config.js";
14
14
 
15
15
  export const mintCommand = new Command()
16
- .name("mint")
17
- .description("Interactively mint tokens to any wallet address")
18
- .option("--rpc-url <url>", "RPC URL to use", "http://127.0.0.1:8899")
19
- .option("--symbol <symbol>", "Token symbol to mint")
20
- .option("--wallet <address>", "Wallet address to mint to")
21
- .option("--amount <amount>", "Amount to mint")
22
- .action(async (options) => {
23
- try {
24
- console.log(chalk.blue("đŸĒ™ Interactive Token Minting"));
25
- console.log(chalk.gray("Mint tokens to any wallet address\n"));
16
+ .name("mint")
17
+ .description("Interactively mint tokens to any wallet address")
18
+ .option("--rpc-url <url>", "RPC URL to use", "http://127.0.0.1:8899")
19
+ .option("--symbol <symbol>", "Token symbol to mint")
20
+ .option("--wallet <address>", "Wallet address to mint to")
21
+ .option("--amount <amount>", "Amount to mint")
22
+ .action(async (options) => {
23
+ try {
24
+ console.log(chalk.blue("đŸĒ™ Interactive Token Minting"));
25
+ console.log(chalk.gray("Mint tokens to any wallet address\n"));
26
26
 
27
- // Check if solforge data exists
28
- const workDir = ".solforge";
29
- if (!existsSync(workDir)) {
30
- console.error(
31
- chalk.red("❌ No solforge data found. Run 'solforge start' first.")
32
- );
33
- process.exit(1);
34
- }
27
+ // Check if solforge data exists
28
+ const workDir = ".solforge";
29
+ if (!existsSync(workDir)) {
30
+ console.error(
31
+ chalk.red("❌ No solforge data found. Run 'solforge start' first."),
32
+ );
33
+ process.exit(1);
34
+ }
35
35
 
36
- // Load available tokens
37
- const tokens = await loadAvailableTokens(workDir);
36
+ // Load available tokens
37
+ const tokens = await loadAvailableTokens(workDir);
38
38
 
39
- if (tokens.length === 0) {
40
- console.error(
41
- chalk.red(
42
- "❌ No tokens found. Run 'solforge start' first to clone tokens."
43
- )
44
- );
45
- process.exit(1);
46
- }
39
+ if (tokens.length === 0) {
40
+ console.error(
41
+ chalk.red(
42
+ "❌ No tokens found. Run 'solforge start' first to clone tokens.",
43
+ ),
44
+ );
45
+ process.exit(1);
46
+ }
47
47
 
48
- // Display available tokens
49
- console.log(chalk.cyan("📋 Available Tokens:"));
50
- tokens.forEach((token, index) => {
51
- console.log(
52
- chalk.gray(
53
- ` ${index + 1}. ${token.config.symbol} (${
54
- token.config.mainnetMint
55
- })`
56
- )
57
- );
58
- });
59
- console.log();
48
+ // Display available tokens
49
+ console.log(chalk.cyan("📋 Available Tokens:"));
50
+ tokens.forEach((token, index) => {
51
+ console.log(
52
+ chalk.gray(
53
+ ` ${index + 1}. ${token.config.symbol} (${
54
+ token.config.mainnetMint
55
+ })`,
56
+ ),
57
+ );
58
+ });
59
+ console.log();
60
60
 
61
- // Select token (or use provided symbol)
62
- let selectedToken: ClonedToken;
63
- if (options.symbol) {
64
- const token = findTokenBySymbol(tokens, options.symbol);
65
- if (!token) {
66
- console.error(
67
- chalk.red(`❌ Token ${options.symbol} not found in cloned tokens`)
68
- );
69
- process.exit(1);
70
- }
71
- selectedToken = token;
72
- console.log(
73
- chalk.gray(`Selected token: ${selectedToken.config.symbol}`)
74
- );
75
- } else {
76
- selectedToken = await select({
77
- message: "Select a token to mint:",
78
- choices: tokens.map((token) => ({
79
- name: `${token.config.symbol} (${token.config.mainnetMint})`,
80
- value: token,
81
- })),
82
- });
83
- }
61
+ // Select token (or use provided symbol)
62
+ let selectedToken: ClonedToken;
63
+ if (options.symbol) {
64
+ const token = findTokenBySymbol(tokens, options.symbol);
65
+ if (!token) {
66
+ console.error(
67
+ chalk.red(`❌ Token ${options.symbol} not found in cloned tokens`),
68
+ );
69
+ process.exit(1);
70
+ }
71
+ selectedToken = token;
72
+ console.log(
73
+ chalk.gray(`Selected token: ${selectedToken.config.symbol}`),
74
+ );
75
+ } else {
76
+ selectedToken = await select({
77
+ message: "Select a token to mint:",
78
+ choices: tokens.map((token) => ({
79
+ name: `${token.config.symbol} (${token.config.mainnetMint})`,
80
+ value: token,
81
+ })),
82
+ });
83
+ }
84
84
 
85
- // Get recipient address (or use provided wallet)
86
- let recipientAddress: string;
87
- if (options.wallet) {
88
- recipientAddress = options.wallet;
89
- // Validate wallet address
90
- try {
91
- new PublicKey(recipientAddress);
92
- } catch {
93
- console.error(chalk.red("❌ Invalid wallet address"));
94
- process.exit(1);
95
- }
96
- console.log(chalk.gray(`Recipient wallet: ${recipientAddress}`));
97
- } else {
98
- recipientAddress = await input({
99
- message: "Enter recipient wallet address:",
100
- validate: (value: string) => {
101
- if (!value.trim()) {
102
- return "Please enter a valid address";
103
- }
104
- try {
105
- new PublicKey(value.trim());
106
- return true;
107
- } catch {
108
- return "Please enter a valid Solana address";
109
- }
110
- },
111
- });
112
- }
85
+ // Get recipient address (or use provided wallet)
86
+ let recipientAddress: string;
87
+ if (options.wallet) {
88
+ recipientAddress = options.wallet;
89
+ // Validate wallet address
90
+ try {
91
+ new PublicKey(recipientAddress);
92
+ } catch {
93
+ console.error(chalk.red("❌ Invalid wallet address"));
94
+ process.exit(1);
95
+ }
96
+ console.log(chalk.gray(`Recipient wallet: ${recipientAddress}`));
97
+ } else {
98
+ recipientAddress = await input({
99
+ message: "Enter recipient wallet address:",
100
+ validate: (value: string) => {
101
+ if (!value.trim()) {
102
+ return "Please enter a valid address";
103
+ }
104
+ try {
105
+ new PublicKey(value.trim());
106
+ return true;
107
+ } catch {
108
+ return "Please enter a valid Solana address";
109
+ }
110
+ },
111
+ });
112
+ }
113
113
 
114
- // Get amount to mint (or use provided amount)
115
- let amount: string;
116
- if (options.amount) {
117
- const num = parseFloat(options.amount);
118
- if (isNaN(num) || num <= 0) {
119
- console.error(chalk.red("❌ Invalid amount"));
120
- process.exit(1);
121
- }
122
- amount = options.amount;
123
- console.log(chalk.gray(`Amount to mint: ${amount}`));
124
- } else {
125
- amount = await input({
126
- message: "Enter amount to mint:",
127
- validate: (value: string) => {
128
- const num = parseFloat(value);
129
- if (isNaN(num) || num <= 0) {
130
- return "Please enter a valid positive number";
131
- }
132
- return true;
133
- },
134
- });
135
- }
114
+ // Get amount to mint (or use provided amount)
115
+ let amount: string;
116
+ if (options.amount) {
117
+ const num = parseFloat(options.amount);
118
+ if (isNaN(num) || num <= 0) {
119
+ console.error(chalk.red("❌ Invalid amount"));
120
+ process.exit(1);
121
+ }
122
+ amount = options.amount;
123
+ console.log(chalk.gray(`Amount to mint: ${amount}`));
124
+ } else {
125
+ amount = await input({
126
+ message: "Enter amount to mint:",
127
+ validate: (value: string) => {
128
+ const num = parseFloat(value);
129
+ if (isNaN(num) || num <= 0) {
130
+ return "Please enter a valid positive number";
131
+ }
132
+ return true;
133
+ },
134
+ });
135
+ }
136
136
 
137
- // Confirm minting if interactive
138
- if (!options.symbol || !options.wallet || !options.amount) {
139
- const confirm = await input({
140
- message: `Confirm minting ${amount} ${selectedToken.config.symbol} to ${recipientAddress}? (y/N):`,
141
- default: "N",
142
- });
137
+ // Confirm minting if interactive
138
+ if (!options.symbol || !options.wallet || !options.amount) {
139
+ const confirm = await input({
140
+ message: `Confirm minting ${amount} ${selectedToken.config.symbol} to ${recipientAddress}? (y/N):`,
141
+ default: "N",
142
+ });
143
143
 
144
- if (confirm.toLowerCase() !== "y" && confirm.toLowerCase() !== "yes") {
145
- console.log(chalk.yellow("Minting cancelled."));
146
- process.exit(0);
147
- }
148
- }
144
+ if (confirm.toLowerCase() !== "y" && confirm.toLowerCase() !== "yes") {
145
+ console.log(chalk.yellow("Minting cancelled."));
146
+ process.exit(0);
147
+ }
148
+ }
149
149
 
150
- console.log(chalk.blue("🚀 Starting mint..."));
150
+ console.log(chalk.blue("🚀 Starting mint..."));
151
151
 
152
- // Execute mint
153
- await mintTokenToWallet(
154
- selectedToken,
155
- recipientAddress,
156
- parseFloat(amount),
157
- options.rpcUrl
158
- );
152
+ // Execute mint
153
+ await mintTokenToWallet(
154
+ selectedToken,
155
+ recipientAddress,
156
+ parseFloat(amount),
157
+ options.rpcUrl,
158
+ );
159
159
 
160
- console.log(
161
- chalk.green(
162
- `✅ Successfully minted ${amount} ${selectedToken.config.symbol} to ${recipientAddress}`
163
- )
164
- );
165
- } catch (error) {
166
- console.error(chalk.red(`❌ Mint failed: ${error}`));
167
- process.exit(1);
168
- }
169
- });
160
+ console.log(
161
+ chalk.green(
162
+ `✅ Successfully minted ${amount} ${selectedToken.config.symbol} to ${recipientAddress}`,
163
+ ),
164
+ );
165
+ } catch (error) {
166
+ console.error(chalk.red(`❌ Mint failed: ${error}`));
167
+ process.exit(1);
168
+ }
169
+ });
170
170
 
171
171
  async function loadAvailableTokens(workDir: string): Promise<ClonedToken[]> {
172
- try {
173
- // Load token config from sf.config.json
174
- const configPath = "sf.config.json";
175
- if (!existsSync(configPath)) {
176
- throw new Error("sf.config.json not found in current directory");
177
- }
172
+ try {
173
+ // Load token config from sf.config.json
174
+ const configPath = "sf.config.json";
175
+ if (!existsSync(configPath)) {
176
+ throw new Error("sf.config.json not found in current directory");
177
+ }
178
178
 
179
- const config = JSON.parse(readFileSync(configPath, "utf8"));
180
- const tokenConfigs: TokenConfig[] = config.tokens || [];
179
+ const config = JSON.parse(readFileSync(configPath, "utf8"));
180
+ const tokenConfigs: TokenConfig[] = config.tokens || [];
181
181
 
182
- // Use the shared token loader
183
- return await loadClonedTokens(tokenConfigs, workDir);
184
- } catch (error) {
185
- throw new Error(`Failed to load tokens: ${error}`);
186
- }
182
+ // Use the shared token loader
183
+ return await loadClonedTokens(tokenConfigs, workDir);
184
+ } catch (error) {
185
+ throw new Error(`Failed to load tokens: ${error}`);
186
+ }
187
187
  }
188
188
 
189
189
  export async function mintTokenToWallet(
190
- token: ClonedToken,
191
- walletAddress: string,
192
- amount: number,
193
- rpcUrl: string
190
+ token: ClonedToken,
191
+ walletAddress: string,
192
+ amount: number,
193
+ rpcUrl: string,
194
194
  ): Promise<void> {
195
- // Check if associated token account already exists (same pattern as token-cloner.ts)
196
- console.log(chalk.gray(`🔍 Checking for existing token account...`));
195
+ // Check if associated token account already exists (same pattern as token-cloner.ts)
196
+ console.log(chalk.gray(`🔍 Checking for existing token account...`));
197
197
 
198
- const checkAccountsResult = await runCommand(
199
- "spl-token",
200
- ["accounts", "--owner", walletAddress, "--url", rpcUrl, "--output", "json"],
201
- { silent: true }
202
- );
198
+ const checkAccountsResult = await runCommand(
199
+ "spl-token",
200
+ ["accounts", "--owner", walletAddress, "--url", rpcUrl, "--output", "json"],
201
+ { silent: true },
202
+ );
203
203
 
204
- let tokenAccountAddress = "";
204
+ let tokenAccountAddress = "";
205
205
 
206
- if (checkAccountsResult.success && checkAccountsResult.stdout) {
207
- try {
208
- const accountsData = JSON.parse(checkAccountsResult.stdout);
206
+ if (checkAccountsResult.success && checkAccountsResult.stdout) {
207
+ try {
208
+ const accountsData = JSON.parse(checkAccountsResult.stdout);
209
209
 
210
- // Look for existing token account for this mint
211
- for (const account of accountsData.accounts || []) {
212
- if (account.mint === token.config.mainnetMint) {
213
- tokenAccountAddress = account.address;
214
- console.log(
215
- chalk.gray(
216
- `â„šī¸ Found existing token account: ${tokenAccountAddress}`
217
- )
218
- );
219
- break;
220
- }
221
- }
222
- } catch (error) {
223
- // No existing accounts found or parsing error, will create new account
224
- }
225
- }
210
+ // Look for existing token account for this mint
211
+ for (const account of accountsData.accounts || []) {
212
+ if (account.mint === token.config.mainnetMint) {
213
+ tokenAccountAddress = account.address;
214
+ console.log(
215
+ chalk.gray(
216
+ `â„šī¸ Found existing token account: ${tokenAccountAddress}`,
217
+ ),
218
+ );
219
+ break;
220
+ }
221
+ }
222
+ } catch (error) {
223
+ // No existing accounts found or parsing error, will create new account
224
+ }
225
+ }
226
226
 
227
- if (!tokenAccountAddress) {
228
- // Account doesn't exist, create it (same pattern as token-cloner.ts)
229
- console.log(chalk.gray(`🔧 Creating token account...`));
227
+ if (!tokenAccountAddress) {
228
+ // Account doesn't exist, create it (same pattern as token-cloner.ts)
229
+ console.log(chalk.gray(`🔧 Creating token account...`));
230
230
 
231
- const createAccountResult = await runCommand(
232
- "spl-token",
233
- [
234
- "create-account",
235
- token.config.mainnetMint,
236
- "--owner",
237
- walletAddress,
238
- "--fee-payer",
239
- token.mintAuthorityPath,
240
- "--url",
241
- rpcUrl,
242
- ],
243
- { silent: false }
244
- );
231
+ const createAccountResult = await runCommand(
232
+ "spl-token",
233
+ [
234
+ "create-account",
235
+ token.config.mainnetMint,
236
+ "--owner",
237
+ walletAddress,
238
+ "--fee-payer",
239
+ token.mintAuthorityPath,
240
+ "--url",
241
+ rpcUrl,
242
+ ],
243
+ { silent: false },
244
+ );
245
245
 
246
- if (!createAccountResult.success) {
247
- throw new Error(
248
- `Failed to create token account: ${createAccountResult.stderr}`
249
- );
250
- }
246
+ if (!createAccountResult.success) {
247
+ throw new Error(
248
+ `Failed to create token account: ${createAccountResult.stderr}`,
249
+ );
250
+ }
251
251
 
252
- // Extract token account address from create-account output
253
- const match = createAccountResult.stdout.match(/Creating account (\S+)/);
254
- tokenAccountAddress = match?.[1] || "";
252
+ // Extract token account address from create-account output
253
+ const match = createAccountResult.stdout.match(/Creating account (\S+)/);
254
+ tokenAccountAddress = match?.[1] || "";
255
255
 
256
- if (!tokenAccountAddress) {
257
- throw new Error(
258
- "Failed to determine token account address from create-account output"
259
- );
260
- }
256
+ if (!tokenAccountAddress) {
257
+ throw new Error(
258
+ "Failed to determine token account address from create-account output",
259
+ );
260
+ }
261
261
 
262
- console.log(chalk.gray(`✅ Created token account: ${tokenAccountAddress}`));
263
- }
262
+ console.log(chalk.gray(`✅ Created token account: ${tokenAccountAddress}`));
263
+ }
264
264
 
265
- // Now mint to the token account (same pattern as token-cloner.ts)
266
- console.log(chalk.gray(`💰 Minting ${amount} tokens...`));
265
+ // Now mint to the token account (same pattern as token-cloner.ts)
266
+ console.log(chalk.gray(`💰 Minting ${amount} tokens...`));
267
267
 
268
- const result = await runCommand(
269
- "spl-token",
270
- [
271
- "mint",
272
- token.config.mainnetMint,
273
- amount.toString(),
274
- tokenAccountAddress,
275
- "--mint-authority",
276
- token.mintAuthorityPath,
277
- "--fee-payer",
278
- token.mintAuthorityPath,
279
- "--url",
280
- rpcUrl,
281
- ],
282
- { silent: false }
283
- );
268
+ const result = await runCommand(
269
+ "spl-token",
270
+ [
271
+ "mint",
272
+ token.config.mainnetMint,
273
+ amount.toString(),
274
+ tokenAccountAddress,
275
+ "--mint-authority",
276
+ token.mintAuthorityPath,
277
+ "--fee-payer",
278
+ token.mintAuthorityPath,
279
+ "--url",
280
+ rpcUrl,
281
+ ],
282
+ { silent: false },
283
+ );
284
284
 
285
- if (!result.success) {
286
- throw new Error(`Failed to mint tokens: ${result.stderr}`);
287
- }
285
+ if (!result.success) {
286
+ throw new Error(`Failed to mint tokens: ${result.stderr}`);
287
+ }
288
288
  }