Skip to content

Commit 8937c1c

Browse files
authored
add pythtest cluster support (#35)
* add pythtest cluster support * fix linting error
1 parent a569722 commit 8937c1c

File tree

5 files changed

+30
-12
lines changed

5 files changed

+30
-12
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 2.7.2
4+
### Changed
5+
- Added pythtest program key and cluster url
6+
- Updated examples to work with pythtest
7+
38
## 2.7.1
49
Moved solana/web3 to peerDependencies
510

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pythnetwork/client",
3-
"version": "2.7.1",
3+
"version": "2.7.2",
44
"description": "Client for consuming Pyth price data",
55
"homepage": "https://pyth.network",
66
"main": "lib/index.js",

src/cluster.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
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+
}

src/example_http_usage.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { Cluster, clusterApiUrl, Connection } from '@solana/web3.js'
2-
import { getPythProgramKeyForCluster } from './cluster'
1+
import { Connection } from '@solana/web3.js'
2+
import { getPythClusterApiUrl, getPythProgramKeyForCluster, PythCluster } from './cluster'
33
import { PriceStatus, PythHttpClient } from '.'
44

5-
const SOLANA_CLUSTER_NAME: Cluster = 'mainnet-beta'
6-
const connection = new Connection(clusterApiUrl(SOLANA_CLUSTER_NAME))
5+
const SOLANA_CLUSTER_NAME: PythCluster = 'mainnet-beta'
6+
const connection = new Connection(getPythClusterApiUrl(SOLANA_CLUSTER_NAME))
77
const pythPublicKey = getPythProgramKeyForCluster(SOLANA_CLUSTER_NAME)
88

99
async function runQuery(): Promise<void> {

src/example_ws_usage.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { Cluster, clusterApiUrl, Connection } from '@solana/web3.js'
1+
import { Connection } from '@solana/web3.js'
22
import { PythConnection } from './PythConnection'
3-
import { getPythProgramKeyForCluster } from './cluster'
3+
import { getPythClusterApiUrl, getPythProgramKeyForCluster, PythCluster } from './cluster'
44
import { PriceStatus } from '.'
55

6-
const SOLANA_CLUSTER_NAME: Cluster = 'mainnet-beta'
7-
const connection = new Connection(clusterApiUrl(SOLANA_CLUSTER_NAME))
6+
const SOLANA_CLUSTER_NAME: PythCluster = 'mainnet-beta'
7+
const connection = new Connection(getPythClusterApiUrl(SOLANA_CLUSTER_NAME))
88
const pythPublicKey = getPythProgramKeyForCluster(SOLANA_CLUSTER_NAME)
99

1010
const pythConnection = new PythConnection(connection, pythPublicKey)

0 commit comments

Comments
 (0)