|
|
@@ -4,7 +4,7 @@ import { HermesClient } from "@pythnetwork/hermes-client";
|
|
|
import { PythnetClient, PythStakingClient } from "@pythnetwork/staking-sdk";
|
|
|
import { useLocalStorageValue } from "@react-hookz/web";
|
|
|
import { useConnection, useWallet } from "@solana/wallet-adapter-react";
|
|
|
-import { Connection, type PublicKey } from "@solana/web3.js";
|
|
|
+import { Connection, PublicKey } from "@solana/web3.js";
|
|
|
import { type ComponentProps, createContext, useContext, useMemo } from "react";
|
|
|
import { useSWRConfig } from "swr";
|
|
|
|
|
|
@@ -65,6 +65,7 @@ const State = {
|
|
|
pythnetClient: PythnetClient,
|
|
|
hermesClient: HermesClient,
|
|
|
account: PublicKey,
|
|
|
+ simulationPayer: PublicKey,
|
|
|
allAccounts: [PublicKey, ...PublicKey[]],
|
|
|
selectAccount: (account: PublicKey) => void,
|
|
|
mutate: ReturnType<typeof useSWRConfig>["mutate"],
|
|
|
@@ -95,7 +96,13 @@ const State = {
|
|
|
dashboardDataCacheKey,
|
|
|
|
|
|
loadData: () =>
|
|
|
- api.loadData(client, pythnetClient, hermesClient, account),
|
|
|
+ api.loadData(
|
|
|
+ client,
|
|
|
+ pythnetClient,
|
|
|
+ hermesClient,
|
|
|
+ account,
|
|
|
+ simulationPayer,
|
|
|
+ ),
|
|
|
|
|
|
claim: bindApi(api.claim),
|
|
|
deposit: bindApi(api.deposit),
|
|
|
@@ -131,19 +138,25 @@ type ApiProviderProps = Omit<
|
|
|
> & {
|
|
|
pythnetRpcUrl: string;
|
|
|
hermesUrl: string;
|
|
|
+ simulationPayerAddress: string;
|
|
|
};
|
|
|
|
|
|
export const ApiProvider = ({
|
|
|
hermesUrl,
|
|
|
pythnetRpcUrl,
|
|
|
+ simulationPayerAddress,
|
|
|
...props
|
|
|
}: ApiProviderProps) => {
|
|
|
- const state = useApiContext(hermesUrl, pythnetRpcUrl);
|
|
|
+ const state = useApiContext(hermesUrl, pythnetRpcUrl, simulationPayerAddress);
|
|
|
|
|
|
return <ApiContext.Provider value={state} {...props} />;
|
|
|
};
|
|
|
|
|
|
-const useApiContext = (hermesUrl: string, pythnetRpcUrl: string) => {
|
|
|
+const useApiContext = (
|
|
|
+ hermesUrl: string,
|
|
|
+ pythnetRpcUrl: string,
|
|
|
+ simulationPayerAddress: string,
|
|
|
+) => {
|
|
|
const wallet = useWallet();
|
|
|
const { connection } = useConnection();
|
|
|
const { isMainnet } = useNetwork();
|
|
|
@@ -153,6 +166,10 @@ const useApiContext = (hermesUrl: string, pythnetRpcUrl: string) => {
|
|
|
() => new PythnetClient(new Connection(pythnetRpcUrl)),
|
|
|
[pythnetRpcUrl],
|
|
|
);
|
|
|
+ const simulationPayer = useMemo(
|
|
|
+ () => new PublicKey(simulationPayerAddress),
|
|
|
+ [simulationPayerAddress],
|
|
|
+ );
|
|
|
const pythStakingClient = useMemo(
|
|
|
() =>
|
|
|
wallet.publicKey && wallet.signAllTransactions && wallet.signTransaction
|
|
|
@@ -235,6 +252,7 @@ const useApiContext = (hermesUrl: string, pythnetRpcUrl: string) => {
|
|
|
pythnetClient,
|
|
|
hermesClient,
|
|
|
selectedAccount ?? firstAccount,
|
|
|
+ simulationPayer,
|
|
|
[firstAccount, ...otherAccounts],
|
|
|
(account: PublicKey) => {
|
|
|
localStorageValue.set(account.toBase58());
|