1- import {
2- EvmPriceServiceConnection ,
3- HexString ,
4- UnixTimestamp ,
5- } from "@pythnetwork/pyth-evm-js" ;
61import { Contract , EventData } from "web3-eth-contract" ;
72import { PriceConfig } from "./price-config" ;
83import { ChainPricePusher , PriceInfo , ChainPriceListener } from "./interface" ;
@@ -13,6 +8,11 @@ import HDWalletProvider from "@truffle/hdwallet-provider";
138import { Provider } from "web3/providers" ;
149import Web3 from "web3" ;
1510import { isWsEndpoint } from "./utils" ;
11+ import {
12+ PriceServiceConnection ,
13+ HexString ,
14+ UnixTimestamp ,
15+ } from "@pythnetwork/pyth-common-js" ;
1616
1717export class EvmPriceListener extends ChainPriceListener {
1818 private pythContractFactory : PythContractFactory ;
@@ -116,7 +116,7 @@ export class EvmPriceListener extends ChainPriceListener {
116116
117117export class EvmPricePusher implements ChainPricePusher {
118118 constructor (
119- private connection : EvmPriceServiceConnection ,
119+ private connection : PriceServiceConnection ,
120120 private pythContract : Contract
121121 ) { }
122122 // The pubTimes are passed here to use the values that triggered the push.
@@ -135,7 +135,7 @@ export class EvmPricePusher implements ChainPricePusher {
135135
136136 const priceIdsWith0x = priceIds . map ( ( priceId ) => addLeading0x ( priceId ) ) ;
137137
138- const priceFeedUpdateData = await this . connection . getPriceFeedsUpdateData (
138+ const priceFeedUpdateData = await this . getPriceFeedsUpdateData (
139139 priceIdsWith0x
140140 ) ;
141141
@@ -198,6 +198,15 @@ export class EvmPricePusher implements ChainPricePusher {
198198 throw err ;
199199 } ) ;
200200 }
201+
202+ private async getPriceFeedsUpdateData (
203+ priceIds : HexString [ ]
204+ ) : Promise < string [ ] > {
205+ const latestVaas = await this . connection . getLatestVaas ( priceIds ) ;
206+ return latestVaas . map (
207+ ( vaa ) => "0x" + Buffer . from ( vaa , "base64" ) . toString ( "hex" )
208+ ) ;
209+ }
201210}
202211
203212export class PythContractFactory {
0 commit comments