@@ -4,7 +4,7 @@ import { HermesClient } from "@pythnetwork/hermes-client";
44import { PythnetClient , PythStakingClient } from "@pythnetwork/staking-sdk" ;
55import { useLocalStorageValue } from "@react-hookz/web" ;
66import { useConnection , useWallet } from "@solana/wallet-adapter-react" ;
7- import { Connection , type PublicKey } from "@solana/web3.js" ;
7+ import { Connection , PublicKey } from "@solana/web3.js" ;
88import { type ComponentProps , createContext , useContext , useMemo } from "react" ;
99import { useSWRConfig } from "swr" ;
1010
@@ -65,6 +65,7 @@ const State = {
6565 pythnetClient : PythnetClient ,
6666 hermesClient : HermesClient ,
6767 account : PublicKey ,
68+ simulationPayer : PublicKey ,
6869 allAccounts : [ PublicKey , ...PublicKey [ ] ] ,
6970 selectAccount : ( account : PublicKey ) => void ,
7071 mutate : ReturnType < typeof useSWRConfig > [ "mutate" ] ,
@@ -95,7 +96,13 @@ const State = {
9596 dashboardDataCacheKey,
9697
9798 loadData : ( ) =>
98- api . loadData ( client , pythnetClient , hermesClient , account ) ,
99+ api . loadData (
100+ client ,
101+ pythnetClient ,
102+ hermesClient ,
103+ account ,
104+ simulationPayer ,
105+ ) ,
99106
100107 claim : bindApi ( api . claim ) ,
101108 deposit : bindApi ( api . deposit ) ,
@@ -131,19 +138,25 @@ type ApiProviderProps = Omit<
131138> & {
132139 pythnetRpcUrl : string ;
133140 hermesUrl : string ;
141+ simulationPayerAddress : string ;
134142} ;
135143
136144export const ApiProvider = ( {
137145 hermesUrl,
138146 pythnetRpcUrl,
147+ simulationPayerAddress,
139148 ...props
140149} : ApiProviderProps ) => {
141- const state = useApiContext ( hermesUrl , pythnetRpcUrl ) ;
150+ const state = useApiContext ( hermesUrl , pythnetRpcUrl , simulationPayerAddress ) ;
142151
143152 return < ApiContext . Provider value = { state } { ...props } /> ;
144153} ;
145154
146- const useApiContext = ( hermesUrl : string , pythnetRpcUrl : string ) => {
155+ const useApiContext = (
156+ hermesUrl : string ,
157+ pythnetRpcUrl : string ,
158+ simulationPayerAddress : string ,
159+ ) => {
147160 const wallet = useWallet ( ) ;
148161 const { connection } = useConnection ( ) ;
149162 const { isMainnet } = useNetwork ( ) ;
@@ -153,6 +166,10 @@ const useApiContext = (hermesUrl: string, pythnetRpcUrl: string) => {
153166 ( ) => new PythnetClient ( new Connection ( pythnetRpcUrl ) ) ,
154167 [ pythnetRpcUrl ] ,
155168 ) ;
169+ const simulationPayer = useMemo (
170+ ( ) => new PublicKey ( simulationPayerAddress ) ,
171+ [ simulationPayerAddress ] ,
172+ ) ;
156173 const pythStakingClient = useMemo (
157174 ( ) =>
158175 wallet . publicKey && wallet . signAllTransactions && wallet . signTransaction
@@ -235,6 +252,7 @@ const useApiContext = (hermesUrl: string, pythnetRpcUrl: string) => {
235252 pythnetClient ,
236253 hermesClient ,
237254 selectedAccount ?? firstAccount ,
255+ simulationPayer ,
238256 [ firstAccount , ...otherAccounts ] ,
239257 ( account : PublicKey ) => {
240258 localStorageValue . set ( account . toBase58 ( ) ) ;
0 commit comments