From b55b6d338dfa0f4f2027c480c10d552a7e9caffa Mon Sep 17 00:00:00 2001 From: Hardhat Chad Date: Mon, 1 Jul 2024 14:53:09 -0500 Subject: [PATCH] move loaders to api --- api/src/lib.rs | 1 + {program => api}/src/loaders.rs | 24 ++++++++++++------------ program/src/claim.rs | 4 ++-- program/src/close.rs | 4 ++-- program/src/crown.rs | 7 +++++-- program/src/initialize.rs | 6 ++---- program/src/lib.rs | 1 - program/src/mine.rs | 3 ++- program/src/open.rs | 7 ++----- program/src/reset.rs | 9 ++------- program/src/stake.rs | 4 ++-- program/src/update.rs | 4 ++-- program/src/upgrade.rs | 4 +--- rust-toolchain.toml | 2 +- 14 files changed, 36 insertions(+), 44 deletions(-) rename {program => api}/src/loaders.rs (96%) diff --git a/api/src/lib.rs b/api/src/lib.rs index 409cafb..6218ce7 100644 --- a/api/src/lib.rs +++ b/api/src/lib.rs @@ -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; diff --git a/program/src/loaders.rs b/api/src/loaders.rs similarity index 96% rename from program/src/loaders.rs rename to api/src/loaders.rs index 1daaa96..0b95d4b 100644 --- a/program/src/loaders.rs +++ b/api/src/loaders.rs @@ -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); } diff --git a/program/src/claim.rs b/program/src/claim.rs index 554f824..9a5ae4e 100644 --- a/program/src/claim.rs +++ b/program/src/claim.rs @@ -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. diff --git a/program/src/close.rs b/program/src/close.rs index 107f1c0..d92bb20 100644 --- a/program/src/close.rs +++ b/program/src/close.rs @@ -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. diff --git a/program/src/crown.rs b/program/src/crown.rs index aeb1827..39e3d93 100644 --- a/program/src/crown.rs +++ b/program/src/crown.rs @@ -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>( diff --git a/program/src/initialize.rs b/program/src/initialize.rs index d4200f9..3679132 100644 --- a/program/src/initialize.rs +++ b/program/src/initialize.rs @@ -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. diff --git a/program/src/lib.rs b/program/src/lib.rs index bac4a88..acb5b86 100644 --- a/program/src/lib.rs +++ b/program/src/lib.rs @@ -2,7 +2,6 @@ mod claim; mod close; mod crown; mod initialize; -mod loaders; mod mine; mod open; mod reset; diff --git a/program/src/mine.rs b/program/src/mine.rs index d362ed0..c438a58 100644 --- a/program/src/mine.rs +++ b/program/src/mine.rs @@ -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. diff --git a/program/src/open.rs b/program/src/open.rs index 66e603a..fc6e570 100644 --- a/program/src/open.rs +++ b/program/src/open.rs @@ -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. diff --git a/program/src/reset.rs b/program/src/reset.rs index dd656a3..0e78401 100644 --- a/program/src/reset.rs +++ b/program/src/reset.rs @@ -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. diff --git a/program/src/stake.rs b/program/src/stake.rs index d72ddb3..dbd4f0a 100644 --- a/program/src/stake.rs +++ b/program/src/stake.rs @@ -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. diff --git a/program/src/update.rs b/program/src/update.rs index 35f384c..2ad607d 100644 --- a/program/src/update.rs +++ b/program/src/update.rs @@ -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>( diff --git a/program/src/upgrade.rs b/program/src/upgrade.rs index 0f5a044..b74524b 100644 --- a/program/src/upgrade.rs +++ b/program/src/upgrade.rs @@ -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. diff --git a/rust-toolchain.toml b/rust-toolchain.toml index fa4b8db..61551a5 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -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"