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

Commit c03c1fc

Browse files
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
1 parent 28e779d commit c03c1fc

File tree

7 files changed

+135
-128
lines changed

7 files changed

+135
-128
lines changed

token/program-2022/src/extension/confidential_transfer/instruction.rs

Lines changed: 69 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,8 @@ fn encode_instruction<T: Pod>(
327327
}
328328

329329
/// Create a `InitializeMint` instruction
330-
pub fn initialize_mint(mint: Pubkey, auditor: &ConfidentialTransferMint) -> Instruction {
331-
let accounts = vec![AccountMeta::new(mint, false)];
330+
pub fn initialize_mint(mint: &Pubkey, auditor: &ConfidentialTransferMint) -> Instruction {
331+
let accounts = vec![AccountMeta::new(*mint, false)];
332332
encode_instruction(
333333
accounts,
334334
ConfidentialTransferInstruction::InitializeMint,
@@ -337,13 +337,13 @@ pub fn initialize_mint(mint: Pubkey, auditor: &ConfidentialTransferMint) -> Inst
337337
}
338338
/// Create a `UpdateMint` instruction
339339
pub fn update_mint(
340-
mint: Pubkey,
340+
mint: &Pubkey,
341341
new_auditor: &ConfidentialTransferMint,
342-
authority: Pubkey,
342+
authority: &Pubkey,
343343
) -> Instruction {
344344
let accounts = vec![
345-
AccountMeta::new(mint, false),
346-
AccountMeta::new_readonly(authority, true),
345+
AccountMeta::new(*mint, false),
346+
AccountMeta::new_readonly(*authority, true),
347347
AccountMeta::new_readonly(
348348
new_auditor.authority,
349349
new_auditor.authority != Pubkey::default(),
@@ -359,17 +359,17 @@ pub fn update_mint(
359359
/// Create a `ConfigureAccount` instruction
360360
#[cfg(not(target_arch = "bpf"))]
361361
pub fn configure_account(
362-
token_account: Pubkey,
363-
mint: Pubkey,
362+
token_account: &Pubkey,
363+
mint: &Pubkey,
364364
elgamal_pk: ElGamalPubkey,
365365
decryptable_zero_balance: AeCiphertext,
366-
authority: Pubkey,
366+
authority: &Pubkey,
367367
multisig_signers: &[&Pubkey],
368368
) -> Vec<Instruction> {
369369
let mut accounts = vec![
370-
AccountMeta::new(token_account, false),
371-
AccountMeta::new_readonly(mint, false),
372-
AccountMeta::new_readonly(authority, multisig_signers.is_empty()),
370+
AccountMeta::new(*token_account, false),
371+
AccountMeta::new_readonly(*mint, false),
372+
AccountMeta::new_readonly(*authority, multisig_signers.is_empty()),
373373
];
374374

375375
for multisig_signer in multisig_signers.iter() {
@@ -387,11 +387,15 @@ pub fn configure_account(
387387
}
388388

389389
/// Create an `ApproveAccount` instruction
390-
pub fn approve_account(mint: Pubkey, account_to_approve: Pubkey, authority: Pubkey) -> Instruction {
390+
pub fn approve_account(
391+
mint: &Pubkey,
392+
account_to_approve: &Pubkey,
393+
authority: &Pubkey,
394+
) -> Instruction {
391395
let accounts = vec![
392-
AccountMeta::new(account_to_approve, false),
393-
AccountMeta::new_readonly(mint, false),
394-
AccountMeta::new_readonly(authority, true),
396+
AccountMeta::new(*account_to_approve, false),
397+
AccountMeta::new_readonly(*mint, false),
398+
AccountMeta::new_readonly(*authority, true),
395399
];
396400
encode_instruction(
397401
accounts,
@@ -404,15 +408,15 @@ pub fn approve_account(mint: Pubkey, account_to_approve: Pubkey, authority: Pubk
404408
///
405409
/// This instruction is suitable for use with a cross-program `invoke`
406410
pub fn inner_empty_account(
407-
token_account: Pubkey,
408-
authority: Pubkey,
411+
token_account: &Pubkey,
412+
authority: &Pubkey,
409413
multisig_signers: &[&Pubkey],
410414
proof_instruction_offset: i8,
411415
) -> Instruction {
412416
let mut accounts = vec![
413-
AccountMeta::new_readonly(token_account, false),
417+
AccountMeta::new_readonly(*token_account, false),
414418
AccountMeta::new_readonly(sysvar::instructions::id(), false),
415-
AccountMeta::new_readonly(authority, multisig_signers.is_empty()),
419+
AccountMeta::new_readonly(*authority, multisig_signers.is_empty()),
416420
];
417421

418422
for multisig_signer in multisig_signers.iter() {
@@ -430,8 +434,8 @@ pub fn inner_empty_account(
430434

431435
/// Create a `EmptyAccount` instruction
432436
pub fn empty_account(
433-
token_account: Pubkey,
434-
authority: Pubkey,
437+
token_account: &Pubkey,
438+
authority: &Pubkey,
435439
multisig_signers: &[&Pubkey],
436440
proof_data: &CloseAccountData,
437441
) -> Vec<Instruction> {
@@ -443,19 +447,19 @@ pub fn empty_account(
443447

444448
/// Create a `Deposit` instruction
445449
pub fn deposit(
446-
source_token_account: Pubkey,
447-
mint: Pubkey,
448-
destination_token_account: Pubkey,
450+
source_token_account: &Pubkey,
451+
mint: &Pubkey,
452+
destination_token_account: &Pubkey,
449453
amount: u64,
450454
decimals: u8,
451-
authority: Pubkey,
455+
authority: &Pubkey,
452456
multisig_signers: &[&Pubkey],
453457
) -> Vec<Instruction> {
454458
let mut accounts = vec![
455-
AccountMeta::new(source_token_account, false),
456-
AccountMeta::new(destination_token_account, false),
457-
AccountMeta::new_readonly(mint, false),
458-
AccountMeta::new_readonly(authority, multisig_signers.is_empty()),
459+
AccountMeta::new(*source_token_account, false),
460+
AccountMeta::new(*destination_token_account, false),
461+
AccountMeta::new_readonly(*mint, false),
462+
AccountMeta::new_readonly(*authority, multisig_signers.is_empty()),
459463
];
460464

461465
for multisig_signer in multisig_signers.iter() {
@@ -477,22 +481,22 @@ pub fn deposit(
477481
/// This instruction is suitable for use with a cross-program `invoke`
478482
#[allow(clippy::too_many_arguments)]
479483
pub fn inner_withdraw(
480-
source_token_account: Pubkey,
481-
destination_token_account: Pubkey,
484+
source_token_account: &Pubkey,
485+
destination_token_account: &Pubkey,
482486
mint: &Pubkey,
483487
amount: u64,
484488
decimals: u8,
485489
new_decryptable_available_balance: pod::AeCiphertext,
486-
authority: Pubkey,
490+
authority: &Pubkey,
487491
multisig_signers: &[&Pubkey],
488492
proof_instruction_offset: i8,
489493
) -> Instruction {
490494
let mut accounts = vec![
491-
AccountMeta::new(source_token_account, false),
492-
AccountMeta::new(destination_token_account, false),
495+
AccountMeta::new(*source_token_account, false),
496+
AccountMeta::new(*destination_token_account, false),
493497
AccountMeta::new_readonly(*mint, false),
494498
AccountMeta::new_readonly(sysvar::instructions::id(), false),
495-
AccountMeta::new_readonly(authority, multisig_signers.is_empty()),
499+
AccountMeta::new_readonly(*authority, multisig_signers.is_empty()),
496500
];
497501

498502
for multisig_signer in multisig_signers.iter() {
@@ -515,13 +519,13 @@ pub fn inner_withdraw(
515519
#[allow(clippy::too_many_arguments)]
516520
#[cfg(not(target_arch = "bpf"))]
517521
pub fn withdraw(
518-
source_token_account: Pubkey,
519-
destination_token_account: Pubkey,
522+
source_token_account: &Pubkey,
523+
destination_token_account: &Pubkey,
520524
mint: &Pubkey,
521525
amount: u64,
522526
decimals: u8,
523527
new_decryptable_available_balance: AeCiphertext,
524-
authority: Pubkey,
528+
authority: &Pubkey,
525529
multisig_signers: &[&Pubkey],
526530
proof_data: &WithdrawData,
527531
) -> Vec<Instruction> {
@@ -546,20 +550,20 @@ pub fn withdraw(
546550
/// This instruction is suitable for use with a cross-program `invoke`
547551
#[allow(clippy::too_many_arguments)]
548552
pub fn inner_transfer(
549-
source_token_account: Pubkey,
550-
destination_token_account: Pubkey,
551-
mint: Pubkey,
553+
source_token_account: &Pubkey,
554+
destination_token_account: &Pubkey,
555+
mint: &Pubkey,
552556
new_source_decryptable_available_balance: pod::AeCiphertext,
553-
authority: Pubkey,
557+
authority: &Pubkey,
554558
multisig_signers: &[&Pubkey],
555559
proof_instruction_offset: i8,
556560
) -> Instruction {
557561
let mut accounts = vec![
558-
AccountMeta::new(source_token_account, false),
559-
AccountMeta::new(destination_token_account, false),
560-
AccountMeta::new_readonly(mint, false),
562+
AccountMeta::new(*source_token_account, false),
563+
AccountMeta::new(*destination_token_account, false),
564+
AccountMeta::new_readonly(*mint, false),
561565
AccountMeta::new_readonly(sysvar::instructions::id(), false),
562-
AccountMeta::new_readonly(authority, multisig_signers.is_empty()),
566+
AccountMeta::new_readonly(*authority, multisig_signers.is_empty()),
563567
];
564568

565569
for multisig_signer in multisig_signers.iter() {
@@ -580,11 +584,11 @@ pub fn inner_transfer(
580584
#[allow(clippy::too_many_arguments)]
581585
#[cfg(not(target_arch = "bpf"))]
582586
pub fn transfer(
583-
source_token_account: Pubkey,
584-
destination_token_account: Pubkey,
585-
mint: Pubkey,
587+
source_token_account: &Pubkey,
588+
destination_token_account: &Pubkey,
589+
mint: &Pubkey,
586590
new_source_decryptable_available_balance: AeCiphertext,
587-
authority: Pubkey,
591+
authority: &Pubkey,
588592
multisig_signers: &[&Pubkey],
589593
proof_data: &TransferData,
590594
) -> Vec<Instruction> {
@@ -607,15 +611,15 @@ pub fn transfer(
607611
/// This instruction is suitable for use with a cross-program `invoke`
608612
#[allow(clippy::too_many_arguments)]
609613
pub fn inner_apply_pending_balance(
610-
token_account: Pubkey,
614+
token_account: &Pubkey,
611615
expected_pending_balance_credit_counter: u64,
612616
new_decryptable_available_balance: pod::AeCiphertext,
613-
authority: Pubkey,
617+
authority: &Pubkey,
614618
multisig_signers: &[&Pubkey],
615619
) -> Instruction {
616620
let mut accounts = vec![
617-
AccountMeta::new(token_account, false),
618-
AccountMeta::new_readonly(authority, multisig_signers.is_empty()),
621+
AccountMeta::new(*token_account, false),
622+
AccountMeta::new_readonly(*authority, multisig_signers.is_empty()),
619623
];
620624

621625
for multisig_signer in multisig_signers.iter() {
@@ -635,10 +639,10 @@ pub fn inner_apply_pending_balance(
635639
/// Create a `ApplyPendingBalance` instruction
636640
#[cfg(not(target_arch = "bpf"))]
637641
pub fn apply_pending_balance(
638-
token_account: Pubkey,
642+
token_account: &Pubkey,
639643
pending_balance_instructions: u64,
640644
new_decryptable_available_balance: AeCiphertext,
641-
authority: Pubkey,
645+
authority: &Pubkey,
642646
multisig_signers: &[&Pubkey],
643647
) -> Vec<Instruction> {
644648
vec![inner_apply_pending_balance(
@@ -652,13 +656,13 @@ pub fn apply_pending_balance(
652656

653657
/// Create a `EnableBalanceCredits` instruction
654658
pub fn enable_balance_credits(
655-
token_account: Pubkey,
656-
authority: Pubkey,
659+
token_account: &Pubkey,
660+
authority: &Pubkey,
657661
multisig_signers: &[&Pubkey],
658662
) -> Vec<Instruction> {
659663
let mut accounts = vec![
660-
AccountMeta::new(token_account, false),
661-
AccountMeta::new_readonly(authority, multisig_signers.is_empty()),
664+
AccountMeta::new(*token_account, false),
665+
AccountMeta::new_readonly(*authority, multisig_signers.is_empty()),
662666
];
663667

664668
for multisig_signer in multisig_signers.iter() {
@@ -675,13 +679,13 @@ pub fn enable_balance_credits(
675679
/// Create a `DisableBalanceCredits` instruction
676680
#[cfg(not(target_arch = "bpf"))]
677681
pub fn disable_balance_credits(
678-
token_account: Pubkey,
679-
authority: Pubkey,
682+
token_account: &Pubkey,
683+
authority: &Pubkey,
680684
multisig_signers: &[&Pubkey],
681685
) -> Vec<Instruction> {
682686
let mut accounts = vec![
683-
AccountMeta::new(token_account, false),
684-
AccountMeta::new_readonly(authority, multisig_signers.is_empty()),
687+
AccountMeta::new(*token_account, false),
688+
AccountMeta::new_readonly(*authority, multisig_signers.is_empty()),
685689
];
686690

687691
for multisig_signer in multisig_signers.iter() {

0 commit comments

Comments
 (0)