@oobe-protocol-labs/synapse-sap-sdk 0.4.0 → 0.4.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/dist/cjs/core/client.js +23 -0
- package/dist/cjs/core/client.js.map +1 -1
- package/dist/cjs/core/connection.js +37 -6
- package/dist/cjs/core/connection.js.map +1 -1
- package/dist/cjs/core/index.js +2 -1
- package/dist/cjs/core/index.js.map +1 -1
- package/dist/cjs/index.js +17 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/parser/client.js +146 -0
- package/dist/cjs/parser/client.js.map +1 -0
- package/dist/cjs/parser/complete.js +177 -0
- package/dist/cjs/parser/complete.js.map +1 -0
- package/dist/cjs/parser/index.js +57 -0
- package/dist/cjs/parser/index.js.map +1 -0
- package/dist/cjs/parser/inner.js +185 -0
- package/dist/cjs/parser/inner.js.map +1 -0
- package/dist/cjs/parser/instructions.js +114 -0
- package/dist/cjs/parser/instructions.js.map +1 -0
- package/dist/cjs/parser/transaction.js +153 -0
- package/dist/cjs/parser/transaction.js.map +1 -0
- package/dist/cjs/parser/types.js +14 -0
- package/dist/cjs/parser/types.js.map +1 -0
- package/dist/esm/core/client.js +23 -0
- package/dist/esm/core/client.js.map +1 -1
- package/dist/esm/core/connection.js +36 -6
- package/dist/esm/core/connection.js.map +1 -1
- package/dist/esm/core/index.js +1 -1
- package/dist/esm/core/index.js.map +1 -1
- package/dist/esm/index.js +4 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/parser/client.js +142 -0
- package/dist/esm/parser/client.js.map +1 -0
- package/dist/esm/parser/complete.js +173 -0
- package/dist/esm/parser/complete.js.map +1 -0
- package/dist/esm/parser/index.js +43 -0
- package/dist/esm/parser/index.js.map +1 -0
- package/dist/esm/parser/inner.js +180 -0
- package/dist/esm/parser/inner.js.map +1 -0
- package/dist/esm/parser/instructions.js +109 -0
- package/dist/esm/parser/instructions.js.map +1 -0
- package/dist/esm/parser/transaction.js +149 -0
- package/dist/esm/parser/transaction.js.map +1 -0
- package/dist/esm/parser/types.js +13 -0
- package/dist/esm/parser/types.js.map +1 -0
- package/dist/types/core/client.d.ts +19 -0
- package/dist/types/core/client.d.ts.map +1 -1
- package/dist/types/core/connection.d.ts +32 -6
- package/dist/types/core/connection.d.ts.map +1 -1
- package/dist/types/core/index.d.ts +2 -2
- package/dist/types/core/index.d.ts.map +1 -1
- package/dist/types/index.d.ts +5 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/parser/client.d.ts +123 -0
- package/dist/types/parser/client.d.ts.map +1 -0
- package/dist/types/parser/complete.d.ts +90 -0
- package/dist/types/parser/complete.d.ts.map +1 -0
- package/dist/types/parser/index.d.ts +40 -0
- package/dist/types/parser/index.d.ts.map +1 -0
- package/dist/types/parser/inner.d.ts +114 -0
- package/dist/types/parser/inner.d.ts.map +1 -0
- package/dist/types/parser/instructions.d.ts +76 -0
- package/dist/types/parser/instructions.d.ts.map +1 -0
- package/dist/types/parser/transaction.d.ts +77 -0
- package/dist/types/parser/transaction.d.ts.map +1 -0
- package/dist/types/parser/types.d.ts +154 -0
- package/dist/types/parser/types.d.ts.map +1 -0
- package/package.json +6 -1
- package/src/core/client.ts +25 -0
- package/src/core/connection.ts +59 -7
- package/src/core/index.ts +2 -2
- package/src/index.ts +27 -2
- package/src/parser/client.ts +211 -0
- package/src/parser/complete.ts +232 -0
- package/src/parser/index.ts +71 -0
- package/src/parser/inner.ts +255 -0
- package/src/parser/instructions.ts +135 -0
- package/src/parser/transaction.ts +200 -0
- package/src/parser/types.ts +182 -0
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module parser/types
|
|
3
|
+
* @description Type definitions for SAP v2 transaction parsing.
|
|
4
|
+
*
|
|
5
|
+
* Provides strongly-typed interfaces for decoded instruction data,
|
|
6
|
+
* account metadata, inner (CPI) instructions, and the full parsed
|
|
7
|
+
* transaction result used by indexers and explorers.
|
|
8
|
+
*
|
|
9
|
+
* @category Parser
|
|
10
|
+
* @since v0.5.0
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import type { PublicKey, TransactionInstruction } from "@solana/web3.js";
|
|
14
|
+
import type { ParsedEvent, SapEventName } from "../events";
|
|
15
|
+
|
|
16
|
+
// ================================================================
|
|
17
|
+
// Decoded Instruction
|
|
18
|
+
// ================================================================
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* A single SAP instruction decoded from on-chain transaction data.
|
|
22
|
+
*
|
|
23
|
+
* Contains the human-readable instruction name (as declared in the
|
|
24
|
+
* Anchor IDL), the decoded argument object, the ordered list of
|
|
25
|
+
* account keys, and the raw instruction for advanced consumers.
|
|
26
|
+
*
|
|
27
|
+
* @interface DecodedSapInstruction
|
|
28
|
+
* @category Parser
|
|
29
|
+
* @since v0.5.0
|
|
30
|
+
*/
|
|
31
|
+
export interface DecodedSapInstruction {
|
|
32
|
+
/** Instruction name matching the Anchor IDL method (e.g. `"registerAgent"`). */
|
|
33
|
+
readonly name: string;
|
|
34
|
+
/**
|
|
35
|
+
* Decoded arguments object. Keys match the Anchor IDL argument names.
|
|
36
|
+
* Returns `null` when decoding fails (e.g. IDL mismatch).
|
|
37
|
+
*/
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
39
|
+
readonly args: Record<string, any> | null;
|
|
40
|
+
/** Ordered list of account public keys passed to the instruction. */
|
|
41
|
+
readonly accounts: PublicKey[];
|
|
42
|
+
/** The original `TransactionInstruction`, useful for re-simulation or forwarding. */
|
|
43
|
+
readonly raw: TransactionInstruction;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// ================================================================
|
|
47
|
+
// Inner (CPI) Instruction
|
|
48
|
+
// ================================================================
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* An inner instruction produced by cross-program invocation (CPI)
|
|
52
|
+
* within a SAP transaction.
|
|
53
|
+
*
|
|
54
|
+
* Inner instructions are indexed by the outer instruction position
|
|
55
|
+
* that triggered them. Each entry includes the decoded SAP name
|
|
56
|
+
* when the inner call targets the SAP program, or `null` otherwise.
|
|
57
|
+
*
|
|
58
|
+
* @interface DecodedInnerInstruction
|
|
59
|
+
* @category Parser
|
|
60
|
+
* @since v0.5.0
|
|
61
|
+
*/
|
|
62
|
+
export interface DecodedInnerInstruction {
|
|
63
|
+
/** Zero-based index of the outer instruction that triggered this CPI call. */
|
|
64
|
+
readonly outerIndex: number;
|
|
65
|
+
/** Zero-based position within the inner instruction set of the parent. */
|
|
66
|
+
readonly innerIndex: number;
|
|
67
|
+
/** SAP instruction name if the CPI targets the SAP program, `null` otherwise. */
|
|
68
|
+
readonly name: string | null;
|
|
69
|
+
/** Decoded arguments when the CPI targets SAP and decoding succeeds. */
|
|
70
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
71
|
+
readonly args: Record<string, any> | null;
|
|
72
|
+
/** Ordered account keys for this inner instruction. */
|
|
73
|
+
readonly accounts: PublicKey[];
|
|
74
|
+
/** The program that was invoked by this inner call. */
|
|
75
|
+
readonly programId: PublicKey;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// ================================================================
|
|
79
|
+
// Parsed Transaction (complete result)
|
|
80
|
+
// ================================================================
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Full parse result for a single SAP transaction.
|
|
84
|
+
*
|
|
85
|
+
* Combines top-level instruction decoding, inner instruction
|
|
86
|
+
* analysis, and event extraction into one unified structure
|
|
87
|
+
* suitable for indexing, analytics dashboards, and protocol
|
|
88
|
+
* explorers.
|
|
89
|
+
*
|
|
90
|
+
* @interface ParsedSapTransaction
|
|
91
|
+
* @category Parser
|
|
92
|
+
* @since v0.5.0
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```ts
|
|
96
|
+
* const result = parseSapTransactionComplete(tx, program, SAP_PROGRAM_ID);
|
|
97
|
+
* for (const ix of result.instructions) {
|
|
98
|
+
* console.log(ix.name, ix.args);
|
|
99
|
+
* }
|
|
100
|
+
* for (const event of result.events) {
|
|
101
|
+
* console.log(event.name, event.data);
|
|
102
|
+
* }
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
export interface ParsedSapTransaction {
|
|
106
|
+
/** Transaction signature (base-58), extracted from the response when available. */
|
|
107
|
+
readonly signature: string | null;
|
|
108
|
+
/** Slot at which the transaction was confirmed. */
|
|
109
|
+
readonly slot: number | null;
|
|
110
|
+
/** Block timestamp (unix seconds) or `null` if unavailable. */
|
|
111
|
+
readonly blockTime: number | null;
|
|
112
|
+
/** Whether the transaction succeeded (`true`) or failed. */
|
|
113
|
+
readonly success: boolean;
|
|
114
|
+
/** Top-level SAP instructions found in the transaction. */
|
|
115
|
+
readonly instructions: DecodedSapInstruction[];
|
|
116
|
+
/** All inner (CPI) instructions, including non-SAP programs. */
|
|
117
|
+
readonly innerInstructions: DecodedInnerInstruction[];
|
|
118
|
+
/** Decoded SAP events extracted from the transaction logs. */
|
|
119
|
+
readonly events: ParsedEvent[];
|
|
120
|
+
/** Raw log lines from the transaction, for additional debugging. */
|
|
121
|
+
readonly logs: string[];
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// ================================================================
|
|
125
|
+
// Filter helpers
|
|
126
|
+
// ================================================================
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Options for filtering parsed instruction results.
|
|
130
|
+
*
|
|
131
|
+
* @interface ParseFilterOptions
|
|
132
|
+
* @category Parser
|
|
133
|
+
* @since v0.5.0
|
|
134
|
+
*/
|
|
135
|
+
export interface ParseFilterOptions {
|
|
136
|
+
/**
|
|
137
|
+
* When `true`, include inner (CPI) instructions in the parse
|
|
138
|
+
* result. Defaults to `false` because inner instruction
|
|
139
|
+
* reconstruction requires additional account-table lookups.
|
|
140
|
+
*/
|
|
141
|
+
readonly includeInner?: boolean;
|
|
142
|
+
/**
|
|
143
|
+
* When `true`, decode and attach SAP events from the
|
|
144
|
+
* transaction logs. Defaults to `true`.
|
|
145
|
+
*/
|
|
146
|
+
readonly includeEvents?: boolean;
|
|
147
|
+
/**
|
|
148
|
+
* Restrict the result to instructions matching one of these
|
|
149
|
+
* names. When `undefined` or empty, all SAP instructions are
|
|
150
|
+
* returned.
|
|
151
|
+
*/
|
|
152
|
+
readonly instructionFilter?: string[];
|
|
153
|
+
/**
|
|
154
|
+
* Restrict events to those matching one of these names.
|
|
155
|
+
* When `undefined` or empty, all events are returned.
|
|
156
|
+
*/
|
|
157
|
+
readonly eventFilter?: SapEventName[];
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// ================================================================
|
|
161
|
+
// Coder interface (minimal contract)
|
|
162
|
+
// ================================================================
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Minimal interface for the Anchor instruction coder.
|
|
166
|
+
*
|
|
167
|
+
* Extracted so that parser functions can accept either a full
|
|
168
|
+
* `Program` instance or a standalone coder/IDL pair without
|
|
169
|
+
* requiring a live RPC connection.
|
|
170
|
+
*
|
|
171
|
+
* @interface SapInstructionCoder
|
|
172
|
+
* @category Parser
|
|
173
|
+
* @since v0.5.0
|
|
174
|
+
*/
|
|
175
|
+
export interface SapInstructionCoder {
|
|
176
|
+
/** Decode raw instruction data into a name and typed argument object. */
|
|
177
|
+
decode(
|
|
178
|
+
data: Buffer | Uint8Array,
|
|
179
|
+
encoding?: string,
|
|
180
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
181
|
+
): { name: string; data: Record<string, any> } | null;
|
|
182
|
+
}
|