diff --git a/README.md b/README.md index a95a1ee..7f0a88b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # ORE -ORE is a crypto mining game. +ORE is a crypto mining protocol. ## API @@ -13,6 +13,7 @@ ORE is a crypto mining game. #### Mining - [`Automate`](program/src/automate.rs) - Configures a new automation. +- [`Checkpoint`](program/src/checkpoint.rs) - Checkpoints rewards from an prior round. - [`ClaimORE`](program/src/claim_ore.rs) - Claims ORE mining rewards. - [`ClaimSOL`](program/src/claim_sol.rs) - Claims SOL mining rewards. - [`Deploy`](program/src/deploy.rs) – Deploys SOL to claim space on the board. @@ -36,11 +37,11 @@ ORE is a crypto mining game. ## State - [`Automation`](api/src/state/automation.rs) - Tracks automation configs. -- [`Board`](api/src/state/board.rs) - Holds current game state. +- [`Board`](api/src/state/board.rs) - Tracks the current round number and timestamps. - [`Config`](api/src/state/config.rs) - Global program configs. - [`Miner`](api/src/state/miner.rs) - Tracks a miner's game state. +- [`Round`](api/src/state/round.rs) - Tracks the game state of a given round. - [`Seeker`](api/src/state/seeker.rs) - Tracks whether a Seeker token has been claimed. -- [`Square`](api/src/state/square.rs) - The blockspace state and claims. - [`Stake`](api/src/state/stake.rs) - Manages a user's staking activity. - [`Treasury`](api/src/state/treasury.rs) - Mints, burns, and escrows ORE tokens. diff --git a/program/src/checkpoint.rs b/program/src/checkpoint.rs index f945070..b251a5e 100644 --- a/program/src/checkpoint.rs +++ b/program/src/checkpoint.rs @@ -13,52 +13,48 @@ pub fn process_checkpoint(accounts: &[AccountInfo<'_>], _data: &[u8]) -> Program signer_info.is_signer()?; let board = board_info.as_account::(&ore_api::ID)?; let miner = miner_info.as_account_mut::(&ore_api::ID)?; + // If miner has already checkpointed this round, return. if miner.checkpoint_id == miner.round_id { return Ok(()); } + + // If round account is empty, verify the correct account was provided. + // This can happen if the miner attempted to checkpoint after the round expired and the account was closed. + // In this case, the miner forfeits any potential rewards. if round_info.data_is_empty() { - // If round account is empty, ensure the correct account was provided. - // This can happen if the miner attempted to checkpoint after the round expired and the account was closed. - // In this case, the miner forfeits any potential rewards. round_info.has_seeds(&[ROUND, &miner.round_id.to_le_bytes()], &ore_api::ID)?; miner.checkpoint_id = miner.round_id; return Ok(()); } + let round = round_info.as_account_mut::(&ore_api::ID)?; - - // Ensure miner round ID matches the provided round. - if round.id != miner.round_id { - return Ok(()); - } - treasury_info.as_account::(&ore_api::ID)?; system_program.is_program(&system_program::ID)?; - // If round is current round, return. - if round.id == board.round_id { + // If round is current round, or the miner round ID does not match the provided round, return. + if round.id == board.round_id || round.id != miner.round_id { return Ok(()); } // Ensure round is not expired. + // In this case, the miner forfeits any potential rewards. if clock.slot >= round.expires_at { - // In this case, the miner forfeits any potential rewards. miner.checkpoint_id = miner.round_id; return Ok(()); } // Get the RNG. + // If the round has no RNG, no one wins. let Some(r) = round.rng() else { - // If the round has no RNG, no one wins. miner.checkpoint_id = miner.round_id; return Ok(()); }; // Calculate bot fee. + // If the round expires in less than 12h, anyone may checkpoint this account and collect the bot fee. let mut bot_fee = 0; if clock.slot >= round.expires_at - TWELVE_HOURS_SLOTS { - // The round expires in less than 12h. - // Anyone may checkpoint this account and collect the bot fee. bot_fee = miner.checkpoint_fee; miner.checkpoint_fee = 0; } @@ -112,14 +108,6 @@ pub fn process_checkpoint(accounts: &[AccountInfo<'_>], _data: &[u8]) -> Program miner_info.send(bot_fee, &signer_info); } - // Assert round has sufficient funds for rent. - let account_size = 8 + std::mem::size_of::(); - let required_rent = Rent::get()?.minimum_balance(account_size); - assert!( - round_info.lamports() >= required_rent, - "Round does not have sufficient funds for rent" - ); - let account_size = 8 + std::mem::size_of::(); let required_rent = Rent::get()?.minimum_balance(account_size); assert!(