From 4629f689e4da046d43b79989aeb29df0641bd763 Mon Sep 17 00:00:00 2001 From: Ali Behjati Date: Mon, 24 Oct 2022 19:16:56 +0200 Subject: [PATCH] Add receive time to the price service (#360) * Add receive time to the price service * Bump version to 2.1.0 --- third_party/pyth/p2w-sdk/js/package-lock.json | 14 +++++++------- third_party/pyth/p2w-sdk/js/package.json | 2 +- .../pyth/price-service/package-lock.json | 18 +++++++++--------- third_party/pyth/price-service/package.json | 6 +++--- .../price-service/src/__tests__/rest.test.ts | 1 + .../price-service/src/__tests__/ws.test.ts | 8 ++++++-- third_party/pyth/price-service/src/listen.ts | 2 ++ third_party/pyth/price-service/src/rest.ts | 2 ++ third_party/pyth/price-service/src/ws.ts | 1 + 9 files changed, 32 insertions(+), 22 deletions(-) diff --git a/third_party/pyth/p2w-sdk/js/package-lock.json b/third_party/pyth/p2w-sdk/js/package-lock.json index c0604212..bc2c5788 100644 --- a/third_party/pyth/p2w-sdk/js/package-lock.json +++ b/third_party/pyth/p2w-sdk/js/package-lock.json @@ -11,7 +11,7 @@ "dependencies": { "@certusone/wormhole-sdk": "0.2.1", "@improbable-eng/grpc-web-node-http-transport": "^0.14.1", - "@pythnetwork/pyth-sdk-js": "^1.0.0" + "@pythnetwork/pyth-sdk-js": "^1.1.0" }, "devDependencies": { "@openzeppelin/contracts": "^4.2.0", @@ -913,9 +913,9 @@ "integrity": "sha1-p3c2C1s5oaLlEG+OhY8v0tBgxXA=" }, "node_modules/@pythnetwork/pyth-sdk-js": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/@pythnetwork/pyth-sdk-js/-/pyth-sdk-js-1.0.0.tgz", - "integrity": "sha512-nZ3tmn5EhR7Y6177cAE7p7iQJK40bipMUI4ZBwRhgTONOcg35jG0fsvlETZYgij0baQ1PMJQE6dIqZ50EMZpJw==" + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@pythnetwork/pyth-sdk-js/-/pyth-sdk-js-1.1.0.tgz", + "integrity": "sha512-IfZI/D+7HiA01TfzuA7Fh0SMhsE+hZWoI1pt48G+XMbNkXhiZG4lSQJRsnquSEY06YAFcAX2D66cFtV6BHy8IA==" }, "node_modules/@solana/buffer-layout": { "version": "4.0.0", @@ -3236,9 +3236,9 @@ "integrity": "sha1-p3c2C1s5oaLlEG+OhY8v0tBgxXA=" }, "@pythnetwork/pyth-sdk-js": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/@pythnetwork/pyth-sdk-js/-/pyth-sdk-js-1.0.0.tgz", - "integrity": "sha512-nZ3tmn5EhR7Y6177cAE7p7iQJK40bipMUI4ZBwRhgTONOcg35jG0fsvlETZYgij0baQ1PMJQE6dIqZ50EMZpJw==" + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@pythnetwork/pyth-sdk-js/-/pyth-sdk-js-1.1.0.tgz", + "integrity": "sha512-IfZI/D+7HiA01TfzuA7Fh0SMhsE+hZWoI1pt48G+XMbNkXhiZG4lSQJRsnquSEY06YAFcAX2D66cFtV6BHy8IA==" }, "@solana/buffer-layout": { "version": "4.0.0", diff --git a/third_party/pyth/p2w-sdk/js/package.json b/third_party/pyth/p2w-sdk/js/package.json index 6a129855..4e47a05e 100644 --- a/third_party/pyth/p2w-sdk/js/package.json +++ b/third_party/pyth/p2w-sdk/js/package.json @@ -42,7 +42,7 @@ "dependencies": { "@certusone/wormhole-sdk": "0.2.1", "@improbable-eng/grpc-web-node-http-transport": "^0.14.1", - "@pythnetwork/pyth-sdk-js": "^1.0.0" + "@pythnetwork/pyth-sdk-js": "^1.1.0" }, "bugs": { "url": "https://github.com/pyth-network/pyth-crosschain/issues" diff --git a/third_party/pyth/price-service/package-lock.json b/third_party/pyth/price-service/package-lock.json index 37e9ec31..2183b11a 100644 --- a/third_party/pyth/price-service/package-lock.json +++ b/third_party/pyth/price-service/package-lock.json @@ -1,18 +1,18 @@ { "name": "@pythnetwork/pyth-price-service", - "version": "2.0.0", + "version": "2.1.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@pythnetwork/pyth-price-service", - "version": "2.0.0", + "version": "2.1.0", "license": "Apache-2.0", "dependencies": { "@certusone/wormhole-sdk": "^0.1.4", "@certusone/wormhole-spydk": "^0.0.1", "@pythnetwork/p2w-sdk-js": "file:../p2w-sdk/js", - "@pythnetwork/pyth-sdk-js": "^1.0.0", + "@pythnetwork/pyth-sdk-js": "^1.1.0", "@types/cors": "^2.8.12", "@types/express": "^4.17.13", "@types/morgan": "^1.9.3", @@ -2201,9 +2201,9 @@ "link": true }, "node_modules/@pythnetwork/pyth-sdk-js": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/@pythnetwork/pyth-sdk-js/-/pyth-sdk-js-1.0.0.tgz", - "integrity": "sha512-nZ3tmn5EhR7Y6177cAE7p7iQJK40bipMUI4ZBwRhgTONOcg35jG0fsvlETZYgij0baQ1PMJQE6dIqZ50EMZpJw==" + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@pythnetwork/pyth-sdk-js/-/pyth-sdk-js-1.1.0.tgz", + "integrity": "sha512-IfZI/D+7HiA01TfzuA7Fh0SMhsE+hZWoI1pt48G+XMbNkXhiZG4lSQJRsnquSEY06YAFcAX2D66cFtV6BHy8IA==" }, "node_modules/@sideway/address": { "version": "4.1.4", @@ -10545,9 +10545,9 @@ } }, "@pythnetwork/pyth-sdk-js": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/@pythnetwork/pyth-sdk-js/-/pyth-sdk-js-1.0.0.tgz", - "integrity": "sha512-nZ3tmn5EhR7Y6177cAE7p7iQJK40bipMUI4ZBwRhgTONOcg35jG0fsvlETZYgij0baQ1PMJQE6dIqZ50EMZpJw==" + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@pythnetwork/pyth-sdk-js/-/pyth-sdk-js-1.1.0.tgz", + "integrity": "sha512-IfZI/D+7HiA01TfzuA7Fh0SMhsE+hZWoI1pt48G+XMbNkXhiZG4lSQJRsnquSEY06YAFcAX2D66cFtV6BHy8IA==" }, "@sideway/address": { "version": "4.1.4", diff --git a/third_party/pyth/price-service/package.json b/third_party/pyth/price-service/package.json index 4c9923e5..3646b061 100644 --- a/third_party/pyth/price-service/package.json +++ b/third_party/pyth/price-service/package.json @@ -1,6 +1,6 @@ { "name": "@pythnetwork/pyth-price-service", - "version": "2.0.0", + "version": "2.1.0", "description": "Pyth Price Service", "main": "index.js", "scripts": { @@ -28,10 +28,10 @@ "typescript": "^4.3.5" }, "dependencies": { - "@pythnetwork/p2w-sdk-js": "file:../p2w-sdk/js", "@certusone/wormhole-sdk": "^0.1.4", "@certusone/wormhole-spydk": "^0.0.1", - "@pythnetwork/pyth-sdk-js": "^1.0.0", + "@pythnetwork/p2w-sdk-js": "file:../p2w-sdk/js", + "@pythnetwork/pyth-sdk-js": "^1.1.0", "@types/cors": "^2.8.12", "@types/express": "^4.17.13", "@types/morgan": "^1.9.3", diff --git a/third_party/pyth/price-service/src/__tests__/rest.test.ts b/third_party/pyth/price-service/src/__tests__/rest.test.ts index 00ac51e0..b2a6ae86 100644 --- a/third_party/pyth/price-service/src/__tests__/rest.test.ts +++ b/third_party/pyth/price-service/src/__tests__/rest.test.ts @@ -43,6 +43,7 @@ function dummyPriceInfoPair( seqNum, vaaBytes: Buffer.from(vaa, "hex").toString("binary"), emitterChainId: 0, + priceServiceReceiveTime: 0, }, ]; } diff --git a/third_party/pyth/price-service/src/__tests__/ws.test.ts b/third_party/pyth/price-service/src/__tests__/ws.test.ts index 52913ebe..8c4135b1 100644 --- a/third_party/pyth/price-service/src/__tests__/ws.test.ts +++ b/third_party/pyth/price-service/src/__tests__/ws.test.ts @@ -1,5 +1,6 @@ import { HexString, PriceFeed } from "@pythnetwork/pyth-sdk-js"; import { Server } from "http"; +import { number } from "joi"; import { WebSocket, WebSocketServer } from "ws"; import { sleep } from "../helpers"; import { PriceInfo, PriceStore } from "../listen"; @@ -21,12 +22,14 @@ function expandTo64Len(id: string): string { function dummyPriceMetadata( attestationTime: number, emitterChainId: number, - seqNum: number + seqNum: number, + priceServiceReceiveTime: number ): any { return { attestation_time: attestationTime, emitter_chain: emitterChainId, sequence_number: seqNum, + price_service_receive_time: priceServiceReceiveTime, }; } @@ -41,6 +44,7 @@ function dummyPriceInfo( emitterChainId: dummyPriceMetadataValue.emitter_chain, priceFeed: dummyPriceFeed(id), vaaBytes: Buffer.from(vaa, "hex").toString("binary"), + priceServiceReceiveTime: dummyPriceMetadataValue.price_service_receive_time, }; } @@ -92,7 +96,7 @@ async function createSocketClient(): Promise<[WebSocket, any[]]> { } beforeAll(async () => { - priceMetadata = dummyPriceMetadata(0, 0, 0); + priceMetadata = dummyPriceMetadata(0, 0, 0, 0); priceInfos = [ dummyPriceInfo(expandTo64Len("abcd"), "a1b2c3d4", priceMetadata), dummyPriceInfo(expandTo64Len("ef01"), "a1b2c3d4", priceMetadata), diff --git a/third_party/pyth/price-service/src/listen.ts b/third_party/pyth/price-service/src/listen.ts index 854c9ba1..e26bbb78 100644 --- a/third_party/pyth/price-service/src/listen.ts +++ b/third_party/pyth/price-service/src/listen.ts @@ -32,6 +32,7 @@ export type PriceInfo = { attestationTime: TimestampInSec; priceFeed: PriceFeed; emitterChainId: number; + priceServiceReceiveTime: number; }; export interface PriceStore { @@ -198,6 +199,7 @@ export class Listener implements PriceStore { attestationTime: priceAttestation.attestationTime, priceFeed, emitterChainId: parsedVAA.emitter_chain, + priceServiceReceiveTime: Math.floor(new Date().getTime() / 1000), }; this.priceFeedVaaMap.set(key, priceInfo); diff --git a/third_party/pyth/price-service/src/rest.ts b/third_party/pyth/price-service/src/rest.ts index bb2e307f..2661eb01 100644 --- a/third_party/pyth/price-service/src/rest.ts +++ b/third_party/pyth/price-service/src/rest.ts @@ -179,6 +179,8 @@ export class RestAPI { emitter_chain: latestPriceInfo.emitterChainId, attestation_time: latestPriceInfo.attestationTime, sequence_number: latestPriceInfo.seqNum, + price_service_receive_time: + latestPriceInfo.priceServiceReceiveTime, }, }); } else { diff --git a/third_party/pyth/price-service/src/ws.ts b/third_party/pyth/price-service/src/ws.ts index 43cbccb0..356a2209 100644 --- a/third_party/pyth/price-service/src/ws.ts +++ b/third_party/pyth/price-service/src/ws.ts @@ -109,6 +109,7 @@ export class WebSocketAPI { emitter_chain: priceInfo.emitterChainId, attestation_time: priceInfo.attestationTime, sequence_number: priceInfo.seqNum, + price_service_receive_time: priceInfo.priceServiceReceiveTime, }, }, }