@@ -6,38 +6,38 @@ import {
66 Account ,
77 Address ,
88 address ,
9+ BaseTransactionMessage ,
910 Commitment ,
10- CompilableTransactionMessage ,
1111 compileTransaction ,
1212 createKeyPairSignerFromBytes ,
1313 createNoopSigner ,
1414 createSolanaRpc ,
1515 createSolanaRpcSubscriptions ,
16+ getAllSingleTransactionPlans ,
1617 getTransactionEncoder ,
18+ InstructionPlan ,
1719 MessageSigner ,
1820 pipe ,
1921 Rpc ,
2022 RpcSubscriptions ,
2123 setTransactionMessageLifetimeUsingBlockhash ,
2224 SolanaRpcApi ,
2325 SolanaRpcSubscriptionsApi ,
26+ TransactionMessageWithFeePayer ,
27+ TransactionPlan ,
28+ TransactionPlanExecutor ,
29+ TransactionPlanner ,
2430 TransactionSigner ,
2531} from '@solana/kit' ;
2632import { Command } from 'commander' ;
2733import picocolors from 'picocolors' ;
2834import { parse as parseYaml } from 'yaml' ;
2935import { Buffer , DataSource , fetchBuffer , Format , Seed } from '../generated' ;
3036import {
31- createDefaultTransactionPlanExecutor ,
32- createDefaultTransactionPlanner ,
33- getAllSingleTransactionPlans ,
34- getSetComputeUnitLimitInstructionIndex ,
35- InstructionPlan ,
36- TransactionPlan ,
37- TransactionPlanExecutor ,
38- TransactionPlanner ,
39- } from '../instructionPlans' ;
40- import { getPdaDetails , PdaDetails } from '../internals' ;
37+ createDefaultTransactionPlannerAndExecutor ,
38+ getPdaDetails ,
39+ PdaDetails ,
40+ } from '../internals' ;
4141import {
4242 decodeData ,
4343 packDirectData ,
@@ -55,6 +55,11 @@ import {
5555 RpcOption ,
5656 WriteOptions ,
5757} from './options' ;
58+ import {
59+ COMPUTE_BUDGET_PROGRAM_ADDRESS ,
60+ ComputeBudgetInstruction ,
61+ identifyComputeBudgetInstruction ,
62+ } from '@solana-program/compute-budget' ;
5863
5964const LOCALHOST_URL = 'http://127.0.0.1:8899' ;
6065const DATA_SOURCE_OPTIONS =
@@ -85,14 +90,12 @@ export async function getClient(options: GlobalOptions): Promise<Client> {
8590 options ,
8691 readonlyClient . configs
8792 ) ;
88- const planner = createDefaultTransactionPlanner ( {
89- feePayer : payer ,
90- computeUnitPrice : options . priorityFees ,
91- } ) ;
92- const executor = createDefaultTransactionPlanExecutor ( {
93+ const { planner, executor } = createDefaultTransactionPlannerAndExecutor ( {
94+ priorityFees : options . priorityFees ,
95+ payer,
9396 rpc : readonlyClient . rpc ,
9497 rpcSubscriptions : readonlyClient . rpcSubscriptions ,
95- parallelChunkSize : 5 ,
98+ concurrency : 5 ,
9699 } ) ;
97100 const planAndExecute = async ( instructionPlan : InstructionPlan ) => {
98101 const transactionPlan = await planner ( instructionPlan ) ;
@@ -129,8 +132,8 @@ async function exportTransactionPlan(
129132 for ( let i = 0 ; i < singleTransactions . length ; i ++ ) {
130133 const transaction = pipe (
131134 singleTransactions [ i ] . message ,
132- ( tx ) => setTransactionMessageLifetimeUsingBlockhash ( latestBlockhash , tx ) ,
133- removeComputeUnitLimitInstruction ,
135+ ( m ) => setTransactionMessageLifetimeUsingBlockhash ( latestBlockhash , m ) ,
136+ ( m ) => removeComputeUnitLimitInstruction ( m ) ,
134137 compileTransaction
135138 ) ;
136139 const encodedTransaction = decodeData (
@@ -143,7 +146,8 @@ async function exportTransactionPlan(
143146}
144147
145148function removeComputeUnitLimitInstruction <
146- TTransactionMessage extends CompilableTransactionMessage ,
149+ TTransactionMessage extends BaseTransactionMessage &
150+ TransactionMessageWithFeePayer ,
147151> ( message : TTransactionMessage ) : TTransactionMessage {
148152 const index = getSetComputeUnitLimitInstructionIndex ( message ) ;
149153 if ( index === - 1 ) return message ;
@@ -153,6 +157,18 @@ function removeComputeUnitLimitInstruction<
153157 } ;
154158}
155159
160+ export function getSetComputeUnitLimitInstructionIndex (
161+ transactionMessage : BaseTransactionMessage
162+ ) {
163+ return transactionMessage . instructions . findIndex ( ( ix ) => {
164+ return (
165+ ix . programAddress === COMPUTE_BUDGET_PROGRAM_ADDRESS &&
166+ identifyComputeBudgetInstruction ( ix . data as Uint8Array ) ===
167+ ComputeBudgetInstruction . SetComputeUnitLimit
168+ ) ;
169+ } ) ;
170+ }
171+
156172async function executeTransactionPlan (
157173 transactionPlan : TransactionPlan ,
158174 executor : TransactionPlanExecutor
0 commit comments