From f014e8626e10b3412f6c3d67d061d66e70ae36c3 Mon Sep 17 00:00:00 2001 From: Daniel Chew Date: Wed, 18 Jan 2023 21:49:06 +0900 Subject: [PATCH 1/5] add getVaa function --- pyth-common-js/src/PriceServiceConnection.ts | 23 ++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/pyth-common-js/src/PriceServiceConnection.ts b/pyth-common-js/src/PriceServiceConnection.ts index 781d11f..a8b052f 100644 --- a/pyth-common-js/src/PriceServiceConnection.ts +++ b/pyth-common-js/src/PriceServiceConnection.ts @@ -149,6 +149,29 @@ export class PriceServiceConnection { return response.data; } + /** + * Fetch VAA of given price id and publish time. + * This will throw an axios error if there is a network problem or the price service returns a non-ok response (e.g: Invalid price id) + * + * This function is coupled to wormhole implemntation. + * + * @param priceId Hex-encoded price id. + * @param publishTime Epoch timestamp in seconds. + * @returns Base64 encoded VAAs. + */ + async getVaa( + priceId: HexString, + publishTime: EpochTimeStamp + ): Promise { + const response = await this.httpClient.get("/api/get_vaa", { + params: { + id: priceId, + publish_time: publishTime, + }, + }); + return response.data; + } + /** * Fetch the list of available price feed ids. * This will throw an axios error if there is a network problem or the price service returns a non-ok response. From 7e3e2fc2a263db0708089f347f2a4937b247945d Mon Sep 17 00:00:00 2001 From: Daniel Chew Date: Wed, 18 Jan 2023 21:50:19 +0900 Subject: [PATCH 2/5] bump --- pyth-common-js/package-lock.json | 4 ++-- pyth-common-js/package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pyth-common-js/package-lock.json b/pyth-common-js/package-lock.json index c3fd28d..99fe1c6 100644 --- a/pyth-common-js/package-lock.json +++ b/pyth-common-js/package-lock.json @@ -1,12 +1,12 @@ { "name": "@pythnetwork/pyth-common-js", - "version": "1.3.0", + "version": "1.4.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@pythnetwork/pyth-common-js", - "version": "1.3.0", + "version": "1.4.0", "license": "Apache-2.0", "dependencies": { "@pythnetwork/pyth-sdk-js": "^1.2.0", diff --git a/pyth-common-js/package.json b/pyth-common-js/package.json index 60d2315..5082ce0 100644 --- a/pyth-common-js/package.json +++ b/pyth-common-js/package.json @@ -1,6 +1,6 @@ { "name": "@pythnetwork/pyth-common-js", - "version": "1.3.0", + "version": "1.4.0", "description": "Pyth Network Common Utils in JS", "author": { "name": "Pyth Data Association" From c04ef0537f2b13b1ad95c9330f1c18828abf3d63 Mon Sep 17 00:00:00 2001 From: Daniel Chew Date: Wed, 18 Jan 2023 22:32:30 +0900 Subject: [PATCH 3/5] address feedback --- pyth-common-js/src/PriceServiceConnection.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pyth-common-js/src/PriceServiceConnection.ts b/pyth-common-js/src/PriceServiceConnection.ts index a8b052f..8721768 100644 --- a/pyth-common-js/src/PriceServiceConnection.ts +++ b/pyth-common-js/src/PriceServiceConnection.ts @@ -150,26 +150,27 @@ export class PriceServiceConnection { } /** - * Fetch VAA of given price id and publish time. + * Fetch the earliest VAA of the given price id that is published since the given publish time. + * This will throw an error if the given publish time is in the future, or if the price service does not have a db backend. * This will throw an axios error if there is a network problem or the price service returns a non-ok response (e.g: Invalid price id) * * This function is coupled to wormhole implemntation. * * @param priceId Hex-encoded price id. * @param publishTime Epoch timestamp in seconds. - * @returns Base64 encoded VAAs. + * @returns JSON object of VAA and publishTime. */ async getVaa( priceId: HexString, publishTime: EpochTimeStamp - ): Promise { + ): Promise<[string, EpochTimeStamp]> { const response = await this.httpClient.get("/api/get_vaa", { params: { id: priceId, publish_time: publishTime, }, }); - return response.data; + return [response.data.vaa, response.data.publishTime]; } /** From eab12815605cfde2260339b0f44128b38f828bd0 Mon Sep 17 00:00:00 2001 From: Daniel Chew Date: Wed, 18 Jan 2023 22:33:05 +0900 Subject: [PATCH 4/5] fix getVaa desc --- pyth-common-js/src/PriceServiceConnection.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyth-common-js/src/PriceServiceConnection.ts b/pyth-common-js/src/PriceServiceConnection.ts index 8721768..f5b4d71 100644 --- a/pyth-common-js/src/PriceServiceConnection.ts +++ b/pyth-common-js/src/PriceServiceConnection.ts @@ -158,7 +158,7 @@ export class PriceServiceConnection { * * @param priceId Hex-encoded price id. * @param publishTime Epoch timestamp in seconds. - * @returns JSON object of VAA and publishTime. + * @returns Tuple of VAA and publishTime. */ async getVaa( priceId: HexString, From ea26e6c0566f9a077f6f4d89a862d8ca3709c405 Mon Sep 17 00:00:00 2001 From: Daniel Chew Date: Wed, 18 Jan 2023 22:49:40 +0900 Subject: [PATCH 5/5] Update pyth-common-js/src/PriceServiceConnection.ts Co-authored-by: Ali Behjati --- pyth-common-js/src/PriceServiceConnection.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyth-common-js/src/PriceServiceConnection.ts b/pyth-common-js/src/PriceServiceConnection.ts index f5b4d71..40fe304 100644 --- a/pyth-common-js/src/PriceServiceConnection.ts +++ b/pyth-common-js/src/PriceServiceConnection.ts @@ -151,7 +151,8 @@ export class PriceServiceConnection { /** * Fetch the earliest VAA of the given price id that is published since the given publish time. - * This will throw an error if the given publish time is in the future, or if the price service does not have a db backend. + * This will throw an error if the given publish time is in the future, or if the publish time + * is old and the price service endpoint does not have a db backend for historical requests. * This will throw an axios error if there is a network problem or the price service returns a non-ok response (e.g: Invalid price id) * * This function is coupled to wormhole implemntation.