From ecd5c45726c7948e73db2b77453a005b04215eb0 Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Sat, 11 Mar 2023 05:46:02 +0900 Subject: [PATCH] [token-2022, token-cli] Enable Command::Authorize to update transfer fee extension authorities (#4078) --- token/cli/src/main.rs | 68 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 2 deletions(-) diff --git a/token/cli/src/main.rs b/token/cli/src/main.rs index 94a7ca2d..632c87bd 100644 --- a/token/cli/src/main.rs +++ b/token/cli/src/main.rs @@ -787,8 +787,24 @@ async fn command_authorize( )) } } - AuthorityType::TransferFeeConfig => unimplemented!(), - AuthorityType::WithheldWithdraw => unimplemented!(), + AuthorityType::TransferFeeConfig => { + if let Ok(transfer_fee_config) = mint.get_extension::() { + Ok(COption::::from( + transfer_fee_config.transfer_fee_config_authority, + )) + } else { + Err(format!("Mint `{}` does not support transfer fees", account)) + } + } + AuthorityType::WithheldWithdraw => { + if let Ok(transfer_fee_config) = mint.get_extension::() { + Ok(COption::::from( + transfer_fee_config.withdraw_withheld_authority, + )) + } else { + Err(format!("Mint `{}` does not support transfer fees", account)) + } + } AuthorityType::InterestRate => { if let Ok(interest_rate_config) = mint.get_extension::() { @@ -6666,6 +6682,54 @@ mod tests { u64::from(extension.newer_transfer_fee.maximum_fee), new_maximum_fee ); + + // disable transfer fee authority + process_test_command( + &config, + &payer, + &[ + "spl-token", + CommandName::Authorize.into(), + "--disable", + &token_pubkey.to_string(), + "transfer-fee-config", + ], + ) + .await + .unwrap(); + + let mint = config.rpc_client.get_account(&token_pubkey).await.unwrap(); + let mint_state = StateWithExtensionsOwned::::unpack(mint.data).unwrap(); + let extension = mint_state.get_extension::().unwrap(); + + assert_eq!( + Option::::try_from(extension.transfer_fee_config_authority).unwrap(), + None, + ); + + // disable withdraw withheld authority + process_test_command( + &config, + &payer, + &[ + "spl-token", + CommandName::Authorize.into(), + "--disable", + &token_pubkey.to_string(), + "withheld-withdraw", + ], + ) + .await + .unwrap(); + + let mint = config.rpc_client.get_account(&token_pubkey).await.unwrap(); + let mint_state = StateWithExtensionsOwned::::unpack(mint.data).unwrap(); + let extension = mint_state.get_extension::().unwrap(); + + assert_eq!( + Option::::try_from(extension.withdraw_withheld_authority).unwrap(), + None, + ); } #[tokio::test]