Skip to content

Commit 1b9d17c

Browse files
authored
feat: add InitPriceFeedIndex method IDL (#80)
* feat: add InitPriceFeedIndex method IDL * fix: update tests to use pythnet/pythtest * fix: address review comments * feat: add tests for this instruction and setMaxLatency * refactor: format * fix: remove permissions account from the test as its pda * feat: add account parsing * fix: address lint issues * fix: update oracle version in idl.json
1 parent 8a9c94b commit 1b9d17c

13 files changed

+175
-38
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.1",
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/idl.json

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "2.20.0",
2+
"version": "2.33.0",
33
"name": "pyth_oracle",
44
"instructions": [
55
{
@@ -171,7 +171,7 @@
171171
},
172172
{
173173
"name": "permissionsAccount",
174-
"isMut": false,
174+
"isMut": true,
175175
"isSigner": false,
176176
"pda": {
177177
"seeds": [
@@ -640,6 +640,37 @@
640640
}
641641
}
642642
]
643+
},
644+
{
645+
"name": "initPriceFeedIndex",
646+
"discriminant": { "value": [2, 0, 0, 0, 19, 0, 0, 0] },
647+
"accounts": [
648+
{
649+
"name": "fundingAccount",
650+
"isMut": true,
651+
"isSigner": true
652+
},
653+
{
654+
"name": "priceAccount",
655+
"isMut": true,
656+
"isSigner": false
657+
},
658+
{
659+
"name": "permissionsAccount",
660+
"isMut": true,
661+
"isSigner": false,
662+
"pda": {
663+
"seeds": [
664+
{
665+
"kind": "const",
666+
"type": "string",
667+
"value": "permissions"
668+
}
669+
]
670+
}
671+
}
672+
],
673+
"args": []
643674
}
644675
],
645676
"types": [

0 commit comments

Comments
 (0)