remove all admin functions

This commit is contained in:
Hardhat Chad
2024-06-24 21:08:33 +00:00
parent dfc24e5c46
commit 4ce510cfa2
10 changed files with 11 additions and 181 deletions

View File

@@ -5,26 +5,24 @@ use thiserror::Error;
#[derive(Debug, Error, Clone, Copy, PartialEq, Eq, IntoPrimitive)]
#[repr(u32)]
pub enum OreError {
#[error("Mining is paused")]
IsPaused = 0,
#[error("The epoch has ended and needs reset")]
NeedsReset = 1,
NeedsReset = 0,
#[error("The provided hash is invalid")]
HashInvalid = 2,
HashInvalid = 1,
#[error("The provided hash did not satisfy the minimum required difficulty")]
HashTooEasy = 3,
HashTooEasy = 2,
#[error("The claim amount cannot be greater than the claimable rewards")]
ClaimTooLarge = 4,
ClaimTooLarge = 3,
#[error("The clock time is invalid")]
ClockInvalid = 5,
ClockInvalid = 4,
#[error("You are trying to submit too soon")]
Spam = 6,
Spam = 5,
#[error("Only one hash may be validated per transaction")]
TransactionInvalid = 7,
TransactionInvalid = 6,
#[error("The tolerance cannot exceed i64 max value")]
ToleranceOverflow = 8,
ToleranceOverflow = 7,
#[error("The maximum supply has been reached")]
MaxSupply = 9,
MaxSupply = 8,
}
impl From<OreError> for ProgramError {

View File

@@ -103,16 +103,6 @@ pub enum OreInstruction {
#[account(18, name = "mpl_metadata_program", desc = "Metaplex metadata program")]
#[account(19, name = "rent", desc = "Solana rent sysvar")]
Initialize = 100,
#[account(0, name = "ore_program", desc = "Ore program")]
#[account(1, name = "signer", desc = "Admin signer", signer)]
#[account(2, name = "config", desc = "Ore config account", writable)]
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", writable)]
Pause = 103,
}
impl OreInstruction {
@@ -187,8 +177,6 @@ impl_to_bytes!(MineArgs);
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);
@@ -196,8 +184,6 @@ impl_instruction_from_bytes!(MineArgs);
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 {
@@ -414,39 +400,3 @@ pub fn initialize(signer: Pubkey) -> Instruction {
.concat(),
}
}
/// 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(CONFIG_ADDRESS, false),
],
data: [
OreInstruction::UpdateAdmin.to_vec(),
UpdateAdminArgs { new_admin }.to_bytes().to_vec(),
]
.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(),
}
}

View File

@@ -41,8 +41,6 @@ pub fn process_instruction(
OreInstruction::Stake => process_stake(program_id, accounts, data)?,
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(())

View File

@@ -138,7 +138,6 @@ pub fn process_initialize<'a, 'info>(
config.admin = *signer.key;
config.base_reward_rate = INITIAL_BASE_REWARD_RATE;
config.last_reset_at = 0;
config.paused = 1;
// Initialize treasury
create_pda(

View File

@@ -66,14 +66,9 @@ pub fn process_mine<'a, 'info>(
return Err(OreError::TransactionInvalid.into());
}
// Validate mining is not paused
// Validate epoch is active
let config_data = config_info.data.borrow();
let config = Config::try_from_bytes(&config_data)?;
if config.paused.ne(&0) {
return Err(OreError::IsPaused.into());
}
// Validate epoch is active
let clock = Clock::get().or(Err(ProgramError::InvalidAccountData))?;
if config
.last_reset_at

View File

@@ -2,20 +2,16 @@ mod claim;
mod deregister;
mod initialize;
mod mine;
mod pause;
mod register;
mod reset;
mod stake;
mod update_admin;
mod upgrade;
pub use claim::*;
pub use deregister::*;
pub use initialize::*;
pub use mine::*;
pub use pause::*;
pub use register::*;
pub use reset::*;
pub use stake::*;
pub use update_admin::*;
pub use upgrade::*;

View File

@@ -1,44 +0,0 @@
use solana_program::{
account_info::AccountInfo, entrypoint::ProgramResult, program_error::ProgramError,
pubkey::Pubkey,
};
use crate::{instruction::PauseArgs, loaders::*, state::Config, utils::AccountDeserialize};
/// Pause updates the program's pause flag. Its responsibilities include:
/// 1. Update the pause flag.
///
/// Safety requirements:
/// - Can only succeed if the signer is the program admin.
/// - Can only succeed if the provided config is valid.
///
/// Discussion:
/// - This should only be used to address critical contract risks and force migration to a new
/// verison (hardfork).
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 u64;
Ok(())
}

View File

@@ -70,14 +70,9 @@ pub fn process_reset<'a, 'info>(
bus_7_info,
];
// Validate mining is not paused
// Validate enough time has passed since last reset
let mut config_data = config_info.data.borrow_mut();
let config = Config::try_from_bytes_mut(&mut config_data)?;
if config.paused.ne(&0) {
return Err(OreError::IsPaused.into());
}
// Validate enough time has passed since last reset
let clock = Clock::get().or(Err(ProgramError::InvalidAccountData))?;
if config
.last_reset_at

View File

@@ -1,54 +0,0 @@
use solana_program::{
account_info::AccountInfo, entrypoint::ProgramResult, program_error::ProgramError,
pubkey::Pubkey,
};
use crate::{instruction::UpdateAdminArgs, loaders::*, state::Config, utils::AccountDeserialize};
/// UpdateAdmin updates the program's admin account. Its responsibilities include:
/// 1. Update the treasury admin address.
///
/// Safety requirements:
/// - Can only succeed if the signer is the program admin.
/// - Can only succeed if the provided treasury is valid.
///
/// Discussion:
/// - The admin authority has one lever of power: the ability to adjust the global
/// mining difficulty. If the difficulty is too easy, miners will find hashes very quickly
/// and the bottleneck for mining will shift from local compute to Solana bandwidth. In essence,
/// if the Ore token has value and difficulty is low, mining becomes an incentivized stress
/// test for the Solana network.
/// - At the same time, if difficulty is too hard, miners will have to wait a very long period
/// of time between finding valid hashes. This will bias rewards to well-resourced miners
/// with large compute operations. Keeping a low difficulty ensures casual miners can
/// consistently earn rewards and undercuts some of the advantage of larger players.
/// - Ultimately admin authority should be delegated to a governance mechanism either
/// democratic or futarchic to ensure difficulty is kept at a value that represents the
/// values and interests of the ecosystem.
pub fn process_update_admin<'a, 'info>(
_program_id: &Pubkey,
accounts: &'a [AccountInfo<'info>],
data: &[u8],
) -> ProgramResult {
// Parse args
let args = UpdateAdminArgs::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 admin
config.admin = args.new_admin;
Ok(())
}

View File

@@ -19,9 +19,6 @@ pub struct Config {
/// The timestamp of the last reset
pub last_reset_at: i64,
/// Is mining paused.
pub paused: u64,
}
impl Discriminator for Config {