/** * @module parser/inner * @description Decode inner (CPI) instructions from transaction metadata. * * When a SAP instruction triggers cross-program invocations, the * resulting inner instructions appear in `tx.meta.innerInstructions`. * These are stored in a "compiled" format that references account * indices rather than full public keys. * * This module reconstructs the full account keys from the transaction * message's account list and decodes any inner calls that target the * SAP program. * * @category Parser * @since v0.5.0 * * @example * ```ts * import { decodeInnerInstructions } from "@synapse-sap/sdk/parser"; * * const inner = decodeInnerInstructions( * tx.meta?.innerInstructions ?? [], * accountKeys, * program.coder.instruction, * SAP_PROGRAM_ID, * ); * for (const cpi of inner) { * if (cpi.name) console.log("SAP CPI:", cpi.name); * } * ``` */ import { PublicKey } from "@solana/web3.js"; import type { DecodedInnerInstruction, SapInstructionCoder } from "./types"; /** * Shape of a single compiled inner instruction from `tx.meta.innerInstructions`. * Mirrors the Solana RPC `CompiledInnerInstruction` format. * * @interface CompiledInner * @category Parser * @since v0.5.0 */ export interface CompiledInner { readonly programIdIndex: number; readonly accounts: number[]; readonly data: string; } /** * Top-level inner instruction group from the transaction metadata. * Each group corresponds to one outer instruction by `index`. * * @interface InnerInstructionGroup * @category Parser * @since v0.5.0 */ export interface InnerInstructionGroup { readonly index: number; readonly instructions: CompiledInner[]; } /** * Decode inner (CPI) instructions from transaction metadata. * * Reconstructs full public keys from the compiled account indices * and attempts to decode each inner instruction that targets the * SAP program. Non-SAP inner instructions are included in the * result with `name: null` and `args: null`. * * @param innerInstructionGroups - The `tx.meta.innerInstructions` array. * @param accountKeys - Ordered list of all account public keys from the * transaction message (`staticAccountKeys` for versioned, or * `accountKeys` for legacy). * @param coder - An Anchor instruction coder built from the SAP IDL. * @param sapProgramId - The SAP program public key. * @returns An array of decoded inner instructions. * * @category Parser * @since v0.5.0 */ export declare function decodeInnerInstructions(innerInstructionGroups: InnerInstructionGroup[], accountKeys: PublicKey[], coder: SapInstructionCoder, sapProgramId: PublicKey): DecodedInnerInstruction[]; /** * Filter decoded inner instructions to only those targeting the SAP program. * * @param inner - The full inner instruction list from {@link decodeInnerInstructions}. * @returns Only inner instructions where `name` is not `null`. * * @category Parser * @since v0.5.0 */ export declare function filterSapInnerInstructions(inner: DecodedInnerInstruction[]): DecodedInnerInstruction[]; /** * Extract the full ordered list of account keys from a transaction * response, handling both legacy and versioned formats. * * For versioned transactions that include loaded addresses (from * address lookup tables), these are appended after the static keys * in the order: static, writable loaded, readonly loaded. * * @param tx - The raw transaction response from RPC. * @returns An ordered array of all account public keys. * * @category Parser * @since v0.5.0 */ export declare function extractAccountKeys(tx: { transaction: { message: any; }; meta?: { loadedAddresses?: { writable: PublicKey[]; readonly: PublicKey[]; } | null; } | null; }): PublicKey[]; //# sourceMappingURL=inner.d.ts.map