diff --git a/programs/rewards/src/error.rs b/programs/rewards/src/error.rs index b1d46f19..be8c4545 100644 --- a/programs/rewards/src/error.rs +++ b/programs/rewards/src/error.rs @@ -80,6 +80,16 @@ pub enum MplxRewardsError { /// Account is already initialized #[error("Account is already initialized")] AlreadyInitialized, + + /// 19 + /// Incorrect mining address. + #[error("Invalid mining")] + InvalidMining, + + /// 20 + /// Failed to derive PDA. + #[error("Failed to derive PDA")] + DerivationError, } impl PrintProgramError for MplxRewardsError { diff --git a/programs/rewards/src/instruction.rs b/programs/rewards/src/instruction.rs index 9ee6f9a8..a1c6954d 100644 --- a/programs/rewards/src/instruction.rs +++ b/programs/rewards/src/instruction.rs @@ -65,6 +65,7 @@ pub enum RewardsInstruction { lockup_period: LockupPeriod, /// Specifies the owner of the Mining Account mining_owner: Pubkey, + delegate: Pubkey, }, /// Withdraws amount of supply to the mining account @@ -77,6 +78,7 @@ pub enum RewardsInstruction { amount: u64, /// Specifies the owner of the Mining Account mining_owner: Pubkey, + delegate: Pubkey, }, /// Claims amount of rewards @@ -113,6 +115,8 @@ pub enum RewardsInstruction { additional_amount: u64, /// The wallet who owns the mining account mining_owner: Pubkey, + /// Wallet addres of delegate + delegate: Pubkey, }, /// Distributes tokens among mining owners @@ -138,6 +142,7 @@ pub enum RewardsInstruction { ChangeDelegate { /// Amount of staked tokens staked_amount: u64, + new_delegate: Pubkey, }, } @@ -240,6 +245,7 @@ pub fn deposit_mining( amount: u64, lockup_period: LockupPeriod, mining_owner: &Pubkey, + delegate: &Pubkey, ) -> Instruction { let accounts = vec![ AccountMeta::new(*reward_pool, false), @@ -254,12 +260,14 @@ pub fn deposit_mining( amount, lockup_period, mining_owner: *mining_owner, + delegate: *delegate, }, accounts, ) } /// Creates 'WithdrawMining' instruction. +#[allow(clippy::too_many_arguments)] pub fn withdraw_mining( program_id: &Pubkey, reward_pool: &Pubkey, @@ -268,6 +276,7 @@ pub fn withdraw_mining( delegate_mining: &Pubkey, amount: u64, mining_owner: &Pubkey, + delegate: &Pubkey, ) -> Instruction { let accounts = vec![ AccountMeta::new(*reward_pool, false), @@ -281,6 +290,7 @@ pub fn withdraw_mining( &RewardsInstruction::WithdrawMining { amount, mining_owner: *mining_owner, + delegate: *delegate, }, accounts, ) @@ -326,6 +336,7 @@ pub fn extend_stake( base_amount: u64, additional_amount: u64, mining_owner: &Pubkey, + delegate: &Pubkey, ) -> Instruction { let accounts = vec![ AccountMeta::new(*reward_pool, false), @@ -343,6 +354,7 @@ pub fn extend_stake( base_amount, additional_amount, mining_owner: *mining_owner, + delegate: *delegate, }, accounts, ) @@ -398,6 +410,7 @@ pub fn change_delegate( mining_owner: &Pubkey, old_delegate_mining: &Pubkey, new_delegate_mining: &Pubkey, + new_delegate: &Pubkey, staked_amount: u64, ) -> Instruction { let accounts = vec![ @@ -411,7 +424,10 @@ pub fn change_delegate( Instruction::new_with_borsh( *program_id, - &RewardsInstruction::ChangeDelegate { staked_amount }, + &RewardsInstruction::ChangeDelegate { + staked_amount, + new_delegate: *new_delegate, + }, accounts, ) } diff --git a/programs/rewards/src/instructions/change_delegate.rs b/programs/rewards/src/instructions/change_delegate.rs index b88584fb..2993c686 100644 --- a/programs/rewards/src/instructions/change_delegate.rs +++ b/programs/rewards/src/instructions/change_delegate.rs @@ -1,7 +1,7 @@ use crate::{ asserts::assert_and_get_pool_and_mining, error::MplxRewardsError, - utils::{get_delegate_mining, AccountLoader}, + utils::{get_delegate_mining, verify_delegate_mining_address, AccountLoader}, }; use solana_program::{account_info::AccountInfo, entrypoint::ProgramResult, pubkey::Pubkey}; @@ -9,6 +9,7 @@ pub fn process_change_delegate<'a>( program_id: &Pubkey, accounts: &'a [AccountInfo<'a>], staked_amount: u64, + new_delegate: &Pubkey, ) -> ProgramResult { let account_info_iter = &mut accounts.iter().enumerate(); @@ -37,6 +38,15 @@ pub fn process_change_delegate<'a>( )?; let new_delegate_mining = get_delegate_mining(new_delegate_mining, mining)?; + if let Some(new_delegate_mining) = new_delegate_mining { + verify_delegate_mining_address( + program_id, + new_delegate_mining, + new_delegate, + reward_pool.key, + )? + } + let old_delegate_mining = get_delegate_mining(old_delegate_mining, mining)?; wrapped_reward_pool.change_delegate( diff --git a/programs/rewards/src/instructions/deposit_mining.rs b/programs/rewards/src/instructions/deposit_mining.rs index fbca8b4d..be3d3d8d 100644 --- a/programs/rewards/src/instructions/deposit_mining.rs +++ b/programs/rewards/src/instructions/deposit_mining.rs @@ -1,6 +1,6 @@ use crate::{ asserts::assert_and_get_pool_and_mining, - utils::{get_delegate_mining, AccountLoader, LockupPeriod}, + utils::{get_delegate_mining, verify_delegate_mining_address, AccountLoader, LockupPeriod}, }; use solana_program::{account_info::AccountInfo, entrypoint::ProgramResult, pubkey::Pubkey}; @@ -10,6 +10,7 @@ pub fn process_deposit_mining<'a>( amount: u64, lockup_period: LockupPeriod, mining_owner: &Pubkey, + delegate: &Pubkey, ) -> ProgramResult { let account_info_iter = &mut accounts.iter().enumerate(); @@ -32,6 +33,9 @@ pub fn process_deposit_mining<'a>( )?; let delegate_mining = get_delegate_mining(delegate_mining, mining)?; + if let Some(delegate_mining) = delegate_mining { + verify_delegate_mining_address(program_id, delegate_mining, delegate, reward_pool.key)? + } wrapped_reward_pool.deposit(&mut wrapped_mining, amount, lockup_period, delegate_mining)?; diff --git a/programs/rewards/src/instructions/extend_stake.rs b/programs/rewards/src/instructions/extend_stake.rs index 36be3f40..a1640dd2 100644 --- a/programs/rewards/src/instructions/extend_stake.rs +++ b/programs/rewards/src/instructions/extend_stake.rs @@ -1,6 +1,6 @@ use crate::{ asserts::assert_and_get_pool_and_mining, - utils::{get_delegate_mining, AccountLoader, LockupPeriod}, + utils::{get_delegate_mining, verify_delegate_mining_address, AccountLoader, LockupPeriod}, }; use solana_program::{account_info::AccountInfo, entrypoint::ProgramResult, pubkey::Pubkey}; @@ -14,6 +14,7 @@ pub fn process_extend_stake<'a>( base_amount: u64, additional_amount: u64, mining_owner: &Pubkey, + delegate: &Pubkey, ) -> ProgramResult { let account_info_iter = &mut accounts.iter().enumerate(); @@ -37,6 +38,10 @@ pub fn process_extend_stake<'a>( let delegate_mining = get_delegate_mining(delegate_mining, mining)?; + if let Some(delegate_mining) = delegate_mining { + verify_delegate_mining_address(program_id, delegate_mining, delegate, reward_pool.key)? + } + wrapped_reward_pool.extend( &mut wrapped_mining, old_lockup_period, diff --git a/programs/rewards/src/instructions/mod.rs b/programs/rewards/src/instructions/mod.rs index 8cefba92..c5b8ecd2 100644 --- a/programs/rewards/src/instructions/mod.rs +++ b/programs/rewards/src/instructions/mod.rs @@ -55,16 +55,25 @@ pub fn process_instruction<'a>( amount, lockup_period, mining_owner, + delegate, } => { msg!("RewardsInstruction: DepositMining"); - process_deposit_mining(program_id, accounts, amount, lockup_period, &mining_owner) + process_deposit_mining( + program_id, + accounts, + amount, + lockup_period, + &mining_owner, + &delegate, + ) } RewardsInstruction::WithdrawMining { amount, mining_owner, + delegate, } => { msg!("RewardsInstruction: WithdrawMining"); - process_withdraw_mining(program_id, accounts, amount, &mining_owner) + process_withdraw_mining(program_id, accounts, amount, &mining_owner, &delegate) } RewardsInstruction::Claim => { msg!("RewardsInstruction: Claim"); @@ -77,6 +86,7 @@ pub fn process_instruction<'a>( base_amount, additional_amount, mining_owner, + delegate, } => { msg!("RewardsInstruction: ExtendStake"); process_extend_stake( @@ -88,6 +98,7 @@ pub fn process_instruction<'a>( base_amount, additional_amount, &mining_owner, + &delegate, ) } RewardsInstruction::DistributeRewards => { @@ -98,9 +109,12 @@ pub fn process_instruction<'a>( msg!("RewardsInstruction: CloseAccount"); process_close_mining(program_id, accounts) } - RewardsInstruction::ChangeDelegate { staked_amount } => { + RewardsInstruction::ChangeDelegate { + staked_amount, + new_delegate, + } => { msg!("RewardsInstruction: ChangeDelegate"); - process_change_delegate(program_id, accounts, staked_amount) + process_change_delegate(program_id, accounts, staked_amount, &new_delegate) } } } diff --git a/programs/rewards/src/instructions/withdraw_mining.rs b/programs/rewards/src/instructions/withdraw_mining.rs index 17aa13b9..d9f88993 100644 --- a/programs/rewards/src/instructions/withdraw_mining.rs +++ b/programs/rewards/src/instructions/withdraw_mining.rs @@ -3,6 +3,7 @@ use crate::{ utils::{get_delegate_mining, AccountLoader}, }; +use crate::utils::verify_delegate_mining_address; use solana_program::{account_info::AccountInfo, entrypoint::ProgramResult, pubkey::Pubkey}; pub fn process_withdraw_mining<'a>( @@ -10,6 +11,7 @@ pub fn process_withdraw_mining<'a>( accounts: &'a [AccountInfo<'a>], amount: u64, mining_owner: &Pubkey, + delegate: &Pubkey, ) -> ProgramResult { let account_info_iter = &mut accounts.iter().enumerate(); @@ -32,6 +34,9 @@ pub fn process_withdraw_mining<'a>( )?; let delegate_mining = get_delegate_mining(delegate_mining, mining)?; + if let Some(delegate_mining) = delegate_mining { + verify_delegate_mining_address(program_id, delegate_mining, delegate, reward_pool.key)? + } wrapped_reward_pool.withdraw(&mut wrapped_mining, amount, delegate_mining)?; diff --git a/programs/rewards/src/utils.rs b/programs/rewards/src/utils.rs index 255984ea..5bd2c415 100644 --- a/programs/rewards/src/utils.rs +++ b/programs/rewards/src/utils.rs @@ -1,7 +1,7 @@ //! Arbitrary auxilliary functions use std::iter::Enumerate; -use crate::error::MplxRewardsError; +use crate::{error::MplxRewardsError, state::WrappedImmutableMining}; use borsh::{BorshDeserialize, BorshSerialize}; use solana_program::{ account_info::AccountInfo, @@ -11,7 +11,7 @@ use solana_program::{ program::{invoke, invoke_signed}, program_error::ProgramError, program_pack::Pack, - pubkey::Pubkey, + pubkey::{Pubkey, PubkeyError}, rent::Rent, system_instruction, sysvar::Sysvar, @@ -118,6 +118,29 @@ pub fn get_delegate_mining<'a, 'b>( } } +pub fn verify_delegate_mining_address( + program_id: &Pubkey, + delegate_mining: &AccountInfo<'_>, + delegate: &Pubkey, + reward_pool_key: &Pubkey, +) -> Result<(), ProgramError> { + if *delegate_mining.key + != create_mining_address( + program_id, + delegate, + reward_pool_key, + WrappedImmutableMining::from_bytes(&delegate_mining.data.borrow())? + .mining + .bump, + ) + .map_err(|_| MplxRewardsError::DerivationError)? + { + return Err(MplxRewardsError::InvalidMining.into()); + } + + Ok(()) +} + /// Helper for parsing accounts with arbitrary input conditions pub struct AccountLoader {} @@ -321,3 +344,20 @@ impl SafeArithmeticOperations for u128 { .ok_or(MplxRewardsError::MathOverflow) } } + +pub fn create_mining_address( + program_id: &Pubkey, + mining_owner: &Pubkey, + reward_pool: &Pubkey, + bump: u8, +) -> Result { + Pubkey::create_program_address( + &[ + "mining".as_bytes(), + &mining_owner.to_bytes(), + &reward_pool.to_bytes(), + &[bump], + ], + program_id, + ) +} diff --git a/programs/rewards/tests/rewards/change_delegate.rs b/programs/rewards/tests/rewards/change_delegate.rs index efaa92dd..2a6bfdcc 100644 --- a/programs/rewards/tests/rewards/change_delegate.rs +++ b/programs/rewards/tests/rewards/change_delegate.rs @@ -59,6 +59,7 @@ async fn change_delegate_to_the_same() { LockupPeriod::OneYear, &user_a.pubkey(), &user_mining_a, + &user_a.pubkey(), ) .await .unwrap(); @@ -69,6 +70,7 @@ async fn change_delegate_to_the_same() { &user_a, &user_mining_a, &user_mining_a, + &user_a.pubkey(), 6_000_000, ) .await @@ -89,6 +91,7 @@ async fn change_delegate_then_claim() { LockupPeriod::OneYear, &delegate.pubkey(), &delegate_mining, + &delegate.pubkey(), ) .await .unwrap(); @@ -108,6 +111,7 @@ async fn change_delegate_then_claim() { LockupPeriod::OneYear, &user_a.pubkey(), &user_mining_a, + &user_a.pubkey(), ) .await .unwrap(); @@ -118,6 +122,7 @@ async fn change_delegate_then_claim() { &user_a, &delegate_mining, &user_mining_a, + &delegate.pubkey(), 1_000_000, ) .await diff --git a/programs/rewards/tests/rewards/claim.rs b/programs/rewards/tests/rewards/claim.rs index ba0cf463..aa935e7d 100644 --- a/programs/rewards/tests/rewards/claim.rs +++ b/programs/rewards/tests/rewards/claim.rs @@ -58,6 +58,7 @@ async fn with_two_users() { LockupPeriod::ThreeMonths, &user_a.pubkey(), &user_mining_a, + &user_a.pubkey(), ) .await .unwrap(); @@ -72,6 +73,7 @@ async fn with_two_users() { LockupPeriod::ThreeMonths, &user_b.pubkey(), &user_mining_b, + &user_b.pubkey(), ) .await .unwrap(); @@ -138,6 +140,7 @@ async fn flex_vs_three_months() { LockupPeriod::ThreeMonths, &user_a.pubkey(), &user_mining_a, + &user_a.pubkey(), ) .await .unwrap(); @@ -154,6 +157,7 @@ async fn flex_vs_three_months() { LockupPeriod::ThreeMonths, &user_b.pubkey(), &user_mining_b, + &user_b.pubkey(), ) .await .unwrap(); @@ -220,6 +224,7 @@ async fn multiple_consequantial_distributions_for_two_users() { LockupPeriod::ThreeMonths, &user_a.pubkey(), &user_mining_a, + &user_a.pubkey(), ) .await .unwrap(); @@ -234,6 +239,7 @@ async fn multiple_consequantial_distributions_for_two_users() { LockupPeriod::OneYear, &user_b.pubkey(), &user_mining_b, + &user_b.pubkey(), ) .await .unwrap(); @@ -315,6 +321,7 @@ async fn rewards_after_distribution_are_unclaimable() { LockupPeriod::ThreeMonths, &user_a.pubkey(), &user_mining_a, + &user_a.pubkey(), ) .await .unwrap(); @@ -370,6 +377,7 @@ async fn rewards_after_distribution_are_unclaimable() { LockupPeriod::OneYear, &user_b.pubkey(), &user_mining_b, + &user_b.pubkey(), ) .await .unwrap(); @@ -406,6 +414,7 @@ async fn switch_to_flex_is_correct() { LockupPeriod::ThreeMonths, &user_a.pubkey(), &user_mining_a, + &user_a.pubkey(), ) .await .unwrap(); @@ -420,6 +429,7 @@ async fn switch_to_flex_is_correct() { LockupPeriod::OneYear, &user_b.pubkey(), &user_mining_b, + &user_b.pubkey(), ) .await .unwrap(); @@ -485,6 +495,7 @@ async fn two_deposits_vs_one() { LockupPeriod::OneYear, &user_a.pubkey(), &user_mining_a, + &user_a.pubkey(), ) .await .unwrap(); @@ -499,6 +510,7 @@ async fn two_deposits_vs_one() { LockupPeriod::OneYear, &user_b.pubkey(), &user_mining_b, + &user_b.pubkey(), ) .await .unwrap(); @@ -513,6 +525,7 @@ async fn two_deposits_vs_one() { LockupPeriod::OneYear, &user_b.pubkey(), &user_mining_b, + &user_b.pubkey(), ) .await .unwrap(); @@ -575,6 +588,7 @@ async fn claim_tokens_after_deposit_expiration() { LockupPeriod::OneYear, &user_a.pubkey(), &user_mining_a, + &user_a.pubkey(), ) .await .unwrap(); @@ -589,6 +603,7 @@ async fn claim_tokens_after_deposit_expiration() { LockupPeriod::ThreeMonths, &user_b.pubkey(), &user_mining_b, + &user_b.pubkey(), ) .await .unwrap(); @@ -654,6 +669,7 @@ async fn claim_after_withdraw_is_correct() { LockupPeriod::OneYear, &user_a.pubkey(), &user_mining_a, + &user_a.pubkey(), ) .await .unwrap(); @@ -667,6 +683,7 @@ async fn claim_after_withdraw_is_correct() { LockupPeriod::OneYear, &user_b.pubkey(), &user_mining_b, + &user_b.pubkey(), ) .await .unwrap(); @@ -679,6 +696,7 @@ async fn claim_after_withdraw_is_correct() { LockupPeriod::ThreeMonths, &user_b.pubkey(), &user_mining_b, + &user_b.pubkey(), ) .await .unwrap(); @@ -761,6 +779,7 @@ async fn claim_after_withdraw_is_correct() { &user_mining_b, 150, &user_b.pubkey(), + &user_b.pubkey(), ) .await .unwrap(); @@ -813,6 +832,7 @@ async fn with_two_users_with_flex() { LockupPeriod::Flex, &user_a.pubkey(), &user_mining_a, + &user_a.pubkey(), ) .await .unwrap(); @@ -827,6 +847,7 @@ async fn with_two_users_with_flex() { LockupPeriod::Flex, &user_b.pubkey(), &user_mining_b, + &user_b.pubkey(), ) .await .unwrap(); @@ -892,6 +913,7 @@ async fn claim_with_delegate() { LockupPeriod::OneYear, &delegate.pubkey(), &delegate_mining, + &delegate.pubkey(), ) .await .unwrap(); @@ -911,6 +933,7 @@ async fn claim_with_delegate() { LockupPeriod::OneYear, &user_a.pubkey(), &delegate_mining, + &delegate.pubkey(), ) .await .unwrap(); diff --git a/programs/rewards/tests/rewards/close_mining.rs b/programs/rewards/tests/rewards/close_mining.rs index 56b613d3..ecf9dd64 100644 --- a/programs/rewards/tests/rewards/close_mining.rs +++ b/programs/rewards/tests/rewards/close_mining.rs @@ -50,6 +50,7 @@ async fn success() { LockupPeriod::ThreeMonths, &mining_owner.pubkey(), &mining, + &mining_owner.pubkey(), ) .await .unwrap(); @@ -82,6 +83,7 @@ async fn close_when_has_stake_from_others() { LockupPeriod::OneYear, &delegate.pubkey(), &delegate_mining, + &delegate.pubkey(), ) .await .unwrap(); @@ -106,6 +108,7 @@ async fn close_when_has_stake_from_others() { LockupPeriod::ThreeMonths, &mining_owner.pubkey(), &delegate_mining, + &delegate.pubkey(), ) .await .unwrap(); @@ -133,6 +136,7 @@ async fn close_when_has_unclaimed_rewards() { LockupPeriod::ThreeMonths, &mining_owner.pubkey(), &mining, + &mining_owner.pubkey(), ) .await .unwrap(); diff --git a/programs/rewards/tests/rewards/deposit_mining.rs b/programs/rewards/tests/rewards/deposit_mining.rs index 30c0791c..2372c8f6 100644 --- a/programs/rewards/tests/rewards/deposit_mining.rs +++ b/programs/rewards/tests/rewards/deposit_mining.rs @@ -44,6 +44,7 @@ async fn success() { LockupPeriod::ThreeMonths, &user, &mining, + &user, ) .await .unwrap(); @@ -74,6 +75,7 @@ async fn success_with_flex() { LockupPeriod::Flex, &user, &mining, + &user, ) .await .unwrap(); @@ -108,6 +110,7 @@ async fn delegating_success() { LockupPeriod::OneYear, &delegate.pubkey(), &delegate_mining, + &delegate.pubkey(), ) .await .unwrap(); @@ -125,6 +128,7 @@ async fn delegating_success() { LockupPeriod::Flex, &user, &delegate_mining, + &delegate.pubkey(), ) .await .unwrap(); diff --git a/programs/rewards/tests/rewards/distribute_rewards.rs b/programs/rewards/tests/rewards/distribute_rewards.rs index 0102c97c..83492184 100644 --- a/programs/rewards/tests/rewards/distribute_rewards.rs +++ b/programs/rewards/tests/rewards/distribute_rewards.rs @@ -52,6 +52,7 @@ async fn happy_path() { LockupPeriod::ThreeMonths, &user.pubkey(), &user_mining_addr, + &user.pubkey(), ) .await .unwrap(); @@ -99,6 +100,7 @@ async fn happy_path_with_flex() { LockupPeriod::Flex, &user.pubkey(), &user_mining_addr, + &user.pubkey(), ) .await .unwrap(); @@ -146,6 +148,7 @@ async fn happy_path_with_flex_continious_distribution() { LockupPeriod::Flex, &user.pubkey(), &user_mining_addr, + &user.pubkey(), ) .await .unwrap(); @@ -197,6 +200,7 @@ async fn happy_path_with_flex_continious_distribution_with_two_users() { LockupPeriod::Flex, &alice.pubkey(), &alice_mining_addr, + &alice.pubkey(), ) .await .unwrap(); @@ -210,6 +214,7 @@ async fn happy_path_with_flex_continious_distribution_with_two_users() { LockupPeriod::Flex, &bob.pubkey(), &bob_mining_addr, + &bob.pubkey(), ) .await .unwrap(); diff --git a/programs/rewards/tests/rewards/extend_stake.rs b/programs/rewards/tests/rewards/extend_stake.rs index 7e07eabb..9d9989d1 100644 --- a/programs/rewards/tests/rewards/extend_stake.rs +++ b/programs/rewards/tests/rewards/extend_stake.rs @@ -57,6 +57,7 @@ async fn restake_before_its_expired() { old_lockup_period, &mining_owner, &mining, + &mining_owner, ) .await .unwrap(); @@ -76,6 +77,7 @@ async fn restake_before_its_expired() { base_amount, additional_amount, &mining_owner, + &mining_owner, ) .await .unwrap(); @@ -117,6 +119,7 @@ async fn restake_for_another_period_after_old_is_expired() { LockupPeriod::ThreeMonths, &mining_owner, &mining, + &mining_owner, ) .await .unwrap(); @@ -139,6 +142,7 @@ async fn restake_for_another_period_after_old_is_expired() { base_amount, additional_amount, &mining_owner, + &mining_owner, ) .await .unwrap(); @@ -175,6 +179,7 @@ async fn just_prolong_without_adding_tokes() { old_lockup_period, &mining_owner, &mining, + &mining_owner, ) .await .unwrap(); @@ -194,6 +199,7 @@ async fn just_prolong_without_adding_tokes() { base_amount, additional_amount, &mining_owner, + &mining_owner, ) .await .unwrap(); @@ -235,6 +241,7 @@ async fn restake_after_its_expired_with_no_additional_tokens() { LockupPeriod::ThreeMonths, &mining_owner, &mining, + &mining_owner, ) .await .unwrap(); @@ -257,6 +264,7 @@ async fn restake_after_its_expired_with_no_additional_tokens() { base_amount, additional_amount, &mining_owner, + &mining_owner, ) .await .unwrap(); @@ -292,6 +300,7 @@ async fn restake_in_expiration_day() { LockupPeriod::ThreeMonths, &mining_owner, &mining, + &mining_owner, ) .await .unwrap(); @@ -314,6 +323,7 @@ async fn restake_in_expiration_day() { base_amount, additional_amount, &mining_owner, + &mining_owner, ) .await .unwrap(); @@ -344,6 +354,7 @@ async fn prolong_with_delegate() { LockupPeriod::OneYear, &delegate.pubkey(), &delegate_mining, + &delegate.pubkey(), ) .await .unwrap(); @@ -373,6 +384,7 @@ async fn prolong_with_delegate() { old_lockup_period, &mining_owner, &delegate_mining, + &delegate.pubkey(), ) .await .unwrap(); @@ -411,6 +423,7 @@ async fn prolong_with_delegate() { base_amount, additional_amount, &mining_owner, + &delegate.pubkey(), ) .await .unwrap(); diff --git a/programs/rewards/tests/rewards/fill_vault.rs b/programs/rewards/tests/rewards/fill_vault.rs index fa4c6059..277e451e 100644 --- a/programs/rewards/tests/rewards/fill_vault.rs +++ b/programs/rewards/tests/rewards/fill_vault.rs @@ -33,6 +33,7 @@ async fn setup() -> (ProgramTestContext, TestRewards) { LockupPeriod::ThreeMonths, &user.pubkey(), &user_mining, + &user.pubkey(), ) .await .unwrap(); diff --git a/programs/rewards/tests/rewards/fixtures/mplx_rewards.so b/programs/rewards/tests/rewards/fixtures/mplx_rewards.so index bc56cc3f..d33fc338 100755 Binary files a/programs/rewards/tests/rewards/fixtures/mplx_rewards.so and b/programs/rewards/tests/rewards/fixtures/mplx_rewards.so differ diff --git a/programs/rewards/tests/rewards/precision.rs b/programs/rewards/tests/rewards/precision.rs index f4022c5e..f0b79bd0 100644 --- a/programs/rewards/tests/rewards/precision.rs +++ b/programs/rewards/tests/rewards/precision.rs @@ -53,6 +53,7 @@ async fn precision_distribution() { LockupPeriod::Flex, &rich_user.pubkey(), &rich_user_mining_addr, + &rich_user.pubkey(), ) .await .unwrap(); @@ -66,6 +67,7 @@ async fn precision_distribution() { LockupPeriod::Flex, &user.pubkey(), &user_mining_addr, + &user.pubkey(), ) .await .unwrap(); diff --git a/programs/rewards/tests/rewards/utils.rs b/programs/rewards/tests/rewards/utils.rs index 11030838..6fa5e09c 100644 --- a/programs/rewards/tests/rewards/utils.rs +++ b/programs/rewards/tests/rewards/utils.rs @@ -119,6 +119,7 @@ impl TestRewards { mining_account } + #[allow(clippy::too_many_arguments)] pub async fn change_delegate( &self, context: &mut ProgramTestContext, @@ -126,6 +127,7 @@ impl TestRewards { mining_owner: &Keypair, new_delegate_mining: &Pubkey, old_delegate_mining: &Pubkey, + new_delegate: &Pubkey, amount: u64, ) -> BanksClientResult<()> { let tx = Transaction::new_signed_with_payer( @@ -137,6 +139,7 @@ impl TestRewards { &mining_owner.pubkey(), old_delegate_mining, new_delegate_mining, + new_delegate, amount, )], Some(&context.payer.pubkey()), @@ -147,6 +150,7 @@ impl TestRewards { context.banks_client.process_transaction(tx).await } + #[allow(clippy::too_many_arguments)] pub async fn deposit_mining( &self, context: &mut ProgramTestContext, @@ -155,6 +159,7 @@ impl TestRewards { lockup_period: LockupPeriod, owner: &Pubkey, delegate_mining: &Pubkey, + delegate_wallet_addr: &Pubkey, ) -> BanksClientResult<()> { let tx = Transaction::new_signed_with_payer( &[mplx_rewards::instruction::deposit_mining( @@ -166,6 +171,7 @@ impl TestRewards { amount, lockup_period, owner, + delegate_wallet_addr, )], Some(&context.payer.pubkey()), &[&context.payer, &self.deposit_authority], @@ -182,6 +188,7 @@ impl TestRewards { delegate_mining: &Pubkey, amount: u64, owner: &Pubkey, + delegate_wallet_addr: &Pubkey, ) -> BanksClientResult<()> { let tx = Transaction::new_signed_with_payer( &[mplx_rewards::instruction::withdraw_mining( @@ -192,6 +199,7 @@ impl TestRewards { delegate_mining, amount, owner, + delegate_wallet_addr, )], Some(&context.payer.pubkey()), &[&context.payer, &self.deposit_authority], @@ -283,6 +291,7 @@ impl TestRewards { base_amount: u64, additional_amount: u64, mining_owner: &Pubkey, + delegate_wallet_addr: &Pubkey, ) -> BanksClientResult<()> { let tx = Transaction::new_signed_with_payer( &[mplx_rewards::instruction::extend_stake( @@ -297,6 +306,7 @@ impl TestRewards { base_amount, additional_amount, mining_owner, + delegate_wallet_addr, )], Some(&context.payer.pubkey()), &[&context.payer, &self.deposit_authority], diff --git a/programs/rewards/tests/rewards/withdraw_mining.rs b/programs/rewards/tests/rewards/withdraw_mining.rs index 3417efbc..6bc58e02 100644 --- a/programs/rewards/tests/rewards/withdraw_mining.rs +++ b/programs/rewards/tests/rewards/withdraw_mining.rs @@ -32,12 +32,20 @@ async fn success() { let lockup_period = LockupPeriod::ThreeMonths; test_rewards - .deposit_mining(&mut context, &mining, 100, lockup_period, &user, &mining) + .deposit_mining( + &mut context, + &mining, + 100, + lockup_period, + &user, + &mining, + &user, + ) .await .unwrap(); test_rewards - .withdraw_mining(&mut context, &mining, &mining, 30, &user) + .withdraw_mining(&mut context, &mining, &mining, 30, &user, &user) .await .unwrap(); @@ -68,6 +76,7 @@ async fn success_with_5kkk_after_expiring() { lockup_period, &user, &mining, + &user, ) .await .unwrap(); @@ -75,7 +84,7 @@ async fn success_with_5kkk_after_expiring() { advance_clock_by_ts(&mut context, (100 * SECONDS_PER_DAY).try_into().unwrap()).await; test_rewards - .withdraw_mining(&mut context, &mining, &mining, 5000000000, &user) + .withdraw_mining(&mut context, &mining, &mining, 5000000000, &user, &user) .await .unwrap();