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.
- package/LICENSE +2 -2
- package/README.md +323 -364
- package/cli.cjs +126 -69
- package/package.json +1 -1
- package/scripts/install.sh +112 -0
- package/scripts/postinstall.cjs +66 -58
- package/server/methods/program/get-token-accounts-by-owner.ts +7 -2
- package/server/ws-server.ts +4 -1
- package/src/api-server-entry.ts +91 -91
- package/src/cli/commands/rpc-start.ts +4 -1
- package/src/cli/main.ts +39 -14
- package/src/cli/run-solforge.ts +20 -6
- package/src/commands/add-program.ts +324 -328
- package/src/commands/init.ts +106 -106
- package/src/commands/list.ts +125 -125
- package/src/commands/mint.ts +246 -246
- package/src/commands/start.ts +834 -831
- package/src/commands/status.ts +80 -80
- package/src/commands/stop.ts +381 -382
- package/src/config/manager.ts +149 -149
- package/src/gui/public/app.css +1556 -1
- package/src/gui/public/build/main.css +1569 -1
- package/src/gui/server.ts +20 -21
- package/src/gui/src/app.tsx +56 -37
- package/src/gui/src/components/airdrop-mint-form.tsx +17 -11
- package/src/gui/src/components/clone-program-modal.tsx +6 -6
- package/src/gui/src/components/clone-token-modal.tsx +7 -7
- package/src/gui/src/components/modal.tsx +13 -11
- package/src/gui/src/components/programs-panel.tsx +27 -15
- package/src/gui/src/components/status-panel.tsx +31 -17
- package/src/gui/src/components/tokens-panel.tsx +25 -19
- package/src/gui/src/index.css +491 -463
- package/src/index.ts +161 -146
- package/src/rpc/start.ts +1 -1
- package/src/services/api-server.ts +470 -473
- package/src/services/port-manager.ts +167 -167
- package/src/services/process-registry.ts +143 -143
- package/src/services/program-cloner.ts +312 -312
- package/src/services/token-cloner.ts +799 -797
- package/src/services/validator.ts +288 -288
- package/src/types/config.ts +71 -71
- package/src/utils/shell.ts +75 -75
- package/src/utils/token-loader.ts +77 -77
|
@@ -1,317 +1,317 @@
|
|
|
1
|
-
import { readFileSync, writeFileSync, existsSync, mkdirSync } from "fs";
|
|
2
|
-
import { join } from "path";
|
|
3
|
-
import chalk from "chalk";
|
|
4
1
|
import { Connection, PublicKey } from "@solana/web3.js";
|
|
5
|
-
import
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
4
|
+
import { join } from "path";
|
|
6
5
|
import type { ProgramConfig } from "../types/config.js";
|
|
6
|
+
import { runCommand } from "../utils/shell.js";
|
|
7
7
|
|
|
8
8
|
export class ProgramCloner {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
9
|
+
private workDir: string;
|
|
10
|
+
|
|
11
|
+
constructor(workDir: string = ".solforge") {
|
|
12
|
+
this.workDir = workDir;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Clone programs for validator startup (saved as .so files)
|
|
17
|
+
*/
|
|
18
|
+
async clonePrograms(
|
|
19
|
+
programs: ProgramConfig[],
|
|
20
|
+
targetCluster: string = "mainnet-beta",
|
|
21
|
+
): Promise<
|
|
22
|
+
Array<{
|
|
23
|
+
success: boolean;
|
|
24
|
+
program: ProgramConfig;
|
|
25
|
+
error?: string;
|
|
26
|
+
filePath?: string;
|
|
27
|
+
}>
|
|
28
|
+
> {
|
|
29
|
+
console.log(chalk.cyan("\nš§ Cloning programs from mainnet..."));
|
|
30
|
+
|
|
31
|
+
if (!existsSync(this.workDir)) {
|
|
32
|
+
mkdirSync(this.workDir, { recursive: true });
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const programsDir = join(this.workDir, "programs");
|
|
36
|
+
if (!existsSync(programsDir)) {
|
|
37
|
+
mkdirSync(programsDir, { recursive: true });
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const results = [];
|
|
41
|
+
|
|
42
|
+
for (const program of programs) {
|
|
43
|
+
console.log(
|
|
44
|
+
chalk.gray(
|
|
45
|
+
` š¦ Processing ${program.name || program.mainnetProgramId}...`,
|
|
46
|
+
),
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
// Clone dependencies first
|
|
51
|
+
if (program.dependencies && program.dependencies.length > 0) {
|
|
52
|
+
console.log(
|
|
53
|
+
chalk.gray(
|
|
54
|
+
` š Cloning ${program.dependencies.length} dependencies...`,
|
|
55
|
+
),
|
|
56
|
+
);
|
|
57
|
+
for (const depId of program.dependencies) {
|
|
58
|
+
await this.cloneSingleProgram(depId, programsDir, targetCluster);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Clone the main program
|
|
63
|
+
const result = await this.cloneSingleProgram(
|
|
64
|
+
program.mainnetProgramId,
|
|
65
|
+
programsDir,
|
|
66
|
+
targetCluster,
|
|
67
|
+
program.name,
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
results.push({
|
|
71
|
+
success: true,
|
|
72
|
+
program,
|
|
73
|
+
filePath: result.filePath,
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
console.log(chalk.gray(` ā Cloned to ${result.filePath}`));
|
|
77
|
+
} catch (error) {
|
|
78
|
+
console.error(
|
|
79
|
+
chalk.red(` ā Failed to clone ${program.mainnetProgramId}`),
|
|
80
|
+
);
|
|
81
|
+
console.error(
|
|
82
|
+
chalk.red(
|
|
83
|
+
` ${error instanceof Error ? error.message : String(error)}`,
|
|
84
|
+
),
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
results.push({
|
|
88
|
+
success: false,
|
|
89
|
+
program,
|
|
90
|
+
error: error instanceof Error ? error.message : String(error),
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const successful = results.filter((r) => r.success).length;
|
|
96
|
+
console.log(
|
|
97
|
+
chalk.cyan(`\nā
Cloned ${successful}/${programs.length} programs`),
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
return results;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Clone a single program from mainnet
|
|
105
|
+
*/
|
|
106
|
+
private async cloneSingleProgram(
|
|
107
|
+
programId: string,
|
|
108
|
+
outputDir: string,
|
|
109
|
+
cluster: string = "mainnet-beta",
|
|
110
|
+
name?: string,
|
|
111
|
+
): Promise<{ filePath: string }> {
|
|
112
|
+
const fileName = name
|
|
113
|
+
? `${name.toLowerCase().replace(/\s+/g, "-")}.so`
|
|
114
|
+
: `${programId}.so`;
|
|
115
|
+
const outputPath = join(outputDir, fileName);
|
|
116
|
+
|
|
117
|
+
// Skip if already exists
|
|
118
|
+
if (existsSync(outputPath)) {
|
|
119
|
+
return { filePath: outputPath };
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Use solana account command to fetch program data
|
|
123
|
+
const rpcUrl = this.getClusterUrl(cluster);
|
|
124
|
+
const accountResult = await runCommand(
|
|
125
|
+
"solana",
|
|
126
|
+
["account", programId, "--output", "json", "--url", rpcUrl],
|
|
127
|
+
{ silent: true },
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
if (!accountResult.success) {
|
|
131
|
+
throw new Error(
|
|
132
|
+
`Failed to fetch program account: ${accountResult.stderr}`,
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
try {
|
|
137
|
+
const accountData = JSON.parse(accountResult.stdout);
|
|
138
|
+
const programData = accountData.account.data;
|
|
139
|
+
|
|
140
|
+
if (!programData || programData[1] !== "base64") {
|
|
141
|
+
throw new Error("Invalid program data format");
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Decode base64 program data
|
|
145
|
+
const binaryData = Buffer.from(programData[0], "base64");
|
|
146
|
+
|
|
147
|
+
// Write as .so file
|
|
148
|
+
writeFileSync(outputPath, binaryData);
|
|
149
|
+
|
|
150
|
+
return { filePath: outputPath };
|
|
151
|
+
} catch (error) {
|
|
152
|
+
throw new Error(
|
|
153
|
+
`Failed to process program data: ${
|
|
154
|
+
error instanceof Error ? error.message : String(error)
|
|
155
|
+
}`,
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Generate validator arguments for cloned programs
|
|
162
|
+
*/
|
|
163
|
+
generateValidatorArgs(
|
|
164
|
+
clonedPrograms: Array<{
|
|
165
|
+
success: boolean;
|
|
166
|
+
program: ProgramConfig;
|
|
167
|
+
filePath?: string;
|
|
168
|
+
}>,
|
|
169
|
+
): string[] {
|
|
170
|
+
const args: string[] = [];
|
|
171
|
+
|
|
172
|
+
for (const result of clonedPrograms) {
|
|
173
|
+
if (result.success && result.filePath) {
|
|
174
|
+
args.push("--bpf-program");
|
|
175
|
+
args.push(result.program.mainnetProgramId);
|
|
176
|
+
args.push(result.filePath);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return args;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Deploy program to running validator (hot deployment)
|
|
185
|
+
*/
|
|
186
|
+
async deployToRunningValidator(
|
|
187
|
+
programId: string,
|
|
188
|
+
rpcUrl: string,
|
|
189
|
+
name?: string,
|
|
190
|
+
): Promise<{ success: boolean; deployedAddress?: string; error?: string }> {
|
|
191
|
+
try {
|
|
192
|
+
console.log(
|
|
193
|
+
chalk.cyan(`\nš Hot deploying program ${name || programId}...`),
|
|
194
|
+
);
|
|
195
|
+
|
|
196
|
+
// First, clone the program if we don't have it
|
|
197
|
+
const programsDir = join(this.workDir, "programs");
|
|
198
|
+
if (!existsSync(programsDir)) {
|
|
199
|
+
mkdirSync(programsDir, { recursive: true });
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const cloneResult = await this.cloneSingleProgram(
|
|
203
|
+
programId,
|
|
204
|
+
programsDir,
|
|
205
|
+
"mainnet-beta",
|
|
206
|
+
name,
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
// Deploy to running validator using solana program deploy
|
|
210
|
+
console.log(chalk.gray(" š¤ Deploying to validator..."));
|
|
211
|
+
|
|
212
|
+
const deployResult = await runCommand(
|
|
213
|
+
"solana",
|
|
214
|
+
[
|
|
215
|
+
"program",
|
|
216
|
+
"deploy",
|
|
217
|
+
cloneResult.filePath,
|
|
218
|
+
"--program-id",
|
|
219
|
+
programId,
|
|
220
|
+
"--url",
|
|
221
|
+
rpcUrl,
|
|
222
|
+
],
|
|
223
|
+
{ silent: false },
|
|
224
|
+
);
|
|
225
|
+
|
|
226
|
+
if (!deployResult.success) {
|
|
227
|
+
return {
|
|
228
|
+
success: false,
|
|
229
|
+
error: `Deployment failed: ${
|
|
230
|
+
deployResult.stderr || deployResult.stdout
|
|
231
|
+
}`,
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
console.log(
|
|
236
|
+
chalk.green(` ā
Successfully deployed ${name || programId}`),
|
|
237
|
+
);
|
|
238
|
+
|
|
239
|
+
return {
|
|
240
|
+
success: true,
|
|
241
|
+
deployedAddress: programId,
|
|
242
|
+
};
|
|
243
|
+
} catch (error) {
|
|
244
|
+
return {
|
|
245
|
+
success: false,
|
|
246
|
+
error: error instanceof Error ? error.message : String(error),
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Get cluster RPC URL
|
|
253
|
+
*/
|
|
254
|
+
private getClusterUrl(cluster: string): string {
|
|
255
|
+
switch (cluster) {
|
|
256
|
+
case "mainnet-beta":
|
|
257
|
+
return "https://api.mainnet-beta.solana.com";
|
|
258
|
+
case "devnet":
|
|
259
|
+
return "https://api.devnet.solana.com";
|
|
260
|
+
case "testnet":
|
|
261
|
+
return "https://api.testnet.solana.com";
|
|
262
|
+
default:
|
|
263
|
+
return cluster; // Assume it's a custom URL
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Verify program exists on cluster
|
|
269
|
+
*/
|
|
270
|
+
async verifyProgram(
|
|
271
|
+
programId: string,
|
|
272
|
+
cluster: string = "mainnet-beta",
|
|
273
|
+
): Promise<boolean> {
|
|
274
|
+
try {
|
|
275
|
+
const connection = new Connection(this.getClusterUrl(cluster));
|
|
276
|
+
const programAccount = await connection.getAccountInfo(
|
|
277
|
+
new PublicKey(programId),
|
|
278
|
+
);
|
|
279
|
+
return programAccount !== null && programAccount.executable;
|
|
280
|
+
} catch {
|
|
281
|
+
return false;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Get program info from cluster
|
|
287
|
+
*/
|
|
288
|
+
async getProgramInfo(
|
|
289
|
+
programId: string,
|
|
290
|
+
cluster: string = "mainnet-beta",
|
|
291
|
+
): Promise<{
|
|
292
|
+
exists: boolean;
|
|
293
|
+
executable?: boolean;
|
|
294
|
+
owner?: string;
|
|
295
|
+
size?: number;
|
|
296
|
+
}> {
|
|
297
|
+
try {
|
|
298
|
+
const connection = new Connection(this.getClusterUrl(cluster));
|
|
299
|
+
const programAccount = await connection.getAccountInfo(
|
|
300
|
+
new PublicKey(programId),
|
|
301
|
+
);
|
|
302
|
+
|
|
303
|
+
if (!programAccount) {
|
|
304
|
+
return { exists: false };
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
return {
|
|
308
|
+
exists: true,
|
|
309
|
+
executable: programAccount.executable,
|
|
310
|
+
owner: programAccount.owner.toBase58(),
|
|
311
|
+
size: programAccount.data.length,
|
|
312
|
+
};
|
|
313
|
+
} catch (error) {
|
|
314
|
+
return { exists: false };
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
317
|
}
|