8
8
solana_program_test:: tokio:: time,
9
9
solana_sdk:: {
10
10
account:: Account as BaseAccount ,
11
+ compute_budget:: ComputeBudgetInstruction ,
11
12
hash:: Hash ,
12
13
instruction:: { AccountMeta , Instruction } ,
13
14
message:: Message ,
@@ -339,6 +340,8 @@ pub struct Token<T> {
339
340
nonce_blockhash : Option < Hash > ,
340
341
memo : Arc < RwLock < Option < TokenMemo > > > ,
341
342
transfer_hook_accounts : Option < Vec < AccountMeta > > ,
343
+ compute_unit_price : Option < u64 > ,
344
+ compute_unit_limit : Option < u32 > ,
342
345
}
343
346
344
347
impl < T > fmt:: Debug for Token < T > {
@@ -356,6 +359,8 @@ impl<T> fmt::Debug for Token<T> {
356
359
. field ( "nonce_blockhash" , & self . nonce_blockhash )
357
360
. field ( "memo" , & self . memo . read ( ) . unwrap ( ) )
358
361
. 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 )
359
364
. finish ( )
360
365
}
361
366
}
@@ -402,6 +407,8 @@ where
402
407
nonce_blockhash : None ,
403
408
memo : Arc :: new ( RwLock :: new ( None ) ) ,
404
409
transfer_hook_accounts : None ,
410
+ compute_unit_price : None ,
411
+ compute_unit_limit : None ,
405
412
}
406
413
}
407
414
@@ -451,6 +458,16 @@ where
451
458
self
452
459
}
453
460
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
+
454
471
pub fn with_memo < M : AsRef < str > > ( & self , memo : M , signers : Vec < Pubkey > ) -> & Self {
455
472
let mut w_memo = self . memo . write ( ) . unwrap ( ) ;
456
473
* w_memo = Some ( TokenMemo {
@@ -508,7 +525,6 @@ where
508
525
async fn construct_tx < S : Signers > (
509
526
& self ,
510
527
token_instructions : & [ Instruction ] ,
511
- additional_compute_budget : Option < u32 > ,
512
528
signing_keypairs : & S ,
513
529
) -> TokenResult < Transaction > {
514
530
let mut instructions = vec ! [ ] ;
@@ -533,12 +549,16 @@ where
533
549
534
550
instructions. extend_from_slice ( token_instructions) ;
535
551
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
+ ) ) ;
542
562
}
543
563
544
564
let ( message, blockhash) =
@@ -598,7 +618,7 @@ where
598
618
signing_keypairs : & S ,
599
619
) -> TokenResult < T :: SimulationOutput > {
600
620
let transaction = self
601
- . construct_tx ( token_instructions, None , signing_keypairs)
621
+ . construct_tx ( token_instructions, signing_keypairs)
602
622
. await ?;
603
623
604
624
self . client
@@ -613,27 +633,7 @@ where
613
633
signing_keypairs : & S ,
614
634
) -> TokenResult < T :: Output > {
615
635
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)
637
637
. await ?;
638
638
639
639
self . client
@@ -2728,9 +2728,6 @@ where
2728
2728
. new_decryptable_available_balance ( transfer_amount, source_aes_key)
2729
2729
. map_err ( |_| TokenError :: AccountDecryption ) ?;
2730
2730
2731
- // additional compute budget required for `VerifyTransferWithFee`
2732
- const TRANSFER_WITH_FEE_COMPUTE_BUDGET : u32 = 500_000 ;
2733
-
2734
2731
let mut instructions = confidential_transfer:: instruction:: transfer_with_fee (
2735
2732
& self . program_id ,
2736
2733
source_account,
@@ -2756,12 +2753,7 @@ where
2756
2753
)
2757
2754
. await
2758
2755
. 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
2765
2757
}
2766
2758
2767
2759
/// Transfer tokens confidentially with fee using split proofs.
0 commit comments