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

Commit fe1ac9a

Browse files
authored
token-cli: Add priority fee args (#6501)
1 parent 19c2dd7 commit fe1ac9a

File tree

4 files changed

+94
-30
lines changed

4 files changed

+94
-30
lines changed

token/cli/src/clap_app.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,18 @@ pub const MULTISIG_SIGNER_ARG: ArgConstant<'static> = ArgConstant {
6464
help: "Member signer of a multisig account",
6565
};
6666

67+
pub const COMPUTE_UNIT_PRICE_ARG: ArgConstant<'static> = ArgConstant {
68+
name: "compute_unit_price",
69+
long: "--with-compute-unit-price",
70+
help: "Set compute unit price for transaction, in increments of 0.000001 lamports per compute unit.",
71+
};
72+
73+
pub const COMPUTE_UNIT_LIMIT_ARG: ArgConstant<'static> = ArgConstant {
74+
name: "compute_unit_limit",
75+
long: "--with-compute-unit-limit",
76+
help: "Set compute unit limit for transaction, in compute units.",
77+
};
78+
6779
pub static VALID_TOKEN_PROGRAM_IDS: [Pubkey; 2] = [spl_token_2022::ID, spl_token::ID];
6880

6981
#[derive(Debug, Clone, Copy, PartialEq, EnumString, IntoStaticStr)]
@@ -611,6 +623,22 @@ pub fn app<'a, 'b>(
611623
.hidden(true)
612624
.help("Use unchecked instruction if appropriate. Supports transfer, burn, mint, and approve."),
613625
)
626+
.arg(
627+
Arg::with_name(COMPUTE_UNIT_LIMIT_ARG.name)
628+
.long(COMPUTE_UNIT_LIMIT_ARG.long)
629+
.takes_value(true)
630+
.value_name("COMPUTE-UNIT-LIMIT")
631+
.validator(is_parsable::<u32>)
632+
.help(COMPUTE_UNIT_LIMIT_ARG.help)
633+
)
634+
.arg(
635+
Arg::with_name(COMPUTE_UNIT_PRICE_ARG.name)
636+
.long(COMPUTE_UNIT_PRICE_ARG.long)
637+
.takes_value(true)
638+
.value_name("COMPUTE-UNIT-PRICE")
639+
.validator(is_parsable::<u64>)
640+
.help(COMPUTE_UNIT_PRICE_ARG.help)
641+
)
614642
.bench_subcommand()
615643
.subcommand(SubCommand::with_name(CommandName::CreateToken.into()).about("Create a new token")
616644
.arg(

token/cli/src/command.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,18 @@ fn token_client_from_config(
147147
config.fee_payer()?.clone(),
148148
);
149149

150+
let token = if let Some(compute_unit_limit) = config.compute_unit_limit {
151+
token.with_compute_unit_limit(compute_unit_limit)
152+
} else {
153+
token
154+
};
155+
156+
let token = if let Some(compute_unit_price) = config.compute_unit_price {
157+
token.with_compute_unit_price(compute_unit_price)
158+
} else {
159+
token
160+
};
161+
150162
if let (Some(nonce_account), Some(nonce_authority), Some(nonce_blockhash)) = (
151163
config.nonce_account,
152164
&config.nonce_authority,

token/cli/src/config.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use {
2-
crate::clap_app::{Error, MULTISIG_SIGNER_ARG},
2+
crate::clap_app::{Error, COMPUTE_UNIT_LIMIT_ARG, COMPUTE_UNIT_PRICE_ARG, MULTISIG_SIGNER_ARG},
33
clap::ArgMatches,
44
solana_clap_utils::{
55
input_parsers::{pubkey_of_signer, value_of},
@@ -67,6 +67,8 @@ pub struct Config<'a> {
6767
pub multisigner_pubkeys: Vec<&'a Pubkey>,
6868
pub program_id: Pubkey,
6969
pub restrict_to_program_id: bool,
70+
pub compute_unit_price: Option<u64>,
71+
pub compute_unit_limit: Option<u32>,
7072
}
7173

7274
impl<'a> Config<'a> {
@@ -279,6 +281,8 @@ impl<'a> Config<'a> {
279281
};
280282

281283
let nonce_blockhash = value_of(matches, BLOCKHASH_ARG.name);
284+
let compute_unit_price = value_of(matches, COMPUTE_UNIT_PRICE_ARG.name);
285+
let compute_unit_limit = value_of(matches, COMPUTE_UNIT_LIMIT_ARG.name);
282286
Self {
283287
default_signer,
284288
rpc_client,
@@ -294,6 +298,8 @@ impl<'a> Config<'a> {
294298
multisigner_pubkeys,
295299
program_id,
296300
restrict_to_program_id,
301+
compute_unit_price,
302+
compute_unit_limit,
297303
}
298304
}
299305

token/cli/tests/command.rs

Lines changed: 47 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ async fn main() {
135135
async_trial!(metadata, test_validator, payer),
136136
async_trial!(group, test_validator, payer),
137137
async_trial!(confidential_transfer_with_fee, test_validator, payer),
138+
async_trial!(compute_budget, test_validator, payer),
138139
// GC messes with every other test, so have it on its own test validator
139140
async_trial!(gc, gc_test_validator, gc_payer),
140141
];
@@ -199,6 +200,8 @@ fn test_config_with_default_signer<'a>(
199200
multisigner_pubkeys: vec![],
200201
program_id: *program_id,
201202
restrict_to_program_id: true,
203+
compute_unit_price: None,
204+
compute_unit_limit: None,
202205
}
203206
}
204207

@@ -226,6 +229,8 @@ fn test_config_without_default_signer<'a>(
226229
multisigner_pubkeys: vec![],
227230
program_id: *program_id,
228231
restrict_to_program_id: true,
232+
compute_unit_price: None,
233+
compute_unit_limit: None,
229234
}
230235
}
231236

@@ -380,6 +385,38 @@ async fn mint_tokens(
380385
.await
381386
}
382387

388+
async fn run_transfer_test(config: &Config<'_>, payer: &Keypair) {
389+
let token = create_token(config, payer).await;
390+
let source = create_associated_account(config, payer, &token, &payer.pubkey()).await;
391+
let destination = create_auxiliary_account(config, payer, token).await;
392+
let ui_amount = 100.0;
393+
mint_tokens(config, payer, token, ui_amount, source)
394+
.await
395+
.unwrap();
396+
let result = process_test_command(
397+
config,
398+
payer,
399+
&[
400+
"spl-token",
401+
CommandName::Transfer.into(),
402+
&token.to_string(),
403+
"10",
404+
&destination.to_string(),
405+
],
406+
)
407+
.await;
408+
result.unwrap();
409+
410+
let account = config.rpc_client.get_account(&source).await.unwrap();
411+
let token_account = StateWithExtensionsOwned::<Account>::unpack(account.data).unwrap();
412+
let amount = spl_token::ui_amount_to_amount(90.0, TEST_DECIMALS);
413+
assert_eq!(token_account.base.amount, amount);
414+
let account = config.rpc_client.get_account(&destination).await.unwrap();
415+
let token_account = StateWithExtensionsOwned::<Account>::unpack(account.data).unwrap();
416+
let amount = spl_token::ui_amount_to_amount(10.0, TEST_DECIMALS);
417+
assert_eq!(token_account.base.amount, amount);
418+
}
419+
383420
async fn process_test_command<I, T>(config: &Config<'_>, payer: &Keypair, args: I) -> CommandResult
384421
where
385422
I: IntoIterator<Item = T>,
@@ -855,35 +892,7 @@ async fn wrapped_sol(test_validator: &TestValidator, payer: &Keypair) {
855892
async fn transfer(test_validator: &TestValidator, payer: &Keypair) {
856893
for program_id in VALID_TOKEN_PROGRAM_IDS.iter() {
857894
let config = test_config_with_default_signer(test_validator, payer, program_id);
858-
let token = create_token(&config, payer).await;
859-
let source = create_associated_account(&config, payer, &token, &payer.pubkey()).await;
860-
let destination = create_auxiliary_account(&config, payer, token).await;
861-
let ui_amount = 100.0;
862-
mint_tokens(&config, payer, token, ui_amount, source)
863-
.await
864-
.unwrap();
865-
let result = process_test_command(
866-
&config,
867-
payer,
868-
&[
869-
"spl-token",
870-
CommandName::Transfer.into(),
871-
&token.to_string(),
872-
"10",
873-
&destination.to_string(),
874-
],
875-
)
876-
.await;
877-
result.unwrap();
878-
879-
let account = config.rpc_client.get_account(&source).await.unwrap();
880-
let token_account = StateWithExtensionsOwned::<Account>::unpack(account.data).unwrap();
881-
let amount = spl_token::ui_amount_to_amount(90.0, TEST_DECIMALS);
882-
assert_eq!(token_account.base.amount, amount);
883-
let account = config.rpc_client.get_account(&destination).await.unwrap();
884-
let token_account = StateWithExtensionsOwned::<Account>::unpack(account.data).unwrap();
885-
let amount = spl_token::ui_amount_to_amount(10.0, TEST_DECIMALS);
886-
assert_eq!(token_account.base.amount, amount);
895+
run_transfer_test(&config, payer).await;
887896
}
888897
}
889898

@@ -4010,3 +4019,12 @@ async fn group(test_validator: &TestValidator, payer: &Keypair) {
40104019
let extension = mint_state.get_extension::<TokenGroup>().unwrap();
40114020
assert_eq!(extension.update_authority, Some(mint).try_into().unwrap());
40124021
}
4022+
4023+
async fn compute_budget(test_validator: &TestValidator, payer: &Keypair) {
4024+
for program_id in VALID_TOKEN_PROGRAM_IDS.iter() {
4025+
let mut config = test_config_with_default_signer(test_validator, payer, program_id);
4026+
config.compute_unit_price = Some(42);
4027+
config.compute_unit_limit = Some(30_000);
4028+
run_transfer_test(&config, payer).await;
4029+
}
4030+
}

0 commit comments

Comments
 (0)