Skip to content

Commit 0936673

Browse files
feat(simulated_transaction): Add Inner Instructions (#2756)
* Add Inner Instructions to Simulated Transaction * Formatting * Nit: Change 'response' to 'simulation' * Update Types and Structs * Start Addressing Feedback * Stop Overthinking and Reuse Types lol * Format source code * Don't widen the type of `parsed` to `any` when parsing the server response, because that makes it optional on the result --------- Co-authored-by: steveluscher <[email protected]>
1 parent abecbe4 commit 0936673

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

packages/library-legacy/src/connection.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,8 @@ export type SimulateTransactionConfig = {
952952
};
953953
/** Optional parameter used to specify the minimum block slot that can be used for simulation */
954954
minContextSlot?: number;
955+
/** Optional parameter used to include inner instructions in the simulation */
956+
innerInstructions?: boolean;
955957
};
956958

957959
export type SimulatedTransactionResponse = {
@@ -960,7 +962,20 @@ export type SimulatedTransactionResponse = {
960962
accounts?: (SimulatedTransactionAccountInfo | null)[] | null;
961963
unitsConsumed?: number;
962964
returnData?: TransactionReturnData | null;
965+
innerInstructions?: ParsedInnerInstruction[] | null;
963966
};
967+
const ParsedInstructionStruct = pick({
968+
program: string(),
969+
programId: PublicKeyFromString,
970+
parsed: unknown(),
971+
});
972+
973+
const PartiallyDecodedInstructionStruct = pick({
974+
programId: PublicKeyFromString,
975+
accounts: array(PublicKeyFromString),
976+
data: string(),
977+
});
978+
964979
const SimulatedTransactionResponseStruct = jsonRpcResultAndContext(
965980
pick({
966981
err: nullable(union([pick({}), string()])),
@@ -989,6 +1004,21 @@ const SimulatedTransactionResponseStruct = jsonRpcResultAndContext(
9891004
}),
9901005
),
9911006
),
1007+
innerInstructions: optional(
1008+
nullable(
1009+
array(
1010+
pick({
1011+
index: number(),
1012+
instructions: array(
1013+
union([
1014+
ParsedInstructionStruct,
1015+
PartiallyDecodedInstructionStruct,
1016+
]),
1017+
),
1018+
}),
1019+
),
1020+
),
1021+
),
9921022
}),
9931023
);
9941024

@@ -5712,6 +5742,14 @@ export class Connection {
57125742
config.commitment = this.commitment;
57135743
}
57145744

5745+
if (
5746+
configOrSigners &&
5747+
typeof configOrSigners === 'object' &&
5748+
'innerInstructions' in configOrSigners
5749+
) {
5750+
config.innerInstructions = configOrSigners.innerInstructions;
5751+
}
5752+
57155753
const args = [encodedTransaction, config];
57165754
const unsafeRes = await this._rpcRequest('simulateTransaction', args);
57175755
const res = create(unsafeRes, SimulatedTransactionResponseStruct);
@@ -5802,6 +5840,14 @@ export class Connection {
58025840
config.sigVerify = true;
58035841
}
58045842

5843+
if (
5844+
configOrSigners &&
5845+
typeof configOrSigners === 'object' &&
5846+
'innerInstructions' in configOrSigners
5847+
) {
5848+
config.innerInstructions = configOrSigners.innerInstructions;
5849+
}
5850+
58055851
const args = [encodedTransaction, config];
58065852
const unsafeRes = await this._rpcRequest('simulateTransaction', args);
58075853
const res = create(unsafeRes, SimulatedTransactionResponseStruct);

0 commit comments

Comments
 (0)