From 937938ab808bb6a37db558fe70c0a1512d0999da Mon Sep 17 00:00:00 2001 From: Hardhat Chad Date: Tue, 23 Sep 2025 15:44:10 -0700 Subject: [PATCH] close --- api/src/sdk.rs | 1 + program/src/deploy.rs | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/api/src/sdk.rs b/api/src/sdk.rs index 11eaac6..398afc0 100644 --- a/api/src/sdk.rs +++ b/api/src/sdk.rs @@ -172,6 +172,7 @@ pub fn deploy( program_id: crate::ID, accounts: vec![ AccountMeta::new(signer, true), + AccountMeta::new(authority, false), AccountMeta::new(automation_address, false), AccountMeta::new(board_address, false), AccountMeta::new(config_address, false), diff --git a/program/src/deploy.rs b/program/src/deploy.rs index 862bab0..5243255 100644 --- a/program/src/deploy.rs +++ b/program/src/deploy.rs @@ -13,12 +13,13 @@ pub fn process_deploy(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResul // Load accounts. let clock = Clock::get()?; - let [signer_info, automation_info, board_info, config_info, fee_collector_info, miner_info, square_info, system_program] = + let [signer_info, authority_info, automation_info, board_info, config_info, fee_collector_info, miner_info, square_info, system_program] = accounts else { return Err(ProgramError::NotEnoughAccountKeys); }; signer_info.is_signer()?; + authority_info.is_writable()?; automation_info.is_writable()?; let board = board_info .as_account_mut::(&ore_api::ID)? @@ -43,7 +44,8 @@ pub fn process_deploy(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResul let automation = if !automation_info.data_is_empty() { let automation = automation_info .as_account_mut::(&ore_api::ID)? - .assert_mut(|a| a.executor == *signer_info.key)?; + .assert_mut(|a| a.executor == *signer_info.key)? + .assert_mut(|a| a.authority == *authority_info.key)?; Some(automation) } else { None @@ -186,6 +188,11 @@ pub fn process_deploy(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResul automation_info.send(total_amount, &board_info); automation_info.send(total_fee, &fee_collector_info); automation_info.send(automation.fee, &signer_info); + + // Close automation if balance is 0. + if automation.balance == 0 { + automation_info.close(authority_info)?; + } } else { board_info.collect(total_amount, &signer_info)?; fee_collector_info.collect(total_fee, &signer_info)?;