Skip to content

Commit

Permalink
make linter happy && small renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
kstepanovdev committed Aug 30, 2024
1 parent 94c1bf7 commit f32a952
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use super::Penalty;
use crate::cpi_instructions;
use anchor_lang::prelude::*;
use mplx_staking_states::error::MplStakingError;

use super::ClaimingAllowance;

/// Restricts claiming rewards from the specified mining account.
pub fn allow_claiming<'info>(ctx: Context<ClaimingAllowance>) -> Result<()> {
pub fn allow_claiming(ctx: Context<Penalty>) -> Result<()> {
let registrar = ctx.accounts.registrar.load()?;

require_keys_eq!(
Expand Down
5 changes: 2 additions & 3 deletions programs/mpl-staking/src/instructions/penalties/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
pub use allow_claiming::*;
use anchor_lang::{
prelude::{AccountLoader, Signer, ToAccountInfo, UncheckedAccount},
Accounts,
};

pub use allow_claiming::*;
pub use restrict_claiming::*;

mod allow_claiming;
Expand All @@ -12,7 +11,7 @@ mod restrict_claiming;
use mplx_staking_states::state::Registrar;

#[derive(Accounts)]
pub struct ClaimingAllowance<'info> {
pub struct Penalty<'info> {
pub registrar: AccountLoader<'info, Registrar>,

pub realm_authority: Signer<'info>,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use crate::cpi_instructions;
use anchor_lang::prelude::*;
use mplx_staking_states::error::MplStakingError;

use super::Penalty;

/// Restricts claiming rewards from the specified mining account.
pub fn restrict_batch_minting<'info>(ctx: Context<Penalty>, until_ts: u64) -> Result<()> {
let registrar = ctx.accounts.registrar.load()?;

require_keys_eq!(
registrar.realm_authority,
ctx.accounts.realm_authority.key(),
MplStakingError::InvalidRealmAuthority
);

let signers_seeds = &[
&registrar.realm.key().to_bytes(),
b"registrar".as_ref(),
&registrar.realm_governing_token_mint.key().to_bytes(),
&[registrar.bump][..],
];

cpi_instructions::restrict_batch_minting(
ctx.accounts.rewards_program.to_account_info(),
ctx.accounts.registrar.to_account_info(),
ctx.accounts.reward_pool.to_account_info(),
ctx.accounts.deposit_mining.to_account_info(),
until_ts,
signers_seeds,
)?;

Ok(())
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use super::Penalty;
use crate::cpi_instructions;
use anchor_lang::prelude::*;
use mplx_staking_states::error::MplStakingError;

use super::ClaimingAllowance;

/// Restricts claiming rewards from the specified mining account.
pub fn restrict_claiming<'info>(ctx: Context<ClaimingAllowance>) -> Result<()> {
pub fn restrict_claiming(ctx: Context<Penalty>) -> Result<()> {
let registrar = ctx.accounts.registrar.load()?;

require_keys_eq!(
Expand Down
4 changes: 2 additions & 2 deletions programs/mpl-staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,11 @@ pub mod mpl_staking {
instructions::change_delegate(ctx, deposit_entry_index)
}

pub fn restrict_claiming(ctx: Context<ClaimingAllowance>) -> Result<()> {
pub fn restrict_claiming(ctx: Context<Penalty>) -> Result<()> {
instructions::restrict_claiming(ctx)
}

pub fn allow_claiming(ctx: Context<ClaimingAllowance>) -> Result<()> {
pub fn allow_claiming(ctx: Context<Penalty>) -> Result<()> {
instructions::allow_claiming(ctx)
}
}
Expand Down
4 changes: 2 additions & 2 deletions programs/mpl-staking/tests/program_test/addin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ impl AddinCookie {
let data = InstructionData::data(&mpl_staking::instruction::RestrictClaiming {});

let accounts = anchor_lang::ToAccountMetas::to_account_metas(
&mpl_staking::accounts::ClaimingAllowance {
&mpl_staking::accounts::Penalty {
registrar: registrar.address,
realm_authority: realm_authority.pubkey(),
reward_pool: *reward_pool,
Expand Down Expand Up @@ -804,7 +804,7 @@ impl AddinCookie {
let data = InstructionData::data(&mpl_staking::instruction::AllowClaiming {});

let accounts = anchor_lang::ToAccountMetas::to_account_metas(
&mpl_staking::accounts::ClaimingAllowance {
&mpl_staking::accounts::Penalty {
registrar: registrar.address,
realm_authority: realm_authority.pubkey(),
reward_pool: *reward_pool,
Expand Down

0 comments on commit f32a952

Please sign in to comment.