Skip to content

Commit 532316e

Browse files
committed
update-2
1 parent 74b4aa3 commit 532316e

File tree

5 files changed

+20
-31
lines changed

5 files changed

+20
-31
lines changed

apps/price_pusher/src/__tests__/pyth-price-listener.test.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { PythPriceListener } from "../pyth-price-listener";
2-
import { PriceServiceConnection } from "@pythnetwork/price-service-client";
2+
import { HermesClient } from "@pythnetwork/hermes-client";
33
import { Logger } from "pino";
44

55
describe("PythPriceListener", () => {
66
let logger: Logger;
7-
let connection: PriceServiceConnection;
7+
let connection: HermesClient;
88
let listener: PythPriceListener;
99
let originalConsoleError: typeof console.error;
1010

@@ -20,12 +20,10 @@ describe("PythPriceListener", () => {
2020
} as unknown as Logger;
2121

2222
// Use real Hermes beta endpoint for testing
23-
connection = new PriceServiceConnection("https://hermes.pyth.network");
23+
connection = new HermesClient("https://hermes.pyth.network");
2424
});
2525

2626
afterEach(() => {
27-
// Clean up websocket connection
28-
connection.closeWebSocket();
2927
// Clean up health check interval
3028
if (listener) {
3129
listener.cleanup();

apps/price_pusher/src/evm/command.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PriceServiceConnection } from "@pythnetwork/price-service-client";
1+
import { HermesClient } from "@pythnetwork/hermes-client";
22
import fs from "fs";
33
import { Options } from "yargs";
44
import * as options from "../options";
@@ -85,7 +85,7 @@ export default {
8585
const {
8686
endpoint,
8787
priceConfigFile,
88-
priceServiceEndpoint,
88+
hermesEndpoint,
8989
mnemonicFile,
9090
pythContractAddress,
9191
pushingFrequency,
@@ -97,29 +97,20 @@ export default {
9797
gasLimit,
9898
updateFeeMultiplier,
9999
logLevel,
100-
priceServiceConnectionLogLevel,
101100
controllerLogLevel,
102101
} = argv;
103102

104103
const logger = pino({ level: logLevel });
105104

106105
const priceConfigs = readPriceConfigFile(priceConfigFile);
107-
const priceServiceConnection = new PriceServiceConnection(
108-
priceServiceEndpoint,
109-
{
110-
logger: logger.child(
111-
{ module: "PriceServiceConnection" },
112-
{ level: priceServiceConnectionLogLevel }
113-
),
114-
}
115-
);
106+
const hermesClient = new HermesClient(hermesEndpoint);
116107

117108
const mnemonic = fs.readFileSync(mnemonicFile, "utf-8").trim();
118109

119110
const priceItems = priceConfigs.map(({ id, alias }) => ({ id, alias }));
120111

121112
const pythListener = new PythPriceListener(
122-
priceServiceConnection,
113+
hermesClient,
123114
priceItems,
124115
logger.child({ module: "PythPriceListener" })
125116
);
@@ -152,7 +143,7 @@ export default {
152143
txSpeed
153144
);
154145
const evmPusher = new EvmPricePusher(
155-
priceServiceConnection,
146+
hermesClient,
156147
client,
157148
pythContract,
158149
logger.child({ module: "EvmPricePusher" }),

apps/price_pusher/src/evm/evm.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ import {
1313
import { PythAbi } from "./pyth-abi";
1414
import { Logger } from "pino";
1515
import {
16-
PriceServiceConnection,
16+
HermesClient,
1717
HexString,
1818
UnixTimestamp,
19-
} from "@pythnetwork/price-service-client";
19+
} from "@pythnetwork/hermes-client";
2020
import { CustomGasStation } from "./custom-gas-station";
2121
import { PushAttempt } from "../common";
2222
import {
@@ -128,7 +128,7 @@ export class EvmPricePusher implements IPricePusher {
128128
private lastPushAttempt: PushAttempt | undefined;
129129

130130
constructor(
131-
private connection: PriceServiceConnection,
131+
private connection: HermesClient,
132132
private client: SuperWalletClient,
133133
private pythContract: PythContract,
134134
private logger: Logger,
@@ -156,10 +156,9 @@ export class EvmPricePusher implements IPricePusher {
156156
if (priceIds.length !== pubTimesToPush.length)
157157
throw new Error("Invalid arguments");
158158

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

161160
const priceFeedUpdateData = (await this.getPriceFeedsUpdateData(
162-
priceIdsWith0x
161+
priceIds
163162
)) as `0x${string}`[];
164163

165164
let updateFee;
@@ -227,6 +226,8 @@ export class EvmPricePusher implements IPricePusher {
227226
BigInt(pubTime)
228227
);
229228

229+
const priceIdsWith0x = priceIds.map((priceId) => addLeading0x(priceId));
230+
230231
try {
231232
const { request } =
232233
await this.pythContract.simulate.updatePriceFeedsIfNecessary(
@@ -409,9 +410,10 @@ export class EvmPricePusher implements IPricePusher {
409410
private async getPriceFeedsUpdateData(
410411
priceIds: HexString[]
411412
): Promise<string[]> {
412-
const latestVaas = await this.connection.getLatestVaas(priceIds);
413-
return latestVaas.map(
414-
(vaa) => "0x" + Buffer.from(vaa, "base64").toString("hex")
415-
);
413+
const response = await this.connection.getLatestPriceUpdates(priceIds, {
414+
encoding: "hex",
415+
ignoreInvalidPriceIds: true,
416+
});
417+
return response.binary.data;
416418
}
417419
}

apps/price_pusher/src/pyth-price-listener.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import {
22
HexString,
33
HermesClient,
4-
PriceUpdate,
54
} from "@pythnetwork/hermes-client";
65
import { PriceInfo, IPriceListener, PriceItem } from "./interface";
76
import { Logger } from "pino";
8-
import { PriceFeed } from "@pythnetwork/price-service-sdk";
97

108
type TimestampInMs = number & { readonly _: unique symbol };
119

apps/price_pusher/src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { HexString } from "@pythnetwork/price-service-client";
1+
import { HexString } from "@pythnetwork/hermes-client";
22

33
export type PctNumber = number;
44
export type DurationInSeconds = number;

0 commit comments

Comments
 (0)