Skip to content

Commit

Permalink
Fix bugs in nft and token voter (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChewingGlass authored Dec 13, 2024
1 parent 9e64627 commit ebf582e
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::state::*;
use anchor_lang::prelude::*;
use anchor_spl::token::Mint;
use nft_proxy::state::ProxyConfigV0;

use crate::state::*;

#[derive(AnchorSerialize, AnchorDeserialize, Clone, Default)]
pub struct InitializeNftVoterArgsV0 {
pub name: String,
Expand All @@ -19,7 +20,7 @@ pub struct InitializeNftVoterV0<'info> {
#[account(
init,
payer = payer,
space = 8 + 60 + std::mem::size_of::<NftVoterV0>(),
space = 8 + 60 + std::mem::size_of::<NftVoterV0>() + 4 + args.name.len(),
seeds = [b"nft_voter", args.name.as_bytes()],
bump
)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use crate::{error::ErrorCode, metaplex::MetadataAccount, RelinquishVoteArgsV0};
use anchor_lang::prelude::*;
use anchor_spl::token::Mint;
use nft_proxy::state::ProxyAssignmentV0;
use proposal::{ProposalConfigV0, ProposalV0};

use crate::{nft_voter_seeds, state::*};
use crate::{
error::ErrorCode, metaplex::MetadataAccount, nft_voter_seeds, state::*, RelinquishVoteArgsV0,
};

#[derive(Accounts)]
pub struct ProxiedRelinquishVoteV0<'info> {
Expand Down Expand Up @@ -35,6 +36,7 @@ pub struct ProxiedRelinquishVoteV0<'info> {
constraint = proxy_assignment.proxy_config == nft_voter.proxy_config,
constraint = proxy_assignment.index <= marker.proxy_index,
constraint = proxy_assignment.expiration_time > Clock::get().unwrap().unix_timestamp,
constraint = proxy_assignment.asset == mint.key(),
)]
pub proxy_assignment: Box<Account<'info, ProxyAssignmentV0>>,
#[account(
Expand Down
6 changes: 3 additions & 3 deletions programs/nft_voter/src/instructions/proxied_vote_v0.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use crate::{error::ErrorCode, metaplex::MetadataAccount, VoteArgsV0};
use anchor_lang::prelude::*;
use anchor_spl::token::Mint;
use nft_proxy::state::ProxyAssignmentV0;
use proposal::{ProposalConfigV0, ProposalV0};

use crate::{nft_voter_seeds, state::*};
use crate::{error::ErrorCode, metaplex::MetadataAccount, nft_voter_seeds, state::*, VoteArgsV0};

#[derive(Accounts)]
pub struct ProxyVoteV0<'info> {
Expand All @@ -13,7 +12,7 @@ pub struct ProxyVoteV0<'info> {
#[account(
init_if_needed,
payer = payer,
space = 8 + 60 + std::mem::size_of::<VoteMarkerV0>(),
space = 8 + 60 + std::mem::size_of::<VoteMarkerV0>() + 2 * proposal.choices.len(),
seeds = [b"marker", nft_voter.key().as_ref(), mint.key().as_ref(), proposal.key().as_ref()],
bump
)]
Expand All @@ -24,6 +23,7 @@ pub struct ProxyVoteV0<'info> {
// only the current or earlier delegates can change vote. Or if proposal not set, this was an `init` for the marker
constraint = proxy_assignment.index <= marker.proxy_index || marker.proposal == Pubkey::default(),
constraint = proxy_assignment.expiration_time > Clock::get().unwrap().unix_timestamp,
constraint = proxy_assignment.asset == mint.key(),
)]
pub proxy_assignment: Box<Account<'info, ProxyAssignmentV0>>,
pub nft_voter: Box<Account<'info, NftVoterV0>>,
Expand Down
5 changes: 2 additions & 3 deletions programs/nft_voter/src/instructions/vote_v0.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use crate::{error::ErrorCode, metaplex::MetadataAccount};
use anchor_lang::prelude::*;
use anchor_spl::token::{Mint, TokenAccount};
use proposal::{ProposalConfigV0, ProposalV0};

use crate::{nft_voter_seeds, state::*};
use crate::{error::ErrorCode, metaplex::MetadataAccount, nft_voter_seeds, state::*};

#[derive(AnchorSerialize, AnchorDeserialize, Clone, Default)]
pub struct VoteArgsV0 {
Expand All @@ -17,7 +16,7 @@ pub struct VoteV0<'info> {
#[account(
init_if_needed,
payer = payer,
space = 8 + 60 + std::mem::size_of::<VoteMarkerV0>(),
space = 8 + 60 + std::mem::size_of::<VoteMarkerV0>() + 2 * proposal.choices.len(),
seeds = [b"marker", nft_voter.key().as_ref(), mint.key().as_ref(), proposal.key().as_ref()],
bump
)]
Expand Down
22 changes: 14 additions & 8 deletions programs/token_voter/src/instructions/initialize_token_voter_v0.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
use crate::metaplex::{
create_master_edition_v3, create_metadata_accounts_v3, CollectionDetails, CreateMasterEditionV3,
CreateMetadataAccountsV3, DataV2, Metadata,
};
use crate::{state::*, token_voter_seeds};
use anchor_lang::prelude::*;
use anchor_spl::associated_token::AssociatedToken;
use anchor_spl::token::{self, Mint, MintTo, Token, TokenAccount};
use anchor_spl::{
associated_token::AssociatedToken,
token::{self, Mint, MintTo, Token, TokenAccount},
};

use crate::{
metaplex::{
create_master_edition_v3, create_metadata_accounts_v3, CollectionDetails,
CreateMasterEditionV3, CreateMetadataAccountsV3, DataV2, Metadata,
},
state::*,
token_voter_seeds,
};

#[derive(AnchorSerialize, AnchorDeserialize, Clone, Default)]
pub struct InitializeTokenVoterArgsV0 {
Expand All @@ -23,7 +29,7 @@ pub struct InitializeTokenVoterV0<'info> {
#[account(
init,
payer = payer,
space = 8 + 60 + std::mem::size_of::<TokenVoterV0>(),
space = 8 + 60 + std::mem::size_of::<TokenVoterV0>() + 4 + args.name.len(),
seeds = [b"token_voter", args.name.as_bytes()],
bump
)]
Expand Down
5 changes: 2 additions & 3 deletions programs/token_voter/src/instructions/vote_v0.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use crate::error::ErrorCode;
use anchor_lang::prelude::*;
use anchor_spl::token::{Mint, TokenAccount};
use proposal::{ProposalConfigV0, ProposalV0};

use crate::{state::*, token_voter_seeds};
use crate::{error::ErrorCode, state::*, token_voter_seeds};

#[derive(AnchorSerialize, AnchorDeserialize, Clone, Default)]
pub struct VoteArgsV0 {
Expand All @@ -17,7 +16,7 @@ pub struct VoteV0<'info> {
#[account(
init_if_needed,
payer = payer,
space = 8 + 60 + std::mem::size_of::<VoteMarkerV0>(),
space = 8 + 60 + std::mem::size_of::<VoteMarkerV0>() + 2 * proposal.choices.len(),
seeds = [b"marker", token_voter.key().as_ref(), mint.key().as_ref(), proposal.key().as_ref()],
bump
)]
Expand Down
17 changes: 10 additions & 7 deletions programs/token_voter/src/instructions/withdraw_v0.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
use crate::metaplex::{burn, Burn, Metadata};
use crate::receipt_seeds;
use crate::state::*;
use anchor_lang::prelude::*;
use anchor_spl::associated_token::AssociatedToken;
use anchor_spl::token::{self, CloseAccount, Transfer};
use anchor_spl::token::{Mint, Token, TokenAccount};
use anchor_spl::{
associated_token::AssociatedToken,
token::{self, CloseAccount, Mint, Token, TokenAccount, Transfer},
};

use crate::{
metaplex::{burn, Burn, Metadata},
receipt_seeds,
state::*,
};

#[derive(Accounts)]
pub struct WithdrawV0<'info> {
Expand Down Expand Up @@ -62,7 +66,6 @@ pub struct WithdrawV0<'info> {

#[account(
mut,
close = refund,
associated_token::authority = receipt,
associated_token::mint = deposit_mint,
)]
Expand Down

0 comments on commit ebf582e

Please sign in to comment.