1- import { Cluster , PublicKey } from '@solana/web3.js'
1+ import { Cluster , clusterApiUrl , PublicKey } from '@solana/web3.js'
2+
3+ export type PythCluster = Cluster | 'pythtest'
24
35/** Mapping from solana clusters to the public key of the pyth program. */
4- const clusterToPythProgramKey : Record < Cluster , string > = {
6+ const clusterToPythProgramKey : Record < PythCluster , string > = {
57 'mainnet-beta' : 'FsJ3A3u2vn5cTVofAjvy6y5kwABJAqYWpe4975bi2epH' ,
68 devnet : 'gSbePebfvPy7tRqimPoVecS2UsBvYv46ynrzWocc92s' ,
79 testnet : '8tfDNiaEyrV6Q1U4DEXrEigs9DoDtkugzFbybENEbCDz' ,
10+ pythtest : '8tfDNiaEyrV6Q1U4DEXrEigs9DoDtkugzFbybENEbCDz' ,
811}
912
1013/** Gets the public key of the Pyth program running on the given cluster. */
11- export function getPythProgramKeyForCluster ( cluster : Cluster ) : PublicKey {
14+ export function getPythProgramKeyForCluster ( cluster : PythCluster ) : PublicKey {
1215 if ( clusterToPythProgramKey [ cluster ] !== undefined ) {
1316 return new PublicKey ( clusterToPythProgramKey [ cluster ] )
1417 } else {
@@ -19,3 +22,13 @@ export function getPythProgramKeyForCluster(cluster: Cluster): PublicKey {
1922 )
2023 }
2124}
25+
26+ /** Retrieves the RPC API URL for the specified Pyth cluster */
27+ export function getPythClusterApiUrl ( cluster : PythCluster ) : string {
28+ // TODO: Add pythnet when it's ready
29+ if ( cluster === 'pythtest' ) {
30+ return 'https://api.pythtest.pyth.network'
31+ } else {
32+ return clusterApiUrl ( cluster )
33+ }
34+ }
0 commit comments