From 3abe0e080b1b75939befb5bfdb451933a3bedcf3 Mon Sep 17 00:00:00 2001 From: Hardhat Chad Date: Tue, 23 Sep 2025 11:21:30 -0700 Subject: [PATCH] set executor --- api/src/instruction.rs | 22 ++++++++++----------- program/src/lib.rs | 6 +++--- program/src/reimburse.rs | 38 ------------------------------------- program/src/set_executor.rs | 27 ++++++++++++++++++++++++++ 4 files changed, 41 insertions(+), 52 deletions(-) delete mode 100644 program/src/reimburse.rs create mode 100644 program/src/set_executor.rs diff --git a/api/src/instruction.rs b/api/src/instruction.rs index 8df4360..113cd5e 100644 --- a/api/src/instruction.rs +++ b/api/src/instruction.rs @@ -11,12 +11,12 @@ pub enum OreInstruction { Initialize = 4, Log = 5, Reset = 7, - Reimburse = 8, + SetExecutor = 9, // Admin - Bury = 9, - SetAdmin = 10, - SetFeeCollector = 11, + Bury = 10, + SetAdmin = 11, + SetFeeCollector = 12, // Seeker ClaimSeeker = 14, @@ -78,6 +78,12 @@ pub struct Uncommit { pub amount: [u8; 8], } +#[repr(C)] +#[derive(Clone, Copy, Debug, Pod, Zeroable)] +pub struct SetExecutor { + pub executor: [u8; 32], +} + #[repr(C)] #[derive(Clone, Copy, Debug, Pod, Zeroable)] pub struct SetAdmin { @@ -106,12 +112,6 @@ pub struct Bury { #[derive(Clone, Copy, Debug, Pod, Zeroable)] pub struct ClaimSeeker {} -#[repr(C)] -#[derive(Clone, Copy, Debug, Pod, Zeroable)] -pub struct Reimburse { - pub amount: [u8; 8], -} - instruction!(OreInstruction, Boost); instruction!(OreInstruction, ClaimSOL); instruction!(OreInstruction, ClaimORE); @@ -120,7 +120,7 @@ instruction!(OreInstruction, Initialize); instruction!(OreInstruction, Log); instruction!(OreInstruction, Bury); instruction!(OreInstruction, Reset); -instruction!(OreInstruction, Reimburse); +instruction!(OreInstruction, SetExecutor); instruction!(OreInstruction, SetAdmin); instruction!(OreInstruction, SetFeeCollector); instruction!(OreInstruction, ClaimSeeker); diff --git a/program/src/lib.rs b/program/src/lib.rs index dacf123..c2c4a96 100644 --- a/program/src/lib.rs +++ b/program/src/lib.rs @@ -6,9 +6,9 @@ mod claim_sol; mod deploy; mod initialize; mod log; -mod reimburse; mod reset; mod set_admin; +mod set_executor; mod set_fee_collector; mod whitelist; @@ -20,9 +20,9 @@ use claim_sol::*; use deploy::*; use initialize::*; use log::*; -use reimburse::*; use reset::*; use set_admin::*; +use set_executor::*; use set_fee_collector::*; use ore_api::instruction::*; @@ -44,7 +44,7 @@ pub fn process_instruction( OreInstruction::Log => process_log(accounts, data)?, OreInstruction::Initialize => process_initialize(accounts, data)?, OreInstruction::Reset => process_reset(accounts, data)?, - OreInstruction::Reimburse => process_reimburse(accounts, data)?, + OreInstruction::SetExecutor => process_set_executor(accounts, data)?, // Admin OreInstruction::SetAdmin => process_set_admin(accounts, data)?, diff --git a/program/src/reimburse.rs b/program/src/reimburse.rs deleted file mode 100644 index c39fb4c..0000000 --- a/program/src/reimburse.rs +++ /dev/null @@ -1,38 +0,0 @@ -use ore_api::prelude::*; -use solana_program::rent::Rent; -use steel::*; - -/// Reimburses an executor keypair for their tx fee expenses. -pub fn process_reimburse(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult { - // Parse data. - let args = Reimburse::try_from_bytes(data)?; - let amount = u64::from_le_bytes(args.amount); - - // Load accounts. - let [signer_info, miner_info, system_program] = accounts else { - return Err(ProgramError::NotEnoughAccountKeys); - }; - signer_info.is_signer()?; - let miner = miner_info - .as_account_mut::(&ore_api::ID)? - .assert_mut(|m| m.executor == *signer_info.key)?; - system_program.is_program(&system_program::ID)?; - - // Check if miner can charge.// Check total amount. - let account_size = 8 + std::mem::size_of::(); - let min_rent = Rent::get()?.minimum_balance(account_size); - let claimable_sol = miner.rewards_sol; - let obligations = min_rent + claimable_sol; - let new_lamports = miner_info.lamports().saturating_sub(amount); - if new_lamports < obligations { - return Err(trace( - "Miner account has insufficient SOL", - ProgramError::InsufficientFunds, - )); - } - - // Send reimbursement. - miner_info.send(amount, signer_info); - - Ok(()) -} diff --git a/program/src/set_executor.rs b/program/src/set_executor.rs new file mode 100644 index 0000000..21ad808 --- /dev/null +++ b/program/src/set_executor.rs @@ -0,0 +1,27 @@ +use ore_api::prelude::*; +use steel::*; + +/// Sets the executor. +pub fn process_set_executor(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult { + // Parse data. + let args = SetExecutor::try_from_bytes(data)?; + let new_executor = Pubkey::new_from_array(args.executor); + + // Load accounts. + let [signer_info, miner_info, system_program] = accounts else { + return Err(ProgramError::NotEnoughAccountKeys); + }; + signer_info.is_signer()?; + let miner = miner_info + .as_account_mut::(&ore_api::ID)? + .assert_mut_err( + |m| m.authority == *signer_info.key, + OreError::NotAuthorized.into(), + )?; + system_program.is_program(&system_program::ID)?; + + // Set executor. + miner.executor = new_executor; + + Ok(()) +}