diff --git a/src/error.rs b/src/error.rs index c232367..4ca9232 100644 --- a/src/error.rs +++ b/src/error.rs @@ -5,18 +5,20 @@ use thiserror::Error; #[derive(Debug, Error, Clone, Copy, PartialEq, Eq, IntoPrimitive)] #[repr(u32)] pub enum OreError { - #[error("The epoch is still active and cannot be reset")] - EpochActive = 0, + #[error("The start time has not passed yet")] + NotStarted = 0, #[error("The epoch has ended and needs reset")] - EpochEnded = 1, + NeedsReset = 1, + #[error("The epoch is active and cannot be reset at this time")] + InvalidReset = 2, #[error("The provided hash was invalid")] - InvalidHash = 2, + InvalidHash = 3, #[error("The provided hash does not satisfy the difficulty requirement")] - InsufficientHashDifficulty = 3, + InsufficientHashDifficulty = 4, #[error("The bus has insufficient rewards to mine at this time")] - InsufficientBusRewards = 4, + InsufficientBusRewards = 5, #[error("The claim amount cannot be larger than the claimable rewards")] - InvalidClaimAmount = 5, + InvalidClaimAmount = 6, } impl From for ProgramError { diff --git a/src/instruction.rs b/src/instruction.rs index 43a70c5..a7ec2e8 100644 --- a/src/instruction.rs +++ b/src/instruction.rs @@ -73,7 +73,7 @@ pub enum OreInstruction { #[account(14, name = "system_program", desc = "Solana system program")] #[account(15, name = "token_program", desc = "SPL token program")] #[account(16, name = "associated_token_program", desc = "SPL associated token program")] - #[account(17, name = "mpl_token_metadata", desc = "MPL token metadata program")] + #[account(17, name = "mpl_metadata_program", desc = "MPL token metadata program")] #[account(18, name = "rent", desc = "Solana rent sysvar")] Initialize = 100, diff --git a/src/processor/mine.rs b/src/processor/mine.rs index ff622b8..6e80f26 100644 --- a/src/processor/mine.rs +++ b/src/processor/mine.rs @@ -19,7 +19,7 @@ use crate::{ loaders::*, state::{Bus, Proof, Treasury}, utils::AccountDeserialize, - EPOCH_DURATION, + EPOCH_DURATION, START_AT, }; /// Mine is the primary workhorse instruction of the Ore program. Its responsibilities include: @@ -52,13 +52,18 @@ pub fn process_mine<'a, 'info>( load_treasury(treasury_info, false)?; load_sysvar(slot_hashes_info, sysvar::slot_hashes::id())?; - // Validate epoch is active + // Validate mining has starting let clock = Clock::get().or(Err(ProgramError::InvalidAccountData))?; + if clock.unix_timestamp.lt(&START_AT) { + return Err(OreError::NotStarted.into()); + } + + // Validate epoch is active let treasury_data = treasury_info.data.borrow(); let treasury = Treasury::try_from_bytes(&treasury_data)?; let threshold = treasury.last_reset_at.saturating_add(EPOCH_DURATION); if clock.unix_timestamp.ge(&threshold) { - return Err(OreError::EpochEnded.into()); + return Err(OreError::NeedsReset.into()); } // Validate provided hash diff --git a/src/processor/reset.rs b/src/processor/reset.rs index 460eb5c..6a8cec5 100644 --- a/src/processor/reset.rs +++ b/src/processor/reset.rs @@ -8,7 +8,7 @@ use crate::{ loaders::*, state::{Bus, Treasury}, utils::AccountDeserialize, - BUS_COUNT, BUS_EPOCH_REWARDS, EPOCH_DURATION, MAX_EPOCH_REWARDS, SMOOTHING_FACTOR, + BUS_COUNT, BUS_EPOCH_REWARDS, EPOCH_DURATION, MAX_EPOCH_REWARDS, SMOOTHING_FACTOR, START_AT, TARGET_EPOCH_REWARDS, TREASURY, }; @@ -61,13 +61,18 @@ pub fn process_reset<'a, 'info>( bus_7_info, ]; - // Validate at least 60 seconds have passed since last reset + // Validate mining has starting let clock = Clock::get().or(Err(ProgramError::InvalidAccountData))?; + if clock.unix_timestamp.lt(&START_AT) { + return Err(OreError::NotStarted.into()); + } + + // Validate at least 60 seconds have passed since last reset let mut treasury_data = treasury_info.data.borrow_mut(); let treasury = Treasury::try_from_bytes_mut(&mut treasury_data)?; let threshold = treasury.last_reset_at.saturating_add(EPOCH_DURATION); if clock.unix_timestamp.lt(&threshold) { - return Err(OreError::EpochActive.into()); + return Err(OreError::InvalidReset.into()); } // Record current timestamp