From 647af6faae0750219ad83654da8cb48b2b330ebb Mon Sep 17 00:00:00 2001 From: Eric Nagel Date: Tue, 27 Jun 2023 21:49:33 +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..9a5ababc 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 */