Skip to content

Commit

Permalink
Treat expired delegations as 0 voting power (#764)
Browse files Browse the repository at this point in the history
* Treat expired delegations as 0 voting power

* Fix tests
  • Loading branch information
ChewingGlass authored Jan 6, 2025
1 parent 084dfdd commit 6ebc744
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,12 @@ pub fn handler(ctx: Context<ClaimRewardsV1>, args: ClaimRewardsArgsV0) -> Result
}
}

let delegated_vehnt_at_epoch =
position.voting_power(voting_mint_config, ctx.accounts.dao_epoch_info.start_ts())?;
let epoch_start_ts = ctx.accounts.dao_epoch_info.start_ts();
let delegated_vehnt_at_epoch = if delegated_position.expiration_ts > epoch_start_ts {
position.voting_power(voting_mint_config, epoch_start_ts)?
} else {
0
};

msg!("Staked {} veHNT at start of epoch with {} total veHNT delegated to dao and {} total rewards to dao",
delegated_vehnt_at_epoch,
Expand Down
9 changes: 4 additions & 5 deletions programs/voter-stake-registry/src/instructions/withdraw_v0.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use crate::error::*;
use crate::position_seeds;
use crate::state::*;
use anchor_lang::prelude::*;
use anchor_spl::{
associated_token::AssociatedToken,
token::{transfer, Mint, Token, TokenAccount, Transfer},
};

use crate::{error::*, position_seeds, state::*};

#[derive(AnchorSerialize, AnchorDeserialize, Clone, Default)]
pub struct WithdrawArgsV0 {
pub amount: u64,
Expand All @@ -33,8 +32,8 @@ pub struct WithdrawV0<'info> {
#[account(
init_if_needed,
payer = position_authority,
token::mint = mint,
token::authority = position_authority,
associated_token::mint = mint,
associated_token::authority = position_authority,
constraint = position_token_account.amount > 0
)]
pub position_token_account: Box<Account<'info, TokenAccount>>,
Expand Down

0 comments on commit 6ebc744

Please sign in to comment.