@vtx-labs/solana-explain 0.1.0
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 +21 -0
- package/README.md +328 -0
- package/dist/cli/index.d.ts +14 -0
- package/dist/cli/index.js +3317 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/index.d.ts +116 -0
- package/dist/index.js +3130 -0
- package/dist/index.js.map +1 -0
- package/dist/programs.d.ts +42 -0
- package/dist/programs.js +919 -0
- package/dist/programs.js.map +1 -0
- package/dist/render.d.ts +59 -0
- package/dist/render.js +300 -0
- package/dist/render.js.map +1 -0
- package/dist/types-MSKEy1VA.d.ts +482 -0
- package/package.json +83 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { E as ExplainInput, a as ExplainResult, b as ExplainInstruction, c as ExplainOptions, d as ExplainInstructionsOptions, e as ExplainSignatureOptions, f as ExplainTransactionOptions, B as BalanceSnapshot, g as BalanceDelta, R as RpcClient } from './types-MSKEy1VA.js';
|
|
2
|
+
export { A as AccountCreation, h as Action, i as Approval, C as Commitment, j as CompiledInstructionView, D as DecodeOutput, k as DecodedInstruction, l as DecoderEffect, m as ExplainInstructionAccount, G as GetAccountsOpts, n as GetTransactionOpts, K as KnownProgramInfo, P as ProgramDecoder, o as ProgramInvocation, p as ProgramKind, q as ProgramRegistry, r as RawAccount, s as RawSimulateResponse, t as RawTransactionResponse, u as RenderOptions, S as SimulateOpts, T as TokenBalanceEntry, W as Warning, v as WarningCode } from './types-MSKEy1VA.js';
|
|
3
|
+
export { KNOWN_PROGRAMS, createRegistry, decodeInstruction, defaultRegistry } from './programs.js';
|
|
4
|
+
export { renderJson, renderMarkdown, renderText } from './render.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Error hierarchy for solana-explain.
|
|
8
|
+
*
|
|
9
|
+
* Every public async function rejects ONLY with a {@link SolanaExplainError}
|
|
10
|
+
* subclass. Raw/underlying errors are always wrapped and preserved on `.cause`.
|
|
11
|
+
*/
|
|
12
|
+
type ErrorCode = 'INVALID_INPUT' | 'INVALID_SIGNATURE' | 'INVALID_ENCODING' | 'EMPTY_INPUT' | 'TX_NOT_FOUND' | 'RPC_HTTP' | 'RPC_JSON' | 'RPC_TIMEOUT' | 'ABORTED' | 'DECODE_FAILED' | 'SIMULATION_REJECTED' | 'UNSUPPORTED_TX_VERSION';
|
|
13
|
+
interface SolanaExplainErrorOptions {
|
|
14
|
+
cause?: unknown;
|
|
15
|
+
/** Optional human hint surfaced by the CLI alongside the message. */
|
|
16
|
+
hint?: string;
|
|
17
|
+
}
|
|
18
|
+
/** Base class. Never thrown directly by public functions — only its subclasses. */
|
|
19
|
+
declare class SolanaExplainError extends Error {
|
|
20
|
+
readonly code: ErrorCode;
|
|
21
|
+
readonly cause?: unknown;
|
|
22
|
+
/** Optional, CLI-friendly remediation hint. */
|
|
23
|
+
readonly hint?: string;
|
|
24
|
+
constructor(code: ErrorCode, message: string, options?: SolanaExplainErrorOptions);
|
|
25
|
+
}
|
|
26
|
+
/** Transport / JSON-RPC error (HTTP failure, malformed JSON, JSON-RPC error object, timeout). */
|
|
27
|
+
declare class RpcError extends SolanaExplainError {
|
|
28
|
+
}
|
|
29
|
+
/** Malformed transaction bytes / wire message. */
|
|
30
|
+
declare class DecodeError extends SolanaExplainError {
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Simulation produced a runtime error (the tx would fail). Still carries a
|
|
34
|
+
* partial {@link import('./types').ExplainResult} on `.result` when available,
|
|
35
|
+
* because the user usually wants to know *why* it failed.
|
|
36
|
+
*
|
|
37
|
+
* Note: a node *rejecting* the simulation outright (bad blockhash, etc.) is a
|
|
38
|
+
* different condition and is also surfaced as a `SimulationError`, with code
|
|
39
|
+
* `SIMULATION_REJECTED`.
|
|
40
|
+
*/
|
|
41
|
+
declare class SimulationError extends SolanaExplainError {
|
|
42
|
+
/** Partial result when the simulation ran but reverted. */
|
|
43
|
+
readonly result?: unknown;
|
|
44
|
+
/** Tail of the node's program logs, for diagnostics. */
|
|
45
|
+
readonly logs?: readonly string[];
|
|
46
|
+
constructor(code: ErrorCode, message: string, options?: SolanaExplainErrorOptions & {
|
|
47
|
+
result?: unknown;
|
|
48
|
+
logs?: readonly string[];
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/** Bad signature / encoding / empty input. */
|
|
52
|
+
declare class InputError extends SolanaExplainError {
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Top-level orchestrators: `explain`, `explainSignature`, `explainTransaction`,
|
|
57
|
+
* `explainInstructions`, and the pure `buildExplanation`.
|
|
58
|
+
*
|
|
59
|
+
* Behavioral contracts:
|
|
60
|
+
* - All public async functions reject ONLY with a SolanaExplainError subclass.
|
|
61
|
+
* - A failed/reverted tx still returns a fully-populated ExplainResult
|
|
62
|
+
* (success:false); it does NOT throw.
|
|
63
|
+
* - explainSignature on a missing sig throws RpcError TX_NOT_FOUND.
|
|
64
|
+
* - Simulation the node outright rejects throws SimulationError.
|
|
65
|
+
*/
|
|
66
|
+
|
|
67
|
+
/** Pure: given pre/post balances + decoded instructions, produce the narrative. */
|
|
68
|
+
declare function buildExplanation(input: ExplainInput): ExplainResult;
|
|
69
|
+
declare function explainSignature(signature: string, options: ExplainSignatureOptions): Promise<ExplainResult>;
|
|
70
|
+
declare function explainTransaction(tx: string | Uint8Array, options: ExplainTransactionOptions): Promise<ExplainResult>;
|
|
71
|
+
declare function explainInstructions(instructions: ExplainInstruction[], options: ExplainInstructionsOptions): Promise<ExplainResult>;
|
|
72
|
+
declare function explain(input: string | Uint8Array | ExplainInstruction[], options: ExplainOptions): Promise<ExplainResult>;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* `diffBalances`: pure diff of pre/post lamport + token balances into typed
|
|
76
|
+
* {@link BalanceDelta}[]. No I/O.
|
|
77
|
+
*
|
|
78
|
+
* - SOL deltas: by account key index (post − pre).
|
|
79
|
+
* - Token deltas: keyed by token-account address + mint, matching pre/post.
|
|
80
|
+
* Accounts present on only one side are created (post-only) or closed
|
|
81
|
+
* (pre-only).
|
|
82
|
+
*/
|
|
83
|
+
|
|
84
|
+
declare function diffBalances(pre: BalanceSnapshot, post: BalanceSnapshot): BalanceDelta[];
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* `createHttpRpc`: zero-dep JSON-RPC over the global `fetch` (Node 18+).
|
|
88
|
+
*
|
|
89
|
+
* - Per-call timeout via AbortController, composed with the caller's signal.
|
|
90
|
+
* - Single jittered-backoff retry on 429/5xx.
|
|
91
|
+
* - Strict JSON-RPC error mapping → RpcError.
|
|
92
|
+
*/
|
|
93
|
+
|
|
94
|
+
interface HttpRpcOptions {
|
|
95
|
+
/** Default per-call timeout in ms. Default 30_000. */
|
|
96
|
+
timeoutMs?: number;
|
|
97
|
+
/** Extra HTTP headers (e.g. API key). */
|
|
98
|
+
headers?: Record<string, string>;
|
|
99
|
+
/** Override fetch (for testing). Defaults to global fetch. */
|
|
100
|
+
fetch?: typeof fetch;
|
|
101
|
+
}
|
|
102
|
+
declare function createHttpRpc(url: string, opts?: HttpRpcOptions): RpcClient;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* `fromWeb3Rpc`: adapt an existing `@solana/web3.js` v1 `Connection` or a
|
|
106
|
+
* `@solana/kit` / web3.js v2 RPC object to our {@link RpcClient}, by
|
|
107
|
+
* duck-typing its methods. We never import web3.js — it stays an optional peer.
|
|
108
|
+
*/
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Wrap a web3.js v1 `Connection` or a kit RPC into an {@link RpcClient}.
|
|
112
|
+
* Throws {@link RpcError} if the object exposes neither shape.
|
|
113
|
+
*/
|
|
114
|
+
declare function fromWeb3Rpc(rpc: unknown): RpcClient;
|
|
115
|
+
|
|
116
|
+
export { BalanceDelta, BalanceSnapshot, DecodeError, type ErrorCode, ExplainInput, ExplainInstruction, ExplainInstructionsOptions, ExplainOptions, ExplainResult, ExplainSignatureOptions, ExplainTransactionOptions, type HttpRpcOptions, InputError, RpcClient, RpcError, SimulationError, SolanaExplainError, buildExplanation, createHttpRpc, diffBalances, explain, explainInstructions, explainSignature, explainTransaction, fromWeb3Rpc };
|