1
- import type { PriceData , Product } from '@pythnetwork/client' ;
2
1
import superjson from "superjson" ;
2
+ import { z } from 'zod' ;
3
3
4
4
import { Cluster , clients , getFeeds , priceFeedsSchema } from "../services/pyth" ;
5
5
@@ -19,21 +19,28 @@ export const getPublishersForFeed = async (
19
19
const getAllFeeds = async ( cluster : Cluster ) => {
20
20
"use cache" ;
21
21
const data = await clients [ cluster ] . getData ( ) ;
22
- return superjson . stringify ( data . symbols . filter (
22
+
23
+ return superjson . stringify ( priceFeedsSchema . parse ( data . symbols . filter (
23
24
( symbol ) =>
24
25
data . productFromSymbol . get ( symbol ) ?. display_symbol !== undefined ,
25
26
) . map ( ( symbol ) => ( {
26
27
symbol,
27
28
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
+ } ) ) ) )
30
36
}
31
37
32
38
export const getFeedsForPublisherCached = async (
33
39
cluster : Cluster ,
34
40
publisher : string ,
35
41
) => {
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 ) ;
37
44
return priceFeedsSchema . parse ( feeds . filter ( ( { price } ) =>
38
45
price . priceComponents . some (
39
46
( component ) => component . publisher . toString ( ) === publisher ,
0 commit comments