use crate::*;
use locked_voter::Escrow;
#[derive(Accounts)]
#[instruction(voting_epoch: u32)]
pub struct CloseEpochGaugeVote<'info> {
#[account(
mut,
seeds = [
b"EpochGaugeVote".as_ref(),
gauge_vote.key().as_ref(),
voting_epoch.to_le_bytes().as_ref(),
],
bump,
close = recipient
)]
pub epoch_gauge_vote: Account<'info, EpochGaugeVote>,
pub gaugemeister: Account<'info, Gaugemeister>,
#[account(has_one = gaugemeister)]
pub gauge: Account<'info, Gauge>,
#[account(has_one = gaugemeister, has_one = escrow)]
pub gauge_voter: Account<'info, GaugeVoter>,
#[account(has_one = gauge_voter, has_one = gauge)]
pub gauge_vote: Account<'info, GaugeVote>,
#[account(has_one = vote_delegate @ crate::ErrorCode::UnauthorizedNotDelegate)]
pub escrow: Account<'info, Escrow>,
pub vote_delegate: Signer<'info>,
#[account(mut)]
pub recipient: SystemAccount<'info>,
}
pub fn handler(ctx: Context<CloseEpochGaugeVote>, voting_epoch: u32) -> Result<()> {
let current_voting_epoch = ctx.accounts.gaugemeister.voting_epoch()?;
invariant!(voting_epoch < current_voting_epoch, CloseEpochNotElapsed);
let (epoch_gauge_vote_key, _) =
EpochGaugeVote::find_program_address(ctx.accounts.gauge_vote.as_key_ref(), voting_epoch);
assert_keys_eq!(epoch_gauge_vote_key, ctx.accounts.epoch_gauge_vote);
Ok(())
}
impl<'info> Validate<'info> for CloseEpochGaugeVote<'info> {
fn validate(&self) -> Result<()> {
Ok(())
}
}