Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 23916b2

Browse files
[token-client] Add interface to add additional compute budget for transactions (#6121)
* add `process_ixs_with_additional_compute_budget` * add extra compute budget for transfer with fee * update `process_ixs_with_additional_compute_budget` to take in a regular `u32`
1 parent 52a962a commit 23916b2

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

token/client/src/token.rs

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,7 @@ where
508508
async fn construct_tx<S: Signers>(
509509
&self,
510510
token_instructions: &[Instruction],
511+
additional_compute_budget: Option<u32>,
511512
signing_keypairs: &S,
512513
) -> TokenResult<Transaction> {
513514
let mut instructions = vec![];
@@ -532,6 +533,14 @@ where
532533

533534
instructions.extend_from_slice(token_instructions);
534535

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+
);
542+
}
543+
535544
let (message, blockhash) =
536545
if let (Some(nonce_account), Some(nonce_authority), Some(nonce_blockhash)) = (
537546
self.nonce_account,
@@ -581,7 +590,7 @@ where
581590
signing_keypairs: &S,
582591
) -> TokenResult<T::SimulationOutput> {
583592
let transaction = self
584-
.construct_tx(token_instructions, signing_keypairs)
593+
.construct_tx(token_instructions, None, signing_keypairs)
585594
.await?;
586595

587596
self.client
@@ -596,7 +605,27 @@ where
596605
signing_keypairs: &S,
597606
) -> TokenResult<T::Output> {
598607
let transaction = self
599-
.construct_tx(token_instructions, signing_keypairs)
608+
.construct_tx(token_instructions, None, signing_keypairs)
609+
.await?;
610+
611+
self.client
612+
.send_transaction(&transaction)
613+
.await
614+
.map_err(TokenError::Client)
615+
}
616+
617+
pub async fn process_ixs_with_additional_compute_budget<S: Signers>(
618+
&self,
619+
token_instructions: &[Instruction],
620+
additional_compute_budget: u32,
621+
signing_keypairs: &S,
622+
) -> TokenResult<T::Output> {
623+
let transaction = self
624+
.construct_tx(
625+
token_instructions,
626+
Some(additional_compute_budget),
627+
signing_keypairs,
628+
)
600629
.await?;
601630

602631
self.client
@@ -2653,7 +2682,10 @@ where
26532682
.new_decryptable_available_balance(transfer_amount, source_aes_key)
26542683
.map_err(|_| TokenError::AccountDecryption)?;
26552684

2656-
self.process_ixs(
2685+
// additional compute budget required for `VerifyTransferWithFee`
2686+
const TRANSFER_WITH_FEE_COMPUTE_BUDGET: u32 = 500_000;
2687+
2688+
self.process_ixs_with_additional_compute_budget(
26572689
&confidential_transfer::instruction::transfer_with_fee(
26582690
&self.program_id,
26592691
source_account,
@@ -2664,6 +2696,7 @@ where
26642696
&multisig_signers,
26652697
proof_location,
26662698
)?,
2699+
TRANSFER_WITH_FEE_COMPUTE_BUDGET,
26672700
signing_keypairs,
26682701
)
26692702
.await

0 commit comments

Comments
 (0)