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

Commit 8e98905

Browse files
authored
token-cli: Add non-transferable mint creation (#3795)
* token-cli: Add non-transferable mint creation * Add alias
1 parent 574fe73 commit 8e98905

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

token/cli/src/main.rs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ async fn command_create_token(
386386
authority: Pubkey,
387387
enable_freeze: bool,
388388
enable_close: bool,
389+
enable_non_transferable: bool,
389390
memo: Option<String>,
390391
rate_bps: Option<i16>,
391392
bulk_signers: Vec<Arc<dyn Signer>>,
@@ -417,6 +418,10 @@ async fn command_create_token(
417418
})
418419
}
419420

421+
if enable_non_transferable {
422+
extensions.push(ExtensionInitializationParams::NonTransferable);
423+
}
424+
420425
if let Some(text) = memo {
421426
token.with_memo(text, vec![config.default_signer()?.pubkey()]);
422427
}
@@ -2160,6 +2165,15 @@ fn app<'a, 'b>(
21602165
Rate authority defaults to the mint authority."
21612166
),
21622167
)
2168+
.arg(
2169+
Arg::with_name("enable_non_transferable")
2170+
.long("enable-non-transferable")
2171+
.alias("enable-nontransferable")
2172+
.takes_value(false)
2173+
.help(
2174+
"Permanently force tokens to be non-transferable. Thay may still be burned."
2175+
),
2176+
)
21632177
.nonce_args(true)
21642178
.arg(memo_arg())
21652179
)
@@ -3114,6 +3128,7 @@ async fn process_command<'a>(
31143128
mint_authority,
31153129
arg_matches.is_present("enable_freeze"),
31163130
arg_matches.is_present("enable_close"),
3131+
arg_matches.is_present("enable_non_transferable"),
31173132
memo,
31183133
rate_bps,
31193134
bulk_signers,
@@ -3707,6 +3722,7 @@ mod tests {
37073722
transaction::Transaction,
37083723
},
37093724
solana_test_validator::{ProgramInfo, TestValidator, TestValidatorGenesis},
3725+
spl_token_2022::extension::non_transferable::NonTransferable,
37103726
spl_token_client::client::{
37113727
ProgramClient, ProgramRpcClient, ProgramRpcClientSendTransaction,
37123728
},
@@ -3828,6 +3844,7 @@ mod tests {
38283844
payer.pubkey(),
38293845
false,
38303846
false,
3847+
false,
38313848
None,
38323849
None,
38333850
bulk_signers,
@@ -3854,6 +3871,7 @@ mod tests {
38543871
payer.pubkey(),
38553872
false,
38563873
false,
3874+
false,
38573875
None,
38583876
Some(rate_bps),
38593877
bulk_signers,
@@ -5100,6 +5118,7 @@ mod tests {
51005118
payer.pubkey(),
51015119
false,
51025120
true,
5121+
false,
51035122
None,
51045123
None,
51055124
bulk_signers,
@@ -5383,4 +5402,57 @@ mod tests {
53835402
.await;
53845403
result.unwrap_err();
53855404
}
5405+
5406+
#[tokio::test]
5407+
#[serial]
5408+
async fn non_transferable() {
5409+
let (test_validator, payer) = new_validator_for_test().await;
5410+
let config =
5411+
test_config_with_default_signer(&test_validator, &payer, &spl_token_2022::id());
5412+
5413+
let token_keypair = Keypair::new();
5414+
let token_pubkey = token_keypair.pubkey();
5415+
let bulk_signers: Vec<Arc<dyn Signer>> =
5416+
vec![Arc::new(clone_keypair(&payer)), Arc::new(token_keypair)];
5417+
5418+
command_create_token(
5419+
&config,
5420+
TEST_DECIMALS,
5421+
token_pubkey,
5422+
payer.pubkey(),
5423+
false,
5424+
false,
5425+
true,
5426+
None,
5427+
None,
5428+
bulk_signers,
5429+
)
5430+
.await
5431+
.unwrap();
5432+
5433+
let account = config.rpc_client.get_account(&token_pubkey).await.unwrap();
5434+
let test_mint = StateWithExtensionsOwned::<Mint>::unpack(account.data).unwrap();
5435+
assert!(test_mint.get_extension::<NonTransferable>().is_ok());
5436+
5437+
let associated_account = create_associated_account(&config, &payer, token_pubkey).await;
5438+
let aux_account = create_auxiliary_account(&config, &payer, token_pubkey).await;
5439+
mint_tokens(&config, &payer, token_pubkey, 100.0, associated_account).await;
5440+
5441+
// transfer not allowed
5442+
process_test_command(
5443+
&config,
5444+
&payer,
5445+
&[
5446+
"spl-token",
5447+
CommandName::Transfer.into(),
5448+
"--from",
5449+
&associated_account.to_string(),
5450+
&token_pubkey.to_string(),
5451+
"1",
5452+
&aux_account.to_string(),
5453+
],
5454+
)
5455+
.await
5456+
.unwrap_err();
5457+
}
53865458
}

0 commit comments

Comments
 (0)