Skip to content

Commit

Permalink
support USDT-ERC20
Browse files Browse the repository at this point in the history
  • Loading branch information
woodser committed Nov 5, 2024
1 parent c965177 commit 3a68b49
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
16 changes: 9 additions & 7 deletions src/main/java/haveno/price/spot/ExchangeRateProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public Set<String> 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()
Expand Down Expand Up @@ -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()));
}

Expand Down Expand Up @@ -217,8 +217,10 @@ private Set<ExchangeRate> doGetInternal(Class<? extends Exchange> exchangeClass)

// Find the desired fiat pairs (pair format is CRYPTO-FIAT)
List<CurrencyPair> 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)
Expand Down Expand Up @@ -348,7 +350,7 @@ public Collection<CurrencyPair> 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()
));
Expand Down Expand Up @@ -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;
}
}
8 changes: 3 additions & 5 deletions src/main/java/haveno/price/spot/ExchangeRateService.java
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,9 @@ private Map<String, Map<String, List<ExchangeRate>>> getAllExchangeRates() {
for (ExchangeRate providerRate : providerRates) {
if (!exchangeRates.containsKey(providerRate.getBaseCurrency())) exchangeRates.put(providerRate.getBaseCurrency(), new HashMap<String, List<ExchangeRate>>());
Map<String, List<ExchangeRate>> baseMap = exchangeRates.get(providerRate.getBaseCurrency());

String currencyCode = providerRate.getCounterCurrency();

if (!baseMap.containsKey(providerRate.getCounterCurrency())) baseMap.put(providerRate.getCounterCurrency(), new ArrayList<ExchangeRate>());
List<ExchangeRate> rates = baseMap.get(providerRate.getCounterCurrency());
String counterCurrencyCode = providerRate.getCounterCurrency();
if (!baseMap.containsKey(counterCurrencyCode)) baseMap.put(counterCurrencyCode, new ArrayList<ExchangeRate>());
List<ExchangeRate> rates = baseMap.get(counterCurrencyCode);
rates.add(providerRate);
}
}
Expand Down

0 comments on commit 3a68b49

Please sign in to comment.