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" diff --git a/pyth-common-js/src/PriceServiceConnection.ts b/pyth-common-js/src/PriceServiceConnection.ts index 781d11f..40fe304 100644 --- a/pyth-common-js/src/PriceServiceConnection.ts +++ b/pyth-common-js/src/PriceServiceConnection.ts @@ -149,6 +149,31 @@ export class PriceServiceConnection { return response.data; } + /** + * 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 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. + * + * @param priceId Hex-encoded price id. + * @param publishTime Epoch timestamp in seconds. + * @returns Tuple of VAA and publishTime. + */ + async getVaa( + priceId: HexString, + publishTime: EpochTimeStamp + ): Promise<[string, EpochTimeStamp]> { + const response = await this.httpClient.get("/api/get_vaa", { + params: { + id: priceId, + publish_time: publishTime, + }, + }); + return [response.data.vaa, response.data.publishTime]; + } + /** * 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.