Skip to content

Commit

Permalink
Delegate vote fix (solana-labs#2254)
Browse files Browse the repository at this point in the history
  • Loading branch information
dankelleher authored Apr 22, 2024
1 parent 0f2c746 commit 01410f9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
15 changes: 9 additions & 6 deletions actions/castVote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
withPostChatMessage,
withCreateTokenOwnerRecord,
getVoteRecordAddress,
getTokenOwnerRecord,
} from '@solana/spl-governance'
import { ProgramAccount } from '@solana/spl-governance'
import { RpcContext } from '@solana/spl-governance'
Expand Down Expand Up @@ -62,15 +63,15 @@ const createDelegatorVote = async ({
realmPk,
proposalPk,
tokenOwnerRecordPk,
userPk,
delegatePk,
vote,
votingPlugin,
}: {
connection: Connection
realmPk: PublicKey
proposalPk: PublicKey
tokenOwnerRecordPk: PublicKey
userPk: PublicKey
delegatePk: PublicKey
vote: Vote
votingPlugin: VotingClient | undefined
}) => {
Expand Down Expand Up @@ -107,10 +108,10 @@ const createDelegatorVote = async ({
proposal.pubkey,
proposal.account.tokenOwnerRecord,
tokenOwnerRecordPk,
userPk,
delegatePk,
proposal.account.governingTokenMint,
vote,
userPk,
delegatePk,
pluginAddresses?.voterWeightPk,
pluginAddresses?.maxVoterWeightRecord
)
Expand Down Expand Up @@ -276,14 +277,16 @@ export async function castVote(
)
if (voteRecord.found) return undefined

const torOwnerPk = (await getTokenOwnerRecord(connection, tokenOwnerRecordPk)).account.governingTokenOwner

return createDelegatorVote({
connection,
realmPk: realm.pubkey,
proposalPk: proposal.pubkey,
tokenOwnerRecordPk,
userPk: walletPubkey,
delegatePk: walletPubkey,
vote,
votingPlugin: votingPlugin,
votingPlugin: votingPlugin?.for(torOwnerPk),
})
})
)
Expand Down
10 changes: 10 additions & 0 deletions utils/uiTypes/VotePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ export class VotingClient {
}
}

// Take this exact voting client, but set a different voter wallet - useful for combining delegate and delegator votes
public for(wallet: PublicKey): VotingClient {
return new VotingClient({
client: this.client,
realm: this.realm,
walletPk: wallet,
voterWeightPluginDetails: this.voterWeightPluginDetails,
})
}

private get voterWeightPk() {
return this.walletPk ? this.voterWeightPluginDetails.voterWeightPkForWallet(this.walletPk) : undefined
}
Expand Down

0 comments on commit 01410f9

Please sign in to comment.