Skip to content

Commit

Permalink
feat: add max percentage deviation metric (celo-org#174)
Browse files Browse the repository at this point in the history
  • Loading branch information
erNail committed Jun 27, 2023
1 parent fe3b63c commit 74c3b52
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/aggregator_functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export function crossCheckPriceData(
// 1. Prices should not deviate more than maxPercentageDeviation.
const prices = tickerData.map((price: WeightedPrice) => price.price)
const maxNormalizedAbsMeanDev = maxPercentageDeviaton(prices)
config.metricCollector?.maxPercentageDeviation(config.currencyPair, maxNormalizedAbsMeanDev)
assert(
maxNormalizedAbsMeanDev.isLessThanOrEqualTo(config.maxPercentageDeviation),
`Max price cross-sectional deviation too large (${maxNormalizedAbsMeanDev} >= ${config.maxPercentageDeviation} )`
Expand Down
14 changes: 14 additions & 0 deletions src/metric_collector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export class MetricCollector {

private tickerPropertyGauge: Gauge<string>
private priceSourceGauge: Gauge<string>
private maxPercentageDeviationGauge: Gauge<string>

private transactionBlockNumberGauge: Gauge<string>
private transactionGasGauge: Gauge<string>
Expand Down Expand Up @@ -158,6 +159,12 @@ export class MetricCollector {
labelNames: ['pair', 'source', 'property'],
})

this.maxPercentageDeviationGauge = new Gauge({
name: 'oracle_max_percentage_deviation',
help: 'Gauge to indicate the max price cross-sectional deviation of a price pair',
labelNames: ['currencyPair'],
})

this.transactionBlockNumberGauge = new Gauge({
name: 'oracle_transaction_block_number',
help: 'Gauge showing the block number of the most recent transaction defined by type',
Expand Down Expand Up @@ -331,6 +338,13 @@ export class MetricCollector {
this.priceSourceGauge.set({ pair, source, property: 'weight' }, weightedPrice.weight.toNumber())
}

/**
* Indicates the max price cross-sectional deviation of a price pair
*/
maxPercentageDeviation(pair: string, maxPercentageDeviation: BigNumber) {
this.maxPercentageDeviationGauge.set({ pair }, maxPercentageDeviation.toNumber())
}

/**
* Indicates the most recent block number of a specific type
*/
Expand Down

0 comments on commit 74c3b52

Please sign in to comment.