@@ -3,6 +3,7 @@ import { z } from "zod";
33
44import { PUBLIC_URL , VERCEL_AUTOMATION_BYPASS_SECRET } from '../config/server' ;
55import { Cluster , priceFeedsSchema } from "../services/pyth" ;
6+ import { DEFAULT_CACHE_TTL } from "../utils/cache" ;
67
78// Convenience helpers matching your previous functions
89export async function getPublishersForFeedCached (
@@ -11,7 +12,7 @@ export async function getPublishersForFeedCached(
1112) {
1213 const data = await fetch ( `${ PUBLIC_URL } /api/pyth/get-publishers/${ encodeURIComponent ( symbol ) } ?cluster=${ cluster . toString ( ) } ` , {
1314 next : {
14- revalidate : 1000 * 60 * 60 * 24 ,
15+ revalidate : DEFAULT_CACHE_TTL ,
1516 } ,
1617 headers : {
1718 'x-vercel-protection-bypass' : VERCEL_AUTOMATION_BYPASS_SECRET ,
@@ -26,12 +27,44 @@ export async function getFeedsForPublisherCached(
2627) {
2728 const data = await fetch ( `${ PUBLIC_URL } /api/pyth/get-feeds-for-publisher/${ encodeURIComponent ( publisher ) } ?cluster=${ cluster . toString ( ) } ` , {
2829 next : {
29- revalidate : 1000 * 60 * 60 * 24 ,
30+ revalidate : DEFAULT_CACHE_TTL ,
3031 } ,
3132 headers : {
3233 'x-vercel-protection-bypass' : VERCEL_AUTOMATION_BYPASS_SECRET ,
3334 } ,
3435 } ) ;
3536 const rawData = await data . text ( ) ;
3637 return parse < z . infer < typeof priceFeedsSchema > > ( rawData ) ;
38+ }
39+
40+ export const getFeedsCached = async ( cluster : Cluster ) => {
41+ const data = await fetch ( `${ PUBLIC_URL } /api/pyth/get-feeds?cluster=${ cluster . toString ( ) } &excludePriceComponents=true` , {
42+ next : {
43+ revalidate : DEFAULT_CACHE_TTL ,
44+ } ,
45+ headers : {
46+ 'x-vercel-protection-bypass' : VERCEL_AUTOMATION_BYPASS_SECRET ,
47+ } ,
48+ } ) ;
49+ const dataJson = await data . text ( ) ;
50+ const feeds : z . infer < typeof priceFeedsSchema > = parse ( dataJson ) ;
51+ return feeds ;
52+ }
53+
54+ export const getFeedForSymbolCached = async ( { symbol, cluster = Cluster . Pythnet } : { symbol : string , cluster ?: Cluster } ) : Promise < z . infer < typeof priceFeedsSchema > [ 0 ] | undefined > => {
55+ const data = await fetch ( `${ PUBLIC_URL } /api/pyth/get-feeds/${ encodeURIComponent ( symbol ) } ?cluster=${ cluster . toString ( ) } ` , {
56+ next : {
57+ revalidate : DEFAULT_CACHE_TTL ,
58+ } ,
59+ headers : {
60+ 'x-vercel-protection-bypass' : VERCEL_AUTOMATION_BYPASS_SECRET ,
61+ } ,
62+ } ) ;
63+
64+ if ( ! data . ok ) {
65+ return undefined ;
66+ }
67+ const dataJson = await data . text ( ) ;
68+ const feed : z . infer < typeof priceFeedsSchema > [ 0 ] = parse ( dataJson ) ;
69+ return feed ;
3770}
0 commit comments