commit
fbba3cc410
|
@ -16,6 +16,25 @@ import { Submitter, SubmitterConfig } from "./Submitter"
|
|||
import { log } from "./log"
|
||||
import { conn } from "./context"
|
||||
|
||||
const priceFeedMapping = {
|
||||
'btc:usd': {
|
||||
minValueChangeForNewRound: 5000,
|
||||
useFeeds: [0,1,2,3]
|
||||
},
|
||||
'eth:usd': {
|
||||
minValueChangeForNewRound: 150,
|
||||
useFeeds: [0,1,2,3]
|
||||
},
|
||||
'sol:usd': {
|
||||
minValueChangeForNewRound: 4,
|
||||
useFeeds: [2,3,4]
|
||||
},
|
||||
'srm:usd': {
|
||||
minValueChangeForNewRound: 1,
|
||||
useFeeds: [2,3,4]
|
||||
},
|
||||
}
|
||||
|
||||
// Look at all the available aggregators and submit to those that the wallet can
|
||||
// act as an oracle.
|
||||
export class PriceFeeder {
|
||||
|
@ -33,7 +52,6 @@ export class PriceFeeder {
|
|||
for (const feed of this.feeds) {
|
||||
feed.connect()
|
||||
}
|
||||
|
||||
// find aggregators that this wallet can act as oracle
|
||||
this.startAccessibleAggregators()
|
||||
}
|
||||
|
@ -58,19 +76,11 @@ export class PriceFeeder {
|
|||
continue
|
||||
}
|
||||
|
||||
const feed = new AggregatedFeed(this.feeds, name)
|
||||
const useFeeds = (priceFeedMapping[name]) ? priceFeedMapping[name].useFeeds.map(x => this.feeds[x]) : this.feeds;
|
||||
const feed = new AggregatedFeed(useFeeds, name)
|
||||
const priceFeed = feed.medians()
|
||||
|
||||
let minValueChangeForNewRound = 100
|
||||
if (name === "btc:usd") {
|
||||
minValueChangeForNewRound = 5000
|
||||
} else if (name === "eth:usd") {
|
||||
minValueChangeForNewRound = 150
|
||||
} else if (name === "sol:usd") {
|
||||
minValueChangeForNewRound = 4
|
||||
} else if (name === "srm:usd") {
|
||||
minValueChangeForNewRound = 1
|
||||
}
|
||||
const minValueChangeForNewRound = priceFeedMapping[name].minValueChangeForNewRound || 100
|
||||
|
||||
const submitter = new Submitter(
|
||||
this.deployInfo.programID,
|
||||
|
|
14
src/feeds.ts
14
src/feeds.ts
|
@ -286,12 +286,12 @@ export class Binance extends PriceFeed {
|
|||
if (payload.e != "trade") {
|
||||
return
|
||||
}
|
||||
// "btcusdt" => "btc:usd"
|
||||
// "btcbusd" => "btc:usd"
|
||||
// assume that the base symbol for the pair is 3 letters
|
||||
const baseCurrency = payload.s.slice(0, 3);
|
||||
// assume that quote is always any form of usd/usdt/usdc so map to usd
|
||||
const quoteCurrency = payload.s.slice(3, 3);
|
||||
const pair = `${baseCurrency.toLowerCase()}:${quoteCurrency.toLowerCase()}`;
|
||||
const baseCurrency = payload.s.slice(0, 3).toLowerCase();
|
||||
const quoteCurrency = payload.s.slice(3).toLowerCase();
|
||||
const pair = `${baseCurrency}:${quoteCurrency == 'busd' ? 'usd' : quoteCurrency}`;
|
||||
|
||||
|
||||
const price: IPrice = {
|
||||
source: Binance.name,
|
||||
|
@ -304,9 +304,9 @@ export class Binance extends PriceFeed {
|
|||
}
|
||||
|
||||
async handleSubscribe(pair: string) {
|
||||
// "btc:usd" => "btcusdt"
|
||||
// "btc:usd" => "btcbusd"
|
||||
const [baseCurrency, quoteCurrency] = pair.split(':')
|
||||
const targetPair = `${baseCurrency}${(quoteCurrency.toLowerCase() === 'usd' ? 'usdt' : quoteCurrency)}@trade`.toLowerCase()
|
||||
const targetPair = `${baseCurrency}${(quoteCurrency.toLowerCase() === 'usd' ? 'busd' : quoteCurrency)}@trade`.toLowerCase()
|
||||
this.conn.send(
|
||||
JSON.stringify({
|
||||
method: "SUBSCRIBE",
|
||||
|
|
Loading…
Reference in New Issue