2021-02-19 05:13:56 -08:00
|
|
|
import fs from "fs"
|
|
|
|
import { Wallet } from "solray"
|
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"
|
2021-02-20 02:11:02 -08:00
|
|
|
import { log } from "./log"
|
2021-02-19 05:13:56 -08:00
|
|
|
|
2021-02-20 02:11:02 -08:00
|
|
|
// Look at all the available aggregators and submit to those that the wallet can
|
|
|
|
// act as an oracle.
|
2021-02-19 05:13:56 -08:00
|
|
|
export class PriceFeeder {
|
|
|
|
constructor(
|
2021-02-20 02:11:02 -08:00
|
|
|
private deployInfo: AggregatorDeployFile,
|
2021-02-19 05:13:56 -08:00
|
|
|
private wallet: Wallet
|
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2021-02-20 02:11:02 -08:00
|
|
|
log.debug("Is not an oracle for:", name)
|
2021-02-19 05:13:56 -08:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
const priceFeed = coinbase(name)
|
|
|
|
const submitter = new Submitter(
|
|
|
|
this.deployInfo.programID,
|
|
|
|
aggregatorInfo.pubkey,
|
|
|
|
oracleInfo.pubkey,
|
|
|
|
this.wallet,
|
|
|
|
priceFeed,
|
|
|
|
{
|
2021-02-20 02:11:02 -08:00
|
|
|
// TODO: errrrr... probably make configurable on chain. hardwire for
|
|
|
|
// now, don't submit value unless btc changes at least a dollar
|
2021-02-19 05:13:56 -08:00
|
|
|
minValueChangeForNewRound: 100,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
submitter.start()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|