1- import type { PriceData , Product } from '@pythnetwork/client' ;
21import superjson from "superjson" ;
2+ import { z } from 'zod' ;
33
44import { Cluster , clients , getFeeds , priceFeedsSchema } from "../services/pyth" ;
55
@@ -19,21 +19,28 @@ export const getPublishersForFeed = async (
1919const getAllFeeds = async ( cluster : Cluster ) => {
2020 "use cache" ;
2121 const data = await clients [ cluster ] . getData ( ) ;
22- return superjson . stringify ( data . symbols . filter (
22+
23+ return superjson . stringify ( priceFeedsSchema . parse ( data . symbols . filter (
2324 ( symbol ) =>
2425 data . productFromSymbol . get ( symbol ) ?. display_symbol !== undefined ,
2526 ) . map ( ( symbol ) => ( {
2627 symbol,
2728 product : data . productFromSymbol . get ( symbol ) ,
28- price : data . productPrice . get ( symbol ) ,
29- } ) ) )
29+ price : {
30+ ...data . productPrice . get ( symbol ) ,
31+ priceComponents : data . productPrice . get ( symbol ) ?. priceComponents . map ( ( { publisher } ) => ( {
32+ publisher : publisher . toBase58 ( ) ,
33+ } ) ) ?? [ ] ,
34+ } ,
35+ } ) ) ) )
3036}
3137
3238export const getFeedsForPublisherCached = async (
3339 cluster : Cluster ,
3440 publisher : string ,
3541) => {
36- const feeds = superjson . parse < { symbol : string , product : Product , price : PriceData } [ ] > ( await getAllFeeds ( cluster ) ) ;
42+ const rawFeeds = await getAllFeeds ( cluster ) ;
43+ const feeds = superjson . parse < z . infer < typeof priceFeedsSchema > > ( rawFeeds ) ;
3744 return priceFeedsSchema . parse ( feeds . filter ( ( { price } ) =>
3845 price . priceComponents . some (
3946 ( component ) => component . publisher . toString ( ) === publisher ,
0 commit comments