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

Commit ecd5c45

Browse files
[token-2022, token-cli] Enable Command::Authorize to update transfer fee extension authorities (#4078)
1 parent 331c0c2 commit ecd5c45

File tree

1 file changed

+66
-2
lines changed

1 file changed

+66
-2
lines changed

token/cli/src/main.rs

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -787,8 +787,24 @@ async fn command_authorize(
787787
))
788788
}
789789
}
790-
AuthorityType::TransferFeeConfig => unimplemented!(),
791-
AuthorityType::WithheldWithdraw => unimplemented!(),
790+
AuthorityType::TransferFeeConfig => {
791+
if let Ok(transfer_fee_config) = mint.get_extension::<TransferFeeConfig>() {
792+
Ok(COption::<Pubkey>::from(
793+
transfer_fee_config.transfer_fee_config_authority,
794+
))
795+
} else {
796+
Err(format!("Mint `{}` does not support transfer fees", account))
797+
}
798+
}
799+
AuthorityType::WithheldWithdraw => {
800+
if let Ok(transfer_fee_config) = mint.get_extension::<TransferFeeConfig>() {
801+
Ok(COption::<Pubkey>::from(
802+
transfer_fee_config.withdraw_withheld_authority,
803+
))
804+
} else {
805+
Err(format!("Mint `{}` does not support transfer fees", account))
806+
}
807+
}
792808
AuthorityType::InterestRate => {
793809
if let Ok(interest_rate_config) = mint.get_extension::<InterestBearingConfig>()
794810
{
@@ -6666,6 +6682,54 @@ mod tests {
66666682
u64::from(extension.newer_transfer_fee.maximum_fee),
66676683
new_maximum_fee
66686684
);
6685+
6686+
// disable transfer fee authority
6687+
process_test_command(
6688+
&config,
6689+
&payer,
6690+
&[
6691+
"spl-token",
6692+
CommandName::Authorize.into(),
6693+
"--disable",
6694+
&token_pubkey.to_string(),
6695+
"transfer-fee-config",
6696+
],
6697+
)
6698+
.await
6699+
.unwrap();
6700+
6701+
let mint = config.rpc_client.get_account(&token_pubkey).await.unwrap();
6702+
let mint_state = StateWithExtensionsOwned::<Mint>::unpack(mint.data).unwrap();
6703+
let extension = mint_state.get_extension::<TransferFeeConfig>().unwrap();
6704+
6705+
assert_eq!(
6706+
Option::<Pubkey>::try_from(extension.transfer_fee_config_authority).unwrap(),
6707+
None,
6708+
);
6709+
6710+
// disable withdraw withheld authority
6711+
process_test_command(
6712+
&config,
6713+
&payer,
6714+
&[
6715+
"spl-token",
6716+
CommandName::Authorize.into(),
6717+
"--disable",
6718+
&token_pubkey.to_string(),
6719+
"withheld-withdraw",
6720+
],
6721+
)
6722+
.await
6723+
.unwrap();
6724+
6725+
let mint = config.rpc_client.get_account(&token_pubkey).await.unwrap();
6726+
let mint_state = StateWithExtensionsOwned::<Mint>::unpack(mint.data).unwrap();
6727+
let extension = mint_state.get_extension::<TransferFeeConfig>().unwrap();
6728+
6729+
assert_eq!(
6730+
Option::<Pubkey>::try_from(extension.withdraw_withheld_authority).unwrap(),
6731+
None,
6732+
);
66696733
}
66706734

66716735
#[tokio::test]

0 commit comments

Comments
 (0)