Skip to content

Commit 9cdad39

Browse files
committed
Tune compute units for exchange deposits
1 parent 4113057 commit 9cdad39

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/main.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ async fn process_exchange_deposit<T: Signers>(
512512
.into());
513513
}
514514

515-
let (mut instructions, amount) = match token.token() {
515+
let (mut instructions, amount, compute_units) = match token.token() {
516516
/*SOL*/
517517
None => {
518518
assert_eq!(from_account.lamports, from_account_balance);
@@ -533,6 +533,7 @@ async fn process_exchange_deposit<T: Signers>(
533533
amount,
534534
)],
535535
amount,
536+
1_000,
536537
)
537538
} else if from_account.owner == solana_vote_program::id() {
538539
let minimum_balance = rpc_client.get_minimum_balance_for_rent_exemption(
@@ -550,6 +551,7 @@ async fn process_exchange_deposit<T: Signers>(
550551
&deposit_address,
551552
)],
552553
amount,
554+
1_000,
553555
)
554556
} else if from_account.owner == solana_sdk::stake::program::id() {
555557
let amount = amount.unwrap_or(from_account_balance);
@@ -563,6 +565,7 @@ async fn process_exchange_deposit<T: Signers>(
563565
None,
564566
)],
565567
amount,
568+
1_000,
566569
)
567570
} else {
568571
return Err(
@@ -575,6 +578,8 @@ async fn process_exchange_deposit<T: Signers>(
575578

576579
let mut instructions = vec![];
577580

581+
let mut compute_units = 5_000;
582+
578583
if rpc_client
579584
.get_account_with_commitment(&token.ata(&deposit_address), rpc_client.commitment())?
580585
.value
@@ -588,6 +593,7 @@ async fn process_exchange_deposit<T: Signers>(
588593
&spl_token::id(),
589594
),
590595
);
596+
compute_units += 20_000
591597
}
592598

593599
instructions.push(
@@ -604,10 +610,10 @@ async fn process_exchange_deposit<T: Signers>(
604610
.unwrap(),
605611
);
606612

607-
(instructions, amount)
613+
(instructions, amount, compute_units)
608614
}
609615
};
610-
apply_priority_fee(rpc_client, &mut instructions, 20_000, priority_fee)?;
616+
apply_priority_fee(rpc_client, &mut instructions, compute_units, priority_fee)?;
611617

612618
if amount == 0 {
613619
return Err("Nothing to deposit".into());

0 commit comments

Comments
 (0)