From 5fa6c60ef0e4b69ba90b2f1d632ea6c2d169e9cf Mon Sep 17 00:00:00 2001 From: steveluscher Date: Thu, 27 Jun 2024 21:28:15 +0000 Subject: [PATCH] You can now request `innerInstructions` with simulation --- .changeset/calm-camels-decide.md | 5 + packages/rpc-api/src/simulateTransaction.ts | 100 ++++++++++++++++++++ packages/rpc-types/src/transaction.ts | 4 +- 3 files changed, 107 insertions(+), 2 deletions(-) create mode 100644 .changeset/calm-camels-decide.md diff --git a/.changeset/calm-camels-decide.md b/.changeset/calm-camels-decide.md new file mode 100644 index 000000000000..dd60d52e71e7 --- /dev/null +++ b/.changeset/calm-camels-decide.md @@ -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. diff --git a/packages/rpc-api/src/simulateTransaction.ts b/packages/rpc-api/src/simulateTransaction.ts index 9e25cce729c0..c4e90675bde5 100644 --- a/packages/rpc-api/src/simulateTransaction.ts +++ b/packages/rpc-api/src/simulateTransaction.ts @@ -11,6 +11,8 @@ import type { Slot, SolanaRpcResponse, TransactionError, + TransactionForFullMetaInnerInstructionsParsed, + TransactionForFullMetaInnerInstructionsUnparsed, U64UnsafeBeyond2Pow53Minus1, } from '@solana/rpc-types'; import type { Base64EncodedWireTransaction } from '@solana/transactions'; @@ -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; }>; @@ -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; @@ -95,7 +107,22 @@ type SimulateTransactionApiResponseWithAccounts = Sol accounts: (T | null)[]; }>; +type SimulateTransactionApiResponseWithInnerInstructions = SolanaRpcResponse< + TransactionForFullMetaInnerInstructionsParsed | TransactionForFullMetaInnerInstructionsUnparsed +>; + export interface SimulateTransactionApi extends RpcApiMethods { + /** @deprecated Set `encoding` to `'base64'` when calling this method */ + simulateTransaction( + base58EncodedWireTransaction: Base58EncodedBytes, + config: AccountsConfigWithBase64Encoding & + SigVerifyAndReplaceRecentBlockhashConfig & + SimulateTransactionConfigBase & + WithInnerInstructionsConfig, + ): SimulateTransactionApiResponseBase & + SimulateTransactionApiResponseWithAccounts & + SimulateTransactionApiResponseWithInnerInstructions; + /** @deprecated Set `encoding` to `'base64'` when calling this method */ simulateTransaction( base58EncodedWireTransaction: Base58EncodedBytes, @@ -105,6 +132,17 @@ export interface SimulateTransactionApi extends RpcApiMethods { ): SimulateTransactionApiResponseBase & SimulateTransactionApiResponseWithAccounts; + /** @deprecated Set `encoding` to `'base64'` when calling this method */ + simulateTransaction( + base58EncodedWireTransaction: Base58EncodedBytes, + config: AccountsConfigWithBase64EncodingZstdCompression & + SigVerifyAndReplaceRecentBlockhashConfig & + SimulateTransactionConfigBase & + WithInnerInstructionsConfig, + ): SimulateTransactionApiResponseBase & + SimulateTransactionApiResponseWithAccounts & + SimulateTransactionApiResponseWithInnerInstructions; + /** @deprecated Set `encoding` to `'base64'` when calling this method */ simulateTransaction( base58EncodedWireTransaction: Base58EncodedBytes, @@ -114,6 +152,17 @@ export interface SimulateTransactionApi extends RpcApiMethods { ): SimulateTransactionApiResponseBase & SimulateTransactionApiResponseWithAccounts; + /** @deprecated Set `encoding` to `'base64'` when calling this method */ + simulateTransaction( + base58EncodedWireTransaction: Base58EncodedBytes, + config: AccountsConfigWithJsonParsedEncoding & + SigVerifyAndReplaceRecentBlockhashConfig & + SimulateTransactionConfigBase & + WithInnerInstructionsConfig, + ): SimulateTransactionApiResponseBase & + SimulateTransactionApiResponseWithAccounts & + SimulateTransactionApiResponseWithInnerInstructions; + /** @deprecated Set `encoding` to `'base64'` when calling this method */ simulateTransaction( base58EncodedWireTransaction: Base58EncodedBytes, @@ -123,12 +172,31 @@ export interface SimulateTransactionApi extends RpcApiMethods { ): SimulateTransactionApiResponseBase & SimulateTransactionApiResponseWithAccounts; + /** @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 & + SimulateTransactionApiResponseWithInnerInstructions; + /** Simulate sending a transaction */ simulateTransaction( base64EncodedWireTransaction: Base64EncodedWireTransaction, @@ -138,6 +206,17 @@ export interface SimulateTransactionApi extends RpcApiMethods { ): SimulateTransactionApiResponseBase & SimulateTransactionApiResponseWithAccounts; + /** Simulate sending a transaction */ + simulateTransaction( + base64EncodedWireTransaction: Base64EncodedWireTransaction, + config: AccountsConfigWithBase64EncodingZstdCompression & + SigVerifyAndReplaceRecentBlockhashConfig & + SimulateTransactionConfigBase & + WithInnerInstructionsConfig & { encoding: 'base64' }, + ): SimulateTransactionApiResponseBase & + SimulateTransactionApiResponseWithAccounts & + SimulateTransactionApiResponseWithInnerInstructions; + /** Simulate sending a transaction */ simulateTransaction( base64EncodedWireTransaction: Base64EncodedWireTransaction, @@ -147,6 +226,17 @@ export interface SimulateTransactionApi extends RpcApiMethods { ): SimulateTransactionApiResponseBase & SimulateTransactionApiResponseWithAccounts; + /** Simulate sending a transaction */ + simulateTransaction( + base64EncodedWireTransaction: Base64EncodedWireTransaction, + config: AccountsConfigWithJsonParsedEncoding & + SigVerifyAndReplaceRecentBlockhashConfig & + SimulateTransactionConfigBase & + WithInnerInstructionsConfig & { encoding: 'base64' }, + ): SimulateTransactionApiResponseBase & + SimulateTransactionApiResponseWithAccounts & + SimulateTransactionApiResponseWithInnerInstructions; + /** Simulate sending a transaction */ simulateTransaction( base64EncodedWireTransaction: Base64EncodedWireTransaction, @@ -156,6 +246,16 @@ export interface SimulateTransactionApi extends RpcApiMethods { ): SimulateTransactionApiResponseBase & SimulateTransactionApiResponseWithAccounts; + /** 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, diff --git a/packages/rpc-types/src/transaction.ts b/packages/rpc-types/src/transaction.ts index 10a09416cede..de4b306aced6 100644 --- a/packages/rpc-types/src/transaction.ts +++ b/packages/rpc-types/src/transaction.ts @@ -144,7 +144,7 @@ type TransactionForFullMetaBase = Readonly<{ status: TransactionStatus; }>; -type TransactionForFullMetaInnerInstructionsUnparsed = Readonly<{ +export type TransactionForFullMetaInnerInstructionsUnparsed = Readonly<{ innerInstructions: readonly Readonly<{ /** The index of the instruction in the transaction */ index: number; @@ -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;