Add receive time to the price service (#360)

* Add receive time to the price service

* Bump version to 2.1.0
This commit is contained in:
Ali Behjati 2022-10-24 19:16:56 +02:00 committed by GitHub
parent 3eb2beabe7
commit 4629f689e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 32 additions and 22 deletions

View File

@ -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",

View File

@ -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"

View File

@ -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",

View File

@ -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",

View File

@ -43,6 +43,7 @@ function dummyPriceInfoPair(
seqNum,
vaaBytes: Buffer.from(vaa, "hex").toString("binary"),
emitterChainId: 0,
priceServiceReceiveTime: 0,
},
];
}

View File

@ -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),

View File

@ -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);

View File

@ -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 {

View File

@ -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,
},
},
}