From 1904505234640404cca6164e59e83ccd622542f5 Mon Sep 17 00:00:00 2001 From: Daniel Chew Date: Tue, 27 Feb 2024 10:21:50 +0900 Subject: [PATCH 1/6] add support for maxLatency --- package.json | 2 +- src/example_ws_single_feed.ts | 6 +++--- src/index.ts | 18 +++++++++++------- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index f23a0a9..8c9983d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@pythnetwork/client", - "version": "2.19.0", + "version": "2.20.0", "description": "Client for consuming Pyth price data", "homepage": "https://pyth.network", "main": "lib/index.js", diff --git a/src/example_ws_single_feed.ts b/src/example_ws_single_feed.ts index 75c089d..028f87f 100644 --- a/src/example_ws_single_feed.ts +++ b/src/example_ws_single_feed.ts @@ -7,7 +7,7 @@ const connection = new Connection(getPythClusterApiUrl(PYTHNET_CLUSTER_NAME)) const pythPublicKey = getPythProgramKeyForCluster(PYTHNET_CLUSTER_NAME) // This feed ID comes from this list: https://pyth.network/developers/price-feed-ids#solana-mainnet-beta // This example shows Crypto.SOL/USD -const feeds = [new PublicKey('H6ARHf6YXhGYeQfUzQNGk6rDNnLBQKrenN712K4AQJEG')] +const feeds = [new PublicKey('HD7fKr26unn2521YNNKeV7o45c4qzpzbNMceg2NCysE1')] const pythConnection = new PythConnection(connection, pythPublicKey, 'confirmed', feeds) pythConnection.onPriceChangeVerbose((productAccount, priceAccount) => { @@ -16,9 +16,9 @@ pythConnection.onPriceChangeVerbose((productAccount, priceAccount) => { const price = priceAccount.accountInfo.data // sample output: // SOL/USD: $14.627930000000001 ±$0.01551797 - if (price.price && price.confidence) { + if (price.price && price.confidence && price.status === PriceStatus.Trading) { // tslint:disable-next-line:no-console - console.log(`${product.symbol}: $${price.price} \xB1$${price.confidence}`) + console.log(`${price.timestamp} ${product.symbol}: $${price.aggregate.price} $${price.aggregate.priceComponent} \xB1$${price.confidence}`) } else { // tslint:disable-next-line:no-console console.log(`${product.symbol}: price currently unavailable. status is ${PriceStatus[price.status]}`) diff --git a/src/index.ts b/src/index.ts index 64bf9bd..5cef564 100644 --- a/src/index.ts +++ b/src/index.ts @@ -103,7 +103,8 @@ export interface PriceData extends Base { emaConfidence: Ema timestamp: bigint minPublishers: number - drv2: number + messageSent: number + maxLatency: number drv3: number drv4: number productAccountKey: PublicKey @@ -285,10 +286,12 @@ export const parsePriceData = (data: Buffer, currentSlot?: number): PriceData => const timestamp = readBigInt64LE(data, 96) // minimum number of publishers for status to be TRADING const minPublishers = data.readUInt8(104) + // message sent flag + const messageSent = data.readUInt8(105) + // configurable max latency in slots between send and receive + const maxLatency = data.readUInt8(106) // space for future derived values - const drv2 = data.readInt8(105) - // space for future derived values - const drv3 = data.readInt16LE(106) + const drv3 = data.readInt8(107) // space for future derived values const drv4 = data.readInt32LE(108) // product id / reference account @@ -350,7 +353,8 @@ export const parsePriceData = (data: Buffer, currentSlot?: number): PriceData => emaConfidence, timestamp, minPublishers, - drv2, + messageSent, + maxLatency, drv3, drv4, productAccountKey, @@ -394,5 +398,5 @@ export const parsePermissionData = (data: Buffer): PermissionData => { export { PythConnection } from './PythConnection' export { PythHttpClient } from './PythHttpClient' -export { getPythProgramKeyForCluster, PythCluster, getPythClusterApiUrl } from './cluster' -export { pythOracleProgram, pythOracleCoder, pythIdl } from './anchor' +export { pythIdl, pythOracleCoder, pythOracleProgram } from './anchor' +export { PythCluster, getPythClusterApiUrl, getPythProgramKeyForCluster } from './cluster' From 73982d5d15e856d59ade6cbb0ddbe5dfa5a709e7 Mon Sep 17 00:00:00 2001 From: Daniel Chew Date: Tue, 27 Feb 2024 10:23:03 +0900 Subject: [PATCH 2/6] revert --- src/example_ws_single_feed.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/example_ws_single_feed.ts b/src/example_ws_single_feed.ts index 028f87f..8dcb3b0 100644 --- a/src/example_ws_single_feed.ts +++ b/src/example_ws_single_feed.ts @@ -7,7 +7,7 @@ const connection = new Connection(getPythClusterApiUrl(PYTHNET_CLUSTER_NAME)) const pythPublicKey = getPythProgramKeyForCluster(PYTHNET_CLUSTER_NAME) // This feed ID comes from this list: https://pyth.network/developers/price-feed-ids#solana-mainnet-beta // This example shows Crypto.SOL/USD -const feeds = [new PublicKey('HD7fKr26unn2521YNNKeV7o45c4qzpzbNMceg2NCysE1')] +const feeds = [new PublicKey('H6ARHf6YXhGYeQfUzQNGk6rDNnLBQKrenN712K4AQJEG')] const pythConnection = new PythConnection(connection, pythPublicKey, 'confirmed', feeds) pythConnection.onPriceChangeVerbose((productAccount, priceAccount) => { @@ -16,9 +16,9 @@ pythConnection.onPriceChangeVerbose((productAccount, priceAccount) => { const price = priceAccount.accountInfo.data // sample output: // SOL/USD: $14.627930000000001 ±$0.01551797 - if (price.price && price.confidence && price.status === PriceStatus.Trading) { + if (price.price && price.confidence) { // tslint:disable-next-line:no-console - console.log(`${price.timestamp} ${product.symbol}: $${price.aggregate.price} $${price.aggregate.priceComponent} \xB1$${price.confidence}`) + console.log(`${product.symbol}: $${price.price} \xB1$${price.confidence}`) } else { // tslint:disable-next-line:no-console console.log(`${product.symbol}: price currently unavailable. status is ${PriceStatus[price.status]}`) @@ -27,4 +27,4 @@ pythConnection.onPriceChangeVerbose((productAccount, priceAccount) => { // tslint:disable-next-line:no-console console.log('Reading from Pyth price feed...') -pythConnection.start() +pythConnection.start() \ No newline at end of file From e8b7a668c9d0819ff4abb301c3c881e49e8b8f5a Mon Sep 17 00:00:00 2001 From: Daniel Chew Date: Tue, 27 Feb 2024 10:23:41 +0900 Subject: [PATCH 3/6] revert --- src/example_ws_single_feed.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/example_ws_single_feed.ts b/src/example_ws_single_feed.ts index 8dcb3b0..75c089d 100644 --- a/src/example_ws_single_feed.ts +++ b/src/example_ws_single_feed.ts @@ -27,4 +27,4 @@ pythConnection.onPriceChangeVerbose((productAccount, priceAccount) => { // tslint:disable-next-line:no-console console.log('Reading from Pyth price feed...') -pythConnection.start() \ No newline at end of file +pythConnection.start() From bfe454b7165ed1313ec9f43750c666f7cf563f83 Mon Sep 17 00:00:00 2001 From: Daniel Chew Date: Tue, 27 Feb 2024 10:35:04 +0900 Subject: [PATCH 4/6] update readme --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a09721..39d0865 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 2.w0.0 + +- Add `messageSent` field to `PriceData` +- Add `maxLatency` field to `PriceData` + ## 2.19.0 - Upgrade `@coral-xyz/anchor` to `^0.28.1-beta.1` From 3a83cf3727bea554f400b6b863878534fc3bded7 Mon Sep 17 00:00:00 2001 From: Daniel Chew Date: Tue, 27 Feb 2024 23:04:50 +0900 Subject: [PATCH 5/6] address comments --- CHANGELOG.md | 2 +- src/anchor/idl.json | 42 +++++++++++++++++++++++++++++++++++++++++ src/anchor/program.ts | 44 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 86 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 39d0865..dd9749c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## 2.w0.0 +## 2.20.0 - Add `messageSent` field to `PriceData` - Add `maxLatency` field to `PriceData` diff --git a/src/anchor/idl.json b/src/anchor/idl.json index eeeed91..927802f 100644 --- a/src/anchor/idl.json +++ b/src/anchor/idl.json @@ -598,6 +598,48 @@ "type": "publicKey" } ] + }, + { + "name": "setMaxLatency", + "discriminant": { "value": [2, 0, 0, 0, 18, 0, 0, 0] }, + "accounts": [ + { + "name": "fundingAccount", + "isMut": true, + "isSigner": true + }, + { + "name": "priceAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "permissionsAccount", + "isMut": false, + "isSigner": false, + "pda": { + "seeds": [ + { + "kind": "const", + "type": "string", + "value": "permissions" + } + ] + } + } + ], + "args": [ + { + "name": "maxLatency", + "type": "u8" + }, + { + "name": "unused", + "type": { + "array": ["u8", 3] + } + } + ] } ], "types": [ diff --git a/src/anchor/program.ts b/src/anchor/program.ts index fd8555c..a61705e 100644 --- a/src/anchor/program.ts +++ b/src/anchor/program.ts @@ -1,5 +1,5 @@ +import { AnchorProvider, Idl, Program } from '@coral-xyz/anchor' import { PublicKey } from '@solana/web3.js' -import { Program, AnchorProvider, Idl } from '@coral-xyz/anchor' import { PythOracleCoder } from './coder' import IDL from './idl.json' @@ -619,6 +619,48 @@ export type PythOracle = { }, ] }, + { + name: 'setMaxLatency' + discriminant: { value: [2, 0, 0, 0, 18, 0, 0, 0] } + accounts: [ + { + name: 'fundingAccount' + isMut: true + isSigner: true + }, + { + name: 'priceAccount' + isMut: true + isSigner: false + }, + { + name: 'permissionsAccount' + isMut: false + isSigner: false + pda: { + seeds: [ + { + kind: 'const' + type: 'string' + value: 'permissions' + }, + ] + } + }, + ] + args: [ + { + name: 'maxLatency' + type: 'u8' + }, + { + name: 'unused' + type: { + array: ['u8', 3] + } + }, + ] + }, ] types: [ { From 5f15322b2a7b30f52adeac5365e1762ec7e92dfe Mon Sep 17 00:00:00 2001 From: Daniel Chew Date: Wed, 28 Feb 2024 07:40:05 +0900 Subject: [PATCH 6/6] Update package version to 2.20.0 --- package-lock.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 86f122e..6d20b44 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@pythnetwork/client", - "version": "2.19.0", + "version": "2.20.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@pythnetwork/client", - "version": "2.19.0", + "version": "2.20.0", "license": "Apache-2.0", "dependencies": { "@coral-xyz/anchor": "^0.28.1-beta.1",