88 solana_program_test:: tokio:: time,
99 solana_sdk:: {
1010 account:: Account as BaseAccount ,
11+ compute_budget:: ComputeBudgetInstruction ,
1112 hash:: Hash ,
1213 instruction:: { AccountMeta , Instruction } ,
1314 message:: Message ,
@@ -339,6 +340,8 @@ pub struct Token<T> {
339340 nonce_blockhash : Option < Hash > ,
340341 memo : Arc < RwLock < Option < TokenMemo > > > ,
341342 transfer_hook_accounts : Option < Vec < AccountMeta > > ,
343+ compute_unit_price : Option < u64 > ,
344+ compute_unit_limit : Option < u32 > ,
342345}
343346
344347impl < T > fmt:: Debug for Token < T > {
@@ -356,6 +359,8 @@ impl<T> fmt::Debug for Token<T> {
356359 . field ( "nonce_blockhash" , & self . nonce_blockhash )
357360 . field ( "memo" , & self . memo . read ( ) . unwrap ( ) )
358361 . field ( "transfer_hook_accounts" , & self . transfer_hook_accounts )
362+ . field ( "compute_unit_price" , & self . compute_unit_price )
363+ . field ( "compute_unit_limit" , & self . compute_unit_limit )
359364 . finish ( )
360365 }
361366}
@@ -402,6 +407,8 @@ where
402407 nonce_blockhash : None ,
403408 memo : Arc :: new ( RwLock :: new ( None ) ) ,
404409 transfer_hook_accounts : None ,
410+ compute_unit_price : None ,
411+ compute_unit_limit : None ,
405412 }
406413 }
407414
@@ -451,6 +458,16 @@ where
451458 self
452459 }
453460
461+ pub fn with_compute_unit_price ( mut self , compute_unit_price : u64 ) -> Self {
462+ self . compute_unit_price = Some ( compute_unit_price) ;
463+ self
464+ }
465+
466+ pub fn with_compute_unit_limit ( mut self , compute_unit_limit : u32 ) -> Self {
467+ self . compute_unit_limit = Some ( compute_unit_limit) ;
468+ self
469+ }
470+
454471 pub fn with_memo < M : AsRef < str > > ( & self , memo : M , signers : Vec < Pubkey > ) -> & Self {
455472 let mut w_memo = self . memo . write ( ) . unwrap ( ) ;
456473 * w_memo = Some ( TokenMemo {
@@ -508,7 +525,6 @@ where
508525 async fn construct_tx < S : Signers > (
509526 & self ,
510527 token_instructions : & [ Instruction ] ,
511- additional_compute_budget : Option < u32 > ,
512528 signing_keypairs : & S ,
513529 ) -> TokenResult < Transaction > {
514530 let mut instructions = vec ! [ ] ;
@@ -533,12 +549,16 @@ where
533549
534550 instructions. extend_from_slice ( token_instructions) ;
535551
536- if let Some ( additional_compute_budget) = additional_compute_budget {
537- instructions. push (
538- solana_sdk:: compute_budget:: ComputeBudgetInstruction :: set_compute_unit_limit (
539- additional_compute_budget,
540- ) ,
541- ) ;
552+ if let Some ( compute_unit_limit) = self . compute_unit_limit {
553+ instructions. push ( ComputeBudgetInstruction :: set_compute_unit_limit (
554+ compute_unit_limit,
555+ ) ) ;
556+ }
557+
558+ if let Some ( compute_unit_price) = self . compute_unit_price {
559+ instructions. push ( ComputeBudgetInstruction :: set_compute_unit_price (
560+ compute_unit_price,
561+ ) ) ;
542562 }
543563
544564 let ( message, blockhash) =
@@ -598,7 +618,7 @@ where
598618 signing_keypairs : & S ,
599619 ) -> TokenResult < T :: SimulationOutput > {
600620 let transaction = self
601- . construct_tx ( token_instructions, None , signing_keypairs)
621+ . construct_tx ( token_instructions, signing_keypairs)
602622 . await ?;
603623
604624 self . client
@@ -613,27 +633,7 @@ where
613633 signing_keypairs : & S ,
614634 ) -> TokenResult < T :: Output > {
615635 let transaction = self
616- . construct_tx ( token_instructions, None , signing_keypairs)
617- . await ?;
618-
619- self . client
620- . send_transaction ( & transaction)
621- . await
622- . map_err ( TokenError :: Client )
623- }
624-
625- pub async fn process_ixs_with_additional_compute_budget < S : Signers > (
626- & self ,
627- token_instructions : & [ Instruction ] ,
628- additional_compute_budget : u32 ,
629- signing_keypairs : & S ,
630- ) -> TokenResult < T :: Output > {
631- let transaction = self
632- . construct_tx (
633- token_instructions,
634- Some ( additional_compute_budget) ,
635- signing_keypairs,
636- )
636+ . construct_tx ( token_instructions, signing_keypairs)
637637 . await ?;
638638
639639 self . client
@@ -2728,9 +2728,6 @@ where
27282728 . new_decryptable_available_balance ( transfer_amount, source_aes_key)
27292729 . map_err ( |_| TokenError :: AccountDecryption ) ?;
27302730
2731- // additional compute budget required for `VerifyTransferWithFee`
2732- const TRANSFER_WITH_FEE_COMPUTE_BUDGET : u32 = 500_000 ;
2733-
27342731 let mut instructions = confidential_transfer:: instruction:: transfer_with_fee (
27352732 & self . program_id ,
27362733 source_account,
@@ -2756,12 +2753,7 @@ where
27562753 )
27572754 . await
27582755 . map_err ( |_| TokenError :: AccountNotFound ) ?;
2759- self . process_ixs_with_additional_compute_budget (
2760- & instructions,
2761- TRANSFER_WITH_FEE_COMPUTE_BUDGET ,
2762- signing_keypairs,
2763- )
2764- . await
2756+ self . process_ixs ( & instructions, signing_keypairs) . await
27652757 }
27662758
27672759 /// Transfer tokens confidentially with fee using split proofs.
0 commit comments