From bc3516995cab53242f286f7a6a347eb1fc05ee2e Mon Sep 17 00:00:00 2001 From: Hardhat Chad Date: Thu, 2 Oct 2025 13:52:27 -0700 Subject: [PATCH] autoclose --- program/src/automate.rs | 8 +++++++- program/src/deploy.rs | 15 ++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/program/src/automate.rs b/program/src/automate.rs index 044a715..a60dd3f 100644 --- a/program/src/automate.rs +++ b/program/src/automate.rs @@ -17,7 +17,7 @@ pub fn process_automate(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramRes }; signer_info.is_signer()?; automation_info.is_writable()?; - miner_info + let miner = miner_info .as_account_mut::(&ore_api::ID)? .assert_mut_err( |m| m.authority == *signer_info.key, @@ -72,6 +72,12 @@ pub fn process_automate(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramRes automation.mask = mask; automation.strategy = strategy as u64; + // Top up checkpoint fee. + if miner.checkpoint_fee == 0 { + miner.checkpoint_fee = CHECKPOINT_FEE; + miner_info.collect(CHECKPOINT_FEE, &signer_info)?; + } + // Transfer balance to executor. automation_info.collect(deposit, signer_info)?; diff --git a/program/src/deploy.rs b/program/src/deploy.rs index 5940478..843c76b 100644 --- a/program/src/deploy.rs +++ b/program/src/deploy.rs @@ -34,11 +34,6 @@ pub fn process_deploy(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResul .has_seeds(&[MINER, &authority_info.key.to_bytes()], &ore_api::ID)?; system_program.is_program(&system_program::ID)?; - // Check whitelist - if !AUTHORIZED_ACCOUNTS.contains(&signer_info.key) { - return Err(trace("Not authorized", OreError::NotAuthorized.into())); - } - // Wait until first deploy to start round. if board.end_slot == u64::MAX { board.start_slot = clock.slot; @@ -118,6 +113,12 @@ pub fn process_deploy(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResul })? }; + // Check whitelist + if !AUTHORIZED_ACCOUNTS.contains(&miner.authority) { + sol_log(miner.authority.to_string().as_str()); + return Err(trace("Not authorized", OreError::NotAuthorized.into())); + } + // Reset miner if miner.round_id != round.id { // Assert miner has checkpointed prior round. @@ -186,8 +187,8 @@ pub fn process_deploy(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResul automation_info.send(total_amount, &round_info); automation_info.send(automation.fee, &signer_info); - // Close automation if balance is 0. - if automation.balance == 0 { + // Close automation if balance is less than what's required to deploy 1 square. + if automation.balance < automation.amount + automation.fee { automation_info.close(authority_info)?; } } else {