1
1
import { Contract , EventData } from "web3-eth-contract" ;
2
- import { PriceConfig } from "./price-config" ;
3
- import { ChainPricePusher , PriceInfo , ChainPriceListener } from "./interface" ;
2
+ import {
3
+ ChainPricePusher ,
4
+ PriceInfo ,
5
+ ChainPriceListener ,
6
+ PriceItem ,
7
+ } from "./interface" ;
4
8
import { TransactionReceipt } from "ethereum-protocol" ;
5
9
import { addLeading0x , DurationInSeconds , removeLeading0x } from "./utils" ;
6
10
import AbstractPythAbi from "@pythnetwork/pyth-sdk-solidity/abis/AbstractPyth.json" ;
@@ -17,23 +21,15 @@ import {
17
21
export class EvmPriceListener extends ChainPriceListener {
18
22
private pythContractFactory : PythContractFactory ;
19
23
private pythContract : Contract ;
20
- private priceIdToAlias : Map < HexString , string > ;
21
24
22
25
constructor (
23
26
pythContractFactory : PythContractFactory ,
24
- priceConfigs : PriceConfig [ ] ,
27
+ priceItems : PriceItem [ ] ,
25
28
config : {
26
29
pollingFrequency : DurationInSeconds ;
27
30
}
28
31
) {
29
- super (
30
- "Evm" ,
31
- config . pollingFrequency ,
32
- priceConfigs . map ( ( priceConfig ) => priceConfig . id )
33
- ) ;
34
- this . priceIdToAlias = new Map (
35
- priceConfigs . map ( ( priceConfig ) => [ priceConfig . id , priceConfig . alias ] )
36
- ) ;
32
+ super ( "Evm" , config . pollingFrequency , priceItems ) ;
37
33
38
34
this . pythContractFactory = pythContractFactory ;
39
35
this . pythContract = this . pythContractFactory . createPythContract ( ) ;
@@ -57,7 +53,7 @@ export class EvmPriceListener extends ChainPriceListener {
57
53
}
58
54
59
55
private async startSubscription ( ) {
60
- for ( const priceId of this . priceIds ) {
56
+ for ( const { id : priceId } of this . priceItems ) {
61
57
this . pythContract . events . PriceFeedUpdate (
62
58
{
63
59
filter : {
@@ -106,6 +102,12 @@ export class EvmPriceListener extends ChainPriceListener {
106
102
return undefined ;
107
103
}
108
104
105
+ console . log (
106
+ `Polled an EVM on chain price for feed ${ this . priceIdToAlias . get (
107
+ priceId
108
+ ) } (${ priceId } ).`
109
+ ) ;
110
+
109
111
return {
110
112
conf : priceRaw . conf ,
111
113
price : priceRaw . price ,
0 commit comments