solana-flux-aggregator/src/PriceFeeder.ts

66 lines
1.6 KiB
TypeScript
Raw Normal View History

2021-02-19 05:13:56 -08:00
import fs from "fs"
import { Wallet } from "solray"
import { config } from "winston"
2021-02-19 05:16:33 -08:00
import { AggregatorDeployFile } from "./Deployer"
2021-02-19 05:13:56 -08:00
import { loadJSONFile } from "./json"
2021-02-19 05:16:33 -08:00
import { coinbase } from "./feeds"
2021-02-19 05:13:56 -08:00
import { Submitter, SubmitterConfig } from "./Submitter"
interface IPriceFeederConfig {
feeds: {
[key: string]: SubmitterConfig
}
}
export class PriceFeeder {
private deployInfo: AggregatorDeployFile
private config: IPriceFeederConfig
constructor(
deployInfoFile: string,
configFile: string,
private wallet: Wallet
) {
this.deployInfo = loadJSONFile(deployInfoFile)
this.config = loadJSONFile(configFile)
}
async start() {
// find aggregators that this wallet can act as oracle
this.startAccessibleAggregators()
}
private startAccessibleAggregators() {
for (let [name, aggregatorInfo] of Object.entries(
this.deployInfo.aggregators
)) {
const oracleInfo = Object.values(aggregatorInfo.oracles).find(
(oracleInfo) => {
return oracleInfo.owner.equals(this.wallet.pubkey)
}
)
if (oracleInfo == null) {
console.log("no oracle found for:", name)
continue
}
const priceFeed = coinbase(name)
const submitter = new Submitter(
this.deployInfo.programID,
aggregatorInfo.pubkey,
oracleInfo.pubkey,
this.wallet,
priceFeed,
{
// TODO: errrrr... how do i make this configurable?
// don't submit value unless btc changes at least a dollar
minValueChangeForNewRound: 100,
}
)
submitter.start()
}
}
}