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

token-2022: add token 2022 argument to token cli for easy use #7006

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions token/cli/src/clap_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,13 @@ pub fn app<'a, 'b>(
"Enable the mint authority to close this mint"
),
)
.arg(
Arg::with_name("token_program_2022")
.value_name("token-program-2022")
.short("2")
.long("token-program-2022")
.takes_value(false)
.help("Use token extension program token 2022 with program id: TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"))
.arg(
Arg::with_name("interest_rate")
.long("interest-rate")
Expand Down
4 changes: 3 additions & 1 deletion token/cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,9 @@ impl<'a> Config<'a> {

let default_program_id = spl_token::id();
let (program_id, restrict_to_program_id) =
if let Some(program_id) = value_of(matches, "program_id") {
if matches.is_present("token_program_2022") {
(spl_token_2022::id(), true)
} else if let Some(program_id) = value_of(matches, "program_id") {
(program_id, true)
} else if !sign_only {
if let Some(address) = value_of(matches, "token")
Expand Down
41 changes: 41 additions & 0 deletions token/cli/tests/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ async fn main() {
// maybe come up with a way to do this through a some macro tag on the function?
let tests = vec![
async_trial!(create_token_default, test_validator, payer),
async_trial!(create_token_2022, test_validator, payer),
async_trial!(create_token_interest_bearing, test_validator, payer),
async_trial!(set_interest_rate, test_validator, payer),
async_trial!(supply, test_validator, payer),
Expand Down Expand Up @@ -495,6 +496,46 @@ async fn create_token_default(test_validator: &TestValidator, payer: &Keypair) {
}
}


async fn create_token_2022(test_validator: &TestValidator, payer: &Keypair) {
let config = test_config_with_default_signer(test_validator, payer, &spl_token_2022::id());
let mut wallet_manager = None;
let mut bulk_signers: Vec<Arc<dyn Signer>> = Vec::new();
let mut multisigner_ids = Vec::new();

let args = &[
"spl-token",
CommandName::CreateToken.into(),
"--token-program-2022"
];

let default_decimals = format!("{}", spl_token_2022::native_mint::DECIMALS);
let minimum_signers_help = minimum_signers_help_string();
let multisig_member_help = multisig_member_help_string();

let app_matches = app(
&default_decimals,
&minimum_signers_help,
&multisig_member_help,
)
.get_matches_from(args);

let (_sub_command, sub_matches) = app_matches.subcommand();
let matches = sub_matches.unwrap();

let config = Config::new_with_clients_and_ws_url(
matches,
&mut wallet_manager,
&mut bulk_signers,
&mut multisigner_ids,
config.rpc_client.clone(),
config.program_client.clone(),
config.websocket_url.clone(),
).await;

assert_eq!(config.program_id, spl_token_2022::ID);
}

async fn create_token_interest_bearing(test_validator: &TestValidator, payer: &Keypair) {
let config = test_config_with_default_signer(test_validator, payer, &spl_token_2022::id());
let rate_bps: i16 = 100;
Expand Down