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

Commit 304e1bd

Browse files
committed
token-cli: implement --immutable for wrap
1 parent 5756e7f commit 304e1bd

File tree

1 file changed

+56
-10
lines changed

1 file changed

+56
-10
lines changed

token/cli/src/main.rs

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,6 +1210,7 @@ async fn command_wrap(
12101210
sol: f64,
12111211
wallet_address: Pubkey,
12121212
wrapped_sol_account: Option<Pubkey>,
1213+
immutable_owner: bool,
12131214
bulk_signers: BulkSigners,
12141215
) -> CommandResult {
12151216
let lamports = sol_to_lamports(sol);
@@ -1235,9 +1236,24 @@ async fn command_wrap(
12351236
check_wallet_balance(config, &wallet_address, lamports).await?;
12361237
}
12371238

1238-
let res = token
1239-
.wrap_transferable(&account, &wallet_address, lamports, &bulk_signers)
1240-
.await?;
1239+
let res = if immutable_owner {
1240+
if config.program_id == spl_token::id() {
1241+
return Err(format!(
1242+
"Specified --immutable, but token program {} does not support the extension",
1243+
config.program_id
1244+
)
1245+
.into());
1246+
}
1247+
1248+
token
1249+
.wrap(&account, &wallet_address, lamports, &bulk_signers)
1250+
.await?
1251+
} else {
1252+
// this case is hit for a token22 ata, which is always immutable. but it does the right thing anyway
1253+
token
1254+
.wrap_transferable(&account, &wallet_address, lamports, &bulk_signers)
1255+
.await?
1256+
};
12411257

12421258
let tx_return = finish_tx(config, &res, false).await?;
12431259
Ok(match tx_return {
@@ -2530,6 +2546,14 @@ fn app<'a, 'b>(
25302546
.long("create-aux-account")
25312547
.help("Wrap SOL in an auxiliary account instead of associated token account"),
25322548
)
2549+
.arg(
2550+
Arg::with_name("immutable")
2551+
.long("immutable")
2552+
.takes_value(false)
2553+
.help(
2554+
"Lock the owner of this token account from ever being changed"
2555+
),
2556+
)
25332557
.nonce_args(true)
25342558
.offline_args(),
25352559
)
@@ -3276,7 +3300,15 @@ async fn process_command<'a>(
32763300
bulk_signers.push(wallet_signer);
32773301
}
32783302

3279-
command_wrap(config, amount, wallet_address, account, bulk_signers).await
3303+
command_wrap(
3304+
config,
3305+
amount,
3306+
wallet_address,
3307+
account,
3308+
arg_matches.is_present("immutable"),
3309+
bulk_signers,
3310+
)
3311+
.await
32803312
}
32813313
(CommandName::Unwrap, arg_matches) => {
32823314
let (wallet_signer, wallet_address) =
@@ -4142,9 +4174,16 @@ mod tests {
41424174
do_create_native_mint(&config, &program_id, &payer).await;
41434175
let (signer, account) = new_throwaway_signer();
41444176
let bulk_signers: Vec<Arc<dyn Signer>> = vec![Arc::new(clone_keypair(&payer)), signer];
4145-
command_wrap(&config, 0.5, payer.pubkey(), Some(account), bulk_signers)
4146-
.await
4147-
.unwrap();
4177+
command_wrap(
4178+
&config,
4179+
0.5,
4180+
payer.pubkey(),
4181+
Some(account),
4182+
false,
4183+
bulk_signers,
4184+
)
4185+
.await
4186+
.unwrap();
41484187
let result = process_test_command(
41494188
&config,
41504189
&payer,
@@ -4304,9 +4343,16 @@ mod tests {
43044343
let source = create_associated_account(&config, &payer, token).await;
43054344
do_create_native_mint(&config, &program_id, &payer).await;
43064345
let ui_amount = 10.0;
4307-
command_wrap(&config, ui_amount, payer.pubkey(), None, bulk_signers)
4308-
.await
4309-
.unwrap();
4346+
command_wrap(
4347+
&config,
4348+
ui_amount,
4349+
payer.pubkey(),
4350+
None,
4351+
false,
4352+
bulk_signers,
4353+
)
4354+
.await
4355+
.unwrap();
43104356

43114357
let recipient = get_associated_token_address_with_program_id(
43124358
&payer.pubkey(),

0 commit comments

Comments
 (0)