Skip to content

Commit 6632ccb

Browse files
Merge pull request #1 from pyth-network/main
PYcharm
2 parents af0239d + 1b9d17c commit 6632ccb

File tree

14 files changed

+177
-40
lines changed

14 files changed

+177
-40
lines changed

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.21.0",
3+
"version": "2.22.0",
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: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import { AnchorProvider, Wallet } from '@coral-xyz/anchor'
22
import { Connection, Keypair, PublicKey } from '@solana/web3.js'
33
import { BN } from 'bn.js'
4+
import { getPythClusterApiUrl } from '../cluster'
45
import { getPythProgramKeyForCluster, pythOracleProgram, pythOracleCoder } from '../index'
56

67
test('Anchor', (done) => {
78
jest.setTimeout(60000)
89
const provider = new AnchorProvider(
9-
new Connection('https://api.mainnet-beta.solana.com'),
10+
new Connection(getPythClusterApiUrl('pythnet')),
1011
new Wallet(new Keypair()),
1112
AnchorProvider.defaultOptions(),
1213
)
13-
const pythOracle = pythOracleProgram(getPythProgramKeyForCluster('mainnet-beta'), provider)
14+
const pythOracle = pythOracleProgram(getPythProgramKeyForCluster('pythnet'), provider)
1415
pythOracle.methods
1516
.initMapping()
1617
.accounts({ fundingAccount: PublicKey.unique(), freshMappingAccount: PublicKey.unique() })
@@ -202,5 +203,30 @@ test('Anchor', (done) => {
202203
expect(decoded?.data.securityAuthority.equals(new PublicKey(8))).toBeTruthy()
203204
})
204205

206+
pythOracle.methods
207+
.setMaxLatency(1, [0, 0, 0])
208+
.accounts({ fundingAccount: PublicKey.unique(), priceAccount: PublicKey.unique() })
209+
.instruction()
210+
.then((instruction) => {
211+
expect(instruction.data).toStrictEqual(Buffer.from([2, 0, 0, 0, 18, 0, 0, 0, 1, 0, 0, 0]))
212+
const decoded = pythOracleCoder().instruction.decode(instruction.data)
213+
expect(decoded?.name).toBe('setMaxLatency')
214+
expect(decoded?.data.maxLatency === 1).toBeTruthy()
215+
})
216+
217+
pythOracle.methods
218+
.initPriceFeedIndex()
219+
.accounts({
220+
fundingAccount: PublicKey.unique(),
221+
priceAccount: PublicKey.unique(),
222+
})
223+
.instruction()
224+
.then((instruction) => {
225+
expect(instruction.data).toStrictEqual(Buffer.from([2, 0, 0, 0, 19, 0, 0, 0]))
226+
const decoded = pythOracleCoder().instruction.decode(instruction.data)
227+
expect(decoded?.name).toBe('initPriceFeedIndex')
228+
expect(decoded?.data).toStrictEqual({})
229+
})
230+
205231
done()
206232
})

src/__tests__/Example.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { clusterApiUrl, Connection, PublicKey } from '@solana/web3.js'
2-
import { parseMappingData, parsePriceData, parseProductData } from '../index'
1+
import { Connection, PublicKey } from '@solana/web3.js'
2+
import { getPythClusterApiUrl, parseMappingData, parsePriceData, parseProductData } from '../index'
33

4-
const SOLANA_CLUSTER_URL = clusterApiUrl('devnet')
4+
const SOLANA_CLUSTER_URL = getPythClusterApiUrl('pythtest-crosschain')
55
const ORACLE_MAPPING_PUBLIC_KEY = 'BmA9Z6FjioHJPpjT39QazZyhDRUdZy2ezwx4GiDdE2u2'
66

77
test('Mapping', (done) => {

src/__tests__/Mapping.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { clusterApiUrl, Connection, PublicKey } from '@solana/web3.js'
2-
import { parseMappingData, Magic, Version } from '../index'
1+
import { Connection, PublicKey } from '@solana/web3.js'
2+
import { parseMappingData, Magic, Version, getPythClusterApiUrl } from '../index'
33

44
test('Mapping', (done) => {
55
jest.setTimeout(60000)
6-
const url = clusterApiUrl('devnet')
6+
const url = getPythClusterApiUrl('pythtest-crosschain')
77
const oraclePublicKey = 'BmA9Z6FjioHJPpjT39QazZyhDRUdZy2ezwx4GiDdE2u2'
88
const connection = new Connection(url)
99
const publicKey = new PublicKey(oraclePublicKey)

src/__tests__/Price.test.ts

Lines changed: 36 additions & 2 deletions
Large diffs are not rendered by default.

src/__tests__/Product.ETH.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { clusterApiUrl, Connection, PublicKey } from '@solana/web3.js'
2-
import { Magic, parseProductData, Version } from '../index'
1+
import { Connection, PublicKey } from '@solana/web3.js'
2+
import { getPythClusterApiUrl, Magic, parseProductData, Version } from '../index'
33

44
test('Product', (done) => {
55
jest.setTimeout(60000)
6-
const url = clusterApiUrl('devnet')
6+
const url = getPythClusterApiUrl('pythtest-crosschain')
77
const ethProductKey = '2ciUuGZiee5macAMeQ7bHGTJtwcYTgnt6jdmQnnKZrfu'
88
const connection = new Connection(url)
99
const publicKey = new PublicKey(ethProductKey)

src/__tests__/Product.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { clusterApiUrl, Connection, PublicKey } from '@solana/web3.js'
1+
import { Connection, PublicKey } from '@solana/web3.js'
2+
import { getPythClusterApiUrl } from '../cluster'
23
import { parseMappingData, parseProductData, Magic, Version } from '../index'
34

45
test('Product', (done) => {
56
jest.setTimeout(60000)
6-
const url = clusterApiUrl('devnet')
7+
const url = getPythClusterApiUrl('pythtest-crosschain')
78
const oraclePublicKey = 'BmA9Z6FjioHJPpjT39QazZyhDRUdZy2ezwx4GiDdE2u2'
89
const connection = new Connection(url)
910
const publicKey = new PublicKey(oraclePublicKey)

src/__tests__/PythNetworkRestClient.test.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import { clusterApiUrl, Connection, PublicKey, SystemProgram } from '@solana/web3.js'
1+
import { Connection, PublicKey, SystemProgram } from '@solana/web3.js'
22
import { getPythProgramKeyForCluster, parseProductData, PythHttpClient } from '..'
3+
import { getPythClusterApiUrl } from '../cluster'
34

45
test('PythHttpClientCall: getData', (done) => {
5-
jest.setTimeout(20000)
6+
jest.setTimeout(60000)
67
try {
7-
const programKey = getPythProgramKeyForCluster('testnet')
8-
const currentConnection = new Connection(clusterApiUrl('testnet'))
8+
const programKey = getPythProgramKeyForCluster('pythtest-conformance')
9+
const currentConnection = new Connection(getPythClusterApiUrl('pythtest-conformance'))
910
const pyth_client = new PythHttpClient(currentConnection, programKey)
1011
pyth_client.getData().then(
1112
(result) => {
@@ -30,7 +31,7 @@ test('PythHttpClientCall: getAssetPricesFromAccounts for one account', (done) =>
3031
const solUSDKey = new PublicKey('7VJsBtJzgTftYzEeooSDYyjKXvYRWJHdwvbwfBvTg9K')
3132
try {
3233
const programKey = getPythProgramKeyForCluster('testnet')
33-
const currentConnection = new Connection(clusterApiUrl('testnet'))
34+
const currentConnection = new Connection(getPythClusterApiUrl('pythtest-conformance'))
3435
const pyth_client = new PythHttpClient(currentConnection, programKey)
3536
pyth_client
3637
.getAssetPricesFromAccounts([solUSDKey])
@@ -66,7 +67,7 @@ test('PythHttpClientCall: getAssetPricesFromAccounts for multiple accounts', (do
6667

6768
try {
6869
const programKey = getPythProgramKeyForCluster('testnet')
69-
const currentConnection = new Connection(clusterApiUrl('testnet'))
70+
const currentConnection = new Connection(getPythClusterApiUrl('pythtest-conformance'))
7071
const pyth_client = new PythHttpClient(currentConnection, programKey)
7172
pyth_client
7273
.getAssetPricesFromAccounts([solUSDKey, bonkUSDKey, usdcUSDKey])
@@ -106,7 +107,7 @@ test('PythHttpClientCall: getAssetPricesFromAccounts should throw for invalid ac
106107

107108
try {
108109
const programKey = getPythProgramKeyForCluster('testnet')
109-
const currentConnection = new Connection(clusterApiUrl('testnet'))
110+
const currentConnection = new Connection(getPythClusterApiUrl('pythtest-conformance'))
110111
const pyth_client = new PythHttpClient(currentConnection, programKey)
111112
pyth_client
112113
.getAssetPricesFromAccounts([solUSDKey, systemProgram, usdcUSDKey])

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).writeInt8(key.length)
96+
offset += buffer.subarray(offset).writeUInt8(key.length)
9797
offset += buffer.subarray(offset).write(key)
98-
offset += buffer.subarray(offset).writeInt8(ix.productMetadata[key].length)
98+
offset += buffer.subarray(offset).writeUInt8(ix.productMetadata[key].length)
9999
offset += buffer.subarray(offset).write(ix.productMetadata[key])
100100
}
101101
if (offset > MAX_METADATA_SIZE) {

0 commit comments

Comments
 (0)