Skip to content

Commit f8fd7ba

Browse files
authored
Release/v2.6.0 (#21)
* Update changelog + update packages * 2.6.0
1 parent 1834779 commit f8fd7ba

7 files changed

+217
-140
lines changed

CHANGELOG.md

+19-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,33 @@
11
# Changelog
22

3-
### 2.5.1
3+
## 2.6.0
4+
5+
### Added
6+
- Checks current slot when parsing a Price account and set status to unknown if price is stale. Being stale means it is not updated in `MAX_SLOT_DIFFERENCE` slots (currently 25).
7+
- Adds status field in PriceData to access the current status (considering price getting stale) easier.
8+
9+
### Changed
10+
- Converts Some type/status structs to enums to be able to use them in a cleaner way. It's backward compatible.
11+
12+
13+
## 2.5.3
14+
15+
### Fixed
16+
Updated tests for Pyth symbology change
17+
18+
## 2.5.1
419

520
### Changed
621

722
Improved error message when passing an invalid cluster name to `pythProgramKeyForCluster`
823

9-
### 2.5.0
24+
## 2.5.0
1025

1126
### Changed
1227

1328
Restructure `drv2` field in `PriceData` to `minPublishers` and other future drv values
1429

15-
### 2.4.0
30+
## 2.4.0
1631

1732
### Changed
1833

@@ -22,7 +37,7 @@ Product only define `price` and `confidence` fields if it currently has a valid
2237

2338
Memory leak in an underlying library
2439

25-
### 2.3.2
40+
## 2.3.2
2641

2742
### Added
2843

package-lock.json

+70-16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

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

src/PythHttpClient.ts

+43-43
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,96 @@
1-
import { Commitment, Connection, PublicKey } from "@solana/web3.js";
2-
import { Product, PriceData, parseProductData, parsePriceData, parseBaseData, AccountType } from ".";
1+
import { Commitment, Connection, PublicKey } from '@solana/web3.js'
2+
import { Product, PriceData, parseProductData, parsePriceData, parseBaseData, AccountType } from '.'
33

44
export interface PythHttpClientResult {
5-
assetTypes: string[];
6-
symbols: string[];
7-
products: Product[];
8-
productFromSymbol: Map<string, Product>;
9-
productPrice: Map<string, PriceData>;
10-
prices: PriceData[];
5+
assetTypes: string[]
6+
symbols: string[]
7+
products: Product[]
8+
productFromSymbol: Map<string, Product>
9+
productPrice: Map<string, PriceData>
10+
prices: PriceData[]
1111
}
1212

1313
/**
1414
* Reads Pyth price data from a solana web3 connection. This class uses a single HTTP call.
1515
* Use the method getData() to get updated prices values.
1616
*/
1717
export class PythHttpClient {
18-
connection: Connection;
19-
pythProgramKey: PublicKey;
20-
commitment: Commitment;
18+
connection: Connection
19+
pythProgramKey: PublicKey
20+
commitment: Commitment
2121

2222
constructor(connection: Connection, pythProgramKey: PublicKey, commitment: Commitment = 'finalized') {
23-
this.connection = connection;
24-
this.pythProgramKey = pythProgramKey;
25-
this.commitment = commitment;
23+
this.connection = connection
24+
this.pythProgramKey = pythProgramKey
25+
this.commitment = commitment
2626
}
2727

2828
/*
29-
* Get Pyth Network account information and return actual price state.
30-
* The result contains lists of asset types, product symbols and their prices.
31-
*/
29+
* Get Pyth Network account information and return actual price state.
30+
* The result contains lists of asset types, product symbols and their prices.
31+
*/
3232
public async getData(): Promise<PythHttpClientResult> {
33-
const assetTypes = new Set<string>();
34-
const productSymbols = new Set<string>();
33+
const assetTypes = new Set<string>()
34+
const productSymbols = new Set<string>()
3535
const products = new Set<Product>()
3636
const productFromSymbol = new Map<string, Product>()
3737
const productPrice = new Map<string, PriceData>()
38-
const prices = new Array<PriceData>();
38+
const prices = new Array<PriceData>()
3939

4040
// Retrieve data from blockchain
41-
const accountList = await this.connection.getProgramAccounts(this.pythProgramKey, this.commitment);
41+
const accountList = await this.connection.getProgramAccounts(this.pythProgramKey, this.commitment)
4242

4343
// Popolate producs and prices
44-
const priceDataQueue = new Array<PriceData>();
45-
const productAccountKeyToProduct = new Map<string, Product>();
46-
const currentSlot = await this.connection.getSlot(this.commitment);
44+
const priceDataQueue = new Array<PriceData>()
45+
const productAccountKeyToProduct = new Map<string, Product>()
46+
const currentSlot = await this.connection.getSlot(this.commitment)
4747

48-
accountList.forEach(singleAccount => {
49-
const base = parseBaseData(singleAccount.account.data);
48+
accountList.forEach((singleAccount) => {
49+
const base = parseBaseData(singleAccount.account.data)
5050
if (base) {
5151
switch (base.type) {
5252
case AccountType.Mapping:
5353
// We can skip these because we're going to get every account owned by this program anyway.
54-
break;
54+
break
5555
case AccountType.Product:
5656
const productData = parseProductData(singleAccount.account.data)
5757

5858
productAccountKeyToProduct.set(singleAccount.pubkey.toBase58(), productData.product)
59-
assetTypes.add(productData.product.asset_type);
60-
productSymbols.add(productData.product.symbol);
61-
products.add(productData.product);
62-
productFromSymbol.set(productData.product.symbol, productData.product);
63-
break;
59+
assetTypes.add(productData.product.asset_type)
60+
productSymbols.add(productData.product.symbol)
61+
products.add(productData.product)
62+
productFromSymbol.set(productData.product.symbol, productData.product)
63+
break
6464
case AccountType.Price:
6565
const priceData = parsePriceData(singleAccount.account.data, currentSlot)
6666
priceDataQueue.push(priceData)
67-
break;
67+
break
6868
case AccountType.Test:
69-
break;
69+
break
7070
default:
7171
throw new Error(`Unknown account type: ${base.type}. Try upgrading pyth-client.`)
7272
}
7373
}
74-
});
74+
})
7575

76-
priceDataQueue.forEach(priceData => {
76+
priceDataQueue.forEach((priceData) => {
7777
const product = productAccountKeyToProduct.get(priceData.productAccountKey.toBase58())
7878

7979
if (product) {
80-
productPrice.set(product.symbol, priceData);
81-
prices.push(priceData);
80+
productPrice.set(product.symbol, priceData)
81+
prices.push(priceData)
8282
}
83-
});
83+
})
8484

8585
const result: PythHttpClientResult = {
8686
assetTypes: Array.from(assetTypes),
8787
symbols: Array.from(productSymbols),
8888
products: Array.from(products),
8989
productFromSymbol,
9090
productPrice,
91-
prices
92-
};
91+
prices,
92+
}
9393

94-
return result;
94+
return result
9595
}
96-
}
96+
}

0 commit comments

Comments
 (0)