Skip to content

Commit 3232b08

Browse files
Merge branch 'pyth-network:main' into main
2 parents 6632ccb + f37e2d9 commit 3232b08

File tree

7 files changed

+34
-17
lines changed

7 files changed

+34
-17
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# @pythnetwork/client
22

3-
## A library for reading on-chain Pyth oracle data
3+
## A library for reading Pyth accounts on Pythnet
44

55
[Pyth](https://pyth.network/) is building a way to deliver a decentralized, cross-chain market of verifiable data from high-quality nodes to any smart contract, anywhere.
66

7-
This library reads on-chain Pyth data from [@solana/web3.js](https://www.npmjs.com/package/@solana/web3.js) and returns JavaScript-friendly objects.
7+
This library reads Pythnet (Pyth's app-specific SVM blockchain) data using [@solana/web3.js](https://www.npmjs.com/package/@solana/web3.js) and returns JavaScript-friendly objects.
8+
9+
> ⚠️ **Important Warning**: For most use cases, it is recommended and more user-friendly to use Pyth's off-chain API ([Hermes](https://hermes.pyth.network/docs/)) via the [@pythnetwork/hermes-client](https://www.npmjs.com/package/@pythnetwork/hermes-client) package to get the most up-to-date Pyth prices. Using `@pythnetwork/client` requires a Pythnet RPC connection and exposes many low-level details.
810
911
## Installation
1012

@@ -29,7 +31,7 @@ This library lets you consume prices in two different ways: you can either get c
2931
The websocket connection provides a subscription model for consuming price updates:
3032

3133
```typescript
32-
const pythConnection = new PythConnection(solanaWeb3Connection, getPythProgramKeyForCluster(solanaClusterName))
34+
const pythConnection = new PythConnection(pythnetWeb3Connection, getPythProgramKeyForCluster(pythnetClusterName))
3335
pythConnection.onPriceChange((product, price) => {
3436
// sample output:
3537
// Crypto.SRM/USD: $8.68725 ±$0.0131 Status: Trading

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pythnetwork/client",
3-
"version": "2.22.0",
3+
"version": "2.22.1",
44
"description": "Client for consuming Pyth price data",
55
"homepage": "https://pyth.network",
66
"main": "lib/index.js",

src/__tests__/Anchor.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,21 @@ test('Anchor', (done) => {
5858
expect(decoded?.data.generic_symbol).toBe('ETHUSD')
5959
})
6060

61+
pythOracle.methods
62+
.addProduct({
63+
'😆': 'ÉTH',
64+
})
65+
.accounts({
66+
fundingAccount: PublicKey.unique(),
67+
productAccount: PublicKey.unique(),
68+
tailMappingAccount: PublicKey.unique(),
69+
})
70+
.instruction()
71+
.then((instruction) => {
72+
const decoded = pythOracleCoder().instruction.decode(instruction.data)
73+
expect(decoded?.data['😆']).toBe('ÉTH')
74+
})
75+
6176
pythOracle.methods
6277
.updProduct({
6378
asset_type: 'Crypto',

src/__tests__/Price.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ test('Handle price getting stale', (done) => {
104104
expect(price.magic).toBe(Magic)
105105
expect(price.version).toBe(Version)
106106
expect(price.status).toBe(PriceStatus.Trading)
107-
expect(price.flags.accumulatorV2).toBe(false);
108-
expect(price.flags.messageBufferCleared).toBe(false);
107+
expect(price.flags.accumulatorV2).toBe(false)
108+
expect(price.flags.messageBufferCleared).toBe(false)
109109
expect(price.feedIndex).toBe(0)
110110

111111
expect(parsePriceData(data, price.aggregate.publishSlot + MAX_SLOT_DIFFERENCE).status).toBe(PriceStatus.Trading)
@@ -143,8 +143,8 @@ test('Handle flags', (done) => {
143143
const data = Buffer.from(b64_data, 'base64')
144144
const price = parsePriceData(data)
145145

146-
expect(price.flags.accumulatorV2).toBe(true);
147-
expect(price.flags.messageBufferCleared).toBe(true);
146+
expect(price.flags.accumulatorV2).toBe(true)
147+
expect(price.flags.messageBufferCleared).toBe(true)
148148

149149
done()
150150
})

src/anchor/coder/instructions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ export class PythOracleInstructionCoder implements InstructionCoder {
9393
if (methodName === 'updProduct' || methodName === 'addProduct') {
9494
let offset = 0
9595
for (const key of Object.keys(ix.productMetadata)) {
96-
offset += buffer.subarray(offset).writeUInt8(key.length)
96+
offset += buffer.subarray(offset).writeUInt8(Buffer.byteLength(key))
9797
offset += buffer.subarray(offset).write(key)
98-
offset += buffer.subarray(offset).writeUInt8(ix.productMetadata[key].length)
98+
offset += buffer.subarray(offset).writeUInt8(Buffer.byteLength(ix.productMetadata[key]))
9999
offset += buffer.subarray(offset).write(ix.productMetadata[key])
100100
}
101101
if (offset > MAX_METADATA_SIZE) {

src/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ export enum AccountType {
4242
}
4343

4444
export type Flags = {
45-
accumulatorV2: boolean,
46-
messageBufferCleared: boolean,
45+
accumulatorV2: boolean
46+
messageBufferCleared: boolean
4747
}
4848

4949
const empty32Buffer = Buffer.alloc(32)
@@ -110,7 +110,7 @@ export interface PriceData extends Base {
110110
minPublishers: number
111111
messageSent: number
112112
maxLatency: number
113-
flags: Flags,
113+
flags: Flags
114114
feedIndex: number
115115
productAccountKey: PublicKey
116116
nextPriceAccountKey: PublicKey | null
@@ -300,8 +300,8 @@ export const parsePriceData = (data: Buffer, currentSlot?: number): PriceData =>
300300

301301
/* tslint:disable:no-bitwise */
302302
const flags = {
303-
accumulatorV2: (flagBits & (1<<0)) !== 0,
304-
messageBufferCleared: (flagBits & (1<<1)) !== 0,
303+
accumulatorV2: (flagBits & (1 << 0)) !== 0,
304+
messageBufferCleared: (flagBits & (1 << 1)) !== 0,
305305
}
306306
/* tslint:enable:no-bitwise */
307307

0 commit comments

Comments
 (0)