Skip to content

Commit

Permalink
feat: add support for maxLatency (#76)
Browse files Browse the repository at this point in the history
* add support for maxLatency

* revert

* revert

* update readme

* address comments

* Update package version to 2.20.0
  • Loading branch information
cctdaniel authored Feb 28, 2024
1 parent 8c24cfc commit 0ba9357
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 11 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 2.20.0

- Add `messageSent` field to `PriceData`
- Add `maxLatency` field to `PriceData`

## 2.19.0

- Upgrade `@coral-xyz/anchor` to `^0.28.1-beta.1`
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
42 changes: 42 additions & 0 deletions src/anchor/idl.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
44 changes: 43 additions & 1 deletion src/anchor/program.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -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: [
{
Expand Down
18 changes: 11 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -350,7 +353,8 @@ export const parsePriceData = (data: Buffer, currentSlot?: number): PriceData =>
emaConfidence,
timestamp,
minPublishers,
drv2,
messageSent,
maxLatency,
drv3,
drv4,
productAccountKey,
Expand Down Expand Up @@ -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'

0 comments on commit 0ba9357

Please sign in to comment.