diff --git a/src/PriceFeeder.ts b/src/PriceFeeder.ts index cf70167..2f5bae2 100644 --- a/src/PriceFeeder.ts +++ b/src/PriceFeeder.ts @@ -1,28 +1,18 @@ import fs from "fs" import { Wallet } from "solray" -import { config } from "winston" import { AggregatorDeployFile } from "./Deployer" import { loadJSONFile } from "./json" import { coinbase } from "./feeds" import { Submitter, SubmitterConfig } from "./Submitter" +import { log } from "./log" -interface IPriceFeederConfig { - feeds: { - [key: string]: SubmitterConfig - } -} - +// Look at all the available aggregators and submit to those that the wallet can +// act as an oracle. export class PriceFeeder { - private deployInfo: AggregatorDeployFile - private config: IPriceFeederConfig - constructor( - deployInfoFile: string, - configFile: string, + private deployInfo: AggregatorDeployFile, private wallet: Wallet ) { - this.deployInfo = loadJSONFile(deployInfoFile) - this.config = loadJSONFile(configFile) } async start() { @@ -41,7 +31,7 @@ export class PriceFeeder { ) if (oracleInfo == null) { - console.log("no oracle found for:", name) + log.debug("Is not an oracle for:", name) continue } @@ -53,8 +43,8 @@ export class PriceFeeder { this.wallet, priceFeed, { - // TODO: errrrr... how do i make this configurable? - // don't submit value unless btc changes at least a dollar + // TODO: errrrr... probably make configurable on chain. hardwire for + // now, don't submit value unless btc changes at least a dollar minValueChangeForNewRound: 100, } ) diff --git a/src/cli.ts b/src/cli.ts index 6d5b309..d735b51 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -6,13 +6,25 @@ import { AggregatorDeployFile } from "./Deployer" import { conn, network } from "./context" import { AggregatorObserver } from "./AggregatorObserver" import { Aggregator, Answer } from "./schema" +import { PriceFeeder } from "./PriceFeeder" +import { walletFromEnv } from "./utils" const cli = new Command() +cli.command("oracle").action(async (name) => { + const wallet = await walletFromEnv("ORACLE_MNEMONIC", conn) + let deploy = loadJSONFile(process.env.DEPLOY_FILE!) + const feeder = new PriceFeeder(deploy, wallet) + feeder.start() +}) + cli.command("observe ").action(async (name) => { let deploy = loadJSONFile(process.env.DEPLOY_FILE!) const aggregatorInfo = deploy.aggregators[name] + if (!aggregatorInfo) { + throw new Error(`Cannot find aggregator: ${name}`) + } const observer = new AggregatorObserver(aggregatorInfo.pubkey, conn) let agg = await Aggregator.load(aggregatorInfo.pubkey)