diff --git a/packages/voter-stake-registry-hooks/src/hooks/useRelinquishVote.ts b/packages/voter-stake-registry-hooks/src/hooks/useRelinquishVote.ts index 553eb51ed..1648b2ead 100644 --- a/packages/voter-stake-registry-hooks/src/hooks/useRelinquishVote.ts +++ b/packages/voter-stake-registry-hooks/src/hooks/useRelinquishVote.ts @@ -97,10 +97,9 @@ export const useRelinquishVote = (proposal: PublicKey) => { ); const marker = markers?.[index]?.info; const markerK = voteMarkerKey(position.mint, proposal)[0]; + const instructions: TransactionInstruction[] = []; if (marker && canRelinquishVote) { - const instructions: TransactionInstruction[] = []; - if (position.isProxiedToMe) { if (marker.proxyIndex < (position.proxy?.index || 0)) { // Do not vote with a position that has been delegated to us, but voting overidden @@ -140,16 +139,19 @@ export const useRelinquishVote = (proposal: PublicKey) => { ); } - instructions.push( - await hsdProgram.methods - .trackVoteV0() - .accounts({ - proposal, - marker: markerK, - position: position.pubkey, - }) - .instruction() - ); + if (position.isDelegated) { + instructions.push( + await hsdProgram.methods + .trackVoteV0() + .accounts({ + proposal, + marker: markerK, + position: position.pubkey, + }) + .instruction() + ); + } + return instructions; }) ) diff --git a/packages/voter-stake-registry-hooks/src/hooks/useVote.ts b/packages/voter-stake-registry-hooks/src/hooks/useVote.ts index 8e4ef8833..298245860 100644 --- a/packages/voter-stake-registry-hooks/src/hooks/useVote.ts +++ b/packages/voter-stake-registry-hooks/src/hooks/useVote.ts @@ -2,16 +2,9 @@ import { useSolanaUnixNow } from "@helium/helium-react-hooks"; import { init as hsdInit } from "@helium/helium-sub-daos-sdk"; import { useProposal } from "@helium/modular-governance-hooks"; import { proxyAssignmentKey } from "@helium/nft-proxy-sdk"; -import { - Status, - batchParallelInstructions, - truthy -} from "@helium/spl-utils"; +import { Status, batchParallelInstructions, truthy } from "@helium/spl-utils"; import { init, voteMarkerKey } from "@helium/voter-stake-registry-sdk"; -import { - PublicKey, - TransactionInstruction -} from "@solana/web3.js"; +import { PublicKey, TransactionInstruction } from "@solana/web3.js"; import BN from "bn.js"; import { useCallback, useMemo } from "react"; import { useAsyncCallback } from "react-async-hook"; @@ -166,9 +159,8 @@ export const useVote = (proposalKey: PublicKey) => { const markerK = voteMarkerKey(position.mint, proposalKey)[0]; const canVote = canPositionVote(index, choice); + const instructions: TransactionInstruction[] = []; if (canVote) { - const instructions: TransactionInstruction[] = []; - if (position.isProxiedToMe) { if ( marker && @@ -215,20 +207,25 @@ export const useVote = (proposalKey: PublicKey) => { ); } - instructions.push( - await hsdProgram.methods - .trackVoteV0() - .accounts({ - proposal: proposalKey, - marker: markerK, - position: position.pubkey, - }) - .instruction() - ); + if (position.isDelegated) { + instructions.push( + await hsdProgram.methods + .trackVoteV0() + .accounts({ + proposal: proposalKey, + marker: markerK, + position: position.pubkey, + }) + .instruction() + ); + } + return instructions; }) ) - ).filter(truthy).flat(); + ) + .filter(truthy) + .flat(); if (onInstructions) { await onInstructions(instructions); diff --git a/programs/helium-sub-daos/src/instructions/delegation/claim_rewards_v1.rs b/programs/helium-sub-daos/src/instructions/delegation/claim_rewards_v1.rs index aad4abf0d..c91b33b19 100644 --- a/programs/helium-sub-daos/src/instructions/delegation/claim_rewards_v1.rs +++ b/programs/helium-sub-daos/src/instructions/delegation/claim_rewards_v1.rs @@ -134,6 +134,7 @@ pub fn handler(ctx: Context, args: ClaimRewardsArgsV0) -> Result // load the vehnt information let position = &mut ctx.accounts.position; let registrar = &ctx.accounts.registrar; + let curr_ts = registrar.clock_unix_timestamp(); let voting_mint_config = ®istrar.voting_mints[position.voting_mint_config_idx as usize]; let delegated_position = &mut ctx.accounts.delegated_position; @@ -187,13 +188,16 @@ pub fn handler(ctx: Context, args: ClaimRewardsArgsV0) -> Result .filter(|p| p.ts <= last_ts) .map(|rp| rp.proposal) .collect::>(); + // Check eligibility based on recent proposals let eligible_count = ctx .accounts .dao .recent_proposals .iter() - .filter(|&proposal| proposal_set.contains(&proposal.proposal)) + .filter(|&proposal| { + proposal_set.contains(&proposal.proposal) || proposal.is_in_progress(curr_ts) + }) .count(); let not_four_proposals = ctx.accounts.dao.recent_proposals.len() < 4 || ctx diff --git a/programs/helium-sub-daos/src/state.rs b/programs/helium-sub-daos/src/state.rs index f697cb6c6..d814bdd1c 100644 --- a/programs/helium-sub-daos/src/state.rs +++ b/programs/helium-sub-daos/src/state.rs @@ -176,6 +176,13 @@ pub struct RecentProposal { pub ts: i64, } +const ONE_WEEK: i64 = 60 * 60 * 24 * 7; +impl RecentProposal { + pub fn is_in_progress(&self, curr_ts: i64) -> bool { + self.ts + ONE_WEEK > curr_ts + } +} + impl DaoEpochInfoV0 { pub fn size() -> usize { 60 + 8 + std::mem::size_of::()