token-2022: make extension instruction builders consistent with vanilla token (#2782)
* Make TransferFee and MintClose ix builders consistent with vanilla token * Make ConfidentialTransfer ix builders consistent with vanilla token
This commit is contained in:
parent
28e779d480
commit
c03c1fc7b4
|
@ -327,8 +327,8 @@ fn encode_instruction<T: Pod>(
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a `InitializeMint` instruction
|
/// Create a `InitializeMint` instruction
|
||||||
pub fn initialize_mint(mint: Pubkey, auditor: &ConfidentialTransferMint) -> Instruction {
|
pub fn initialize_mint(mint: &Pubkey, auditor: &ConfidentialTransferMint) -> Instruction {
|
||||||
let accounts = vec![AccountMeta::new(mint, false)];
|
let accounts = vec![AccountMeta::new(*mint, false)];
|
||||||
encode_instruction(
|
encode_instruction(
|
||||||
accounts,
|
accounts,
|
||||||
ConfidentialTransferInstruction::InitializeMint,
|
ConfidentialTransferInstruction::InitializeMint,
|
||||||
|
@ -337,13 +337,13 @@ pub fn initialize_mint(mint: Pubkey, auditor: &ConfidentialTransferMint) -> Inst
|
||||||
}
|
}
|
||||||
/// Create a `UpdateMint` instruction
|
/// Create a `UpdateMint` instruction
|
||||||
pub fn update_mint(
|
pub fn update_mint(
|
||||||
mint: Pubkey,
|
mint: &Pubkey,
|
||||||
new_auditor: &ConfidentialTransferMint,
|
new_auditor: &ConfidentialTransferMint,
|
||||||
authority: Pubkey,
|
authority: &Pubkey,
|
||||||
) -> Instruction {
|
) -> Instruction {
|
||||||
let accounts = vec![
|
let accounts = vec![
|
||||||
AccountMeta::new(mint, false),
|
AccountMeta::new(*mint, false),
|
||||||
AccountMeta::new_readonly(authority, true),
|
AccountMeta::new_readonly(*authority, true),
|
||||||
AccountMeta::new_readonly(
|
AccountMeta::new_readonly(
|
||||||
new_auditor.authority,
|
new_auditor.authority,
|
||||||
new_auditor.authority != Pubkey::default(),
|
new_auditor.authority != Pubkey::default(),
|
||||||
|
@ -359,17 +359,17 @@ pub fn update_mint(
|
||||||
/// Create a `ConfigureAccount` instruction
|
/// Create a `ConfigureAccount` instruction
|
||||||
#[cfg(not(target_arch = "bpf"))]
|
#[cfg(not(target_arch = "bpf"))]
|
||||||
pub fn configure_account(
|
pub fn configure_account(
|
||||||
token_account: Pubkey,
|
token_account: &Pubkey,
|
||||||
mint: Pubkey,
|
mint: &Pubkey,
|
||||||
elgamal_pk: ElGamalPubkey,
|
elgamal_pk: ElGamalPubkey,
|
||||||
decryptable_zero_balance: AeCiphertext,
|
decryptable_zero_balance: AeCiphertext,
|
||||||
authority: Pubkey,
|
authority: &Pubkey,
|
||||||
multisig_signers: &[&Pubkey],
|
multisig_signers: &[&Pubkey],
|
||||||
) -> Vec<Instruction> {
|
) -> Vec<Instruction> {
|
||||||
let mut accounts = vec![
|
let mut accounts = vec![
|
||||||
AccountMeta::new(token_account, false),
|
AccountMeta::new(*token_account, false),
|
||||||
AccountMeta::new_readonly(mint, false),
|
AccountMeta::new_readonly(*mint, false),
|
||||||
AccountMeta::new_readonly(authority, multisig_signers.is_empty()),
|
AccountMeta::new_readonly(*authority, multisig_signers.is_empty()),
|
||||||
];
|
];
|
||||||
|
|
||||||
for multisig_signer in multisig_signers.iter() {
|
for multisig_signer in multisig_signers.iter() {
|
||||||
|
@ -387,11 +387,15 @@ pub fn configure_account(
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create an `ApproveAccount` instruction
|
/// Create an `ApproveAccount` instruction
|
||||||
pub fn approve_account(mint: Pubkey, account_to_approve: Pubkey, authority: Pubkey) -> Instruction {
|
pub fn approve_account(
|
||||||
|
mint: &Pubkey,
|
||||||
|
account_to_approve: &Pubkey,
|
||||||
|
authority: &Pubkey,
|
||||||
|
) -> Instruction {
|
||||||
let accounts = vec![
|
let accounts = vec![
|
||||||
AccountMeta::new(account_to_approve, false),
|
AccountMeta::new(*account_to_approve, false),
|
||||||
AccountMeta::new_readonly(mint, false),
|
AccountMeta::new_readonly(*mint, false),
|
||||||
AccountMeta::new_readonly(authority, true),
|
AccountMeta::new_readonly(*authority, true),
|
||||||
];
|
];
|
||||||
encode_instruction(
|
encode_instruction(
|
||||||
accounts,
|
accounts,
|
||||||
|
@ -404,15 +408,15 @@ pub fn approve_account(mint: Pubkey, account_to_approve: Pubkey, authority: Pubk
|
||||||
///
|
///
|
||||||
/// This instruction is suitable for use with a cross-program `invoke`
|
/// This instruction is suitable for use with a cross-program `invoke`
|
||||||
pub fn inner_empty_account(
|
pub fn inner_empty_account(
|
||||||
token_account: Pubkey,
|
token_account: &Pubkey,
|
||||||
authority: Pubkey,
|
authority: &Pubkey,
|
||||||
multisig_signers: &[&Pubkey],
|
multisig_signers: &[&Pubkey],
|
||||||
proof_instruction_offset: i8,
|
proof_instruction_offset: i8,
|
||||||
) -> Instruction {
|
) -> Instruction {
|
||||||
let mut accounts = vec![
|
let mut accounts = vec![
|
||||||
AccountMeta::new_readonly(token_account, false),
|
AccountMeta::new_readonly(*token_account, false),
|
||||||
AccountMeta::new_readonly(sysvar::instructions::id(), false),
|
AccountMeta::new_readonly(sysvar::instructions::id(), false),
|
||||||
AccountMeta::new_readonly(authority, multisig_signers.is_empty()),
|
AccountMeta::new_readonly(*authority, multisig_signers.is_empty()),
|
||||||
];
|
];
|
||||||
|
|
||||||
for multisig_signer in multisig_signers.iter() {
|
for multisig_signer in multisig_signers.iter() {
|
||||||
|
@ -430,8 +434,8 @@ pub fn inner_empty_account(
|
||||||
|
|
||||||
/// Create a `EmptyAccount` instruction
|
/// Create a `EmptyAccount` instruction
|
||||||
pub fn empty_account(
|
pub fn empty_account(
|
||||||
token_account: Pubkey,
|
token_account: &Pubkey,
|
||||||
authority: Pubkey,
|
authority: &Pubkey,
|
||||||
multisig_signers: &[&Pubkey],
|
multisig_signers: &[&Pubkey],
|
||||||
proof_data: &CloseAccountData,
|
proof_data: &CloseAccountData,
|
||||||
) -> Vec<Instruction> {
|
) -> Vec<Instruction> {
|
||||||
|
@ -443,19 +447,19 @@ pub fn empty_account(
|
||||||
|
|
||||||
/// Create a `Deposit` instruction
|
/// Create a `Deposit` instruction
|
||||||
pub fn deposit(
|
pub fn deposit(
|
||||||
source_token_account: Pubkey,
|
source_token_account: &Pubkey,
|
||||||
mint: Pubkey,
|
mint: &Pubkey,
|
||||||
destination_token_account: Pubkey,
|
destination_token_account: &Pubkey,
|
||||||
amount: u64,
|
amount: u64,
|
||||||
decimals: u8,
|
decimals: u8,
|
||||||
authority: Pubkey,
|
authority: &Pubkey,
|
||||||
multisig_signers: &[&Pubkey],
|
multisig_signers: &[&Pubkey],
|
||||||
) -> Vec<Instruction> {
|
) -> Vec<Instruction> {
|
||||||
let mut accounts = vec![
|
let mut accounts = vec![
|
||||||
AccountMeta::new(source_token_account, false),
|
AccountMeta::new(*source_token_account, false),
|
||||||
AccountMeta::new(destination_token_account, false),
|
AccountMeta::new(*destination_token_account, false),
|
||||||
AccountMeta::new_readonly(mint, false),
|
AccountMeta::new_readonly(*mint, false),
|
||||||
AccountMeta::new_readonly(authority, multisig_signers.is_empty()),
|
AccountMeta::new_readonly(*authority, multisig_signers.is_empty()),
|
||||||
];
|
];
|
||||||
|
|
||||||
for multisig_signer in multisig_signers.iter() {
|
for multisig_signer in multisig_signers.iter() {
|
||||||
|
@ -477,22 +481,22 @@ pub fn deposit(
|
||||||
/// This instruction is suitable for use with a cross-program `invoke`
|
/// This instruction is suitable for use with a cross-program `invoke`
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn inner_withdraw(
|
pub fn inner_withdraw(
|
||||||
source_token_account: Pubkey,
|
source_token_account: &Pubkey,
|
||||||
destination_token_account: Pubkey,
|
destination_token_account: &Pubkey,
|
||||||
mint: &Pubkey,
|
mint: &Pubkey,
|
||||||
amount: u64,
|
amount: u64,
|
||||||
decimals: u8,
|
decimals: u8,
|
||||||
new_decryptable_available_balance: pod::AeCiphertext,
|
new_decryptable_available_balance: pod::AeCiphertext,
|
||||||
authority: Pubkey,
|
authority: &Pubkey,
|
||||||
multisig_signers: &[&Pubkey],
|
multisig_signers: &[&Pubkey],
|
||||||
proof_instruction_offset: i8,
|
proof_instruction_offset: i8,
|
||||||
) -> Instruction {
|
) -> Instruction {
|
||||||
let mut accounts = vec![
|
let mut accounts = vec![
|
||||||
AccountMeta::new(source_token_account, false),
|
AccountMeta::new(*source_token_account, false),
|
||||||
AccountMeta::new(destination_token_account, false),
|
AccountMeta::new(*destination_token_account, false),
|
||||||
AccountMeta::new_readonly(*mint, false),
|
AccountMeta::new_readonly(*mint, false),
|
||||||
AccountMeta::new_readonly(sysvar::instructions::id(), false),
|
AccountMeta::new_readonly(sysvar::instructions::id(), false),
|
||||||
AccountMeta::new_readonly(authority, multisig_signers.is_empty()),
|
AccountMeta::new_readonly(*authority, multisig_signers.is_empty()),
|
||||||
];
|
];
|
||||||
|
|
||||||
for multisig_signer in multisig_signers.iter() {
|
for multisig_signer in multisig_signers.iter() {
|
||||||
|
@ -515,13 +519,13 @@ pub fn inner_withdraw(
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
#[cfg(not(target_arch = "bpf"))]
|
#[cfg(not(target_arch = "bpf"))]
|
||||||
pub fn withdraw(
|
pub fn withdraw(
|
||||||
source_token_account: Pubkey,
|
source_token_account: &Pubkey,
|
||||||
destination_token_account: Pubkey,
|
destination_token_account: &Pubkey,
|
||||||
mint: &Pubkey,
|
mint: &Pubkey,
|
||||||
amount: u64,
|
amount: u64,
|
||||||
decimals: u8,
|
decimals: u8,
|
||||||
new_decryptable_available_balance: AeCiphertext,
|
new_decryptable_available_balance: AeCiphertext,
|
||||||
authority: Pubkey,
|
authority: &Pubkey,
|
||||||
multisig_signers: &[&Pubkey],
|
multisig_signers: &[&Pubkey],
|
||||||
proof_data: &WithdrawData,
|
proof_data: &WithdrawData,
|
||||||
) -> Vec<Instruction> {
|
) -> Vec<Instruction> {
|
||||||
|
@ -546,20 +550,20 @@ pub fn withdraw(
|
||||||
/// This instruction is suitable for use with a cross-program `invoke`
|
/// This instruction is suitable for use with a cross-program `invoke`
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn inner_transfer(
|
pub fn inner_transfer(
|
||||||
source_token_account: Pubkey,
|
source_token_account: &Pubkey,
|
||||||
destination_token_account: Pubkey,
|
destination_token_account: &Pubkey,
|
||||||
mint: Pubkey,
|
mint: &Pubkey,
|
||||||
new_source_decryptable_available_balance: pod::AeCiphertext,
|
new_source_decryptable_available_balance: pod::AeCiphertext,
|
||||||
authority: Pubkey,
|
authority: &Pubkey,
|
||||||
multisig_signers: &[&Pubkey],
|
multisig_signers: &[&Pubkey],
|
||||||
proof_instruction_offset: i8,
|
proof_instruction_offset: i8,
|
||||||
) -> Instruction {
|
) -> Instruction {
|
||||||
let mut accounts = vec![
|
let mut accounts = vec![
|
||||||
AccountMeta::new(source_token_account, false),
|
AccountMeta::new(*source_token_account, false),
|
||||||
AccountMeta::new(destination_token_account, false),
|
AccountMeta::new(*destination_token_account, false),
|
||||||
AccountMeta::new_readonly(mint, false),
|
AccountMeta::new_readonly(*mint, false),
|
||||||
AccountMeta::new_readonly(sysvar::instructions::id(), false),
|
AccountMeta::new_readonly(sysvar::instructions::id(), false),
|
||||||
AccountMeta::new_readonly(authority, multisig_signers.is_empty()),
|
AccountMeta::new_readonly(*authority, multisig_signers.is_empty()),
|
||||||
];
|
];
|
||||||
|
|
||||||
for multisig_signer in multisig_signers.iter() {
|
for multisig_signer in multisig_signers.iter() {
|
||||||
|
@ -580,11 +584,11 @@ pub fn inner_transfer(
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
#[cfg(not(target_arch = "bpf"))]
|
#[cfg(not(target_arch = "bpf"))]
|
||||||
pub fn transfer(
|
pub fn transfer(
|
||||||
source_token_account: Pubkey,
|
source_token_account: &Pubkey,
|
||||||
destination_token_account: Pubkey,
|
destination_token_account: &Pubkey,
|
||||||
mint: Pubkey,
|
mint: &Pubkey,
|
||||||
new_source_decryptable_available_balance: AeCiphertext,
|
new_source_decryptable_available_balance: AeCiphertext,
|
||||||
authority: Pubkey,
|
authority: &Pubkey,
|
||||||
multisig_signers: &[&Pubkey],
|
multisig_signers: &[&Pubkey],
|
||||||
proof_data: &TransferData,
|
proof_data: &TransferData,
|
||||||
) -> Vec<Instruction> {
|
) -> Vec<Instruction> {
|
||||||
|
@ -607,15 +611,15 @@ pub fn transfer(
|
||||||
/// This instruction is suitable for use with a cross-program `invoke`
|
/// This instruction is suitable for use with a cross-program `invoke`
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn inner_apply_pending_balance(
|
pub fn inner_apply_pending_balance(
|
||||||
token_account: Pubkey,
|
token_account: &Pubkey,
|
||||||
expected_pending_balance_credit_counter: u64,
|
expected_pending_balance_credit_counter: u64,
|
||||||
new_decryptable_available_balance: pod::AeCiphertext,
|
new_decryptable_available_balance: pod::AeCiphertext,
|
||||||
authority: Pubkey,
|
authority: &Pubkey,
|
||||||
multisig_signers: &[&Pubkey],
|
multisig_signers: &[&Pubkey],
|
||||||
) -> Instruction {
|
) -> Instruction {
|
||||||
let mut accounts = vec![
|
let mut accounts = vec![
|
||||||
AccountMeta::new(token_account, false),
|
AccountMeta::new(*token_account, false),
|
||||||
AccountMeta::new_readonly(authority, multisig_signers.is_empty()),
|
AccountMeta::new_readonly(*authority, multisig_signers.is_empty()),
|
||||||
];
|
];
|
||||||
|
|
||||||
for multisig_signer in multisig_signers.iter() {
|
for multisig_signer in multisig_signers.iter() {
|
||||||
|
@ -635,10 +639,10 @@ pub fn inner_apply_pending_balance(
|
||||||
/// Create a `ApplyPendingBalance` instruction
|
/// Create a `ApplyPendingBalance` instruction
|
||||||
#[cfg(not(target_arch = "bpf"))]
|
#[cfg(not(target_arch = "bpf"))]
|
||||||
pub fn apply_pending_balance(
|
pub fn apply_pending_balance(
|
||||||
token_account: Pubkey,
|
token_account: &Pubkey,
|
||||||
pending_balance_instructions: u64,
|
pending_balance_instructions: u64,
|
||||||
new_decryptable_available_balance: AeCiphertext,
|
new_decryptable_available_balance: AeCiphertext,
|
||||||
authority: Pubkey,
|
authority: &Pubkey,
|
||||||
multisig_signers: &[&Pubkey],
|
multisig_signers: &[&Pubkey],
|
||||||
) -> Vec<Instruction> {
|
) -> Vec<Instruction> {
|
||||||
vec![inner_apply_pending_balance(
|
vec![inner_apply_pending_balance(
|
||||||
|
@ -652,13 +656,13 @@ pub fn apply_pending_balance(
|
||||||
|
|
||||||
/// Create a `EnableBalanceCredits` instruction
|
/// Create a `EnableBalanceCredits` instruction
|
||||||
pub fn enable_balance_credits(
|
pub fn enable_balance_credits(
|
||||||
token_account: Pubkey,
|
token_account: &Pubkey,
|
||||||
authority: Pubkey,
|
authority: &Pubkey,
|
||||||
multisig_signers: &[&Pubkey],
|
multisig_signers: &[&Pubkey],
|
||||||
) -> Vec<Instruction> {
|
) -> Vec<Instruction> {
|
||||||
let mut accounts = vec![
|
let mut accounts = vec![
|
||||||
AccountMeta::new(token_account, false),
|
AccountMeta::new(*token_account, false),
|
||||||
AccountMeta::new_readonly(authority, multisig_signers.is_empty()),
|
AccountMeta::new_readonly(*authority, multisig_signers.is_empty()),
|
||||||
];
|
];
|
||||||
|
|
||||||
for multisig_signer in multisig_signers.iter() {
|
for multisig_signer in multisig_signers.iter() {
|
||||||
|
@ -675,13 +679,13 @@ pub fn enable_balance_credits(
|
||||||
/// Create a `DisableBalanceCredits` instruction
|
/// Create a `DisableBalanceCredits` instruction
|
||||||
#[cfg(not(target_arch = "bpf"))]
|
#[cfg(not(target_arch = "bpf"))]
|
||||||
pub fn disable_balance_credits(
|
pub fn disable_balance_credits(
|
||||||
token_account: Pubkey,
|
token_account: &Pubkey,
|
||||||
authority: Pubkey,
|
authority: &Pubkey,
|
||||||
multisig_signers: &[&Pubkey],
|
multisig_signers: &[&Pubkey],
|
||||||
) -> Vec<Instruction> {
|
) -> Vec<Instruction> {
|
||||||
let mut accounts = vec![
|
let mut accounts = vec![
|
||||||
AccountMeta::new(token_account, false),
|
AccountMeta::new(*token_account, false),
|
||||||
AccountMeta::new_readonly(authority, multisig_signers.is_empty()),
|
AccountMeta::new_readonly(*authority, multisig_signers.is_empty()),
|
||||||
];
|
];
|
||||||
|
|
||||||
for multisig_signer in multisig_signers.iter() {
|
for multisig_signer in multisig_signers.iter() {
|
||||||
|
|
|
@ -256,12 +256,14 @@ impl TransferFeeInstruction {
|
||||||
|
|
||||||
/// Create a `InitializeTransferFeeConfig` instruction
|
/// Create a `InitializeTransferFeeConfig` instruction
|
||||||
pub fn initialize_transfer_fee_config(
|
pub fn initialize_transfer_fee_config(
|
||||||
mint: Pubkey,
|
mint: &Pubkey,
|
||||||
transfer_fee_config_authority: COption<Pubkey>,
|
transfer_fee_config_authority: Option<&Pubkey>,
|
||||||
withdraw_withheld_authority: COption<Pubkey>,
|
withdraw_withheld_authority: Option<&Pubkey>,
|
||||||
transfer_fee_basis_points: u16,
|
transfer_fee_basis_points: u16,
|
||||||
maximum_fee: u64,
|
maximum_fee: u64,
|
||||||
) -> Instruction {
|
) -> Instruction {
|
||||||
|
let transfer_fee_config_authority = transfer_fee_config_authority.cloned().into();
|
||||||
|
let withdraw_withheld_authority = withdraw_withheld_authority.cloned().into();
|
||||||
let data = TokenInstruction::TransferFeeExtension(
|
let data = TokenInstruction::TransferFeeExtension(
|
||||||
TransferFeeInstruction::InitializeTransferFeeConfig {
|
TransferFeeInstruction::InitializeTransferFeeConfig {
|
||||||
transfer_fee_config_authority,
|
transfer_fee_config_authority,
|
||||||
|
@ -274,7 +276,7 @@ pub fn initialize_transfer_fee_config(
|
||||||
|
|
||||||
Instruction {
|
Instruction {
|
||||||
program_id: id(),
|
program_id: id(),
|
||||||
accounts: vec![AccountMeta::new(mint, false)],
|
accounts: vec![AccountMeta::new(*mint, false)],
|
||||||
data,
|
data,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -282,11 +284,11 @@ pub fn initialize_transfer_fee_config(
|
||||||
/// Create a `TransferCheckedWithFee` instruction
|
/// Create a `TransferCheckedWithFee` instruction
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn transfer_checked_with_fee(
|
pub fn transfer_checked_with_fee(
|
||||||
source: Pubkey,
|
source: &Pubkey,
|
||||||
mint: Pubkey,
|
mint: &Pubkey,
|
||||||
destination: Pubkey,
|
destination: &Pubkey,
|
||||||
authority: Pubkey,
|
authority: &Pubkey,
|
||||||
signers: &[Pubkey],
|
signers: &[&Pubkey],
|
||||||
amount: u64,
|
amount: u64,
|
||||||
decimals: u8,
|
decimals: u8,
|
||||||
fee: u64,
|
fee: u64,
|
||||||
|
@ -300,12 +302,12 @@ pub fn transfer_checked_with_fee(
|
||||||
.pack();
|
.pack();
|
||||||
|
|
||||||
let mut accounts = Vec::with_capacity(4 + signers.len());
|
let mut accounts = Vec::with_capacity(4 + signers.len());
|
||||||
accounts.push(AccountMeta::new(source, false));
|
accounts.push(AccountMeta::new(*source, false));
|
||||||
accounts.push(AccountMeta::new_readonly(mint, false));
|
accounts.push(AccountMeta::new_readonly(*mint, false));
|
||||||
accounts.push(AccountMeta::new(destination, false));
|
accounts.push(AccountMeta::new(*destination, false));
|
||||||
accounts.push(AccountMeta::new_readonly(authority, signers.is_empty()));
|
accounts.push(AccountMeta::new_readonly(*authority, signers.is_empty()));
|
||||||
for signer in signers.iter() {
|
for signer in signers.iter() {
|
||||||
accounts.push(AccountMeta::new_readonly(*signer, true));
|
accounts.push(AccountMeta::new_readonly(**signer, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
Instruction {
|
Instruction {
|
||||||
|
@ -317,17 +319,17 @@ pub fn transfer_checked_with_fee(
|
||||||
|
|
||||||
/// Creates a `WithdrawWithheldTokensFromMint` instruction
|
/// Creates a `WithdrawWithheldTokensFromMint` instruction
|
||||||
pub fn withdraw_withheld_tokens_from_mint(
|
pub fn withdraw_withheld_tokens_from_mint(
|
||||||
mint: Pubkey,
|
mint: &Pubkey,
|
||||||
destination: Pubkey,
|
destination: &Pubkey,
|
||||||
authority: Pubkey,
|
authority: &Pubkey,
|
||||||
signers: &[Pubkey],
|
signers: &[&Pubkey],
|
||||||
) -> Instruction {
|
) -> Instruction {
|
||||||
let mut accounts = Vec::with_capacity(3 + signers.len());
|
let mut accounts = Vec::with_capacity(3 + signers.len());
|
||||||
accounts.push(AccountMeta::new(mint, false));
|
accounts.push(AccountMeta::new(*mint, false));
|
||||||
accounts.push(AccountMeta::new(destination, false));
|
accounts.push(AccountMeta::new(*destination, false));
|
||||||
accounts.push(AccountMeta::new_readonly(authority, signers.is_empty()));
|
accounts.push(AccountMeta::new_readonly(*authority, signers.is_empty()));
|
||||||
for signer in signers.iter() {
|
for signer in signers.iter() {
|
||||||
accounts.push(AccountMeta::new_readonly(*signer, true));
|
accounts.push(AccountMeta::new_readonly(**signer, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
Instruction {
|
Instruction {
|
||||||
|
@ -342,21 +344,21 @@ pub fn withdraw_withheld_tokens_from_mint(
|
||||||
|
|
||||||
/// Creates a `WithdrawWithheldTokensFromAccounts` instruction
|
/// Creates a `WithdrawWithheldTokensFromAccounts` instruction
|
||||||
pub fn withdraw_withheld_tokens_from_accounts(
|
pub fn withdraw_withheld_tokens_from_accounts(
|
||||||
mint: Pubkey,
|
mint: &Pubkey,
|
||||||
destination: Pubkey,
|
destination: &Pubkey,
|
||||||
authority: Pubkey,
|
authority: &Pubkey,
|
||||||
signers: &[Pubkey],
|
signers: &[&Pubkey],
|
||||||
sources: &[Pubkey],
|
sources: &[&Pubkey],
|
||||||
) -> Instruction {
|
) -> Instruction {
|
||||||
let mut accounts = Vec::with_capacity(3 + signers.len() + sources.len());
|
let mut accounts = Vec::with_capacity(3 + signers.len() + sources.len());
|
||||||
accounts.push(AccountMeta::new_readonly(mint, false));
|
accounts.push(AccountMeta::new_readonly(*mint, false));
|
||||||
accounts.push(AccountMeta::new(destination, false));
|
accounts.push(AccountMeta::new(*destination, false));
|
||||||
accounts.push(AccountMeta::new_readonly(authority, signers.is_empty()));
|
accounts.push(AccountMeta::new_readonly(*authority, signers.is_empty()));
|
||||||
for signer in signers.iter() {
|
for signer in signers.iter() {
|
||||||
accounts.push(AccountMeta::new_readonly(*signer, true));
|
accounts.push(AccountMeta::new_readonly(**signer, true));
|
||||||
}
|
}
|
||||||
for source in sources.iter() {
|
for source in sources.iter() {
|
||||||
accounts.push(AccountMeta::new(*source, false));
|
accounts.push(AccountMeta::new(**source, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
Instruction {
|
Instruction {
|
||||||
|
@ -370,11 +372,11 @@ pub fn withdraw_withheld_tokens_from_accounts(
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a `HarvestWithheldTokensToMint` instruction
|
/// Creates a `HarvestWithheldTokensToMint` instruction
|
||||||
pub fn harvest_withheld_tokens_to_mint(mint: Pubkey, sources: &[Pubkey]) -> Instruction {
|
pub fn harvest_withheld_tokens_to_mint(mint: &Pubkey, sources: &[&Pubkey]) -> Instruction {
|
||||||
let mut accounts = Vec::with_capacity(1 + sources.len());
|
let mut accounts = Vec::with_capacity(1 + sources.len());
|
||||||
accounts.push(AccountMeta::new(mint, false));
|
accounts.push(AccountMeta::new(*mint, false));
|
||||||
for source in sources.iter() {
|
for source in sources.iter() {
|
||||||
accounts.push(AccountMeta::new(*source, false));
|
accounts.push(AccountMeta::new(**source, false));
|
||||||
}
|
}
|
||||||
Instruction {
|
Instruction {
|
||||||
program_id: id(),
|
program_id: id(),
|
||||||
|
@ -388,17 +390,17 @@ pub fn harvest_withheld_tokens_to_mint(mint: Pubkey, sources: &[Pubkey]) -> Inst
|
||||||
|
|
||||||
/// Creates a `SetTransferFee` instruction
|
/// Creates a `SetTransferFee` instruction
|
||||||
pub fn set_transfer_fee(
|
pub fn set_transfer_fee(
|
||||||
mint: Pubkey,
|
mint: &Pubkey,
|
||||||
authority: Pubkey,
|
authority: &Pubkey,
|
||||||
signers: &[Pubkey],
|
signers: &[&Pubkey],
|
||||||
transfer_fee_basis_points: u16,
|
transfer_fee_basis_points: u16,
|
||||||
maximum_fee: u64,
|
maximum_fee: u64,
|
||||||
) -> Instruction {
|
) -> Instruction {
|
||||||
let mut accounts = Vec::with_capacity(2 + signers.len());
|
let mut accounts = Vec::with_capacity(2 + signers.len());
|
||||||
accounts.push(AccountMeta::new(mint, false));
|
accounts.push(AccountMeta::new(*mint, false));
|
||||||
accounts.push(AccountMeta::new_readonly(authority, signers.is_empty()));
|
accounts.push(AccountMeta::new_readonly(*authority, signers.is_empty()));
|
||||||
for signer in signers.iter() {
|
for signer in signers.iter() {
|
||||||
accounts.push(AccountMeta::new_readonly(*signer, true));
|
accounts.push(AccountMeta::new_readonly(**signer, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
Instruction {
|
Instruction {
|
||||||
|
|
|
@ -1422,9 +1422,10 @@ pub fn get_account_data_size(
|
||||||
pub fn initialize_mint_close_authority(
|
pub fn initialize_mint_close_authority(
|
||||||
token_program_id: &Pubkey,
|
token_program_id: &Pubkey,
|
||||||
mint_pubkey: &Pubkey,
|
mint_pubkey: &Pubkey,
|
||||||
close_authority: COption<Pubkey>,
|
close_authority: Option<&Pubkey>,
|
||||||
) -> Result<Instruction, ProgramError> {
|
) -> Result<Instruction, ProgramError> {
|
||||||
check_program_account(token_program_id)?;
|
check_program_account(token_program_id)?;
|
||||||
|
let close_authority = close_authority.cloned().into();
|
||||||
Ok(Instruction {
|
Ok(Instruction {
|
||||||
program_id: *token_program_id,
|
program_id: *token_program_id,
|
||||||
accounts: vec![AccountMeta::new(*mint_pubkey, false)],
|
accounts: vec![AccountMeta::new(*mint_pubkey, false)],
|
||||||
|
|
|
@ -65,7 +65,7 @@ async fn fail_extension_no_space() {
|
||||||
instruction::initialize_mint_close_authority(
|
instruction::initialize_mint_close_authority(
|
||||||
&spl_token_2022::id(),
|
&spl_token_2022::id(),
|
||||||
&mint_account.pubkey(),
|
&mint_account.pubkey(),
|
||||||
COption::Some(mint_authority_pubkey),
|
Some(&mint_authority_pubkey),
|
||||||
)
|
)
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
instruction::initialize_mint(
|
instruction::initialize_mint(
|
||||||
|
@ -126,7 +126,7 @@ async fn fail_extension_after_mint_init() {
|
||||||
instruction::initialize_mint_close_authority(
|
instruction::initialize_mint_close_authority(
|
||||||
&spl_token_2022::id(),
|
&spl_token_2022::id(),
|
||||||
&mint_account.pubkey(),
|
&mint_account.pubkey(),
|
||||||
COption::Some(mint_authority_pubkey),
|
Some(&mint_authority_pubkey),
|
||||||
)
|
)
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
];
|
];
|
||||||
|
@ -153,7 +153,7 @@ async fn fail_extension_after_mint_init() {
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn success_extension_and_base() {
|
async fn success_extension_and_base() {
|
||||||
let close_authority = COption::Some(Pubkey::new_unique());
|
let close_authority = Some(Pubkey::new_unique());
|
||||||
let TestContext {
|
let TestContext {
|
||||||
decimals,
|
decimals,
|
||||||
mint_authority,
|
mint_authority,
|
||||||
|
@ -266,7 +266,7 @@ async fn fail_account_init_after_mint_extension() {
|
||||||
instruction::initialize_mint_close_authority(
|
instruction::initialize_mint_close_authority(
|
||||||
&spl_token_2022::id(),
|
&spl_token_2022::id(),
|
||||||
&token_account.pubkey(),
|
&token_account.pubkey(),
|
||||||
COption::Some(mint_authority_pubkey),
|
Some(&mint_authority_pubkey),
|
||||||
)
|
)
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
instruction::initialize_account(
|
instruction::initialize_account(
|
||||||
|
@ -375,7 +375,7 @@ async fn fail_account_init_after_mint_init_with_extension() {
|
||||||
instruction::initialize_mint_close_authority(
|
instruction::initialize_mint_close_authority(
|
||||||
&spl_token_2022::id(),
|
&spl_token_2022::id(),
|
||||||
&mint_account.pubkey(),
|
&mint_account.pubkey(),
|
||||||
COption::Some(mint_authority_pubkey),
|
Some(&mint_authority_pubkey),
|
||||||
)
|
)
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
instruction::initialize_mint(
|
instruction::initialize_mint(
|
||||||
|
@ -441,9 +441,9 @@ async fn fail_fee_init_after_mint_init() {
|
||||||
)
|
)
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
transfer_fee::instruction::initialize_transfer_fee_config(
|
transfer_fee::instruction::initialize_transfer_fee_config(
|
||||||
mint_account.pubkey(),
|
&mint_account.pubkey(),
|
||||||
COption::Some(Pubkey::new_unique()),
|
Some(&Pubkey::new_unique()),
|
||||||
COption::Some(Pubkey::new_unique()),
|
Some(&Pubkey::new_unique()),
|
||||||
10,
|
10,
|
||||||
100,
|
100,
|
||||||
),
|
),
|
||||||
|
|
|
@ -17,7 +17,7 @@ use {
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn success_init() {
|
async fn success_init() {
|
||||||
let close_authority = COption::Some(Pubkey::new_unique());
|
let close_authority = Some(Pubkey::new_unique());
|
||||||
let TestContext {
|
let TestContext {
|
||||||
decimals,
|
decimals,
|
||||||
mint_authority,
|
mint_authority,
|
||||||
|
@ -50,7 +50,7 @@ async fn set_authority() {
|
||||||
let close_authority = Keypair::new();
|
let close_authority = Keypair::new();
|
||||||
let TestContext { token, .. } =
|
let TestContext { token, .. } =
|
||||||
TestContext::new(vec![ExtensionInitializationParams::MintCloseAuthority {
|
TestContext::new(vec![ExtensionInitializationParams::MintCloseAuthority {
|
||||||
close_authority: COption::Some(close_authority.pubkey()),
|
close_authority: Some(close_authority.pubkey()),
|
||||||
}])
|
}])
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -150,7 +150,7 @@ async fn success_close() {
|
||||||
let close_authority = Keypair::new();
|
let close_authority = Keypair::new();
|
||||||
let TestContext { token, .. } =
|
let TestContext { token, .. } =
|
||||||
TestContext::new(vec![ExtensionInitializationParams::MintCloseAuthority {
|
TestContext::new(vec![ExtensionInitializationParams::MintCloseAuthority {
|
||||||
close_authority: COption::Some(close_authority.pubkey()),
|
close_authority: Some(close_authority.pubkey()),
|
||||||
}])
|
}])
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -212,7 +212,7 @@ async fn fail_close_with_supply() {
|
||||||
mint_authority,
|
mint_authority,
|
||||||
..
|
..
|
||||||
} = TestContext::new(vec![ExtensionInitializationParams::MintCloseAuthority {
|
} = TestContext::new(vec![ExtensionInitializationParams::MintCloseAuthority {
|
||||||
close_authority: COption::Some(close_authority.pubkey()),
|
close_authority: Some(close_authority.pubkey()),
|
||||||
}])
|
}])
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
|
@ -85,7 +85,7 @@ async fn fail_init_default_pubkey_as_authority() {
|
||||||
} = test_transfer_fee_config();
|
} = test_transfer_fee_config();
|
||||||
let err = TestContext::new(vec![ExtensionInitializationParams::TransferFeeConfig {
|
let err = TestContext::new(vec![ExtensionInitializationParams::TransferFeeConfig {
|
||||||
transfer_fee_config_authority: transfer_fee_config_authority.into(),
|
transfer_fee_config_authority: transfer_fee_config_authority.into(),
|
||||||
withdraw_withheld_authority: COption::Some(Pubkey::default()),
|
withdraw_withheld_authority: Some(Pubkey::default()),
|
||||||
transfer_fee_basis_points: newer_transfer_fee.transfer_fee_basis_points.into(),
|
transfer_fee_basis_points: newer_transfer_fee.transfer_fee_basis_points.into(),
|
||||||
maximum_fee: newer_transfer_fee.maximum_fee.into(),
|
maximum_fee: newer_transfer_fee.maximum_fee.into(),
|
||||||
}])
|
}])
|
||||||
|
|
|
@ -3,7 +3,6 @@ use solana_sdk::{
|
||||||
account::Account as BaseAccount,
|
account::Account as BaseAccount,
|
||||||
instruction::Instruction,
|
instruction::Instruction,
|
||||||
program_error::ProgramError,
|
program_error::ProgramError,
|
||||||
program_option::COption,
|
|
||||||
program_pack::Pack,
|
program_pack::Pack,
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
signer::{signers::Signers, Signer},
|
signer::{signers::Signers, Signer},
|
||||||
|
@ -52,11 +51,11 @@ impl PartialEq for TokenError {
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub enum ExtensionInitializationParams {
|
pub enum ExtensionInitializationParams {
|
||||||
MintCloseAuthority {
|
MintCloseAuthority {
|
||||||
close_authority: COption<Pubkey>,
|
close_authority: Option<Pubkey>,
|
||||||
},
|
},
|
||||||
TransferFeeConfig {
|
TransferFeeConfig {
|
||||||
transfer_fee_config_authority: COption<Pubkey>,
|
transfer_fee_config_authority: Option<Pubkey>,
|
||||||
withdraw_withheld_authority: COption<Pubkey>,
|
withdraw_withheld_authority: Option<Pubkey>,
|
||||||
transfer_fee_basis_points: u16,
|
transfer_fee_basis_points: u16,
|
||||||
maximum_fee: u64,
|
maximum_fee: u64,
|
||||||
},
|
},
|
||||||
|
@ -73,7 +72,8 @@ impl ExtensionInitializationParams {
|
||||||
pub fn instruction(self, mint: &Pubkey) -> Instruction {
|
pub fn instruction(self, mint: &Pubkey) -> Instruction {
|
||||||
match self {
|
match self {
|
||||||
Self::MintCloseAuthority { close_authority } => {
|
Self::MintCloseAuthority { close_authority } => {
|
||||||
instruction::initialize_mint_close_authority(&id(), mint, close_authority).unwrap()
|
instruction::initialize_mint_close_authority(&id(), mint, close_authority.as_ref())
|
||||||
|
.unwrap()
|
||||||
}
|
}
|
||||||
Self::TransferFeeConfig {
|
Self::TransferFeeConfig {
|
||||||
transfer_fee_config_authority,
|
transfer_fee_config_authority,
|
||||||
|
@ -81,9 +81,9 @@ impl ExtensionInitializationParams {
|
||||||
transfer_fee_basis_points,
|
transfer_fee_basis_points,
|
||||||
maximum_fee,
|
maximum_fee,
|
||||||
} => transfer_fee::instruction::initialize_transfer_fee_config(
|
} => transfer_fee::instruction::initialize_transfer_fee_config(
|
||||||
*mint,
|
mint,
|
||||||
transfer_fee_config_authority,
|
transfer_fee_config_authority.as_ref(),
|
||||||
withdraw_withheld_authority,
|
withdraw_withheld_authority.as_ref(),
|
||||||
transfer_fee_basis_points,
|
transfer_fee_basis_points,
|
||||||
maximum_fee,
|
maximum_fee,
|
||||||
),
|
),
|
||||||
|
|
Loading…
Reference in New Issue