@solana/instruction-plans 3.0.0-canary-20250808140605 → 3.0.0-canary-20250808141109

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,303 @@
1
+ import { SolanaError } from '@solana/errors';
2
+ import { BaseTransactionMessage, TransactionMessageWithFeePayer } from '@solana/transaction-messages';
3
+ import { Transaction } from '@solana/transactions';
4
+ /**
5
+ * The result of executing a transaction plan.
6
+ *
7
+ * This is structured as a recursive tree of results that mirrors the structure
8
+ * of the original transaction plan, capturing the execution status at each level.
9
+ *
10
+ * Namely, the following result types are supported:
11
+ * - {@link SingleTransactionPlanResult} - A result for a single transaction message
12
+ * containing its execution status.
13
+ * - {@link ParallelTransactionPlanResult} - A result containing other results that
14
+ * were executed in parallel.
15
+ * - {@link SequentialTransactionPlanResult} - A result containing other results that
16
+ * were executed sequentially. It also retains the divisibility property from the
17
+ * original plan.
18
+ *
19
+ * @template TContext - The type of the context object that may be passed along with successful results
20
+ *
21
+ * @see {@link SingleTransactionPlanResult}
22
+ * @see {@link ParallelTransactionPlanResult}
23
+ * @see {@link SequentialTransactionPlanResult}
24
+ * @see {@link TransactionPlanResultStatus}
25
+ */
26
+ export type TransactionPlanResult<TContext extends TransactionPlanResultContext = TransactionPlanResultContext> = ParallelTransactionPlanResult<TContext> | SequentialTransactionPlanResult<TContext> | SingleTransactionPlanResult<TContext>;
27
+ /** A context object that may be passed along with successful results. */
28
+ export type TransactionPlanResultContext = Record<number | string | symbol, unknown>;
29
+ /**
30
+ * A result for a sequential transaction plan.
31
+ *
32
+ * This represents the execution result of a {@link SequentialTransactionPlan} and
33
+ * contains child results that were executed sequentially. It also retains the
34
+ * divisibility property from the original plan.
35
+ *
36
+ * You may use the {@link sequentialTransactionPlanResult} and
37
+ * {@link nonDivisibleSequentialTransactionPlanResult} helpers to create objects of this type.
38
+ *
39
+ * @template TContext - The type of the context object that may be passed along with successful results
40
+ *
41
+ * @example
42
+ * ```ts
43
+ * const result = sequentialTransactionPlanResult([
44
+ * singleResultA,
45
+ * singleResultB,
46
+ * ]);
47
+ * result satisfies SequentialTransactionPlanResult;
48
+ * ```
49
+ *
50
+ * @example
51
+ * Non-divisible sequential result.
52
+ * ```ts
53
+ * const result = nonDivisibleSequentialTransactionPlanResult([
54
+ * singleResultA,
55
+ * singleResultB,
56
+ * ]);
57
+ * result satisfies SequentialTransactionPlanResult & { divisible: false };
58
+ * ```
59
+ *
60
+ * @see {@link sequentialTransactionPlanResult}
61
+ * @see {@link nonDivisibleSequentialTransactionPlanResult}
62
+ */
63
+ export type SequentialTransactionPlanResult<TContext extends TransactionPlanResultContext = TransactionPlanResultContext> = Readonly<{
64
+ divisible: boolean;
65
+ kind: 'sequential';
66
+ plans: TransactionPlanResult<TContext>[];
67
+ }>;
68
+ /**
69
+ * A result for a parallel transaction plan.
70
+ *
71
+ * This represents the execution result of a {@link ParallelTransactionPlan} and
72
+ * contains child results that were executed in parallel.
73
+ *
74
+ * You may use the {@link parallelTransactionPlanResult} helper to create objects of this type.
75
+ *
76
+ * @template TContext - The type of the context object that may be passed along with successful results
77
+ *
78
+ * @example
79
+ * ```ts
80
+ * const result = parallelTransactionPlanResult([
81
+ * singleResultA,
82
+ * singleResultB,
83
+ * ]);
84
+ * result satisfies ParallelTransactionPlanResult;
85
+ * ```
86
+ *
87
+ * @see {@link parallelTransactionPlanResult}
88
+ */
89
+ export type ParallelTransactionPlanResult<TContext extends TransactionPlanResultContext = TransactionPlanResultContext> = Readonly<{
90
+ kind: 'parallel';
91
+ plans: TransactionPlanResult<TContext>[];
92
+ }>;
93
+ /**
94
+ * A result for a single transaction plan.
95
+ *
96
+ * This represents the execution result of a {@link SingleTransactionPlan} and
97
+ * contains the original transaction message along with its execution status.
98
+ *
99
+ * You may use the {@link successfulSingleTransactionPlanResult},
100
+ * {@link failedSingleTransactionPlanResult}, or {@link canceledSingleTransactionPlanResult}
101
+ * helpers to create objects of this type.
102
+ *
103
+ * @template TContext - The type of the context object that may be passed along with successful results
104
+ * @template TTransactionMessage - The type of the transaction message
105
+ *
106
+ * @example
107
+ * Successful result with a transaction and context.
108
+ * ```ts
109
+ * const result = successfulSingleTransactionPlanResult(
110
+ * transactionMessage,
111
+ * transaction
112
+ * );
113
+ * result satisfies SingleTransactionPlanResult;
114
+ * ```
115
+ *
116
+ * @example
117
+ * Failed result with an error.
118
+ * ```ts
119
+ * const result = failedSingleTransactionPlanResult(
120
+ * transactionMessage,
121
+ * new SolanaError(SOLANA_ERROR__TRANSACTION_ERROR__INSUFFICIENT_FUNDS_FOR_FEE),
122
+ * );
123
+ * result satisfies SingleTransactionPlanResult;
124
+ * ```
125
+ *
126
+ * @example
127
+ * Canceled result.
128
+ * ```ts
129
+ * const result = canceledSingleTransactionPlanResult(transactionMessage);
130
+ * result satisfies SingleTransactionPlanResult;
131
+ * ```
132
+ *
133
+ * @see {@link successfulSingleTransactionPlanResult}
134
+ * @see {@link failedSingleTransactionPlanResult}
135
+ * @see {@link canceledSingleTransactionPlanResult}
136
+ */
137
+ export type SingleTransactionPlanResult<TContext extends TransactionPlanResultContext = TransactionPlanResultContext, TTransactionMessage extends BaseTransactionMessage & TransactionMessageWithFeePayer = BaseTransactionMessage & TransactionMessageWithFeePayer> = Readonly<{
138
+ kind: 'single';
139
+ message: TTransactionMessage;
140
+ status: TransactionPlanResultStatus<TContext>;
141
+ }>;
142
+ /**
143
+ * The status of a single transaction plan execution.
144
+ *
145
+ * This represents the outcome of executing a single transaction message and can be one of:
146
+ * - `successful` - The transaction was successfully executed. Contains the transaction
147
+ * and an optional context object.
148
+ * - `failed` - The transaction execution failed. Contains the error that caused the failure.
149
+ * - `canceled` - The transaction execution was canceled.
150
+ *
151
+ * @template TContext - The type of the context object that may be passed along with successful results
152
+ */
153
+ export type TransactionPlanResultStatus<TContext extends TransactionPlanResultContext = TransactionPlanResultContext> = Readonly<{
154
+ context: TContext;
155
+ kind: 'successful';
156
+ transaction: Transaction;
157
+ }> | Readonly<{
158
+ error: SolanaError;
159
+ kind: 'failed';
160
+ }> | Readonly<{
161
+ kind: 'canceled';
162
+ }>;
163
+ /**
164
+ * Creates a divisible {@link SequentialTransactionPlanResult} from an array of nested results.
165
+ *
166
+ * This function creates a sequential result with the `divisible` property set to `true`,
167
+ * indicating that the nested plans were executed sequentially but could have been
168
+ * split into separate transactions or batches.
169
+ *
170
+ * @template TContext - The type of the context object that may be passed along with successful results
171
+ * @param plans - The child results that were executed sequentially
172
+ *
173
+ * @example
174
+ * ```ts
175
+ * const result = sequentialTransactionPlanResult([
176
+ * singleResultA,
177
+ * singleResultB,
178
+ * ]);
179
+ * result satisfies SequentialTransactionPlanResult & { divisible: true };
180
+ * ```
181
+ *
182
+ * @see {@link SequentialTransactionPlanResult}
183
+ */
184
+ export declare function sequentialTransactionPlanResult<TContext extends TransactionPlanResultContext = TransactionPlanResultContext>(plans: TransactionPlanResult<TContext>[]): SequentialTransactionPlanResult<TContext> & {
185
+ divisible: true;
186
+ };
187
+ /**
188
+ * Creates a non-divisible {@link SequentialTransactionPlanResult} from an array of nested results.
189
+ *
190
+ * This function creates a sequential result with the `divisible` property set to `false`,
191
+ * indicating that the nested plans were executed sequentially and could not have been
192
+ * split into separate transactions or batches (e.g., they were executed as a transaction bundle).
193
+ *
194
+ * @template TContext - The type of the context object that may be passed along with successful results
195
+ * @param plans - The child results that were executed sequentially
196
+ *
197
+ * @example
198
+ * ```ts
199
+ * const result = nonDivisibleSequentialTransactionPlanResult([
200
+ * singleResultA,
201
+ * singleResultB,
202
+ * ]);
203
+ * result satisfies SequentialTransactionPlanResult & { divisible: false };
204
+ * ```
205
+ *
206
+ * @see {@link SequentialTransactionPlanResult}
207
+ */
208
+ export declare function nonDivisibleSequentialTransactionPlanResult<TContext extends TransactionPlanResultContext = TransactionPlanResultContext>(plans: TransactionPlanResult<TContext>[]): SequentialTransactionPlanResult<TContext> & {
209
+ divisible: false;
210
+ };
211
+ /**
212
+ * Creates a {@link ParallelTransactionPlanResult} from an array of nested results.
213
+ *
214
+ * This function creates a parallel result indicating that the nested plans
215
+ * were executed in parallel.
216
+ *
217
+ * @template TContext - The type of the context object that may be passed along with successful results
218
+ * @param plans - The child results that were executed in parallel
219
+ *
220
+ * @example
221
+ * ```ts
222
+ * const result = parallelTransactionPlanResult([
223
+ * singleResultA,
224
+ * singleResultB,
225
+ * ]);
226
+ * result satisfies ParallelTransactionPlanResult;
227
+ * ```
228
+ *
229
+ * @see {@link ParallelTransactionPlanResult}
230
+ */
231
+ export declare function parallelTransactionPlanResult<TContext extends TransactionPlanResultContext = TransactionPlanResultContext>(plans: TransactionPlanResult<TContext>[]): ParallelTransactionPlanResult<TContext>;
232
+ /**
233
+ * Creates a successful {@link SingleTransactionPlanResult} from a transaction message and transaction.
234
+ *
235
+ * This function creates a single result with a 'successful' status, indicating that
236
+ * the transaction was successfully executed. It also includes the original transaction
237
+ * message, the executed transaction, and an optional context object.
238
+ *
239
+ * @template TContext - The type of the context object
240
+ * @template TTransactionMessage - The type of the transaction message
241
+ * @param transactionMessage - The original transaction message
242
+ * @param transaction - The successfully executed transaction
243
+ * @param context - Optional context object to be included with the result
244
+ *
245
+ * @example
246
+ * ```ts
247
+ * const result = successfulSingleTransactionPlanResult(
248
+ * transactionMessage,
249
+ * transaction
250
+ * );
251
+ * result satisfies SingleTransactionPlanResult;
252
+ * ```
253
+ *
254
+ * @see {@link SingleTransactionPlanResult}
255
+ */
256
+ export declare function successfulSingleTransactionPlanResult<TContext extends TransactionPlanResultContext = TransactionPlanResultContext, TTransactionMessage extends BaseTransactionMessage & TransactionMessageWithFeePayer = BaseTransactionMessage & TransactionMessageWithFeePayer>(transactionMessage: TTransactionMessage, transaction: Transaction, context?: TContext): SingleTransactionPlanResult<TContext, TTransactionMessage>;
257
+ /**
258
+ * Creates a failed {@link SingleTransactionPlanResult} from a transaction message and error.
259
+ *
260
+ * This function creates a single result with a 'failed' status, indicating that
261
+ * the transaction execution failed. It includes the original transaction message
262
+ * and the error that caused the failure.
263
+ *
264
+ * @template TContext - The type of the context object (not used in failed results)
265
+ * @template TTransactionMessage - The type of the transaction message
266
+ * @param transactionMessage - The original transaction message
267
+ * @param error - The error that caused the transaction to fail
268
+ *
269
+ * @example
270
+ * ```ts
271
+ * const result = failedSingleTransactionPlanResult(
272
+ * transactionMessage,
273
+ * new SolanaError({
274
+ * code: 123,
275
+ * message: 'Transaction simulation failed',
276
+ * }),
277
+ * );
278
+ * result satisfies SingleTransactionPlanResult;
279
+ * ```
280
+ *
281
+ * @see {@link SingleTransactionPlanResult}
282
+ */
283
+ export declare function failedSingleTransactionPlanResult<TContext extends TransactionPlanResultContext = TransactionPlanResultContext, TTransactionMessage extends BaseTransactionMessage & TransactionMessageWithFeePayer = BaseTransactionMessage & TransactionMessageWithFeePayer>(transactionMessage: TTransactionMessage, error: SolanaError): SingleTransactionPlanResult<TContext, TTransactionMessage>;
284
+ /**
285
+ * Creates a canceled {@link SingleTransactionPlanResult} from a transaction message.
286
+ *
287
+ * This function creates a single result with a 'canceled' status, indicating that
288
+ * the transaction execution was canceled. It includes the original transaction message.
289
+ *
290
+ * @template TContext - The type of the context object (not used in canceled results)
291
+ * @template TTransactionMessage - The type of the transaction message
292
+ * @param transactionMessage - The original transaction message
293
+ *
294
+ * @example
295
+ * ```ts
296
+ * const result = canceledSingleTransactionPlanResult(transactionMessage);
297
+ * result satisfies SingleTransactionPlanResult;
298
+ * ```
299
+ *
300
+ * @see {@link SingleTransactionPlanResult}
301
+ */
302
+ export declare function canceledSingleTransactionPlanResult<TContext extends TransactionPlanResultContext = TransactionPlanResultContext, TTransactionMessage extends BaseTransactionMessage & TransactionMessageWithFeePayer = BaseTransactionMessage & TransactionMessageWithFeePayer>(transactionMessage: TTransactionMessage): SingleTransactionPlanResult<TContext, TTransactionMessage>;
303
+ //# sourceMappingURL=transaction-plan-result.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction-plan-result.d.ts","sourceRoot":"","sources":["../../src/transaction-plan-result.ts"],"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AqC,CACjD,QAAQ,SAAS,4BAA4B,GAAG,4BAA4B,EAC5E,mBAAmB,SAAS,sBAAsB,GAAG,8BAA8B,GAAG,sBAAsB,GACxG,8BAA8B,EAElC,kBAAkB,EAAE,mBAAmB,EACvC,WAAW,EAAE,WAAW,EACxB,OAAO,CAAC,EAAE,QAAQ,GACnB,2BAA2B,CAAC,QAAQ,EAAE,mBAAmB,CAAC,CAM5D;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,iCAAiC,CAC7C,QAAQ,SAAS,4BAA4B,GAAG,4BAA4B,EAC5E,mBAAmB,SAAS,sBAAsB,GAAG,8BAA8B,GAAG,sBAAsB,GACxG,8BAA8B,EAElC,kBAAkB,EAAE,mBAAmB,EACvC,KAAK,EAAE,WAAW,GACnB,2BAA2B,CAAC,QAAQ,EAAE,mBAAmB,CAAC,CAM5D;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,mCAAmC,CAC/C,QAAQ,SAAS,4BAA4B,GAAG,4BAA4B,EAC5E,mBAAmB,SAAS,sBAAsB,GAAG,8BAA8B,GAAG,sBAAsB,GACxG,8BAA8B,EACpC,kBAAkB,EAAE,mBAAmB,GAAG,2BAA2B,CAAC,QAAQ,EAAE,mBAAmB,CAAC,CAMrG"}
@@ -0,0 +1,243 @@
1
+ import { BaseTransactionMessage, TransactionMessageWithFeePayer } from '@solana/transaction-messages';
2
+ /**
3
+ * A set of transaction messages with constraints on how they can be executed.
4
+ *
5
+ * This is structured as a recursive tree of plans to allow for
6
+ * parallel execution, sequential execution and combinations of both.
7
+ *
8
+ * Namely, the following plans are supported:
9
+ * - {@link SingleTransactionPlan} - A plan that contains a single transaction message.
10
+ * This is the simplest leaf in this tree.
11
+ * - {@link ParallelTransactionPlan} - A plan that contains other plans that
12
+ * can be executed in parallel.
13
+ * - {@link SequentialTransactionPlan} - A plan that contains other plans that
14
+ * must be executed sequentially. It also defines whether the plan is divisible
15
+ * meaning that transaction messages inside it can be split into separate batches.
16
+ *
17
+ * Helpers are provided for each of these plans to make it easier to create them.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * const myTransactionPlan: TransactionPlan = parallelTransactionPlan([
22
+ * sequentialTransactionPlan([messageA, messageB]),
23
+ * messageC,
24
+ * ]);
25
+ * ```
26
+ *
27
+ * @see {@link SingleTransactionPlan}
28
+ * @see {@link ParallelTransactionPlan}
29
+ * @see {@link SequentialTransactionPlan}
30
+ */
31
+ export type TransactionPlan = ParallelTransactionPlan | SequentialTransactionPlan | SingleTransactionPlan;
32
+ /**
33
+ * A plan wrapping other plans that must be executed sequentially.
34
+ *
35
+ * It also defines whether nested plans are divisible — meaning that
36
+ * the transaction messages inside them can be split into separate batches.
37
+ * When `divisible` is `false`, the transaction messages inside the plan should
38
+ * all be executed atomically — usually in a transaction bundle.
39
+ *
40
+ * You may use the {@link sequentialTransactionPlan} and {@link nonDivisibleSequentialTransactionPlan}
41
+ * helpers to create objects of this type.
42
+ *
43
+ * @example
44
+ * Simple sequential plan with two transaction messages.
45
+ * ```ts
46
+ * const plan = sequentialTransactionPlan([messageA, messageB]);
47
+ * plan satisfies SequentialTransactionPlan;
48
+ * ```
49
+ *
50
+ * @example
51
+ * Non-divisible sequential plan with two transaction messages.
52
+ * ```ts
53
+ * const plan = nonDivisibleSequentialTransactionPlan([messageA, messageB]);
54
+ * plan satisfies SequentialTransactionPlan & { divisible: false };
55
+ * ```
56
+ *
57
+ * @example
58
+ * Sequential plan with nested parallel plans.
59
+ * Here, messages A and B can be executed in parallel, but they must both be finalized
60
+ * before messages C and D can be sent — which can also be executed in parallel.
61
+ * ```ts
62
+ * const plan = sequentialTransactionPlan([
63
+ * parallelTransactionPlan([messageA, messageB]),
64
+ * parallelTransactionPlan([messageC, messageD]),
65
+ * ]);
66
+ * ```
67
+ *
68
+ * @see {@link sequentialTransactionPlan}
69
+ * @see {@link nonDivisibleSequentialTransactionPlan}
70
+ */
71
+ export type SequentialTransactionPlan = Readonly<{
72
+ divisible: boolean;
73
+ kind: 'sequential';
74
+ plans: TransactionPlan[];
75
+ }>;
76
+ /**
77
+ * A plan wrapping other plans that can be executed in parallel.
78
+ *
79
+ * This means direct children of this plan can be executed in separate
80
+ * parallel transactions without causing any side effects.
81
+ * However, the children themselves can define additional constraints
82
+ * for that specific branch of the tree — such as the {@link SequentialTransactionPlan}.
83
+ *
84
+ * You may use the {@link parallelTransactionPlan} helper to create objects of this type.
85
+ *
86
+ * @example
87
+ * Simple parallel plan with two transaction messages.
88
+ * ```ts
89
+ * const plan = parallelTransactionPlan([messageA, messageB]);
90
+ * plan satisfies ParallelTransactionPlan;
91
+ * ```
92
+ *
93
+ * @example
94
+ * Parallel plan with nested sequential plans.
95
+ * Here, messages A and B must be executed sequentially and so must messages C and D,
96
+ * but both pairs can be executed in parallel.
97
+ * ```ts
98
+ * const plan = parallelTransactionPlan([
99
+ * sequentialTransactionPlan([messageA, messageB]),
100
+ * sequentialTransactionPlan([messageC, messageD]),
101
+ * ]);
102
+ * plan satisfies ParallelTransactionPlan;
103
+ * ```
104
+ *
105
+ * @see {@link parallelTransactionPlan}
106
+ */
107
+ export type ParallelTransactionPlan = Readonly<{
108
+ kind: 'parallel';
109
+ plans: TransactionPlan[];
110
+ }>;
111
+ /**
112
+ * A plan that contains a single transaction message.
113
+ *
114
+ * This is a simple transaction message wrapper that transforms a message into a plan.
115
+ *
116
+ * You may use the {@link singleTransactionPlan} helper to create objects of this type.
117
+ *
118
+ * @example
119
+ * ```ts
120
+ * const plan = singleTransactionPlan(transactionMessage);
121
+ * plan satisfies SingleTransactionPlan;
122
+ * ```
123
+ *
124
+ * @see {@link singleTransactionPlan}
125
+ */
126
+ export type SingleTransactionPlan<TTransactionMessage extends BaseTransactionMessage & TransactionMessageWithFeePayer = BaseTransactionMessage & TransactionMessageWithFeePayer> = Readonly<{
127
+ kind: 'single';
128
+ message: TTransactionMessage;
129
+ }>;
130
+ /**
131
+ * Creates a {@link ParallelTransactionPlan} from an array of nested plans.
132
+ *
133
+ * It can accept {@link TransactionMessage} objects directly, which will be wrapped
134
+ * in {@link SingleTransactionPlan | SingleTransactionPlans} automatically.
135
+ *
136
+ * @example
137
+ * Using explicit {@link SingleTransactionPlan | SingleTransactionPlans}.
138
+ * ```ts
139
+ * const plan = parallelTransactionPlan([
140
+ * singleTransactionPlan(messageA),
141
+ * singleTransactionPlan(messageB),
142
+ * ]);
143
+ * ```
144
+ *
145
+ * @example
146
+ * Using {@link TransactionMessage | TransactionMessages} directly.
147
+ * ```ts
148
+ * const plan = parallelTransactionPlan([messageA, messageB]);
149
+ * ```
150
+ *
151
+ * @see {@link ParallelTransactionPlan}
152
+ */
153
+ export declare function parallelTransactionPlan(plans: (TransactionPlan | (BaseTransactionMessage & TransactionMessageWithFeePayer))[]): ParallelTransactionPlan;
154
+ /**
155
+ * Creates a divisible {@link SequentialTransactionPlan} from an array of nested plans.
156
+ *
157
+ * It can accept {@link TransactionMessage} objects directly, which will be wrapped
158
+ * in {@link SingleTransactionPlan | SingleTransactionPlans} automatically.
159
+ *
160
+ * @example
161
+ * Using explicit {@link SingleTransactionPlan | SingleTransactionPlans}.
162
+ * ```ts
163
+ * const plan = sequentialTransactionPlan([
164
+ * singleTransactionPlan(messageA),
165
+ * singleTransactionPlan(messageB),
166
+ * ]);
167
+ * ```
168
+ *
169
+ * @example
170
+ * Using {@link TransactionMessage | TransactionMessages} directly.
171
+ * ```ts
172
+ * const plan = sequentialTransactionPlan([messageA, messageB]);
173
+ * ```
174
+ *
175
+ * @see {@link SequentialTransactionPlan}
176
+ */
177
+ export declare function sequentialTransactionPlan(plans: (TransactionPlan | (BaseTransactionMessage & TransactionMessageWithFeePayer))[]): SequentialTransactionPlan & {
178
+ divisible: true;
179
+ };
180
+ /**
181
+ * Creates a non-divisible {@link SequentialTransactionPlan} from an array of nested plans.
182
+ *
183
+ * It can accept {@link TransactionMessage} objects directly, which will be wrapped
184
+ * in {@link SingleTransactionPlan | SingleTransactionPlans} automatically.
185
+ *
186
+ * @example
187
+ * Using explicit {@link SingleTransactionPlan | SingleTransactionPlans}.
188
+ * ```ts
189
+ * const plan = nonDivisibleSequentialTransactionPlan([
190
+ * singleTransactionPlan(messageA),
191
+ * singleTransactionPlan(messageB),
192
+ * ]);
193
+ * ```
194
+ *
195
+ * @example
196
+ * Using {@link TransactionMessage | TransactionMessages} directly.
197
+ * ```ts
198
+ * const plan = nonDivisibleSequentialTransactionPlan([messageA, messageB]);
199
+ * ```
200
+ *
201
+ * @see {@link SequentialTransactionPlan}
202
+ */
203
+ export declare function nonDivisibleSequentialTransactionPlan(plans: (TransactionPlan | (BaseTransactionMessage & TransactionMessageWithFeePayer))[]): SequentialTransactionPlan & {
204
+ divisible: false;
205
+ };
206
+ /**
207
+ * Creates a {@link SingleTransactionPlan} from a {@link TransactionMessage} object.
208
+ *
209
+ * @example
210
+ * ```ts
211
+ * const plan = singleTransactionPlan(transactionMessage);
212
+ * plan satisfies SingleTransactionPlan;
213
+ * ```
214
+ *
215
+ * @see {@link SingleTransactionPlan}
216
+ */
217
+ export declare function singleTransactionPlan<TTransactionMessage extends BaseTransactionMessage & TransactionMessageWithFeePayer = BaseTransactionMessage & TransactionMessageWithFeePayer>(transactionMessage: TTransactionMessage): SingleTransactionPlan<TTransactionMessage>;
218
+ /**
219
+ * Retrieves all individual {@link SingleTransactionPlan} instances from a transaction plan tree.
220
+ *
221
+ * This function recursively traverses any nested structure of transaction plans and extracts
222
+ * all the single transaction plans they contain. It's useful when you need to access all
223
+ * the actual transaction messages that will be executed, regardless of their organization
224
+ * in the plan tree (parallel or sequential).
225
+ *
226
+ * @param transactionPlan - The transaction plan to extract single plans from
227
+ * @returns An array of all single transaction plans contained in the tree
228
+ *
229
+ * @example
230
+ * ```ts
231
+ * const plan = parallelTransactionPlan([
232
+ * sequentialTransactionPlan([messageA, messageB]),
233
+ * nonDivisibleSequentialTransactionPlan([messageC, messageD]),
234
+ * messageE,
235
+ * ]);
236
+ *
237
+ * const singlePlans = getAllSingleTransactionPlans(plan);
238
+ * // Array of `SingleTransactionPlan` containing:
239
+ * // messageA, messageB, messageC and messageD.
240
+ * ```
241
+ */
242
+ export declare function getAllSingleTransactionPlans(transactionPlan: TransactionPlan): SingleTransactionPlan[];
243
+ //# sourceMappingURL=transaction-plan.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction-plan.d.ts","sourceRoot":"","sources":["../../src/transaction-plan.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,8BAA8B,EAAE,MAAM,8BAA8B,CAAC;AAEtG;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,MAAM,eAAe,GAAG,uBAAuB,GAAG,yBAAyB,GAAG,qBAAqB,CAAC;AAE1G;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,MAAM,MAAM,yBAAyB,GAAG,QAAQ,CAAC;IAC7C,SAAS,EAAE,OAAO,CAAC;IACnB,IAAI,EAAE,YAAY,CAAC;IACnB,KAAK,EAAE,eAAe,EAAE,CAAC;CAC5B,CAAC,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,MAAM,uBAAuB,GAAG,QAAQ,CAAC;IAC3C,IAAI,EAAE,UAAU,CAAC;IACjB,KAAK,EAAE,eAAe,EAAE,CAAC;CAC5B,CAAC,CAAC;AAEH;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,qBAAqB,CAC7B,mBAAmB,SAAS,sBAAsB,GAAG,8BAA8B,GAAG,sBAAsB,GACxG,8BAA8B,IAClC,QAAQ,CAAC;IACT,IAAI,EAAE,QAAQ,CAAC;IACf,OAAO,EAAE,mBAAmB,CAAC;CAChC,CAAC,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,uBAAuB,CACnC,KAAK,EAAE,CAAC,eAAe,GAAG,CAAC,sBAAsB,GAAG,8BAA8B,CAAC,CAAC,EAAE,GACvF,uBAAuB,CAEzB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,yBAAyB,CACrC,KAAK,EAAE,CAAC,eAAe,GAAG,CAAC,sBAAsB,GAAG,8BAA8B,CAAC,CAAC,EAAE,GACvF,yBAAyB,GAAG;IAAE,SAAS,EAAE,IAAI,CAAA;CAAE,CAEjD;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,qCAAqC,CACjD,KAAK,EAAE,CAAC,eAAe,GAAG,CAAC,sBAAsB,GAAG,8BAA8B,CAAC,CAAC,EAAE,GACvF,yBAAyB,GAAG;IAAE,SAAS,EAAE,KAAK,CAAA;CAAE,CAElD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,qBAAqB,CACjC,mBAAmB,SAAS,sBAAsB,GAAG,8BAA8B,GAAG,sBAAsB,GACxG,8BAA8B,EACpC,kBAAkB,EAAE,mBAAmB,GAAG,qBAAqB,CAAC,mBAAmB,CAAC,CAErF;AAQD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,4BAA4B,CAAC,eAAe,EAAE,eAAe,GAAG,qBAAqB,EAAE,CAKtG"}
@@ -0,0 +1,62 @@
1
+ import { BaseTransactionMessage, TransactionMessageWithFeePayer } from '@solana/transaction-messages';
2
+ import { InstructionPlan } from './instruction-plan';
3
+ import { TransactionPlan } from './transaction-plan';
4
+ /**
5
+ * Plans one or more transactions according to the provided instruction plan.
6
+ *
7
+ * @param instructionPlan - The instruction plan to be planned and executed.
8
+ * @param config - Optional configuration object that can include an `AbortSignal` to cancel the planning process.
9
+ *
10
+ * @see {@link InstructionPlan}
11
+ * @see {@link TransactionPlan}
12
+ */
13
+ export type TransactionPlanner = (instructionPlan: InstructionPlan, config?: {
14
+ abortSignal?: AbortSignal;
15
+ }) => Promise<TransactionPlan>;
16
+ type CreateTransactionMessage = (config?: {
17
+ abortSignal?: AbortSignal;
18
+ }) => Promise<BaseTransactionMessage & TransactionMessageWithFeePayer> | (BaseTransactionMessage & TransactionMessageWithFeePayer);
19
+ type OnTransactionMessageUpdated = <TTransactionMessage extends BaseTransactionMessage & TransactionMessageWithFeePayer>(transactionMessage: TTransactionMessage, config?: {
20
+ abortSignal?: AbortSignal;
21
+ }) => Promise<TTransactionMessage> | TTransactionMessage;
22
+ /**
23
+ * Configuration object for creating a new transaction planner.
24
+ *
25
+ * @see {@link createTransactionPlanner}
26
+ */
27
+ export type TransactionPlannerConfig = {
28
+ /** Called whenever a new transaction message is needed. */
29
+ createTransactionMessage: CreateTransactionMessage;
30
+ /**
31
+ * Called whenever a transaction message is updated — e.g. new instructions were added.
32
+ * This function must return the updated transaction message back — even if no changes were made.
33
+ */
34
+ onTransactionMessageUpdated?: OnTransactionMessageUpdated;
35
+ };
36
+ /**
37
+ * Creates a new transaction planner based on the provided configuration.
38
+ *
39
+ * At the very least, the `createTransactionMessage` function must be provided.
40
+ * This function is used to create new transaction messages whenever needed.
41
+ *
42
+ * Additionally, the `onTransactionMessageUpdated` function can be provided
43
+ * to update transaction messages during the planning process. This function will
44
+ * be called whenever a transaction message is updated, e.g. when new instructions
45
+ * are added to a transaction message. It accepts the updated transaction message
46
+ * and must return a transaction message back, even if no changes were made.
47
+ *
48
+ * @example
49
+ * ```ts
50
+ * const transactionPlanner = createTransactionPlanner({
51
+ * createTransactionMessage: () => pipe(
52
+ * createTransactionMessage({ version: 0 }),
53
+ * message => setTransactionMessageFeePayerSigner(mySigner, message),
54
+ * )
55
+ * });
56
+ * ```
57
+ *
58
+ * @see {@link TransactionPlannerConfig}
59
+ */
60
+ export declare function createTransactionPlanner(config: TransactionPlannerConfig): TransactionPlanner;
61
+ export {};
62
+ //# sourceMappingURL=transaction-planner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction-planner.d.ts","sourceRoot":"","sources":["../../src/transaction-planner.ts"],"names":[],"mappings":"AASA,OAAO,EAEH,sBAAsB,EACtB,8BAA8B,EACjC,MAAM,8BAA8B,CAAC;AAGtC,OAAO,EACH,eAAe,EAKlB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAOH,eAAe,EAClB,MAAM,oBAAoB,CAAC;AAE5B;;;;;;;;GAQG;AACH,MAAM,MAAM,kBAAkB,GAAG,CAC7B,eAAe,EAAE,eAAe,EAChC,MAAM,CAAC,EAAE;IAAE,WAAW,CAAC,EAAE,WAAW,CAAA;CAAE,KACrC,OAAO,CAAC,eAAe,CAAC,CAAC;AAI9B,KAAK,wBAAwB,GAAG,CAAC,MAAM,CAAC,EAAE;IACtC,WAAW,CAAC,EAAE,WAAW,CAAC;CAC7B,KACK,OAAO,CAAC,sBAAsB,GAAG,8BAA8B,CAAC,GAChE,CAAC,sBAAsB,GAAG,8BAA8B,CAAC,CAAC;AAEhE,KAAK,2BAA2B,GAAG,CAC/B,mBAAmB,SAAS,sBAAsB,GAAG,8BAA8B,EAEnF,kBAAkB,EAAE,mBAAmB,EACvC,MAAM,CAAC,EAAE;IAAE,WAAW,CAAC,EAAE,WAAW,CAAA;CAAE,KACrC,OAAO,CAAC,mBAAmB,CAAC,GAAG,mBAAmB,CAAC;AAExD;;;;GAIG;AACH,MAAM,MAAM,wBAAwB,GAAG;IACnC,2DAA2D;IAC3D,wBAAwB,EAAE,wBAAwB,CAAC;IACnD;;;OAGG;IACH,2BAA2B,CAAC,EAAE,2BAA2B,CAAC;CAC7D,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,wBAAwB,GAAG,kBAAkB,CAgB7F"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solana/instruction-plans",
3
- "version": "3.0.0-canary-20250808140605",
3
+ "version": "3.0.0-canary-20250808141109",
4
4
  "description": "Construct, plan and execute transactions from multiple instructions.",
5
5
  "exports": {
6
6
  "edge-light": {
@@ -54,11 +54,11 @@
54
54
  "maintained node versions"
55
55
  ],
56
56
  "dependencies": {
57
- "@solana/errors": "3.0.0-canary-20250808140605",
58
- "@solana/instructions": "3.0.0-canary-20250808140605",
59
- "@solana/promises": "3.0.0-canary-20250808140605",
60
- "@solana/transaction-messages": "3.0.0-canary-20250808140605",
61
- "@solana/transactions": "3.0.0-canary-20250808140605"
57
+ "@solana/errors": "3.0.0-canary-20250808141109",
58
+ "@solana/instructions": "3.0.0-canary-20250808141109",
59
+ "@solana/promises": "3.0.0-canary-20250808141109",
60
+ "@solana/transactions": "3.0.0-canary-20250808141109",
61
+ "@solana/transaction-messages": "3.0.0-canary-20250808141109"
62
62
  },
63
63
  "peerDependencies": {
64
64
  "typescript": ">=5.3.3"