Voting System
Objective
To allow verified users to vote on DAO proposals based on their NFT holdings. One NFT equals one vote.
Logic
Each proposal has two counters: votes_yes
and votes_no
. When a verified user votes, their NFT balance determines the weight of their vote.
Mathematical Model
votes_yes = Σ NFT holdings of all "yes" voters
votes_no = Σ NFT holdings of all "no" voters
Anchor Code
pub fn vote(ctx: Context<Vote>, proposal_id: u64, vote_yes: bool) -> Result<()> {
let nft_account = &ctx.accounts.nft_account;
let vote_weight = nft_account.amount;
if vote_yes {
ctx.accounts.proposal.votes_yes += vote_weight;
} else {
ctx.accounts.proposal.votes_no += vote_weight;
}
Ok(())
}
Security Notes
Only verified NFT holders can call this function.
All votes are transparently stored on-chain and cannot be altered.
Prevents Sybil attacks, since voting power is proportional to NFT ownership.
Last updated