Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PROGRAM TWEAKS #52

Merged
merged 13 commits into from
Jun 28, 2024
10 changes: 6 additions & 4 deletions programs/steward/src/instructions/add_validator_to_blacklist.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
use crate::{utils::get_config_authority, Config};
use crate::{utils::get_config_blacklist_authority, Config};
use anchor_lang::prelude::*;

#[derive(Accounts)]
pub struct AddValidatorToBlacklist<'info> {
#[account(mut)]
pub config: AccountLoader<'info, Config>,

#[account(mut, address = get_config_authority(&config)?)]
#[account(mut, address = get_config_blacklist_authority(&config)?)]
pub authority: Signer<'info>,
}

// Removes ability for validator to receive delegation. Score will be set to 0 and instant unstaking will occur.
// Index is the index of the validator from ValidatorHistory.
pub fn handler(ctx: Context<AddValidatorToBlacklist>, validator_list_index: u32) -> Result<()> {
pub fn handler(ctx: Context<AddValidatorToBlacklist>, validator_history_index: u32) -> Result<()> {
let mut config = ctx.accounts.config.load_mut()?;
config.blacklist.set(validator_list_index as usize, true)?;
config
.validator_history_blacklist
.set(validator_history_index as usize, true)?;
Ok(())
}
19 changes: 5 additions & 14 deletions programs/steward/src/instructions/auto_add_validator_to_pool.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::constants::{MAX_VALIDATORS, STAKE_POOL_WITHDRAW_SEED};
use crate::errors::StewardError;
use crate::state::{Config, Staker, StewardStateAccount};
use crate::state::{Config, StewardStateAccount};
use crate::utils::{deserialize_stake_pool, get_stake_pool_address};
use anchor_lang::prelude::*;
use anchor_lang::solana_program::{program::invoke_signed, stake, sysvar, vote};
Expand Down Expand Up @@ -40,12 +40,6 @@ pub struct AutoAddValidator<'info> {
)]
pub stake_pool: AccountInfo<'info>,

#[account(
seeds = [Staker::SEED, config.key().as_ref()],
bump = staker.bump
)]
pub staker: Account<'info, Staker>,

/// CHECK: passing through, checks are done by spl-stake-pool
#[account(mut, address = deserialize_stake_pool(&stake_pool)?.reserve_stake)]
pub reserve_stake: AccountInfo<'info>,
Expand Down Expand Up @@ -98,9 +92,6 @@ pub struct AutoAddValidator<'info> {
/// CHECK: passing through, checks are done by spl-stake-pool
#[account(address = stake::program::ID)]
pub stake_program: AccountInfo<'info>,

#[account(mut)]
pub signer: Signer<'info>,
}

/*
Expand Down Expand Up @@ -160,7 +151,7 @@ pub fn handler(ctx: Context<AutoAddValidator>) -> Result<()> {
&spl_stake_pool::instruction::add_validator_to_pool(
&ctx.accounts.stake_pool_program.key(),
&ctx.accounts.stake_pool.key(),
&ctx.accounts.staker.key(),
&ctx.accounts.stake_account.key(),
&ctx.accounts.reserve_stake.key(),
&ctx.accounts.withdraw_authority.key(),
&ctx.accounts.validator_list.key(),
Expand All @@ -170,7 +161,7 @@ pub fn handler(ctx: Context<AutoAddValidator>) -> Result<()> {
),
&[
ctx.accounts.stake_pool.to_account_info(),
ctx.accounts.staker.to_account_info(),
ctx.accounts.stake_account.to_account_info(),
ctx.accounts.reserve_stake.to_owned(),
ctx.accounts.withdraw_authority.to_owned(),
ctx.accounts.validator_list.to_account_info(),
Expand All @@ -184,9 +175,9 @@ pub fn handler(ctx: Context<AutoAddValidator>) -> Result<()> {
ctx.accounts.stake_program.to_account_info(),
],
&[&[
Staker::SEED,
StewardStateAccount::SEED,
&ctx.accounts.config.key().to_bytes(),
&[ctx.accounts.staker.bump],
&[ctx.bumps.steward_state],
]],
)?;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::num::NonZeroU32;

use crate::constants::STAKE_POOL_WITHDRAW_SEED;
use crate::errors::StewardError;
use crate::state::{Config, Staker};
use crate::state::Config;
use crate::utils::{
deserialize_stake_pool, get_stake_pool_address, get_validator_stake_info_at_index,
};
Expand Down Expand Up @@ -46,12 +46,6 @@ pub struct AutoRemoveValidator<'info> {
)]
pub stake_pool: AccountInfo<'info>,

#[account(
seeds = [Staker::SEED, config.key().as_ref()],
bump = staker.bump
)]
pub staker: Account<'info, Staker>,

/// CHECK: passing through, checks are done by spl-stake-pool
#[account(mut, address = deserialize_stake_pool(&stake_pool)?.reserve_stake)]
pub reserve_stake: AccountInfo<'info>,
Expand Down Expand Up @@ -123,9 +117,6 @@ pub struct AutoRemoveValidator<'info> {
/// CHECK: passing through, checks are done by spl-stake-pool
#[account(address = stake::program::ID)]
pub stake_program: AccountInfo<'info>,

#[account(mut)]
pub signer: Signer<'info>,
}

/*
Expand Down Expand Up @@ -178,15 +169,15 @@ pub fn handler(ctx: Context<AutoRemoveValidator>, validator_list_index: usize) -
&spl_stake_pool::instruction::remove_validator_from_pool(
&ctx.accounts.stake_pool_program.key(),
&ctx.accounts.stake_pool.key(),
&ctx.accounts.staker.key(),
&ctx.accounts.state_account.key(),
&ctx.accounts.withdraw_authority.key(),
&ctx.accounts.validator_list.key(),
&ctx.accounts.stake_account.key(),
&ctx.accounts.transient_stake_account.key(),
),
&[
ctx.accounts.stake_pool.to_account_info(),
ctx.accounts.staker.to_account_info(),
ctx.accounts.state_account.to_account_info(),
ctx.accounts.reserve_stake.to_owned(),
ctx.accounts.withdraw_authority.to_owned(),
ctx.accounts.validator_list.to_account_info(),
Expand All @@ -201,9 +192,9 @@ pub fn handler(ctx: Context<AutoRemoveValidator>, validator_list_index: usize) -
ctx.accounts.stake_program.to_account_info(),
],
&[&[
Staker::SEED,
StewardStateAccount::SEED,
&ctx.accounts.config.key().to_bytes(),
&[ctx.accounts.staker.bump],
&[ctx.bumps.state_account],
]],
)?;

Expand Down
13 changes: 2 additions & 11 deletions programs/steward/src/instructions/close_steward_accounts.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
use crate::{
state::{Config, StewardStateAccount},
utils::get_config_authority,
Staker,
utils::get_config_admin,
};
use anchor_lang::prelude::*;

#[derive(Accounts)]
pub struct CloseStewardAccounts<'info> {
pub config: AccountLoader<'info, Config>,

#[account(
mut,
close = authority,
seeds = [Staker::SEED, config.key().as_ref()],
bump,
)]
staker: Account<'info, Staker>,

#[account(
mut,
close = authority,
Expand All @@ -25,7 +16,7 @@ pub struct CloseStewardAccounts<'info> {
)]
pub state_account: AccountLoader<'info, StewardStateAccount>,

#[account(mut, address = get_config_authority(&config)?)]
#[account(mut, address = get_config_admin(&config)?)]
pub authority: Signer<'info>,
}

Expand Down
3 changes: 0 additions & 3 deletions programs/steward/src/instructions/compute_delegations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ pub struct ComputeDelegations<'info> {
bump
)]
pub state_account: AccountLoader<'info, StewardStateAccount>,

#[account(mut)]
pub signer: Signer<'info>,
}

/*
Expand Down
11 changes: 5 additions & 6 deletions programs/steward/src/instructions/compute_instant_unstake.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::{
errors::StewardError, maybe_transition_and_emit, utils::get_validator_stake_info_at_index,
errors::StewardError,
maybe_transition_and_emit,
utils::{get_validator_list, get_validator_stake_info_at_index},
Config, StewardStateAccount,
};
use anchor_lang::prelude::*;
Expand All @@ -18,8 +20,8 @@ pub struct ComputeInstantUnstake<'info> {

pub validator_history: AccountLoader<'info, ValidatorHistory>,

/// CHECK: TODO add validator list to config
#[account(owner = spl_stake_pool::id())]
#[account(address = get_validator_list(&config)?)]
/// CHECK: We check against the Config
pub validator_list: AccountInfo<'info>,

#[account(
Expand All @@ -28,9 +30,6 @@ pub struct ComputeInstantUnstake<'info> {
bump
)]
pub cluster_history: AccountLoader<'info, ClusterHistory>,

#[account(mut)]
pub signer: Signer<'info>,
}

pub fn handler(ctx: Context<ComputeInstantUnstake>, validator_list_index: usize) -> Result<()> {
Expand Down
7 changes: 2 additions & 5 deletions programs/steward/src/instructions/compute_score.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use anchor_lang::prelude::*;
use crate::{
errors::StewardError,
maybe_transition_and_emit,
utils::{get_validator_list_length, get_validator_stake_info_at_index},
utils::{get_validator_list, get_validator_list_length, get_validator_stake_info_at_index},
Config, StewardStateAccount, StewardStateEnum,
};
use validator_history::{ClusterHistory, ValidatorHistory};
Expand All @@ -22,7 +22,7 @@ pub struct ComputeScore<'info> {
pub validator_history: AccountLoader<'info, ValidatorHistory>,

/// CHECK: Account owner checked, account type checked in get_validator_stake_info_at_index
#[account(owner = spl_stake_pool::id())]
#[account(address = get_validator_list(&config)?)]
pub validator_list: AccountInfo<'info>,

#[account(
Expand All @@ -31,9 +31,6 @@ pub struct ComputeScore<'info> {
bump
)]
pub cluster_history: AccountLoader<'info, ClusterHistory>,

#[account(mut)]
pub signer: Signer<'info>,
}

pub fn handler(ctx: Context<ComputeScore>, validator_list_index: usize) -> Result<()> {
Expand Down
10 changes: 5 additions & 5 deletions programs/steward/src/instructions/epoch_maintenance.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::{
errors::StewardError,
utils::{
check_validator_list_has_stake_status, deserialize_stake_pool, get_stake_pool_address,
get_validator_list_length,
check_validator_list_has_stake_status_other_than, deserialize_stake_pool,
get_stake_pool_address, get_validator_list_length,
},
Config, StewardStateAccount,
};
Expand Down Expand Up @@ -51,12 +51,13 @@ pub fn handler(
if (!state_account.state.checked_validators_removed_from_list).into() {
// Ensure there are no validators in the list that have not been removed, that should be
require!(
!check_validator_list_has_stake_status(
!check_validator_list_has_stake_status_other_than(
&ctx.accounts.validator_list,
StakeStatus::ReadyForRemoval
StakeStatus::Active
)?,
StewardError::ValidatorsHaveNotBeenRemoved
);

state_account.state.checked_validators_removed_from_list = true.into();
}

Expand All @@ -74,7 +75,6 @@ pub fn handler(
== validators_in_list,
StewardError::ListStateMismatch
);

if let Some(validator_index_to_remove) = validator_index_to_remove {
state_account
.state
Expand Down
3 changes: 0 additions & 3 deletions programs/steward/src/instructions/idle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ pub struct Idle<'info> {
bump
)]
pub state_account: AccountLoader<'info, StewardStateAccount>,

#[account(mut)]
pub signer: Signer<'info>,
}

/*
Expand Down
32 changes: 0 additions & 32 deletions programs/steward/src/instructions/initialize_state.rs

This file was deleted.

Loading