Skip to content

Commit

Permalink
This works
Browse files Browse the repository at this point in the history
  • Loading branch information
guibescos committed Nov 12, 2023
1 parent 831ed69 commit 34a8514
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 26 deletions.
13 changes: 7 additions & 6 deletions actions/createProposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,20 @@ export const createProposal = async (

const voteType = isMulti
? VoteType.MULTI_CHOICE(
MultiChoiceType.FullWeight,
1,
options.length,
options.length
)
MultiChoiceType.FullWeight,
1,
options.length,
options.length
)
: VoteType.SINGLE_CHOICE

//will run only if plugin is connected with realm
const plugin = await client?.withUpdateVoterWeightRecord(
instructions,
tokenOwnerRecord.pubkey,
'createProposal',
createNftTicketsIxs
createNftTicketsIxs,
governance
)

const proposalAddress = await withCreateProposal(
Expand Down
10 changes: 8 additions & 2 deletions hooks/queries/governancePower.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
GATEWAY_PLUGINS_PKS,
HELIUM_VSR_PLUGINS_PKS,
NFT_PLUGINS_PKS,
PYTH_PLUGIN_PK,
VSR_PLUGIN_PKS,
} from '@constants/plugins'
import useHeliumVsrStore from 'HeliumVotePlugin/hooks/useHeliumVsrStore'
Expand Down Expand Up @@ -126,7 +127,8 @@ export const determineVotingPowerType = async (
? 'NFT'
: GATEWAY_PLUGINS_PKS.includes(programId.toString())
? 'gateway'
: 'pyth'
: PYTH_PLUGIN_PK.includes(programId.toString()) ? "pyth"
: "unknown"
}

export const useGovernancePowerAsync = (
Expand Down Expand Up @@ -216,7 +218,11 @@ export const useLegacyVoterWeight = () => {
: shouldCareAboutCouncil === true && councilTOR === undefined
? undefined
: plugin === 'pyth'
? new VoteRegistryVoterWeight(communityTOR.result, councilTOR?.result, new BN(1000000000000000))
? new VoteRegistryVoterWeight(
communityTOR.result,
councilTOR?.result,
new BN(1000000000000000)
)
: plugin === 'NFT'
? communityTOR.result?.pubkey
? new VoteNftWeight(
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"@project-serum/serum": "0.13.65",
"@project-serum/sol-wallet-adapter": "0.2.6",
"@pythnetwork/client": "2.17.0",
"@pythnetwork/staking": "^1.3.2",
"@pythnetwork/staking": "^1.3.5",
"@radix-ui/react-accordion": "1.0.0",
"@radix-ui/react-aspect-ratio": "1.0.0",
"@radix-ui/react-dialog": "1.0.0",
Expand Down
6 changes: 3 additions & 3 deletions stores/useVotePluginsClientStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { HeliumVsrClient } from 'HeliumVotePlugin/sdk/client'
import { Registrar as HeliumVsrRegistrar } from 'HeliumVotePlugin/sdk/types'
import * as heliumVsrSdk from '@helium/voter-stake-registry-sdk'
import { NftVoterClient } from '@utils/uiTypes/NftVoterClient'
import { PythClient } from "@pythnetwork/staking"
import { PythClient } from '@pythnetwork/staking'

interface UseVotePluginsClientStore extends State {
state: {
Expand Down Expand Up @@ -247,11 +247,11 @@ const useVotePluginsClientStore = create<UseVotePluginsClientStore>(
(wallet as unknown) as Wallet,
options
)
const pythClient = await PythClient.connect(provider, "devnet")
const pythClient = await PythClient.connect(provider, 'devnet')
set((s) => {
s.state.pythClient = pythClient
})
}
},
})
)

Expand Down
55 changes: 51 additions & 4 deletions utils/uiTypes/VotePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import { NftVoter } from 'idls/nft_voter'
import { NftVoterV2 } from 'idls/nft_voter_v2'
import { Program } from '@project-serum/anchor'
import { fetchTokenOwnerRecordByPubkey } from '@hooks/queries/tokenOwnerRecord'
import { PythClient } from "@pythnetwork/staking"
import { PythClient } from '@pythnetwork/staking'

export type UpdateVoterWeightRecordTypes =
| 'castVote'
Expand All @@ -78,6 +78,7 @@ export enum VotingClientType {
HeliumVsrClient,
NftVoterClient,
GatewayClient,
PythClient,
}

export class AccountData {
Expand Down Expand Up @@ -150,21 +151,26 @@ export class VotingClient {
this.clientType = VotingClientType.GatewayClient
this.noClient = false
}
if (this.client instanceof PythClient) {
this.clientType = VotingClientType.PythClient
this.noClient = false
}
}
withUpdateVoterWeightRecord = async (
instructions: TransactionInstruction[],
tokenOwnerRecord: PublicKey,
type: UpdateVoterWeightRecordTypes,
createNftActionTicketIxs?: TransactionInstruction[]
createNftActionTicketIxs?: TransactionInstruction[],
voterWeightTarget?: PublicKey
): Promise<ProgramAddresses | undefined> => {
if (this.noClient) return

const realm = this.realm!
const torAccount = await fetchTokenOwnerRecordByPubkey(
this.client!.program.provider.connection,
this.client!.stakeConnection.program.provider.connection, // FIX ME
tokenOwnerRecord
)
console.log(this.client)

if (!torAccount.result) return
if (
!realm.account.communityMint.equals(
Expand Down Expand Up @@ -318,6 +324,26 @@ export class VotingClient {
instructions.push(updateVoterWeightRecordIx)
return { voterWeightPk, maxVoterWeightRecord: undefined }
}
if (this.client instanceof PythClient) {
const stakeAccount = await this.client!.stakeConnection.getMainAccount(
walletPk
)

const {
voterWeightAccount,
maxVoterWeightRecord,
} = await this.client.stakeConnection.withUpdateVoterWeight(
instructions,
stakeAccount!,
{ [type]: {} },
voterWeightTarget
)

return {
voterWeightPk: voterWeightAccount,
maxVoterWeightRecord,
}
}
}
withCastPluginVote = async (
instructions: TransactionInstruction[],
Expand Down Expand Up @@ -436,6 +462,27 @@ export class VotingClient {
}
}

if (this.client instanceof PythClient) {
const stakeAccount = await this.client!.stakeConnection.getMainAccount(
walletPk
)

const {
voterWeightAccount,
maxVoterWeightRecord,
} = await this.client.stakeConnection.withUpdateVoterWeight(
instructions,
stakeAccount!,
{ ['castVote']: {} },
proposal.pubkey
)

return {
voterWeightPk: voterWeightAccount,
maxVoterWeightRecord,
}
}

if (this.client instanceof NftVoterClient) {
const { registrar } = await getPluginRegistrarPDA(
realm.pubkey,
Expand Down
20 changes: 10 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3598,17 +3598,22 @@
"@coral-xyz/anchor" "^0.26.0"
"buffer" "^6.0.1"

"@pythnetwork/staking@^1.3.2":
"integrity" "sha512-N6I+IfvbcE7b/8LjgdRfYZykXFGbg3OlkyJ/z3gnlfG96UIPljLGlQtjex64o3/VFP5U0WL2KgKcF7fGg0x1DA=="
"resolved" "https://registry.npmjs.org/@pythnetwork/staking/-/staking-1.3.2.tgz"
"version" "1.3.2"
"@pythnetwork/staking-wasm@*":
"integrity" "sha512-0ZdaWmueVO5hucdVH4UDfHyBuxtW6UDcrpEFtD/3pq4naQjcgu1u6rK8iL2pgKi8W2UlsB4vwJqay2Sf1sA4mw=="
"resolved" "https://registry.npmjs.org/@pythnetwork/staking-wasm/-/staking-wasm-0.3.4.tgz"
"version" "0.3.4"

"@pythnetwork/staking@^1.3.5":
"integrity" "sha512-g9mZ1H72RjpuWgSzK+7/R6LB5PddCr770XOOajpU0nQxHBdim+777PKH7aZ4aYbMyU+vKQ8dWgYmyxgjRttIHw=="
"resolved" "https://registry.npmjs.org/@pythnetwork/staking/-/staking-1.3.5.tgz"
"version" "1.3.5"
dependencies:
"@project-serum/anchor" "0.24.2"
"@pythnetwork/staking-wasm" "*"
"@solana/spl-governance" "0.3.26"
"@solana/spl-token" "^0.1.8"
"@solana/web3.js" "^1.36.0"
"encoding" "^0.1.13"
"pyth-staking-wasm" "*"
"ts-node" "^10.7.0"
"typescript" "^4.3.5"

Expand Down Expand Up @@ -15502,11 +15507,6 @@
"postcss" "^8.3.5"
"postcss-selector-parser" "^6.0.6"

"pyth-staking-wasm@*":
"integrity" "sha512-cRjsQFsUngazwbRZyZBs0y2gcu9OHfnQFEmUW0cq9fjZWla7a3zMXGDayQbBDs4gzCPP3Fuk584SJZQpGHQrfA=="
"resolved" "https://registry.npmjs.org/pyth-staking-wasm/-/pyth-staking-wasm-0.4.0.tgz"
"version" "0.4.0"

"[email protected]":
"integrity" "sha512-ModRIiW6oUnsP18QzrRYZSc/CFKFKIdj7pUs57AEVH20ajlglRpN3HukjHk0UbNMTlKGuaYl7Gt6/O5Gg2NU2Q=="
"resolved" "https://registry.npmjs.org/qr-code-styling/-/qr-code-styling-1.6.0-rc.1.tgz"
Expand Down

0 comments on commit 34a8514

Please sign in to comment.