@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.
Files changed (78) hide show
  1. package/dist/cjs/core/client.js +23 -0
  2. package/dist/cjs/core/client.js.map +1 -1
  3. package/dist/cjs/core/connection.js +37 -6
  4. package/dist/cjs/core/connection.js.map +1 -1
  5. package/dist/cjs/core/index.js +2 -1
  6. package/dist/cjs/core/index.js.map +1 -1
  7. package/dist/cjs/index.js +17 -2
  8. package/dist/cjs/index.js.map +1 -1
  9. package/dist/cjs/parser/client.js +146 -0
  10. package/dist/cjs/parser/client.js.map +1 -0
  11. package/dist/cjs/parser/complete.js +177 -0
  12. package/dist/cjs/parser/complete.js.map +1 -0
  13. package/dist/cjs/parser/index.js +57 -0
  14. package/dist/cjs/parser/index.js.map +1 -0
  15. package/dist/cjs/parser/inner.js +185 -0
  16. package/dist/cjs/parser/inner.js.map +1 -0
  17. package/dist/cjs/parser/instructions.js +114 -0
  18. package/dist/cjs/parser/instructions.js.map +1 -0
  19. package/dist/cjs/parser/transaction.js +153 -0
  20. package/dist/cjs/parser/transaction.js.map +1 -0
  21. package/dist/cjs/parser/types.js +14 -0
  22. package/dist/cjs/parser/types.js.map +1 -0
  23. package/dist/esm/core/client.js +23 -0
  24. package/dist/esm/core/client.js.map +1 -1
  25. package/dist/esm/core/connection.js +36 -6
  26. package/dist/esm/core/connection.js.map +1 -1
  27. package/dist/esm/core/index.js +1 -1
  28. package/dist/esm/core/index.js.map +1 -1
  29. package/dist/esm/index.js +4 -1
  30. package/dist/esm/index.js.map +1 -1
  31. package/dist/esm/parser/client.js +142 -0
  32. package/dist/esm/parser/client.js.map +1 -0
  33. package/dist/esm/parser/complete.js +173 -0
  34. package/dist/esm/parser/complete.js.map +1 -0
  35. package/dist/esm/parser/index.js +43 -0
  36. package/dist/esm/parser/index.js.map +1 -0
  37. package/dist/esm/parser/inner.js +180 -0
  38. package/dist/esm/parser/inner.js.map +1 -0
  39. package/dist/esm/parser/instructions.js +109 -0
  40. package/dist/esm/parser/instructions.js.map +1 -0
  41. package/dist/esm/parser/transaction.js +149 -0
  42. package/dist/esm/parser/transaction.js.map +1 -0
  43. package/dist/esm/parser/types.js +13 -0
  44. package/dist/esm/parser/types.js.map +1 -0
  45. package/dist/types/core/client.d.ts +19 -0
  46. package/dist/types/core/client.d.ts.map +1 -1
  47. package/dist/types/core/connection.d.ts +32 -6
  48. package/dist/types/core/connection.d.ts.map +1 -1
  49. package/dist/types/core/index.d.ts +2 -2
  50. package/dist/types/core/index.d.ts.map +1 -1
  51. package/dist/types/index.d.ts +5 -2
  52. package/dist/types/index.d.ts.map +1 -1
  53. package/dist/types/parser/client.d.ts +123 -0
  54. package/dist/types/parser/client.d.ts.map +1 -0
  55. package/dist/types/parser/complete.d.ts +90 -0
  56. package/dist/types/parser/complete.d.ts.map +1 -0
  57. package/dist/types/parser/index.d.ts +40 -0
  58. package/dist/types/parser/index.d.ts.map +1 -0
  59. package/dist/types/parser/inner.d.ts +114 -0
  60. package/dist/types/parser/inner.d.ts.map +1 -0
  61. package/dist/types/parser/instructions.d.ts +76 -0
  62. package/dist/types/parser/instructions.d.ts.map +1 -0
  63. package/dist/types/parser/transaction.d.ts +77 -0
  64. package/dist/types/parser/transaction.d.ts.map +1 -0
  65. package/dist/types/parser/types.d.ts +154 -0
  66. package/dist/types/parser/types.d.ts.map +1 -0
  67. package/package.json +6 -1
  68. package/src/core/client.ts +25 -0
  69. package/src/core/connection.ts +59 -7
  70. package/src/core/index.ts +2 -2
  71. package/src/index.ts +27 -2
  72. package/src/parser/client.ts +211 -0
  73. package/src/parser/complete.ts +232 -0
  74. package/src/parser/index.ts +71 -0
  75. package/src/parser/inner.ts +255 -0
  76. package/src/parser/instructions.ts +135 -0
  77. package/src/parser/transaction.ts +200 -0
  78. 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
+ }