diff --git a/api/src/instruction.rs b/api/src/instruction.rs index 30c7a28..ac7dcc2 100644 --- a/api/src/instruction.rs +++ b/api/src/instruction.rs @@ -15,9 +15,10 @@ pub enum OreInstruction { // Admin SetAdmin = 8, - SetFeeCollector = 9, - SetFeeRate = 10, - SetSniperFeeDuration = 11, + SetBlockDuration = 9, + SetFeeCollector = 10, + SetFeeRate = 11, + SetSniperFeeDuration = 12, } #[repr(C)] @@ -84,6 +85,12 @@ pub struct SetAdmin { pub admin: [u8; 32], } +#[repr(C)] +#[derive(Clone, Copy, Debug, Pod, Zeroable)] +pub struct SetBlockDuration { + pub block_duration: [u8; 8], +} + #[repr(C)] #[derive(Clone, Copy, Debug, Pod, Zeroable)] pub struct SetFeeCollector { @@ -111,6 +118,7 @@ instruction!(OreInstruction, Log); instruction!(OreInstruction, Mine); instruction!(OreInstruction, Swap); instruction!(OreInstruction, SetAdmin); +instruction!(OreInstruction, SetBlockDuration); instruction!(OreInstruction, SetFeeCollector); instruction!(OreInstruction, SetFeeRate); instruction!(OreInstruction, SetSniperFeeDuration); diff --git a/api/src/sdk.rs b/api/src/sdk.rs index f62ed0e..66b8526 100644 --- a/api/src/sdk.rs +++ b/api/src/sdk.rs @@ -224,6 +224,22 @@ pub fn set_admin(signer: Pubkey, admin: Pubkey) -> Instruction { } } +pub fn set_block_duration(signer: Pubkey, block_duration: u64) -> Instruction { + let config_address = config_pda().0; + Instruction { + program_id: crate::ID, + accounts: vec![ + AccountMeta::new(signer, true), + AccountMeta::new(config_address, false), + AccountMeta::new_readonly(system_program::ID, false), + ], + data: SetBlockDuration { + block_duration: block_duration.to_le_bytes(), + } + .to_bytes(), + } +} + pub fn set_fee_collector(signer: Pubkey, fee_collector: Pubkey) -> Instruction { let config_address = config_pda().0; Instruction { @@ -255,3 +271,19 @@ pub fn set_fee_rate(signer: Pubkey, fee_rate: u64) -> Instruction { .to_bytes(), } } + +pub fn set_sniper_fee_duration(signer: Pubkey, sniper_fee_duration: u64) -> Instruction { + let config_address = config_pda().0; + Instruction { + program_id: crate::ID, + accounts: vec![ + AccountMeta::new(signer, true), + AccountMeta::new(config_address, false), + AccountMeta::new_readonly(system_program::ID, false), + ], + data: SetSniperFeeDuration { + sniper_fee_duration: sniper_fee_duration.to_le_bytes(), + } + .to_bytes(), + } +} diff --git a/program/src/lib.rs b/program/src/lib.rs index be7cf0c..b6bcde3 100644 --- a/program/src/lib.rs +++ b/program/src/lib.rs @@ -6,6 +6,7 @@ mod mine; mod open; mod reset; mod set_admin; +mod set_block_duration; mod set_fee_collector; mod set_fee_rate; mod set_sniper_fee_duration; @@ -19,6 +20,7 @@ use mine::*; use open::*; use reset::*; use set_admin::*; +use set_block_duration::*; use set_fee_collector::*; use set_fee_rate::*; use set_sniper_fee_duration::*; @@ -47,6 +49,7 @@ pub fn process_instruction( // Admin OreInstruction::SetAdmin => process_set_admin(accounts, data)?, + OreInstruction::SetBlockDuration => process_set_block_duration(accounts, data)?, OreInstruction::SetFeeCollector => process_set_fee_collector(accounts, data)?, OreInstruction::SetFeeRate => process_set_fee_rate(accounts, data)?, OreInstruction::SetSniperFeeDuration => process_set_sniper_fee_duration(accounts, data)?, diff --git a/program/src/set_block_duration.rs b/program/src/set_block_duration.rs new file mode 100644 index 0000000..5a19e79 --- /dev/null +++ b/program/src/set_block_duration.rs @@ -0,0 +1,24 @@ +use ore_api::prelude::*; +use steel::*; + +/// Sets the block duration. +pub fn process_set_block_duration(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult { + // Parse data. + let args = SetBlockDuration::try_from_bytes(data)?; + let new_block_duration = u64::from_le_bytes(args.block_duration); + + // Load accounts. + let [signer_info, config_info, system_program] = accounts else { + return Err(ProgramError::NotEnoughAccountKeys); + }; + signer_info.is_signer()?; + let config = config_info + .as_account_mut::(&ore_api::ID)? + .assert_mut(|c| c.admin == *signer_info.key)?; + system_program.is_program(&system_program::ID)?; + + // Set fee collector. + config.block_duration = new_block_duration; + + Ok(()) +}