diff --git a/packages/library-legacy/src/connection.ts b/packages/library-legacy/src/connection.ts index f0d2f772e8d8..a0fcd2e033d5 100644 --- a/packages/library-legacy/src/connection.ts +++ b/packages/library-legacy/src/connection.ts @@ -952,6 +952,8 @@ export type SimulateTransactionConfig = { }; /** Optional parameter used to specify the minimum block slot that can be used for simulation */ minContextSlot?: number; + /** Optional parameter used to include inner instructions in the simulation */ + innerInstructions?: boolean; }; export type SimulatedTransactionResponse = { @@ -960,7 +962,20 @@ export type SimulatedTransactionResponse = { accounts?: (SimulatedTransactionAccountInfo | null)[] | null; unitsConsumed?: number; returnData?: TransactionReturnData | null; + innerInstructions?: ParsedInnerInstruction[] | null; }; +const ParsedInstructionStruct = pick({ + program: string(), + programId: PublicKeyFromString, + parsed: unknown(), +}); + +const PartiallyDecodedInstructionStruct = pick({ + programId: PublicKeyFromString, + accounts: array(PublicKeyFromString), + data: string(), +}); + const SimulatedTransactionResponseStruct = jsonRpcResultAndContext( pick({ err: nullable(union([pick({}), string()])), @@ -989,6 +1004,21 @@ const SimulatedTransactionResponseStruct = jsonRpcResultAndContext( }), ), ), + innerInstructions: optional( + nullable( + array( + pick({ + index: number(), + instructions: array( + union([ + ParsedInstructionStruct, + PartiallyDecodedInstructionStruct, + ]), + ), + }), + ), + ), + ), }), ); @@ -5712,6 +5742,14 @@ export class Connection { config.commitment = this.commitment; } + if ( + configOrSigners && + typeof configOrSigners === 'object' && + 'innerInstructions' in configOrSigners + ) { + config.innerInstructions = configOrSigners.innerInstructions; + } + const args = [encodedTransaction, config]; const unsafeRes = await this._rpcRequest('simulateTransaction', args); const res = create(unsafeRes, SimulatedTransactionResponseStruct); @@ -5802,6 +5840,14 @@ export class Connection { config.sigVerify = true; } + if ( + configOrSigners && + typeof configOrSigners === 'object' && + 'innerInstructions' in configOrSigners + ) { + config.innerInstructions = configOrSigners.innerInstructions; + } + const args = [encodedTransaction, config]; const unsafeRes = await this._rpcRequest('simulateTransaction', args); const res = create(unsafeRes, SimulatedTransactionResponseStruct);