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

Commit 37168db

Browse files
committed
token-cli: convert required memos and interest rate to client
1 parent 7e3a624 commit 37168db

File tree

2 files changed

+36
-65
lines changed

2 files changed

+36
-65
lines changed

token/cli/src/main.rs

Lines changed: 35 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,8 @@ use spl_associated_token_account::{
4343
};
4444
use spl_token_2022::{
4545
extension::{
46-
interest_bearing_mint, interest_bearing_mint::InterestBearingConfig,
47-
memo_transfer::MemoTransfer, mint_close_authority::MintCloseAuthority, ExtensionType,
48-
StateWithExtensionsOwned,
46+
interest_bearing_mint::InterestBearingConfig, memo_transfer::MemoTransfer,
47+
mint_close_authority::MintCloseAuthority, ExtensionType, StateWithExtensionsOwned,
4948
},
5049
instruction::*,
5150
state::{Account, Mint, Multisig},
@@ -450,6 +449,8 @@ async fn command_set_interest_rate(
450449
rate_bps: i16,
451450
bulk_signers: Vec<Arc<dyn Signer>>,
452451
) -> CommandResult {
452+
let token = token_client_from_config(config, &token_pubkey);
453+
453454
if !config.sign_only {
454455
let mint_account = config.get_account_checked(&token_pubkey).await?;
455456

@@ -484,25 +485,11 @@ async fn command_set_interest_rate(
484485
),
485486
);
486487

487-
let instructions = vec![interest_bearing_mint::instruction::update_rate(
488-
&config.program_id,
489-
&token_pubkey,
490-
&rate_authority,
491-
&[&rate_authority],
492-
rate_bps,
493-
)?];
494-
495-
let tx_return = handle_tx(
496-
&CliSignerInfo {
497-
signers: bulk_signers,
498-
},
499-
config,
500-
false,
501-
0,
502-
instructions,
503-
)
504-
.await?;
488+
let res = token
489+
.update_interest_rate(&rate_authority, rate_bps, &bulk_signers)
490+
.await?;
505491

492+
let tx_return = finish_tx(config, &res, false).await?;
506493
Ok(match tx_return {
507494
TransactionReturnData::CliSignature(signature) => {
508495
config.output_format.formatted_string(&signature)
@@ -1871,11 +1858,14 @@ async fn command_required_transfer_memos(
18711858
if config.sign_only {
18721859
panic!("Config can not be sign only for enabling/disabling required transfer memos.");
18731860
}
1861+
18741862
let account = config.get_account_checked(&token_account_address).await?;
1875-
let mut instructions: Vec<Instruction> = Vec::new();
1876-
// Reallocation (if needed)
18771863
let current_account_len = account.data.len();
1864+
18781865
let state_with_extension = StateWithExtensionsOwned::<Account>::unpack(account.data)?;
1866+
let token = token_client_from_config(config, &state_with_extension.base.mint);
1867+
1868+
// Reallocation (if needed)
18791869
let mut existing_extensions: Vec<ExtensionType> = state_with_extension.get_extension_types()?;
18801870
if existing_extensions.contains(&ExtensionType::MemoTransfer) {
18811871
let extension_data: bool = state_with_extension
@@ -1896,45 +1886,28 @@ async fn command_required_transfer_memos(
18961886
existing_extensions.push(ExtensionType::MemoTransfer);
18971887
let needed_account_len = ExtensionType::get_account_len::<Account>(&existing_extensions);
18981888
if needed_account_len > current_account_len {
1899-
instructions.push(reallocate(
1900-
&config.program_id,
1901-
&token_account_address,
1902-
&config.fee_payer.pubkey(),
1903-
&owner,
1904-
&config.multisigner_pubkeys,
1905-
&existing_extensions,
1906-
)?);
1889+
token
1890+
.reallocate(
1891+
&token_account_address,
1892+
&owner,
1893+
&[ExtensionType::MemoTransfer],
1894+
&bulk_signers,
1895+
)
1896+
.await?;
19071897
}
19081898
}
1909-
if enable_memos {
1910-
instructions.push(
1911-
spl_token_2022::extension::memo_transfer::instruction::enable_required_transfer_memos(
1912-
&config.program_id,
1913-
&token_account_address,
1914-
&owner,
1915-
&config.multisigner_pubkeys,
1916-
)?,
1917-
);
1899+
1900+
let res = if enable_memos {
1901+
token
1902+
.enable_required_transfer_memos(&token_account_address, &owner, &bulk_signers)
1903+
.await
19181904
} else {
1919-
instructions.push(
1920-
spl_token_2022::extension::memo_transfer::instruction::disable_required_transfer_memos(
1921-
&config.program_id,
1922-
&token_account_address,
1923-
&owner,
1924-
&config.multisigner_pubkeys,
1925-
)?,
1926-
);
1927-
}
1928-
let tx_return = handle_tx(
1929-
&CliSignerInfo {
1930-
signers: bulk_signers,
1931-
},
1932-
config,
1933-
false,
1934-
0,
1935-
instructions,
1936-
)
1937-
.await?;
1905+
token
1906+
.disable_required_transfer_memos(&token_account_address, &owner, &bulk_signers)
1907+
.await
1908+
}?;
1909+
1910+
let tx_return = finish_tx(config, &res, false).await?;
19381911
Ok(match tx_return {
19391912
TransactionReturnData::CliSignature(signature) => {
19401913
config.output_format.formatted_string(&signature)
@@ -2929,7 +2902,6 @@ fn app<'a, 'b>(
29292902
)
29302903
.arg(multisig_signer_arg())
29312904
.nonce_args(true)
2932-
.offline_args()
29332905
)
29342906
.subcommand(
29352907
SubCommand::with_name(CommandName::DisableRequiredTransferMemos.into())
@@ -2948,7 +2920,6 @@ fn app<'a, 'b>(
29482920
)
29492921
.arg(multisig_signer_arg())
29502922
.nonce_args(true)
2951-
.offline_args()
29522923
)
29532924
}
29542925

@@ -3933,7 +3904,7 @@ mod tests {
39333904
let mint_account =
39343905
StateWithExtensionsOwned::<spl_token_2022::state::Mint>::unpack(account.data).unwrap();
39353906
let extension = mint_account
3936-
.get_extension::<interest_bearing_mint::InterestBearingConfig>()
3907+
.get_extension::<InterestBearingConfig>()
39373908
.unwrap();
39383909
assert_eq!(account.owner, spl_token_2022::id());
39393910
assert_eq!(i16::from(extension.current_rate), rate_bps);
@@ -3955,7 +3926,7 @@ mod tests {
39553926
let mint_account =
39563927
StateWithExtensionsOwned::<spl_token_2022::state::Mint>::unpack(account.data).unwrap();
39573928
let extension = mint_account
3958-
.get_extension::<interest_bearing_mint::InterestBearingConfig>()
3929+
.get_extension::<InterestBearingConfig>()
39593930
.unwrap();
39603931
assert_eq!(account.owner, spl_token_2022::id());
39613932
assert_eq!(i16::from(extension.current_rate), initial_rate);
@@ -3976,7 +3947,7 @@ mod tests {
39763947
let mint_account =
39773948
StateWithExtensionsOwned::<spl_token_2022::state::Mint>::unpack(account.data).unwrap();
39783949
let extension = mint_account
3979-
.get_extension::<interest_bearing_mint::InterestBearingConfig>()
3950+
.get_extension::<InterestBearingConfig>()
39803951
.unwrap();
39813952
assert_eq!(i16::from(extension.current_rate), new_rate);
39823953
}

token/program-2022-test/tests/confidential_transfer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ impl ConfidentialTokenAccountMeta {
154154
.unwrap();
155155

156156
token
157-
.enable_required_transfer_memos(&token_account, owner)
157+
.enable_required_transfer_memos(&token_account, &owner.pubkey(), &vec![owner])
158158
.await
159159
.unwrap();
160160

0 commit comments

Comments
 (0)