@@ -143,17 +143,40 @@ export class PriceServiceConnection {
143143 return [ ] ;
144144 }
145145
146- const response = await this . httpClient . get ( "/api/latest_price_feeds " , {
146+ const response = await this . httpClient . get ( "/v2/updates/price/latest " , {
147147 params : {
148148 ids : priceIds ,
149149 verbose : this . priceFeedRequestConfig . verbose ,
150150 binary : this . priceFeedRequestConfig . binary ,
151151 } ,
152152 } ) ;
153- const priceFeedsJson = response . data as any [ ] ;
154- return priceFeedsJson . map ( ( priceFeedJson ) =>
155- PriceFeed . fromJson ( priceFeedJson )
156- ) ;
153+ // Transform v2 API response to match old format
154+ const transformedPriceFeeds = response . data . parsed . map ( ( item : any ) => {
155+ const priceFeedJson : any = {
156+ id : item . id ,
157+ price : item . price ,
158+ ema_price : item . ema_price ,
159+ } ;
160+
161+ // Include metadata if verbose flag is set
162+ if ( this . priceFeedRequestConfig . verbose && item . metadata ) {
163+ priceFeedJson . metadata = item . metadata ;
164+ }
165+
166+ // Include VAA if binary flag is set
167+ if ( this . priceFeedRequestConfig . binary && response . data . binary ?. data ) {
168+ const vaaIndex = response . data . parsed . findIndex (
169+ ( p : any ) => p . id === item . id
170+ ) ;
171+ if ( vaaIndex >= 0 && vaaIndex < response . data . binary . data . length ) {
172+ priceFeedJson . vaa = response . data . binary . data [ vaaIndex ] ;
173+ }
174+ }
175+
176+ return PriceFeed . fromJson ( priceFeedJson ) ;
177+ } ) ;
178+
179+ return transformedPriceFeeds ;
157180 }
158181
159182 /**
@@ -164,14 +187,37 @@ export class PriceServiceConnection {
164187 *
165188 * @param priceIds Array of hex-encoded price ids.
166189 * @returns Array of base64 encoded VAAs.
190+ * @deprecated This method uses the v2 API endpoint which may return data in a different format.
191+ * Please verify the response format when using this method.
192+ */
193+ /**
194+ * Fetch latest VAA of given price ids.
195+ * This will throw an axios error if there is a network problem or the price service returns a non-ok response (e.g: Invalid price ids)
196+ *
197+ * This function is coupled to wormhole implementation.
198+ *
199+ * @param priceIds Array of hex-encoded price ids.
200+ * @returns Array of base64 encoded VAAs.
201+ * @deprecated This method uses the v2 API endpoint which may return data in a different format.
202+ * Please verify the response format when using this method.
167203 */
168204 async getLatestVaas ( priceIds : HexString [ ] ) : Promise < string [ ] > {
169- const response = await this . httpClient . get ( "/api/latest_vaas " , {
205+ const response = await this . httpClient . get ( "/v2/updates/price/latest " , {
170206 params : {
171207 ids : priceIds ,
208+ binary : true , // Always request binary data for VAAs
172209 } ,
173210 } ) ;
174- return response . data ;
211+
212+ // Extract VAAs from binary data array
213+ if (
214+ ! response . data . binary ?. data ||
215+ ! Array . isArray ( response . data . binary . data )
216+ ) {
217+ return [ ] ;
218+ }
219+
220+ return response . data . binary . data ;
175221 }
176222
177223 /**
@@ -185,18 +231,38 @@ export class PriceServiceConnection {
185231 * @param priceId Hex-encoded price id.
186232 * @param publishTime Epoch timestamp in seconds.
187233 * @returns Tuple of VAA and publishTime.
234+ * @deprecated This method uses the v2 API endpoint which may return data in a different format.
235+ * Please verify the response format when using this method.
188236 */
189237 async getVaa (
190238 priceId : HexString ,
191239 publishTime : EpochTimeStamp
192240 ) : Promise < [ string , EpochTimeStamp ] > {
193- const response = await this . httpClient . get ( "/api/get_vaa" , {
194- params : {
195- id : priceId ,
196- publish_time : publishTime ,
197- } ,
198- } ) ;
199- return [ response . data . vaa , response . data . publishTime ] ;
241+ const response = await this . httpClient . get (
242+ `/v2/updates/price/${ publishTime } ` ,
243+ {
244+ params : {
245+ id : priceId ,
246+ binary : true , // Always request binary data for VAAs
247+ } ,
248+ }
249+ ) ;
250+
251+ // Extract VAA and publishTime from response
252+ if ( ! response . data . binary ?. data ?. [ 0 ] || ! response . data . parsed ?. [ 0 ] ) {
253+ throw new Error (
254+ "No VAA data found for the given price id and publish time"
255+ ) ;
256+ }
257+
258+ const vaa = response . data . binary . data [ 0 ] ;
259+ const actualPublishTime = response . data . parsed [ 0 ] . price . publish_time ;
260+
261+ if ( actualPublishTime < publishTime ) {
262+ throw new Error ( "No VAA found after the specified publish time" ) ;
263+ }
264+
265+ return [ vaa , actualPublishTime ] ;
200266 }
201267
202268 /**
@@ -208,32 +274,78 @@ export class PriceServiceConnection {
208274 * @param priceId Hex-encoded price id.
209275 * @param publishTime Epoch timestamp in seconds.
210276 * @returns PriceFeed
277+ * @deprecated This method uses the v2 API endpoint which may return data in a different format.
278+ * Please verify the response format when using this method.
211279 */
212280 async getPriceFeed (
213281 priceId : HexString ,
214282 publishTime : EpochTimeStamp
215283 ) : Promise < PriceFeed > {
216- const response = await this . httpClient . get ( "/api/get_price_feed" , {
217- params : {
218- id : priceId ,
219- publish_time : publishTime ,
220- verbose : this . priceFeedRequestConfig . verbose ,
221- binary : this . priceFeedRequestConfig . binary ,
222- } ,
223- } ) ;
284+ const response = await this . httpClient . get (
285+ `/v2/updates/price/${ publishTime } ` ,
286+ {
287+ params : {
288+ id : priceId ,
289+ verbose : this . priceFeedRequestConfig . verbose ,
290+ binary : this . priceFeedRequestConfig . binary ,
291+ } ,
292+ }
293+ ) ;
294+
295+ // Extract price feed from response
296+ if ( ! response . data . parsed ?. [ 0 ] ) {
297+ throw new Error (
298+ "No price feed data found for the given price id and publish time"
299+ ) ;
300+ }
301+
302+ const priceFeedJson : any = {
303+ id : response . data . parsed [ 0 ] . id ,
304+ price : response . data . parsed [ 0 ] . price ,
305+ ema_price : response . data . parsed [ 0 ] . ema_price ,
306+ } ;
224307
225- return PriceFeed . fromJson ( response . data ) ;
308+ // Include metadata if verbose flag is set
309+ if (
310+ this . priceFeedRequestConfig . verbose &&
311+ response . data . parsed [ 0 ] . metadata
312+ ) {
313+ priceFeedJson . metadata = response . data . parsed [ 0 ] . metadata ;
314+ }
315+
316+ // Include VAA if binary flag is set
317+ if ( this . priceFeedRequestConfig . binary && response . data . binary ?. data ?. [ 0 ] ) {
318+ priceFeedJson . vaa = response . data . binary . data [ 0 ] ;
319+ }
320+
321+ return PriceFeed . fromJson ( priceFeedJson ) ;
226322 }
227323
228324 /**
229325 * Fetch the list of available price feed ids.
230326 * This will throw an axios error if there is a network problem or the price service returns a non-ok response.
231327 *
232328 * @returns Array of hex-encoded price ids.
329+ * @deprecated This method uses the v2 API endpoint which may return data in a different format.
330+ * Please verify the response format when using this method.
331+ */
332+ /**
333+ * Fetch the list of available price feed ids.
334+ * This will throw an axios error if there is a network problem or the price service returns a non-ok response.
335+ *
336+ * @returns Array of hex-encoded price ids.
337+ * @deprecated This method uses the v2 API endpoint which may return data in a different format.
338+ * Please verify the response format when using this method.
233339 */
234340 async getPriceFeedIds ( ) : Promise < HexString [ ] > {
235- const response = await this . httpClient . get ( "/api/price_feed_ids" ) ;
236- return response . data ;
341+ const response = await this . httpClient . get ( "/v2/price_feeds" ) ;
342+
343+ // Extract ids from response array
344+ if ( ! Array . isArray ( response . data ) ) {
345+ return [ ] ;
346+ }
347+
348+ return response . data . map ( ( item : any ) => item . id ) ;
237349 }
238350
239351 /**
0 commit comments