From c1f3bca0c806eef3ec46bbd9b90ae9496b31da35 Mon Sep 17 00:00:00 2001 From: Ali Behjati Date: Mon, 24 Oct 2022 16:01:24 +0000 Subject: [PATCH 1/2] Add receive time to the price service --- third_party/pyth/p2w-sdk/js/package-lock.json | 14 +++++++------- third_party/pyth/p2w-sdk/js/package.json | 2 +- third_party/pyth/price-service/package-lock.json | 14 +++++++------- third_party/pyth/price-service/package.json | 4 ++-- .../pyth/price-service/src/__tests__/rest.test.ts | 1 + .../pyth/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 | 1 + third_party/pyth/price-service/src/ws.ts | 1 + 9 files changed, 28 insertions(+), 19 deletions(-) diff --git a/third_party/pyth/p2w-sdk/js/package-lock.json b/third_party/pyth/p2w-sdk/js/package-lock.json index c060421205..bc2c578856 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 6a129855df..4e47a05e44 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 37e9ec3197..a1fdca9c41 100644 --- a/third_party/pyth/price-service/package-lock.json +++ b/third_party/pyth/price-service/package-lock.json @@ -12,7 +12,7 @@ "@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 4c9923e56e..a3107463c8 100644 --- a/third_party/pyth/price-service/package.json +++ b/third_party/pyth/price-service/package.json @@ -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 00ac51e08d..b2a6ae8695 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 52913ebe1e..8c4135b138 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 854c9ba1cf..46b1bb46fa 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 bb2e307f52..f17cab3468 100644 --- a/third_party/pyth/price-service/src/rest.ts +++ b/third_party/pyth/price-service/src/rest.ts @@ -179,6 +179,7 @@ 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 43cbccb045..356a2209e6 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, }, }, } From dbeb99502f6753aef01a1ae7ed2011dfb7264fc4 Mon Sep 17 00:00:00 2001 From: Ali Behjati Date: Mon, 24 Oct 2022 17:06:49 +0000 Subject: [PATCH 2/2] Bump version to 2.1.0 --- third_party/pyth/price-service/package-lock.json | 4 ++-- third_party/pyth/price-service/package.json | 2 +- third_party/pyth/price-service/src/listen.ts | 2 +- third_party/pyth/price-service/src/rest.ts | 3 ++- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/third_party/pyth/price-service/package-lock.json b/third_party/pyth/price-service/package-lock.json index a1fdca9c41..2183b11a03 100644 --- a/third_party/pyth/price-service/package-lock.json +++ b/third_party/pyth/price-service/package-lock.json @@ -1,12 +1,12 @@ { "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", diff --git a/third_party/pyth/price-service/package.json b/third_party/pyth/price-service/package.json index a3107463c8..3646b0611f 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": { diff --git a/third_party/pyth/price-service/src/listen.ts b/third_party/pyth/price-service/src/listen.ts index 46b1bb46fa..e26bbb7817 100644 --- a/third_party/pyth/price-service/src/listen.ts +++ b/third_party/pyth/price-service/src/listen.ts @@ -199,7 +199,7 @@ export class Listener implements PriceStore { attestationTime: priceAttestation.attestationTime, priceFeed, emitterChainId: parsedVAA.emitter_chain, - priceServiceReceiveTime: Math.floor((new Date()).getTime() / 1000), + 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 f17cab3468..2661eb0106 100644 --- a/third_party/pyth/price-service/src/rest.ts +++ b/third_party/pyth/price-service/src/rest.ts @@ -179,7 +179,8 @@ export class RestAPI { emitter_chain: latestPriceInfo.emitterChainId, attestation_time: latestPriceInfo.attestationTime, sequence_number: latestPriceInfo.seqNum, - price_service_receive_time: latestPriceInfo.priceServiceReceiveTime, + price_service_receive_time: + latestPriceInfo.priceServiceReceiveTime, }, }); } else {