1
- import { PythCluster } from '@pythnetwork/client/lib/cluster'
1
+ import {
2
+ PythCluster ,
3
+ getPythClusterApiUrl ,
4
+ } from '@pythnetwork/client/lib/cluster'
2
5
3
- const CLUSTER_URLS : Record < PythCluster , any > = {
6
+ const CLUSTER_URLS : Record < PythCluster , string [ ] > = {
4
7
'mainnet-beta' : [
5
- {
6
- rpcUrl : 'http://mainnet.xyz.pyth.network' ,
7
- wsUrl : 'ws://mainnet.xyz.pyth.network' ,
8
- } ,
9
- {
10
- rpcUrl :
11
- 'https://pyth-network.rpcpool.com/' +
12
- ( process . env . NEXT_PUBLIC_RPC_POOL_TOKEN || '' ) ,
13
- wsUrl :
14
- 'wss://pyth-network.rpcpool.com/' +
15
- ( process . env . NEXT_PUBLIC_RPC_POOL_TOKEN || '' ) ,
16
- } ,
17
- {
18
- rpcUrl : 'http://pyth-rpc1.certus.one:8899/' ,
19
- wsUrl : 'ws://pyth-rpc1.certus.one:8900/' ,
20
- } ,
21
- {
22
- rpcUrl : 'http://pyth-rpc2.certus.one:8899/' ,
23
- wsUrl : 'ws://pyth-rpc2.certus.one:8900/' ,
24
- } ,
25
- {
26
- rpcUrl : 'https://api.mainnet-beta.solana.com/' ,
27
- wsUrl : 'wss://api.mainnet-beta.solana.com/' ,
28
- } ,
8
+ process . env . NEXT_PUBLIC_MAINNET_RPC || getPythClusterApiUrl ( 'mainnet-beta' ) ,
9
+ 'https://pyth-network.rpcpool.com/' +
10
+ ( process . env . NEXT_PUBLIC_RPC_POOL_TOKEN || '' ) ,
11
+ 'http://pyth-rpc1.certus.one:8899/' ,
12
+ 'http://pyth-rpc2.certus.one:8899/' ,
13
+ 'https://api.mainnet-beta.solana.com/' ,
29
14
] ,
30
15
devnet : [
31
- {
32
- rpcUrl : 'http://devnet.xyz.pyth.network' ,
33
- wsUrl : 'ws://devnet.xyz.pyth.network' ,
34
- } ,
35
- {
36
- rpcUrl : 'https://api.devnet.solana.com/' ,
37
- wsUrl : 'wss://api.devnet.solana.com/' ,
38
- } ,
16
+ process . env . NEXT_PUBLIC_DEVNET_RPC || getPythClusterApiUrl ( 'devnet' ) ,
17
+ 'https://api.devnet.solana.com/' ,
39
18
] ,
40
19
testnet : [
41
- {
42
- rpcUrl : 'http://testnet.xyz.pyth.network' ,
43
- wsUrl : 'ws://testnet.xyz.pyth.network' ,
44
- } ,
45
- {
46
- rpcUrl : 'https://api.testnet.solana.com/' ,
47
- wsUrl : 'wss://api.testnet.solana.com/' ,
48
- } ,
20
+ process . env . NEXT_PUBLIC_TESTNET_RPC || getPythClusterApiUrl ( 'testnet' ) ,
21
+ 'https://api.testnet.solana.com/' ,
49
22
] ,
50
23
'pythtest-conformance' : [
51
- {
52
- rpcUrl : 'http://pythtest.xyz.pyth.network' ,
53
- wsUrl : 'ws://pythtest.xyz.pyth.network' ,
54
- } ,
55
- {
56
- rpcUrl : 'https://api.pythtest.pyth.network/' ,
57
- wsUrl : 'wss://api.pythtest.pyth.network/' ,
58
- } ,
24
+ process . env . NEXT_PUBLIC_PYTHTEST_RPC ||
25
+ getPythClusterApiUrl ( 'pythtest-conformance' ) ,
26
+ 'https://api.pythtest.pyth.network/' ,
59
27
] ,
60
28
'pythtest-crosschain' : [
61
- {
62
- rpcUrl : 'http://pythtest.xyz.pyth.network' ,
63
- wsUrl : 'ws://pythtest.xyz.pyth.network' ,
64
- } ,
65
- {
66
- rpcUrl : 'https://api.pythtest.pyth.network/' ,
67
- wsUrl : 'wss://api.pythtest.pyth.network/' ,
68
- } ,
29
+ process . env . NEXT_PUBLIC_PYTHTEST_RPC ||
30
+ getPythClusterApiUrl ( 'pythtest-crosschain' ) ,
31
+ 'https://api.pythtest.pyth.network/' ,
69
32
] ,
70
33
pythnet : [
71
- {
72
- rpcUrl : 'http://pythnet.xyz.pyth.network' ,
73
- wsUrl : 'ws://pythnet.xyz.pyth.network' ,
74
- } ,
75
- {
76
- rpcUrl : 'https://pythnet.rpcpool.com/' ,
77
- wsUrl : 'wss://pythnet.rpcpool.com/' ,
78
- } ,
79
- ] ,
80
- localnet : [
81
- {
82
- rpcUrl : 'http://localhost:8899/' ,
83
- wsUrl : 'ws://localhost:8900/' ,
84
- } ,
34
+ process . env . NEXT_PUBLIC_PYTHNET_RPC || getPythClusterApiUrl ( 'pythnet' ) ,
35
+ 'https://pythnet.rpcpool.com/' ,
85
36
] ,
37
+ localnet : [ 'http://localhost:8899/' ] ,
86
38
}
87
39
88
40
export function pythClusterApiUrls ( cluster : PythCluster ) {
@@ -92,3 +44,11 @@ export function pythClusterApiUrls(cluster: PythCluster) {
92
44
return [ ]
93
45
}
94
46
}
47
+
48
+ export function deriveWsUrl ( httpUrl : string ) {
49
+ if ( httpUrl . startsWith ( 'https://' ) ) {
50
+ return 'wss://' + httpUrl . slice ( 8 )
51
+ } else {
52
+ return 'ws://' + httpUrl . slice ( 7 )
53
+ }
54
+ }
0 commit comments