Skip to content

Commit d14e733

Browse files
authored
restructure drv2 and add minPublishers field to PriceData (#13)
* restructure drv2 and add minPublishers field to PriceData * update version to 2.5.0 * update CHANGELOG.md * update README.md
1 parent 6e7e54f commit d14e733

File tree

4 files changed

+41
-13
lines changed

4 files changed

+41
-13
lines changed

CHANGELOG.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,26 @@
11
# Changelog
22

3+
### 2.5.0
4+
5+
### Changed
6+
7+
Restructure `drv2` field in `PriceData` to `minPublishers` and other future drv values
8+
9+
### 2.4.0
10+
11+
### Changed
12+
13+
Product only define `price` and `confidence` fields if it currently has a valid price
14+
15+
### Fixed
16+
17+
Memory leak in an underlying library
18+
319
### 2.3.2
420

5-
Added PythConnection
21+
### Added
22+
23+
PythConnection
624

725
## 2.2.0
826

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,4 @@ use the methods in `index.ts` to parse the on-chain data structures into Javascr
5454
In order to release a new version of this library and publish it to npm, follow these steps:
5555
1. Update `CHANGELOG.md` with a description of the changes in this version.
5656
2. Run `npm version <new version number>`. This command will update the version of the package, tag the branch in git, and push your changes to github.
57-
3. Once your change is merged into `main`, a github action will automatically publish a new version of the package to npm.
57+
3. Once your change is merged into `main`, create a release, and a github action will automatically publish a new version of the package to npm.

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.4.0",
3+
"version": "2.5.0",
44
"description": "Client for consuming Pyth price data",
55
"homepage": "https://pyth.network",
66
"main": "lib/index.js",

src/index.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,19 @@ export interface PriceData extends Base {
7878
twac: Ema
7979
drv1Component: bigint
8080
drv1: number
81-
drv2Component: bigint
81+
minPublishers: number
8282
drv2: number
83+
drv3: number
84+
drv4: number
8385
productAccountKey: PublicKey
8486
nextPriceAccountKey: PublicKey | null
8587
previousSlot: bigint
8688
previousPriceComponent: bigint
8789
previousPrice: number
8890
previousConfidenceComponent: bigint
8991
previousConfidence: number
90-
drv3Component: bigint
91-
drv3: number
92+
drv5Component: bigint
93+
drv5: number
9294
priceComponents: PriceComponent[]
9395
aggregate: Price,
9496
// The current price and confidence. The typical use of this interface is to consume these two fields.
@@ -249,8 +251,14 @@ export const parsePriceData = (data: Buffer): PriceData => {
249251
// space for future derived values
250252
const drv1Component = readBigInt64LE(data, 96)
251253
const drv1 = Number(drv1Component) * 10 ** exponent
252-
const drv2Component = readBigInt64LE(data, 104)
253-
const drv2 = Number(drv2Component) * 10 ** exponent
254+
// minimum number of publishers for status to be TRADING
255+
const minPublishers = data.readUInt8(104)
256+
// space for future derived values
257+
const drv2 = data.readInt8(105)
258+
// space for future derived values
259+
const drv3 = data.readInt16LE(106)
260+
// space for future derived values
261+
const drv4 = data.readInt32LE(108)
254262
// product id / reference account
255263
const productAccountKey = new PublicKey(data.slice(112, 144))
256264
// next price account in list
@@ -264,8 +272,8 @@ export const parsePriceData = (data: Buffer): PriceData => {
264272
const previousConfidenceComponent = readBigUInt64LE(data, 192)
265273
const previousConfidence = Number(previousConfidenceComponent) * 10 ** exponent
266274
// space for future derived values
267-
const drv3Component = readBigInt64LE(data, 200)
268-
const drv3 = Number(drv3Component) * 10 ** exponent
275+
const drv5Component = readBigInt64LE(data, 200)
276+
const drv5 = Number(drv5Component) * 10 ** exponent
269277
const aggregate = parsePriceInfo(data.slice(208, 240), exponent)
270278

271279
let price
@@ -308,17 +316,19 @@ export const parsePriceData = (data: Buffer): PriceData => {
308316
twac,
309317
drv1Component,
310318
drv1,
311-
drv2Component,
319+
minPublishers,
312320
drv2,
321+
drv3,
322+
drv4,
313323
productAccountKey,
314324
nextPriceAccountKey,
315325
previousSlot,
316326
previousPriceComponent,
317327
previousPrice,
318328
previousConfidenceComponent,
319329
previousConfidence,
320-
drv3Component,
321-
drv3,
330+
drv5Component,
331+
drv5,
322332
aggregate,
323333
priceComponents,
324334
price,

0 commit comments

Comments
 (0)