Skip to content

Commit 3c46e49

Browse files
committed
More nits
1 parent cd4f3e1 commit 3c46e49

File tree

8 files changed

+171
-260
lines changed

8 files changed

+171
-260
lines changed

programs/token-2022/src/instructions/extensions/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ pub mod transfer_hook;
1919
pub enum ExtensionDiscriminator {
2020
MintCloseAuthority = 25,
2121
TransferFee = 26,
22-
2322
DefaultAccountState = 28,
2423
MemoTransfer = 30,
2524
InterestBearingMint = 33,

programs/token-2022/src/instructions/extensions/transfer_fee/harvest_withheld_tokens_to_mint.rs

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use {
2-
crate::{instructions::ExtensionDiscriminator, UNINIT_ACCOUNT_REF, UNINIT_INSTRUCTION_ACCOUNT},
3-
core::slice::from_raw_parts,
2+
crate::instructions::ExtensionDiscriminator,
3+
core::{mem::MaybeUninit, slice::from_raw_parts},
44
solana_account_view::AccountView,
55
solana_address::Address,
66
solana_instruction_view::{
@@ -45,40 +45,27 @@ impl HarvestWithheldTokensToMint<'_, '_, '_> {
4545

4646
// Instruction accounts.
4747

48-
let mut instruction_accounts = [UNINIT_INSTRUCTION_ACCOUNT; MAX_STATIC_CPI_ACCOUNTS];
48+
let mut instruction_accounts =
49+
[const { MaybeUninit::<InstructionAccount>::uninit() }; MAX_STATIC_CPI_ACCOUNTS];
4950

50-
// SAFETY: The expected number of accounts has been validated to be less than
51-
// the maximum allocated.
52-
unsafe {
53-
instruction_accounts
54-
.get_unchecked_mut(0)
55-
.write(InstructionAccount::writable(self.mint.address()));
51+
instruction_accounts[0].write(InstructionAccount::writable(self.mint.address()));
5652

57-
for (instruction_account, source) in instruction_accounts
58-
.get_unchecked_mut(1..)
59-
.iter_mut()
60-
.zip(self.sources.iter())
61-
{
62-
instruction_account.write(InstructionAccount::writable(source.address()));
63-
}
53+
for (instruction_account, source) in instruction_accounts[1..]
54+
.iter_mut()
55+
.zip(self.sources.iter())
56+
{
57+
instruction_account.write(InstructionAccount::writable(source.address()));
6458
}
6559

6660
// Accounts.
6761

68-
let mut accounts = [UNINIT_ACCOUNT_REF; MAX_STATIC_CPI_ACCOUNTS];
62+
let mut accounts =
63+
[const { MaybeUninit::<&AccountView>::uninit() }; MAX_STATIC_CPI_ACCOUNTS];
6964

70-
// SAFETY: The expected number of accounts has been validated to be less than
71-
// the maximum allocated.
72-
unsafe {
73-
accounts.get_unchecked_mut(0).write(self.mint);
65+
accounts[0].write(self.mint);
7466

75-
for (account, source) in accounts
76-
.get_unchecked_mut(1..)
77-
.iter_mut()
78-
.zip(self.sources.iter())
79-
{
80-
account.write(*source);
81-
}
67+
for (account, source) in accounts[1..].iter_mut().zip(self.sources.iter()) {
68+
account.write(*source);
8269
}
8370

8471
invoke_with_bounds::<MAX_STATIC_CPI_ACCOUNTS>(

programs/token-2022/src/instructions/extensions/transfer_fee/initialize_transfer_fee_config.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,36 +56,32 @@ impl InitializeTransferFeeConfig<'_, '_> {
5656
// - 2 bytes for each optional authority
5757
let mut data_len = 2 + 2 + 8 + 2;
5858

59-
// discriminators
60-
write_bytes(
61-
&mut instruction_data[..2],
62-
&[
63-
ExtensionDiscriminator::TransferFee as u8,
64-
Self::DISCRIMINATOR,
65-
],
66-
);
67-
// transfer_fee_config_authority
59+
instruction_data[0].write(ExtensionDiscriminator::TransferFee as u8);
60+
61+
instruction_data[1].write(Self::DISCRIMINATOR);
62+
6863
if let Some(authority) = self.transfer_fee_config_authority {
6964
instruction_data[2].write(1);
7065
write_bytes(&mut instruction_data[3..35], authority.as_ref());
66+
// Add 32 bytes for the authority.
7167
data_len += size_of::<Address>();
7268
} else {
7369
instruction_data[2].write(0);
7470
}
75-
// withdraw_withheld_authority
7671
if let Some(authority) = self.withdraw_withheld_authority {
7772
instruction_data[35].write(1);
7873
write_bytes(&mut instruction_data[36..68], authority.as_ref());
74+
// Add 32 bytes for the authority.
7975
data_len += size_of::<Address>();
8076
} else {
8177
instruction_data[35].write(0);
8278
}
83-
// transfer_fee_basis_points
79+
8480
write_bytes(
8581
&mut instruction_data[68..70],
8682
&self.transfer_fee_basis_points.to_le_bytes(),
8783
);
88-
// maximum_fee
84+
8985
write_bytes(
9086
&mut instruction_data[70..78],
9187
&self.maximum_fee.to_le_bytes(),

programs/token-2022/src/instructions/extensions/transfer_fee/set_transfer_fee.rs

Lines changed: 31 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
use {
2-
crate::{
3-
instructions::{ExtensionDiscriminator, MAX_MULTISIG_SIGNERS},
4-
UNINIT_ACCOUNT_REF, UNINIT_INSTRUCTION_ACCOUNT,
5-
},
6-
core::slice::from_raw_parts,
2+
crate::instructions::{ExtensionDiscriminator, MAX_MULTISIG_SIGNERS},
3+
core::{mem::MaybeUninit, slice::from_raw_parts},
74
solana_account_view::AccountView,
85
solana_address::Address,
96
solana_instruction_view::{
@@ -34,7 +31,7 @@ pub struct SetTransferFee<'a, 'b, 'c> {
3431
pub authority: &'a AccountView,
3532

3633
/// Multisignature owner/delegate.
37-
pub signers: &'c [&'a AccountView],
34+
pub multisig_signers: &'c [&'a AccountView],
3835

3936
/// Amount of transfer collected as fees, expressed as basis points of
4037
/// the transfer amount
@@ -60,7 +57,7 @@ impl<'a, 'b, 'c> SetTransferFee<'a, 'b, 'c> {
6057
transfer_fee_basis_points: u16,
6158
maximum_fee: u64,
6259
) -> Self {
63-
Self::with_signers(
60+
Self::with_multisig_signers(
6461
token_program,
6562
mint,
6663
authority,
@@ -73,18 +70,18 @@ impl<'a, 'b, 'c> SetTransferFee<'a, 'b, 'c> {
7370
/// Creates a new `SetTransferFee` instruction with a multisignature
7471
/// owner/delegate authority and signer accounts.
7572
#[inline(always)]
76-
pub fn with_signers(
73+
pub fn with_multisig_signers(
7774
token_program: &'b Address,
7875
mint: &'a AccountView,
7976
authority: &'a AccountView,
8077
transfer_fee_basis_points: u16,
8178
maximum_fee: u64,
82-
signers: &'c [&'a AccountView],
79+
multisig_signers: &'c [&'a AccountView],
8380
) -> Self {
8481
Self {
8582
mint,
8683
authority,
87-
signers,
84+
multisig_signers,
8885
transfer_fee_basis_points,
8986
maximum_fee,
9087
token_program,
@@ -98,56 +95,43 @@ impl<'a, 'b, 'c> SetTransferFee<'a, 'b, 'c> {
9895

9996
#[inline(always)]
10097
pub fn invoke_signed(&self, signers: &[Signer]) -> ProgramResult {
101-
if self.signers.len() > MAX_MULTISIG_SIGNERS {
98+
if self.multisig_signers.len() > MAX_MULTISIG_SIGNERS {
10299
return Err(ProgramError::InvalidArgument);
103100
}
104101

105-
let expected_accounts = 2 + self.signers.len();
102+
let expected_accounts = 2 + self.multisig_signers.len();
106103

107104
// Instruction accounts.
108105

109-
let mut instruction_accounts = [UNINIT_INSTRUCTION_ACCOUNT; 2 + MAX_MULTISIG_SIGNERS];
110-
111-
// SAFETY: The allocation is valid to the maximum number of accounts.
112-
unsafe {
113-
instruction_accounts
114-
.get_unchecked_mut(0)
115-
.write(InstructionAccount::writable(self.mint.address()));
116-
117-
instruction_accounts
118-
.get_unchecked_mut(1)
119-
.write(InstructionAccount::new(
120-
self.authority.address(),
121-
false,
122-
self.signers.is_empty(),
123-
));
124-
125-
for (instruction_account, signer) in instruction_accounts
126-
.get_unchecked_mut(2..)
127-
.iter_mut()
128-
.zip(self.signers.iter())
129-
{
130-
instruction_account.write(InstructionAccount::readonly_signer(signer.address()));
131-
}
106+
let mut instruction_accounts =
107+
[const { MaybeUninit::<InstructionAccount>::uninit() }; 2 + MAX_MULTISIG_SIGNERS];
108+
109+
instruction_accounts[0].write(InstructionAccount::writable(self.mint.address()));
110+
111+
instruction_accounts[1].write(InstructionAccount::new(
112+
self.authority.address(),
113+
false,
114+
self.multisig_signers.is_empty(),
115+
));
116+
117+
for (instruction_account, signer) in instruction_accounts[2..]
118+
.iter_mut()
119+
.zip(self.multisig_signers.iter())
120+
{
121+
instruction_account.write(InstructionAccount::readonly_signer(signer.address()));
132122
}
133123

134124
// Accounts.
135125

136-
let mut accounts = [UNINIT_ACCOUNT_REF; 2 + MAX_MULTISIG_SIGNERS];
126+
let mut accounts =
127+
[const { MaybeUninit::<&AccountView>::uninit() }; 2 + MAX_MULTISIG_SIGNERS];
137128

138-
// SAFETY: The allocation is valid to the maximum number of accounts.
139-
unsafe {
140-
accounts.get_unchecked_mut(0).write(self.mint);
129+
accounts[0].write(self.mint);
141130

142-
accounts.get_unchecked_mut(1).write(self.authority);
131+
accounts[1].write(self.authority);
143132

144-
for (account, signer) in accounts
145-
.get_unchecked_mut(2..)
146-
.iter_mut()
147-
.zip(self.signers.iter())
148-
{
149-
account.write(*signer);
150-
}
133+
for (account, signer) in accounts[2..].iter_mut().zip(self.multisig_signers.iter()) {
134+
account.write(*signer);
151135
}
152136

153137
invoke_signed_with_bounds::<{ 2 + MAX_MULTISIG_SIGNERS }>(

0 commit comments

Comments
 (0)