Skip to content

Commit

Permalink
Remove placeholders
Browse files Browse the repository at this point in the history
  • Loading branch information
guibescos committed Nov 16, 2023
1 parent 47a71b1 commit c0d103c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
23 changes: 20 additions & 3 deletions hooks/queries/governancePower.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
VoterWeight,
} from '@models/voteWeights'
import { useConnection } from '@solana/wallet-adapter-react'
import { Connection, PublicKey } from '@solana/web3.js'
import { Connection, Keypair, PublicKey } from '@solana/web3.js'
import { getNetworkFromEndpoint } from '@utils/connection'
import useGatewayPluginStore from 'GatewayPlugin/store/gatewayPluginStore'
import useHeliumVsrStore from 'HeliumVotePlugin/hooks/useHeliumVsrStore'
Expand All @@ -36,6 +36,9 @@ import {
useUserCommunityTokenOwnerRecord,
useUserCouncilTokenOwnerRecord,
} from './tokenOwnerRecord'
import { PythClient } from '@pythnetwork/staking'
import { AnchorProvider } from '@coral-xyz/anchor'
import NodeWallet from '@coral-xyz/anchor/dist/cjs/nodewallet'

export const getVanillaGovpower = async (
connection: Connection,
Expand Down Expand Up @@ -103,6 +106,20 @@ export const getNftGovpower = async (
return power
}

export const getPythGovPower = async (connection: Connection, user : PublicKey | undefined) : Promise<BN> => {
if (!user) return new BN(0)

const pythClient = await PythClient.connect(new AnchorProvider(connection, new NodeWallet(new Keypair()), {}), "mainnet-beta")
const stakeAccount = await pythClient.stakeConnection.getMainAccount(user)

if (stakeAccount){
return stakeAccount.getVoterWeight(await pythClient.stakeConnection.getTime()).toBN()
}
else {
return new BN(0)
}
}

export const findPluginName = (programId: PublicKey | undefined) =>
programId === undefined
? ('vanilla' as const)
Expand Down Expand Up @@ -186,7 +203,7 @@ export const useGovernancePowerAsync = (
: plugin === 'gateway'
? gatewayVotingPower
: plugin === 'pyth'
? new BN(1000000000000000)
? getPythGovPower(connection, actingAsWalletPk)
: new BN(0)),
[
plugin,
Expand Down Expand Up @@ -239,7 +256,7 @@ export const useLegacyVoterWeight = () => {
? new VoteRegistryVoterWeight(
communityTOR.result,
councilTOR?.result,
new BN(1000000000000000)
await getPythGovPower(connection, actingAsWalletPk)
)
: plugin === 'NFT'
? communityTOR.result?.pubkey
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.5",
"@pythnetwork/staking": "^1.3.6",
"@radix-ui/react-accordion": "1.0.0",
"@radix-ui/react-aspect-ratio": "1.0.0",
"@radix-ui/react-dialog": "1.0.0",
Expand Down
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2935,10 +2935,10 @@
resolved "https://registry.yarnpkg.com/@pythnetwork/staking-wasm/-/staking-wasm-0.3.4.tgz#29c0f47467249a4c66814a8aab9eadf2cc008add"
integrity sha512-0ZdaWmueVO5hucdVH4UDfHyBuxtW6UDcrpEFtD/3pq4naQjcgu1u6rK8iL2pgKi8W2UlsB4vwJqay2Sf1sA4mw==

"@pythnetwork/staking@^1.3.5":
version "1.3.5"
resolved "https://registry.yarnpkg.com/@pythnetwork/staking/-/staking-1.3.5.tgz#62131bfde650765ddc832dfb72ac3bf01440cc40"
integrity sha512-g9mZ1H72RjpuWgSzK+7/R6LB5PddCr770XOOajpU0nQxHBdim+777PKH7aZ4aYbMyU+vKQ8dWgYmyxgjRttIHw==
"@pythnetwork/staking@^1.3.6":
version "1.3.6"
resolved "https://registry.yarnpkg.com/@pythnetwork/staking/-/staking-1.3.6.tgz#861f38a88f6744f953ac2ef96fb758d6db01b755"
integrity sha512-M5bigpcM97AHHLFYl0Y9HLWP3KRPcymW20Fg/tcukvs6ivFAcw1SLWDRlR6qMYQ9QFaMa5mmy7SIOMQrdcLJJg==
dependencies:
"@project-serum/anchor" "0.24.2"
"@pythnetwork/staking-wasm" "*"
Expand Down Expand Up @@ -6218,12 +6218,12 @@ ansi-escapes@^4.2.1:
dependencies:
type-fest "^0.21.3"

ansi-regex@3.0.1:
ansi-regex@3.0.1, ansi-regex@^2.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-3.0.1.tgz#123d6479e92ad45ad897d4054e3c7ca7db4944e1"
integrity sha512-+O9Jct8wf++lXxxFc4hc8LsjaSq0HFzzL7cVsw8pRDIPdjKD2mT4ytDZlLuSBZ4cLKZFXIrMGO7DbQCtMJJMKw==

"ansi-regex@>=3.0.1 <=5.0.1", ansi-regex@^2.0.0, ansi-regex@^3.0.0, ansi-regex@^4.1.0, ansi-regex@^5.0.0, ansi-regex@^5.0.1:
"ansi-regex@>=3.0.1 <=5.0.1", ansi-regex@^3.0.0, ansi-regex@^4.1.0, ansi-regex@^5.0.0, ansi-regex@^5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.1.tgz#082cb2c89c9fe8659a311a53bd6a4dc5301db304"
integrity sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==
Expand Down

0 comments on commit c0d103c

Please sign in to comment.