mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-14 15:10:13 +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(())
|
||||
|
||||
@@ -31,7 +31,7 @@ pub fn process_mine(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
|
||||
seed[..8].copy_from_slice(&block.id.to_le_bytes());
|
||||
seed[8..40].copy_from_slice(&block.slot_hash);
|
||||
seed[40..72].copy_from_slice(&miner.authority.to_bytes());
|
||||
seed[72..].copy_from_slice(&miner.seed);
|
||||
seed[72..104].copy_from_slice(&miner.seed);
|
||||
seed[104..].copy_from_slice(&nonce.to_le_bytes());
|
||||
let h = hash(&seed);
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ pub fn process_open(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
|
||||
let block = block_info.as_account_mut::<Block>(&ore_api::ID)?;
|
||||
block.id = id;
|
||||
block.opener = *signer_info.key;
|
||||
block.best_hash = [0; 32];
|
||||
block.best_hash = [u8::MAX; 32];
|
||||
block.best_hash_miner = Pubkey::default();
|
||||
block.reward = 0; // Set by reset instruction
|
||||
block.start_slot = u64::MAX; // Set by reset instruction
|
||||
|
||||
@@ -8,7 +8,7 @@ use steel::*;
|
||||
pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResult {
|
||||
// Load accounts.
|
||||
let clock = Clock::get()?;
|
||||
let [signer_info, block_prev_info, block_next_info, config_info, fee_collector_info, market_info, mint_info, treasury_info, treasury_tokens_info, vault_info, system_program, token_program, ore_program, slot_hashes_sysvar] =
|
||||
let [signer_info, block_prev_info, block_next_info, config_info, market_info, mint_info, treasury_info, treasury_tokens_info, vault_info, system_program, token_program, ore_program, slot_hashes_sysvar] =
|
||||
accounts
|
||||
else {
|
||||
return Err(ProgramError::NotEnoughAccountKeys);
|
||||
@@ -16,9 +16,6 @@ pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
|
||||
signer_info.is_signer()?;
|
||||
let block_next = block_next_info.as_account_mut::<Block>(&ore_api::ID)?;
|
||||
let config = config_info.as_account::<Config>(&ore_api::ID)?;
|
||||
fee_collector_info
|
||||
.is_writable()?
|
||||
.as_associated_token_account(&config.fee_collector, &mint_info.key)?;
|
||||
let market = market_info
|
||||
.as_account_mut::<Market>(&ore_api::ID)?
|
||||
.assert_mut(|m| m.block_id == block_next.id - 1)?;
|
||||
|
||||
@@ -36,7 +36,6 @@ pub fn process_swap(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
|
||||
.as_mint()?;
|
||||
vault_info
|
||||
.is_writable()?
|
||||
.has_address(&vault_pda().0)?
|
||||
.as_associated_token_account(market_info.key, mint_info.key)?;
|
||||
system_program.is_program(&system_program::ID)?;
|
||||
token_program.is_program(&spl_token::ID)?;
|
||||
@@ -76,7 +75,7 @@ pub fn process_swap(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
|
||||
|
||||
// Pay swap fee.
|
||||
if config.fee_rate > 0 {
|
||||
signer_info.send(config.fee_rate, fee_collector_info);
|
||||
fee_collector_info.collect(config.fee_rate, &signer_info)?;
|
||||
}
|
||||
|
||||
// Load token acccounts.
|
||||
|
||||
Reference in New Issue
Block a user