solforge 0.2.12 → 0.2.14
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/package.json +1 -5
- package/start.cjs +19 -23
- package/docs/API.md +0 -379
- package/docs/CONFIGURATION.md +0 -407
- package/docs/bun-single-file-executable.md +0 -585
- package/docs/cli-plan.md +0 -154
- package/docs/data-indexing-plan.md +0 -214
- package/docs/gui-roadmap.md +0 -202
- package/scripts/decode-b58.ts +0 -10
- package/scripts/install.sh +0 -112
- package/server/index.ts +0 -5
- package/server/lib/base58.ts +0 -33
- package/server/lib/faucet.ts +0 -110
- package/server/lib/instruction-parser.ts +0 -328
- package/server/lib/parsers/spl-associated-token-account.ts +0 -50
- package/server/lib/parsers/spl-token.ts +0 -340
- package/server/lib/spl-token.ts +0 -57
- package/server/methods/TEMPLATE.md +0 -117
- package/server/methods/account/get-account-info.ts +0 -86
- package/server/methods/account/get-balance.ts +0 -23
- package/server/methods/account/get-multiple-accounts.ts +0 -84
- package/server/methods/account/get-parsed-account-info.ts +0 -17
- package/server/methods/account/index.ts +0 -12
- package/server/methods/account/parsers/index.ts +0 -52
- package/server/methods/account/parsers/loader-upgradeable.ts +0 -79
- package/server/methods/account/parsers/spl-token.ts +0 -256
- package/server/methods/account/parsers/system.ts +0 -4
- package/server/methods/account/request-airdrop.ts +0 -271
- package/server/methods/admin/adopt-mint-authority.ts +0 -94
- package/server/methods/admin/clone-program-accounts.ts +0 -55
- package/server/methods/admin/clone-program.ts +0 -152
- package/server/methods/admin/clone-token-accounts.ts +0 -117
- package/server/methods/admin/clone-token-mint.ts +0 -82
- package/server/methods/admin/create-mint.ts +0 -114
- package/server/methods/admin/create-token-account.ts +0 -137
- package/server/methods/admin/helpers.ts +0 -70
- package/server/methods/admin/index.ts +0 -10
- package/server/methods/admin/list-mints.ts +0 -21
- package/server/methods/admin/load-program.ts +0 -52
- package/server/methods/admin/mint-to.ts +0 -266
- package/server/methods/block/get-block-height.ts +0 -5
- package/server/methods/block/get-block.ts +0 -31
- package/server/methods/block/get-blocks-with-limit.ts +0 -19
- package/server/methods/block/get-latest-blockhash.ts +0 -12
- package/server/methods/block/get-slot.ts +0 -5
- package/server/methods/block/index.ts +0 -6
- package/server/methods/block/is-blockhash-valid.ts +0 -19
- package/server/methods/epoch/get-cluster-nodes.ts +0 -17
- package/server/methods/epoch/get-epoch-info.ts +0 -16
- package/server/methods/epoch/get-epoch-schedule.ts +0 -15
- package/server/methods/epoch/get-highest-snapshot-slot.ts +0 -9
- package/server/methods/epoch/get-leader-schedule.ts +0 -8
- package/server/methods/epoch/get-max-retransmit-slot.ts +0 -9
- package/server/methods/epoch/get-max-shred-insert-slot.ts +0 -9
- package/server/methods/epoch/get-slot-leader.ts +0 -6
- package/server/methods/epoch/get-slot-leaders.ts +0 -9
- package/server/methods/epoch/get-stake-activation.ts +0 -9
- package/server/methods/epoch/get-stake-minimum-delegation.ts +0 -9
- package/server/methods/epoch/get-vote-accounts.ts +0 -19
- package/server/methods/epoch/index.ts +0 -13
- package/server/methods/epoch/minimum-ledger-slot.ts +0 -5
- package/server/methods/fee/get-fee-calculator-for-blockhash.ts +0 -12
- package/server/methods/fee/get-fee-for-message.ts +0 -8
- package/server/methods/fee/get-fee-rate-governor.ts +0 -16
- package/server/methods/fee/get-fees.ts +0 -14
- package/server/methods/fee/get-recent-prioritization-fees.ts +0 -22
- package/server/methods/fee/index.ts +0 -5
- package/server/methods/get-address-lookup-table.ts +0 -27
- package/server/methods/index.ts +0 -265
- package/server/methods/performance/get-recent-performance-samples.ts +0 -25
- package/server/methods/performance/get-transaction-count.ts +0 -5
- package/server/methods/performance/index.ts +0 -2
- package/server/methods/program/get-block-commitment.ts +0 -9
- package/server/methods/program/get-block-production.ts +0 -14
- package/server/methods/program/get-block-time.ts +0 -21
- package/server/methods/program/get-blocks.ts +0 -11
- package/server/methods/program/get-first-available-block.ts +0 -9
- package/server/methods/program/get-genesis-hash.ts +0 -6
- package/server/methods/program/get-identity.ts +0 -6
- package/server/methods/program/get-inflation-governor.ts +0 -15
- package/server/methods/program/get-inflation-rate.ts +0 -10
- package/server/methods/program/get-inflation-reward.ts +0 -12
- package/server/methods/program/get-largest-accounts.ts +0 -8
- package/server/methods/program/get-parsed-program-accounts.ts +0 -12
- package/server/methods/program/get-parsed-token-accounts-by-delegate.ts +0 -12
- package/server/methods/program/get-parsed-token-accounts-by-owner.ts +0 -12
- package/server/methods/program/get-program-accounts.ts +0 -221
- package/server/methods/program/get-supply.ts +0 -13
- package/server/methods/program/get-token-account-balance.ts +0 -60
- package/server/methods/program/get-token-accounts-by-delegate.ts +0 -82
- package/server/methods/program/get-token-accounts-by-owner.ts +0 -416
- package/server/methods/program/get-token-largest-accounts.ts +0 -81
- package/server/methods/program/get-token-supply.ts +0 -39
- package/server/methods/program/index.ts +0 -21
- package/server/methods/solforge/index.ts +0 -158
- package/server/methods/system/get-health.ts +0 -5
- package/server/methods/system/get-minimum-balance-for-rent-exemption.ts +0 -13
- package/server/methods/system/get-version.ts +0 -9
- package/server/methods/system/index.ts +0 -3
- package/server/methods/transaction/get-confirmed-transaction.ts +0 -11
- package/server/methods/transaction/get-parsed-transaction.ts +0 -17
- package/server/methods/transaction/get-signature-statuses.ts +0 -79
- package/server/methods/transaction/get-signatures-for-address.ts +0 -41
- package/server/methods/transaction/get-transaction.ts +0 -639
- package/server/methods/transaction/index.ts +0 -7
- package/server/methods/transaction/inner-instructions.test.ts +0 -104
- package/server/methods/transaction/send-transaction.ts +0 -469
- package/server/methods/transaction/simulate-transaction.ts +0 -57
- package/server/rpc-server.ts +0 -521
- package/server/types.ts +0 -109
- package/server/ws-server.ts +0 -178
- package/src/api-server-entry.ts +0 -109
- package/src/cli/bootstrap.ts +0 -67
- package/src/cli/commands/airdrop.ts +0 -37
- package/src/cli/commands/config.ts +0 -39
- package/src/cli/commands/mint.ts +0 -187
- package/src/cli/commands/program-clone.ts +0 -122
- package/src/cli/commands/program-load.ts +0 -64
- package/src/cli/commands/rpc-start.ts +0 -49
- package/src/cli/commands/token-adopt-authority.ts +0 -37
- package/src/cli/commands/token-clone.ts +0 -112
- package/src/cli/commands/token-create.ts +0 -81
- package/src/cli/main.ts +0 -158
- package/src/cli/run-solforge.ts +0 -112
- package/src/cli/setup-utils.ts +0 -54
- package/src/cli/setup-wizard.ts +0 -258
- package/src/cli/utils/args.ts +0 -15
- package/src/commands/add-program.ts +0 -333
- package/src/commands/init.ts +0 -122
- package/src/commands/list.ts +0 -136
- package/src/commands/mint.ts +0 -287
- package/src/commands/start.ts +0 -881
- package/src/commands/status.ts +0 -99
- package/src/commands/stop.ts +0 -405
- package/src/config/index.ts +0 -146
- package/src/config/manager.ts +0 -157
- package/src/db/index.ts +0 -83
- package/src/db/schema/accounts.ts +0 -23
- package/src/db/schema/address-signatures.ts +0 -31
- package/src/db/schema/index.ts +0 -6
- package/src/db/schema/meta-kv.ts +0 -9
- package/src/db/schema/transactions.ts +0 -36
- package/src/db/schema/tx-account-states.ts +0 -23
- package/src/db/schema/tx-accounts.ts +0 -33
- package/src/db/tx-store.ts +0 -264
- package/src/gui/public/app.css +0 -1556
- package/src/gui/public/build/main.css +0 -1569
- package/src/gui/public/build/main.js +0 -303
- package/src/gui/public/build/main.js.txt +0 -231
- package/src/gui/public/index.html +0 -19
- package/src/gui/server.ts +0 -296
- package/src/gui/src/api.ts +0 -127
- package/src/gui/src/app.tsx +0 -441
- package/src/gui/src/components/airdrop-mint-form.tsx +0 -246
- package/src/gui/src/components/clone-program-modal.tsx +0 -202
- package/src/gui/src/components/clone-token-modal.tsx +0 -230
- package/src/gui/src/components/modal.tsx +0 -134
- package/src/gui/src/components/programs-panel.tsx +0 -124
- package/src/gui/src/components/status-panel.tsx +0 -136
- package/src/gui/src/components/tokens-panel.tsx +0 -122
- package/src/gui/src/hooks/use-interval.ts +0 -17
- package/src/gui/src/index.css +0 -557
- package/src/gui/src/main.tsx +0 -17
- package/src/index.ts +0 -216
- package/src/migrations-bundled.ts +0 -23
- package/src/rpc/start.ts +0 -44
- package/src/services/api-server.ts +0 -504
- package/src/services/port-manager.ts +0 -174
- package/src/services/process-registry.ts +0 -153
- package/src/services/program-cloner.ts +0 -317
- package/src/services/token-cloner.ts +0 -811
- package/src/services/validator.ts +0 -293
- package/src/types/config.ts +0 -110
- package/src/utils/shell.ts +0 -110
- package/src/utils/token-loader.ts +0 -115
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { RpcMethodHandler } from "../../types";
|
|
2
|
-
import { getAccountInfo } from "./get-account-info";
|
|
3
|
-
|
|
4
|
-
export const getParsedAccountInfo: RpcMethodHandler = async (
|
|
5
|
-
id,
|
|
6
|
-
params,
|
|
7
|
-
context,
|
|
8
|
-
) => {
|
|
9
|
-
const [pubkey, config] = params || [];
|
|
10
|
-
const cfg = { ...(config || {}), encoding: "jsonParsed" };
|
|
11
|
-
try {
|
|
12
|
-
return await getAccountInfo(id, [pubkey, cfg], context);
|
|
13
|
-
} catch (error: unknown) {
|
|
14
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
15
|
-
return context.createErrorResponse(id, -32603, "Internal error", message);
|
|
16
|
-
}
|
|
17
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Account-related RPC methods
|
|
3
|
-
*
|
|
4
|
-
* This module contains all account-related RPC methods.
|
|
5
|
-
* Each method is in its own file to maintain modularity.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
export { getAccountInfo } from "./get-account-info";
|
|
9
|
-
export { getBalance } from "./get-balance";
|
|
10
|
-
export { getMultipleAccounts } from "./get-multiple-accounts";
|
|
11
|
-
export { getParsedAccountInfo } from "./get-parsed-account-info";
|
|
12
|
-
export { requestAirdrop } from "./request-airdrop";
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { PublicKey } from "@solana/web3.js";
|
|
2
|
-
import type { RpcMethodContext } from "../../../server/types";
|
|
3
|
-
import { parseUpgradeableLoader } from "./loader-upgradeable";
|
|
4
|
-
import { parseSplTokenAccountOrMint } from "./spl-token";
|
|
5
|
-
import { parseSystemAccount } from "./system";
|
|
6
|
-
|
|
7
|
-
export type ParsedAccountData = {
|
|
8
|
-
program: string;
|
|
9
|
-
parsed: unknown; // match Solana RPC jsonParsed payloads
|
|
10
|
-
space: number;
|
|
11
|
-
} | null;
|
|
12
|
-
|
|
13
|
-
export function parseAccountJson(
|
|
14
|
-
pubkey: PublicKey,
|
|
15
|
-
account: {
|
|
16
|
-
owner: PublicKey | string;
|
|
17
|
-
data: Uint8Array | Buffer | number[];
|
|
18
|
-
lamports: bigint | number;
|
|
19
|
-
executable?: boolean;
|
|
20
|
-
rentEpoch?: bigint | number;
|
|
21
|
-
},
|
|
22
|
-
context: RpcMethodContext,
|
|
23
|
-
): ParsedAccountData {
|
|
24
|
-
const ownerStr =
|
|
25
|
-
typeof account.owner === "string"
|
|
26
|
-
? account.owner
|
|
27
|
-
: new PublicKey(account.owner).toBase58();
|
|
28
|
-
const ownerPk =
|
|
29
|
-
typeof account.owner === "string"
|
|
30
|
-
? new PublicKey(account.owner)
|
|
31
|
-
: (account.owner as PublicKey);
|
|
32
|
-
const dataBytes =
|
|
33
|
-
account.data instanceof Uint8Array
|
|
34
|
-
? account.data
|
|
35
|
-
: Buffer.from(account.data as ReadonlyArray<number>);
|
|
36
|
-
const space = dataBytes.length;
|
|
37
|
-
|
|
38
|
-
// 1) System program
|
|
39
|
-
const sys = parseSystemAccount(ownerStr, space);
|
|
40
|
-
if (sys) return sys;
|
|
41
|
-
|
|
42
|
-
// 2) SPL Token (v1) & Token-2022
|
|
43
|
-
const token = parseSplTokenAccountOrMint(pubkey, ownerPk, dataBytes, context);
|
|
44
|
-
if (token) return token;
|
|
45
|
-
|
|
46
|
-
// 3) BPF Upgradeable Loader
|
|
47
|
-
const loader = parseUpgradeableLoader(ownerStr, dataBytes, context);
|
|
48
|
-
if (loader) return loader;
|
|
49
|
-
|
|
50
|
-
// 4) Unknown
|
|
51
|
-
return { program: "unknown", parsed: null, space };
|
|
52
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { PublicKey } from "@solana/web3.js";
|
|
2
|
-
import type { RpcMethodContext } from "../../../server/types";
|
|
3
|
-
|
|
4
|
-
const LOADER_UPGRADEABLE = "BPFLoaderUpgradeab1e11111111111111111111111";
|
|
5
|
-
|
|
6
|
-
export function parseUpgradeableLoader(
|
|
7
|
-
owner: string,
|
|
8
|
-
data: Uint8Array,
|
|
9
|
-
context: RpcMethodContext,
|
|
10
|
-
) {
|
|
11
|
-
if (owner !== LOADER_UPGRADEABLE) return null;
|
|
12
|
-
const bytes = data;
|
|
13
|
-
const dv = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
14
|
-
const space = bytes.length;
|
|
15
|
-
type UpgradeableParsed =
|
|
16
|
-
| { type: "program"; info: { programData: string } }
|
|
17
|
-
| {
|
|
18
|
-
type: "programData";
|
|
19
|
-
info: {
|
|
20
|
-
slot: number;
|
|
21
|
-
upgradeAuthority: string | null;
|
|
22
|
-
authority: string | null;
|
|
23
|
-
data: [string, "base64"];
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
| { type: "buffer"; info: { authority: string | null } }
|
|
27
|
-
| null;
|
|
28
|
-
let parsed: UpgradeableParsed = null;
|
|
29
|
-
try {
|
|
30
|
-
if (bytes.length >= 4) {
|
|
31
|
-
const tag = dv.getUint32(0, true);
|
|
32
|
-
if (tag === 2 && bytes.length >= 36) {
|
|
33
|
-
// Program: [u32 tag][32 programDataPubkey]
|
|
34
|
-
const pd = new PublicKey(bytes.slice(4, 36)).toBase58();
|
|
35
|
-
parsed = { type: "program", info: { programData: pd } };
|
|
36
|
-
} else if (tag === 3 && bytes.length >= 4 + 8 + 1) {
|
|
37
|
-
// ProgramData: [u32 tag][u64 slot][Option<Pubkey> upgradeAuthority]
|
|
38
|
-
const slot = Number(dv.getBigUint64(4, true));
|
|
39
|
-
let upgradeAuthority: string | null = null;
|
|
40
|
-
const opt = dv.getUint8(12);
|
|
41
|
-
let hdr = 13; // after u8 option
|
|
42
|
-
if (opt === 1 && bytes.length >= 13 + 32) {
|
|
43
|
-
upgradeAuthority = new PublicKey(bytes.slice(13, 45)).toBase58();
|
|
44
|
-
hdr = 45;
|
|
45
|
-
} else if (opt === 0) {
|
|
46
|
-
hdr = 13;
|
|
47
|
-
} else if (bytes.length >= 12 + 4) {
|
|
48
|
-
// Fallback u32 option at offset 12
|
|
49
|
-
const opt32 = dv.getUint32(12, true);
|
|
50
|
-
hdr = 16;
|
|
51
|
-
if (opt32 === 1 && bytes.length >= 16 + 32) {
|
|
52
|
-
upgradeAuthority = new PublicKey(bytes.slice(16, 48)).toBase58();
|
|
53
|
-
hdr = 48;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
const programBytes = bytes.slice(hdr);
|
|
57
|
-
parsed = {
|
|
58
|
-
type: "programData",
|
|
59
|
-
info: {
|
|
60
|
-
slot: slot === 0 ? Number(context.slot) : slot,
|
|
61
|
-
upgradeAuthority,
|
|
62
|
-
authority: upgradeAuthority,
|
|
63
|
-
data: [Buffer.from(programBytes).toString("base64"), "base64"],
|
|
64
|
-
},
|
|
65
|
-
};
|
|
66
|
-
} else if (tag === 1) {
|
|
67
|
-
// Buffer: [u32 tag][Option<Pubkey> authority]
|
|
68
|
-
let authority: string | null = null;
|
|
69
|
-
if (bytes.length >= 5) {
|
|
70
|
-
const hasAuth = dv.getUint8(4);
|
|
71
|
-
if (hasAuth === 1 && bytes.length >= 5 + 32)
|
|
72
|
-
authority = new PublicKey(bytes.slice(5, 37)).toBase58();
|
|
73
|
-
}
|
|
74
|
-
parsed = { type: "buffer", info: { authority } };
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
} catch {}
|
|
78
|
-
return { program: "bpf-upgradeable-loader", parsed, space };
|
|
79
|
-
}
|
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ExtensionType,
|
|
3
|
-
getExtensionData,
|
|
4
|
-
getExtensionTypes,
|
|
5
|
-
getMetadataPointerState,
|
|
6
|
-
TOKEN_2022_PROGRAM_ID,
|
|
7
|
-
TOKEN_PROGRAM_ID,
|
|
8
|
-
unpackAccount,
|
|
9
|
-
unpackMint,
|
|
10
|
-
} from "@solana/spl-token";
|
|
11
|
-
import { unpack as unpackTokenMetadata } from "@solana/spl-token-metadata";
|
|
12
|
-
import { type AccountInfo, PublicKey } from "@solana/web3.js";
|
|
13
|
-
import type { RpcMethodContext } from "../../../server/types";
|
|
14
|
-
|
|
15
|
-
export function parseSplTokenAccountOrMint(
|
|
16
|
-
pubkey: PublicKey,
|
|
17
|
-
ownerPk: PublicKey,
|
|
18
|
-
data: Uint8Array,
|
|
19
|
-
context: RpcMethodContext,
|
|
20
|
-
) {
|
|
21
|
-
const isTokenOwner =
|
|
22
|
-
ownerPk.equals(TOKEN_PROGRAM_ID) || ownerPk.equals(TOKEN_2022_PROGRAM_ID);
|
|
23
|
-
if (!isTokenOwner) return null;
|
|
24
|
-
const programPk = ownerPk.equals(TOKEN_2022_PROGRAM_ID)
|
|
25
|
-
? TOKEN_2022_PROGRAM_ID
|
|
26
|
-
: TOKEN_PROGRAM_ID;
|
|
27
|
-
const programLabel = ownerPk.equals(TOKEN_2022_PROGRAM_ID)
|
|
28
|
-
? "spl-token-2022"
|
|
29
|
-
: "spl-token";
|
|
30
|
-
const space = data.length;
|
|
31
|
-
|
|
32
|
-
// Try token account first
|
|
33
|
-
if (space >= 165) {
|
|
34
|
-
try {
|
|
35
|
-
const dec = unpackAccount(
|
|
36
|
-
pubkey,
|
|
37
|
-
toAccountInfo(
|
|
38
|
-
{
|
|
39
|
-
data,
|
|
40
|
-
lamports: 0,
|
|
41
|
-
owner: ownerPk,
|
|
42
|
-
executable: false,
|
|
43
|
-
rentEpoch: 0,
|
|
44
|
-
},
|
|
45
|
-
ownerPk,
|
|
46
|
-
),
|
|
47
|
-
programPk,
|
|
48
|
-
);
|
|
49
|
-
// fetch mint decimals
|
|
50
|
-
let decimals = 0;
|
|
51
|
-
try {
|
|
52
|
-
const mintAcc = context.svm.getAccount(dec.mint);
|
|
53
|
-
if (mintAcc) {
|
|
54
|
-
const rawOwner = (mintAcc as { owner?: unknown }).owner;
|
|
55
|
-
const mintOwner = ((): PublicKey => {
|
|
56
|
-
if (
|
|
57
|
-
rawOwner &&
|
|
58
|
-
typeof (rawOwner as { toBase58?: unknown }).toBase58 ===
|
|
59
|
-
"function"
|
|
60
|
-
) {
|
|
61
|
-
return rawOwner as PublicKey;
|
|
62
|
-
}
|
|
63
|
-
return new PublicKey(String(rawOwner));
|
|
64
|
-
})();
|
|
65
|
-
const mintProg = mintOwner.equals(TOKEN_2022_PROGRAM_ID)
|
|
66
|
-
? TOKEN_2022_PROGRAM_ID
|
|
67
|
-
: TOKEN_PROGRAM_ID;
|
|
68
|
-
const mi = unpackMint(
|
|
69
|
-
dec.mint,
|
|
70
|
-
toAccountInfo(mintAcc, mintOwner),
|
|
71
|
-
mintProg,
|
|
72
|
-
);
|
|
73
|
-
decimals = mi?.decimals ?? 0;
|
|
74
|
-
}
|
|
75
|
-
} catch {}
|
|
76
|
-
const amount = BigInt(dec.amount?.toString?.() ?? dec.amount ?? 0);
|
|
77
|
-
const ui = Number.isFinite(decimals)
|
|
78
|
-
? Number(amount) / 10 ** decimals
|
|
79
|
-
: null;
|
|
80
|
-
const state = dec.isFrozen
|
|
81
|
-
? "frozen"
|
|
82
|
-
: dec.isInitialized
|
|
83
|
-
? "initialized"
|
|
84
|
-
: "uninitialized";
|
|
85
|
-
const delegated = BigInt(
|
|
86
|
-
dec.delegatedAmount?.toString?.() ?? dec.delegatedAmount ?? 0n,
|
|
87
|
-
);
|
|
88
|
-
const delegatedUi = Number.isFinite(decimals)
|
|
89
|
-
? Number(delegated) / 10 ** decimals
|
|
90
|
-
: null;
|
|
91
|
-
const rentExemptReserve = dec.isNative
|
|
92
|
-
? {
|
|
93
|
-
amount: BigInt(
|
|
94
|
-
dec.rentExemptReserve?.toString?.() ?? dec.rentExemptReserve ?? 0,
|
|
95
|
-
).toString(),
|
|
96
|
-
decimals: 9,
|
|
97
|
-
uiAmount: null,
|
|
98
|
-
uiAmountString: "0",
|
|
99
|
-
}
|
|
100
|
-
: null;
|
|
101
|
-
const extensions = buildAccountExtensions(dec);
|
|
102
|
-
return {
|
|
103
|
-
program: programLabel,
|
|
104
|
-
parsed: {
|
|
105
|
-
type: "account",
|
|
106
|
-
info: {
|
|
107
|
-
mint: dec.mint.toBase58(),
|
|
108
|
-
owner: dec.owner.toBase58(),
|
|
109
|
-
tokenAmount: {
|
|
110
|
-
amount: amount.toString(),
|
|
111
|
-
decimals,
|
|
112
|
-
uiAmount: ui,
|
|
113
|
-
uiAmountString: (ui ?? 0).toString(),
|
|
114
|
-
},
|
|
115
|
-
state,
|
|
116
|
-
isNative: !!dec.isNative,
|
|
117
|
-
delegatedAmount: {
|
|
118
|
-
amount: delegated.toString(),
|
|
119
|
-
decimals,
|
|
120
|
-
uiAmount: delegatedUi,
|
|
121
|
-
uiAmountString: (delegatedUi ?? 0).toString(),
|
|
122
|
-
},
|
|
123
|
-
delegate: dec.delegate ? dec.delegate.toBase58() : null,
|
|
124
|
-
rentExemptReserve,
|
|
125
|
-
closeAuthority: dec.closeAuthority
|
|
126
|
-
? dec.closeAuthority.toBase58()
|
|
127
|
-
: null,
|
|
128
|
-
extensions,
|
|
129
|
-
},
|
|
130
|
-
},
|
|
131
|
-
space,
|
|
132
|
-
};
|
|
133
|
-
} catch {}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// Try mint
|
|
137
|
-
try {
|
|
138
|
-
const dec = unpackMint(
|
|
139
|
-
pubkey,
|
|
140
|
-
toAccountInfo(
|
|
141
|
-
{ data, lamports: 0, owner: ownerPk, executable: false, rentEpoch: 0 },
|
|
142
|
-
ownerPk,
|
|
143
|
-
),
|
|
144
|
-
programPk,
|
|
145
|
-
);
|
|
146
|
-
const supply = BigInt(dec.supply?.toString?.() ?? dec.supply ?? 0);
|
|
147
|
-
const mintAuthority = dec.mintAuthority
|
|
148
|
-
? dec.mintAuthority.toBase58()
|
|
149
|
-
: null;
|
|
150
|
-
const freezeAuthority = dec.freezeAuthority
|
|
151
|
-
? dec.freezeAuthority.toBase58()
|
|
152
|
-
: null;
|
|
153
|
-
const extensions = buildMintExtensions(dec);
|
|
154
|
-
return {
|
|
155
|
-
program: programLabel,
|
|
156
|
-
parsed: {
|
|
157
|
-
type: "mint",
|
|
158
|
-
info: {
|
|
159
|
-
mintAuthority,
|
|
160
|
-
supply: supply.toString(),
|
|
161
|
-
decimals: dec.decimals,
|
|
162
|
-
isInitialized: !!dec.isInitialized,
|
|
163
|
-
freezeAuthority,
|
|
164
|
-
extensions,
|
|
165
|
-
},
|
|
166
|
-
},
|
|
167
|
-
space,
|
|
168
|
-
};
|
|
169
|
-
} catch {}
|
|
170
|
-
|
|
171
|
-
// Fallback if not parsed
|
|
172
|
-
return { program: programLabel, parsed: null, space };
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
function buildAccountExtensions(account: {
|
|
176
|
-
tlvData: Buffer;
|
|
177
|
-
}): Array<{ type: string }> | undefined {
|
|
178
|
-
if (!account.tlvData || account.tlvData.length === 0) return undefined;
|
|
179
|
-
const types = getExtensionTypes(account.tlvData);
|
|
180
|
-
if (!types.length) return undefined;
|
|
181
|
-
return types.map((ext) => ({ type: ExtensionType[ext] ?? String(ext) }));
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
function buildMintExtensions(mint: {
|
|
185
|
-
tlvData: Buffer;
|
|
186
|
-
}): Array<Record<string, unknown>> | undefined {
|
|
187
|
-
if (!mint.tlvData || mint.tlvData.length === 0) return undefined;
|
|
188
|
-
const types = getExtensionTypes(mint.tlvData);
|
|
189
|
-
if (!types.length) return undefined;
|
|
190
|
-
const out: Array<Record<string, unknown>> = [];
|
|
191
|
-
for (const ext of types) {
|
|
192
|
-
const entry: Record<string, unknown> = {
|
|
193
|
-
type: ExtensionType[ext] ?? String(ext),
|
|
194
|
-
};
|
|
195
|
-
try {
|
|
196
|
-
if (ext === ExtensionType.MetadataPointer) {
|
|
197
|
-
const state = getMetadataPointerState(mint as { tlvData: Buffer });
|
|
198
|
-
if (state) {
|
|
199
|
-
entry.info = {
|
|
200
|
-
authority: state.authority ? state.authority.toBase58() : null,
|
|
201
|
-
metadataAddress: state.metadataAddress
|
|
202
|
-
? state.metadataAddress.toBase58()
|
|
203
|
-
: null,
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
} else if (ext === ExtensionType.TokenMetadata) {
|
|
207
|
-
const data = getExtensionData(ext, mint.tlvData);
|
|
208
|
-
if (data) {
|
|
209
|
-
const meta = unpackTokenMetadata(data);
|
|
210
|
-
entry.info = {
|
|
211
|
-
updateAuthority: meta.updateAuthority
|
|
212
|
-
? meta.updateAuthority.toBase58()
|
|
213
|
-
: null,
|
|
214
|
-
mint: meta.mint.toBase58(),
|
|
215
|
-
name: meta.name,
|
|
216
|
-
symbol: meta.symbol,
|
|
217
|
-
uri: meta.uri,
|
|
218
|
-
additionalMetadata: meta.additionalMetadata.map(([k, v]) => [k, v]),
|
|
219
|
-
};
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
} catch (error) {
|
|
223
|
-
try {
|
|
224
|
-
console.warn("[rpc] decode mint extension failed", error);
|
|
225
|
-
} catch {}
|
|
226
|
-
}
|
|
227
|
-
out.push(entry);
|
|
228
|
-
}
|
|
229
|
-
return out.length ? out : undefined;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
function toAccountInfo(
|
|
233
|
-
raw: {
|
|
234
|
-
data?: Buffer | Uint8Array | number[];
|
|
235
|
-
lamports?: number | bigint;
|
|
236
|
-
executable?: boolean;
|
|
237
|
-
rentEpoch?: number | bigint;
|
|
238
|
-
},
|
|
239
|
-
owner: PublicKey,
|
|
240
|
-
): AccountInfo<Buffer> {
|
|
241
|
-
const data =
|
|
242
|
-
raw.data instanceof Buffer
|
|
243
|
-
? raw.data
|
|
244
|
-
: raw.data instanceof Uint8Array
|
|
245
|
-
? Buffer.from(raw.data)
|
|
246
|
-
: Buffer.from((raw.data ?? []) as number[]);
|
|
247
|
-
return {
|
|
248
|
-
data,
|
|
249
|
-
executable: !!raw.executable,
|
|
250
|
-
lamports: Number(
|
|
251
|
-
typeof raw.lamports === "bigint" ? raw.lamports : (raw.lamports ?? 0),
|
|
252
|
-
),
|
|
253
|
-
owner,
|
|
254
|
-
rentEpoch: Number(raw.rentEpoch ?? 0),
|
|
255
|
-
} as AccountInfo<Buffer>;
|
|
256
|
-
}
|
|
@@ -1,271 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
PublicKey,
|
|
3
|
-
SystemProgram,
|
|
4
|
-
TransactionInstruction,
|
|
5
|
-
TransactionMessage,
|
|
6
|
-
VersionedTransaction,
|
|
7
|
-
} from "@solana/web3.js";
|
|
8
|
-
import type { RpcMethodHandler } from "../../types";
|
|
9
|
-
import { sendTransaction as sendTxRpc } from "../transaction/send-transaction";
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Implements the requestAirdrop RPC method
|
|
13
|
-
* @see https://docs.solana.com/api/http#requestairdrop
|
|
14
|
-
*/
|
|
15
|
-
export const requestAirdrop: RpcMethodHandler = async (id, params, context) => {
|
|
16
|
-
const [pubkeyStr, lamports, _config] = params || [];
|
|
17
|
-
|
|
18
|
-
try {
|
|
19
|
-
const toPubkey = new PublicKey(pubkeyStr);
|
|
20
|
-
const faucet = context.getFaucet();
|
|
21
|
-
// Use SVM's latest blockhash; uniqueness ensured via memo nonce
|
|
22
|
-
let recentBlockhash: string | undefined;
|
|
23
|
-
try {
|
|
24
|
-
recentBlockhash = context.svm.latestBlockhash();
|
|
25
|
-
} catch {}
|
|
26
|
-
if (!recentBlockhash) {
|
|
27
|
-
const bh = new Uint8Array(32);
|
|
28
|
-
crypto.getRandomValues(bh);
|
|
29
|
-
recentBlockhash = context.encodeBase58(bh);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// No per-request top-up; faucet is funded heavily at startup
|
|
33
|
-
|
|
34
|
-
const ix = SystemProgram.transfer({
|
|
35
|
-
fromPubkey: faucet.publicKey,
|
|
36
|
-
toPubkey,
|
|
37
|
-
lamports: Number(BigInt(lamports)),
|
|
38
|
-
});
|
|
39
|
-
// Add a memo with random nonce to guarantee unique signatures
|
|
40
|
-
const memoProgramId = new PublicKey(
|
|
41
|
-
"MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr",
|
|
42
|
-
);
|
|
43
|
-
const nonce = new Uint8Array(8);
|
|
44
|
-
crypto.getRandomValues(nonce);
|
|
45
|
-
const memoIx = new TransactionInstruction({
|
|
46
|
-
keys: [],
|
|
47
|
-
programId: memoProgramId,
|
|
48
|
-
data: Buffer.from(`airdrop:${Buffer.from(nonce).toString("hex")}`),
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
const messageV0 = new TransactionMessage({
|
|
52
|
-
payerKey: faucet.publicKey,
|
|
53
|
-
recentBlockhash,
|
|
54
|
-
instructions: [ix, memoIx],
|
|
55
|
-
});
|
|
56
|
-
// Prefer legacy message for maximum LiteSVM compatibility
|
|
57
|
-
const compiled = messageV0.compileToLegacyMessage();
|
|
58
|
-
|
|
59
|
-
const tx = new VersionedTransaction(compiled);
|
|
60
|
-
tx.sign([faucet]);
|
|
61
|
-
|
|
62
|
-
// Compute pre balances for all static account keys
|
|
63
|
-
const msg = tx.message as unknown as {
|
|
64
|
-
staticAccountKeys?: unknown;
|
|
65
|
-
accountKeys?: unknown;
|
|
66
|
-
};
|
|
67
|
-
const rawKeys = Array.isArray(msg.staticAccountKeys)
|
|
68
|
-
? (msg.staticAccountKeys as unknown[])
|
|
69
|
-
: Array.isArray(msg.accountKeys)
|
|
70
|
-
? (msg.accountKeys as unknown[])
|
|
71
|
-
: [];
|
|
72
|
-
const staticKeys = rawKeys.map((k) => {
|
|
73
|
-
try {
|
|
74
|
-
return typeof k === "string" ? new PublicKey(k) : (k as PublicKey);
|
|
75
|
-
} catch {
|
|
76
|
-
return faucet.publicKey;
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
const preBalances = staticKeys.map((pk) => {
|
|
80
|
-
try {
|
|
81
|
-
return Number(context.svm.getBalance(pk));
|
|
82
|
-
} catch {
|
|
83
|
-
return 0;
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
const preAccountStates = staticKeys.map((pk) => {
|
|
87
|
-
try {
|
|
88
|
-
const addr = pk.toBase58();
|
|
89
|
-
const acc = context.svm.getAccount(pk);
|
|
90
|
-
if (!acc) return { address: addr, pre: null } as const;
|
|
91
|
-
return {
|
|
92
|
-
address: addr,
|
|
93
|
-
pre: {
|
|
94
|
-
lamports: Number(acc.lamports || 0n),
|
|
95
|
-
ownerProgram: new PublicKey(acc.owner).toBase58(),
|
|
96
|
-
executable: !!acc.executable,
|
|
97
|
-
rentEpoch: Number(acc.rentEpoch || 0),
|
|
98
|
-
dataLen: acc.data?.length ?? 0,
|
|
99
|
-
dataBase64: undefined,
|
|
100
|
-
lastSlot: Number(context.slot),
|
|
101
|
-
},
|
|
102
|
-
} as const;
|
|
103
|
-
} catch {
|
|
104
|
-
return { address: pk.toBase58(), pre: null } as const;
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
try {
|
|
108
|
-
if (process.env.DEBUG_TX_CAPTURE === "1") {
|
|
109
|
-
console.debug(
|
|
110
|
-
`[tx-capture] pre snapshots: keys=${staticKeys.length} captured=${preAccountStates.length}`,
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
} catch {}
|
|
114
|
-
const toIndex = staticKeys.findIndex((pk) => pk.equals(toPubkey));
|
|
115
|
-
const beforeTo =
|
|
116
|
-
toIndex >= 0
|
|
117
|
-
? preBalances[toIndex]
|
|
118
|
-
: (() => {
|
|
119
|
-
try {
|
|
120
|
-
return Number(context.svm.getBalance(toPubkey));
|
|
121
|
-
} catch {
|
|
122
|
-
return 0;
|
|
123
|
-
}
|
|
124
|
-
})();
|
|
125
|
-
|
|
126
|
-
// Send via standard sendTransaction RPC to unify capture + persistence
|
|
127
|
-
const rawB64 = Buffer.from(tx.serialize()).toString("base64");
|
|
128
|
-
const resp = await (sendTxRpc as RpcMethodHandler)(id, [rawB64], context);
|
|
129
|
-
if (
|
|
130
|
-
resp &&
|
|
131
|
-
typeof resp === "object" &&
|
|
132
|
-
"error" in (resp as Record<string, unknown>) &&
|
|
133
|
-
(resp as Record<string, unknown>).error != null
|
|
134
|
-
) {
|
|
135
|
-
return resp;
|
|
136
|
-
}
|
|
137
|
-
// Any send errors would have been returned by send-transaction already
|
|
138
|
-
|
|
139
|
-
let signature = (() => {
|
|
140
|
-
try {
|
|
141
|
-
const r = resp as Record<string, unknown>;
|
|
142
|
-
const v = r?.result;
|
|
143
|
-
return v == null ? "" : String(v);
|
|
144
|
-
} catch {
|
|
145
|
-
return "";
|
|
146
|
-
}
|
|
147
|
-
})();
|
|
148
|
-
if (!signature) {
|
|
149
|
-
signature = tx.signatures[0]
|
|
150
|
-
? context.encodeBase58(tx.signatures[0])
|
|
151
|
-
: context.encodeBase58(new Uint8Array(64).fill(0));
|
|
152
|
-
}
|
|
153
|
-
try {
|
|
154
|
-
context.notifySignature(signature);
|
|
155
|
-
} catch {}
|
|
156
|
-
// Compute post balances and capture logs if available for explorer detail view
|
|
157
|
-
let postBalances = staticKeys.map((pk) => {
|
|
158
|
-
try {
|
|
159
|
-
return Number(context.svm.getBalance(pk));
|
|
160
|
-
} catch {
|
|
161
|
-
return 0;
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
const postAccountStates = staticKeys.map((pk) => {
|
|
165
|
-
try {
|
|
166
|
-
const addr = pk.toBase58();
|
|
167
|
-
const acc = context.svm.getAccount(pk);
|
|
168
|
-
if (!acc) return { address: addr, post: null } as const;
|
|
169
|
-
return {
|
|
170
|
-
address: addr,
|
|
171
|
-
post: {
|
|
172
|
-
lamports: Number(acc.lamports || 0n),
|
|
173
|
-
ownerProgram: new PublicKey(acc.owner).toBase58(),
|
|
174
|
-
executable: !!acc.executable,
|
|
175
|
-
rentEpoch: Number(acc.rentEpoch || 0),
|
|
176
|
-
dataLen: acc.data?.length ?? 0,
|
|
177
|
-
dataBase64: undefined,
|
|
178
|
-
lastSlot: Number(context.slot),
|
|
179
|
-
},
|
|
180
|
-
} as const;
|
|
181
|
-
} catch {
|
|
182
|
-
return { address: pk.toBase58(), post: null } as const;
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
try {
|
|
186
|
-
if (process.env.DEBUG_TX_CAPTURE === "1") {
|
|
187
|
-
console.debug(
|
|
188
|
-
`[tx-capture] post snapshots: keys=${staticKeys.length} captured=${postAccountStates.length}`,
|
|
189
|
-
);
|
|
190
|
-
}
|
|
191
|
-
} catch {}
|
|
192
|
-
// Parsing, recording etc. are performed by send-transaction
|
|
193
|
-
// Verify recipient received lamports; retry once if not
|
|
194
|
-
const afterTo =
|
|
195
|
-
toIndex >= 0
|
|
196
|
-
? postBalances[toIndex]
|
|
197
|
-
: (() => {
|
|
198
|
-
try {
|
|
199
|
-
return Number(context.svm.getBalance(toPubkey));
|
|
200
|
-
} catch {
|
|
201
|
-
return 0;
|
|
202
|
-
}
|
|
203
|
-
})();
|
|
204
|
-
const expectedDelta = Number(BigInt(lamports));
|
|
205
|
-
if (afterTo - beforeTo < expectedDelta) {
|
|
206
|
-
// Retry once with fresh blockhash + memo
|
|
207
|
-
try {
|
|
208
|
-
const bh2 = new Uint8Array(32);
|
|
209
|
-
crypto.getRandomValues(bh2);
|
|
210
|
-
const rb2 = context.encodeBase58(bh2);
|
|
211
|
-
const memoProgramId2 = new PublicKey(
|
|
212
|
-
"MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr",
|
|
213
|
-
);
|
|
214
|
-
const nonce2 = new Uint8Array(8);
|
|
215
|
-
crypto.getRandomValues(nonce2);
|
|
216
|
-
const memoIx2 = new TransactionInstruction({
|
|
217
|
-
keys: [],
|
|
218
|
-
programId: memoProgramId2,
|
|
219
|
-
data: Buffer.from(
|
|
220
|
-
`airdrop-retry:${Buffer.from(nonce2).toString("hex")}`,
|
|
221
|
-
),
|
|
222
|
-
});
|
|
223
|
-
const msg2 = new TransactionMessage({
|
|
224
|
-
payerKey: faucet.publicKey,
|
|
225
|
-
recentBlockhash: rb2,
|
|
226
|
-
instructions: [ix, memoIx2],
|
|
227
|
-
}).compileToV0Message();
|
|
228
|
-
const tx2 = new VersionedTransaction(msg2);
|
|
229
|
-
tx2.sign([faucet]);
|
|
230
|
-
const res2 = context.svm.sendTransaction(tx2);
|
|
231
|
-
try {
|
|
232
|
-
const e2Raw = (res2 as { err?: unknown }).err;
|
|
233
|
-
const e2 =
|
|
234
|
-
typeof e2Raw === "function" ? (e2Raw as () => unknown)() : e2Raw;
|
|
235
|
-
if (e2) console.warn("[requestAirdrop] retry failed:", e2);
|
|
236
|
-
} catch {}
|
|
237
|
-
signature = tx2.signatures[0]
|
|
238
|
-
? context.encodeBase58(tx2.signatures[0])
|
|
239
|
-
: signature;
|
|
240
|
-
context.notifySignature(signature);
|
|
241
|
-
postBalances = staticKeys.map((pk) => {
|
|
242
|
-
try {
|
|
243
|
-
return Number(context.svm.getBalance(pk));
|
|
244
|
-
} catch {
|
|
245
|
-
return 0;
|
|
246
|
-
}
|
|
247
|
-
});
|
|
248
|
-
} catch {}
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
// Try to capture error again for accurate status reporting
|
|
252
|
-
// No additional error capture; send-transaction has already recorded it
|
|
253
|
-
// Pre/post snapshots are still useful for account cache; we can upsert
|
|
254
|
-
try {
|
|
255
|
-
const snapshots = new Map<string, { pre?: unknown; post?: unknown }>();
|
|
256
|
-
for (const s of preAccountStates)
|
|
257
|
-
snapshots.set(s.address, { pre: s.pre || null });
|
|
258
|
-
for (const s of postAccountStates) {
|
|
259
|
-
const e = snapshots.get(s.address) || {};
|
|
260
|
-
e.post = s.post || null;
|
|
261
|
-
snapshots.set(s.address, e);
|
|
262
|
-
}
|
|
263
|
-
// Not persisted here; DB already has the transaction via send-transaction
|
|
264
|
-
} catch {}
|
|
265
|
-
|
|
266
|
-
return context.createSuccessResponse(id, signature);
|
|
267
|
-
} catch (error: unknown) {
|
|
268
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
269
|
-
return context.createErrorResponse(id, -32602, "Invalid params", message);
|
|
270
|
-
}
|
|
271
|
-
};
|