@pythnetwork/price-pusher
Version:
Pyth Price Pusher
104 lines (103 loc) • 4.78 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const hermes_client_1 = require("@pythnetwork/hermes-client");
const options = __importStar(require("../options"));
const price_config_1 = require("../price-config");
const pyth_price_listener_1 = require("../pyth-price-listener");
const controller_1 = require("../controller");
const near_1 = require("./near");
const pino_1 = __importDefault(require("pino"));
const utils_1 = require("../utils");
exports.default = {
command: "near",
describe: "run price pusher for near",
builder: {
"node-url": {
description: "NEAR RPC API url. used to make JSON RPC calls to interact with NEAR.",
type: "string",
required: true,
},
network: {
description: "testnet or mainnet.",
type: "string",
required: true,
},
"account-id": {
description: "payer account identifier.",
type: "string",
required: true,
},
"private-key-path": {
description: "path to payer private key file.",
type: "string",
required: false,
},
...options.priceConfigFile,
...options.priceServiceEndpoint,
...options.pythContractAddress,
...options.pollingFrequency,
...options.pushingFrequency,
...options.logLevel,
...options.controllerLogLevel,
},
handler: async function (argv) {
// FIXME: type checks for this
const { nodeUrl, network, accountId, privateKeyPath, priceConfigFile, priceServiceEndpoint, pythContractAddress, pushingFrequency, pollingFrequency, logLevel, controllerLogLevel, } = argv;
const logger = (0, pino_1.default)({ level: logLevel });
const priceConfigs = (0, price_config_1.readPriceConfigFile)(priceConfigFile);
const hermesClient = new hermes_client_1.HermesClient(priceServiceEndpoint);
let priceItems = priceConfigs.map(({ id, alias }) => ({ id, alias }));
// Better to filter out invalid price items before creating the pyth listener
const { existingPriceItems, invalidPriceItems } = await (0, utils_1.filterInvalidPriceItems)(hermesClient, priceItems);
if (invalidPriceItems.length > 0) {
logger.error(`Invalid price id submitted for: ${invalidPriceItems
.map(({ alias }) => alias)
.join(", ")}`);
}
priceItems = existingPriceItems;
const pythListener = new pyth_price_listener_1.PythPriceListener(hermesClient, priceItems, logger);
const nearAccount = new near_1.NearAccount(network, accountId, nodeUrl, privateKeyPath, pythContractAddress);
const nearListener = new near_1.NearPriceListener(nearAccount, priceItems, logger.child({ module: "NearPriceListener" }), {
pollingFrequency,
});
const nearPusher = new near_1.NearPricePusher(nearAccount, hermesClient, logger.child({ module: "NearPricePusher" }));
const controller = new controller_1.Controller(priceConfigs, pythListener, nearListener, nearPusher, logger.child({ module: "Controller" }, { level: controllerLogLevel }), { pushingFrequency });
controller.start();
},
};