Skip to content

feat: add InitPriceFeedIndex method IDL #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.21.1",
"version": "2.22.0",
"description": "Client for consuming Pyth price data",
"homepage": "https://pyth.network",
"main": "lib/index.js",
Expand Down
5 changes: 3 additions & 2 deletions src/__tests__/Anchor.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { AnchorProvider, Wallet } from '@coral-xyz/anchor'
import { Connection, Keypair, PublicKey } from '@solana/web3.js'
import { BN } from 'bn.js'
import { getPythClusterApiUrl } from '../cluster'
import { getPythProgramKeyForCluster, pythOracleProgram, pythOracleCoder } from '../index'

test('Anchor', (done) => {
jest.setTimeout(60000)
const provider = new AnchorProvider(
new Connection('https://api.mainnet-beta.solana.com'),
new Connection(getPythClusterApiUrl('pythnet')),
new Wallet(new Keypair()),
AnchorProvider.defaultOptions(),
)
const pythOracle = pythOracleProgram(getPythProgramKeyForCluster('mainnet-beta'), provider)
const pythOracle = pythOracleProgram(getPythProgramKeyForCluster('pythnet'), provider)
pythOracle.methods
.initMapping()
.accounts({ fundingAccount: PublicKey.unique(), freshMappingAccount: PublicKey.unique() })
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/Example.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { clusterApiUrl, Connection, PublicKey } from '@solana/web3.js'
import { parseMappingData, parsePriceData, parseProductData } from '../index'
import { Connection, PublicKey } from '@solana/web3.js'
import { getPythClusterApiUrl, parseMappingData, parsePriceData, parseProductData } from '../index'

const SOLANA_CLUSTER_URL = clusterApiUrl('devnet')
const SOLANA_CLUSTER_URL = getPythClusterApiUrl('pythtest-crosschain')
const ORACLE_MAPPING_PUBLIC_KEY = 'BmA9Z6FjioHJPpjT39QazZyhDRUdZy2ezwx4GiDdE2u2'

test('Mapping', (done) => {
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/Mapping.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { clusterApiUrl, Connection, PublicKey } from '@solana/web3.js'
import { parseMappingData, Magic, Version } from '../index'
import { Connection, PublicKey } from '@solana/web3.js'
import { parseMappingData, Magic, Version, getPythClusterApiUrl } from '../index'

test('Mapping', (done) => {
jest.setTimeout(60000)
const url = clusterApiUrl('devnet')
const url = getPythClusterApiUrl('pythtest-crosschain')
const oraclePublicKey = 'BmA9Z6FjioHJPpjT39QazZyhDRUdZy2ezwx4GiDdE2u2'
const connection = new Connection(url)
const publicKey = new PublicKey(oraclePublicKey)
Expand Down
5 changes: 3 additions & 2 deletions src/__tests__/Price.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { clusterApiUrl, Connection, PublicKey } from '@solana/web3.js'
import { Connection, PublicKey } from '@solana/web3.js'
import {
getPythClusterApiUrl,
Magic,
MAX_SLOT_DIFFERENCE,
parseMappingData,
Expand All @@ -11,7 +12,7 @@ import {

test('Price', (done) => {
jest.setTimeout(60000)
const url = clusterApiUrl('devnet')
const url = getPythClusterApiUrl('pythtest-crosschain')
const oraclePublicKey = 'BmA9Z6FjioHJPpjT39QazZyhDRUdZy2ezwx4GiDdE2u2'
const connection = new Connection(url)
const publicKey = new PublicKey(oraclePublicKey)
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/Product.ETH.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { clusterApiUrl, Connection, PublicKey } from '@solana/web3.js'
import { Magic, parseProductData, Version } from '../index'
import { Connection, PublicKey } from '@solana/web3.js'
import { getPythClusterApiUrl, Magic, parseProductData, Version } from '../index'

test('Product', (done) => {
jest.setTimeout(60000)
const url = clusterApiUrl('devnet')
const url = getPythClusterApiUrl('pythtest-crosschain')
const ethProductKey = '2ciUuGZiee5macAMeQ7bHGTJtwcYTgnt6jdmQnnKZrfu'
const connection = new Connection(url)
const publicKey = new PublicKey(ethProductKey)
Expand Down
5 changes: 3 additions & 2 deletions src/__tests__/Product.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { clusterApiUrl, Connection, PublicKey } from '@solana/web3.js'
import { Connection, PublicKey } from '@solana/web3.js'
import { getPythClusterApiUrl } from '../cluster'
import { parseMappingData, parseProductData, Magic, Version } from '../index'

test('Product', (done) => {
jest.setTimeout(60000)
const url = clusterApiUrl('devnet')
const url = getPythClusterApiUrl('pythtest-crosschain')
const oraclePublicKey = 'BmA9Z6FjioHJPpjT39QazZyhDRUdZy2ezwx4GiDdE2u2'
const connection = new Connection(url)
const publicKey = new PublicKey(oraclePublicKey)
Expand Down
15 changes: 8 additions & 7 deletions src/__tests__/PythNetworkRestClient.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { clusterApiUrl, Connection, PublicKey, SystemProgram } from '@solana/web3.js'
import { Connection, PublicKey, SystemProgram } from '@solana/web3.js'
import { getPythProgramKeyForCluster, parseProductData, PythHttpClient } from '..'
import { getPythClusterApiUrl } from '../cluster'

test('PythHttpClientCall: getData', (done) => {
jest.setTimeout(20000)
jest.setTimeout(60000)
try {
const programKey = getPythProgramKeyForCluster('testnet')
const currentConnection = new Connection(clusterApiUrl('testnet'))
const programKey = getPythProgramKeyForCluster('pythtest-conformance')
const currentConnection = new Connection(getPythClusterApiUrl('pythtest-conformance'))
const pyth_client = new PythHttpClient(currentConnection, programKey)
pyth_client.getData().then(
(result) => {
Expand All @@ -30,7 +31,7 @@ test('PythHttpClientCall: getAssetPricesFromAccounts for one account', (done) =>
const solUSDKey = new PublicKey('7VJsBtJzgTftYzEeooSDYyjKXvYRWJHdwvbwfBvTg9K')
try {
const programKey = getPythProgramKeyForCluster('testnet')
const currentConnection = new Connection(clusterApiUrl('testnet'))
const currentConnection = new Connection(getPythClusterApiUrl('pythtest-conformance'))
const pyth_client = new PythHttpClient(currentConnection, programKey)
pyth_client
.getAssetPricesFromAccounts([solUSDKey])
Expand Down Expand Up @@ -66,7 +67,7 @@ test('PythHttpClientCall: getAssetPricesFromAccounts for multiple accounts', (do

try {
const programKey = getPythProgramKeyForCluster('testnet')
const currentConnection = new Connection(clusterApiUrl('testnet'))
const currentConnection = new Connection(getPythClusterApiUrl('pythtest-conformance'))
const pyth_client = new PythHttpClient(currentConnection, programKey)
pyth_client
.getAssetPricesFromAccounts([solUSDKey, bonkUSDKey, usdcUSDKey])
Expand Down Expand Up @@ -106,7 +107,7 @@ test('PythHttpClientCall: getAssetPricesFromAccounts should throw for invalid ac

try {
const programKey = getPythProgramKeyForCluster('testnet')
const currentConnection = new Connection(clusterApiUrl('testnet'))
const currentConnection = new Connection(getPythClusterApiUrl('pythtest-conformance'))
const pyth_client = new PythHttpClient(currentConnection, programKey)
pyth_client
.getAssetPricesFromAccounts([solUSDKey, systemProgram, usdcUSDKey])
Expand Down
36 changes: 36 additions & 0 deletions src/anchor/idl.json
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,42 @@
}
}
]
},
{
"name": "initPriceFeedIndex",
"discriminant": { "value": [2, 0, 0, 0, 19, 0, 0, 0] },
"accounts": [
{
"name": "fundingAccount",
"isMut": true,
"isSigner": true
},
{
"name": "priceAccount",
"isMut": true,
"isSigner": false
},
{
"name": "permissionsAccount",
"isMut": true,
"isSigner": false,
"pda": {
"seeds": [
{
"kind": "const",
"type": "string",
"value": "permissions"
}
]
}
},
{
"name": "systemProgram",
"isMut": false,
"isSigner": false
}
],
"args": []
}
],
"types": [
Expand Down
38 changes: 37 additions & 1 deletion src/anchor/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function pythOracleCoder(): PythOracleCoder {
export { default as pythIdl } from './idl.json'

export type PythOracle = {
version: '2.20.0'
version: '2.33.0'
name: 'pyth_oracle'
instructions: [
{
Expand Down Expand Up @@ -661,6 +661,42 @@ export type PythOracle = {
},
]
},
{
name: 'initPriceFeedIndex'
discriminant: { value: [2, 0, 0, 0, 19, 0, 0, 0] }
accounts: [
{
name: 'fundingAccount'
isMut: true
isSigner: true
},
{
name: 'priceAccount'
isMut: true
isSigner: false
},
{
name: 'permissionsAccount'
isMut: true
isSigner: false
pda: {
seeds: [
{
kind: 'const'
type: 'string'
value: 'permissions'
},
]
}
},
{
name: 'systemProgram'
isMut: false
isSigner: false
},
]
args: []
},
]
types: [
{
Expand Down
2 changes: 1 addition & 1 deletion src/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function getPythClusterApiUrl(cluster: PythCluster): string {
if (cluster === 'pythtest-conformance' || cluster === 'pythtest-crosschain') {
return 'https://api.pythtest.pyth.network'
} else if (cluster === 'pythnet') {
return 'https://pythnet.rpcpool.com'
return 'https://api2.pythnet.pyth.network'
} else if (cluster === 'localnet') {
return 'http://localhost:8899'
} else {
Expand Down
Loading