mirror of
https://github.com/d0zingcat/ore.git
synced 2026-06-07 15:11:33 +00:00
Disallow closing the top stake account
This commit is contained in:
@@ -23,6 +23,10 @@ pub enum OreError {
|
|||||||
ToleranceOverflow = 7,
|
ToleranceOverflow = 7,
|
||||||
#[error("The maximum supply has been reached")]
|
#[error("The maximum supply has been reached")]
|
||||||
MaxSupply = 8,
|
MaxSupply = 8,
|
||||||
|
#[error("This account cannot be closed because it's the top staker")]
|
||||||
|
CannotClose = 9,
|
||||||
|
#[error("This account cannot be crowned because its last stake was too recent")]
|
||||||
|
CannotCrown = 10,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<OreError> for ProgramError {
|
impl From<OreError> for ProgramError {
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
use ore_api::{loaders::*, state::Proof};
|
use ore_api::{
|
||||||
|
error::OreError,
|
||||||
|
loaders::*,
|
||||||
|
state::{Config, Proof},
|
||||||
|
};
|
||||||
use solana_program::{
|
use solana_program::{
|
||||||
account_info::AccountInfo, entrypoint::ProgramResult, program_error::ProgramError,
|
account_info::AccountInfo, entrypoint::ProgramResult, program_error::ProgramError,
|
||||||
pubkey::Pubkey, system_program,
|
pubkey::Pubkey, system_program,
|
||||||
@@ -20,13 +24,21 @@ pub fn process_close<'a, 'info>(
|
|||||||
_data: &[u8],
|
_data: &[u8],
|
||||||
) -> ProgramResult {
|
) -> ProgramResult {
|
||||||
// Load accounts
|
// Load accounts
|
||||||
let [signer, proof_info, system_program] = accounts else {
|
let [signer, config_info, proof_info, system_program] = accounts else {
|
||||||
return Err(ProgramError::NotEnoughAccountKeys);
|
return Err(ProgramError::NotEnoughAccountKeys);
|
||||||
};
|
};
|
||||||
load_signer(signer)?;
|
load_signer(signer)?;
|
||||||
|
load_config(config_info, false)?;
|
||||||
load_proof(proof_info, signer.key, true)?;
|
load_proof(proof_info, signer.key, true)?;
|
||||||
load_program(system_program, system_program::id())?;
|
load_program(system_program, system_program::id())?;
|
||||||
|
|
||||||
|
// Validate the account is not the crowned top staker.
|
||||||
|
let config_data = config_info.data.borrow();
|
||||||
|
let config = Config::try_from_bytes(&config_data)?;
|
||||||
|
if config.top_staker.eq(proof_info.key) {
|
||||||
|
return Err(OreError::CannotClose.into());
|
||||||
|
}
|
||||||
|
|
||||||
// Validate balance is zero
|
// Validate balance is zero
|
||||||
let proof_data = proof_info.data.borrow();
|
let proof_data = proof_info.data.borrow();
|
||||||
let proof = Proof::try_from_bytes(&proof_data)?;
|
let proof = Proof::try_from_bytes(&proof_data)?;
|
||||||
|
|||||||
Reference in New Issue
Block a user