Skip to content

Commit b5b34b9

Browse files
committed
solana: clean up helpers
1 parent 533fd2e commit b5b34b9

File tree

1 file changed

+23
-27
lines changed
  • solana/programs/matching-engine/src/fallback/processor

1 file changed

+23
-27
lines changed

solana/programs/matching-engine/src/fallback/processor/helpers.rs

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
use anchor_lang::prelude::*;
2-
3-
use crate::ID;
4-
use anchor_spl::mint::USDC;
52
use anchor_spl::token::spl_token;
6-
use solana_program::program_pack::Pack;
73
use solana_program::{
84
entrypoint::ProgramResult,
95
instruction::{AccountMeta, Instruction},
106
program::invoke_signed_unchecked,
7+
program_pack::Pack,
118
system_instruction,
129
};
1310

11+
use crate::ID;
12+
1413
#[inline(always)]
15-
pub fn require_min_account_infos_len(accounts: &[AccountInfo], len: usize) -> Result<()> {
16-
if accounts.len() < len {
14+
pub fn require_min_account_infos_len(accounts: &[AccountInfo], at_least_len: usize) -> Result<()> {
15+
if accounts.len() < at_least_len {
1716
return Err(ErrorCode::AccountNotEnoughKeys.into());
1817
}
18+
1919
Ok(())
2020
}
2121

@@ -140,47 +140,43 @@ pub fn create_account_reliably(
140140
Ok(())
141141
}
142142

143-
/// Create a token account reliably
143+
/// Create a USDC token account reliably.
144144
///
145-
/// This function creates a token account and initializes it with the given mint and owner.
145+
/// This function creates a USDC token account and initializes it with the given owner.
146146
///
147147
/// # Arguments
148148
///
149-
/// * `payer_pubkey` - The pubkey of the account that will pay for the token account.
150-
/// * `account_pubkey_to_create` - The pubkey of the account to create.
151-
/// * `owner_account_info` - The account info of the owner of the token account.
152-
/// * `mint_pubkey` - The pubkey of the mint.
153-
/// * `data_len` - The length of the data to be written to the token account.
149+
/// * `payer_key` - The pubkey of the account that will pay for the token account.
150+
/// * `token_account_key` - The pubkey of the account to create.
151+
/// * `token_account_owner_key` - The account info of the owner of the token account.
152+
/// * `token_account_lamports` - Current lamports on token account.
154153
/// * `accounts` - The accounts to be used in the CPI.
155154
/// * `signer_seeds` - The signer seeds to be used in the CPI.
156155
pub fn create_usdc_token_account_reliably(
157-
payer_pubkey: &Pubkey,
158-
account_pubkey_to_create: &Pubkey,
159-
owner_account_pubkey: &Pubkey,
156+
payer_key: &Pubkey,
157+
token_account_key: &Pubkey,
158+
token_account_owner_key: &Pubkey,
160159
token_account_lamports: u64,
161160
accounts: &[AccountInfo],
162161
signer_seeds: &[&[&[u8]]],
163162
) -> ProgramResult {
164-
// Create the owner account
165163
create_account_reliably(
166-
payer_pubkey,
167-
account_pubkey_to_create,
164+
payer_key,
165+
token_account_key,
168166
token_account_lamports,
169167
spl_token::state::Account::LEN,
170168
accounts,
171169
&spl_token::ID,
172170
signer_seeds,
173171
)?;
174172

175-
// Create the token account
176173
let init_token_account_ix = spl_token::instruction::initialize_account3(
177174
&spl_token::ID,
178-
account_pubkey_to_create,
179-
&USDC,
180-
owner_account_pubkey,
181-
)?;
175+
token_account_key,
176+
&common::USDC_MINT,
177+
token_account_owner_key,
178+
)
179+
.unwrap();
182180

183-
solana_program::program::invoke_signed_unchecked(&init_token_account_ix, accounts, &[])?;
184-
185-
Ok(())
181+
solana_program::program::invoke_signed_unchecked(&init_token_account_ix, accounts, &[])
186182
}

0 commit comments

Comments
 (0)