Skip to content

Commit f2fcff4

Browse files
committed
update-3
1 parent 532316e commit f2fcff4

File tree

18 files changed

+109
-191
lines changed

18 files changed

+109
-191
lines changed

apps/price_pusher/src/aptos/aptos.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
} from "../interface";
77
import { AptosAccount, AptosClient } from "aptos";
88
import { DurationInSeconds } from "../utils";
9-
import { PriceServiceConnection } from "@pythnetwork/price-service-client";
9+
import { HermesClient } from "@pythnetwork/hermes-client";
1010
import { Logger } from "pino";
1111

1212
export class AptosPriceListener extends ChainPriceListener {
@@ -89,7 +89,7 @@ export class AptosPricePusher implements IPricePusher {
8989
private sequenceNumberLocked: boolean;
9090

9191
constructor(
92-
private priceServiceConnection: PriceServiceConnection,
92+
private hermesClient: HermesClient,
9393
private logger: Logger,
9494
private pythContractAddress: string,
9595
private endpoint: string,
@@ -107,11 +107,12 @@ export class AptosPricePusher implements IPricePusher {
107107
* @returns Array of price update data.
108108
*/
109109
async getPriceFeedsUpdateData(priceIds: string[]): Promise<number[][]> {
110-
// Fetch the latest price feed update VAAs from the price service
111-
const latestVaas = await this.priceServiceConnection.getLatestVaas(
112-
priceIds
110+
const response = await this.hermesClient.getLatestPriceUpdates(priceIds, {
111+
encoding: "base64",
112+
});
113+
return response.binary.data.map((data) =>
114+
Array.from(Buffer.from(data, "base64"))
113115
);
114-
return latestVaas.map((vaa) => Array.from(Buffer.from(vaa, "base64")));
115116
}
116117

117118
async updatePriceFeed(

apps/price_pusher/src/aptos/command.ts

Lines changed: 6 additions & 16 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 * as options from "../options";
33
import { readPriceConfigFile } from "../price-config";
44
import fs from "fs";
@@ -33,43 +33,33 @@ export default {
3333
default: 2,
3434
} as Options,
3535
...options.priceConfigFile,
36-
...options.priceServiceEndpoint,
36+
...options.hermesEndpoint,
3737
...options.mnemonicFile,
3838
...options.pythContractAddress,
3939
...options.pollingFrequency,
4040
...options.pushingFrequency,
4141
...options.logLevel,
42-
...options.priceServiceConnectionLogLevel,
4342
...options.controllerLogLevel,
4443
},
4544
handler: function (argv: any) {
4645
// FIXME: type checks for this
4746
const {
4847
endpoint,
4948
priceConfigFile,
50-
priceServiceEndpoint,
49+
hermesEndpoint,
5150
mnemonicFile,
5251
pythContractAddress,
5352
pushingFrequency,
5453
pollingFrequency,
5554
overrideGasPriceMultiplier,
5655
logLevel,
57-
priceServiceConnectionLogLevel,
5856
controllerLogLevel,
5957
} = argv;
6058

6159
const logger = pino({ level: logLevel });
6260

6361
const priceConfigs = readPriceConfigFile(priceConfigFile);
64-
const priceServiceConnection = new PriceServiceConnection(
65-
priceServiceEndpoint,
66-
{
67-
logger: logger.child(
68-
{ module: "PriceServiceConnection" },
69-
{ level: priceServiceConnectionLogLevel }
70-
),
71-
}
72-
);
62+
const hermesClient = new HermesClient(hermesEndpoint);
7363

7464
const mnemonic = fs.readFileSync(mnemonicFile, "utf-8").trim();
7565
const account = AptosAccount.fromDerivePath(
@@ -81,7 +71,7 @@ export default {
8171
const priceItems = priceConfigs.map(({ id, alias }) => ({ id, alias }));
8272

8373
const pythListener = new PythPriceListener(
84-
priceServiceConnection,
74+
hermesClient,
8575
priceItems,
8676
logger.child({ module: "PythPriceListener" })
8777
);
@@ -95,7 +85,7 @@ export default {
9585
);
9686

9787
const aptosPusher = new AptosPricePusher(
98-
priceServiceConnection,
88+
hermesClient,
9989
logger.child({ module: "AptosPricePusher" }),
10090
pythContractAddress,
10191
endpoint,

apps/price_pusher/src/evm/command.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,12 @@ export default {
7171
default: 1,
7272
} as Options,
7373
...options.priceConfigFile,
74-
...options.priceServiceEndpoint,
74+
...options.hermesEndpoint,
7575
...options.mnemonicFile,
7676
...options.pythContractAddress,
7777
...options.pollingFrequency,
7878
...options.pushingFrequency,
7979
...options.logLevel,
80-
...options.priceServiceConnectionLogLevel,
8180
...options.controllerLogLevel,
8281
},
8382
handler: async function (argv: any) {

apps/price_pusher/src/evm/evm.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export class EvmPricePusher implements IPricePusher {
128128
private lastPushAttempt: PushAttempt | undefined;
129129

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

159-
160159
const priceFeedUpdateData = (await this.getPriceFeedsUpdateData(
161160
priceIds
162161
)) as `0x${string}`[];
@@ -410,7 +409,7 @@ export class EvmPricePusher implements IPricePusher {
410409
private async getPriceFeedsUpdateData(
411410
priceIds: HexString[]
412411
): Promise<string[]> {
413-
const response = await this.connection.getLatestPriceUpdates(priceIds, {
412+
const response = await this.hermesClient.getLatestPriceUpdates(priceIds, {
414413
encoding: "hex",
415414
ignoreInvalidPriceIds: true,
416415
});

apps/price_pusher/src/fuel/command.ts

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Options } from "yargs";
22
import * as options from "../options";
33
import { readPriceConfigFile } from "../price-config";
4-
import { PriceServiceConnection } from "@pythnetwork/price-service-client";
4+
import { HermesClient } from "@pythnetwork/hermes-client";
55
import { PythPriceListener } from "../pyth-price-listener";
66
import { FuelPriceListener, FuelPricePusher } from "./fuel";
77
import { Controller } from "../controller";
@@ -29,11 +29,10 @@ export default {
2929
required: true,
3030
} as Options,
3131
...options.priceConfigFile,
32-
...options.priceServiceEndpoint,
32+
...options.hermesEndpoint,
3333
...options.pushingFrequency,
3434
...options.pollingFrequency,
3535
...options.logLevel,
36-
...options.priceServiceConnectionLogLevel,
3736
...options.controllerLogLevel,
3837
},
3938
handler: async function (argv: any) {
@@ -42,32 +41,23 @@ export default {
4241
privateKeyFile,
4342
pythContractAddress,
4443
priceConfigFile,
45-
priceServiceEndpoint,
44+
hermesEndpoint,
4645
pushingFrequency,
4746
pollingFrequency,
4847
logLevel,
49-
priceServiceConnectionLogLevel,
5048
controllerLogLevel,
5149
} = argv;
5250

5351
const logger = pino({ level: logLevel });
5452

5553
const priceConfigs = readPriceConfigFile(priceConfigFile);
5654

57-
const priceServiceConnection = new PriceServiceConnection(
58-
priceServiceEndpoint,
59-
{
60-
logger: logger.child(
61-
{ module: "PriceServiceConnection" },
62-
{ level: priceServiceConnectionLogLevel }
63-
),
64-
}
65-
);
55+
const hermesClient = new HermesClient(hermesEndpoint);
6656

6757
const priceItems = priceConfigs.map(({ id, alias }) => ({ id, alias }));
6858

6959
const pythListener = new PythPriceListener(
70-
priceServiceConnection,
60+
hermesClient,
7161
priceItems,
7262
logger.child({ module: "PythPriceListener" })
7363
);
@@ -87,7 +77,7 @@ export default {
8777
const fuelPricePusher = new FuelPricePusher(
8878
wallet,
8979
pythContractAddress,
90-
priceServiceConnection,
80+
hermesClient,
9181
logger.child({ module: "FuelPricePusher" })
9282
);
9383

apps/price_pusher/src/fuel/fuel.ts

Lines changed: 7 additions & 8 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 {
33
ChainPriceListener,
44
IPricePusher,
@@ -78,7 +78,7 @@ export class FuelPricePusher implements IPricePusher {
7878
constructor(
7979
private wallet: Wallet,
8080
private pythContractId: string,
81-
private priceServiceConnection: PriceServiceConnection,
81+
private hermesClient: HermesClient,
8282
private logger: Logger
8383
) {
8484
this.contract = new Contract(
@@ -99,17 +99,16 @@ export class FuelPricePusher implements IPricePusher {
9999

100100
let priceFeedUpdateData: string[];
101101
try {
102-
priceFeedUpdateData = await this.priceServiceConnection.getLatestVaas(
103-
priceIds
104-
);
102+
const response = await this.hermesClient.getLatestPriceUpdates(priceIds, {
103+
encoding: "base64",
104+
});
105+
priceFeedUpdateData = response.binary.data;
105106
} catch (err: any) {
106107
this.logger.error(err, "getPriceFeedsUpdateData failed");
107108
return;
108109
}
109110

110-
const updateData = priceFeedUpdateData.map((data) =>
111-
arrayify(Buffer.from(data, "base64"))
112-
);
111+
const updateData = priceFeedUpdateData.map((data) => arrayify(data));
113112

114113
try {
115114
const updateFee = await this.contract.functions

apps/price_pusher/src/injective/command.ts

Lines changed: 6 additions & 16 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 * as options from "../options";
33
import { readPriceConfigFile } from "../price-config";
44
import fs from "fs";
@@ -35,13 +35,12 @@ export default {
3535
type: "number",
3636
} as Options,
3737
...options.priceConfigFile,
38-
...options.priceServiceEndpoint,
38+
...options.hermesEndpoint,
3939
...options.mnemonicFile,
4040
...options.pythContractAddress,
4141
...options.pollingFrequency,
4242
...options.pushingFrequency,
4343
...options.logLevel,
44-
...options.priceServiceConnectionLogLevel,
4544
...options.controllerLogLevel,
4645
},
4746
handler: function (argv: any) {
@@ -51,14 +50,13 @@ export default {
5150
gasMultiplier,
5251
grpcEndpoint,
5352
priceConfigFile,
54-
priceServiceEndpoint,
53+
hermesEndpoint,
5554
mnemonicFile,
5655
pythContractAddress,
5756
pushingFrequency,
5857
pollingFrequency,
5958
network,
6059
logLevel,
61-
priceServiceConnectionLogLevel,
6260
controllerLogLevel,
6361
} = argv;
6462

@@ -69,21 +67,13 @@ export default {
6967
}
7068

7169
const priceConfigs = readPriceConfigFile(priceConfigFile);
72-
const priceServiceConnection = new PriceServiceConnection(
73-
priceServiceEndpoint,
74-
{
75-
logger: logger.child(
76-
{ module: "PriceServiceConnection" },
77-
{ level: priceServiceConnectionLogLevel }
78-
),
79-
}
80-
);
70+
const hermesClient = new HermesClient(hermesEndpoint);
8171
const mnemonic = fs.readFileSync(mnemonicFile, "utf-8").trim();
8272

8373
const priceItems = priceConfigs.map(({ id, alias }) => ({ id, alias }));
8474

8575
const pythListener = new PythPriceListener(
86-
priceServiceConnection,
76+
hermesClient,
8777
priceItems,
8878
logger.child({ module: "PythPriceListener" })
8979
);
@@ -98,7 +88,7 @@ export default {
9888
}
9989
);
10090
const injectivePusher = new InjectivePricePusher(
101-
priceServiceConnection,
91+
hermesClient,
10292
pythContractAddress,
10393
grpcEndpoint,
10494
logger.child({ module: "InjectivePricePusher" }),

apps/price_pusher/src/injective/injective.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import {
2-
HexString,
3-
PriceServiceConnection,
4-
} from "@pythnetwork/price-service-client";
1+
import { HexString, HermesClient } from "@pythnetwork/hermes-client";
52
import {
63
IPricePusher,
74
PriceInfo,
@@ -100,7 +97,7 @@ export class InjectivePricePusher implements IPricePusher {
10097
private account: Account | null = null;
10198

10299
constructor(
103-
private priceServiceConnection: PriceServiceConnection,
100+
private hermesClient: HermesClient,
104101
private pythContractAddress: string,
105102
private grpcEndpoint: string,
106103
private logger: Logger,
@@ -187,7 +184,10 @@ export class InjectivePricePusher implements IPricePusher {
187184
}
188185

189186
async getPriceFeedUpdateObject(priceIds: string[]): Promise<any> {
190-
const vaas = await this.priceServiceConnection.getLatestVaas(priceIds);
187+
const response = await this.hermesClient.getLatestPriceUpdates(priceIds, {
188+
encoding: "base64",
189+
});
190+
const vaas = response.binary.data;
191191

192192
return {
193193
update_price_feeds: {

0 commit comments

Comments
 (0)