Skip to content
This repository was archived by the owner on Mar 14, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pythnetwork/pyth-sdk-js",
"version": "1.1.0",
"version": "1.2.0",
"description": "Pyth Network SDK in JS",
"homepage": "https://pyth.network",
"main": "lib/index.js",
Expand Down
25 changes: 25 additions & 0 deletions src/__tests__/PriceFeed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,28 @@ test("getMetadata returns PriceFeedMetadata as expected", () => {
})
);
});

test("getVAA returns string as expected", () => {
const data = {
ema_price: {
conf: "2",
expo: 4,
price: "3",
publish_time: 11,
},
id: "abcdef0123456789",
price: {
conf: "1",
expo: 4,
price: "10",
publish_time: 11,
},
vaa: "abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdef",
};

const priceFeed = PriceFeed.fromJson(data);

expect(priceFeed.getVAA()).toStrictEqual(
"abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdef"
);
});
17 changes: 17 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ export class PriceFeed {
* Metadata of the price
*/
metadata?: PriceFeedMetadata;
/**
* VAA of the price
*/
vaa?: string;
/**
* Price
*/
Expand All @@ -162,11 +166,13 @@ export class PriceFeed {
emaPrice: Price;
id: HexString;
metadata?: PriceFeedMetadata;
vaa?: string;
price: Price;
}) {
this.emaPrice = rawFeed.emaPrice;
this.id = rawFeed.id;
this.metadata = rawFeed.metadata;
this.vaa = rawFeed.vaa;
this.price = rawFeed.price;
}

Expand All @@ -176,6 +182,7 @@ export class PriceFeed {
emaPrice: Price.fromJson(jsonFeed.ema_price),
id: jsonFeed.id,
metadata: PriceFeedMetadata.fromJson(jsonFeed.metadata),
vaa: jsonFeed.vaa,
price: Price.fromJson(jsonFeed.price),
});
}
Expand Down Expand Up @@ -293,4 +300,14 @@ export class PriceFeed {
getMetadata(): PriceFeedMetadata | undefined {
return this.metadata;
}

/**
* Get the price feed vaa.
*
* @returns vaa in base64.
* Returns `undefined` if vaa is unavailable.
*/
getVAA(): string | undefined {
return this.vaa;
}
}
9 changes: 9 additions & 0 deletions src/schemas/PriceFeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,18 @@ export interface PriceFeed {
* Price
*/
price: Price;
/**
* VAA of the price
*/
vaa?: string;
}

/**
* Exponentially-weighted moving average Price
*
* Represents a Pyth price
*
* Price
*/
export interface Price {
/**
Expand Down Expand Up @@ -261,6 +269,7 @@ const typeMap: any = {
typ: u(undefined, r("PriceFeedMetadata")),
},
{ json: "price", js: "price", typ: r("Price") },
{ json: "vaa", js: "vaa", typ: u(undefined, "") },
],
"any"
),
Expand Down
19 changes: 12 additions & 7 deletions src/schemas/price_feed.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
"title": "PriceFeed",
"description": "Represents an aggregate price from Pyth publisher feeds.",
"type": "object",
"required": [
"id",
"price",
"ema_price"
],
"required": ["id", "price", "ema_price"],
"properties": {
"id": {
"description": "Unique identifier for this price.",
Expand All @@ -24,6 +20,10 @@
"metadata": {
"description": "Metadata of the price",
"$ref": "#/definitions/PriceFeedMetadata"
},
"vaa": {
"description": "VAA of the price",
"$ref": "#/definitions/Identifier"
}
},
"definitions": {
Expand Down Expand Up @@ -52,13 +52,18 @@
"description": "Publish Time of the price",
"type": "integer",
"format": "int64"
}
}
}
},
"PriceFeedMetadata": {
"description": "Represents metadata of a price feed.",
"type": "object",
"required": ["attestation_time", "emitter_chain", "price_service_receive_time", "sequence_number"],
"required": [
"attestation_time",
"emitter_chain",
"price_service_receive_time",
"sequence_number"
],
"properties": {
"attestation_time": {
"description": "Attestation time of the price",
Expand Down