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

Commit 411cfcb

Browse files
authored
token-cli: Support creating mint with fee and conf transfer (#5862)
1 parent 32114b0 commit 411cfcb

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

token/cli/src/command.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,21 @@ async fn command_create_token(
269269
auto_approve_new_accounts: auto_approve,
270270
auditor_elgamal_pubkey: None,
271271
});
272+
if transfer_fee.is_some() {
273+
// Deriving ElGamal key from default signer. Custom ElGamal keys
274+
// will be supported in the future once upgrading to clap-v3.
275+
//
276+
// NOTE: Seed bytes are hardcoded to be empty bytes for now. They
277+
// will be updated once custom ElGamal keys are supported.
278+
let elgamal_keypair =
279+
ElGamalKeypair::new_from_signer(config.default_signer()?.as_ref(), b"").unwrap();
280+
extensions.push(
281+
ExtensionInitializationParams::ConfidentialTransferFeeConfig {
282+
authority: Some(authority),
283+
withdraw_withheld_authority_elgamal_pubkey: (*elgamal_keypair.pubkey()).into(),
284+
},
285+
);
286+
}
272287
}
273288

274289
if let Some(program_id) = transfer_hook_program_id {

token/cli/tests/command.rs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use {
1818
spl_token_2022::{
1919
extension::{
2020
confidential_transfer::{ConfidentialTransferAccount, ConfidentialTransferMint},
21+
confidential_transfer_fee::ConfidentialTransferFeeConfig,
2122
cpi_guard::CpiGuard,
2223
default_account_state::DefaultAccountState,
2324
group_member_pointer::GroupMemberPointer,
@@ -130,6 +131,7 @@ async fn main() {
130131
async_trial!(group_member_pointer, test_validator, payer),
131132
async_trial!(transfer_hook, test_validator, payer),
132133
async_trial!(metadata, test_validator, payer),
134+
async_trial!(confidential_transfer_with_fee, test_validator, payer),
133135
// GC messes with every other test, so have it on its own test validator
134136
async_trial!(gc, gc_test_validator, gc_payer),
135137
];
@@ -2721,6 +2723,62 @@ async fn confidential_transfer(test_validator: &TestValidator, payer: &Keypair)
27212723
.unwrap();
27222724
}
27232725

2726+
async fn confidential_transfer_with_fee(test_validator: &TestValidator, payer: &Keypair) {
2727+
let config = test_config_with_default_signer(test_validator, payer, &spl_token_2022::id());
2728+
2729+
// create token with confidential transfers enabled
2730+
let auto_approve = true;
2731+
let confidential_transfer_mint_authority = payer.pubkey();
2732+
2733+
let token = Keypair::new();
2734+
let token_keypair_file = NamedTempFile::new().unwrap();
2735+
write_keypair_file(&token, &token_keypair_file).unwrap();
2736+
let token_pubkey = token.pubkey();
2737+
process_test_command(
2738+
&config,
2739+
payer,
2740+
&[
2741+
"spl-token",
2742+
CommandName::CreateToken.into(),
2743+
token_keypair_file.path().to_str().unwrap(),
2744+
"--enable-confidential-transfers",
2745+
"auto",
2746+
"--transfer-fee",
2747+
"100",
2748+
"1000000000",
2749+
],
2750+
)
2751+
.await
2752+
.unwrap();
2753+
2754+
let account = config.rpc_client.get_account(&token_pubkey).await.unwrap();
2755+
let test_mint = StateWithExtensionsOwned::<Mint>::unpack(account.data).unwrap();
2756+
let extension = test_mint
2757+
.get_extension::<ConfidentialTransferMint>()
2758+
.unwrap();
2759+
2760+
assert_eq!(
2761+
Option::<Pubkey>::from(extension.authority),
2762+
Some(confidential_transfer_mint_authority),
2763+
);
2764+
assert_eq!(
2765+
bool::from(extension.auto_approve_new_accounts),
2766+
auto_approve,
2767+
);
2768+
assert_eq!(
2769+
Option::<ElGamalPubkey>::from(extension.auditor_elgamal_pubkey),
2770+
None,
2771+
);
2772+
2773+
let extension = test_mint
2774+
.get_extension::<ConfidentialTransferFeeConfig>()
2775+
.unwrap();
2776+
assert_eq!(
2777+
Option::<Pubkey>::from(extension.authority),
2778+
Some(confidential_transfer_mint_authority),
2779+
);
2780+
}
2781+
27242782
async fn multisig_transfer(test_validator: &TestValidator, payer: &Keypair) {
27252783
let m = 3;
27262784
let n = 5u8;

0 commit comments

Comments
 (0)