continued refactor

This commit is contained in:
Hardhat Chad
2024-06-29 12:39:11 +00:00
parent eaa90ae0ab
commit 9c1cc9babf
27 changed files with 122 additions and 87 deletions

View File

@@ -8,6 +8,8 @@ use solana_program::{
pubkey::Pubkey,
};
pub(crate) use utils;
#[cfg(not(feature = "no-entrypoint"))]
solana_program::entrypoint!(process_instruction);

View File

@@ -1,7 +1,6 @@
use ore_api::{
consts::*,
state::{Bus, Config, Proof, Treasury},
utils::{AccountDeserialize, Discriminator},
};
use solana_program::{
account_info::AccountInfo, program_error::ProgramError, program_pack::Pack, pubkey::Pubkey,
@@ -9,6 +8,8 @@ use solana_program::{
};
use spl_token::state::Mint;
use crate::utils::{AccountDeserialize, Discriminator};
/// Errors if:
/// - Account is not a signer.
pub fn load_signer<'a, 'info>(info: &'a AccountInfo<'info>) -> Result<(), ProgramError> {

View File

@@ -1,12 +1,10 @@
use ore_api::{
consts::*, error::OreError, instruction::ClaimArgs, state::Proof, utils::AccountDeserialize,
};
use ore_api::{consts::*, error::OreError, instruction::ClaimArgs, state::Proof};
use solana_program::{
account_info::AccountInfo, entrypoint::ProgramResult, program_error::ProgramError,
pubkey::Pubkey,
};
use crate::loaders::*;
use crate::{loaders::*, utils::AccountDeserialize};
/// Claim distributes Ore from the treasury to a miner. Its responsibilies include:
/// 1. Decrement the miner's claimable balance.

View File

@@ -1,10 +1,10 @@
use ore_api::{state::Proof, utils::AccountDeserialize};
use ore_api::state::Proof;
use solana_program::{
account_info::AccountInfo, entrypoint::ProgramResult, program_error::ProgramError,
pubkey::Pubkey, system_program,
};
use crate::loaders::*;
use crate::{loaders::*, utils::AccountDeserialize};
/// Close closes a proof account and returns the rent to the owner. Its responsibilities include:
/// 1. Realloc proof account size to 0.

View File

@@ -1,13 +1,10 @@
use ore_api::{
state::{Config, Proof},
utils::AccountDeserialize,
};
use ore_api::state::{Config, Proof};
use solana_program::{
account_info::AccountInfo, entrypoint::ProgramResult, program_error::ProgramError,
pubkey::Pubkey,
};
use crate::loaders::*;
use crate::{loaders::*, utils::AccountDeserialize};
/// Crown flags an account as the top staker if their balance is greater than the last known top staker.
pub fn process_crown<'a, 'info>(

View File

@@ -4,9 +4,6 @@ use ore_api::{
consts::*,
instruction::*,
state::{Bus, Config, Treasury},
utils::create_pda,
utils::AccountDeserialize,
utils::Discriminator,
};
use solana_program::{
account_info::AccountInfo,
@@ -18,7 +15,10 @@ use solana_program::{
};
use spl_token::state::Mint;
use crate::loaders::*;
use crate::{
loaders::*,
utils::{create_pda, AccountDeserialize, Discriminator},
};
/// Initialize sets up the Ore program. Its responsibilities include:
/// 1. Initialize the 8 bus accounts.

View File

@@ -4,9 +4,9 @@ use drillx::Solution;
use ore_api::{
consts::*,
error::OreError,
event::MineEvent,
instruction::{MineArgs, OreInstruction},
state::{Bus, Config, Proof},
utils::{AccountDeserialize, MineEvent},
};
use solana_program::program::set_return_data;
#[allow(deprecated)]
@@ -25,7 +25,7 @@ use solana_program::{
sysvar::{self, instructions::load_current_index, Sysvar},
};
use crate::loaders::*;
use crate::{loaders::*, utils::AccountDeserialize};
/// Mine is the primary workhorse instruction of the Ore program. Its responsibilities include:
/// 1. Calculate the hash from the provided nonce.

View File

@@ -1,11 +1,6 @@
use std::mem::size_of;
use ore_api::{
consts::*,
instruction::OpenArgs,
state::Proof,
utils::{create_pda, AccountDeserialize, Discriminator},
};
use ore_api::{consts::*, instruction::OpenArgs, state::Proof};
use solana_program::{
account_info::AccountInfo,
blake3::hashv,
@@ -18,7 +13,10 @@ use solana_program::{
sysvar::{self, Sysvar},
};
use crate::loaders::*;
use crate::{
loaders::*,
utils::{create_pda, AccountDeserialize, Discriminator},
};
/// Register generates a new hash chain for a prospective miner. Its responsibilities include:
/// 1. Initialize a new proof account.

View File

@@ -2,7 +2,6 @@ use ore_api::{
consts::*,
error::OreError,
state::{Bus, Config},
utils::AccountDeserialize,
};
use solana_program::{
account_info::AccountInfo, clock::Clock, entrypoint::ProgramResult,
@@ -10,8 +9,12 @@ use solana_program::{
};
use spl_token::state::Mint;
use crate::loaders::{
load_bus, load_config, load_mint, load_program, load_signer, load_token_account, load_treasury,
use crate::{
loaders::{
load_bus, load_config, load_mint, load_program, load_signer, load_token_account,
load_treasury,
},
utils::AccountDeserialize,
};
/// Reset sets up the Ore program for the next epoch. Its responsibilities include:
@@ -165,9 +168,9 @@ pub(crate) fn calculate_new_reward_rate(current_rate: u64, epoch_rewards: u64) -
mod tests {
use rand::{distributions::Uniform, Rng};
use crate::{
calculate_new_reward_rate, BUS_EPOCH_REWARDS, MAX_EPOCH_REWARDS, SMOOTHING_FACTOR,
TARGET_EPOCH_REWARDS,
use crate::calculate_new_reward_rate;
use ore_api::consts::{
BUS_EPOCH_REWARDS, MAX_EPOCH_REWARDS, SMOOTHING_FACTOR, TARGET_EPOCH_REWARDS,
};
const FUZZ_SIZE: u64 = 10_000;

View File

@@ -1,10 +1,10 @@
use ore_api::{consts::*, instruction::StakeArgs, state::Proof, utils::AccountDeserialize};
use ore_api::{consts::*, instruction::StakeArgs, state::Proof};
use solana_program::{
account_info::AccountInfo, clock::Clock, entrypoint::ProgramResult,
program_error::ProgramError, pubkey::Pubkey, sysvar::Sysvar,
};
use crate::loaders::*;
use crate::{loaders::*, utils::AccountDeserialize};
/// Stake deposits Ore into a miner's proof account to earn multiplier. Its responsibilies include:
/// 1. Transfer tokens from the miner to the treasury account.

View File

@@ -1,10 +1,10 @@
use ore_api::{state::Proof, utils::AccountDeserialize};
use ore_api::state::Proof;
use solana_program::{
account_info::AccountInfo, entrypoint::ProgramResult, program_error::ProgramError,
pubkey::Pubkey,
};
use crate::loaders::*;
use crate::{loaders::*, utils::AccountDeserialize};
/// Update changes the miner authority on a proof account.
pub fn process_update<'a, 'info>(