Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Commit

Permalink
[token-client] Add interface to add additional compute budget for tra…
Browse files Browse the repository at this point in the history
…nsactions (#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`
  • Loading branch information
samkim-crypto authored Jan 12, 2024
1 parent 52a962a commit 23916b2
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions token/client/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ where
async fn construct_tx<S: Signers>(
&self,
token_instructions: &[Instruction],
additional_compute_budget: Option<u32>,
signing_keypairs: &S,
) -> TokenResult<Transaction> {
let mut instructions = vec![];
Expand All @@ -532,6 +533,14 @@ where

instructions.extend_from_slice(token_instructions);

if let Some(additional_compute_budget) = additional_compute_budget {
instructions.push(
solana_sdk::compute_budget::ComputeBudgetInstruction::set_compute_unit_limit(
additional_compute_budget,
),
);
}

let (message, blockhash) =
if let (Some(nonce_account), Some(nonce_authority), Some(nonce_blockhash)) = (
self.nonce_account,
Expand Down Expand Up @@ -581,7 +590,7 @@ where
signing_keypairs: &S,
) -> TokenResult<T::SimulationOutput> {
let transaction = self
.construct_tx(token_instructions, signing_keypairs)
.construct_tx(token_instructions, None, signing_keypairs)
.await?;

self.client
Expand All @@ -596,7 +605,27 @@ where
signing_keypairs: &S,
) -> TokenResult<T::Output> {
let transaction = self
.construct_tx(token_instructions, signing_keypairs)
.construct_tx(token_instructions, None, signing_keypairs)
.await?;

self.client
.send_transaction(&transaction)
.await
.map_err(TokenError::Client)
}

pub async fn process_ixs_with_additional_compute_budget<S: Signers>(
&self,
token_instructions: &[Instruction],
additional_compute_budget: u32,
signing_keypairs: &S,
) -> TokenResult<T::Output> {
let transaction = self
.construct_tx(
token_instructions,
Some(additional_compute_budget),
signing_keypairs,
)
.await?;

self.client
Expand Down Expand Up @@ -2653,7 +2682,10 @@ where
.new_decryptable_available_balance(transfer_amount, source_aes_key)
.map_err(|_| TokenError::AccountDecryption)?;

self.process_ixs(
// additional compute budget required for `VerifyTransferWithFee`
const TRANSFER_WITH_FEE_COMPUTE_BUDGET: u32 = 500_000;

self.process_ixs_with_additional_compute_budget(
&confidential_transfer::instruction::transfer_with_fee(
&self.program_id,
source_account,
Expand All @@ -2664,6 +2696,7 @@ where
&multisig_signers,
proof_location,
)?,
TRANSFER_WITH_FEE_COMPUTE_BUDGET,
signing_keypairs,
)
.await
Expand Down

0 comments on commit 23916b2

Please sign in to comment.