use anchor_lang::solana_program::pubkey::PUBKEY_BYTES;
use crate::*;
#[account]
#[derive(Copy, Debug, Default)]
pub struct Gaugemeister {
pub base: Pubkey,
pub bump: u8,
pub rewarder: Pubkey,
pub operator: Pubkey,
pub locker: Pubkey,
pub foreman: Pubkey,
pub epoch_duration_seconds: u32,
pub current_rewards_epoch: u32,
pub next_epoch_starts_at: u64,
pub locker_token_mint: Pubkey,
pub locker_governor: Pubkey,
}
impl Gaugemeister {
pub const LEN: usize = PUBKEY_BYTES + 1 + PUBKEY_BYTES * 4 + 4 + 4 + 8 + PUBKEY_BYTES * 2;
pub fn voting_epoch(&self) -> Result<u32> {
let voting_epoch = unwrap_int!(self.current_rewards_epoch.checked_add(1));
Ok(voting_epoch)
}
}
#[account]
#[derive(Copy, Debug, Default)]
pub struct Gauge {
pub gaugemeister: Pubkey,
pub quarry: Pubkey,
pub is_disabled: bool,
}
impl Gauge {
pub const LEN: usize = PUBKEY_BYTES * 2 + 1;
}
#[account]
#[derive(Copy, Debug, Default)]
pub struct GaugeVoter {
pub gaugemeister: Pubkey,
pub escrow: Pubkey,
pub owner: Pubkey,
pub total_weight: u32,
pub weight_change_seqno: u64,
}
impl GaugeVoter {
pub const LEN: usize = PUBKEY_BYTES * 3 + 4 + 8;
}
#[account]
#[derive(Copy, Debug, Default)]
pub struct GaugeVote {
pub gauge_voter: Pubkey,
pub gauge: Pubkey,
pub weight: u32,
}
impl GaugeVote {
pub const LEN: usize = PUBKEY_BYTES * 2 + 4;
}
#[account]
#[derive(Copy, Debug, Default)]
pub struct EpochGauge {
pub gauge: Pubkey,
pub voting_epoch: u32,
pub total_power: u64,
}
impl EpochGauge {
pub const LEN: usize = PUBKEY_BYTES + 4 + 8;
}
#[account]
#[derive(Copy, Debug, Default)]
pub struct EpochGaugeVoter {
pub gauge_voter: Pubkey,
pub voting_epoch: u32,
pub weight_change_seqno: u64,
pub voting_power: u64,
pub allocated_power: u64,
}
impl EpochGaugeVoter {
pub const LEN: usize = PUBKEY_BYTES + 4 + 8 * 3;
}
#[account]
#[derive(Copy, Debug, Default)]
pub struct EpochGaugeVote {
pub allocated_power: u64,
}
impl EpochGaugeVote {
pub const LEN: usize = 8;
}
impl EpochGaugeVote {
pub fn find_program_address(gauge_vote: &Pubkey, voting_epoch: u32) -> (Pubkey, u8) {
let epoch_bytes = voting_epoch.to_le_bytes();
Pubkey::find_program_address(
&[b"EpochGaugeVote", gauge_vote.as_ref(), epoch_bytes.as_ref()],
&crate::ID,
)
}
}
#[cfg(test)]
#[allow(clippy::unwrap_used)]
mod tests {
use super::*;
#[test]
fn test_gaugemeister_len() {
assert_eq!(
Gaugemeister::default().try_to_vec().unwrap().len(),
Gaugemeister::LEN
);
}
#[test]
fn test_gauge_voter_len() {
assert_eq!(
GaugeVoter::default().try_to_vec().unwrap().len(),
GaugeVoter::LEN
);
}
#[test]
fn test_gauge_len() {
assert_eq!(Gauge::default().try_to_vec().unwrap().len(), Gauge::LEN);
}
#[test]
fn test_gauge_vote_len() {
assert_eq!(
GaugeVote::default().try_to_vec().unwrap().len(),
GaugeVote::LEN
);
}
#[test]
fn test_epoch_gauge_voter_len() {
assert_eq!(
EpochGaugeVoter::default().try_to_vec().unwrap().len(),
EpochGaugeVoter::LEN
);
}
#[test]
fn test_epoch_gauge_len() {
assert_eq!(
EpochGauge::default().try_to_vec().unwrap().len(),
EpochGauge::LEN
);
}
#[test]
fn test_epoch_gauge_vote_len() {
assert_eq!(
EpochGaugeVote::default().try_to_vec().unwrap().len(),
EpochGaugeVote::LEN
);
}
}