token-cli: use token client for command_mint
* client: change mint_to to accept decimals and prefer mint_checked * client: move multisig key winnowing into utility function
This commit is contained in:
parent
685e957ba9
commit
e540b172db
|
@ -1125,36 +1125,18 @@ async fn command_mint(
|
|||
);
|
||||
|
||||
let amount = spl_token::ui_amount_to_amount(ui_amount, mint_info.decimals);
|
||||
let instructions = if use_unchecked_instruction {
|
||||
vec![mint_to(
|
||||
&mint_info.program_id,
|
||||
&token,
|
||||
&recipient,
|
||||
&mint_authority,
|
||||
&config.multisigner_pubkeys,
|
||||
amount,
|
||||
)?]
|
||||
let decimals = if use_unchecked_instruction {
|
||||
None
|
||||
} else {
|
||||
vec![mint_to_checked(
|
||||
&mint_info.program_id,
|
||||
&token,
|
||||
&recipient,
|
||||
&mint_authority,
|
||||
&config.multisigner_pubkeys,
|
||||
amount,
|
||||
mint_info.decimals,
|
||||
)?]
|
||||
Some(mint_info.decimals)
|
||||
};
|
||||
let tx_return = handle_tx(
|
||||
&CliSignerInfo {
|
||||
signers: bulk_signers,
|
||||
},
|
||||
config,
|
||||
false,
|
||||
0,
|
||||
instructions,
|
||||
)
|
||||
.await?;
|
||||
|
||||
let token = token_client_from_config(config, &mint_info.program_id, &mint_info.address);
|
||||
let res = token
|
||||
.mint_to(&recipient, &mint_authority, amount, decimals, &bulk_signers)
|
||||
.await?;
|
||||
|
||||
let tx_return = finish_tx(config, &res, false).await?;
|
||||
Ok(match tx_return {
|
||||
TransactionReturnData::CliSignature(signature) => {
|
||||
config.output_format.formatted_string(&signature)
|
||||
|
|
|
@ -281,7 +281,21 @@ where
|
|||
))))
|
||||
}
|
||||
|
||||
pub async fn construct_tx<S: Signers>(
|
||||
fn get_multisig_signers<S: Signers>(
|
||||
&self,
|
||||
authority: &Pubkey,
|
||||
signing_keypairs: &S,
|
||||
) -> Vec<Pubkey> {
|
||||
let signing_pubkeys = signing_keypairs.pubkeys();
|
||||
|
||||
if signing_pubkeys == [*authority] {
|
||||
vec![]
|
||||
} else {
|
||||
signing_pubkeys
|
||||
}
|
||||
}
|
||||
|
||||
async fn construct_tx<S: Signers>(
|
||||
&self,
|
||||
token_instructions: &[Instruction],
|
||||
signing_keypairs: &S,
|
||||
|
@ -544,12 +558,7 @@ where
|
|||
authority_type: instruction::AuthorityType,
|
||||
signing_keypairs: &S,
|
||||
) -> TokenResult<T::Output> {
|
||||
let signing_pubkeys = signing_keypairs.pubkeys();
|
||||
let multisig_signing_pubkeys = if signing_pubkeys == [*authority] {
|
||||
vec![]
|
||||
} else {
|
||||
signing_pubkeys.iter().collect::<Vec<_>>()
|
||||
};
|
||||
let multisig_signers = self.get_multisig_signers(authority, signing_keypairs);
|
||||
|
||||
self.process_ixs(
|
||||
&[instruction::set_authority(
|
||||
|
@ -558,7 +567,7 @@ where
|
|||
new_authority,
|
||||
authority_type,
|
||||
authority,
|
||||
&multisig_signing_pubkeys,
|
||||
&multisig_signers.iter().collect::<Vec<_>>(),
|
||||
)?],
|
||||
signing_keypairs,
|
||||
)
|
||||
|
@ -566,25 +575,38 @@ where
|
|||
}
|
||||
|
||||
/// Mint new tokens
|
||||
pub async fn mint_to<S: Signer>(
|
||||
pub async fn mint_to<S: Signers>(
|
||||
&self,
|
||||
destination: &Pubkey,
|
||||
authority: &S,
|
||||
authority: &Pubkey,
|
||||
amount: u64,
|
||||
) -> TokenResult<()> {
|
||||
self.process_ixs(
|
||||
&[instruction::mint_to(
|
||||
decimals: Option<u8>,
|
||||
signing_keypairs: &S,
|
||||
) -> TokenResult<T::Output> {
|
||||
let multisig_signers = self.get_multisig_signers(authority, signing_keypairs);
|
||||
|
||||
let instructions = if let Some(decimals) = decimals {
|
||||
[instruction::mint_to_checked(
|
||||
&self.program_id,
|
||||
&self.pubkey,
|
||||
destination,
|
||||
&authority.pubkey(),
|
||||
&[],
|
||||
authority,
|
||||
&multisig_signers.iter().collect::<Vec<_>>(),
|
||||
amount,
|
||||
)?],
|
||||
&[authority],
|
||||
)
|
||||
.await
|
||||
.map(|_| ())
|
||||
decimals,
|
||||
)?]
|
||||
} else {
|
||||
[instruction::mint_to(
|
||||
&self.program_id,
|
||||
&self.pubkey,
|
||||
destination,
|
||||
authority,
|
||||
&multisig_signers.iter().collect::<Vec<_>>(),
|
||||
amount,
|
||||
)?]
|
||||
};
|
||||
|
||||
self.process_ixs(&instructions, signing_keypairs).await
|
||||
}
|
||||
|
||||
/// Transfer tokens to another account
|
||||
|
@ -779,19 +801,14 @@ where
|
|||
authority: &Pubkey,
|
||||
signing_keypairs: &S,
|
||||
) -> TokenResult<T::Output> {
|
||||
let signing_pubkeys = signing_keypairs.pubkeys();
|
||||
let multisig_signing_pubkeys = if signing_pubkeys == [*authority] {
|
||||
vec![]
|
||||
} else {
|
||||
signing_pubkeys.iter().collect::<Vec<_>>()
|
||||
};
|
||||
let multisig_signers = self.get_multisig_signers(authority, signing_keypairs);
|
||||
|
||||
let mut instructions = vec![instruction::close_account(
|
||||
&self.program_id,
|
||||
account,
|
||||
destination,
|
||||
authority,
|
||||
&multisig_signing_pubkeys,
|
||||
&multisig_signers.iter().collect::<Vec<_>>(),
|
||||
)?];
|
||||
|
||||
if let Ok(Some(destination_account)) = self.client.get_account(*destination).await {
|
||||
|
|
|
@ -145,6 +145,7 @@ async fn get_or_create_associated_token_account() {
|
|||
#[tokio::test]
|
||||
async fn set_authority() {
|
||||
let TestContext {
|
||||
decimals,
|
||||
mint_authority,
|
||||
token,
|
||||
alice,
|
||||
|
@ -158,7 +159,13 @@ async fn set_authority() {
|
|||
.expect("failed to create associated token account");
|
||||
|
||||
token
|
||||
.mint_to(&alice_vault, &mint_authority, 1)
|
||||
.mint_to(
|
||||
&alice_vault,
|
||||
&mint_authority.pubkey(),
|
||||
1,
|
||||
Some(decimals),
|
||||
&vec![&mint_authority],
|
||||
)
|
||||
.await
|
||||
.expect("failed to mint token");
|
||||
|
||||
|
@ -182,7 +189,13 @@ async fn set_authority() {
|
|||
// TODO: compare
|
||||
// Err(Client(TransactionError(InstructionError(0, Custom(5)))))
|
||||
assert!(token
|
||||
.mint_to(&alice_vault, &mint_authority, 2)
|
||||
.mint_to(
|
||||
&alice_vault,
|
||||
&mint_authority.pubkey(),
|
||||
2,
|
||||
Some(decimals),
|
||||
&vec![&mint_authority]
|
||||
)
|
||||
.await
|
||||
.is_err());
|
||||
|
||||
|
@ -228,7 +241,13 @@ async fn mint_to() {
|
|||
|
||||
let mint_amount = 10 * u64::pow(10, decimals as u32);
|
||||
token
|
||||
.mint_to(&alice_vault, &mint_authority, mint_amount)
|
||||
.mint_to(
|
||||
&alice_vault,
|
||||
&mint_authority.pubkey(),
|
||||
mint_amount,
|
||||
Some(decimals),
|
||||
&vec![&mint_authority],
|
||||
)
|
||||
.await
|
||||
.expect("failed to mint token");
|
||||
|
||||
|
@ -268,7 +287,13 @@ async fn transfer() {
|
|||
|
||||
let mint_amount = 10 * u64::pow(10, decimals as u32);
|
||||
token
|
||||
.mint_to(&alice_vault, &mint_authority, mint_amount)
|
||||
.mint_to(
|
||||
&alice_vault,
|
||||
&mint_authority.pubkey(),
|
||||
mint_amount,
|
||||
Some(decimals),
|
||||
&vec![&mint_authority],
|
||||
)
|
||||
.await
|
||||
.expect("failed to mint token");
|
||||
|
||||
|
|
|
@ -31,7 +31,13 @@ async fn run_basic(context: TestContext) {
|
|||
// mint a token
|
||||
let amount = 10;
|
||||
token
|
||||
.mint_to(&alice_account, &mint_authority, amount)
|
||||
.mint_to(
|
||||
&alice_account,
|
||||
&mint_authority.pubkey(),
|
||||
amount,
|
||||
Some(decimals),
|
||||
&vec![&mint_authority],
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
@ -114,7 +120,13 @@ async fn run_self_owned(context: TestContext) {
|
|||
// mint a token
|
||||
let amount = 10;
|
||||
token
|
||||
.mint_to(&alice_account, &mint_authority, amount)
|
||||
.mint_to(
|
||||
&alice_account,
|
||||
&mint_authority.pubkey(),
|
||||
amount,
|
||||
Some(decimals),
|
||||
&vec![&mint_authority],
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
@ -167,7 +179,13 @@ async fn run_burn_and_close_system_or_incinerator(context: TestContext, non_owne
|
|||
|
||||
// mint a token
|
||||
token
|
||||
.mint_to(&alice_account, &mint_authority, 1)
|
||||
.mint_to(
|
||||
&alice_account,
|
||||
&mint_authority.pubkey(),
|
||||
1,
|
||||
Some(decimals),
|
||||
&vec![&mint_authority],
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
|
|
@ -134,7 +134,13 @@ impl ConfidentialTokenAccountMeta {
|
|||
let meta = Self::new(token, owner).await;
|
||||
|
||||
token
|
||||
.mint_to(&meta.token_account, mint_authority, amount)
|
||||
.mint_to(
|
||||
&meta.token_account,
|
||||
&mint_authority.pubkey(),
|
||||
amount,
|
||||
Some(decimals),
|
||||
&vec![mint_authority],
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
@ -447,7 +453,13 @@ async fn ct_deposit() {
|
|||
let alice_meta = ConfidentialTokenAccountMeta::new(&token, &alice).await;
|
||||
|
||||
token
|
||||
.mint_to(&alice_meta.token_account, &mint_authority, 65537)
|
||||
.mint_to(
|
||||
&alice_meta.token_account,
|
||||
&mint_authority.pubkey(),
|
||||
65537,
|
||||
Some(decimals),
|
||||
&vec![&mint_authority],
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
|
|
@ -67,7 +67,13 @@ async fn run_basic(
|
|||
// mint tokens
|
||||
let amount = 100;
|
||||
token
|
||||
.mint_to(&alice_account, &mint_authority, amount)
|
||||
.mint_to(
|
||||
&alice_account,
|
||||
&mint_authority.pubkey(),
|
||||
amount,
|
||||
Some(decimals),
|
||||
&vec![&mint_authority],
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ async fn test_memo_transfers(
|
|||
bob_account: Pubkey,
|
||||
) {
|
||||
let TokenContext {
|
||||
decimals,
|
||||
mint_authority,
|
||||
token,
|
||||
alice,
|
||||
|
@ -39,7 +40,13 @@ async fn test_memo_transfers(
|
|||
|
||||
// mint tokens
|
||||
token
|
||||
.mint_to(&alice_account, &mint_authority, 4242)
|
||||
.mint_to(
|
||||
&alice_account,
|
||||
&mint_authority.pubkey(),
|
||||
4242,
|
||||
Some(decimals),
|
||||
&vec![&mint_authority],
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
|
|
@ -244,6 +244,7 @@ async fn fail_close_with_supply() {
|
|||
.await
|
||||
.unwrap();
|
||||
let TokenContext {
|
||||
decimals,
|
||||
mint_authority,
|
||||
token,
|
||||
..
|
||||
|
@ -256,7 +257,16 @@ async fn fail_close_with_supply() {
|
|||
.create_auxiliary_token_account(&account, &owner)
|
||||
.await
|
||||
.unwrap();
|
||||
token.mint_to(&account, &mint_authority, 1).await.unwrap();
|
||||
token
|
||||
.mint_to(
|
||||
&account,
|
||||
&mint_authority.pubkey(),
|
||||
1,
|
||||
Some(decimals),
|
||||
&vec![&mint_authority],
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
// fail close
|
||||
let destination = Pubkey::new_unique();
|
||||
|
|
|
@ -42,7 +42,13 @@ async fn run_basic_transfers(context: TestContext, test_mode: TestMode) {
|
|||
// mint a token
|
||||
let amount = 10;
|
||||
token
|
||||
.mint_to(&alice_account, &mint_authority, amount)
|
||||
.mint_to(
|
||||
&alice_account,
|
||||
&mint_authority.pubkey(),
|
||||
amount,
|
||||
Some(decimals),
|
||||
&vec![&mint_authority],
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
@ -131,7 +137,13 @@ async fn run_self_transfers(context: TestContext, test_mode: TestMode) {
|
|||
// mint a token
|
||||
let amount = 10;
|
||||
token
|
||||
.mint_to(&alice_account, &mint_authority, amount)
|
||||
.mint_to(
|
||||
&alice_account,
|
||||
&mint_authority.pubkey(),
|
||||
amount,
|
||||
Some(decimals),
|
||||
&vec![&mint_authority],
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
@ -208,7 +220,13 @@ async fn run_self_owned(context: TestContext, test_mode: TestMode) {
|
|||
// mint a token
|
||||
let amount = 10;
|
||||
token
|
||||
.mint_to(&alice_account, &mint_authority, amount)
|
||||
.mint_to(
|
||||
&alice_account,
|
||||
&mint_authority.pubkey(),
|
||||
amount,
|
||||
Some(decimals),
|
||||
&vec![&mint_authority],
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
@ -282,7 +300,13 @@ async fn transfer_with_fee_on_mint_without_fee_configured() {
|
|||
// mint some tokens
|
||||
let amount = 10;
|
||||
token
|
||||
.mint_to(&alice_account, &mint_authority, amount)
|
||||
.mint_to(
|
||||
&alice_account,
|
||||
&mint_authority.pubkey(),
|
||||
amount,
|
||||
Some(decimals),
|
||||
&vec![&mint_authority],
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
|
|
@ -130,7 +130,13 @@ async fn create_mint_with_accounts(alice_amount: u64) -> TokenWithAccounts {
|
|||
|
||||
// mint tokens
|
||||
token
|
||||
.mint_to(&alice_account, &mint_authority, alice_amount)
|
||||
.mint_to(
|
||||
&alice_account,
|
||||
&mint_authority.pubkey(),
|
||||
alice_amount,
|
||||
Some(decimals),
|
||||
&vec![&mint_authority],
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
TokenWithAccounts {
|
||||
|
|
Loading…
Reference in New Issue