solforge 0.1.1 ā 0.1.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.
- package/README.md +41 -4
- package/package.json +1 -1
- package/src/api-server-entry.ts +105 -0
- package/src/commands/mint.ts +336 -0
- package/src/commands/start.ts +126 -0
- package/src/commands/stop.ts +20 -3
- package/src/index.ts +2 -2
- package/src/services/api-server.ts +519 -0
- package/src/services/process-registry.ts +4 -5
- package/src/commands/transfer.ts +0 -259
package/README.md
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
- š **Port management** - Automatic port allocation and conflict resolution
|
|
14
14
|
- š **Configuration-driven** - JSON-based configuration for reproducible environments
|
|
15
15
|
- šØ **Beautiful CLI** - Colorful, intuitive command-line interface
|
|
16
|
+
- š **REST API** - Background API server for programmatic access to validator operations
|
|
16
17
|
|
|
17
18
|
## š Quick Start
|
|
18
19
|
|
|
@@ -66,10 +67,33 @@ bun run install:binary
|
|
|
66
67
|
solforge stop --all
|
|
67
68
|
```
|
|
68
69
|
|
|
70
|
+
### API Server
|
|
71
|
+
|
|
72
|
+
SolForge automatically starts a REST API server alongside your validator, providing programmatic access to validator operations:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
# API server starts automatically with the validator
|
|
76
|
+
solforge start
|
|
77
|
+
|
|
78
|
+
# API available at http://127.0.0.1:3000/api
|
|
79
|
+
curl http://127.0.0.1:3000/api/health
|
|
80
|
+
|
|
81
|
+
# Mint tokens via API
|
|
82
|
+
curl -X POST http://127.0.0.1:3000/api/tokens/USDC/mint \
|
|
83
|
+
-H "Content-Type: application/json" \
|
|
84
|
+
-d '{"walletAddress": "YOUR_WALLET_ADDRESS", "amount": 1000}'
|
|
85
|
+
|
|
86
|
+
# Get wallet balances
|
|
87
|
+
curl http://127.0.0.1:3000/api/wallet/YOUR_WALLET_ADDRESS/balances
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
For complete API documentation, see [API Documentation](docs/API.md).
|
|
91
|
+
|
|
69
92
|
## š Documentation
|
|
70
93
|
|
|
71
94
|
### š Additional Documentation
|
|
72
95
|
|
|
96
|
+
- [API Documentation](docs/API.md) - REST API endpoints and usage examples
|
|
73
97
|
- [Configuration Guide](docs/CONFIGURATION.md) - Detailed configuration options and examples
|
|
74
98
|
- [Troubleshooting Guide](#-troubleshooting) - Common issues and solutions
|
|
75
99
|
|
|
@@ -178,18 +202,31 @@ solforge add-program --program-id <address> --name <name>
|
|
|
178
202
|
- `--name <name>` - Friendly name for the program
|
|
179
203
|
- `--no-interactive` - Run in non-interactive mode
|
|
180
204
|
|
|
181
|
-
#### `solforge
|
|
205
|
+
#### `solforge mint [options]`
|
|
182
206
|
|
|
183
|
-
Interactively
|
|
207
|
+
Interactively mint tokens to any wallet address.
|
|
184
208
|
|
|
185
209
|
```bash
|
|
186
|
-
solforge
|
|
187
|
-
solforge
|
|
210
|
+
solforge mint # Interactive mode
|
|
211
|
+
solforge mint --symbol USDC --wallet <address> --amount 1000 # CLI mode
|
|
212
|
+
solforge mint --rpc-url http://localhost:8899 # Custom RPC
|
|
188
213
|
```
|
|
189
214
|
|
|
190
215
|
**Options:**
|
|
191
216
|
|
|
192
217
|
- `--rpc-url <url>` - RPC URL to use (default: "http://127.0.0.1:8899")
|
|
218
|
+
- `--symbol <symbol>` - Token symbol to mint
|
|
219
|
+
- `--wallet <address>` - Wallet address to mint to
|
|
220
|
+
- `--amount <amount>` - Amount to mint
|
|
221
|
+
|
|
222
|
+
**Interactive Mode:**
|
|
223
|
+
When run without arguments, `solforge mint` will:
|
|
224
|
+
|
|
225
|
+
- Display available cloned tokens
|
|
226
|
+
- Allow you to select which token to mint
|
|
227
|
+
- Prompt for recipient wallet address
|
|
228
|
+
- Prompt for amount to mint
|
|
229
|
+
- Handle SPL token account creation automatically
|
|
193
230
|
|
|
194
231
|
#### `solforge reset`
|
|
195
232
|
|
package/package.json
CHANGED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { APIServer } from "./services/api-server.js";
|
|
4
|
+
import { configManager } from "./config/manager.js";
|
|
5
|
+
import chalk from "chalk";
|
|
6
|
+
|
|
7
|
+
async function main() {
|
|
8
|
+
try {
|
|
9
|
+
// Parse command line arguments
|
|
10
|
+
const args = process.argv.slice(2);
|
|
11
|
+
const portIndex = args.indexOf("--port");
|
|
12
|
+
const configIndex = args.indexOf("--config");
|
|
13
|
+
const rpcIndex = args.indexOf("--rpc-url");
|
|
14
|
+
const faucetIndex = args.indexOf("--faucet-url");
|
|
15
|
+
const workDirIndex = args.indexOf("--work-dir");
|
|
16
|
+
|
|
17
|
+
if (
|
|
18
|
+
portIndex === -1 ||
|
|
19
|
+
configIndex === -1 ||
|
|
20
|
+
rpcIndex === -1 ||
|
|
21
|
+
faucetIndex === -1 ||
|
|
22
|
+
workDirIndex === -1 ||
|
|
23
|
+
!args[portIndex + 1] ||
|
|
24
|
+
!args[configIndex + 1] ||
|
|
25
|
+
!args[rpcIndex + 1] ||
|
|
26
|
+
!args[faucetIndex + 1] ||
|
|
27
|
+
!args[workDirIndex + 1]
|
|
28
|
+
) {
|
|
29
|
+
console.error(
|
|
30
|
+
"Usage: api-server-entry --port <port> --config <config-path> --rpc-url <url> --faucet-url <url> --work-dir <dir>"
|
|
31
|
+
);
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const port = parseInt(args[portIndex + 1]!);
|
|
36
|
+
const configPath = args[configIndex + 1]!;
|
|
37
|
+
const rpcUrl = args[rpcIndex + 1]!;
|
|
38
|
+
const faucetUrl = args[faucetIndex + 1]!;
|
|
39
|
+
const workDir = args[workDirIndex + 1]!;
|
|
40
|
+
|
|
41
|
+
// Load configuration
|
|
42
|
+
await configManager.load(configPath);
|
|
43
|
+
const config = configManager.getConfig();
|
|
44
|
+
|
|
45
|
+
// Create and start API server
|
|
46
|
+
const apiServer = new APIServer({
|
|
47
|
+
port,
|
|
48
|
+
validatorRpcUrl: rpcUrl,
|
|
49
|
+
validatorFaucetUrl: faucetUrl,
|
|
50
|
+
config,
|
|
51
|
+
workDir,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const result = await apiServer.start();
|
|
55
|
+
|
|
56
|
+
if (result.success) {
|
|
57
|
+
console.log(chalk.green(`š API Server started on port ${port}`));
|
|
58
|
+
|
|
59
|
+
// Keep the process alive
|
|
60
|
+
process.on("SIGTERM", async () => {
|
|
61
|
+
console.log(
|
|
62
|
+
chalk.yellow("š” API Server received SIGTERM, shutting down...")
|
|
63
|
+
);
|
|
64
|
+
await apiServer.stop();
|
|
65
|
+
process.exit(0);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
process.on("SIGINT", async () => {
|
|
69
|
+
console.log(
|
|
70
|
+
chalk.yellow("š” API Server received SIGINT, shutting down...")
|
|
71
|
+
);
|
|
72
|
+
await apiServer.stop();
|
|
73
|
+
process.exit(0);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// Keep process alive
|
|
77
|
+
setInterval(() => {}, 1000);
|
|
78
|
+
} else {
|
|
79
|
+
console.error(
|
|
80
|
+
chalk.red(`ā Failed to start API server: ${result.error}`)
|
|
81
|
+
);
|
|
82
|
+
process.exit(1);
|
|
83
|
+
}
|
|
84
|
+
} catch (error) {
|
|
85
|
+
console.error(
|
|
86
|
+
chalk.red(
|
|
87
|
+
`ā API Server error: ${
|
|
88
|
+
error instanceof Error ? error.message : String(error)
|
|
89
|
+
}`
|
|
90
|
+
)
|
|
91
|
+
);
|
|
92
|
+
process.exit(1);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
main().catch((error) => {
|
|
97
|
+
console.error(
|
|
98
|
+
chalk.red(
|
|
99
|
+
`ā Fatal error: ${
|
|
100
|
+
error instanceof Error ? error.message : String(error)
|
|
101
|
+
}`
|
|
102
|
+
)
|
|
103
|
+
);
|
|
104
|
+
process.exit(1);
|
|
105
|
+
});
|
|
@@ -0,0 +1,336 @@
|
|
|
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
|
+
|
|
9
|
+
interface TokenConfig {
|
|
10
|
+
symbol: string;
|
|
11
|
+
mainnetMint: string;
|
|
12
|
+
mintAmount: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface ClonedToken {
|
|
16
|
+
config: TokenConfig;
|
|
17
|
+
mintAuthorityPath: string;
|
|
18
|
+
modifiedAccountPath: string;
|
|
19
|
+
mintAuthority: {
|
|
20
|
+
publicKey: string;
|
|
21
|
+
secretKey: number[];
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const mintCommand = new Command()
|
|
26
|
+
.name("mint")
|
|
27
|
+
.description("Interactively mint tokens to any wallet address")
|
|
28
|
+
.option("--rpc-url <url>", "RPC URL to use", "http://127.0.0.1:8899")
|
|
29
|
+
.option("--symbol <symbol>", "Token symbol to mint")
|
|
30
|
+
.option("--wallet <address>", "Wallet address to mint to")
|
|
31
|
+
.option("--amount <amount>", "Amount to mint")
|
|
32
|
+
.action(async (options) => {
|
|
33
|
+
try {
|
|
34
|
+
console.log(chalk.blue("šŖ Interactive Token Minting"));
|
|
35
|
+
console.log(chalk.gray("Mint tokens to any wallet address\n"));
|
|
36
|
+
|
|
37
|
+
// Check if solforge data exists
|
|
38
|
+
const workDir = ".solforge";
|
|
39
|
+
if (!existsSync(workDir)) {
|
|
40
|
+
console.error(
|
|
41
|
+
chalk.red("ā No solforge data found. Run 'solforge start' first.")
|
|
42
|
+
);
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Load available tokens
|
|
47
|
+
const tokens = await loadAvailableTokens(workDir);
|
|
48
|
+
|
|
49
|
+
if (tokens.length === 0) {
|
|
50
|
+
console.error(
|
|
51
|
+
chalk.red(
|
|
52
|
+
"ā No tokens found. Run 'solforge start' first to clone tokens."
|
|
53
|
+
)
|
|
54
|
+
);
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Display available tokens
|
|
59
|
+
console.log(chalk.cyan("š Available Tokens:"));
|
|
60
|
+
tokens.forEach((token, index) => {
|
|
61
|
+
console.log(
|
|
62
|
+
chalk.gray(
|
|
63
|
+
` ${index + 1}. ${token.config.symbol} (${
|
|
64
|
+
token.config.mainnetMint
|
|
65
|
+
})`
|
|
66
|
+
)
|
|
67
|
+
);
|
|
68
|
+
});
|
|
69
|
+
console.log();
|
|
70
|
+
|
|
71
|
+
// Select token (or use provided symbol)
|
|
72
|
+
let selectedToken: ClonedToken;
|
|
73
|
+
if (options.symbol) {
|
|
74
|
+
const token = tokens.find(
|
|
75
|
+
(t) => t.config.symbol.toLowerCase() === options.symbol.toLowerCase()
|
|
76
|
+
);
|
|
77
|
+
if (!token) {
|
|
78
|
+
console.error(
|
|
79
|
+
chalk.red(`ā Token ${options.symbol} not found in cloned tokens`)
|
|
80
|
+
);
|
|
81
|
+
process.exit(1);
|
|
82
|
+
}
|
|
83
|
+
selectedToken = token;
|
|
84
|
+
console.log(
|
|
85
|
+
chalk.gray(`Selected token: ${selectedToken.config.symbol}`)
|
|
86
|
+
);
|
|
87
|
+
} else {
|
|
88
|
+
selectedToken = await select({
|
|
89
|
+
message: "Select a token to mint:",
|
|
90
|
+
choices: tokens.map((token) => ({
|
|
91
|
+
name: `${token.config.symbol} (${token.config.mainnetMint})`,
|
|
92
|
+
value: token,
|
|
93
|
+
})),
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Get recipient address (or use provided wallet)
|
|
98
|
+
let recipientAddress: string;
|
|
99
|
+
if (options.wallet) {
|
|
100
|
+
recipientAddress = options.wallet;
|
|
101
|
+
// Validate wallet address
|
|
102
|
+
try {
|
|
103
|
+
new PublicKey(recipientAddress);
|
|
104
|
+
} catch {
|
|
105
|
+
console.error(chalk.red("ā Invalid wallet address"));
|
|
106
|
+
process.exit(1);
|
|
107
|
+
}
|
|
108
|
+
console.log(chalk.gray(`Recipient wallet: ${recipientAddress}`));
|
|
109
|
+
} else {
|
|
110
|
+
recipientAddress = await input({
|
|
111
|
+
message: "Enter recipient wallet address:",
|
|
112
|
+
validate: (value: string) => {
|
|
113
|
+
if (!value.trim()) {
|
|
114
|
+
return "Please enter a valid address";
|
|
115
|
+
}
|
|
116
|
+
try {
|
|
117
|
+
new PublicKey(value.trim());
|
|
118
|
+
return true;
|
|
119
|
+
} catch {
|
|
120
|
+
return "Please enter a valid Solana address";
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Get amount to mint (or use provided amount)
|
|
127
|
+
let amount: string;
|
|
128
|
+
if (options.amount) {
|
|
129
|
+
const num = parseFloat(options.amount);
|
|
130
|
+
if (isNaN(num) || num <= 0) {
|
|
131
|
+
console.error(chalk.red("ā Invalid amount"));
|
|
132
|
+
process.exit(1);
|
|
133
|
+
}
|
|
134
|
+
amount = options.amount;
|
|
135
|
+
console.log(chalk.gray(`Amount to mint: ${amount}`));
|
|
136
|
+
} else {
|
|
137
|
+
amount = await input({
|
|
138
|
+
message: "Enter amount to mint:",
|
|
139
|
+
validate: (value: string) => {
|
|
140
|
+
const num = parseFloat(value);
|
|
141
|
+
if (isNaN(num) || num <= 0) {
|
|
142
|
+
return "Please enter a valid positive number";
|
|
143
|
+
}
|
|
144
|
+
return true;
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Confirm minting if interactive
|
|
150
|
+
if (!options.symbol || !options.wallet || !options.amount) {
|
|
151
|
+
const confirm = await input({
|
|
152
|
+
message: `Confirm minting ${amount} ${selectedToken.config.symbol} to ${recipientAddress}? (y/N):`,
|
|
153
|
+
default: "N",
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
if (confirm.toLowerCase() !== "y" && confirm.toLowerCase() !== "yes") {
|
|
157
|
+
console.log(chalk.yellow("Minting cancelled."));
|
|
158
|
+
process.exit(0);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
console.log(chalk.blue("š Starting mint..."));
|
|
163
|
+
|
|
164
|
+
// Execute mint
|
|
165
|
+
await mintTokenToWallet(
|
|
166
|
+
selectedToken,
|
|
167
|
+
recipientAddress,
|
|
168
|
+
parseFloat(amount),
|
|
169
|
+
options.rpcUrl
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
console.log(
|
|
173
|
+
chalk.green(
|
|
174
|
+
`ā
Successfully minted ${amount} ${selectedToken.config.symbol} to ${recipientAddress}`
|
|
175
|
+
)
|
|
176
|
+
);
|
|
177
|
+
} catch (error) {
|
|
178
|
+
console.error(chalk.red(`ā Mint failed: ${error}`));
|
|
179
|
+
process.exit(1);
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
async function loadAvailableTokens(workDir: string): Promise<ClonedToken[]> {
|
|
184
|
+
const tokens: ClonedToken[] = [];
|
|
185
|
+
|
|
186
|
+
try {
|
|
187
|
+
// Load token config from sf.config.json
|
|
188
|
+
const configPath = "sf.config.json";
|
|
189
|
+
if (!existsSync(configPath)) {
|
|
190
|
+
throw new Error("sf.config.json not found in current directory");
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const config = JSON.parse(readFileSync(configPath, "utf8"));
|
|
194
|
+
const tokenConfigs: TokenConfig[] = config.tokens || [];
|
|
195
|
+
|
|
196
|
+
// Load shared mint authority
|
|
197
|
+
const sharedMintAuthorityPath = join(workDir, "shared-mint-authority.json");
|
|
198
|
+
if (!existsSync(sharedMintAuthorityPath)) {
|
|
199
|
+
throw new Error("Shared mint authority not found");
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const secretKeyArray = JSON.parse(
|
|
203
|
+
readFileSync(sharedMintAuthorityPath, "utf8")
|
|
204
|
+
);
|
|
205
|
+
const mintAuthorityKeypair = Keypair.fromSecretKey(
|
|
206
|
+
new Uint8Array(secretKeyArray)
|
|
207
|
+
);
|
|
208
|
+
const mintAuthority = {
|
|
209
|
+
publicKey: mintAuthorityKeypair.publicKey.toBase58(),
|
|
210
|
+
secretKey: Array.from(mintAuthorityKeypair.secretKey),
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
// Build cloned tokens list
|
|
214
|
+
for (const tokenConfig of tokenConfigs) {
|
|
215
|
+
const tokenDir = join(
|
|
216
|
+
workDir,
|
|
217
|
+
`token-${tokenConfig.symbol.toLowerCase()}`
|
|
218
|
+
);
|
|
219
|
+
const modifiedAccountPath = join(tokenDir, "modified.json");
|
|
220
|
+
|
|
221
|
+
if (existsSync(modifiedAccountPath)) {
|
|
222
|
+
tokens.push({
|
|
223
|
+
config: tokenConfig,
|
|
224
|
+
mintAuthorityPath: sharedMintAuthorityPath,
|
|
225
|
+
modifiedAccountPath,
|
|
226
|
+
mintAuthority,
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
return tokens;
|
|
232
|
+
} catch (error) {
|
|
233
|
+
throw new Error(`Failed to load tokens: ${error}`);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export async function mintTokenToWallet(
|
|
238
|
+
token: ClonedToken,
|
|
239
|
+
walletAddress: string,
|
|
240
|
+
amount: number,
|
|
241
|
+
rpcUrl: string
|
|
242
|
+
): Promise<void> {
|
|
243
|
+
// Check if associated token account already exists (same pattern as token-cloner.ts)
|
|
244
|
+
console.log(chalk.gray(`š Checking for existing token account...`));
|
|
245
|
+
|
|
246
|
+
const checkAccountsResult = await runCommand(
|
|
247
|
+
"spl-token",
|
|
248
|
+
["accounts", "--owner", walletAddress, "--url", rpcUrl, "--output", "json"],
|
|
249
|
+
{ silent: true }
|
|
250
|
+
);
|
|
251
|
+
|
|
252
|
+
let tokenAccountAddress = "";
|
|
253
|
+
|
|
254
|
+
if (checkAccountsResult.success && checkAccountsResult.stdout) {
|
|
255
|
+
try {
|
|
256
|
+
const accountsData = JSON.parse(checkAccountsResult.stdout);
|
|
257
|
+
|
|
258
|
+
// Look for existing token account for this mint
|
|
259
|
+
for (const account of accountsData.accounts || []) {
|
|
260
|
+
if (account.mint === token.config.mainnetMint) {
|
|
261
|
+
tokenAccountAddress = account.address;
|
|
262
|
+
console.log(
|
|
263
|
+
chalk.gray(
|
|
264
|
+
`ā¹ļø Found existing token account: ${tokenAccountAddress}`
|
|
265
|
+
)
|
|
266
|
+
);
|
|
267
|
+
break;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
} catch (error) {
|
|
271
|
+
// No existing accounts found or parsing error, will create new account
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
if (!tokenAccountAddress) {
|
|
276
|
+
// Account doesn't exist, create it (same pattern as token-cloner.ts)
|
|
277
|
+
console.log(chalk.gray(`š§ Creating token account...`));
|
|
278
|
+
|
|
279
|
+
const createAccountResult = await runCommand(
|
|
280
|
+
"spl-token",
|
|
281
|
+
[
|
|
282
|
+
"create-account",
|
|
283
|
+
token.config.mainnetMint,
|
|
284
|
+
"--owner",
|
|
285
|
+
walletAddress,
|
|
286
|
+
"--fee-payer",
|
|
287
|
+
token.mintAuthorityPath,
|
|
288
|
+
"--url",
|
|
289
|
+
rpcUrl,
|
|
290
|
+
],
|
|
291
|
+
{ silent: false }
|
|
292
|
+
);
|
|
293
|
+
|
|
294
|
+
if (!createAccountResult.success) {
|
|
295
|
+
throw new Error(
|
|
296
|
+
`Failed to create token account: ${createAccountResult.stderr}`
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// Extract token account address from create-account output
|
|
301
|
+
const match = createAccountResult.stdout.match(/Creating account (\S+)/);
|
|
302
|
+
tokenAccountAddress = match?.[1] || "";
|
|
303
|
+
|
|
304
|
+
if (!tokenAccountAddress) {
|
|
305
|
+
throw new Error(
|
|
306
|
+
"Failed to determine token account address from create-account output"
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
console.log(chalk.gray(`ā
Created token account: ${tokenAccountAddress}`));
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// Now mint to the token account (same pattern as token-cloner.ts)
|
|
314
|
+
console.log(chalk.gray(`š° Minting ${amount} tokens...`));
|
|
315
|
+
|
|
316
|
+
const result = await runCommand(
|
|
317
|
+
"spl-token",
|
|
318
|
+
[
|
|
319
|
+
"mint",
|
|
320
|
+
token.config.mainnetMint,
|
|
321
|
+
amount.toString(),
|
|
322
|
+
tokenAccountAddress,
|
|
323
|
+
"--mint-authority",
|
|
324
|
+
token.mintAuthorityPath,
|
|
325
|
+
"--fee-payer",
|
|
326
|
+
token.mintAuthorityPath,
|
|
327
|
+
"--url",
|
|
328
|
+
rpcUrl,
|
|
329
|
+
],
|
|
330
|
+
{ silent: false }
|
|
331
|
+
);
|
|
332
|
+
|
|
333
|
+
if (!result.success) {
|
|
334
|
+
throw new Error(`Failed to mint tokens: ${result.stderr}`);
|
|
335
|
+
}
|
|
336
|
+
}
|
package/src/commands/start.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { TokenCloner } from "../services/token-cloner.js";
|
|
|
9
9
|
import { ProgramCloner } from "../services/program-cloner.js";
|
|
10
10
|
import { processRegistry } from "../services/process-registry.js";
|
|
11
11
|
import { portManager } from "../services/port-manager.js";
|
|
12
|
+
|
|
12
13
|
import type { Config, TokenConfig, ProgramConfig } from "../types/config.js";
|
|
13
14
|
import type { ClonedToken } from "../services/token-cloner.js";
|
|
14
15
|
import type { RunningValidator } from "../services/process-registry.js";
|
|
@@ -334,6 +335,93 @@ export async function startCommand(debug: boolean = false): Promise<void> {
|
|
|
334
335
|
debug
|
|
335
336
|
);
|
|
336
337
|
|
|
338
|
+
// Find an available port for the API server
|
|
339
|
+
let apiServerPort = 3000;
|
|
340
|
+
while (!(await portManager.isPortAvailable(apiServerPort))) {
|
|
341
|
+
apiServerPort++;
|
|
342
|
+
if (apiServerPort > 3100) {
|
|
343
|
+
throw new Error("Could not find available port for API server");
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// Start the API server as a background process
|
|
348
|
+
let apiServerPid: number | undefined;
|
|
349
|
+
let apiResult: { success: boolean; error?: string } = {
|
|
350
|
+
success: false,
|
|
351
|
+
error: "Not started",
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
try {
|
|
355
|
+
const currentDir = process.cwd();
|
|
356
|
+
const testpilotDir = join(__dirname, "..", "..");
|
|
357
|
+
const apiServerScript = join(testpilotDir, "src", "api-server-entry.ts");
|
|
358
|
+
const configPath =
|
|
359
|
+
configManager.getConfigPath() ?? join(currentDir, "sf.config.json");
|
|
360
|
+
const workDir = join(currentDir, ".solforge");
|
|
361
|
+
|
|
362
|
+
// Start API server in background using runCommand with nohup
|
|
363
|
+
const apiServerCommand = `nohup bun run "${apiServerScript}" --port ${apiServerPort} --config "${configPath}" --rpc-url "http://127.0.0.1:${config.localnet.port}" --faucet-url "http://127.0.0.1:${config.localnet.faucetPort}" --work-dir "${workDir}" > /dev/null 2>&1 &`;
|
|
364
|
+
|
|
365
|
+
const startResult = await runCommand("sh", ["-c", apiServerCommand], {
|
|
366
|
+
silent: !debug,
|
|
367
|
+
debug: debug,
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
if (startResult.success) {
|
|
371
|
+
// Wait a moment for the API server to start
|
|
372
|
+
await new Promise((resolve) => setTimeout(resolve, 3000));
|
|
373
|
+
|
|
374
|
+
// Test if the API server is responding
|
|
375
|
+
try {
|
|
376
|
+
const response = await fetch(
|
|
377
|
+
`http://127.0.0.1:${apiServerPort}/api/health`
|
|
378
|
+
);
|
|
379
|
+
if (response.ok) {
|
|
380
|
+
apiResult = { success: true };
|
|
381
|
+
// Get the PID of the API server process
|
|
382
|
+
const pidResult = await runCommand(
|
|
383
|
+
"pgrep",
|
|
384
|
+
["-f", `api-server-entry.*--port ${apiServerPort}`],
|
|
385
|
+
{ silent: true, debug: false }
|
|
386
|
+
);
|
|
387
|
+
if (pidResult.success && pidResult.stdout.trim()) {
|
|
388
|
+
apiServerPid = parseInt(pidResult.stdout.trim().split("\n")[0]);
|
|
389
|
+
}
|
|
390
|
+
} else {
|
|
391
|
+
apiResult = {
|
|
392
|
+
success: false,
|
|
393
|
+
error: `Health check failed: ${response.status}`,
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
} catch (error) {
|
|
397
|
+
apiResult = {
|
|
398
|
+
success: false,
|
|
399
|
+
error: `Health check failed: ${
|
|
400
|
+
error instanceof Error ? error.message : String(error)
|
|
401
|
+
}`,
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
} else {
|
|
405
|
+
apiResult = {
|
|
406
|
+
success: false,
|
|
407
|
+
error: `Failed to start API server: ${
|
|
408
|
+
startResult.stderr || "Unknown error"
|
|
409
|
+
}`,
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
} catch (error) {
|
|
413
|
+
apiResult = {
|
|
414
|
+
success: false,
|
|
415
|
+
error: error instanceof Error ? error.message : String(error),
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
if (!apiResult.success) {
|
|
420
|
+
console.warn(
|
|
421
|
+
chalk.yellow("ā ļø Failed to start API server:", apiResult.error)
|
|
422
|
+
);
|
|
423
|
+
}
|
|
424
|
+
|
|
337
425
|
// Register the running validator
|
|
338
426
|
const runningValidator: RunningValidator = {
|
|
339
427
|
id: validatorId,
|
|
@@ -346,6 +434,11 @@ export async function startCommand(debug: boolean = false): Promise<void> {
|
|
|
346
434
|
configPath: configManager.getConfigPath() || "./sf.config.json",
|
|
347
435
|
startTime: new Date(),
|
|
348
436
|
status: "running",
|
|
437
|
+
apiServerPort: apiResult.success ? apiServerPort : undefined,
|
|
438
|
+
apiServerUrl: apiResult.success
|
|
439
|
+
? `http://127.0.0.1:${apiServerPort}`
|
|
440
|
+
: undefined,
|
|
441
|
+
apiServerPid: apiResult.success ? apiServerPid : undefined,
|
|
349
442
|
};
|
|
350
443
|
|
|
351
444
|
processRegistry.register(runningValidator);
|
|
@@ -363,6 +456,11 @@ export async function startCommand(debug: boolean = false): Promise<void> {
|
|
|
363
456
|
`š° Faucet URL: http://127.0.0.1:${config.localnet.faucetPort}`
|
|
364
457
|
)
|
|
365
458
|
);
|
|
459
|
+
if (apiResult.success) {
|
|
460
|
+
console.log(
|
|
461
|
+
chalk.cyan(`š API Server: http://127.0.0.1:${apiServerPort}/api`)
|
|
462
|
+
);
|
|
463
|
+
}
|
|
366
464
|
|
|
367
465
|
// Airdrop SOL to mint authority if tokens were cloned
|
|
368
466
|
if (clonedTokens.length > 0) {
|
|
@@ -464,6 +562,34 @@ export async function startCommand(debug: boolean = false): Promise<void> {
|
|
|
464
562
|
console.log(
|
|
465
563
|
chalk.gray(" - Run `solforge stop --all` to stop all validators")
|
|
466
564
|
);
|
|
565
|
+
if (apiResult.success) {
|
|
566
|
+
console.log(chalk.blue("\nš API Endpoints:"));
|
|
567
|
+
console.log(
|
|
568
|
+
chalk.gray(
|
|
569
|
+
` - GET http://127.0.0.1:${apiServerPort}/api/tokens - List cloned tokens`
|
|
570
|
+
)
|
|
571
|
+
);
|
|
572
|
+
console.log(
|
|
573
|
+
chalk.gray(
|
|
574
|
+
` - GET http://127.0.0.1:${apiServerPort}/api/programs - List cloned programs`
|
|
575
|
+
)
|
|
576
|
+
);
|
|
577
|
+
console.log(
|
|
578
|
+
chalk.gray(
|
|
579
|
+
` - POST http://127.0.0.1:${apiServerPort}/api/tokens/{symbol}/mint - Mint tokens`
|
|
580
|
+
)
|
|
581
|
+
);
|
|
582
|
+
console.log(
|
|
583
|
+
chalk.gray(
|
|
584
|
+
` - POST http://127.0.0.1:${apiServerPort}/api/airdrop - Airdrop SOL`
|
|
585
|
+
)
|
|
586
|
+
);
|
|
587
|
+
console.log(
|
|
588
|
+
chalk.gray(
|
|
589
|
+
` - GET http://127.0.0.1:${apiServerPort}/api/wallet/{address}/balances - Get balances`
|
|
590
|
+
)
|
|
591
|
+
);
|
|
592
|
+
}
|
|
467
593
|
} catch (error) {
|
|
468
594
|
spinner.fail("Failed to start validator");
|
|
469
595
|
console.error(chalk.red("ā Unexpected error:"));
|