-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from adm-metaex/penalties/block-the-clam-opera…
…tion [mtg-578] Add both restrict and allow claim instructions with tests
- Loading branch information
Showing
14 changed files
with
1,364 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
programs/mpl-staking/src/instructions/penalties/allow_tokenflow.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use super::Penalty; | ||
use crate::cpi_instructions; | ||
use anchor_lang::prelude::*; | ||
use mplx_staking_states::error::MplStakingError; | ||
|
||
/// Restricts claiming rewards from the specified mining account. | ||
pub fn allow_tokenflow(ctx: Context<Penalty>, mining_owner: Pubkey) -> Result<()> { | ||
let registrar = ctx.accounts.registrar.load()?; | ||
|
||
require_keys_eq!( | ||
registrar.realm_authority, | ||
ctx.accounts.realm_authority.key(), | ||
MplStakingError::InvalidRealmAuthority | ||
); | ||
|
||
let signers_seeds = &[ | ||
®istrar.realm.key().to_bytes(), | ||
b"registrar".as_ref(), | ||
®istrar.realm_governing_token_mint.key().to_bytes(), | ||
&[registrar.bump][..], | ||
]; | ||
|
||
cpi_instructions::allow_tokenflow( | ||
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(), | ||
&mining_owner, | ||
signers_seeds, | ||
)?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
pub use allow_tokenflow::*; | ||
use anchor_lang::{ | ||
prelude::{AccountLoader, Signer, ToAccountInfo, UncheckedAccount}, | ||
Accounts, | ||
}; | ||
pub use restrict_batch_minting::*; | ||
pub use restrict_tokenflow::*; | ||
|
||
mod allow_tokenflow; | ||
mod restrict_batch_minting; | ||
mod restrict_tokenflow; | ||
|
||
use mplx_staking_states::state::Registrar; | ||
|
||
#[derive(Accounts)] | ||
pub struct Penalty<'info> { | ||
pub registrar: AccountLoader<'info, Registrar>, | ||
|
||
pub realm_authority: Signer<'info>, | ||
|
||
/// CHECK: | ||
/// Ownership of the account will be checked in the rewards contract | ||
/// It's the core account for the rewards contract, which will | ||
/// keep track of all rewards and staking logic. | ||
pub reward_pool: UncheckedAccount<'info>, | ||
|
||
/// CHECK: mining PDA will be checked in the rewards contract | ||
/// PDA(["mining", mining owner <aka voter_authority in our case>, reward_pool], | ||
/// reward_program) | ||
#[account(mut)] | ||
pub deposit_mining: UncheckedAccount<'info>, | ||
|
||
/// CHECK: Rewards Program account | ||
#[account(executable)] | ||
pub rewards_program: UncheckedAccount<'info>, | ||
} |
38 changes: 38 additions & 0 deletions
38
programs/mpl-staking/src/instructions/penalties/restrict_batch_minting.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use super::Penalty; | ||
use crate::cpi_instructions; | ||
use anchor_lang::prelude::*; | ||
use mplx_staking_states::error::MplStakingError; | ||
|
||
/// Restricts batch minting operation for the account until the specified timestamp. | ||
pub fn restrict_batch_minting( | ||
ctx: Context<Penalty>, | ||
until_ts: u64, | ||
mining_owner: Pubkey, | ||
) -> Result<()> { | ||
let registrar = ctx.accounts.registrar.load()?; | ||
|
||
require_keys_eq!( | ||
registrar.realm_authority, | ||
ctx.accounts.realm_authority.key(), | ||
MplStakingError::InvalidRealmAuthority | ||
); | ||
|
||
let signers_seeds = &[ | ||
®istrar.realm.key().to_bytes(), | ||
b"registrar".as_ref(), | ||
®istrar.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(), | ||
&mining_owner, | ||
until_ts, | ||
signers_seeds, | ||
)?; | ||
|
||
Ok(()) | ||
} |
33 changes: 33 additions & 0 deletions
33
programs/mpl-staking/src/instructions/penalties/restrict_tokenflow.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use super::Penalty; | ||
use crate::cpi_instructions; | ||
use anchor_lang::prelude::*; | ||
use mplx_staking_states::error::MplStakingError; | ||
|
||
/// Restricts claiming rewards from the specified mining account. | ||
pub fn restrict_tokenflow(ctx: Context<Penalty>, mining_owner: Pubkey) -> Result<()> { | ||
let registrar = ctx.accounts.registrar.load()?; | ||
|
||
require_keys_eq!( | ||
registrar.realm_authority, | ||
ctx.accounts.realm_authority.key(), | ||
MplStakingError::InvalidRealmAuthority | ||
); | ||
|
||
let signers_seeds = &[ | ||
®istrar.realm.key().to_bytes(), | ||
b"registrar".as_ref(), | ||
®istrar.realm_governing_token_mint.key().to_bytes(), | ||
&[registrar.bump][..], | ||
]; | ||
|
||
cpi_instructions::restrict_tokenflow( | ||
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(), | ||
&mining_owner, | ||
signers_seeds, | ||
)?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Oops, something went wrong.