1
- import {
2
- EvmPriceServiceConnection ,
3
- HexString ,
4
- UnixTimestamp ,
5
- } from "@pythnetwork/pyth-evm-js" ;
6
1
import { Contract , EventData } from "web3-eth-contract" ;
7
2
import { PriceConfig } from "./price-config" ;
8
3
import { ChainPricePusher , PriceInfo , ChainPriceListener } from "./interface" ;
@@ -13,6 +8,11 @@ import HDWalletProvider from "@truffle/hdwallet-provider";
13
8
import { Provider } from "web3/providers" ;
14
9
import Web3 from "web3" ;
15
10
import { isWsEndpoint } from "./utils" ;
11
+ import {
12
+ PriceServiceConnection ,
13
+ HexString ,
14
+ UnixTimestamp ,
15
+ } from "@pythnetwork/pyth-common-js" ;
16
16
17
17
export class EvmPriceListener extends ChainPriceListener {
18
18
private pythContractFactory : PythContractFactory ;
@@ -116,7 +116,7 @@ export class EvmPriceListener extends ChainPriceListener {
116
116
117
117
export class EvmPricePusher implements ChainPricePusher {
118
118
constructor (
119
- private connection : EvmPriceServiceConnection ,
119
+ private connection : PriceServiceConnection ,
120
120
private pythContract : Contract
121
121
) { }
122
122
// The pubTimes are passed here to use the values that triggered the push.
@@ -135,7 +135,7 @@ export class EvmPricePusher implements ChainPricePusher {
135
135
136
136
const priceIdsWith0x = priceIds . map ( ( priceId ) => addLeading0x ( priceId ) ) ;
137
137
138
- const priceFeedUpdateData = await this . connection . getPriceFeedsUpdateData (
138
+ const priceFeedUpdateData = await this . getPriceFeedsUpdateData (
139
139
priceIdsWith0x
140
140
) ;
141
141
@@ -198,6 +198,15 @@ export class EvmPricePusher implements ChainPricePusher {
198
198
throw err ;
199
199
} ) ;
200
200
}
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
+ }
201
210
}
202
211
203
212
export class PythContractFactory {
0 commit comments