|
@@ -1,6 +1,9 @@
|
|
|
-import { HexString, PriceServiceConnection } from "@pythnetwork/pyth-common-js";
|
|
|
|
|
import {
|
|
import {
|
|
|
- ChainPricePusher,
|
|
|
|
|
|
|
+ HexString,
|
|
|
|
|
+ PriceServiceConnection,
|
|
|
|
|
+} from "@pythnetwork/price-service-client";
|
|
|
|
|
+import {
|
|
|
|
|
+ IPricePusher,
|
|
|
PriceInfo,
|
|
PriceInfo,
|
|
|
ChainPriceListener,
|
|
ChainPriceListener,
|
|
|
PriceItem,
|
|
PriceItem,
|
|
@@ -35,11 +38,10 @@ type UpdateFeeResponse = {
|
|
|
amount: string;
|
|
amount: string;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-// FIXME: CLEANUP contractAddr variable name consistency
|
|
|
|
|
// this use price without leading 0x
|
|
// this use price without leading 0x
|
|
|
export class InjectivePriceListener extends ChainPriceListener {
|
|
export class InjectivePriceListener extends ChainPriceListener {
|
|
|
constructor(
|
|
constructor(
|
|
|
- private contractAddress: string,
|
|
|
|
|
|
|
+ private pythContractAddress: string,
|
|
|
private grpcEndpoint: string,
|
|
private grpcEndpoint: string,
|
|
|
priceItems: PriceItem[],
|
|
priceItems: PriceItem[],
|
|
|
config: {
|
|
config: {
|
|
@@ -56,14 +58,14 @@ export class InjectivePriceListener extends ChainPriceListener {
|
|
|
try {
|
|
try {
|
|
|
const api = new ChainGrpcWasmApi(this.grpcEndpoint);
|
|
const api = new ChainGrpcWasmApi(this.grpcEndpoint);
|
|
|
const { data } = await api.fetchSmartContractState(
|
|
const { data } = await api.fetchSmartContractState(
|
|
|
- this.contractAddress,
|
|
|
|
|
|
|
+ this.pythContractAddress,
|
|
|
Buffer.from(`{"price_feed":{"id":"${priceId}"}}`).toString("base64")
|
|
Buffer.from(`{"price_feed":{"id":"${priceId}"}}`).toString("base64")
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
const json = Buffer.from(data as string, "base64").toString();
|
|
const json = Buffer.from(data as string, "base64").toString();
|
|
|
priceQueryResponse = JSON.parse(json);
|
|
priceQueryResponse = JSON.parse(json);
|
|
|
} catch (e) {
|
|
} catch (e) {
|
|
|
- console.error(`Getting on-chain price for ${priceId} failed. Error:`);
|
|
|
|
|
|
|
+ console.error(`Polling on-chain price for ${priceId} failed. Error:`);
|
|
|
console.error(e);
|
|
console.error(e);
|
|
|
return undefined;
|
|
return undefined;
|
|
|
}
|
|
}
|
|
@@ -82,11 +84,11 @@ export class InjectivePriceListener extends ChainPriceListener {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-export class InjectivePricePusher implements ChainPricePusher {
|
|
|
|
|
|
|
+export class InjectivePricePusher implements IPricePusher {
|
|
|
private wallet: PrivateKey;
|
|
private wallet: PrivateKey;
|
|
|
constructor(
|
|
constructor(
|
|
|
private priceServiceConnection: PriceServiceConnection,
|
|
private priceServiceConnection: PriceServiceConnection,
|
|
|
- private pythContract: string,
|
|
|
|
|
|
|
+ private pythContractAddress: string,
|
|
|
private grpcEndpoint: string,
|
|
private grpcEndpoint: string,
|
|
|
mnemonic: string
|
|
mnemonic: string
|
|
|
) {
|
|
) {
|
|
@@ -160,7 +162,7 @@ export class InjectivePricePusher implements ChainPricePusher {
|
|
|
try {
|
|
try {
|
|
|
const api = new ChainGrpcWasmApi(this.grpcEndpoint);
|
|
const api = new ChainGrpcWasmApi(this.grpcEndpoint);
|
|
|
const { data } = await api.fetchSmartContractState(
|
|
const { data } = await api.fetchSmartContractState(
|
|
|
- this.pythContract,
|
|
|
|
|
|
|
+ this.pythContractAddress,
|
|
|
Buffer.from(
|
|
Buffer.from(
|
|
|
JSON.stringify({
|
|
JSON.stringify({
|
|
|
get_update_fee: {
|
|
get_update_fee: {
|
|
@@ -178,11 +180,10 @@ export class InjectivePricePusher implements ChainPricePusher {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // TODO: add specific error messages
|
|
|
|
|
try {
|
|
try {
|
|
|
const executeMsg = MsgExecuteContract.fromJSON({
|
|
const executeMsg = MsgExecuteContract.fromJSON({
|
|
|
sender: this.injectiveAddress(),
|
|
sender: this.injectiveAddress(),
|
|
|
- contractAddress: this.pythContract,
|
|
|
|
|
|
|
+ contractAddress: this.pythContractAddress,
|
|
|
msg: priceFeedUpdateObject,
|
|
msg: priceFeedUpdateObject,
|
|
|
funds: [updateFeeQueryResponse],
|
|
funds: [updateFeeQueryResponse],
|
|
|
});
|
|
});
|