@@ -4,7 +4,7 @@ import { HermesClient } from "@pythnetwork/hermes-client";
4
4
import { PythnetClient , PythStakingClient } from "@pythnetwork/staking-sdk" ;
5
5
import { useLocalStorageValue } from "@react-hookz/web" ;
6
6
import { useConnection , useWallet } from "@solana/wallet-adapter-react" ;
7
- import { Connection , type PublicKey } from "@solana/web3.js" ;
7
+ import { Connection , PublicKey } from "@solana/web3.js" ;
8
8
import { type ComponentProps , createContext , useContext , useMemo } from "react" ;
9
9
import { useSWRConfig } from "swr" ;
10
10
@@ -65,6 +65,7 @@ const State = {
65
65
pythnetClient : PythnetClient ,
66
66
hermesClient : HermesClient ,
67
67
account : PublicKey ,
68
+ simulationPayer : PublicKey ,
68
69
allAccounts : [ PublicKey , ...PublicKey [ ] ] ,
69
70
selectAccount : ( account : PublicKey ) => void ,
70
71
mutate : ReturnType < typeof useSWRConfig > [ "mutate" ] ,
@@ -95,7 +96,13 @@ const State = {
95
96
dashboardDataCacheKey,
96
97
97
98
loadData : ( ) =>
98
- api . loadData ( client , pythnetClient , hermesClient , account ) ,
99
+ api . loadData (
100
+ client ,
101
+ pythnetClient ,
102
+ hermesClient ,
103
+ account ,
104
+ simulationPayer ,
105
+ ) ,
99
106
100
107
claim : bindApi ( api . claim ) ,
101
108
deposit : bindApi ( api . deposit ) ,
@@ -131,19 +138,25 @@ type ApiProviderProps = Omit<
131
138
> & {
132
139
pythnetRpcUrl : string ;
133
140
hermesUrl : string ;
141
+ simulationPayerAddress : string ;
134
142
} ;
135
143
136
144
export const ApiProvider = ( {
137
145
hermesUrl,
138
146
pythnetRpcUrl,
147
+ simulationPayerAddress,
139
148
...props
140
149
} : ApiProviderProps ) => {
141
- const state = useApiContext ( hermesUrl , pythnetRpcUrl ) ;
150
+ const state = useApiContext ( hermesUrl , pythnetRpcUrl , simulationPayerAddress ) ;
142
151
143
152
return < ApiContext . Provider value = { state } { ...props } /> ;
144
153
} ;
145
154
146
- const useApiContext = ( hermesUrl : string , pythnetRpcUrl : string ) => {
155
+ const useApiContext = (
156
+ hermesUrl : string ,
157
+ pythnetRpcUrl : string ,
158
+ simulationPayerAddress : string ,
159
+ ) => {
147
160
const wallet = useWallet ( ) ;
148
161
const { connection } = useConnection ( ) ;
149
162
const { isMainnet } = useNetwork ( ) ;
@@ -153,6 +166,10 @@ const useApiContext = (hermesUrl: string, pythnetRpcUrl: string) => {
153
166
( ) => new PythnetClient ( new Connection ( pythnetRpcUrl ) ) ,
154
167
[ pythnetRpcUrl ] ,
155
168
) ;
169
+ const simulationPayer = useMemo (
170
+ ( ) => new PublicKey ( simulationPayerAddress ) ,
171
+ [ simulationPayerAddress ] ,
172
+ ) ;
156
173
const pythStakingClient = useMemo (
157
174
( ) =>
158
175
wallet . publicKey && wallet . signAllTransactions && wallet . signTransaction
@@ -235,6 +252,7 @@ const useApiContext = (hermesUrl: string, pythnetRpcUrl: string) => {
235
252
pythnetClient ,
236
253
hermesClient ,
237
254
selectedAccount ?? firstAccount ,
255
+ simulationPayer ,
238
256
[ firstAccount , ...otherAccounts ] ,
239
257
( account : PublicKey ) => {
240
258
localStorageValue . set ( account . toBase58 ( ) ) ;
0 commit comments