solforge 0.2.0 → 0.2.2

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 (56) hide show
  1. package/LICENSE +21 -0
  2. package/docs/API.md +379 -0
  3. package/docs/CONFIGURATION.md +407 -0
  4. package/package.json +67 -45
  5. package/src/api-server-entry.ts +109 -0
  6. package/src/commands/add-program.ts +337 -0
  7. package/src/commands/init.ts +122 -0
  8. package/src/commands/list.ts +136 -0
  9. package/src/commands/mint.ts +288 -0
  10. package/src/commands/start.ts +877 -0
  11. package/src/commands/status.ts +99 -0
  12. package/src/commands/stop.ts +406 -0
  13. package/src/config/manager.ts +157 -0
  14. package/src/gui/public/build/main.css +1 -0
  15. package/src/gui/public/build/main.js +303 -0
  16. package/src/gui/public/build/main.js.txt +231 -0
  17. package/src/index.ts +188 -0
  18. package/src/services/api-server.ts +485 -0
  19. package/src/services/port-manager.ts +177 -0
  20. package/src/services/process-registry.ts +154 -0
  21. package/src/services/program-cloner.ts +317 -0
  22. package/src/services/token-cloner.ts +809 -0
  23. package/src/services/validator.ts +295 -0
  24. package/src/types/config.ts +110 -0
  25. package/src/utils/shell.ts +110 -0
  26. package/src/utils/token-loader.ts +115 -0
  27. package/.agi/agi.sqlite +0 -0
  28. package/.claude/settings.local.json +0 -9
  29. package/.github/workflows/release-binaries.yml +0 -133
  30. package/.tmp/.787ebcdbf7b8fde8-00000000.hm +0 -0
  31. package/.tmp/.bffe6efebdf8aedc-00000000.hm +0 -0
  32. package/AGENTS.md +0 -271
  33. package/CLAUDE.md +0 -106
  34. package/PROJECT_STRUCTURE.md +0 -124
  35. package/SOLANA_KIT_GUIDE.md +0 -251
  36. package/SOLFORGE.md +0 -119
  37. package/biome.json +0 -34
  38. package/bun.lock +0 -743
  39. package/drizzle/0000_friendly_millenium_guard.sql +0 -53
  40. package/drizzle/0001_stale_sentinels.sql +0 -2
  41. package/drizzle/meta/0000_snapshot.json +0 -329
  42. package/drizzle/meta/0001_snapshot.json +0 -345
  43. package/drizzle/meta/_journal.json +0 -20
  44. package/drizzle.config.ts +0 -12
  45. package/index.ts +0 -21
  46. package/mint.sh +0 -47
  47. package/postcss.config.js +0 -6
  48. package/rpc-server.ts.backup +0 -519
  49. package/sf.config.json +0 -38
  50. package/tailwind.config.js +0 -27
  51. package/test-client.ts +0 -120
  52. package/tmp/inspect-html.ts +0 -4
  53. package/tmp/response-test.ts +0 -5
  54. package/tmp/test-html.ts +0 -5
  55. package/tmp/test-server.ts +0 -13
  56. package/tsconfig.json +0 -29
@@ -0,0 +1,288 @@
1
+ import { Command } from "commander";
2
+ import chalk from "chalk";
3
+ import { existsSync, readFileSync } from "fs";
4
+ import { join } from "path";
5
+ import { input, select } from "@inquirer/prompts";
6
+ import { runCommand } from "../utils/shell";
7
+ import { Keypair, PublicKey } from "@solana/web3.js";
8
+ import {
9
+ loadClonedTokens,
10
+ findTokenBySymbol,
11
+ type ClonedToken,
12
+ } from "../utils/token-loader.js";
13
+ import type { TokenConfig } from "../types/config.js";
14
+
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"));
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
+ }
35
+
36
+ // Load available tokens
37
+ const tokens = await loadAvailableTokens(workDir);
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
+ }
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();
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
+ }
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
+ }
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
+ }
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
+ });
143
+
144
+ if (confirm.toLowerCase() !== "y" && confirm.toLowerCase() !== "yes") {
145
+ console.log(chalk.yellow("Minting cancelled."));
146
+ process.exit(0);
147
+ }
148
+ }
149
+
150
+ console.log(chalk.blue("🚀 Starting mint..."));
151
+
152
+ // Execute mint
153
+ await mintTokenToWallet(
154
+ selectedToken,
155
+ recipientAddress,
156
+ parseFloat(amount),
157
+ options.rpcUrl
158
+ );
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
+ });
170
+
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
+ }
178
+
179
+ const config = JSON.parse(readFileSync(configPath, "utf8"));
180
+ const tokenConfigs: TokenConfig[] = config.tokens || [];
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
+ }
187
+ }
188
+
189
+ export async function mintTokenToWallet(
190
+ token: ClonedToken,
191
+ walletAddress: string,
192
+ amount: number,
193
+ rpcUrl: string
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...`));
197
+
198
+ const checkAccountsResult = await runCommand(
199
+ "spl-token",
200
+ ["accounts", "--owner", walletAddress, "--url", rpcUrl, "--output", "json"],
201
+ { silent: true }
202
+ );
203
+
204
+ let tokenAccountAddress = "";
205
+
206
+ if (checkAccountsResult.success && checkAccountsResult.stdout) {
207
+ try {
208
+ const accountsData = JSON.parse(checkAccountsResult.stdout);
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
+ }
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...`));
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
+ );
245
+
246
+ if (!createAccountResult.success) {
247
+ throw new Error(
248
+ `Failed to create token account: ${createAccountResult.stderr}`
249
+ );
250
+ }
251
+
252
+ // Extract token account address from create-account output
253
+ const match = createAccountResult.stdout.match(/Creating account (\S+)/);
254
+ tokenAccountAddress = match?.[1] || "";
255
+
256
+ if (!tokenAccountAddress) {
257
+ throw new Error(
258
+ "Failed to determine token account address from create-account output"
259
+ );
260
+ }
261
+
262
+ console.log(chalk.gray(`✅ Created token account: ${tokenAccountAddress}`));
263
+ }
264
+
265
+ // Now mint to the token account (same pattern as token-cloner.ts)
266
+ console.log(chalk.gray(`💰 Minting ${amount} tokens...`));
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
+ );
284
+
285
+ if (!result.success) {
286
+ throw new Error(`Failed to mint tokens: ${result.stderr}`);
287
+ }
288
+ }