From b5a4781577b13055358357746bcc0cca33f1da99 Mon Sep 17 00:00:00 2001 From: Guillermo Bescos Date: Thu, 16 Nov 2023 21:17:45 +0000 Subject: [PATCH] Refactor --- hooks/queries/governancePower.ts | 6 +++--- package.json | 2 +- stores/useVotePluginsClientStore.tsx | 10 +++------- utils/uiTypes/VotePlugin.ts | 17 ++++++----------- yarn.lock | 8 ++++---- 5 files changed, 17 insertions(+), 26 deletions(-) diff --git a/hooks/queries/governancePower.ts b/hooks/queries/governancePower.ts index b50c2658b9..0300f88e54 100644 --- a/hooks/queries/governancePower.ts +++ b/hooks/queries/governancePower.ts @@ -109,11 +109,11 @@ export const getNftGovpower = async ( export const getPythGovPower = async (connection: Connection, user : PublicKey | undefined) : Promise => { 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) diff --git a/package.json b/package.json index 1189017970..5664dd71cd 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/stores/useVotePluginsClientStore.tsx b/stores/useVotePluginsClientStore.tsx index 476eadf564..c72c5d672c 100644 --- a/stores/useVotePluginsClientStore.tsx +++ b/stores/useVotePluginsClientStore.tsx @@ -241,16 +241,12 @@ const useVotePluginsClientStore = create( }) }, 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 }) + } }, }) ) diff --git a/utils/uiTypes/VotePlugin.ts b/utils/uiTypes/VotePlugin.ts index e2a02a511a..5d38ac12a2 100644 --- a/utils/uiTypes/VotePlugin.ts +++ b/utils/uiTypes/VotePlugin.ts @@ -165,16 +165,11 @@ export class VotingClient { ): Promise => { 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 @@ -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]: {} }, @@ -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']: {} }, diff --git a/yarn.lock b/yarn.lock index cac3475179..d17174004e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" "*"