1
- import { HexString , PriceServiceConnection } from "@pythnetwork/pyth-common-js" ;
2
1
import {
3
- ChainPricePusher ,
2
+ HexString ,
3
+ PriceServiceConnection ,
4
+ } from "@pythnetwork/price-service-client" ;
5
+ import {
6
+ IPricePusher ,
4
7
PriceInfo ,
5
8
ChainPriceListener ,
6
9
PriceItem ,
@@ -35,11 +38,10 @@ type UpdateFeeResponse = {
35
38
amount : string ;
36
39
} ;
37
40
38
- // FIXME: CLEANUP contractAddr variable name consistency
39
41
// this use price without leading 0x
40
42
export class InjectivePriceListener extends ChainPriceListener {
41
43
constructor (
42
- private contractAddress : string ,
44
+ private pythContractAddress : string ,
43
45
private grpcEndpoint : string ,
44
46
priceItems : PriceItem [ ] ,
45
47
config : {
@@ -56,14 +58,14 @@ export class InjectivePriceListener extends ChainPriceListener {
56
58
try {
57
59
const api = new ChainGrpcWasmApi ( this . grpcEndpoint ) ;
58
60
const { data } = await api . fetchSmartContractState (
59
- this . contractAddress ,
61
+ this . pythContractAddress ,
60
62
Buffer . from ( `{"price_feed":{"id":"${ priceId } "}}` ) . toString ( "base64" )
61
63
) ;
62
64
63
65
const json = Buffer . from ( data as string , "base64" ) . toString ( ) ;
64
66
priceQueryResponse = JSON . parse ( json ) ;
65
67
} catch ( e ) {
66
- console . error ( `Getting on-chain price for ${ priceId } failed. Error:` ) ;
68
+ console . error ( `Polling on-chain price for ${ priceId } failed. Error:` ) ;
67
69
console . error ( e ) ;
68
70
return undefined ;
69
71
}
@@ -82,11 +84,11 @@ export class InjectivePriceListener extends ChainPriceListener {
82
84
}
83
85
}
84
86
85
- export class InjectivePricePusher implements ChainPricePusher {
87
+ export class InjectivePricePusher implements IPricePusher {
86
88
private wallet : PrivateKey ;
87
89
constructor (
88
90
private priceServiceConnection : PriceServiceConnection ,
89
- private pythContract : string ,
91
+ private pythContractAddress : string ,
90
92
private grpcEndpoint : string ,
91
93
mnemonic : string
92
94
) {
@@ -160,7 +162,7 @@ export class InjectivePricePusher implements ChainPricePusher {
160
162
try {
161
163
const api = new ChainGrpcWasmApi ( this . grpcEndpoint ) ;
162
164
const { data } = await api . fetchSmartContractState (
163
- this . pythContract ,
165
+ this . pythContractAddress ,
164
166
Buffer . from (
165
167
JSON . stringify ( {
166
168
get_update_fee : {
@@ -178,11 +180,10 @@ export class InjectivePricePusher implements ChainPricePusher {
178
180
return ;
179
181
}
180
182
181
- // TODO: add specific error messages
182
183
try {
183
184
const executeMsg = MsgExecuteContract . fromJSON ( {
184
185
sender : this . injectiveAddress ( ) ,
185
- contractAddress : this . pythContract ,
186
+ contractAddress : this . pythContractAddress ,
186
187
msg : priceFeedUpdateObject ,
187
188
funds : [ updateFeeQueryResponse ] ,
188
189
} ) ;
0 commit comments