Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
ChewingGlass committed Feb 25, 2025
2 parents 0e921da + 74b9cf5 commit 56147c9
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 35 deletions.
26 changes: 14 additions & 12 deletions packages/voter-stake-registry-hooks/src/hooks/useRelinquishVote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
})
)
Expand Down
41 changes: 19 additions & 22 deletions packages/voter-stake-registry-hooks/src/hooks/useVote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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 &&
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ pub fn handler(ctx: Context<ClaimRewardsV1>, 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 = &registrar.voting_mints[position.voting_mint_config_idx as usize];

let delegated_position = &mut ctx.accounts.delegated_position;
Expand Down Expand Up @@ -187,13 +188,16 @@ pub fn handler(ctx: Context<ClaimRewardsV1>, args: ClaimRewardsArgsV0) -> Result
.filter(|p| p.ts <= last_ts)
.map(|rp| rp.proposal)
.collect::<HashSet<_>>();

// 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
Expand Down
7 changes: 7 additions & 0 deletions programs/helium-sub-daos/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<DaoEpochInfoV0>()
Expand Down

0 comments on commit 56147c9

Please sign in to comment.