Skip to content

Commit 6bd4e2d

Browse files
author
Dev Kalra
authored
[price-pusher] refactor index page (#636)
* refactor index page * remove pythcontractaddr * address comments * bug fix
1 parent c0b801e commit 6bd4e2d

File tree

10 files changed

+179
-109
lines changed

10 files changed

+179
-109
lines changed

package-lock.json

Lines changed: 74 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

price_pusher/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@
4747
},
4848
"dependencies": {
4949
"@injectivelabs/sdk-ts": "^1.0.457",
50-
"@pythnetwork/price-service-client": "*",
51-
"@pythnetwork/pyth-evm-js": "^1.1.0",
50+
"@pythnetwork/pyth-common-js": "^1.4.0",
5251
"@pythnetwork/pyth-sdk-solidity": "^2.2.0",
5352
"@truffle/hdwallet-provider": "^2.1.3",
5453
"joi": "^17.6.0",

price_pusher/src/controller.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { UnixTimestamp } from "@pythnetwork/pyth-evm-js";
1+
import { UnixTimestamp } from "@pythnetwork/pyth-common-js";
22
import { DurationInSeconds, sleep } from "./utils";
33
import { ChainPricePusher, IPriceListener } from "./interface";
44
import { PriceConfig, shouldUpdate } from "./price-config";
@@ -18,6 +18,10 @@ export class Controller {
1818
}
1919

2020
async start() {
21+
// start the listeners
22+
await this.sourcePriceListener.start();
23+
await this.targetPriceListener.start();
24+
2125
for (;;) {
2226
const pricesToPush: PriceConfig[] = [];
2327
const pubTimesToPush: UnixTimestamp[] = [];

price_pusher/src/evm.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
import {
2-
EvmPriceServiceConnection,
3-
HexString,
4-
UnixTimestamp,
5-
} from "@pythnetwork/pyth-evm-js";
61
import { Contract, EventData } from "web3-eth-contract";
72
import { PriceConfig } from "./price-config";
83
import { ChainPricePusher, PriceInfo, ChainPriceListener } from "./interface";
@@ -13,6 +8,11 @@ import HDWalletProvider from "@truffle/hdwallet-provider";
138
import { Provider } from "web3/providers";
149
import Web3 from "web3";
1510
import { isWsEndpoint } from "./utils";
11+
import {
12+
PriceServiceConnection,
13+
HexString,
14+
UnixTimestamp,
15+
} from "@pythnetwork/pyth-common-js";
1616

1717
export class EvmPriceListener extends ChainPriceListener {
1818
private pythContractFactory: PythContractFactory;
@@ -116,7 +116,7 @@ export class EvmPriceListener extends ChainPriceListener {
116116

117117
export 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

203212
export class PythContractFactory {

0 commit comments

Comments
 (0)