mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-16 23:16:47 +00:00
update tolerance
This commit is contained in:
@@ -18,7 +18,7 @@ use crate::{
|
||||
utils::AccountDeserialize,
|
||||
utils::Discriminator,
|
||||
BUS, BUS_COUNT, CONFIG, INITIAL_BASE_REWARD_RATE, INITIAL_TOLERANCE, METADATA, MINT,
|
||||
MINT_ADDRESS, MINT_NOISE, TOKEN_DECIMALS, TREASURY, TWO_YEARS,
|
||||
MINT_ADDRESS, MINT_NOISE, TOKEN_DECIMALS, TREASURY,
|
||||
};
|
||||
|
||||
/// Initialize sets up the Ore program. Its responsibilities include:
|
||||
|
||||
@@ -6,6 +6,7 @@ mod register;
|
||||
mod reset;
|
||||
mod stake;
|
||||
mod update_admin;
|
||||
mod update_tolerance;
|
||||
mod upgrade;
|
||||
|
||||
pub use claim::*;
|
||||
@@ -16,4 +17,5 @@ pub use register::*;
|
||||
pub use reset::*;
|
||||
pub use stake::*;
|
||||
pub use update_admin::*;
|
||||
pub use update_tolerance::*;
|
||||
pub use upgrade::*;
|
||||
|
||||
43
src/processor/update_tolerance.rs
Normal file
43
src/processor/update_tolerance.rs
Normal file
@@ -0,0 +1,43 @@
|
||||
use solana_program::{
|
||||
account_info::AccountInfo, entrypoint::ProgramResult, program_error::ProgramError,
|
||||
pubkey::Pubkey,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
error::OreError, instruction::UpdateToleranceArgs, loaders::*, state::Config,
|
||||
utils::AccountDeserialize,
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
// Update tolerances
|
||||
config.tolerance_liveness = args.tolerance_liveness as i64;
|
||||
config.tolerance_spam = args.tolerance_spam as i64;
|
||||
|
||||
// Sanity checks
|
||||
if config.tolerance_liveness.lt(&0) || config.tolerance_spam.lt(&0) {
|
||||
return Err(OreError::ToleranceNegative.into());
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user