mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-13 23:16:52 +00:00
pause
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
[toolchain]
|
||||
channel = "1.75.0"
|
||||
channel = "1.76.0"
|
||||
components = [ "rustfmt", "rust-analyzer" ]
|
||||
targets = [ "x86_64-apple-darwin", "x86_64-unknown-linux-gnu", "aarch64-apple-darwin"]
|
||||
profile = "minimal"
|
||||
|
||||
@@ -96,8 +96,13 @@ pub enum OreInstruction {
|
||||
|
||||
#[account(0, name = "ore_program", desc = "Ore program")]
|
||||
#[account(1, name = "signer", desc = "Admin signer", signer)]
|
||||
#[account(2, name = "treasury", desc = "Ore treasury account")]
|
||||
#[account(2, name = "config", desc = "Ore config account")]
|
||||
UpdateAdmin = 101,
|
||||
|
||||
#[account(0, name = "ore_program", desc = "Ore program")]
|
||||
#[account(1, name = "signer", desc = "Admin signer", signer)]
|
||||
#[account(2, name = "config", desc = "Ore config account")]
|
||||
Pause = 102,
|
||||
}
|
||||
|
||||
impl OreInstruction {
|
||||
@@ -159,6 +164,12 @@ pub struct UpdateAdminArgs {
|
||||
pub new_admin: Pubkey,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
|
||||
pub struct PauseArgs {
|
||||
pub paused: u8,
|
||||
}
|
||||
|
||||
impl_to_bytes!(InitializeArgs);
|
||||
impl_to_bytes!(RegisterArgs);
|
||||
impl_to_bytes!(MineArgs);
|
||||
@@ -166,6 +177,7 @@ impl_to_bytes!(ClaimArgs);
|
||||
impl_to_bytes!(StakeArgs);
|
||||
impl_to_bytes!(UpgradeArgs);
|
||||
impl_to_bytes!(UpdateAdminArgs);
|
||||
impl_to_bytes!(PauseArgs);
|
||||
|
||||
impl_instruction_from_bytes!(InitializeArgs);
|
||||
impl_instruction_from_bytes!(RegisterArgs);
|
||||
@@ -174,6 +186,7 @@ impl_instruction_from_bytes!(ClaimArgs);
|
||||
impl_instruction_from_bytes!(StakeArgs);
|
||||
impl_instruction_from_bytes!(UpgradeArgs);
|
||||
impl_instruction_from_bytes!(UpdateAdminArgs);
|
||||
impl_instruction_from_bytes!(PauseArgs);
|
||||
|
||||
/// Builds a reset instruction.
|
||||
pub fn reset(signer: Pubkey) -> Instruction {
|
||||
@@ -345,13 +358,13 @@ pub fn initialize(signer: Pubkey) -> Instruction {
|
||||
}
|
||||
}
|
||||
|
||||
/// Builds an update_admin instruction.
|
||||
/// Build an update_admin instruction.
|
||||
pub fn update_admin(signer: Pubkey, new_admin: Pubkey) -> Instruction {
|
||||
Instruction {
|
||||
program_id: crate::id(),
|
||||
accounts: vec![
|
||||
AccountMeta::new(signer, true),
|
||||
AccountMeta::new(TREASURY_ADDRESS, false),
|
||||
AccountMeta::new(CONFIG_ADDRESS, false),
|
||||
],
|
||||
data: [
|
||||
OreInstruction::UpdateAdmin.to_vec(),
|
||||
@@ -360,3 +373,23 @@ pub fn update_admin(signer: Pubkey, new_admin: Pubkey) -> Instruction {
|
||||
.concat(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Build a pause instruction.
|
||||
pub fn pause(signer: Pubkey, paused: bool) -> Instruction {
|
||||
Instruction {
|
||||
program_id: crate::id(),
|
||||
accounts: vec![
|
||||
AccountMeta::new(signer, true),
|
||||
AccountMeta::new(CONFIG_ADDRESS, false),
|
||||
],
|
||||
data: [
|
||||
OreInstruction::UpdateAdmin.to_vec(),
|
||||
PauseArgs {
|
||||
paused: paused as u8,
|
||||
}
|
||||
.to_bytes()
|
||||
.to_vec(),
|
||||
]
|
||||
.concat(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,10 @@ use solana_program::{
|
||||
program_error::ProgramError, pubkey::Pubkey,
|
||||
};
|
||||
|
||||
// TODO Admin fn for pause
|
||||
// TODO u128 for internal rewards representation?
|
||||
// TODO Admin fn for min difficulty? What if this were set automatically by u128 base reward rate?
|
||||
// TODO Increase bus count?
|
||||
// TODO Is downgrade necessary or no?
|
||||
|
||||
declare_id!("mineRHF5r6S7HyD9SppBfVMXMavDkJsxwGesEvxZr2A");
|
||||
@@ -44,6 +47,7 @@ pub fn process_instruction(
|
||||
OreInstruction::Upgrade => process_upgrade(program_id, accounts, data)?,
|
||||
OreInstruction::Initialize => process_initialize(program_id, accounts, data)?,
|
||||
OreInstruction::UpdateAdmin => process_update_admin(program_id, accounts, data)?,
|
||||
OreInstruction::Pause => process_pause(program_id, accounts, data)?,
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
mod claim;
|
||||
mod initialize;
|
||||
mod mine;
|
||||
mod pause;
|
||||
mod register;
|
||||
mod reset;
|
||||
mod stake;
|
||||
@@ -10,6 +11,7 @@ mod upgrade;
|
||||
pub use claim::*;
|
||||
pub use initialize::*;
|
||||
pub use mine::*;
|
||||
pub use pause::*;
|
||||
pub use register::*;
|
||||
pub use reset::*;
|
||||
pub use stake::*;
|
||||
|
||||
34
src/processor/pause.rs
Normal file
34
src/processor/pause.rs
Normal file
@@ -0,0 +1,34 @@
|
||||
use solana_program::{
|
||||
account_info::AccountInfo, entrypoint::ProgramResult, program_error::ProgramError,
|
||||
pubkey::Pubkey,
|
||||
};
|
||||
|
||||
use crate::{instruction::PauseArgs, loaders::*, state::Config, utils::AccountDeserialize};
|
||||
|
||||
pub fn process_pause<'a, 'info>(
|
||||
_program_id: &Pubkey,
|
||||
accounts: &'a [AccountInfo<'info>],
|
||||
data: &[u8],
|
||||
) -> ProgramResult {
|
||||
// Parse args
|
||||
let args = PauseArgs::try_from_bytes(data)?;
|
||||
|
||||
// Load accounts
|
||||
let [signer, config_info] = accounts else {
|
||||
return Err(ProgramError::NotEnoughAccountKeys);
|
||||
};
|
||||
load_signer(signer)?;
|
||||
load_config(config_info, true)?;
|
||||
|
||||
// Validate signer is admin
|
||||
let mut config_data = config_info.data.borrow_mut();
|
||||
let config = Config::try_from_bytes_mut(&mut config_data)?;
|
||||
if config.admin.ne(&signer.key) {
|
||||
return Err(ProgramError::MissingRequiredSignature);
|
||||
}
|
||||
|
||||
// Update paused
|
||||
config.paused = args.paused as u32;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user