mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-17 07:26:52 +00:00
e2e
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
use ore_api::prelude::*;
|
||||
use solana_program::program_pack::Pack;
|
||||
use steel::*;
|
||||
|
||||
/// Initializes the program.
|
||||
@@ -11,84 +10,83 @@ pub fn process_initialize(accounts: &[AccountInfo<'_>], _data: &[u8]) -> Program
|
||||
return Err(ProgramError::NotEnoughAccountKeys);
|
||||
};
|
||||
signer_info.is_signer()?.has_address(&ADMIN_ADDRESS)?;
|
||||
config_info
|
||||
.is_writable()?
|
||||
.is_empty()?
|
||||
.has_seeds(&[CONFIG], &ore_api::ID)?;
|
||||
market_info
|
||||
.is_writable()?
|
||||
.is_empty()?
|
||||
.has_seeds(&[MARKET], &ore_api::ID)?;
|
||||
config_info.has_seeds(&[CONFIG], &ore_api::ID)?;
|
||||
market_info.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)?;
|
||||
treasury_tokens_info.is_writable()?.is_empty()?;
|
||||
vault_info
|
||||
.is_writable()?
|
||||
.is_empty()?
|
||||
.has_address(&vault_pda().0)?;
|
||||
treasury_info.has_seeds(&[TREASURY], &ore_api::ID)?;
|
||||
treasury_tokens_info.is_writable()?;
|
||||
vault_info.has_address(&vault_address())?;
|
||||
system_program.is_program(&system_program::ID)?;
|
||||
token_program.is_program(&spl_token::ID)?;
|
||||
associated_token_program.is_program(&spl_associated_token_account::ID)?;
|
||||
|
||||
// Create config account.
|
||||
create_program_account::<Config>(
|
||||
config_info,
|
||||
system_program,
|
||||
signer_info,
|
||||
&ore_api::ID,
|
||||
&[CONFIG],
|
||||
)?;
|
||||
let config = config_info.as_account_mut::<Config>(&ore_api::ID)?;
|
||||
config.admin = *signer_info.key;
|
||||
config.block_duration = INITIAL_BLOCK_DURATION;
|
||||
config.sniper_fee_duration = INITIAL_SNIPER_FEE_DURATION;
|
||||
config.fee_collector = *signer_info.key;
|
||||
config.fee_rate = FEE_LAMPORTS;
|
||||
if config_info.data_is_empty() {
|
||||
create_program_account::<Config>(
|
||||
config_info,
|
||||
system_program,
|
||||
signer_info,
|
||||
&ore_api::ID,
|
||||
&[CONFIG],
|
||||
)?;
|
||||
let config = config_info.as_account_mut::<Config>(&ore_api::ID)?;
|
||||
config.admin = *signer_info.key;
|
||||
config.block_duration = INITIAL_BLOCK_DURATION;
|
||||
config.sniper_fee_duration = INITIAL_SNIPER_FEE_DURATION;
|
||||
config.fee_collector = *signer_info.key;
|
||||
config.fee_rate = FEE_LAMPORTS;
|
||||
} else {
|
||||
config_info.as_account::<Config>(&ore_api::ID)?;
|
||||
}
|
||||
|
||||
// Initialize market.
|
||||
let initial_id: u64 = 0;
|
||||
create_program_account::<Market>(
|
||||
market_info,
|
||||
system_program,
|
||||
signer_info,
|
||||
&ore_api::ID,
|
||||
&[MARKET],
|
||||
)?;
|
||||
let market = market_info.as_account_mut::<Market>(&ore_api::ID)?;
|
||||
market.base = TokenParams {
|
||||
mint: Pubkey::default(), // Virtual token
|
||||
balance: 0,
|
||||
balance_virtual: 0,
|
||||
};
|
||||
market.quote = TokenParams {
|
||||
mint: MINT_ADDRESS,
|
||||
balance: 0,
|
||||
balance_virtual: 0,
|
||||
};
|
||||
market.fee = FeeParams {
|
||||
rate: 0,
|
||||
uncollected: 0,
|
||||
cumulative: 0,
|
||||
};
|
||||
market.snapshot = Snapshot {
|
||||
enabled: 1,
|
||||
base_balance: 0,
|
||||
quote_balance: 0,
|
||||
slot: 0,
|
||||
};
|
||||
market.block_id = initial_id;
|
||||
if market_info.data_is_empty() {
|
||||
create_program_account::<Market>(
|
||||
market_info,
|
||||
system_program,
|
||||
signer_info,
|
||||
&ore_api::ID,
|
||||
&[MARKET],
|
||||
)?;
|
||||
let market = market_info.as_account_mut::<Market>(&ore_api::ID)?;
|
||||
market.base = TokenParams {
|
||||
mint: Pubkey::default(), // Virtual token
|
||||
balance: 0,
|
||||
balance_virtual: 0,
|
||||
};
|
||||
market.quote = TokenParams {
|
||||
mint: MINT_ADDRESS,
|
||||
balance: 0,
|
||||
balance_virtual: 0,
|
||||
};
|
||||
market.fee = FeeParams {
|
||||
rate: 0,
|
||||
uncollected: 0,
|
||||
cumulative: 0,
|
||||
};
|
||||
market.snapshot = Snapshot {
|
||||
enabled: 1,
|
||||
base_balance: 0,
|
||||
quote_balance: 0,
|
||||
slot: 0,
|
||||
};
|
||||
market.block_id = 0;
|
||||
} else {
|
||||
market_info.as_account::<Market>(&ore_api::ID)?;
|
||||
}
|
||||
|
||||
// Create treasury account.
|
||||
create_program_account::<Treasury>(
|
||||
treasury_info,
|
||||
system_program,
|
||||
signer_info,
|
||||
&ore_api::ID,
|
||||
&[TREASURY],
|
||||
)?;
|
||||
if treasury_info.data_is_empty() {
|
||||
create_program_account::<Treasury>(
|
||||
treasury_info,
|
||||
system_program,
|
||||
signer_info,
|
||||
&ore_api::ID,
|
||||
&[TREASURY],
|
||||
)?;
|
||||
} else {
|
||||
treasury_info.as_account::<Treasury>(&ore_api::ID)?;
|
||||
}
|
||||
|
||||
// Load treasury tokens.
|
||||
if treasury_tokens_info.data_is_empty() {
|
||||
@@ -107,40 +105,17 @@ pub fn process_initialize(accounts: &[AccountInfo<'_>], _data: &[u8]) -> Program
|
||||
|
||||
// Initialize vault token account.
|
||||
if vault_info.data_is_empty() {
|
||||
let vault_pda = vault_pda();
|
||||
allocate_account_with_bump(
|
||||
vault_info,
|
||||
system_program,
|
||||
create_associated_token_account(
|
||||
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(),
|
||||
],
|
||||
market_info,
|
||||
vault_info,
|
||||
mint_info,
|
||||
system_program,
|
||||
token_program,
|
||||
associated_token_program,
|
||||
)?;
|
||||
} 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)?;
|
||||
vault_info.as_associated_token_account(market_info.key, mint_info.key)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user