@pythnetwork/price-pusher 8.0.0 → 8.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,20 @@
1
+ import { Options } from "yargs";
2
+ declare const _default: {
3
+ command: string;
4
+ describe: string;
5
+ builder: {
6
+ "controller-log-level": Options;
7
+ "price-service-connection-log-level": Options;
8
+ "log-level": Options;
9
+ "polling-frequency": Options;
10
+ "pushing-frequency": Options;
11
+ "price-service-endpoint": Options;
12
+ "price-config-file": Options;
13
+ endpoint: Options;
14
+ "private-key-file": Options;
15
+ "pyth-contract-address": Options;
16
+ };
17
+ handler: (argv: any) => Promise<void>;
18
+ };
19
+ export default _default;
20
+ //# sourceMappingURL=command.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../src/fuel/command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;;;;;;;;;;;;;;;;oBAsCC,GAAG;;AA3BpC,wBA6FE"}
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ const options = __importStar(require("../options"));
30
+ const price_config_1 = require("../price-config");
31
+ const price_service_client_1 = require("@pythnetwork/price-service-client");
32
+ const pyth_price_listener_1 = require("../pyth-price-listener");
33
+ const fuel_1 = require("./fuel");
34
+ const controller_1 = require("../controller");
35
+ const fuels_1 = require("fuels");
36
+ const fs_1 = __importDefault(require("fs"));
37
+ const pino_1 = __importDefault(require("pino"));
38
+ exports.default = {
39
+ command: "fuel",
40
+ describe: "run price pusher for Fuel",
41
+ builder: {
42
+ endpoint: {
43
+ description: "Fuel RPC API endpoint",
44
+ type: "string",
45
+ required: true,
46
+ },
47
+ "private-key-file": {
48
+ description: "Path to the private key file",
49
+ type: "string",
50
+ required: true,
51
+ },
52
+ "pyth-contract-address": {
53
+ description: "Pyth contract address on Fuel",
54
+ type: "string",
55
+ required: true,
56
+ },
57
+ ...options.priceConfigFile,
58
+ ...options.priceServiceEndpoint,
59
+ ...options.pushingFrequency,
60
+ ...options.pollingFrequency,
61
+ ...options.logLevel,
62
+ ...options.priceServiceConnectionLogLevel,
63
+ ...options.controllerLogLevel,
64
+ },
65
+ handler: async function (argv) {
66
+ const { endpoint, privateKeyFile, pythContractAddress, priceConfigFile, priceServiceEndpoint, pushingFrequency, pollingFrequency, logLevel, priceServiceConnectionLogLevel, controllerLogLevel, } = argv;
67
+ const logger = (0, pino_1.default)({ level: logLevel });
68
+ const priceConfigs = (0, price_config_1.readPriceConfigFile)(priceConfigFile);
69
+ const priceServiceConnection = new price_service_client_1.PriceServiceConnection(priceServiceEndpoint, {
70
+ logger: logger.child({ module: "PriceServiceConnection" }, { level: priceServiceConnectionLogLevel }),
71
+ });
72
+ const priceItems = priceConfigs.map(({ id, alias }) => ({ id, alias }));
73
+ const pythListener = new pyth_price_listener_1.PythPriceListener(priceServiceConnection, priceItems, logger.child({ module: "PythPriceListener" }));
74
+ const provider = await fuels_1.Provider.create(endpoint);
75
+ const privateKey = fs_1.default.readFileSync(privateKeyFile, "utf8").trim();
76
+ const wallet = fuels_1.Wallet.fromPrivateKey(privateKey, provider);
77
+ const fuelPriceListener = new fuel_1.FuelPriceListener(provider, pythContractAddress, priceItems, logger.child({ module: "FuelPriceListener" }), { pollingFrequency });
78
+ const fuelPricePusher = new fuel_1.FuelPricePusher(wallet, pythContractAddress, priceServiceConnection, logger.child({ module: "FuelPricePusher" }));
79
+ const controller = new controller_1.Controller(priceConfigs, pythListener, fuelPriceListener, fuelPricePusher, logger.child({ module: "Controller" }, { level: controllerLogLevel }), { pushingFrequency });
80
+ await controller.start();
81
+ },
82
+ };
@@ -0,0 +1,25 @@
1
+ import { PriceServiceConnection } from "@pythnetwork/price-service-client";
2
+ import { ChainPriceListener, IPricePusher, PriceInfo, PriceItem } from "../interface";
3
+ import { DurationInSeconds } from "../utils";
4
+ import { Logger } from "pino";
5
+ import { Provider, Wallet } from "fuels";
6
+ export declare class FuelPriceListener extends ChainPriceListener {
7
+ private provider;
8
+ private pythContractId;
9
+ private logger;
10
+ private contract;
11
+ constructor(provider: Provider, pythContractId: string, priceItems: PriceItem[], logger: Logger, config: {
12
+ pollingFrequency: DurationInSeconds;
13
+ });
14
+ getOnChainPriceInfo(priceId: string): Promise<PriceInfo | undefined>;
15
+ }
16
+ export declare class FuelPricePusher implements IPricePusher {
17
+ private wallet;
18
+ private pythContractId;
19
+ private priceServiceConnection;
20
+ private logger;
21
+ private contract;
22
+ constructor(wallet: Wallet, pythContractId: string, priceServiceConnection: PriceServiceConnection, logger: Logger);
23
+ updatePriceFeed(priceIds: string[], pubTimesToPush: number[]): Promise<void>;
24
+ }
25
+ //# sourceMappingURL=fuel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fuel.d.ts","sourceRoot":"","sources":["../../src/fuel/fuel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAC3E,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,SAAS,EACT,SAAS,EACV,MAAM,cAAc,CAAC;AACtB,OAAO,EAAgB,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC3D,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,EAAE,QAAQ,EAA+B,MAAM,EAAM,MAAM,OAAO,CAAC;AAc1E,qBAAa,iBAAkB,SAAQ,kBAAkB;IAIrD,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,cAAc;IAEtB,OAAO,CAAC,MAAM;IANhB,OAAO,CAAC,QAAQ,CAAW;gBAGjB,QAAQ,EAAE,QAAQ,EAClB,cAAc,EAAE,MAAM,EAC9B,UAAU,EAAE,SAAS,EAAE,EACf,MAAM,EAAE,MAAM,EACtB,MAAM,EAAE;QACN,gBAAgB,EAAE,iBAAiB,CAAC;KACrC;IAUG,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;CA6B3E;AAED,qBAAa,eAAgB,YAAW,YAAY;IAIhD,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,cAAc;IACtB,OAAO,CAAC,sBAAsB;IAC9B,OAAO,CAAC,MAAM;IANhB,OAAO,CAAC,QAAQ,CAAW;gBAGjB,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,MAAM,EACtB,sBAAsB,EAAE,sBAAsB,EAC9C,MAAM,EAAE,MAAM;IASlB,eAAe,CACnB,QAAQ,EAAE,MAAM,EAAE,EAElB,cAAc,EAAE,MAAM,EAAE,GACvB,OAAO,CAAC,IAAI,CAAC;CAuCjB"}
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FuelPricePusher = exports.FuelPriceListener = void 0;
4
+ const interface_1 = require("../interface");
5
+ const utils_1 = require("../utils");
6
+ const fuels_1 = require("fuels");
7
+ const pyth_fuel_js_1 = require("@pythnetwork/pyth-fuel-js");
8
+ // Convert TAI64 timestamp to Unix timestamp
9
+ function tai64ToUnix(tai64) {
10
+ // TAI64 is 2^62 seconds ahead of Unix epoch (1970-01-01)
11
+ // Additional 10-second offset accounts for TAI being ahead of UTC at Unix epoch
12
+ const result = BigInt(tai64.toString()) - BigInt(2n ** 62n) - 10n;
13
+ return Number(result);
14
+ }
15
+ class FuelPriceListener extends interface_1.ChainPriceListener {
16
+ provider;
17
+ pythContractId;
18
+ logger;
19
+ contract;
20
+ constructor(provider, pythContractId, priceItems, logger, config) {
21
+ super(config.pollingFrequency, priceItems);
22
+ this.provider = provider;
23
+ this.pythContractId = pythContractId;
24
+ this.logger = logger;
25
+ this.contract = new fuels_1.Contract(this.pythContractId, pyth_fuel_js_1.PYTH_CONTRACT_ABI, this.provider);
26
+ }
27
+ async getOnChainPriceInfo(priceId) {
28
+ try {
29
+ const formattedPriceId = (0, utils_1.addLeading0x)(priceId);
30
+ const priceInfo = await this.contract.functions
31
+ .price_unsafe(formattedPriceId)
32
+ .get();
33
+ console.log({
34
+ conf: priceInfo.value.confidence.toString(),
35
+ price: priceInfo.value.price.toString(),
36
+ publishTime: tai64ToUnix(priceInfo.value.publish_time),
37
+ });
38
+ this.logger.debug(`Polled a Fuel on chain price for feed ${this.priceIdToAlias.get(priceId)} (${priceId}).`);
39
+ return {
40
+ conf: priceInfo.value.confidence.toString(),
41
+ price: priceInfo.value.price.toString(),
42
+ publishTime: tai64ToUnix(priceInfo.value.publish_time),
43
+ };
44
+ }
45
+ catch (err) {
46
+ this.logger.error({ err, priceId }, `Polling on-chain price failed.`);
47
+ return undefined;
48
+ }
49
+ }
50
+ }
51
+ exports.FuelPriceListener = FuelPriceListener;
52
+ class FuelPricePusher {
53
+ wallet;
54
+ pythContractId;
55
+ priceServiceConnection;
56
+ logger;
57
+ contract;
58
+ constructor(wallet, pythContractId, priceServiceConnection, logger) {
59
+ this.wallet = wallet;
60
+ this.pythContractId = pythContractId;
61
+ this.priceServiceConnection = priceServiceConnection;
62
+ this.logger = logger;
63
+ this.contract = new fuels_1.Contract(this.pythContractId, pyth_fuel_js_1.PYTH_CONTRACT_ABI, this.wallet);
64
+ }
65
+ async updatePriceFeed(priceIds,
66
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
67
+ pubTimesToPush) {
68
+ if (priceIds.length === 0) {
69
+ return;
70
+ }
71
+ let priceFeedUpdateData;
72
+ try {
73
+ priceFeedUpdateData = await this.priceServiceConnection.getLatestVaas(priceIds);
74
+ }
75
+ catch (err) {
76
+ this.logger.error(err, "getPriceFeedsUpdateData failed");
77
+ return;
78
+ }
79
+ const updateData = priceFeedUpdateData.map((data) => (0, fuels_1.arrayify)(Buffer.from(data, "base64")));
80
+ try {
81
+ const updateFee = await this.contract.functions
82
+ .update_fee(updateData)
83
+ .get();
84
+ const result = await this.contract.functions
85
+ .update_price_feeds(updateData)
86
+ .callParams({
87
+ forward: [updateFee.value, (0, fuels_1.hexlify)(pyth_fuel_js_1.FUEL_ETH_ASSET_ID)],
88
+ })
89
+ .call();
90
+ this.logger.info({ transactionId: result.transactionId }, "updatePriceFeed successful");
91
+ }
92
+ catch (err) {
93
+ this.logger.error(err, "updatePriceFeed failed");
94
+ }
95
+ }
96
+ }
97
+ exports.FuelPricePusher = FuelPricePusher;
package/lib/index.js CHANGED
@@ -12,6 +12,7 @@ const command_3 = __importDefault(require("./aptos/command"));
12
12
  const command_4 = __importDefault(require("./sui/command"));
13
13
  const command_5 = __importDefault(require("./near/command"));
14
14
  const command_6 = __importDefault(require("./solana/command"));
15
+ const command_7 = __importDefault(require("./fuel/command"));
15
16
  (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
16
17
  .parserConfiguration({
17
18
  "parse-numbers": false,
@@ -19,6 +20,7 @@ const command_6 = __importDefault(require("./solana/command"));
19
20
  .config("config")
20
21
  .global("config")
21
22
  .command(command_2.default)
23
+ .command(command_7.default)
22
24
  .command(command_1.default)
23
25
  .command(command_3.default)
24
26
  .command(command_4.default)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pythnetwork/price-pusher",
3
- "version": "8.0.0",
3
+ "version": "8.0.1",
4
4
  "description": "Pyth Price Pusher",
5
5
  "homepage": "https://pyth.network",
6
6
  "main": "lib/index.js",
@@ -35,7 +35,11 @@
35
35
  "oracle",
36
36
  "evm",
37
37
  "ethereum",
38
- "injective"
38
+ "injective",
39
+ "fuel",
40
+ "aptos",
41
+ "sui",
42
+ "near"
39
43
  ],
40
44
  "license": "Apache-2.0",
41
45
  "devDependencies": {
@@ -59,13 +63,15 @@
59
63
  "@mysten/sui": "^1.3.0",
60
64
  "@pythnetwork/price-service-client": "1.9.0",
61
65
  "@pythnetwork/price-service-sdk": "^1.7.1",
66
+ "@pythnetwork/pyth-fuel-js": "1.0.6",
62
67
  "@pythnetwork/pyth-sdk-solidity": "4.0.0",
63
- "@pythnetwork/pyth-solana-receiver": "0.8.1",
68
+ "@pythnetwork/pyth-solana-receiver": "0.8.2",
64
69
  "@pythnetwork/pyth-sui-js": "2.1.0",
65
70
  "@pythnetwork/solana-utils": "0.4.2",
66
71
  "@solana/web3.js": "^1.93.0",
67
72
  "@types/pino": "^7.0.5",
68
73
  "aptos": "^1.8.5",
74
+ "fuels": "^0.94.5",
69
75
  "jito-ts": "^3.0.1",
70
76
  "joi": "^17.6.0",
71
77
  "near-api-js": "^3.0.2",
@@ -74,5 +80,5 @@
74
80
  "yaml": "^2.1.1",
75
81
  "yargs": "^17.5.1"
76
82
  },
77
- "gitHead": "525ad190de4dfcc1e95502ec056ad446fa6041f5"
83
+ "gitHead": "9109f5f49bf31e8ff4a915bbff2d5f6b1e4f96aa"
78
84
  }