Skip to content

Commit

Permalink
You can now request innerInstructions with simulation (#2868)
Browse files Browse the repository at this point in the history
Closes #2763.

# Test Plan

Notice how `index` and `stackHeight` are `number` instead of `bigint` here.

```js
 const { value } = await rpc
    .simulateTransaction(
        'A8VSjQsioqTM0kyF9hiBLl/D7NlMU69OObLMEALuTzERsr/FJIN4YqOe45SUfkXhH0CI6xClzFEa+/V9/vSiFQoKf75MXBgQPY4gzn6iz86ZzhnydQvNcn5sbJZc6xmS9ey7fj6+v5xkqFshX1b/Mg86WH2DO0xK0kjq7+IWi8YEvD9ZHU0X9fO//akP12jMPJJ67DsoEwgPB630jd5qMFMOMlESOql5YHf9zKBMhJYYx2wZAJMSEQfyVwB3lV0KA4ADAQcNDQ4WRO2tB+MVLamVDMyF3NM9vIycJ5ID5PpIfjp5VnCuCoZk81s1sWU+MG/teETSzT0CK69Xbi9jn/suK3F7CmuzKkWQgpJ5e5NZRWj4wiXXxozEFV8KQyFP9RZQUDVBFHMYdkG3nmJJ/WeMvFrr+E6Ux/obRtql7j1H4ZCkztUBfGU0Be9QIK1utAyLKHqj3w6JeFK9kEohbF/PhFil1VgBR6+Uey25nUP1St50fjufSPx6NYjlxB12FyxZ3PelAwZGb+UhFzL/7K26csOb57yM5bvF9xJrLEObOkAAAAALcGWx49F8RTidUn9rBMPNWLhscxqg/bVJttG8A/gpRgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABqfVFxh70WY12tQEVf3CwMEkxo8hVnWl27rLXwgAAAAG3fbh12Whk9nL4UbO63msHLSF7V9bN5E6jPWFfv8AqYyXJY9OJInxuz0QKRSODYMLWhOZ2v8QhASOe9jb6fhZBUpTWpkpIQZNJOhxYNo4fHw1td28kruB5B+oQEEFRI2BRFO9Mxdx1WGvTJ9EjfepI2IH1WujnvFkbak/EULbEQUGAAkDZAAAAAAAAAAGAAUC1TEDAAcJAwQBAgACCAkKqgEqABEAAABNeSBORlQgQ29sbGVjdGlvbgMAAABBQkNMAAAAaHR0cHM6Ly9pcGZzLmZpbGViYXNlLmlvL2lwZnMvUW1RWThpSkNMYTJWS3FRZEs1N2lZVUV1OUpvYXNMRFN6N3lBZ0RWWGhoMzd5eQAAAQEAAABrsypFkIKSeXuTWUVo+MIl18aMxBVfCkMhT/UWUFA1QQFkAAEAAAABAAAAAAAAAAAAAAABAAcPBQIDBAcBAgcACAkKCwcHCysAAQAAAAAAAAAADAAFMGdiaDUA',
        {encoding: 'base64', innerInstructions: true, replaceRecentBlockhash: true},
    )
    .send();
> value.innerInstructions
[ { index: 2, instructions: [ [Object] ] } ]
> value.innerInstructions[0].instructions
[
  {
    parsed: { info: [Object], type: 'transfer' },
    program: 'system',
    programId: '11111111111111111111111111111111',
    stackHeight: 2
  }
]
```
  • Loading branch information
steveluscher authored Jun 28, 2024
1 parent be36bab commit 91fb1f3
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 2 deletions.
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
>;

export interface SimulateTransactionApi extends RpcApiMethods {
/** @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<{
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

0 comments on commit 91fb1f3

Please sign in to comment.