|
| 1 | +import { PriceServiceConnection } from "@pythnetwork/price-service-client"; |
| 2 | +import * as options from "../options"; |
| 3 | +import { readPriceConfigFile } from "../price-config"; |
| 4 | +import { PythPriceListener } from "../pyth-price-listener"; |
| 5 | +import { Controller } from "../controller"; |
| 6 | +import { Options } from "yargs"; |
| 7 | +import { NearAccount, NearPriceListener, NearPricePusher } from "./near"; |
| 8 | + |
| 9 | +export default { |
| 10 | + command: "near", |
| 11 | + describe: "run price pusher for near", |
| 12 | + builder: { |
| 13 | + "node-url": { |
| 14 | + description: |
| 15 | + "NEAR RPC API url. used to make JSON RPC calls to interact with NEAR.", |
| 16 | + type: "string", |
| 17 | + required: true, |
| 18 | + } as Options, |
| 19 | + network: { |
| 20 | + description: "testnet or mainnet.", |
| 21 | + type: "string", |
| 22 | + required: true, |
| 23 | + } as Options, |
| 24 | + "account-id": { |
| 25 | + description: "payer account identifier.", |
| 26 | + type: "string", |
| 27 | + required: true, |
| 28 | + } as Options, |
| 29 | + "private-key-path": { |
| 30 | + description: "path to payer private key file.", |
| 31 | + type: "string", |
| 32 | + required: false, |
| 33 | + } as Options, |
| 34 | + ...options.priceConfigFile, |
| 35 | + ...options.priceServiceEndpoint, |
| 36 | + ...options.pythContractAddress, |
| 37 | + ...options.pollingFrequency, |
| 38 | + ...options.pushingFrequency, |
| 39 | + }, |
| 40 | + handler: function (argv: any) { |
| 41 | + // FIXME: type checks for this |
| 42 | + const { |
| 43 | + nodeUrl, |
| 44 | + network, |
| 45 | + accountId, |
| 46 | + privateKeyPath, |
| 47 | + priceConfigFile, |
| 48 | + priceServiceEndpoint, |
| 49 | + pythContractAddress, |
| 50 | + pushingFrequency, |
| 51 | + pollingFrequency, |
| 52 | + } = argv; |
| 53 | + |
| 54 | + const priceConfigs = readPriceConfigFile(priceConfigFile); |
| 55 | + const priceServiceConnection = new PriceServiceConnection( |
| 56 | + priceServiceEndpoint, |
| 57 | + { |
| 58 | + logger: { |
| 59 | + // Log only warnings and errors from the price service client |
| 60 | + info: () => undefined, |
| 61 | + warn: console.warn, |
| 62 | + error: console.error, |
| 63 | + debug: () => undefined, |
| 64 | + trace: () => undefined, |
| 65 | + }, |
| 66 | + } |
| 67 | + ); |
| 68 | + |
| 69 | + const priceItems = priceConfigs.map(({ id, alias }) => ({ id, alias })); |
| 70 | + |
| 71 | + const pythListener = new PythPriceListener( |
| 72 | + priceServiceConnection, |
| 73 | + priceItems |
| 74 | + ); |
| 75 | + |
| 76 | + const nearAccount = new NearAccount( |
| 77 | + network, |
| 78 | + accountId, |
| 79 | + nodeUrl, |
| 80 | + privateKeyPath, |
| 81 | + pythContractAddress |
| 82 | + ); |
| 83 | + |
| 84 | + const nearListener = new NearPriceListener(nearAccount, priceItems, { |
| 85 | + pollingFrequency, |
| 86 | + }); |
| 87 | + |
| 88 | + const nearPusher = new NearPricePusher(nearAccount, priceServiceConnection); |
| 89 | + |
| 90 | + const controller = new Controller( |
| 91 | + priceConfigs, |
| 92 | + pythListener, |
| 93 | + nearListener, |
| 94 | + nearPusher, |
| 95 | + { pushingFrequency } |
| 96 | + ); |
| 97 | + |
| 98 | + controller.start(); |
| 99 | + }, |
| 100 | +}; |
0 commit comments