@oobe-protocol-labs/synapse-sap-sdk 0.4.1 → 0.5.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/dist/cjs/constants/index.js +4 -1
- package/dist/cjs/constants/index.js.map +1 -1
- package/dist/cjs/constants/network.js +81 -0
- package/dist/cjs/constants/network.js.map +1 -0
- package/dist/cjs/core/client.js +23 -0
- package/dist/cjs/core/client.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/cjs/registries/x402.js +5 -2
- package/dist/cjs/registries/x402.js.map +1 -1
- package/dist/esm/constants/index.js +2 -0
- package/dist/esm/constants/index.js.map +1 -1
- package/dist/esm/constants/network.js +78 -0
- package/dist/esm/constants/network.js.map +1 -0
- package/dist/esm/core/client.js +23 -0
- package/dist/esm/core/client.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/esm/registries/x402.js +5 -2
- package/dist/esm/registries/x402.js.map +1 -1
- package/dist/types/constants/index.d.ts +2 -0
- package/dist/types/constants/index.d.ts.map +1 -1
- package/dist/types/constants/network.d.ts +81 -0
- package/dist/types/constants/network.d.ts.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/index.d.ts +5 -1
- 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/dist/types/registries/x402.d.ts +35 -2
- package/dist/types/registries/x402.d.ts.map +1 -1
- package/package.json +6 -1
- package/src/constants/index.ts +4 -0
- package/src/constants/network.ts +89 -0
- package/src/core/client.ts +25 -0
- package/src/index.ts +27 -0
- 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
- package/src/registries/x402.ts +38 -3
|
@@ -34,6 +34,7 @@ import { EscrowModule } from "../modules/escrow";
|
|
|
34
34
|
import { AttestationModule } from "../modules/attestation";
|
|
35
35
|
import { LedgerModule } from "../modules/ledger";
|
|
36
36
|
import { EventParser } from "../events";
|
|
37
|
+
import { TransactionParser } from "../parser/client";
|
|
37
38
|
import { DiscoveryRegistry } from "../registries/discovery";
|
|
38
39
|
import { X402Registry } from "../registries/x402";
|
|
39
40
|
import { SessionManager } from "../registries/session";
|
|
@@ -238,6 +239,24 @@ export declare class SapClient {
|
|
|
238
239
|
* @see {@link EventParser}
|
|
239
240
|
*/
|
|
240
241
|
get events(): EventParser;
|
|
242
|
+
/**
|
|
243
|
+
* @name parser
|
|
244
|
+
* @description Transaction parser: decode instruction names, arguments,
|
|
245
|
+
* accounts, inner CPI calls, and protocol events from raw transaction
|
|
246
|
+
* responses. Designed for indexers and explorers.
|
|
247
|
+
* @returns {TransactionParser} The lazily-instantiated `TransactionParser` singleton.
|
|
248
|
+
* @category Modules
|
|
249
|
+
* @since v0.5.0
|
|
250
|
+
* @see {@link TransactionParser}
|
|
251
|
+
*
|
|
252
|
+
* @example
|
|
253
|
+
* ```ts
|
|
254
|
+
* const tx = await connection.getTransaction(sig, { ... });
|
|
255
|
+
* const parsed = client.parser.parseTransaction(tx);
|
|
256
|
+
* console.log(parsed?.instructions.map(i => i.name));
|
|
257
|
+
* ```
|
|
258
|
+
*/
|
|
259
|
+
get parser(): TransactionParser;
|
|
241
260
|
/**
|
|
242
261
|
* @name discovery
|
|
243
262
|
* @description Agent & tool discovery across the SAP network.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/core/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAE,KAAK,cAAc,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAk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I,cAAc,CAE7B;IAED;;;;;;;;OAQG;IACH,IAAI,QAAQ,IAAI,cAAc,CAE7B;IAED;;;;;;;;OAQG;IACH,IAAI,KAAK,IAAI,WAAW,CAEvB;IAED;;;;;;;;OAQG;IACH,IAAI,KAAK,IAAI,WAAW,CAEvB;IAED;;;;;;;;OAQG;IACH,IAAI,MAAM,IAAI,YAAY,CAEzB;IAED;;;;;;;;OAQG;IACH,IAAI,WAAW,IAAI,iBAAiB,CAEnC;IAED;;;;;;;;OAQG;IACH,IAAI,MAAM,IAAI,YAAY,CAEzB;IAED;;;;;;;OAOG;IACH,IAAI,MAAM,IAAI,WAAW,CAExB;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,IAAI,MAAM,IAAI,iBAAiB,CAE9B;IAMD;;;;;;;;;;;;;;;;OAgBG;IACH,IAAI,SAAS,IAAI,iBAAiB,CAEjC;IAED;;;;;;;;;;;;;;;;;OAiBG;IACH,IAAI,IAAI,IAAI,YAAY,CAEvB;IAED;;;;;;;;;;;;;;;;;OAiBG;IACH,IAAI,OAAO,IAAI,cAAc,CAE5B;IAED;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,IAAI,OAAO,IAAI,YAAY,CAE1B;CACF"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
* | `modules/` | Low-level per-domain instruction wrappers |
|
|
16
16
|
* | `registries/` | High-level abstractions (discovery, x402, …) |
|
|
17
17
|
* | `plugin/` | SynapseAgentKit adapter (52 tools) |
|
|
18
|
+
* | `parser/` | Transaction decode, instruction + event parse |
|
|
18
19
|
* | `idl/` | Embedded Anchor IDL |
|
|
19
20
|
*
|
|
20
21
|
* @example
|
|
@@ -46,7 +47,8 @@ export { SapClient, SapConnection, KeypairWallet } from "./core";
|
|
|
46
47
|
export type { SapCluster, SapConnectionConfig, SapWallet } from "./core";
|
|
47
48
|
export type { TokenTypeKind, PluginTypeKind, SettlementModeKind, ToolHttpMethodKind, ToolCategoryKind, DelegatePermissionBit, SchemaTypeValue, CompressionTypeValue, Capability, VolumeCurveBreakpoint, PricingTier, PluginRef, Settlement, AgentAccountData, FeedbackAccountData, CapabilityIndexData, ProtocolIndexData, GlobalRegistryData, MemoryVaultData, SessionLedgerData, EpochPageData, VaultDelegateData, ToolDescriptorData, SessionCheckpointData, EscrowAccountData, AgentStatsData, ToolCategoryIndexData, AgentAttestationData, MemoryLedgerData, LedgerPageData, RegisterAgentArgs, UpdateAgentArgs, GiveFeedbackArgs, UpdateFeedbackArgs, PublishToolArgs, UpdateToolArgs, InscribeMemoryArgs, CompactInscribeArgs, CreateEscrowArgs, CreateAttestationArgs, InscribeToolSchemaArgs, } from "./types";
|
|
48
49
|
export { TokenType, PluginType, SettlementMode, ToolHttpMethod, ToolCategory, DelegatePermission, SchemaType, CompressionType, } from "./types";
|
|
49
|
-
export { SAP_PROGRAM_ADDRESS, SAP_PROGRAM_ID, MAINNET_SAP_PROGRAM_ID, DEVNET_SAP_PROGRAM_ID, LOCALNET_SAP_PROGRAM_ID, SEEDS, LIMITS, AGENT_VERSION, VAULT_PROTOCOL_VERSION, TOOL_CATEGORY_VALUES, HTTP_METHOD_VALUES, } from "./constants";
|
|
50
|
+
export { SAP_PROGRAM_ADDRESS, SAP_PROGRAM_ID, MAINNET_SAP_PROGRAM_ID, DEVNET_SAP_PROGRAM_ID, LOCALNET_SAP_PROGRAM_ID, SEEDS, LIMITS, AGENT_VERSION, VAULT_PROTOCOL_VERSION, TOOL_CATEGORY_VALUES, HTTP_METHOD_VALUES, SapNetwork, } from "./constants";
|
|
51
|
+
export type { SapNetworkId } from "./constants";
|
|
50
52
|
export { SAP_IDL, IDL_PROGRAM_ADDRESS, IDL_METADATA } from "./idl/index";
|
|
51
53
|
export type { SynapseAgentSapIDL } from "./idl/index";
|
|
52
54
|
export { deriveGlobalRegistry, deriveAgent, deriveAgentStats, deriveFeedback, deriveCapabilityIndex, deriveProtocolIndex, deriveToolCategoryIndex, deriveVault, deriveSession, deriveEpochPage, deriveVaultDelegate, deriveCheckpoint, deriveTool, deriveEscrow, deriveAttestation, deriveLedger, deriveLedgerPage, } from "./pda";
|
|
@@ -63,6 +65,8 @@ export type { ProtocolMethod, PluginProtocol, } from "./plugin/protocols";
|
|
|
63
65
|
export { SAP_PROTOCOLS } from "./plugin/protocols";
|
|
64
66
|
export { SapPostgres, SapSyncEngine, SAP_TABLE_MAP } from "./postgres";
|
|
65
67
|
export type { PgClient, SyncAllResult, SapAccountType, SyncMeta, AgentRow, EscrowRow, ToolRow, LedgerRow, EventRow, SyncCursorRow, SyncOptions, } from "./postgres";
|
|
68
|
+
export { parseSapInstructionsFromTransaction, parseSapInstructionNamesFromTransaction, parseSapInstructionsFromList, parseSapInstructionNamesFromList, containsSapInstruction, parseSapTransactionComplete, parseSapTransactionBatch, decodeInnerInstructions, filterSapInnerInstructions, extractAccountKeys, TransactionParser, } from "./parser";
|
|
69
|
+
export type { DecodedSapInstruction, DecodedInnerInstruction, ParsedSapTransaction, ParseFilterOptions, SapInstructionCoder, CompiledInner, InnerInstructionGroup, } from "./parser";
|
|
66
70
|
export { DiscoveryRegistry, X402Registry, SessionManager, AgentBuilder, } from "./registries/index";
|
|
67
71
|
export type { DiscoveredAgent, AgentProfile, DiscoveredTool, NetworkOverview, ToolCategoryName, CostEstimate, PaymentContext, PreparePaymentOptions, X402Headers, EscrowBalance, SettlementResult, BatchSettlementResult, SessionContext, WriteResult, SealResult, RingBufferEntry, SessionStatus, CapabilityInput, PricingTierInput, ToolInput, RegisterResult, RegisterWithToolsResult, } from "./registries/index";
|
|
68
72
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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W,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACvE,YAAY,EACV,QAAQ,EACR,aAAa,EACb,cAAc,EACd,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,OAAO,EACP,SAAS,EACT,QAAQ,EACR,aAAa,EACb,WAAW,GACZ,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,mCAAmC,EACnC,uCAAuC,EACvC,4BAA4B,EAC5B,gCAAgC,EAChC,sBAAsB,EACtB,2BAA2B,EAC3B,wBAAwB,EACxB,uBAAuB,EACvB,0BAA0B,EAC1B,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,UAAU,CAAC;AAClB,YAAY,EACV,qBAAqB,EACrB,uBAAuB,EACvB,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,EACnB,aAAa,EACb,qBAAqB,GACtB,MAAM,UAAU,CAAC;AAGlB,OAAO,EACL,iBAAiB,EACjB,YAAY,EACZ,cAAc,EACd,YAAY,GACb,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EACV,eAAe,EACf,YAAY,EACZ,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,YAAY,EACZ,cAAc,EACd,qBAAqB,EACrB,WAAW,EACX,aAAa,EACb,gBAAgB,EAChB,qBAAqB,EACrB,cAAc,EACd,WAAW,EACX,UAAU,EACV,eAAe,EACf,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,SAAS,EACT,cAAc,EACd,uBAAuB,GACxB,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module parser/client
|
|
3
|
+
* @description Object-oriented wrapper for transaction parsing.
|
|
4
|
+
*
|
|
5
|
+
* Binds the Anchor `Program` reference so callers do not need to
|
|
6
|
+
* pass it on every call. Designed as a lazy singleton accessible
|
|
7
|
+
* from {@link SapClient.parser}.
|
|
8
|
+
*
|
|
9
|
+
* @category Parser
|
|
10
|
+
* @since v0.5.0
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* const client = SapClient.from(provider);
|
|
15
|
+
*
|
|
16
|
+
* // Parse a full transaction
|
|
17
|
+
* const parsed = client.parser.parseTransaction(txResponse);
|
|
18
|
+
*
|
|
19
|
+
* // Quick instruction names
|
|
20
|
+
* const names = client.parser.instructionNames(txResponse);
|
|
21
|
+
*
|
|
22
|
+
* // From pre-built instructions
|
|
23
|
+
* const decoded = client.parser.fromInstructions(ixList);
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
import type { Program } from "@coral-xyz/anchor";
|
|
27
|
+
import type { TransactionInstruction, TransactionResponse, VersionedTransactionResponse } from "@solana/web3.js";
|
|
28
|
+
import { AddressLookupTableAccount } from "@solana/web3.js";
|
|
29
|
+
import type { DecodedSapInstruction, ParsedSapTransaction, ParseFilterOptions } from "./types";
|
|
30
|
+
import { type InnerInstructionGroup } from "./inner";
|
|
31
|
+
/**
|
|
32
|
+
* Stateful transaction parser bound to a specific Anchor `Program`.
|
|
33
|
+
*
|
|
34
|
+
* Stores the program reference, instruction coder, and program ID
|
|
35
|
+
* internally so that repeated parse calls require only the
|
|
36
|
+
* transaction data as input.
|
|
37
|
+
*
|
|
38
|
+
* @name TransactionParser
|
|
39
|
+
* @category Parser
|
|
40
|
+
* @since v0.5.0
|
|
41
|
+
*/
|
|
42
|
+
export declare class TransactionParser {
|
|
43
|
+
private readonly program;
|
|
44
|
+
private readonly coder;
|
|
45
|
+
private readonly programId;
|
|
46
|
+
/**
|
|
47
|
+
* Create a new TransactionParser.
|
|
48
|
+
*
|
|
49
|
+
* @param program - An Anchor `Program` built from the SAP IDL.
|
|
50
|
+
*/
|
|
51
|
+
constructor(program: Program<any>);
|
|
52
|
+
/**
|
|
53
|
+
* Full parse: instructions + inner calls + events.
|
|
54
|
+
*
|
|
55
|
+
* @param tx - Raw transaction response from `connection.getTransaction`.
|
|
56
|
+
* @param options - Optional filters for instructions, events, and inner calls.
|
|
57
|
+
* @param addressLookupTables - Resolved lookup tables for v0 transactions.
|
|
58
|
+
* @returns Complete parsed transaction, or `null` if the input is nullish.
|
|
59
|
+
*
|
|
60
|
+
* @since v0.5.0
|
|
61
|
+
*/
|
|
62
|
+
parseTransaction(tx: TransactionResponse | VersionedTransactionResponse | null | undefined, options?: ParseFilterOptions, addressLookupTables?: AddressLookupTableAccount[]): ParsedSapTransaction | null;
|
|
63
|
+
/**
|
|
64
|
+
* Parse a batch of transactions.
|
|
65
|
+
*
|
|
66
|
+
* @param txs - Array of transaction responses (may contain `null` entries).
|
|
67
|
+
* @param options - Optional parse filters.
|
|
68
|
+
* @param addressLookupTables - Resolved lookup tables for v0 transactions.
|
|
69
|
+
* @returns Non-null parsed transactions.
|
|
70
|
+
*
|
|
71
|
+
* @since v0.5.0
|
|
72
|
+
*/
|
|
73
|
+
parseBatch(txs: (TransactionResponse | VersionedTransactionResponse | null | undefined)[], options?: ParseFilterOptions, addressLookupTables?: AddressLookupTableAccount[]): ParsedSapTransaction[];
|
|
74
|
+
/**
|
|
75
|
+
* Decode top-level SAP instructions from a transaction response.
|
|
76
|
+
*
|
|
77
|
+
* @param tx - Raw transaction response.
|
|
78
|
+
* @param addressLookupTables - Resolved lookup tables for v0 transactions.
|
|
79
|
+
* @returns Decoded SAP instructions.
|
|
80
|
+
*
|
|
81
|
+
* @since v0.5.0
|
|
82
|
+
*/
|
|
83
|
+
instructionsFromTransaction(tx: TransactionResponse | VersionedTransactionResponse, addressLookupTables?: AddressLookupTableAccount[]): DecodedSapInstruction[];
|
|
84
|
+
/**
|
|
85
|
+
* Extract only the instruction names from a transaction response.
|
|
86
|
+
*
|
|
87
|
+
* @param tx - Raw transaction response.
|
|
88
|
+
* @param addressLookupTables - Resolved lookup tables for v0 transactions.
|
|
89
|
+
* @returns Instruction name strings.
|
|
90
|
+
*
|
|
91
|
+
* @since v0.5.0
|
|
92
|
+
*/
|
|
93
|
+
instructionNames(tx: TransactionResponse | VersionedTransactionResponse, addressLookupTables?: AddressLookupTableAccount[]): string[];
|
|
94
|
+
/**
|
|
95
|
+
* Decode SAP instructions from a pre-built instruction array.
|
|
96
|
+
*
|
|
97
|
+
* @param instructions - The instruction list to decode.
|
|
98
|
+
* @returns Decoded SAP instructions.
|
|
99
|
+
*
|
|
100
|
+
* @since v0.5.0
|
|
101
|
+
*/
|
|
102
|
+
fromInstructions(instructions: TransactionInstruction[]): DecodedSapInstruction[];
|
|
103
|
+
/**
|
|
104
|
+
* Check if any instruction in the list targets the SAP program.
|
|
105
|
+
*
|
|
106
|
+
* @param instructions - The instruction array to inspect.
|
|
107
|
+
* @returns `true` if at least one instruction targets SAP.
|
|
108
|
+
*
|
|
109
|
+
* @since v0.5.0
|
|
110
|
+
*/
|
|
111
|
+
isSapTransaction(instructions: TransactionInstruction[]): boolean;
|
|
112
|
+
/**
|
|
113
|
+
* Decode inner (CPI) instructions from transaction metadata.
|
|
114
|
+
*
|
|
115
|
+
* @param innerGroups - The `tx.meta.innerInstructions` array.
|
|
116
|
+
* @param tx - The transaction response (for account key resolution).
|
|
117
|
+
* @returns Decoded inner instructions.
|
|
118
|
+
*
|
|
119
|
+
* @since v0.5.0
|
|
120
|
+
*/
|
|
121
|
+
decodeInner(innerGroups: InnerInstructionGroup[], tx: TransactionResponse | VersionedTransactionResponse): import("./types").DecodedInnerInstruction[];
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/parser/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,KAAK,EAEV,sBAAsB,EACtB,mBAAmB,EACnB,4BAA4B,EAC7B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAE5D,OAAO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IACH,WAAW,CACT,WAAW,EAAE,qBAAqB,EAAE,EACpC,EAAE,EAAE,mBAAmB,GAAG,4BAA4B;CAUzD"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module parser/complete
|
|
3
|
+
* @description Full SAP transaction parser: instructions + args + accounts + events.
|
|
4
|
+
*
|
|
5
|
+
* This is "Case 2 Complete": given a raw transaction response, produce a
|
|
6
|
+
* single {@link ParsedSapTransaction} containing every decoded instruction,
|
|
7
|
+
* all inner (CPI) calls, and all SAP events extracted from the logs.
|
|
8
|
+
*
|
|
9
|
+
* Designed for indexer pipelines where the decode step must be pure,
|
|
10
|
+
* deterministic, and fully testable without an RPC connection.
|
|
11
|
+
*
|
|
12
|
+
* @category Parser
|
|
13
|
+
* @since v0.5.0
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { parseSapTransactionComplete } from "@synapse-sap/sdk/parser";
|
|
18
|
+
* import { SAP_PROGRAM_ID, SAP_IDL } from "@synapse-sap/sdk";
|
|
19
|
+
* import { Program } from "\@coral-xyz/anchor";
|
|
20
|
+
*
|
|
21
|
+
* const program = new Program(SAP_IDL, provider);
|
|
22
|
+
* const tx = await connection.getTransaction(sig, {
|
|
23
|
+
* commitment: "confirmed",
|
|
24
|
+
* maxSupportedTransactionVersion: 0,
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* const parsed = parseSapTransactionComplete(tx, program, SAP_PROGRAM_ID);
|
|
28
|
+
* console.log(parsed.instructions.map(i => i.name));
|
|
29
|
+
* console.log(parsed.events.map(e => e.name));
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
import { AddressLookupTableAccount, type PublicKey, type TransactionResponse, type VersionedTransactionResponse } from "@solana/web3.js";
|
|
33
|
+
import type { Program } from "@coral-xyz/anchor";
|
|
34
|
+
import type { ParsedSapTransaction, ParseFilterOptions } from "./types";
|
|
35
|
+
/**
|
|
36
|
+
* Parse a complete SAP transaction into a unified result.
|
|
37
|
+
*
|
|
38
|
+
* Combines three stages:
|
|
39
|
+
* 1. **Instruction decode** - top-level SAP instructions with args and accounts
|
|
40
|
+
* 2. **Inner instruction decode** - CPI calls with full account reconstruction
|
|
41
|
+
* 3. **Event extraction** - SAP events decoded from the transaction logs
|
|
42
|
+
*
|
|
43
|
+
* All three stages are safe: malformed data produces `null` fields
|
|
44
|
+
* rather than exceptions. This makes the function suitable for
|
|
45
|
+
* batch-processing in indexer workers where a single bad transaction
|
|
46
|
+
* must not halt the pipeline.
|
|
47
|
+
*
|
|
48
|
+
* @param tx - The raw transaction response from `connection.getTransaction`.
|
|
49
|
+
* @param program - An Anchor `Program` instance built from the SAP IDL.
|
|
50
|
+
* The coder and program ID are extracted automatically.
|
|
51
|
+
* @param sapProgramId - The SAP program public key. Passed explicitly so
|
|
52
|
+
* callers can target devnet/localnet deployments independently.
|
|
53
|
+
* @param options - Optional filters for instructions, events, and inner calls.
|
|
54
|
+
* @param addressLookupTables - Resolved lookup table accounts for v0 transactions.
|
|
55
|
+
* @returns A fully parsed transaction, or `null` if the input is `null`/`undefined`.
|
|
56
|
+
*
|
|
57
|
+
* @category Parser
|
|
58
|
+
* @since v0.5.0
|
|
59
|
+
*/
|
|
60
|
+
export declare function parseSapTransactionComplete(tx: TransactionResponse | VersionedTransactionResponse | null | undefined, program: Program<any>, sapProgramId: PublicKey, options?: ParseFilterOptions, addressLookupTables?: AddressLookupTableAccount[]): ParsedSapTransaction | null;
|
|
61
|
+
/**
|
|
62
|
+
* Parse multiple transactions in batch.
|
|
63
|
+
*
|
|
64
|
+
* Convenience wrapper for indexer pipelines that process pages of
|
|
65
|
+
* transactions. Skips `null` entries and failed decodes silently.
|
|
66
|
+
*
|
|
67
|
+
* @param txs - Array of transaction responses (may contain `null` entries).
|
|
68
|
+
* @param program - The Anchor SAP program instance.
|
|
69
|
+
* @param sapProgramId - The SAP program public key.
|
|
70
|
+
* @param options - Optional parse filters applied to every transaction.
|
|
71
|
+
* @param addressLookupTables - Lookup tables for v0 transactions.
|
|
72
|
+
* @returns An array of non-null parsed transactions.
|
|
73
|
+
*
|
|
74
|
+
* @category Parser
|
|
75
|
+
* @since v0.5.0
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* const signatures = await connection.getSignaturesForAddress(agentPda);
|
|
80
|
+
* const txs = await Promise.all(
|
|
81
|
+
* signatures.map(s => connection.getTransaction(s.signature, { ... }))
|
|
82
|
+
* );
|
|
83
|
+
* const parsed = parseSapTransactionBatch(txs, program, SAP_PROGRAM_ID, {
|
|
84
|
+
* includeEvents: true,
|
|
85
|
+
* includeInner: true,
|
|
86
|
+
* });
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
export declare function parseSapTransactionBatch(txs: (TransactionResponse | VersionedTransactionResponse | null | undefined)[], program: Program<any>, sapProgramId: PublicKey, options?: ParseFilterOptions, addressLookupTables?: AddressLookupTableAccount[]): ParsedSapTransaction[];
|
|
90
|
+
//# sourceMappingURL=complete.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"complete.d.ts","sourceRoot":"","sources":["../../../src/parser/complete.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,EACL,yBAAyB,EACzB,KAAK,SAAS,EACd,KAAK,mBAAmB,EACxB,KAAK,4BAA4B,EAClC,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,KAAK,EACV,oBAAoB,EACpB,kBAAkB,EAGnB,MAAM,SAAS,CAAC;AAcjB;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,2BAA2B,CACzC,EAAE,EAAE,mBAAmB,GAAG,4BAA4B,GAAG,IAAI,GAAG,SAAS,EAEzE,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,EACrB,YAAY,EAAE,SAAS,EACvB,OAAO,CAAC,EAAE,kBAAkB,EAC5B,mBAAmB,CAAC,EAAE,yBAAyB,EAAE,GAChD,oBAAoB,GAAG,IAAI,CAoE7B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,wBAAwB,CACtC,GAAG,EAAE,CAAC,mBAAmB,GAAG,4BAA4B,GAAG,IAAI,GAAG,SAAS,CAAC,EAAE,EAE9E,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,EACrB,YAAY,EAAE,SAAS,EACvB,OAAO,CAAC,EAAE,kBAAkB,EAC5B,mBAAmB,CAAC,EAAE,yBAAyB,EAAE,GAChD,oBAAoB,EAAE,CAaxB"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module parser
|
|
3
|
+
* @description Transaction parsing utilities for SAP v2.
|
|
4
|
+
*
|
|
5
|
+
* Provides modular, composable functions for decoding on-chain SAP
|
|
6
|
+
* transactions into typed instruction data, argument objects, account
|
|
7
|
+
* lists, and protocol events.
|
|
8
|
+
*
|
|
9
|
+
* Three levels of parsing are available depending on your use case:
|
|
10
|
+
*
|
|
11
|
+
* | Function | Input | Output |
|
|
12
|
+
* |----------|-------|--------|
|
|
13
|
+
* | `parseSapInstructionsFromTransaction` | `TransactionResponse` (RPC) | Decoded instructions |
|
|
14
|
+
* | `parseSapInstructionsFromList` | `TransactionInstruction[]` | Decoded instructions |
|
|
15
|
+
* | `parseSapTransactionComplete` | `TransactionResponse` (RPC) | Instructions + events + inner calls |
|
|
16
|
+
*
|
|
17
|
+
* All functions are pure and stateless: they accept the Anchor coder
|
|
18
|
+
* (or full Program) as a parameter, making them safe for server-side
|
|
19
|
+
* indexer workers, edge functions (Node.js runtime), and test suites.
|
|
20
|
+
*
|
|
21
|
+
* @category Parser
|
|
22
|
+
* @since v0.5.0
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* import {
|
|
27
|
+
* parseSapTransactionComplete,
|
|
28
|
+
* parseSapInstructionsFromList,
|
|
29
|
+
* containsSapInstruction,
|
|
30
|
+
* } from "@synapse-sap/sdk/parser";
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export type { DecodedSapInstruction, DecodedInnerInstruction, ParsedSapTransaction, ParseFilterOptions, SapInstructionCoder, } from "./types";
|
|
34
|
+
export { parseSapInstructionsFromTransaction, parseSapInstructionNamesFromTransaction, } from "./transaction";
|
|
35
|
+
export { parseSapInstructionsFromList, parseSapInstructionNamesFromList, containsSapInstruction, } from "./instructions";
|
|
36
|
+
export { parseSapTransactionComplete, parseSapTransactionBatch, } from "./complete";
|
|
37
|
+
export { decodeInnerInstructions, filterSapInnerInstructions, extractAccountKeys, } from "./inner";
|
|
38
|
+
export type { CompiledInner, InnerInstructionGroup } from "./inner";
|
|
39
|
+
export { TransactionParser } from "./client";
|
|
40
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/parser/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAGH,YAAY,EACV,qBAAqB,EACrB,uBAAuB,EACvB,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,mCAAmC,EACnC,uCAAuC,GACxC,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,4BAA4B,EAC5B,gCAAgC,EAChC,sBAAsB,GACvB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACL,2BAA2B,EAC3B,wBAAwB,GACzB,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,uBAAuB,EACvB,0BAA0B,EAC1B,kBAAkB,GACnB,MAAM,SAAS,CAAC;AACjB,YAAY,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAGpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module parser/inner
|
|
3
|
+
* @description Decode inner (CPI) instructions from transaction metadata.
|
|
4
|
+
*
|
|
5
|
+
* When a SAP instruction triggers cross-program invocations, the
|
|
6
|
+
* resulting inner instructions appear in `tx.meta.innerInstructions`.
|
|
7
|
+
* These are stored in a "compiled" format that references account
|
|
8
|
+
* indices rather than full public keys.
|
|
9
|
+
*
|
|
10
|
+
* This module reconstructs the full account keys from the transaction
|
|
11
|
+
* message's account list and decodes any inner calls that target the
|
|
12
|
+
* SAP program.
|
|
13
|
+
*
|
|
14
|
+
* @category Parser
|
|
15
|
+
* @since v0.5.0
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { decodeInnerInstructions } from "@synapse-sap/sdk/parser";
|
|
20
|
+
*
|
|
21
|
+
* const inner = decodeInnerInstructions(
|
|
22
|
+
* tx.meta?.innerInstructions ?? [],
|
|
23
|
+
* accountKeys,
|
|
24
|
+
* program.coder.instruction,
|
|
25
|
+
* SAP_PROGRAM_ID,
|
|
26
|
+
* );
|
|
27
|
+
* for (const cpi of inner) {
|
|
28
|
+
* if (cpi.name) console.log("SAP CPI:", cpi.name);
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
import { PublicKey } from "@solana/web3.js";
|
|
33
|
+
import type { DecodedInnerInstruction, SapInstructionCoder } from "./types";
|
|
34
|
+
/**
|
|
35
|
+
* Shape of a single compiled inner instruction from `tx.meta.innerInstructions`.
|
|
36
|
+
* Mirrors the Solana RPC `CompiledInnerInstruction` format.
|
|
37
|
+
*
|
|
38
|
+
* @interface CompiledInner
|
|
39
|
+
* @category Parser
|
|
40
|
+
* @since v0.5.0
|
|
41
|
+
*/
|
|
42
|
+
export interface CompiledInner {
|
|
43
|
+
readonly programIdIndex: number;
|
|
44
|
+
readonly accounts: number[];
|
|
45
|
+
readonly data: string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Top-level inner instruction group from the transaction metadata.
|
|
49
|
+
* Each group corresponds to one outer instruction by `index`.
|
|
50
|
+
*
|
|
51
|
+
* @interface InnerInstructionGroup
|
|
52
|
+
* @category Parser
|
|
53
|
+
* @since v0.5.0
|
|
54
|
+
*/
|
|
55
|
+
export interface InnerInstructionGroup {
|
|
56
|
+
readonly index: number;
|
|
57
|
+
readonly instructions: CompiledInner[];
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Decode inner (CPI) instructions from transaction metadata.
|
|
61
|
+
*
|
|
62
|
+
* Reconstructs full public keys from the compiled account indices
|
|
63
|
+
* and attempts to decode each inner instruction that targets the
|
|
64
|
+
* SAP program. Non-SAP inner instructions are included in the
|
|
65
|
+
* result with `name: null` and `args: null`.
|
|
66
|
+
*
|
|
67
|
+
* @param innerInstructionGroups - The `tx.meta.innerInstructions` array.
|
|
68
|
+
* @param accountKeys - Ordered list of all account public keys from the
|
|
69
|
+
* transaction message (`staticAccountKeys` for versioned, or
|
|
70
|
+
* `accountKeys` for legacy).
|
|
71
|
+
* @param coder - An Anchor instruction coder built from the SAP IDL.
|
|
72
|
+
* @param sapProgramId - The SAP program public key.
|
|
73
|
+
* @returns An array of decoded inner instructions.
|
|
74
|
+
*
|
|
75
|
+
* @category Parser
|
|
76
|
+
* @since v0.5.0
|
|
77
|
+
*/
|
|
78
|
+
export declare function decodeInnerInstructions(innerInstructionGroups: InnerInstructionGroup[], accountKeys: PublicKey[], coder: SapInstructionCoder, sapProgramId: PublicKey): DecodedInnerInstruction[];
|
|
79
|
+
/**
|
|
80
|
+
* Filter decoded inner instructions to only those targeting the SAP program.
|
|
81
|
+
*
|
|
82
|
+
* @param inner - The full inner instruction list from {@link decodeInnerInstructions}.
|
|
83
|
+
* @returns Only inner instructions where `name` is not `null`.
|
|
84
|
+
*
|
|
85
|
+
* @category Parser
|
|
86
|
+
* @since v0.5.0
|
|
87
|
+
*/
|
|
88
|
+
export declare function filterSapInnerInstructions(inner: DecodedInnerInstruction[]): DecodedInnerInstruction[];
|
|
89
|
+
/**
|
|
90
|
+
* Extract the full ordered list of account keys from a transaction
|
|
91
|
+
* response, handling both legacy and versioned formats.
|
|
92
|
+
*
|
|
93
|
+
* For versioned transactions that include loaded addresses (from
|
|
94
|
+
* address lookup tables), these are appended after the static keys
|
|
95
|
+
* in the order: static, writable loaded, readonly loaded.
|
|
96
|
+
*
|
|
97
|
+
* @param tx - The raw transaction response from RPC.
|
|
98
|
+
* @returns An ordered array of all account public keys.
|
|
99
|
+
*
|
|
100
|
+
* @category Parser
|
|
101
|
+
* @since v0.5.0
|
|
102
|
+
*/
|
|
103
|
+
export declare function extractAccountKeys(tx: {
|
|
104
|
+
transaction: {
|
|
105
|
+
message: any;
|
|
106
|
+
};
|
|
107
|
+
meta?: {
|
|
108
|
+
loadedAddresses?: {
|
|
109
|
+
writable: PublicKey[];
|
|
110
|
+
readonly: PublicKey[];
|
|
111
|
+
} | null;
|
|
112
|
+
} | null;
|
|
113
|
+
}): PublicKey[];
|
|
114
|
+
//# sourceMappingURL=inner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inner.d.ts","sourceRoot":"","sources":["../../../src/parser/inner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,KAAK,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAM5E;;;;;;;GAOG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,YAAY,EAAE,aAAa,EAAE,CAAC;CACxC;AAMD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,uBAAuB,CACrC,sBAAsB,EAAE,qBAAqB,EAAE,EAC/C,WAAW,EAAE,SAAS,EAAE,EACxB,KAAK,EAAE,mBAAmB,EAC1B,YAAY,EAAE,SAAS,GACtB,uBAAuB,EAAE,CAwC3B;AAED;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,uBAAuB,EAAE,GAC/B,uBAAuB,EAAE,CAE3B;AAMD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,CAChC,EAAE,EAAE;IACF,WAAW,EAAE;QAEX,OAAO,EAAE,GAAG,CAAC;KACd,CAAC;IACF,IAAI,CAAC,EAAE;QACL,eAAe,CAAC,EAAE;YAChB,QAAQ,EAAE,SAAS,EAAE,CAAC;YACtB,QAAQ,EAAE,SAAS,EAAE,CAAC;SACvB,GAAG,IAAI,CAAC;KACV,GAAG,IAAI,CAAC;CACV,GACA,SAAS,EAAE,CAuBb"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module parser/instructions
|
|
3
|
+
* @description Decode SAP instruction names from a pre-built `TransactionInstruction[]`.
|
|
4
|
+
*
|
|
5
|
+
* This is "Case 2B": you already have the decompiled instruction list
|
|
6
|
+
* (for example, from a UI that constructs instructions before sending)
|
|
7
|
+
* and want to identify which ones target the SAP program.
|
|
8
|
+
*
|
|
9
|
+
* @category Parser
|
|
10
|
+
* @since v0.5.0
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { parseSapInstructionsFromList } from "@synapse-sap/sdk/parser";
|
|
15
|
+
* import { SAP_PROGRAM_ID } from "@synapse-sap/sdk";
|
|
16
|
+
*
|
|
17
|
+
* const decoded = parseSapInstructionsFromList(
|
|
18
|
+
* instructions,
|
|
19
|
+
* program.coder.instruction,
|
|
20
|
+
* SAP_PROGRAM_ID,
|
|
21
|
+
* );
|
|
22
|
+
* for (const ix of decoded) {
|
|
23
|
+
* console.log(ix.name, ix.args);
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
import type { PublicKey, TransactionInstruction } from "@solana/web3.js";
|
|
28
|
+
import type { DecodedSapInstruction, SapInstructionCoder } from "./types";
|
|
29
|
+
/**
|
|
30
|
+
* Decode an array of `TransactionInstruction` and return only the
|
|
31
|
+
* SAP instructions with their decoded names and arguments.
|
|
32
|
+
*
|
|
33
|
+
* Non-SAP instructions (system, token, other programs) are silently
|
|
34
|
+
* skipped. Instructions whose data cannot be decoded against the IDL
|
|
35
|
+
* are still included with `name: "unknown"` and `args: null` so that
|
|
36
|
+
* consumers can detect IDL mismatches or unsupported instruction
|
|
37
|
+
* variants.
|
|
38
|
+
*
|
|
39
|
+
* @param instructions - The instruction array to inspect.
|
|
40
|
+
* @param coder - An Anchor instruction coder built from the SAP IDL.
|
|
41
|
+
* @param sapProgramId - The SAP program public key to filter by.
|
|
42
|
+
* @returns An array of decoded SAP instructions.
|
|
43
|
+
*
|
|
44
|
+
* @category Parser
|
|
45
|
+
* @since v0.5.0
|
|
46
|
+
*/
|
|
47
|
+
export declare function parseSapInstructionsFromList(instructions: TransactionInstruction[], coder: SapInstructionCoder, sapProgramId: PublicKey): DecodedSapInstruction[];
|
|
48
|
+
/**
|
|
49
|
+
* Return only the instruction names for SAP instructions in the list.
|
|
50
|
+
*
|
|
51
|
+
* Convenience wrapper over {@link parseSapInstructionsFromList} for
|
|
52
|
+
* callers that only need the string names.
|
|
53
|
+
*
|
|
54
|
+
* @param instructions - The instruction array to inspect.
|
|
55
|
+
* @param coder - An Anchor instruction coder for the SAP IDL.
|
|
56
|
+
* @param sapProgramId - The SAP program public key.
|
|
57
|
+
* @returns An array of instruction name strings.
|
|
58
|
+
*
|
|
59
|
+
* @category Parser
|
|
60
|
+
* @since v0.5.0
|
|
61
|
+
*/
|
|
62
|
+
export declare function parseSapInstructionNamesFromList(instructions: TransactionInstruction[], coder: SapInstructionCoder, sapProgramId: PublicKey): string[];
|
|
63
|
+
/**
|
|
64
|
+
* Check whether any instruction in the list targets the SAP program.
|
|
65
|
+
*
|
|
66
|
+
* Useful as a fast pre-filter before committing to a full decode pass.
|
|
67
|
+
*
|
|
68
|
+
* @param instructions - The instruction array to inspect.
|
|
69
|
+
* @param sapProgramId - The SAP program public key.
|
|
70
|
+
* @returns `true` if at least one instruction targets the SAP program.
|
|
71
|
+
*
|
|
72
|
+
* @category Parser
|
|
73
|
+
* @since v0.5.0
|
|
74
|
+
*/
|
|
75
|
+
export declare function containsSapInstruction(instructions: TransactionInstruction[], sapProgramId: PublicKey): boolean;
|
|
76
|
+
//# sourceMappingURL=instructions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instructions.d.ts","sourceRoot":"","sources":["../../../src/parser/instructions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACzE,OAAO,KAAK,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAM1E;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,4BAA4B,CAC1C,YAAY,EAAE,sBAAsB,EAAE,EACtC,KAAK,EAAE,mBAAmB,EAC1B,YAAY,EAAE,SAAS,GACtB,qBAAqB,EAAE,CAgBzB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,gCAAgC,CAC9C,YAAY,EAAE,sBAAsB,EAAE,EACtC,KAAK,EAAE,mBAAmB,EAC1B,YAAY,EAAE,SAAS,GACtB,MAAM,EAAE,CAIV;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CACpC,YAAY,EAAE,sBAAsB,EAAE,EACtC,YAAY,EAAE,SAAS,GACtB,OAAO,CAET"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module parser/transaction
|
|
3
|
+
* @description Decode SAP instruction names from a raw `TransactionResponse`.
|
|
4
|
+
*
|
|
5
|
+
* This is "Case 2A": you have a transaction response object obtained
|
|
6
|
+
* from `connection.getTransaction(signature, ...)` and need to extract
|
|
7
|
+
* the SAP instruction names, arguments, and account keys.
|
|
8
|
+
*
|
|
9
|
+
* The function handles both legacy and versioned (v0) transactions
|
|
10
|
+
* by decompiling the message into `TransactionInstruction[]` and then
|
|
11
|
+
* filtering for instructions whose `programId` matches the SAP program.
|
|
12
|
+
*
|
|
13
|
+
* @category Parser
|
|
14
|
+
* @since v0.5.0
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { parseSapInstructionsFromTransaction } from "@synapse-sap/sdk/parser";
|
|
19
|
+
* import { SAP_PROGRAM_ID } from "@synapse-sap/sdk";
|
|
20
|
+
*
|
|
21
|
+
* const tx = await connection.getTransaction(sig, {
|
|
22
|
+
* commitment: "confirmed",
|
|
23
|
+
* maxSupportedTransactionVersion: 0,
|
|
24
|
+
* });
|
|
25
|
+
* if (!tx) throw new Error("Transaction not found");
|
|
26
|
+
*
|
|
27
|
+
* const decoded = parseSapInstructionsFromTransaction(
|
|
28
|
+
* tx,
|
|
29
|
+
* program.coder.instruction,
|
|
30
|
+
* SAP_PROGRAM_ID,
|
|
31
|
+
* );
|
|
32
|
+
* for (const ix of decoded) {
|
|
33
|
+
* console.log(ix.name, ix.args);
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
import { AddressLookupTableAccount, type PublicKey, type VersionedTransactionResponse, type TransactionResponse } from "@solana/web3.js";
|
|
38
|
+
import type { DecodedSapInstruction, SapInstructionCoder } from "./types";
|
|
39
|
+
/**
|
|
40
|
+
* Extract and decode SAP instructions from a transaction response.
|
|
41
|
+
*
|
|
42
|
+
* Supports both legacy (`TransactionResponse`) and versioned
|
|
43
|
+
* (`VersionedTransactionResponse`) formats. For versioned
|
|
44
|
+
* transactions that use address lookup tables, pass the resolved
|
|
45
|
+
* lookup table accounts so that `TransactionMessage.decompile`
|
|
46
|
+
* can reconstruct the full account list.
|
|
47
|
+
*
|
|
48
|
+
* @param tx - The transaction response from `connection.getTransaction`.
|
|
49
|
+
* @param coder - An Anchor instruction coder built from the SAP IDL.
|
|
50
|
+
* @param sapProgramId - The SAP program public key to filter by.
|
|
51
|
+
* @param addressLookupTables - Resolved lookup table accounts for v0 transactions.
|
|
52
|
+
* Required when the transaction uses address lookup tables; omit for legacy txs.
|
|
53
|
+
* @returns An array of decoded SAP instructions found in the transaction.
|
|
54
|
+
*
|
|
55
|
+
* @throws {Error} When the transaction message cannot be decompiled.
|
|
56
|
+
*
|
|
57
|
+
* @category Parser
|
|
58
|
+
* @since v0.5.0
|
|
59
|
+
*/
|
|
60
|
+
export declare function parseSapInstructionsFromTransaction(tx: TransactionResponse | VersionedTransactionResponse, coder: SapInstructionCoder, sapProgramId: PublicKey, addressLookupTables?: AddressLookupTableAccount[]): DecodedSapInstruction[];
|
|
61
|
+
/**
|
|
62
|
+
* Extract only the SAP instruction names from a transaction response.
|
|
63
|
+
*
|
|
64
|
+
* Lighter-weight alternative to {@link parseSapInstructionsFromTransaction}
|
|
65
|
+
* when you only need the instruction names without decoded arguments.
|
|
66
|
+
*
|
|
67
|
+
* @param tx - The transaction response.
|
|
68
|
+
* @param coder - An Anchor instruction coder built from the SAP IDL.
|
|
69
|
+
* @param sapProgramId - The SAP program public key.
|
|
70
|
+
* @param addressLookupTables - Resolved lookup table accounts for v0 transactions.
|
|
71
|
+
* @returns An array of instruction name strings.
|
|
72
|
+
*
|
|
73
|
+
* @category Parser
|
|
74
|
+
* @since v0.5.0
|
|
75
|
+
*/
|
|
76
|
+
export declare function parseSapInstructionNamesFromTransaction(tx: TransactionResponse | VersionedTransactionResponse, coder: SapInstructionCoder, sapProgramId: PublicKey, addressLookupTables?: AddressLookupTableAccount[]): string[];
|
|
77
|
+
//# sourceMappingURL=transaction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../../../src/parser/transaction.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,OAAO,EAEL,yBAAyB,EACzB,KAAK,SAAS,EAEd,KAAK,4BAA4B,EACjC,KAAK,mBAAmB,EACzB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAM1E;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,mCAAmC,CACjD,EAAE,EAAE,mBAAmB,GAAG,4BAA4B,EACtD,KAAK,EAAE,mBAAmB,EAC1B,YAAY,EAAE,SAAS,EACvB,mBAAmB,CAAC,EAAE,yBAAyB,EAAE,GAChD,qBAAqB,EAAE,CAGzB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,uCAAuC,CACrD,EAAE,EAAE,mBAAmB,GAAG,4BAA4B,EACtD,KAAK,EAAE,mBAAmB,EAC1B,YAAY,EAAE,SAAS,EACvB,mBAAmB,CAAC,EAAE,yBAAyB,EAAE,GAChD,MAAM,EAAE,CAOV"}
|