remove admin stuff

This commit is contained in:
Hardhat Chad
2024-06-24 16:55:23 +00:00
parent 0b57e5bba4
commit dfc24e5c46
8 changed files with 10 additions and 115 deletions

View File

@@ -5,7 +5,6 @@ use solana_program::{
entrypoint::ProgramResult,
program_error::ProgramError,
program_pack::Pack,
pubkey,
pubkey::Pubkey,
system_program, {self, sysvar},
};
@@ -18,13 +17,10 @@ use crate::{
utils::create_pda,
utils::AccountDeserialize,
utils::Discriminator,
BUS, BUS_COUNT, CONFIG, INITIAL_BASE_REWARD_RATE, INITIAL_TOLERANCE, METADATA, METADATA_NAME,
BUS, BUS_COUNT, CONFIG, INITIAL_ADMIN, INITIAL_BASE_REWARD_RATE, METADATA, METADATA_NAME,
METADATA_SYMBOL, METADATA_URI, MINT, MINT_ADDRESS, MINT_NOISE, TOKEN_DECIMALS, TREASURY,
};
/// The address to allow for initialization.
const AUTHORIZED_INITIALIZER: Pubkey = pubkey!("HBUh9g46wk2X89CvaNN15UmsznP59rh6od1h8JwYAopk");
/// Initialize sets up the Ore program. Its responsibilities include:
/// 1. Initialize the 8 bus accounts.
/// 2. Initialize the treasury account.
@@ -92,7 +88,7 @@ pub fn process_initialize<'a, 'info>(
load_sysvar(rent_sysvar, sysvar::rent::id())?;
// Check signer
if signer.key.ne(&AUTHORIZED_INITIALIZER) {
if signer.key.ne(&INITIAL_ADMIN) {
return Err(ProgramError::MissingRequiredSignature);
}
@@ -143,8 +139,6 @@ pub fn process_initialize<'a, 'info>(
config.base_reward_rate = INITIAL_BASE_REWARD_RATE;
config.last_reset_at = 0;
config.paused = 1;
config.tolerance_liveness = INITIAL_TOLERANCE;
config.tolerance_spam = INITIAL_TOLERANCE;
// Initialize treasury
create_pda(

View File

@@ -24,7 +24,7 @@ use crate::{
loaders::*,
state::{Bus, Config, Proof},
utils::{AccountDeserialize, MineEvent},
EPOCH_DURATION, MIN_DIFFICULTY, ONE_MINUTE, ONE_YEAR,
EPOCH_DURATION, MIN_DIFFICULTY, ONE_MINUTE, ONE_YEAR, TOLERANCE,
};
/// Mine is the primary workhorse instruction of the Ore program. Its responsibilities include:
@@ -128,14 +128,14 @@ pub fn process_mine<'a, 'info>(
// Apply spam penalty
let t = clock.unix_timestamp;
let t_target = proof.last_hash_at.saturating_add(ONE_MINUTE);
let t_spam = t_target.saturating_sub(config.tolerance_spam);
let t_spam = t_target.saturating_sub(TOLERANCE);
if t.lt(&t_spam) {
sol_log("Spam penalty");
return Err(OreError::Spam.into());
}
// Apply liveness penalty
let t_liveness = t_target.saturating_add(config.tolerance_liveness);
let t_liveness = t_target.saturating_add(TOLERANCE);
if t.gt(&t_liveness) {
reward = reward.saturating_sub(
reward

View File

@@ -7,7 +7,6 @@ mod register;
mod reset;
mod stake;
mod update_admin;
mod update_tolerance;
mod upgrade;
pub use claim::*;
@@ -19,5 +18,4 @@ pub use register::*;
pub use reset::*;
pub use stake::*;
pub use update_admin::*;
pub use update_tolerance::*;
pub use upgrade::*;

View File

@@ -1,54 +0,0 @@
use solana_program::{
account_info::AccountInfo, entrypoint::ProgramResult, program_error::ProgramError,
pubkey::Pubkey,
};
use crate::{
error::OreError, instruction::UpdateToleranceArgs, loaders::*, state::Config,
utils::AccountDeserialize, ONE_MINUTE,
};
/// UpdateTolerance updates the program's tolerance settings. Its responsibilities include:
/// 1. Update the liveness tolerance.
/// 2. Update the spam tolerance.
///
/// Safety requirements:
/// - Can only succeed if the signer is the program admin.
/// - Can only succeed if the provided config is valid.
/// - Can only succeed if the tolerances pass sanity tests.
pub fn process_update_tolerance<'a, 'info>(
_program_id: &Pubkey,
accounts: &'a [AccountInfo<'info>],
data: &[u8],
) -> ProgramResult {
// Parse args
let args = UpdateToleranceArgs::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);
}
// Sanity checks
if args.tolerance_liveness.ge(&(ONE_MINUTE as u64)) {
return Err(OreError::ToleranceOverflow.into());
}
if args.tolerance_spam.ge(&(ONE_MINUTE as u64)) {
return Err(OreError::ToleranceOverflow.into());
}
// Update tolerances
config.tolerance_liveness = args.tolerance_liveness as i64;
config.tolerance_spam = args.tolerance_spam as i64;
Ok(())
}