Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion apps/staking/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"@next/third-parties": "catalog:",
"@pythnetwork/hermes-client": "workspace:*",
"@pythnetwork/known-publishers": "workspace:*",
"@pythnetwork/solana-utils": "workspace:*",
"@pythnetwork/staking-sdk": "workspace:*",
"@react-hookz/web": "catalog:",
"@solana/wallet-adapter-base": "catalog:",
Expand Down
49 changes: 25 additions & 24 deletions apps/staking/src/components/WalletTester/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
import type { Idl } from "@coral-xyz/anchor";
import { Program, AnchorProvider } from "@coral-xyz/anchor";
import { WalletIcon } from "@heroicons/react/24/outline";
import {
TransactionBuilder,
sendTransactions,
} from "@pythnetwork/solana-utils";
import type { AnchorWallet } from "@solana/wallet-adapter-react";
import type { PythStakingWallet } from "@pythnetwork/staking-sdk";
import { useConnection } from "@solana/wallet-adapter-react";
import { useWalletModal } from "@solana/wallet-adapter-react-ui";
import { PublicKey, Connection } from "@solana/web3.js";
import {
PublicKey,
Connection,
VersionedTransaction,
TransactionMessage,
} from "@solana/web3.js";
import type { ComponentProps } from "react";
import { useCallback } from "react";

Expand Down Expand Up @@ -101,7 +102,7 @@ const ConnectWallet = ({ isLoading }: { isLoading?: boolean | undefined }) => {
);
};

const WalletConnected = ({ wallet }: { wallet: AnchorWallet }) => {
const WalletConnected = ({ wallet }: { wallet: PythStakingWallet }) => {
const { connection } = useConnection();

const testedStatus = useData(
Expand Down Expand Up @@ -139,7 +140,7 @@ const WalletConnected = ({ wallet }: { wallet: AnchorWallet }) => {
}
};

const Tester = ({ wallet }: { wallet: AnchorWallet }) => {
const Tester = ({ wallet }: { wallet: PythStakingWallet }) => {
const toast = useToast();
const { connection } = useConnection();
const { state, execute } = useAsync(() => testWallet(connection, wallet));
Expand Down Expand Up @@ -195,7 +196,7 @@ const Tester = ({ wallet }: { wallet: AnchorWallet }) => {

const getHasAlreadyTested = async (
connection: Connection,
wallet: AnchorWallet,
wallet: PythStakingWallet,
) => {
const receiptAddress = PublicKey.findProgramAddressSync(
[wallet.publicKey.toBytes()],
Expand All @@ -205,28 +206,28 @@ const getHasAlreadyTested = async (
return { hasTested: receipt !== null };
};

const testWallet = async (connection: Connection, wallet: AnchorWallet) => {
const testWallet = async (
connection: Connection,
wallet: PythStakingWallet,
) => {
const walletTester = new Program(
WalletTesterIDL as Idl,
new AnchorProvider(connection, wallet),
);
const testMethod = walletTester.methods.test;
if (testMethod) {
await sendTransactions(
await TransactionBuilder.batchIntoVersionedTransactions(
wallet.publicKey,
connection,
[
{
instruction: await testMethod().instruction(),
signers: [],
},
],
{},
),
connection,
wallet,
const instruction = await testMethod().instruction();
const { blockhash } = await connection.getLatestBlockhash({
commitment: "confirmed",
});
const transaction = new VersionedTransaction(
new TransactionMessage({
payerKey: wallet.publicKey,
recentBlockhash: blockhash,
instructions: [instruction],
}).compileToV0Message(),
);
await wallet.sendTransaction(transaction, connection);
} else {
throw new Error("No test method found in program");
}
Expand Down
12 changes: 6 additions & 6 deletions apps/staking/src/hooks/use-api.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"use client";

import { HermesClient } from "@pythnetwork/hermes-client";
import type { PythStakingWallet } from "@pythnetwork/staking-sdk";
import { PythnetClient, PythStakingClient } from "@pythnetwork/staking-sdk";
import { useLocalStorageValue } from "@react-hookz/web";
import type { AnchorWallet } from "@solana/wallet-adapter-react";
import { useConnection, useWallet } from "@solana/wallet-adapter-react";
import { Connection, PublicKey } from "@solana/web3.js";
import type { ComponentProps } from "react";
Expand Down Expand Up @@ -36,18 +36,18 @@ const State = {
type: StateType.WalletConnecting as const,
}),

[StateType.NotLoaded]: (wallet: AnchorWallet) => ({
[StateType.NotLoaded]: (wallet: PythStakingWallet) => ({
type: StateType.NotLoaded as const,
wallet,
}),

[StateType.LoadingStakeAccounts]: (wallet: AnchorWallet) => ({
[StateType.LoadingStakeAccounts]: (wallet: PythStakingWallet) => ({
type: StateType.LoadingStakeAccounts as const,
wallet,
}),

[StateType.LoadedNoStakeAccount]: (
wallet: AnchorWallet,
wallet: PythStakingWallet,
isMainnet: boolean,
client: PythStakingClient,
pythnetClient: PythnetClient,
Expand All @@ -68,7 +68,7 @@ const State = {
}),

[StateType.Loaded]: (
wallet: AnchorWallet,
wallet: PythStakingWallet,
isMainnet: boolean,
client: PythStakingClient,
pythnetClient: PythnetClient,
Expand Down Expand Up @@ -130,7 +130,7 @@ const State = {
},

[StateType.ErrorLoadingStakeAccounts]: (
wallet: AnchorWallet,
wallet: PythStakingWallet,
error: LoadStakeAccountsError,
reset: () => void,
) => ({
Expand Down
1 change: 1 addition & 0 deletions governance/pyth_staking_sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export * from "./utils/clock.js";
export * from "./utils/pool.js";
export * from "./utils/position.js";
export * from "./utils/vesting.js";
export * from "./utils/wallet.js";
Loading
Loading