Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add WSTETH/WETH as supported conversion #410

Merged
merged 3 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions config/supported_assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}{
Expand Down
22 changes: 22 additions & 0 deletions oracle/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions oracle/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

var (
minimumTimeWeight = math.LegacyMustNewDecFromStr("0.2000")
minimumTickerVolume = math.LegacyMustNewDecFromStr("0.000000000000001")
minimumCandleVolume = math.LegacyMustNewDecFromStr("0.0001")
)

Expand Down Expand Up @@ -58,6 +59,9 @@ func ComputeVWAP(prices types.AggregatedProviderPrices) types.CurrencyPairDec {
if _, ok := volumeSum[base]; !ok {
volumeSum[base] = math.LegacyZeroDec()
}
if tp.Volume.LT(minimumTickerVolume) {
tp.Volume = minimumTickerVolume
}

// weightedPrices[base] = Σ {P * V} for all TickerPrice
weightedPrices[base] = weightedPrices[base].Add(tp.Price.Mul(tp.Volume))
Expand Down
Loading