From 3a68b496618e4948b88d7cbb5182f3f05fbe18af Mon Sep 17 00:00:00 2001 From: woodser Date: Tue, 5 Nov 2024 09:10:36 -0500 Subject: [PATCH] support USDT-ERC20 --- .../haveno/price/spot/ExchangeRateProvider.java | 16 +++++++++------- .../haveno/price/spot/ExchangeRateService.java | 8 +++----- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main/java/haveno/price/spot/ExchangeRateProvider.java b/src/main/java/haveno/price/spot/ExchangeRateProvider.java index 18dfedd..db8477d 100644 --- a/src/main/java/haveno/price/spot/ExchangeRateProvider.java +++ b/src/main/java/haveno/price/spot/ExchangeRateProvider.java @@ -138,7 +138,7 @@ public Set getSupportedCryptoCurrencies() { .collect(Collectors.toSet()); SUPPORTED_CRYPTO_CURRENCIES.add("XMR"); // XMR is skipped because it's a base currency log.info("crypto currencies excluded: {}", validatedExclusionList); - log.info("crypto currencies supported: {}", SUPPORTED_CRYPTO_CURRENCIES.size()); + log.info("crypto currencies supported: {}", SUPPORTED_CRYPTO_CURRENCIES); } // filter out any provider specific ccy exclusions return SUPPORTED_CRYPTO_CURRENCIES.stream() @@ -176,7 +176,7 @@ public void maybeClearStaleRates() { @Override protected void onRefresh() { get().stream() - .filter(e -> "USD".equals(e.getCounterCurrency()) || "XMR".equals(e.getBaseCurrency()) || "ETH".equals(e.getBaseCurrency()) || "BCH".equals(e.getBaseCurrency())) + .filter(e -> "USD".equals(e.getCounterCurrency()) || "XMR".equals(e.getBaseCurrency()) || "ETH".equals(e.getBaseCurrency()) || "BCH".equals(e.getBaseCurrency()) || "USDT-ERC20".equals(e.getBaseCurrency())) .forEach(e -> log.info("{}/{}: {}", e.getBaseCurrency(), e.getCounterCurrency(), e.getPrice())); } @@ -217,8 +217,10 @@ private Set doGetInternal(Class exchangeClass) // Find the desired fiat pairs (pair format is CRYPTO-FIAT) List desiredFiatPairs = allCurrencyPairsOnExchange.stream() - .filter(cp -> cp.base.equals(Currency.BTC) || cp.base.equals(Currency.XMR)) - .filter(cp -> getSupportedFiatCurrencies().contains(cp.counter.getCurrencyCode())) + .filter(cp -> cp.base.equals(Currency.BTC) || (cp.base.equals(Currency.XMR) && !cp.counter.equals(Currency.BTC))) + .filter(cp -> getSupportedFiatCurrencies().contains(cp.counter.getCurrencyCode()) || + // include also stablecoins, which are quoted fiat-like.. see below isInverted() + getSupportedCryptoCurrencies().contains(translateToHavenoCurrency(cp.counter.getCurrencyCode()))) .collect(Collectors.toList()); // Find the desired crypto pairs (pair format is CRYPTO-BTC) @@ -348,7 +350,7 @@ public Collection getCurrencyPairs() { result.add(new ExchangeRate( translateToHavenoCurrency(t.getCurrencyPair().base.getCurrencyCode()), translateToHavenoCurrency(t.getCurrencyPair().counter.getCurrencyCode()), - t.getLast(), + last, t.getTimestamp() == null ? new Date() : t.getTimestamp(), // some exchanges don't provide timestamps this.getName() )); @@ -383,7 +385,7 @@ protected boolean requiresFilterDuringBulkTickerRetrieval() { } private String translateToHavenoCurrency(String exchangeCurrency) { - // until Haveno client code is changed we map between USDT & USDT-E - return exchangeCurrency.equalsIgnoreCase("USDT") ? "USDT-E" : exchangeCurrency; + // map between USDT and USDT-ERC20 + return exchangeCurrency.equalsIgnoreCase("USDT") ? "USDT-ERC20" : exchangeCurrency; } } diff --git a/src/main/java/haveno/price/spot/ExchangeRateService.java b/src/main/java/haveno/price/spot/ExchangeRateService.java index ad172a8..609b499 100644 --- a/src/main/java/haveno/price/spot/ExchangeRateService.java +++ b/src/main/java/haveno/price/spot/ExchangeRateService.java @@ -299,11 +299,9 @@ private Map>> getAllExchangeRates() { for (ExchangeRate providerRate : providerRates) { if (!exchangeRates.containsKey(providerRate.getBaseCurrency())) exchangeRates.put(providerRate.getBaseCurrency(), new HashMap>()); Map> baseMap = exchangeRates.get(providerRate.getBaseCurrency()); - - String currencyCode = providerRate.getCounterCurrency(); - - if (!baseMap.containsKey(providerRate.getCounterCurrency())) baseMap.put(providerRate.getCounterCurrency(), new ArrayList()); - List rates = baseMap.get(providerRate.getCounterCurrency()); + String counterCurrencyCode = providerRate.getCounterCurrency(); + if (!baseMap.containsKey(counterCurrencyCode)) baseMap.put(counterCurrencyCode, new ArrayList()); + List rates = baseMap.get(counterCurrencyCode); rates.add(providerRate); } }