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

You can now request innerInstructions with simulation #2868

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/calm-camels-decide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@solana/rpc-api': patch
---

The `simulateTransaction` RPC method now accepts an `innerInstructions` param. When `true`, the simulation result will include an array of inner instructions, if any.
100 changes: 100 additions & 0 deletions packages/rpc-api/src/simulateTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import type {
Slot,
SolanaRpcResponse,
TransactionError,
TransactionForFullMetaInnerInstructionsParsed,
TransactionForFullMetaInnerInstructionsUnparsed,
U64UnsafeBeyond2Pow53Minus1,
} from '@solana/rpc-types';
import type { Base64EncodedWireTransaction } from '@solana/transactions';
Expand All @@ -21,6 +23,12 @@ type SimulateTransactionConfigBase = Readonly<{
* @defaultValue finalized
* */
commitment?: Commitment;
/**
* If `true` the response will include inner instructions. These inner instructions will be
* `jsonParsed` where possible, otherwise `json`.
* @defaultValue false
*/
innerInstructions?: boolean;
/** The minimum slot that the request can be evaluated at */
minContextSlot?: Slot;
}>;
Expand Down Expand Up @@ -74,6 +82,10 @@ type AccountsConfigWithBase64Encoding = Readonly<{
};
}>;

type WithInnerInstructionsConfig = Readonly<{
innerInstructions: true;
}>;

type SimulateTransactionApiResponseBase = SolanaRpcResponse<{
/** Error if transaction failed, null if transaction succeeded. */
err: TransactionError | null;
Expand All @@ -95,7 +107,22 @@ type SimulateTransactionApiResponseWithAccounts<T extends AccountInfoBase> = Sol
accounts: (T | null)[];
}>;

type SimulateTransactionApiResponseWithInnerInstructions = SolanaRpcResponse<
TransactionForFullMetaInnerInstructionsParsed | TransactionForFullMetaInnerInstructionsUnparsed
>;

Comment on lines +110 to +113
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Starting to regret what I might have signed up for with this comment....

export interface SimulateTransactionApi extends RpcApiMethods {
Copy link
Collaborator Author

@steveluscher steveluscher Jun 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to double the number of overloads here, to be able to express ‘inner instructions on’ and ‘inner instructions off’ :(

This still keeps us under the (current) max of 24, but as soon as we want to add replacedBlockhash to the response, we're hosed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh crap that's rough.

/** @deprecated Set `encoding` to `'base64'` when calling this method */
simulateTransaction(
base58EncodedWireTransaction: Base58EncodedBytes,
config: AccountsConfigWithBase64Encoding &
SigVerifyAndReplaceRecentBlockhashConfig &
SimulateTransactionConfigBase &
WithInnerInstructionsConfig,
): SimulateTransactionApiResponseBase &
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithBase64EncodedData> &
SimulateTransactionApiResponseWithInnerInstructions;

/** @deprecated Set `encoding` to `'base64'` when calling this method */
simulateTransaction(
base58EncodedWireTransaction: Base58EncodedBytes,
Expand All @@ -105,6 +132,17 @@ export interface SimulateTransactionApi extends RpcApiMethods {
): SimulateTransactionApiResponseBase &
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithBase64EncodedData>;

/** @deprecated Set `encoding` to `'base64'` when calling this method */
simulateTransaction(
base58EncodedWireTransaction: Base58EncodedBytes,
config: AccountsConfigWithBase64EncodingZstdCompression &
SigVerifyAndReplaceRecentBlockhashConfig &
SimulateTransactionConfigBase &
WithInnerInstructionsConfig,
): SimulateTransactionApiResponseBase &
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithBase64EncodedZStdCompressedData> &
SimulateTransactionApiResponseWithInnerInstructions;

/** @deprecated Set `encoding` to `'base64'` when calling this method */
simulateTransaction(
base58EncodedWireTransaction: Base58EncodedBytes,
Expand All @@ -114,6 +152,17 @@ export interface SimulateTransactionApi extends RpcApiMethods {
): SimulateTransactionApiResponseBase &
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithBase64EncodedZStdCompressedData>;

/** @deprecated Set `encoding` to `'base64'` when calling this method */
simulateTransaction(
base58EncodedWireTransaction: Base58EncodedBytes,
config: AccountsConfigWithJsonParsedEncoding &
SigVerifyAndReplaceRecentBlockhashConfig &
SimulateTransactionConfigBase &
WithInnerInstructionsConfig,
): SimulateTransactionApiResponseBase &
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithJsonData> &
SimulateTransactionApiResponseWithInnerInstructions;

/** @deprecated Set `encoding` to `'base64'` when calling this method */
simulateTransaction(
base58EncodedWireTransaction: Base58EncodedBytes,
Expand All @@ -123,12 +172,31 @@ export interface SimulateTransactionApi extends RpcApiMethods {
): SimulateTransactionApiResponseBase &
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithJsonData>;

/** @deprecated Set `encoding` to `'base64'` when calling this method */
simulateTransaction(
base58EncodedWireTransaction: Base58EncodedBytes,
config?: SigVerifyAndReplaceRecentBlockhashConfig & SimulateTransactionConfigBase & WithInnerInstructionsConfig,
): SimulateTransactionApiResponseBase &
SimulateTransactionApiResponseWithInnerInstructions &
SolanaRpcResponse<{ readonly accounts: null }>;

/** @deprecated Set `encoding` to `'base64'` when calling this method */
simulateTransaction(
base58EncodedWireTransaction: Base58EncodedBytes,
config?: SigVerifyAndReplaceRecentBlockhashConfig & SimulateTransactionConfigBase,
): SimulateTransactionApiResponseBase & SolanaRpcResponse<{ readonly accounts: null }>;

/** Simulate sending a transaction */
simulateTransaction(
base64EncodedWireTransaction: Base64EncodedWireTransaction,
config: AccountsConfigWithBase64Encoding &
SigVerifyAndReplaceRecentBlockhashConfig &
SimulateTransactionConfigBase &
WithInnerInstructionsConfig & { encoding: 'base64' },
): SimulateTransactionApiResponseBase &
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithBase64EncodedData> &
SimulateTransactionApiResponseWithInnerInstructions;

/** Simulate sending a transaction */
simulateTransaction(
base64EncodedWireTransaction: Base64EncodedWireTransaction,
Expand All @@ -138,6 +206,17 @@ export interface SimulateTransactionApi extends RpcApiMethods {
): SimulateTransactionApiResponseBase &
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithBase64EncodedData>;

/** Simulate sending a transaction */
simulateTransaction(
base64EncodedWireTransaction: Base64EncodedWireTransaction,
config: AccountsConfigWithBase64EncodingZstdCompression &
SigVerifyAndReplaceRecentBlockhashConfig &
SimulateTransactionConfigBase &
WithInnerInstructionsConfig & { encoding: 'base64' },
): SimulateTransactionApiResponseBase &
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithBase64EncodedZStdCompressedData> &
SimulateTransactionApiResponseWithInnerInstructions;

/** Simulate sending a transaction */
simulateTransaction(
base64EncodedWireTransaction: Base64EncodedWireTransaction,
Expand All @@ -147,6 +226,17 @@ export interface SimulateTransactionApi extends RpcApiMethods {
): SimulateTransactionApiResponseBase &
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithBase64EncodedZStdCompressedData>;

/** Simulate sending a transaction */
simulateTransaction(
base64EncodedWireTransaction: Base64EncodedWireTransaction,
config: AccountsConfigWithJsonParsedEncoding &
SigVerifyAndReplaceRecentBlockhashConfig &
SimulateTransactionConfigBase &
WithInnerInstructionsConfig & { encoding: 'base64' },
): SimulateTransactionApiResponseBase &
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithJsonData> &
SimulateTransactionApiResponseWithInnerInstructions;

/** Simulate sending a transaction */
simulateTransaction(
base64EncodedWireTransaction: Base64EncodedWireTransaction,
Expand All @@ -156,6 +246,16 @@ export interface SimulateTransactionApi extends RpcApiMethods {
): SimulateTransactionApiResponseBase &
SimulateTransactionApiResponseWithAccounts<AccountInfoBase & AccountInfoWithJsonData>;

/** Simulate sending a transaction */
simulateTransaction(
base64EncodedWireTransaction: Base64EncodedWireTransaction,
config: SigVerifyAndReplaceRecentBlockhashConfig &
SimulateTransactionConfigBase &
WithInnerInstructionsConfig & { encoding: 'base64' },
): SimulateTransactionApiResponseBase &
SimulateTransactionApiResponseWithInnerInstructions &
SolanaRpcResponse<{ readonly accounts: null }>;

/** Simulate sending a transaction */
simulateTransaction(
base64EncodedWireTransaction: Base64EncodedWireTransaction,
Expand Down
4 changes: 2 additions & 2 deletions packages/rpc-types/src/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ type TransactionForFullMetaBase = Readonly<{
status: TransactionStatus;
}>;

type TransactionForFullMetaInnerInstructionsUnparsed = Readonly<{
export type TransactionForFullMetaInnerInstructionsUnparsed = Readonly<{
Copy link
Collaborator Author

@steveluscher steveluscher Jun 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mcintyre94, is there a reason we don't use these in getTransaction? They're copy/pasted in, and I feel like there was a reason for that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure, but my guess would be that it was before we untangled the rpc packages and it would have caused a circular dependency mess. Probably can be changed now!

innerInstructions: readonly Readonly<{
/** The index of the instruction in the transaction */
index: number;
Expand All @@ -153,7 +153,7 @@ type TransactionForFullMetaInnerInstructionsUnparsed = Readonly<{
}>[];
}>;

type TransactionForFullMetaInnerInstructionsParsed = Readonly<{
export type TransactionForFullMetaInnerInstructionsParsed = Readonly<{
innerInstructions: readonly Readonly<{
/** The index of the instruction in the transaction */
index: number;
Expand Down