From 74c3b5298d270bc22f4298b38514e0352f85d134 Mon Sep 17 00:00:00 2001 From: Eric Nagel Date: Tue, 27 Jun 2023 21:57:12 +0000 Subject: [PATCH] feat: add max percentage deviation metric (#174) --- src/aggregator_functions.ts | 1 + src/metric_collector.ts | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/aggregator_functions.ts b/src/aggregator_functions.ts index fb8844b8..19a96d41 100644 --- a/src/aggregator_functions.ts +++ b/src/aggregator_functions.ts @@ -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} )` diff --git a/src/metric_collector.ts b/src/metric_collector.ts index 96bc2d7f..0c74bab2 100644 --- a/src/metric_collector.ts +++ b/src/metric_collector.ts @@ -67,6 +67,7 @@ export class MetricCollector { private tickerPropertyGauge: Gauge private priceSourceGauge: Gauge + private maxPercentageDeviationGauge: Gauge private transactionBlockNumberGauge: Gauge private transactionGasGauge: Gauge @@ -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', @@ -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 */