From cf9338a45275fe1fe970050bcfa1a35381212062 Mon Sep 17 00:00:00 2001 From: rbajollari Date: Tue, 3 Sep 2024 10:04:16 -0400 Subject: [PATCH 1/3] feat: Add WSTETH/WETH as supported conversion --- config/supported_assets.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/config/supported_assets.go b/config/supported_assets.go index 0aa7b4f..2e9a7a0 100644 --- a/config/supported_assets.go +++ b/config/supported_assets.go @@ -47,13 +47,14 @@ var ( {Base: "INJ", Quote: "USD"}: {}, {Base: "TIA", Quote: "USD"}: {}, - {Base: "OSMO", Quote: "USDT"}: {}, - {Base: "JUNO", Quote: "USDT"}: {}, - {Base: "WETH", Quote: "USDC"}: {}, - {Base: "WBTC", Quote: "BTC"}: {}, - {Base: "WBTC", Quote: "WETH"}: {}, - {Base: "INJ", Quote: "USDT"}: {}, - {Base: "TIA", Quote: "USDT"}: {}, + {Base: "OSMO", Quote: "USDT"}: {}, + {Base: "JUNO", Quote: "USDT"}: {}, + {Base: "WETH", Quote: "USDC"}: {}, + {Base: "WBTC", Quote: "BTC"}: {}, + {Base: "WBTC", Quote: "WETH"}: {}, + {Base: "INJ", Quote: "USDT"}: {}, + {Base: "TIA", Quote: "USDT"}: {}, + {Base: "WSTETH", Quote: "WETH"}: {}, } SupportedUniswapCurrencies = map[string]struct{}{ From 43ee94e5455a05734649eb2247a14bdc42ad2d2a Mon Sep 17 00:00:00 2001 From: rbajollari Date: Thu, 5 Sep 2024 16:02:20 -0400 Subject: [PATCH 2/3] one conversion path deeper --- oracle/convert.go | 22 ++++++++++++++++++++++ oracle/util.go | 4 ++++ 2 files changed, 26 insertions(+) diff --git a/oracle/convert.go b/oracle/convert.go index 42151aa..55231b1 100644 --- a/oracle/convert.go +++ b/oracle/convert.go @@ -18,10 +18,32 @@ func ConvertRatesToUSD(rates types.CurrencyPairDec) types.CurrencyPairDec { continue } + var converted bool for cpConvert, rateConvert := range rates { if cpConvert.Quote == config.DenomUSD && cpConvert.Base == cp.Quote { convertedPair := types.CurrencyPair{Base: cp.Base, Quote: config.DenomUSD} convertedRates[convertedPair] = rate.Mul(rateConvert) + converted = true + } + } + + // If the rate is not converted, try one conversion path deeper. + if !converted { + for cpConvert, rateConvert := range rates { + if cpConvert.Base == cp.Quote { + var quoteRate math.LegacyDec + var foundQuoteRate bool + for cpConvert2, rateConvert2 := range rates { + if cpConvert2.Quote == config.DenomUSD && cpConvert2.Base == cpConvert.Quote { + quoteRate = rateConvert2 + foundQuoteRate = true + } + } + if foundQuoteRate { + convertedPair := types.CurrencyPair{Base: cp.Base, Quote: config.DenomUSD} + convertedRates[convertedPair] = rate.Mul(rateConvert).Mul(quoteRate) + } + } } } } diff --git a/oracle/util.go b/oracle/util.go index 638bc55..9e0df61 100644 --- a/oracle/util.go +++ b/oracle/util.go @@ -14,6 +14,7 @@ import ( var ( minimumTimeWeight = math.LegacyMustNewDecFromStr("0.2000") + minimumTickerVolume = math.LegacyMustNewDecFromStr("0.000000000000001") minimumCandleVolume = math.LegacyMustNewDecFromStr("0.0001") ) @@ -58,6 +59,9 @@ func ComputeVWAP(prices types.AggregatedProviderPrices) types.CurrencyPairDec { if _, ok := volumeSum[base]; !ok { volumeSum[base] = math.LegacyZeroDec() } + if tp.Volume.LT(minimumCandleVolume) { + tp.Volume = minimumCandleVolume + } // weightedPrices[base] = Σ {P * V} for all TickerPrice weightedPrices[base] = weightedPrices[base].Add(tp.Price.Mul(tp.Volume)) From 7753c2c293dbbfe937fcd761b055300af8b009ef Mon Sep 17 00:00:00 2001 From: rbajollari Date: Thu, 5 Sep 2024 16:15:38 -0400 Subject: [PATCH 3/3] lint --- oracle/util.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/oracle/util.go b/oracle/util.go index 9e0df61..22aafe6 100644 --- a/oracle/util.go +++ b/oracle/util.go @@ -59,8 +59,8 @@ func ComputeVWAP(prices types.AggregatedProviderPrices) types.CurrencyPairDec { if _, ok := volumeSum[base]; !ok { volumeSum[base] = math.LegacyZeroDec() } - if tp.Volume.LT(minimumCandleVolume) { - tp.Volume = minimumCandleVolume + if tp.Volume.LT(minimumTickerVolume) { + tp.Volume = minimumTickerVolume } // weightedPrices[base] = Σ {P * V} for all TickerPrice