move loaders to api

This commit is contained in:
Hardhat Chad
2024-07-01 14:53:09 -05:00
parent a7c6da1881
commit b55b6d338d
14 changed files with 36 additions and 44 deletions

View File

@@ -2,6 +2,7 @@ pub mod consts;
pub mod error;
pub mod event;
pub mod instruction;
pub mod loaders;
pub mod state;
pub(crate) use utils;

View File

@@ -1,14 +1,14 @@
use ore_api::{
consts::*,
state::{Bus, Config, Proof, Treasury},
};
use solana_program::{
account_info::AccountInfo, program_error::ProgramError, program_pack::Pack, pubkey::Pubkey,
system_program, sysvar,
};
use spl_token::state::Mint;
use crate::utils::{AccountDeserialize, Discriminator};
use crate::{
consts::*,
state::{Bus, Config, Proof, Treasury},
utils::{AccountDeserialize, Discriminator},
};
/// Errors if:
/// - Account is not a signer.
@@ -32,7 +32,7 @@ pub fn load_bus<'a, 'info>(
id: u64,
is_writable: bool,
) -> Result<(), ProgramError> {
if info.owner.ne(&ore_api::id()) {
if info.owner.ne(&crate::id()) {
return Err(ProgramError::InvalidAccountOwner);
}
@@ -69,7 +69,7 @@ pub fn load_any_bus<'a, 'info>(
info: &'a AccountInfo<'info>,
is_writable: bool,
) -> Result<(), ProgramError> {
if info.owner.ne(&ore_api::id()) {
if info.owner.ne(&crate::id()) {
return Err(ProgramError::InvalidAccountOwner);
}
@@ -102,7 +102,7 @@ pub fn load_config<'a, 'info>(
info: &'a AccountInfo<'info>,
is_writable: bool,
) -> Result<(), ProgramError> {
if info.owner.ne(&ore_api::id()) {
if info.owner.ne(&crate::id()) {
return Err(ProgramError::InvalidAccountOwner);
}
@@ -136,7 +136,7 @@ pub fn load_proof<'a, 'info>(
authority: &Pubkey,
is_writable: bool,
) -> Result<(), ProgramError> {
if info.owner.ne(&ore_api::id()) {
if info.owner.ne(&crate::id()) {
return Err(ProgramError::InvalidAccountOwner);
}
@@ -169,7 +169,7 @@ pub fn load_proof_with_miner<'a, 'info>(
miner: &Pubkey,
is_writable: bool,
) -> Result<(), ProgramError> {
if info.owner.ne(&ore_api::id()) {
if info.owner.ne(&crate::id()) {
return Err(ProgramError::InvalidAccountOwner);
}
@@ -200,7 +200,7 @@ pub fn load_any_proof<'a, 'info>(
info: &'a AccountInfo<'info>,
is_writable: bool,
) -> Result<(), ProgramError> {
if info.owner.ne(&ore_api::id()) {
if info.owner.ne(&crate::id()) {
return Err(ProgramError::InvalidAccountOwner);
}
@@ -229,7 +229,7 @@ pub fn load_treasury<'a, 'info>(
info: &'a AccountInfo<'info>,
is_writable: bool,
) -> Result<(), ProgramError> {
if info.owner.ne(&ore_api::id()) {
if info.owner.ne(&crate::id()) {
return Err(ProgramError::InvalidAccountOwner);
}

View File

@@ -1,10 +1,10 @@
use ore_api::{consts::*, error::OreError, instruction::ClaimArgs, state::Proof};
use ore_api::{consts::*, error::OreError, instruction::ClaimArgs, loaders::*, state::Proof};
use solana_program::{
account_info::AccountInfo, entrypoint::ProgramResult, program_error::ProgramError,
pubkey::Pubkey,
};
use crate::{loaders::*, utils::AccountDeserialize};
use crate::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;
use ore_api::{loaders::*, state::Proof};
use solana_program::{
account_info::AccountInfo, entrypoint::ProgramResult, program_error::ProgramError,
pubkey::Pubkey, system_program,
};
use crate::{loaders::*, utils::AccountDeserialize};
use crate::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,10 +1,13 @@
use ore_api::state::{Config, Proof};
use ore_api::{
loaders::*,
state::{Config, Proof},
};
use solana_program::{
account_info::AccountInfo, entrypoint::ProgramResult, program_error::ProgramError,
pubkey::Pubkey,
};
use crate::{loaders::*, utils::AccountDeserialize};
use crate::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

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

View File

@@ -2,7 +2,6 @@ mod claim;
mod close;
mod crown;
mod initialize;
mod loaders;
mod mine;
mod open;
mod reset;

View File

@@ -6,6 +6,7 @@ use ore_api::{
error::OreError,
event::MineEvent,
instruction::{MineArgs, OreInstruction},
loaders::*,
state::{Bus, Config, Proof},
};
use solana_program::program::set_return_data;
@@ -25,7 +26,7 @@ use solana_program::{
sysvar::{self, instructions::load_current_index, Sysvar},
};
use crate::{loaders::*, utils::AccountDeserialize};
use crate::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,6 +1,6 @@
use std::mem::size_of;
use ore_api::{consts::*, instruction::OpenArgs, state::Proof};
use ore_api::{consts::*, instruction::OpenArgs, loaders::*, state::Proof};
use solana_program::{
account_info::AccountInfo,
blake3::hashv,
@@ -13,10 +13,7 @@ use solana_program::{
sysvar::{self, Sysvar},
};
use crate::{
loaders::*,
utils::{create_pda, AccountDeserialize, Discriminator},
};
use crate::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

@@ -1,6 +1,7 @@
use ore_api::{
consts::*,
error::OreError,
loaders::*,
state::{Bus, Config},
};
use solana_program::{
@@ -9,13 +10,7 @@ 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,
},
utils::AccountDeserialize,
};
use crate::utils::AccountDeserialize;
/// Reset sets up the Ore program for the next epoch. Its responsibilities include:
/// 1. Reset bus account rewards counters.

View File

@@ -1,10 +1,10 @@
use ore_api::{consts::*, instruction::StakeArgs, state::Proof};
use ore_api::{consts::*, instruction::StakeArgs, loaders::*, state::Proof};
use solana_program::{
account_info::AccountInfo, clock::Clock, entrypoint::ProgramResult,
program_error::ProgramError, pubkey::Pubkey, sysvar::Sysvar,
};
use crate::{loaders::*, utils::AccountDeserialize};
use crate::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;
use ore_api::{loaders::*, state::Proof};
use solana_program::{
account_info::AccountInfo, entrypoint::ProgramResult, program_error::ProgramError,
pubkey::Pubkey,
};
use crate::{loaders::*, utils::AccountDeserialize};
use crate::utils::AccountDeserialize;
/// Update changes the miner authority on a proof account.
pub fn process_update<'a, 'info>(

View File

@@ -1,12 +1,10 @@
use ore_api::{consts::*, error::OreError, instruction::StakeArgs};
use ore_api::{consts::*, error::OreError, instruction::StakeArgs, loaders::*};
use solana_program::{
account_info::AccountInfo, entrypoint::ProgramResult, program_error::ProgramError,
program_pack::Pack, pubkey::Pubkey,
};
use spl_token::state::Mint;
use crate::loaders::*;
/// Upgrade allows a user to migrate a v1 token to a v2 token one-for-one. Its responsibilies include:
/// 1. Burns the v1 tokens.
/// 2. Mints an equivalent number of v2 tokens to the user.

View File

@@ -1,5 +1,5 @@
[toolchain]
channel = "1.76.0"
channel = "1.79.0"
components = [ "rustfmt", "rust-analyzer" ]
targets = [ "x86_64-apple-darwin", "x86_64-unknown-linux-gnu", "aarch64-apple-darwin"]
profile = "minimal"