Skip to content

Commit

Permalink
Merge pull request #27 from adm-metaex/mtg-572-delegate-changing
Browse files Browse the repository at this point in the history
[mtg-572] delegate changing
  • Loading branch information
kstepanovdev authored Aug 28, 2024
2 parents 61855c5 + c3d5b0d commit 1d76151
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ pub fn change_delegate(ctx: Context<ChangeDelegate>, deposit_entry_index: u8) ->
MplStakingError::InvalidMining
);
target.delegate = delegate_voter.voter_authority;
target.delegate_last_update_ts = curr_ts;
}
target.delegate_last_update_ts = curr_ts;

let reward_pool = ctx.accounts.reward_pool.to_account_info();
let mining = ctx.accounts.deposit_mining.to_account_info();
Expand Down
3 changes: 2 additions & 1 deletion programs/voter-stake-registry/src/instructions/stake.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{cpi_instructions, Stake};
use crate::{clock_unix_timestamp, cpi_instructions, Stake};
use anchor_lang::prelude::*;
use mplx_staking_states::{error::MplStakingError, state::LockupKind};

Expand Down Expand Up @@ -60,6 +60,7 @@ pub fn stake(
.amount_deposited_native
.checked_add(amount)
.ok_or(MplStakingError::ArithmeticOverflow)?;
target.delegate_last_update_ts = clock_unix_timestamp();

let reward_pool = ctx.accounts.reward_pool.to_account_info();
let mining = ctx.accounts.deposit_mining.to_account_info();
Expand Down
9 changes: 5 additions & 4 deletions programs/voter-stake-registry/tests/test_change_delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,13 @@ async fn change_from_own_delegate_to_new_delegate() -> Result<(), TransportError
)
.await?;

advance_clock_by_ts(&mut context.solana.context.borrow_mut(), 5 * 86400).await;

let (old_delegate_mining, _) = find_deposit_mining_addr(
&context.rewards.program_id,
&voter.authority.pubkey(),
&rewards_pool,
);

advance_clock_by_ts(&mut context.solana.context.borrow_mut(), 5 * 86400 + 1).await;
context
.addin
.change_delegate(
Expand Down Expand Up @@ -442,6 +441,7 @@ async fn stake_is_too_little() -> Result<(), TransportError> {
&voter.authority.pubkey(),
&rewards_pool,
);
advance_clock_by_ts(&mut context.solana.context.borrow_mut(), 5 * 86400 + 1).await;
context
.addin
.change_delegate(
Expand Down Expand Up @@ -594,6 +594,7 @@ async fn delegate_is_the_same() -> Result<(), TransportError> {
&voter.authority.pubkey(),
&rewards_pool,
);
advance_clock_by_ts(&mut context.solana.context.borrow_mut(), 5 * 86400 + 1).await;
context
.addin
.change_delegate(
Expand Down Expand Up @@ -818,7 +819,7 @@ async fn change_from_own_delegate_to_new_delegate_and_back_with_cooldown(
&voter.authority.pubkey(),
&rewards_pool,
);

advance_clock_by_ts(&mut context.solana.context.borrow_mut(), 5 * 86400 + 1).await;
context
.addin
.change_delegate(
Expand All @@ -832,7 +833,6 @@ async fn change_from_own_delegate_to_new_delegate_and_back_with_cooldown(
.await?;

advance_clock_by_ts(&mut context.solana.context.borrow_mut(), 5 * 86400 + 1).await;

context
.addin
.change_delegate(
Expand Down Expand Up @@ -1057,6 +1057,7 @@ async fn change_from_own_delegate_to_new_delegate_and_back_instantly() -> Result
&rewards_pool,
);

advance_clock_by_ts(&mut context.solana.context.borrow_mut(), 5 * 86400 + 1).await;
context
.addin
.change_delegate(
Expand Down

0 comments on commit 1d76151

Please sign in to comment.