Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 74 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions price_pusher/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@
},
"dependencies": {
"@injectivelabs/sdk-ts": "^1.0.457",
"@pythnetwork/price-service-client": "*",
"@pythnetwork/pyth-evm-js": "^1.1.0",
"@pythnetwork/pyth-common-js": "^1.4.0",
"@pythnetwork/pyth-sdk-solidity": "^2.2.0",
"@truffle/hdwallet-provider": "^2.1.3",
"joi": "^17.6.0",
Expand Down
6 changes: 5 additions & 1 deletion price_pusher/src/controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { UnixTimestamp } from "@pythnetwork/pyth-evm-js";
import { UnixTimestamp } from "@pythnetwork/pyth-common-js";
import { DurationInSeconds, sleep } from "./utils";
import { ChainPricePusher, IPriceListener } from "./interface";
import { PriceConfig, shouldUpdate } from "./price-config";
Expand All @@ -18,6 +18,10 @@ export class Controller {
}

async start() {
// start the listeners
await this.sourcePriceListener.start();
await this.targetPriceListener.start();

for (;;) {
const pricesToPush: PriceConfig[] = [];
const pubTimesToPush: UnixTimestamp[] = [];
Expand Down
23 changes: 16 additions & 7 deletions price_pusher/src/evm.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import {
EvmPriceServiceConnection,
HexString,
UnixTimestamp,
} from "@pythnetwork/pyth-evm-js";
import { Contract, EventData } from "web3-eth-contract";
import { PriceConfig } from "./price-config";
import { ChainPricePusher, PriceInfo, ChainPriceListener } from "./interface";
Expand All @@ -13,6 +8,11 @@ import HDWalletProvider from "@truffle/hdwallet-provider";
import { Provider } from "web3/providers";
import Web3 from "web3";
import { isWsEndpoint } from "./utils";
import {
PriceServiceConnection,
HexString,
UnixTimestamp,
} from "@pythnetwork/pyth-common-js";

export class EvmPriceListener extends ChainPriceListener {
private pythContractFactory: PythContractFactory;
Expand Down Expand Up @@ -116,7 +116,7 @@ export class EvmPriceListener extends ChainPriceListener {

export class EvmPricePusher implements ChainPricePusher {
constructor(
private connection: EvmPriceServiceConnection,
private connection: PriceServiceConnection,
private pythContract: Contract
) {}
// The pubTimes are passed here to use the values that triggered the push.
Expand All @@ -135,7 +135,7 @@ export class EvmPricePusher implements ChainPricePusher {

const priceIdsWith0x = priceIds.map((priceId) => addLeading0x(priceId));

const priceFeedUpdateData = await this.connection.getPriceFeedsUpdateData(
const priceFeedUpdateData = await this.getPriceFeedsUpdateData(
priceIdsWith0x
);

Expand Down Expand Up @@ -198,6 +198,15 @@ export class EvmPricePusher implements ChainPricePusher {
throw err;
});
}

private async getPriceFeedsUpdateData(
priceIds: HexString[]
): Promise<string[]> {
const latestVaas = await this.connection.getLatestVaas(priceIds);
return latestVaas.map(
(vaa) => "0x" + Buffer.from(vaa, "base64").toString("hex")
);
}
}

export class PythContractFactory {
Expand Down
Loading