Skip to content
This repository was archived by the owner on Mar 14, 2024. It is now read-only.

Commit 6c72f1a

Browse files
authored
Merge pull request #10 from pyth-network/vaa
support vaa
2 parents 5cc03df + 241b7e5 commit 6c72f1a

File tree

6 files changed

+66
-10
lines changed

6 files changed

+66
-10
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pythnetwork/pyth-sdk-js",
3-
"version": "1.1.0",
3+
"version": "1.2.0",
44
"description": "Pyth Network SDK in JS",
55
"homepage": "https://pyth.network",
66
"main": "lib/index.js",

src/__tests__/PriceFeed.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,28 @@ test("getMetadata returns PriceFeedMetadata as expected", () => {
8484
})
8585
);
8686
});
87+
88+
test("getVAA returns string as expected", () => {
89+
const data = {
90+
ema_price: {
91+
conf: "2",
92+
expo: 4,
93+
price: "3",
94+
publish_time: 11,
95+
},
96+
id: "abcdef0123456789",
97+
price: {
98+
conf: "1",
99+
expo: 4,
100+
price: "10",
101+
publish_time: 11,
102+
},
103+
vaa: "abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdef",
104+
};
105+
106+
const priceFeed = PriceFeed.fromJson(data);
107+
108+
expect(priceFeed.getVAA()).toStrictEqual(
109+
"abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdef"
110+
);
111+
});

src/index.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ export class PriceFeed {
153153
* Metadata of the price
154154
*/
155155
metadata?: PriceFeedMetadata;
156+
/**
157+
* VAA of the price
158+
*/
159+
vaa?: string;
156160
/**
157161
* Price
158162
*/
@@ -162,11 +166,13 @@ export class PriceFeed {
162166
emaPrice: Price;
163167
id: HexString;
164168
metadata?: PriceFeedMetadata;
169+
vaa?: string;
165170
price: Price;
166171
}) {
167172
this.emaPrice = rawFeed.emaPrice;
168173
this.id = rawFeed.id;
169174
this.metadata = rawFeed.metadata;
175+
this.vaa = rawFeed.vaa;
170176
this.price = rawFeed.price;
171177
}
172178

@@ -176,6 +182,7 @@ export class PriceFeed {
176182
emaPrice: Price.fromJson(jsonFeed.ema_price),
177183
id: jsonFeed.id,
178184
metadata: PriceFeedMetadata.fromJson(jsonFeed.metadata),
185+
vaa: jsonFeed.vaa,
179186
price: Price.fromJson(jsonFeed.price),
180187
});
181188
}
@@ -293,4 +300,14 @@ export class PriceFeed {
293300
getMetadata(): PriceFeedMetadata | undefined {
294301
return this.metadata;
295302
}
303+
304+
/**
305+
* Get the price feed vaa.
306+
*
307+
* @returns vaa in base64.
308+
* Returns `undefined` if vaa is unavailable.
309+
*/
310+
getVAA(): string | undefined {
311+
return this.vaa;
312+
}
296313
}

src/schemas/PriceFeed.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,18 @@ export interface PriceFeed {
2727
* Price
2828
*/
2929
price: Price;
30+
/**
31+
* VAA of the price
32+
*/
33+
vaa?: string;
3034
}
3135

3236
/**
37+
* Exponentially-weighted moving average Price
38+
*
3339
* Represents a Pyth price
40+
*
41+
* Price
3442
*/
3543
export interface Price {
3644
/**
@@ -261,6 +269,7 @@ const typeMap: any = {
261269
typ: u(undefined, r("PriceFeedMetadata")),
262270
},
263271
{ json: "price", js: "price", typ: r("Price") },
272+
{ json: "vaa", js: "vaa", typ: u(undefined, "") },
264273
],
265274
"any"
266275
),

src/schemas/price_feed.json

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@
33
"title": "PriceFeed",
44
"description": "Represents an aggregate price from Pyth publisher feeds.",
55
"type": "object",
6-
"required": [
7-
"id",
8-
"price",
9-
"ema_price"
10-
],
6+
"required": ["id", "price", "ema_price"],
117
"properties": {
128
"id": {
139
"description": "Unique identifier for this price.",
@@ -24,6 +20,10 @@
2420
"metadata": {
2521
"description": "Metadata of the price",
2622
"$ref": "#/definitions/PriceFeedMetadata"
23+
},
24+
"vaa": {
25+
"description": "VAA of the price",
26+
"$ref": "#/definitions/Identifier"
2727
}
2828
},
2929
"definitions": {
@@ -52,13 +52,18 @@
5252
"description": "Publish Time of the price",
5353
"type": "integer",
5454
"format": "int64"
55-
}
55+
}
5656
}
5757
},
5858
"PriceFeedMetadata": {
5959
"description": "Represents metadata of a price feed.",
6060
"type": "object",
61-
"required": ["attestation_time", "emitter_chain", "price_service_receive_time", "sequence_number"],
61+
"required": [
62+
"attestation_time",
63+
"emitter_chain",
64+
"price_service_receive_time",
65+
"sequence_number"
66+
],
6267
"properties": {
6368
"attestation_time": {
6469
"description": "Attestation time of the price",

0 commit comments

Comments
 (0)