@@ -2,10 +2,12 @@ import { useState, useEffect } from "react";
2
2
import { TextField , Select , MenuItem } from "@mui/material" ;
3
3
import { HermesClient , PriceFeedMetadata } from "@pythnetwork/hermes-client" ;
4
4
import { Table , Td , Th , Tr , CopyToClipboard } from "nextra/components" ;
5
+ import base58 from "bs58" ;
6
+ import { getPriceFeedAccountForProgram } from "@pythnetwork/pyth-solana-receiver" ;
5
7
6
- const fetchStablePriceFeeds = async ( ) => {
8
+ const fetchPriceFeeds = async ( stable : boolean ) => {
7
9
const priceFeeds = await new HermesClient (
8
- "https://hermes.pyth.network"
10
+ stable ? "https://hermes.pyth.network" : "https://hermes-beta .pyth.network"
9
11
) . getPriceFeeds ( ) ;
10
12
const assetTypes = Array . from (
11
13
new Set ( priceFeeds . map ( ( feed ) => feed . attributes . asset_type ?? "" ) )
@@ -14,15 +16,12 @@ const fetchStablePriceFeeds = async () => {
14
16
return { priceFeeds, assetTypes } ;
15
17
} ;
16
18
17
- const fetchBetaPriceFeeds = async ( ) => {
18
- const priceFeeds = await new HermesClient (
19
- "https://hermes-beta.pyth.network"
20
- ) . getPriceFeeds ( ) ;
21
- const assetTypes = Array . from (
22
- new Set ( priceFeeds . map ( ( feed ) => feed . attributes . asset_type ?? "" ) )
19
+ const fetchSolanaPriceFeedAccounts = async ( ) => {
20
+ const priceFeeds = await fetchPriceFeeds ( true ) ;
21
+ const priceFeedIds = priceFeeds . priceFeeds . map ( ( feed ) =>
22
+ getPriceFeedAccountForProgram ( 0 , base58 . decode ( feed . id ) ) . toBase58 ( )
23
23
) ;
24
- console . log ( priceFeeds ) ;
25
- return { priceFeeds, assetTypes } ;
24
+ return priceFeedIds ;
26
25
} ;
27
26
28
27
type AssetTypesSelectorProps = {
@@ -63,7 +62,8 @@ const usePriceFeeds = (): PriceFeedsState => {
63
62
64
63
useEffect ( ( ) => {
65
64
setPriceFeeds ( PriceFeedsState . Loading ( ) ) ;
66
- fetchStablePriceFeeds ( )
65
+ // console.log(fetchSolanaPriceFeedAccounts())
66
+ fetchPriceFeeds ( true )
67
67
. then ( ( { priceFeeds, assetTypes } ) => {
68
68
setPriceFeeds ( PriceFeedsState . Loaded ( priceFeeds , assetTypes ) ) ;
69
69
} )
0 commit comments