Skip to content

Commit bb2621f

Browse files
authored
Merge pull request #2629 from pyth-network/cprussin/use-wallet-to-send-tx-in-wallet-tester
fix(staking): use wallet's `sendTransaction` for wallet tester
2 parents 4574b10 + 1c277a4 commit bb2621f

File tree

5 files changed

+469
-72
lines changed

5 files changed

+469
-72
lines changed

apps/staking/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
"@next/third-parties": "catalog:",
2828
"@pythnetwork/hermes-client": "workspace:*",
2929
"@pythnetwork/known-publishers": "workspace:*",
30-
"@pythnetwork/solana-utils": "workspace:*",
3130
"@pythnetwork/staking-sdk": "workspace:*",
3231
"@react-hookz/web": "catalog:",
3332
"@solana/wallet-adapter-base": "catalog:",

apps/staking/src/components/WalletTester/index.tsx

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
import type { Idl } from "@coral-xyz/anchor";
44
import { Program, AnchorProvider } from "@coral-xyz/anchor";
55
import { WalletIcon } from "@heroicons/react/24/outline";
6-
import {
7-
TransactionBuilder,
8-
sendTransactions,
9-
} from "@pythnetwork/solana-utils";
10-
import type { AnchorWallet } from "@solana/wallet-adapter-react";
6+
import type { PythStakingWallet } from "@pythnetwork/staking-sdk";
117
import { useConnection } from "@solana/wallet-adapter-react";
128
import { useWalletModal } from "@solana/wallet-adapter-react-ui";
13-
import { PublicKey, Connection } from "@solana/web3.js";
9+
import {
10+
PublicKey,
11+
Connection,
12+
VersionedTransaction,
13+
TransactionMessage,
14+
} from "@solana/web3.js";
1415
import type { ComponentProps } from "react";
1516
import { useCallback } from "react";
1617

@@ -101,7 +102,7 @@ const ConnectWallet = ({ isLoading }: { isLoading?: boolean | undefined }) => {
101102
);
102103
};
103104

104-
const WalletConnected = ({ wallet }: { wallet: AnchorWallet }) => {
105+
const WalletConnected = ({ wallet }: { wallet: PythStakingWallet }) => {
105106
const { connection } = useConnection();
106107

107108
const testedStatus = useData(
@@ -139,7 +140,7 @@ const WalletConnected = ({ wallet }: { wallet: AnchorWallet }) => {
139140
}
140141
};
141142

142-
const Tester = ({ wallet }: { wallet: AnchorWallet }) => {
143+
const Tester = ({ wallet }: { wallet: PythStakingWallet }) => {
143144
const toast = useToast();
144145
const { connection } = useConnection();
145146
const { state, execute } = useAsync(() => testWallet(connection, wallet));
@@ -195,7 +196,7 @@ const Tester = ({ wallet }: { wallet: AnchorWallet }) => {
195196

196197
const getHasAlreadyTested = async (
197198
connection: Connection,
198-
wallet: AnchorWallet,
199+
wallet: PythStakingWallet,
199200
) => {
200201
const receiptAddress = PublicKey.findProgramAddressSync(
201202
[wallet.publicKey.toBytes()],
@@ -205,28 +206,28 @@ const getHasAlreadyTested = async (
205206
return { hasTested: receipt !== null };
206207
};
207208

208-
const testWallet = async (connection: Connection, wallet: AnchorWallet) => {
209+
const testWallet = async (
210+
connection: Connection,
211+
wallet: PythStakingWallet,
212+
) => {
209213
const walletTester = new Program(
210214
WalletTesterIDL as Idl,
211215
new AnchorProvider(connection, wallet),
212216
);
213217
const testMethod = walletTester.methods.test;
214218
if (testMethod) {
215-
await sendTransactions(
216-
await TransactionBuilder.batchIntoVersionedTransactions(
217-
wallet.publicKey,
218-
connection,
219-
[
220-
{
221-
instruction: await testMethod().instruction(),
222-
signers: [],
223-
},
224-
],
225-
{},
226-
),
227-
connection,
228-
wallet,
219+
const instruction = await testMethod().instruction();
220+
const { blockhash } = await connection.getLatestBlockhash({
221+
commitment: "confirmed",
222+
});
223+
const transaction = new VersionedTransaction(
224+
new TransactionMessage({
225+
payerKey: wallet.publicKey,
226+
recentBlockhash: blockhash,
227+
instructions: [instruction],
228+
}).compileToV0Message(),
229229
);
230+
await wallet.sendTransaction(transaction, connection);
230231
} else {
231232
throw new Error("No test method found in program");
232233
}

apps/staking/src/hooks/use-api.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
"use client";
22

33
import { HermesClient } from "@pythnetwork/hermes-client";
4+
import type { PythStakingWallet } from "@pythnetwork/staking-sdk";
45
import { PythnetClient, PythStakingClient } from "@pythnetwork/staking-sdk";
56
import { useLocalStorageValue } from "@react-hookz/web";
6-
import type { AnchorWallet } from "@solana/wallet-adapter-react";
77
import { useConnection, useWallet } from "@solana/wallet-adapter-react";
88
import { Connection, PublicKey } from "@solana/web3.js";
99
import type { ComponentProps } from "react";
@@ -36,18 +36,18 @@ const State = {
3636
type: StateType.WalletConnecting as const,
3737
}),
3838

39-
[StateType.NotLoaded]: (wallet: AnchorWallet) => ({
39+
[StateType.NotLoaded]: (wallet: PythStakingWallet) => ({
4040
type: StateType.NotLoaded as const,
4141
wallet,
4242
}),
4343

44-
[StateType.LoadingStakeAccounts]: (wallet: AnchorWallet) => ({
44+
[StateType.LoadingStakeAccounts]: (wallet: PythStakingWallet) => ({
4545
type: StateType.LoadingStakeAccounts as const,
4646
wallet,
4747
}),
4848

4949
[StateType.LoadedNoStakeAccount]: (
50-
wallet: AnchorWallet,
50+
wallet: PythStakingWallet,
5151
isMainnet: boolean,
5252
client: PythStakingClient,
5353
pythnetClient: PythnetClient,
@@ -68,7 +68,7 @@ const State = {
6868
}),
6969

7070
[StateType.Loaded]: (
71-
wallet: AnchorWallet,
71+
wallet: PythStakingWallet,
7272
isMainnet: boolean,
7373
client: PythStakingClient,
7474
pythnetClient: PythnetClient,
@@ -130,7 +130,7 @@ const State = {
130130
},
131131

132132
[StateType.ErrorLoadingStakeAccounts]: (
133-
wallet: AnchorWallet,
133+
wallet: PythStakingWallet,
134134
error: LoadStakeAccountsError,
135135
reset: () => void,
136136
) => ({

governance/pyth_staking_sdk/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ export * from "./utils/clock.js";
77
export * from "./utils/pool.js";
88
export * from "./utils/position.js";
99
export * from "./utils/vesting.js";
10+
export * from "./utils/wallet.js";

0 commit comments

Comments
 (0)