Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(simulated_transaction): Add Inner Instructions #2756

Merged
merged 8 commits into from
Jun 29, 2024
Merged
46 changes: 46 additions & 0 deletions packages/library-legacy/src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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(),
});
0xIchigo marked this conversation as resolved.
Show resolved Hide resolved

const PartiallyDecodedInstructionStruct = pick({
programId: PublicKeyFromString,
0xIchigo marked this conversation as resolved.
Show resolved Hide resolved
accounts: array(PublicKeyFromString),
0xIchigo marked this conversation as resolved.
Show resolved Hide resolved
data: string(),
});

const SimulatedTransactionResponseStruct = jsonRpcResultAndContext(
pick({
err: nullable(union([pick({}), string()])),
Expand Down Expand Up @@ -989,6 +1004,21 @@ const SimulatedTransactionResponseStruct = jsonRpcResultAndContext(
}),
),
),
innerInstructions: optional(
nullable(
array(
pick({
index: number(),
instructions: array(
union([
ParsedInstructionStruct,
PartiallyDecodedInstructionStruct,
]),
),
}),
),
),
),
}),
);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down