use anchor_lang::{prelude::*, solana_program::pubkey::PUBKEY_BYTES};
#[account]
#[derive(Copy, Debug, Default)]
pub struct Governor {
pub base: Pubkey,
pub bump: u8,
pub proposal_count: u64,
pub electorate: Pubkey,
pub smart_wallet: Pubkey,
pub params: GovernanceParameters,
}
impl Governor {
pub const LEN: usize = PUBKEY_BYTES + 1 + 8 + PUBKEY_BYTES * 2 + GovernanceParameters::LEN;
}
#[derive(AnchorSerialize, AnchorDeserialize, Copy, Clone, Debug, Default, Eq, PartialEq)]
pub struct GovernanceParameters {
pub voting_delay: u64,
pub voting_period: u64,
pub quorum_votes: u64,
pub timelock_delay_seconds: i64,
}
impl GovernanceParameters {
pub const LEN: usize = 8 * 4;
}
#[account]
#[derive(Debug, Default)]
pub struct Proposal {
pub governor: Pubkey,
pub index: u64,
pub bump: u8,
pub proposer: Pubkey,
pub quorum_votes: u64,
pub for_votes: u64,
pub against_votes: u64,
pub abstain_votes: u64,
pub canceled_at: i64,
pub created_at: i64,
pub activated_at: i64,
pub voting_ends_at: i64,
pub queued_at: i64,
pub queued_transaction: Pubkey,
pub instructions: Vec<ProposalInstruction>,
}
impl Proposal {
pub fn space(instructions: Vec<ProposalInstruction>) -> usize {
4 + 4 + std::mem::size_of::<Proposal>()
+ (instructions.iter().map(|ix| ix.space()).sum::<usize>())
}
}
#[account]
#[derive(Debug, Default)]
pub struct ProposalMeta {
pub proposal: Pubkey,
pub title: String,
pub description_link: String,
}
#[account]
#[derive(Debug, Default)]
pub struct Vote {
pub proposal: Pubkey,
pub voter: Pubkey,
pub bump: u8,
pub side: u8,
pub weight: u64,
}
impl Vote {
pub const LEN: usize = PUBKEY_BYTES * 2 + 1 + 1 + 8;
}
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug, Default, PartialEq)]
pub struct ProposalInstruction {
pub program_id: Pubkey,
pub keys: Vec<ProposalAccountMeta>,
pub data: Vec<u8>,
}
impl ProposalInstruction {
pub fn space(&self) -> usize {
std::mem::size_of::<Pubkey>()
+ (self.keys.len() as usize) * std::mem::size_of::<AccountMeta>()
+ (self.data.len() as usize)
}
}
#[derive(AnchorSerialize, AnchorDeserialize, Debug, PartialEq, Copy, Clone)]
pub struct ProposalAccountMeta {
pub pubkey: Pubkey,
pub is_signer: bool,
pub is_writable: bool,
}