gauge/instructions/
create_gauge_vote.rs

1//! Creates a [GaugeVote].
2
3use vipers::assert_keys_eq;
4
5use crate::*;
6
7/// Accounts for [gauge::create_gauge_vote].
8#[derive(Accounts)]
9pub struct CreateGaugeVote<'info> {
10    /// The [GaugeVote] to be created.
11    #[account(
12        init,
13        seeds = [
14            b"GaugeVote".as_ref(),
15            gauge_voter.key().as_ref(),
16            gauge.key().as_ref(),
17        ],
18        bump,
19        space = 8 + GaugeVote::LEN,
20        payer = payer
21    )]
22    pub gauge_vote: Account<'info, GaugeVote>,
23
24    /// Gauge voter.
25    pub gauge_voter: Account<'info, GaugeVoter>,
26
27    /// Gauge.
28    pub gauge: Account<'info, Gauge>,
29
30    /// Payer.
31    #[account(mut)]
32    pub payer: Signer<'info>,
33
34    /// System program.
35    pub system_program: Program<'info, System>,
36}
37
38pub fn handler(ctx: Context<CreateGaugeVote>) -> Result<()> {
39    let gauge_vote = &mut ctx.accounts.gauge_vote;
40    gauge_vote.gauge_voter = ctx.accounts.gauge_voter.key();
41    gauge_vote.gauge = ctx.accounts.gauge.key();
42
43    gauge_vote.weight = 0;
44
45    emit!(GaugeVoteCreateEvent {
46        gaugemeister: ctx.accounts.gauge.gaugemeister,
47        gauge: gauge_vote.gauge,
48        quarry: ctx.accounts.gauge.quarry,
49        gauge_voter_owner: ctx.accounts.gauge_voter.owner,
50    });
51
52    Ok(())
53}
54
55impl<'info> Validate<'info> for CreateGaugeVote<'info> {
56    fn validate(&self) -> Result<()> {
57        assert_keys_eq!(self.gauge_voter.gaugemeister, self.gauge.gaugemeister);
58        Ok(())
59    }
60}
61
62/// Event called in [gauge::create_gauge_vote].
63#[event]
64pub struct GaugeVoteCreateEvent {
65    #[index]
66    /// The [Gaugemeister].
67    pub gaugemeister: Pubkey,
68    #[index]
69    /// The [Gauge].
70    pub gauge: Pubkey,
71    #[index]
72    /// The [quarry_mine::Quarry] being voted on.
73    pub quarry: Pubkey,
74    #[index]
75    /// Owner of the Escrow of the [GaugeVoter].
76    pub gauge_voter_owner: Pubkey,
77}