mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-18 07:26:44 +00:00
scaffold
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use ore_api::prelude::*;
|
||||
use solana_program::program_pack::Pack;
|
||||
use steel::*;
|
||||
|
||||
/// Sets the admin.
|
||||
@@ -7,7 +8,9 @@ pub fn process_initialize(accounts: &[AccountInfo<'_>], _data: &[u8]) -> Program
|
||||
// let args = Initialize::try_from_bytes(data)?;
|
||||
|
||||
// Load accounts.
|
||||
let [signer_info, config_info, market_info, treasury_info, system_program] = accounts else {
|
||||
let [signer_info, config_info, market_info, mint_info, treasury_info, vault_info, system_program, token_program] =
|
||||
accounts
|
||||
else {
|
||||
return Err(ProgramError::NotEnoughAccountKeys);
|
||||
};
|
||||
signer_info.is_signer()?.has_address(&ADMIN_ADDRESS)?;
|
||||
@@ -19,11 +22,17 @@ pub fn process_initialize(accounts: &[AccountInfo<'_>], _data: &[u8]) -> Program
|
||||
.is_writable()?
|
||||
.is_empty()?
|
||||
.has_seeds(&[MARKET], &ore_api::ID)?;
|
||||
mint_info.has_address(&MINT_ADDRESS)?.as_mint()?;
|
||||
treasury_info
|
||||
.is_writable()?
|
||||
.is_empty()?
|
||||
.has_seeds(&[TREASURY], &ore_api::ID)?;
|
||||
vault_info
|
||||
.is_writable()?
|
||||
.is_empty()?
|
||||
.has_address(&vault_pda().0)?;
|
||||
system_program.is_program(&system_program::ID)?;
|
||||
token_program.is_program(&spl_token::ID)?;
|
||||
|
||||
// Create config account.
|
||||
create_program_account::<Config>(
|
||||
@@ -80,5 +89,43 @@ pub fn process_initialize(accounts: &[AccountInfo<'_>], _data: &[u8]) -> Program
|
||||
&[TREASURY],
|
||||
)?;
|
||||
|
||||
// Initialize vault token account.
|
||||
if vault_info.data_is_empty() {
|
||||
let vault_pda = vault_pda();
|
||||
allocate_account_with_bump(
|
||||
vault_info,
|
||||
system_program,
|
||||
signer_info,
|
||||
spl_token::state::Account::LEN,
|
||||
&spl_token::ID,
|
||||
&[
|
||||
market_info.key.as_ref(),
|
||||
token_program.key.as_ref(),
|
||||
mint_info.key.as_ref(),
|
||||
],
|
||||
vault_pda.1,
|
||||
)?;
|
||||
solana_program::program::invoke(
|
||||
&spl_token_2022::instruction::initialize_account3(
|
||||
&spl_token::ID,
|
||||
&vault_pda.0,
|
||||
&mint_info.key,
|
||||
&market_info.key,
|
||||
)?,
|
||||
&[
|
||||
vault_info.clone(),
|
||||
mint_info.clone(),
|
||||
market_info.clone(),
|
||||
token_program.clone(),
|
||||
],
|
||||
)?;
|
||||
} else {
|
||||
vault_info
|
||||
.has_address(&vault_pda().0)?
|
||||
.as_token_account()?
|
||||
.assert(|t| t.mint() == *mint_info.key)?
|
||||
.assert(|t| t.owner() == *market_info.key)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user