solforge 0.1.7 → 0.2.1
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 +367 -393
- package/docs/API.md +379 -0
- package/docs/CONFIGURATION.md +407 -0
- package/docs/bun-single-file-executable.md +585 -0
- package/docs/cli-plan.md +154 -0
- package/docs/data-indexing-plan.md +214 -0
- package/docs/gui-roadmap.md +202 -0
- package/package.json +38 -51
- package/server/index.ts +5 -0
- package/server/lib/base58.ts +33 -0
- package/server/lib/faucet.ts +110 -0
- package/server/lib/spl-token.ts +57 -0
- package/server/methods/TEMPLATE.md +117 -0
- package/server/methods/account/get-account-info.ts +90 -0
- package/server/methods/account/get-balance.ts +27 -0
- package/server/methods/account/get-multiple-accounts.ts +83 -0
- package/server/methods/account/get-parsed-account-info.ts +21 -0
- package/server/methods/account/index.ts +12 -0
- package/server/methods/account/parsers/index.ts +52 -0
- package/server/methods/account/parsers/loader-upgradeable.ts +66 -0
- package/server/methods/account/parsers/spl-token.ts +237 -0
- package/server/methods/account/parsers/system.ts +4 -0
- package/server/methods/account/request-airdrop.ts +219 -0
- package/server/methods/admin/adopt-mint-authority.ts +94 -0
- package/server/methods/admin/clone-program-accounts.ts +55 -0
- package/server/methods/admin/clone-program.ts +152 -0
- package/server/methods/admin/clone-token-accounts.ts +117 -0
- package/server/methods/admin/clone-token-mint.ts +82 -0
- package/server/methods/admin/create-mint.ts +114 -0
- package/server/methods/admin/create-token-account.ts +137 -0
- package/server/methods/admin/helpers.ts +70 -0
- package/server/methods/admin/index.ts +10 -0
- package/server/methods/admin/list-mints.ts +21 -0
- package/server/methods/admin/load-program.ts +52 -0
- package/server/methods/admin/mint-to.ts +278 -0
- package/server/methods/block/get-block-height.ts +5 -0
- package/server/methods/block/get-block.ts +35 -0
- package/server/methods/block/get-blocks-with-limit.ts +23 -0
- package/server/methods/block/get-latest-blockhash.ts +12 -0
- package/server/methods/block/get-slot.ts +5 -0
- package/server/methods/block/index.ts +6 -0
- package/server/methods/block/is-blockhash-valid.ts +23 -0
- package/server/methods/epoch/get-cluster-nodes.ts +17 -0
- package/server/methods/epoch/get-epoch-info.ts +16 -0
- package/server/methods/epoch/get-epoch-schedule.ts +15 -0
- package/server/methods/epoch/get-highest-snapshot-slot.ts +9 -0
- package/server/methods/epoch/get-leader-schedule.ts +8 -0
- package/server/methods/epoch/get-max-retransmit-slot.ts +9 -0
- package/server/methods/epoch/get-max-shred-insert-slot.ts +9 -0
- package/server/methods/epoch/get-slot-leader.ts +6 -0
- package/server/methods/epoch/get-slot-leaders.ts +9 -0
- package/server/methods/epoch/get-stake-activation.ts +9 -0
- package/server/methods/epoch/get-stake-minimum-delegation.ts +9 -0
- package/server/methods/epoch/get-vote-accounts.ts +19 -0
- package/server/methods/epoch/index.ts +13 -0
- package/server/methods/epoch/minimum-ledger-slot.ts +5 -0
- package/server/methods/fee/get-fee-calculator-for-blockhash.ts +12 -0
- package/server/methods/fee/get-fee-for-message.ts +8 -0
- package/server/methods/fee/get-fee-rate-governor.ts +16 -0
- package/server/methods/fee/get-fees.ts +14 -0
- package/server/methods/fee/get-recent-prioritization-fees.ts +22 -0
- package/server/methods/fee/index.ts +5 -0
- package/server/methods/get-address-lookup-table.ts +31 -0
- package/server/methods/index.ts +265 -0
- package/server/methods/performance/get-recent-performance-samples.ts +25 -0
- package/server/methods/performance/get-transaction-count.ts +5 -0
- package/server/methods/performance/index.ts +2 -0
- package/server/methods/program/get-block-commitment.ts +9 -0
- package/server/methods/program/get-block-production.ts +14 -0
- package/server/methods/program/get-block-time.ts +21 -0
- package/server/methods/program/get-blocks.ts +11 -0
- package/server/methods/program/get-first-available-block.ts +9 -0
- package/server/methods/program/get-genesis-hash.ts +6 -0
- package/server/methods/program/get-identity.ts +6 -0
- package/server/methods/program/get-inflation-governor.ts +15 -0
- package/server/methods/program/get-inflation-rate.ts +10 -0
- package/server/methods/program/get-inflation-reward.ts +12 -0
- package/server/methods/program/get-largest-accounts.ts +8 -0
- package/server/methods/program/get-parsed-program-accounts.ts +12 -0
- package/server/methods/program/get-parsed-token-accounts-by-delegate.ts +12 -0
- package/server/methods/program/get-parsed-token-accounts-by-owner.ts +12 -0
- package/server/methods/program/get-program-accounts.ts +221 -0
- package/server/methods/program/get-supply.ts +13 -0
- package/server/methods/program/get-token-account-balance.ts +64 -0
- package/server/methods/program/get-token-accounts-by-delegate.ts +81 -0
- package/server/methods/program/get-token-accounts-by-owner.ts +390 -0
- package/server/methods/program/get-token-largest-accounts.ts +80 -0
- package/server/methods/program/get-token-supply.ts +38 -0
- package/server/methods/program/index.ts +21 -0
- package/server/methods/solforge/index.ts +155 -0
- package/server/methods/system/get-health.ts +5 -0
- package/server/methods/system/get-minimum-balance-for-rent-exemption.ts +13 -0
- package/server/methods/system/get-version.ts +9 -0
- package/server/methods/system/index.ts +3 -0
- package/server/methods/transaction/get-confirmed-transaction.ts +11 -0
- package/server/methods/transaction/get-parsed-transaction.ts +21 -0
- package/server/methods/transaction/get-signature-statuses.ts +72 -0
- package/server/methods/transaction/get-signatures-for-address.ts +45 -0
- package/server/methods/transaction/get-transaction.ts +428 -0
- package/server/methods/transaction/index.ts +7 -0
- package/server/methods/transaction/send-transaction.ts +232 -0
- package/server/methods/transaction/simulate-transaction.ts +56 -0
- package/server/rpc-server.ts +474 -0
- package/server/types.ts +74 -0
- package/server/ws-server.ts +171 -0
- package/src/cli/bootstrap.ts +67 -0
- package/src/cli/commands/airdrop.ts +37 -0
- package/src/cli/commands/config.ts +39 -0
- package/src/cli/commands/mint.ts +187 -0
- package/src/cli/commands/program-clone.ts +124 -0
- package/src/cli/commands/program-load.ts +64 -0
- package/src/cli/commands/rpc-start.ts +46 -0
- package/src/cli/commands/token-adopt-authority.ts +37 -0
- package/src/cli/commands/token-clone.ts +113 -0
- package/src/cli/commands/token-create.ts +81 -0
- package/src/cli/main.ts +130 -0
- package/src/cli/run-solforge.ts +98 -0
- package/src/cli/setup-utils.ts +54 -0
- package/src/cli/setup-wizard.ts +256 -0
- package/src/cli/utils/args.ts +15 -0
- package/src/config/index.ts +130 -0
- package/src/db/index.ts +83 -0
- package/src/db/schema/accounts.ts +23 -0
- package/src/db/schema/address-signatures.ts +31 -0
- package/src/db/schema/index.ts +5 -0
- package/src/db/schema/meta-kv.ts +9 -0
- package/src/db/schema/transactions.ts +29 -0
- package/src/db/schema/tx-accounts.ts +33 -0
- package/src/db/tx-store.ts +229 -0
- package/src/gui/public/app.css +1 -0
- package/src/gui/public/build/main.css +1 -0
- package/src/gui/public/build/main.js +303 -0
- package/src/gui/public/build/main.js.txt +231 -0
- package/src/gui/public/index.html +19 -0
- package/src/gui/server.ts +297 -0
- package/src/gui/src/api.ts +127 -0
- package/src/gui/src/app.tsx +390 -0
- package/src/gui/src/components/airdrop-mint-form.tsx +216 -0
- package/src/gui/src/components/clone-program-modal.tsx +183 -0
- package/src/gui/src/components/clone-token-modal.tsx +211 -0
- package/src/gui/src/components/modal.tsx +127 -0
- package/src/gui/src/components/programs-panel.tsx +112 -0
- package/src/gui/src/components/status-panel.tsx +122 -0
- package/src/gui/src/components/tokens-panel.tsx +116 -0
- package/src/gui/src/hooks/use-interval.ts +17 -0
- package/src/gui/src/index.css +529 -0
- package/src/gui/src/main.tsx +17 -0
- package/src/migrations-bundled.ts +17 -0
- package/src/rpc/start.ts +44 -0
- package/scripts/postinstall.cjs +0 -103
- package/tsconfig.json +0 -28
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
|
6
|
+
<meta name="color-scheme" content="dark" />
|
|
7
|
+
<meta name="theme-color" content="#0a0a0f" />
|
|
8
|
+
<title>SolForge - Solana Development Suite</title>
|
|
9
|
+
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
10
|
+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
11
|
+
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&family=JetBrains+Mono:wght@400;500;600;700&display=swap" rel="stylesheet">
|
|
12
|
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
|
|
13
|
+
</head>
|
|
14
|
+
<body>
|
|
15
|
+
<link rel="stylesheet" href="./app.css" />
|
|
16
|
+
<div id="root"></div>
|
|
17
|
+
<script defer src="./build/main.js"></script>
|
|
18
|
+
</body>
|
|
19
|
+
</html>
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import { serve } from "bun";
|
|
2
|
+
import type { LiteSVMRpcServer } from "../../server/rpc-server";
|
|
3
|
+
import type { JsonRpcResponse } from "../../server/types";
|
|
4
|
+
import { readConfig, writeConfig } from "../config";
|
|
5
|
+
import indexHtml from "./public/index.html";
|
|
6
|
+
import { file } from "bun";
|
|
7
|
+
// Embed built GUI assets as files so the compiled binary can stream them
|
|
8
|
+
import appCssFile from "./public/app.css" with { type: "file" };
|
|
9
|
+
import mainJsFile from "./public/build/main.js" with { type: "file" };
|
|
10
|
+
import bundledCssFile from "./public/build/main.css" with { type: "file" };
|
|
11
|
+
|
|
12
|
+
type GuiStartOptions = {
|
|
13
|
+
port?: number;
|
|
14
|
+
host?: string;
|
|
15
|
+
rpcPort?: number;
|
|
16
|
+
rpcServer?: LiteSVMRpcServer;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const LAMPORTS_PER_SOL = 1_000_000_000n;
|
|
20
|
+
const CORS = {
|
|
21
|
+
"Access-Control-Allow-Origin": "*",
|
|
22
|
+
"Access-Control-Allow-Headers": "content-type",
|
|
23
|
+
"Access-Control-Allow-Methods": "GET,POST,OPTIONS",
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
class HttpError extends Error {
|
|
27
|
+
constructor(
|
|
28
|
+
public status: number,
|
|
29
|
+
message: string,
|
|
30
|
+
public details?: unknown,
|
|
31
|
+
) {
|
|
32
|
+
super(message);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const json = (data: unknown, status = 200) =>
|
|
37
|
+
new Response(JSON.stringify(data), {
|
|
38
|
+
status,
|
|
39
|
+
headers: { ...CORS, "Content-Type": "application/json" },
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const text = (value: string, status = 200) =>
|
|
43
|
+
new Response(value, {
|
|
44
|
+
status,
|
|
45
|
+
headers: { ...CORS, "Content-Type": "text/plain" },
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const okOptions = () => new Response(null, { status: 204, headers: CORS });
|
|
49
|
+
const css = (fpath: string) =>
|
|
50
|
+
new Response(file(fpath), {
|
|
51
|
+
headers: { ...CORS, "Content-Type": "text/css" },
|
|
52
|
+
});
|
|
53
|
+
const js = (fpath: string) =>
|
|
54
|
+
new Response(file(fpath), {
|
|
55
|
+
headers: { ...CORS, "Content-Type": "application/javascript" },
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const handleError = (error: unknown) => {
|
|
59
|
+
if (error instanceof HttpError)
|
|
60
|
+
return json({ error: error.message, details: error.details }, error.status);
|
|
61
|
+
console.error("[gui] API error", error);
|
|
62
|
+
return json({ error: "Internal server error" }, 500);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const wrap =
|
|
66
|
+
(handler: (req: Request) => Promise<unknown> | unknown) =>
|
|
67
|
+
async (req: Request) => {
|
|
68
|
+
try {
|
|
69
|
+
const result = await handler(req);
|
|
70
|
+
return result instanceof Response ? result : json(result);
|
|
71
|
+
} catch (error) {
|
|
72
|
+
return handleError(error);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const readJson = async <T extends Record<string, unknown>>(
|
|
77
|
+
req: Request,
|
|
78
|
+
): Promise<T> => {
|
|
79
|
+
try {
|
|
80
|
+
return (await req.json()) as T;
|
|
81
|
+
} catch (error) {
|
|
82
|
+
throw new HttpError(400, "Invalid JSON body", { cause: error });
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const parseLamports = (payload: {
|
|
87
|
+
lamports?: string | number;
|
|
88
|
+
sol?: string | number;
|
|
89
|
+
}) => {
|
|
90
|
+
if (payload.lamports != null) {
|
|
91
|
+
const lamports = BigInt(payload.lamports);
|
|
92
|
+
if (lamports <= 0n) throw new HttpError(400, "lamports must be positive");
|
|
93
|
+
return lamports;
|
|
94
|
+
}
|
|
95
|
+
if (payload.sol != null) {
|
|
96
|
+
const sol = Number(payload.sol);
|
|
97
|
+
if (!Number.isFinite(sol) || sol <= 0)
|
|
98
|
+
throw new HttpError(400, "sol must be positive");
|
|
99
|
+
return BigInt(Math.floor(sol * Number(LAMPORTS_PER_SOL)));
|
|
100
|
+
}
|
|
101
|
+
throw new HttpError(400, "lamports or sol is required");
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
export function startGuiServer(opts: GuiStartOptions = {}) {
|
|
105
|
+
const host = opts.host ?? "127.0.0.1";
|
|
106
|
+
const port = Number(opts.port ?? 42069);
|
|
107
|
+
const rpcPort = Number(opts.rpcPort ?? 8899);
|
|
108
|
+
const rpcServer = opts.rpcServer;
|
|
109
|
+
const rpcUrl = `http://${host}:${rpcPort}`;
|
|
110
|
+
|
|
111
|
+
const callRpc = async (method: string, params: any[] = []) => {
|
|
112
|
+
if (!rpcServer) throw new HttpError(503, "RPC server not available");
|
|
113
|
+
const response: JsonRpcResponse = await rpcServer.handleRequest({
|
|
114
|
+
jsonrpc: "2.0",
|
|
115
|
+
id: `gui-${Date.now()}`,
|
|
116
|
+
method,
|
|
117
|
+
params,
|
|
118
|
+
});
|
|
119
|
+
if (response.error)
|
|
120
|
+
throw new HttpError(
|
|
121
|
+
400,
|
|
122
|
+
response.error.message ?? "RPC error",
|
|
123
|
+
response.error,
|
|
124
|
+
);
|
|
125
|
+
return response.result;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
async function recordTokenClone(mint: string) {
|
|
129
|
+
try {
|
|
130
|
+
const cfg = await readConfig();
|
|
131
|
+
const set = new Set(cfg.clone.tokens || []);
|
|
132
|
+
if (!set.has(mint)) {
|
|
133
|
+
set.add(mint);
|
|
134
|
+
cfg.clone.tokens = Array.from(set);
|
|
135
|
+
await writeConfig(cfg);
|
|
136
|
+
}
|
|
137
|
+
} catch (error) {
|
|
138
|
+
console.warn("[gui] failed to update config for token clone:", error);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
async function recordProgramClone(programId: string) {
|
|
143
|
+
try {
|
|
144
|
+
const cfg = await readConfig();
|
|
145
|
+
const set = new Set(cfg.clone.programs || []);
|
|
146
|
+
if (!set.has(programId)) {
|
|
147
|
+
set.add(programId);
|
|
148
|
+
cfg.clone.programs = Array.from(set);
|
|
149
|
+
await writeConfig(cfg);
|
|
150
|
+
}
|
|
151
|
+
} catch (error) {
|
|
152
|
+
console.warn("[gui] failed to update config for program clone:", error);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const routes = {
|
|
157
|
+
"/": indexHtml,
|
|
158
|
+
"/app.css": { GET: () => css(appCssFile) },
|
|
159
|
+
"/build/main.css": { GET: () => css(bundledCssFile) },
|
|
160
|
+
"/build/main.js": { GET: () => js(mainJsFile) },
|
|
161
|
+
"/health": { GET: () => text("ok") },
|
|
162
|
+
"/api/config": { GET: () => json({ rpcUrl }), OPTIONS: okOptions },
|
|
163
|
+
"/api/status": {
|
|
164
|
+
GET: wrap(() => callRpc("solforgeGetStatus")),
|
|
165
|
+
OPTIONS: okOptions,
|
|
166
|
+
},
|
|
167
|
+
"/api/programs": {
|
|
168
|
+
GET: wrap(() => callRpc("solforgeListPrograms")),
|
|
169
|
+
OPTIONS: okOptions,
|
|
170
|
+
},
|
|
171
|
+
"/api/tokens": {
|
|
172
|
+
GET: wrap(() => callRpc("solforgeListTokensDetailed")),
|
|
173
|
+
OPTIONS: okOptions,
|
|
174
|
+
},
|
|
175
|
+
"/api/airdrop": {
|
|
176
|
+
POST: wrap(async (req) => {
|
|
177
|
+
const body = await readJson<{
|
|
178
|
+
address?: string;
|
|
179
|
+
lamports?: string | number;
|
|
180
|
+
sol?: string | number;
|
|
181
|
+
}>(req);
|
|
182
|
+
const address =
|
|
183
|
+
typeof body.address === "string" ? body.address.trim() : "";
|
|
184
|
+
if (!address) throw new HttpError(400, "address is required");
|
|
185
|
+
const lamports = parseLamports(body);
|
|
186
|
+
const signature = await callRpc("requestAirdrop", [
|
|
187
|
+
address,
|
|
188
|
+
Number(lamports),
|
|
189
|
+
]);
|
|
190
|
+
return { ok: true, signature };
|
|
191
|
+
}),
|
|
192
|
+
OPTIONS: okOptions,
|
|
193
|
+
},
|
|
194
|
+
"/api/mint": {
|
|
195
|
+
POST: wrap(async (req) => {
|
|
196
|
+
const body = await readJson<{
|
|
197
|
+
mint?: string;
|
|
198
|
+
owner?: string;
|
|
199
|
+
amountRaw?: string;
|
|
200
|
+
}>(req);
|
|
201
|
+
const mint = typeof body.mint === "string" ? body.mint.trim() : "";
|
|
202
|
+
const owner = typeof body.owner === "string" ? body.owner.trim() : "";
|
|
203
|
+
const amountRaw =
|
|
204
|
+
typeof body.amountRaw === "string" ? body.amountRaw.trim() : "";
|
|
205
|
+
if (!mint || !owner || !amountRaw)
|
|
206
|
+
throw new HttpError(400, "mint, owner and amountRaw are required");
|
|
207
|
+
return callRpc("solforgeMintTo", [mint, owner, amountRaw]);
|
|
208
|
+
}),
|
|
209
|
+
OPTIONS: okOptions,
|
|
210
|
+
},
|
|
211
|
+
"/api/clone/program": {
|
|
212
|
+
POST: wrap(async (req) => {
|
|
213
|
+
const body = await readJson<{
|
|
214
|
+
programId?: string;
|
|
215
|
+
endpoint?: string;
|
|
216
|
+
withAccounts?: boolean;
|
|
217
|
+
accountsLimit?: number;
|
|
218
|
+
}>(req);
|
|
219
|
+
const programId =
|
|
220
|
+
typeof body.programId === "string" ? body.programId.trim() : "";
|
|
221
|
+
if (!programId) throw new HttpError(400, "programId is required");
|
|
222
|
+
const endpoint =
|
|
223
|
+
typeof body.endpoint === "string" && body.endpoint.trim()
|
|
224
|
+
? body.endpoint.trim()
|
|
225
|
+
: undefined;
|
|
226
|
+
const withAccounts = body.withAccounts === true;
|
|
227
|
+
const accountsLimit =
|
|
228
|
+
typeof body.accountsLimit === "number"
|
|
229
|
+
? body.accountsLimit
|
|
230
|
+
: undefined;
|
|
231
|
+
const res = await callRpc("solforgeAdminCloneProgram", [
|
|
232
|
+
programId,
|
|
233
|
+
{ endpoint, withAccounts, accountsLimit },
|
|
234
|
+
]);
|
|
235
|
+
await recordProgramClone(programId);
|
|
236
|
+
return res;
|
|
237
|
+
}),
|
|
238
|
+
OPTIONS: okOptions,
|
|
239
|
+
},
|
|
240
|
+
"/api/clone/token": {
|
|
241
|
+
POST: wrap(async (req) => {
|
|
242
|
+
const body = await readJson<{
|
|
243
|
+
mint?: string;
|
|
244
|
+
endpoint?: string;
|
|
245
|
+
cloneAccounts?: boolean;
|
|
246
|
+
holders?: number;
|
|
247
|
+
allAccounts?: boolean;
|
|
248
|
+
}>(req);
|
|
249
|
+
const mint = typeof body.mint === "string" ? body.mint.trim() : "";
|
|
250
|
+
if (!mint) throw new HttpError(400, "mint is required");
|
|
251
|
+
const endpoint =
|
|
252
|
+
typeof body.endpoint === "string" && body.endpoint.trim()
|
|
253
|
+
? body.endpoint.trim()
|
|
254
|
+
: undefined;
|
|
255
|
+
const cloneAccounts = body.cloneAccounts === true;
|
|
256
|
+
const holders =
|
|
257
|
+
typeof body.holders === "number" ? body.holders : undefined;
|
|
258
|
+
const allAccounts = body.allAccounts === true;
|
|
259
|
+
const mintResult = await callRpc("solforgeAdminCloneTokenMint", [
|
|
260
|
+
mint,
|
|
261
|
+
{ endpoint },
|
|
262
|
+
]);
|
|
263
|
+
// Ensure local faucet is the mint authority so GUI minting works out of the box
|
|
264
|
+
try {
|
|
265
|
+
await callRpc("solforgeAdoptMintAuthority", [mint]);
|
|
266
|
+
} catch (e) {
|
|
267
|
+
console.warn("[gui] adopt mint authority failed (continuing)", e);
|
|
268
|
+
}
|
|
269
|
+
let accountsResult: unknown = null;
|
|
270
|
+
if (cloneAccounts) {
|
|
271
|
+
accountsResult = await callRpc("solforgeAdminCloneTokenAccounts", [
|
|
272
|
+
mint,
|
|
273
|
+
{ endpoint, holders, allAccounts },
|
|
274
|
+
]);
|
|
275
|
+
}
|
|
276
|
+
await recordTokenClone(mint);
|
|
277
|
+
return {
|
|
278
|
+
mint: mintResult,
|
|
279
|
+
adoptedAuthority: true,
|
|
280
|
+
accounts: accountsResult,
|
|
281
|
+
};
|
|
282
|
+
}),
|
|
283
|
+
OPTIONS: okOptions,
|
|
284
|
+
},
|
|
285
|
+
} as const;
|
|
286
|
+
|
|
287
|
+
const server = serve({
|
|
288
|
+
port,
|
|
289
|
+
hostname: host,
|
|
290
|
+
routes,
|
|
291
|
+
development: false,
|
|
292
|
+
});
|
|
293
|
+
console.log(`🖥️ Solforge GUI available at http://${host}:${server.port}`);
|
|
294
|
+
return { server, port: server.port };
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
export type { GuiStartOptions };
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
export interface ApiConfig {
|
|
2
|
+
rpcUrl: string;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export interface ApiStatus {
|
|
6
|
+
slot: number;
|
|
7
|
+
slotBigint: string;
|
|
8
|
+
blockHeight: number;
|
|
9
|
+
blockHeightBigint: string;
|
|
10
|
+
txCount: number;
|
|
11
|
+
txCountBigint: string;
|
|
12
|
+
latestBlockhash: string;
|
|
13
|
+
faucet: {
|
|
14
|
+
address: string;
|
|
15
|
+
lamports: string;
|
|
16
|
+
sol: number;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface ProgramSummary {
|
|
21
|
+
programId: string;
|
|
22
|
+
owner: string;
|
|
23
|
+
executable: boolean;
|
|
24
|
+
dataLen: number;
|
|
25
|
+
lamports: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface TokenSummary {
|
|
29
|
+
mint: string;
|
|
30
|
+
supply: string;
|
|
31
|
+
decimals: number;
|
|
32
|
+
uiAmount: number;
|
|
33
|
+
uiAmountString: string;
|
|
34
|
+
mintAuthority: string | null;
|
|
35
|
+
isInitialized: boolean;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface AirdropPayload {
|
|
39
|
+
address: string;
|
|
40
|
+
lamports?: string | number;
|
|
41
|
+
sol?: string | number;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface MintPayload {
|
|
45
|
+
mint: string;
|
|
46
|
+
owner: string;
|
|
47
|
+
amountRaw: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface CloneProgramPayload {
|
|
51
|
+
programId: string;
|
|
52
|
+
endpoint?: string;
|
|
53
|
+
withAccounts?: boolean;
|
|
54
|
+
accountsLimit?: number;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface CloneTokenPayload {
|
|
58
|
+
mint: string;
|
|
59
|
+
endpoint?: string;
|
|
60
|
+
cloneAccounts?: boolean;
|
|
61
|
+
holders?: number;
|
|
62
|
+
allAccounts?: boolean;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
interface ApiError {
|
|
66
|
+
error?: string;
|
|
67
|
+
details?: unknown;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async function request<T>(path: string, init: RequestInit = {}): Promise<T> {
|
|
71
|
+
const headers = new Headers(init.headers ?? {});
|
|
72
|
+
if (!headers.has("content-type") && init.body)
|
|
73
|
+
headers.set("content-type", "application/json");
|
|
74
|
+
const response = await fetch(path, { ...init, headers });
|
|
75
|
+
let payload: any = null;
|
|
76
|
+
const text = await response.text();
|
|
77
|
+
if (text) {
|
|
78
|
+
try {
|
|
79
|
+
payload = JSON.parse(text);
|
|
80
|
+
} catch (error) {
|
|
81
|
+
throw new Error(
|
|
82
|
+
`Failed to parse response from ${path}: ${String(error)}`,
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (!response.ok) {
|
|
87
|
+
const errPayload = payload as ApiError | null;
|
|
88
|
+
const message =
|
|
89
|
+
errPayload?.error || response.statusText || "Request failed";
|
|
90
|
+
throw new Error(message);
|
|
91
|
+
}
|
|
92
|
+
return payload as T;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export const fetchConfig = () => request<ApiConfig>("/api/config");
|
|
96
|
+
export const fetchStatus = () => request<ApiStatus>("/api/status");
|
|
97
|
+
export const fetchPrograms = () => request<ProgramSummary[]>("/api/programs");
|
|
98
|
+
export const fetchTokens = () => request<TokenSummary[]>("/api/tokens");
|
|
99
|
+
export const submitAirdrop = (body: AirdropPayload) =>
|
|
100
|
+
request<{ ok: boolean; signature?: string }>("/api/airdrop", {
|
|
101
|
+
method: "POST",
|
|
102
|
+
body: JSON.stringify(body),
|
|
103
|
+
});
|
|
104
|
+
export const submitMint = (body: MintPayload) =>
|
|
105
|
+
request<
|
|
106
|
+
| {
|
|
107
|
+
ok: boolean;
|
|
108
|
+
signature?: string;
|
|
109
|
+
mint: string;
|
|
110
|
+
owner: string;
|
|
111
|
+
amount: string;
|
|
112
|
+
}
|
|
113
|
+
| Record<string, unknown>
|
|
114
|
+
>("/api/mint", {
|
|
115
|
+
method: "POST",
|
|
116
|
+
body: JSON.stringify(body),
|
|
117
|
+
});
|
|
118
|
+
export const cloneProgram = (body: CloneProgramPayload) =>
|
|
119
|
+
request<Record<string, unknown>>("/api/clone/program", {
|
|
120
|
+
method: "POST",
|
|
121
|
+
body: JSON.stringify(body),
|
|
122
|
+
});
|
|
123
|
+
export const cloneToken = (body: CloneTokenPayload) =>
|
|
124
|
+
request<Record<string, unknown>>("/api/clone/token", {
|
|
125
|
+
method: "POST",
|
|
126
|
+
body: JSON.stringify(body),
|
|
127
|
+
});
|