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

Commit

Permalink
Abehjati/add-receive-time-metadata (#9)
Browse files Browse the repository at this point in the history
* Add receive time metadata

* Bump version to 1.1

This is not a breaking change

* Rename field to be more clear
  • Loading branch information
ali-bahjati authored Oct 24, 2022
1 parent c771175 commit 5cc03df
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 6 deletions.
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.0.0",
"version": "1.1.0",
"description": "Pyth Network SDK in JS",
"homepage": "https://pyth.network",
"main": "lib/index.js",
Expand Down
7 changes: 5 additions & 2 deletions src/__tests__/PriceFeed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ test("getMetadata returns PriceFeedMetadata as expected", () => {
metadata: {
attestation_time: 7,
emitter_chain: 8,
sequence_number: 9,
price_service_receive_time: 9,
sequence_number: 10,
something_else: 11, // Ensuring the code is future compatible.
},
};

Expand All @@ -77,7 +79,8 @@ test("getMetadata returns PriceFeedMetadata as expected", () => {
PriceFeedMetadata.fromJson({
attestation_time: 7,
emitter_chain: 8,
sequence_number: 9,
price_service_receive_time: 9,
sequence_number: 10,
})
);
});
8 changes: 8 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ export class PriceFeedMetadata {
* Chain of the emitter
*/
emitterChain: number;
/**
* The time that the price service received the price
*/
priceServiceReceiveTime: number;
/**
* Sequence number of the price
*/
Expand All @@ -96,10 +100,12 @@ export class PriceFeedMetadata {
constructor(metadata: {
attestationTime: number;
emitterChain: number;
receiveTime: number;
sequenceNumber: number;
}) {
this.attestationTime = metadata.attestationTime;
this.emitterChain = metadata.emitterChain;
this.priceServiceReceiveTime = metadata.receiveTime;
this.sequenceNumber = metadata.sequenceNumber;
}

Expand All @@ -111,6 +117,7 @@ export class PriceFeedMetadata {
return new PriceFeedMetadata({
attestationTime: jsonFeed.attestation_time,
emitterChain: jsonFeed.emitter_chain,
receiveTime: jsonFeed.price_service_receive_time,
sequenceNumber: jsonFeed.sequence_number,
});
}
Expand All @@ -119,6 +126,7 @@ export class PriceFeedMetadata {
const jsonFeed: JsonPriceFeedMetadata = {
attestation_time: this.attestationTime,
emitter_chain: this.emitterChain,
price_service_receive_time: this.priceServiceReceiveTime,
sequence_number: this.sequenceNumber,
};
// this is done to avoid sending undefined values to the server
Expand Down
9 changes: 9 additions & 0 deletions src/schemas/PriceFeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ export interface PriceFeedMetadata {
* Chain of the emitter
*/
emitter_chain: number;
/**
* The time that the price service received the price
*/
price_service_receive_time: number;
/**
* Sequence number of the price
*/
Expand Down Expand Up @@ -273,6 +277,11 @@ const typeMap: any = {
[
{ json: "attestation_time", js: "attestation_time", typ: 0 },
{ json: "emitter_chain", js: "emitter_chain", typ: 0 },
{
json: "price_service_receive_time",
js: "price_service_receive_time",
typ: 0,
},
{ json: "sequence_number", js: "sequence_number", typ: 0 },
],
"any"
Expand Down
7 changes: 6 additions & 1 deletion src/schemas/price_feed.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"PriceFeedMetadata": {
"description": "Represents metadata of a price feed.",
"type": "object",
"required": ["attestation_time", "emitter_chain", "sequence_number"],
"required": ["attestation_time", "emitter_chain", "price_service_receive_time", "sequence_number"],
"properties": {
"attestation_time": {
"description": "Attestation time of the price",
Expand All @@ -70,6 +70,11 @@
"type": "integer",
"format": "int16"
},
"price_service_receive_time": {
"description": "The time that the price service received the price",
"type": "integer",
"format": "int64"
},
"sequence_number": {
"description": "Sequence number of the price",
"type": "integer",
Expand Down

0 comments on commit 5cc03df

Please sign in to comment.