Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
guibescos committed Nov 16, 2023
1 parent 057a403 commit b5a4781
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 26 deletions.
6 changes: 3 additions & 3 deletions hooks/queries/governancePower.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ export const getNftGovpower = async (
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)
const pythClient = await PythClient.connect(connection, new NodeWallet(new Keypair()))
const stakeAccount = await pythClient.getMainAccount(user)

if (stakeAccount){
return stakeAccount.getVoterWeight(await pythClient.stakeConnection.getTime()).toBN()
return stakeAccount.getVoterWeight(await pythClient.getTime()).toBN()
}
else {
return new BN(0)
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.6",
"@pythnetwork/staking": "^2.0.0",
"@radix-ui/react-accordion": "1.0.0",
"@radix-ui/react-aspect-ratio": "1.0.0",
"@radix-ui/react-dialog": "1.0.0",
Expand Down
10 changes: 3 additions & 7 deletions stores/useVotePluginsClientStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -241,16 +241,12 @@ const useVotePluginsClientStore = create<UseVotePluginsClientStore>(
})
},
handleSetPythClient: async (wallet, connection) => {
const options = AnchorProvider.defaultOptions()
const provider = new AnchorProvider(
connection.current,
(wallet as unknown) as Wallet,
options
)
const pythClient = await PythClient.connect(provider, 'devnet')
if (wallet) {
const pythClient = await PythClient.connect(connection.current, wallet as unknown as Wallet)
set((s) => {
s.state.pythClient = pythClient
})
}
},
})
)
Expand Down
17 changes: 6 additions & 11 deletions utils/uiTypes/VotePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,11 @@ export class VotingClient {
): Promise<ProgramAddresses | undefined> => {
if (this.noClient) return
const realm = this.realm!
const torAccount =
this.client instanceof PythClient
? await fetchTokenOwnerRecordByPubkey(
this.client.stakeConnection.program.provider.connection,
tokenOwnerRecord
)
: await fetchTokenOwnerRecordByPubkey(
const torAccount = await fetchTokenOwnerRecordByPubkey(
this.client!.program.provider.connection,
tokenOwnerRecord
)

console.log(this.client)

if (!torAccount.result) return
Expand Down Expand Up @@ -331,14 +326,14 @@ export class VotingClient {
return { voterWeightPk, maxVoterWeightRecord: undefined }
}
if (this.client instanceof PythClient) {
const stakeAccount = await this.client!.stakeConnection.getMainAccount(
const stakeAccount = await this.client!.getMainAccount(
walletPk
)

const {
voterWeightAccount,
maxVoterWeightRecord,
} = await this.client.stakeConnection.withUpdateVoterWeight(
} = await this.client.withUpdateVoterWeight(
instructions,
stakeAccount!,
{ [type]: {} },
Expand Down Expand Up @@ -469,14 +464,14 @@ export class VotingClient {
}

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

const {
voterWeightAccount,
maxVoterWeightRecord,
} = await this.client.stakeConnection.withUpdateVoterWeight(
} = await this.client.withUpdateVoterWeight(
instructions,
stakeAccount!,
{ ['castVote']: {} },
Expand Down
8 changes: 4 additions & 4 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.6":
version "1.3.6"
resolved "https://registry.yarnpkg.com/@pythnetwork/staking/-/staking-1.3.6.tgz#861f38a88f6744f953ac2ef96fb758d6db01b755"
integrity sha512-M5bigpcM97AHHLFYl0Y9HLWP3KRPcymW20Fg/tcukvs6ivFAcw1SLWDRlR6qMYQ9QFaMa5mmy7SIOMQrdcLJJg==
"@pythnetwork/staking@^2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@pythnetwork/staking/-/staking-2.0.0.tgz#41edcb000a3c2d1db938a3017dae46f54aac061e"
integrity sha512-7RPcsYfEJxGZ12P+OyQ1lfXxgcoe69N0Zftj525GaxUDMBvCXtNSQM+FuskF8y/GKHifZ+CDI8eP3w26gv0ZzQ==
dependencies:
"@project-serum/anchor" "0.24.2"
"@pythnetwork/staking-wasm" "*"
Expand Down

0 comments on commit b5a4781

Please sign in to comment.