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

Add Tether token support via ERC20 and Omni #4434

Closed
wants to merge 1 commit into from
Closed
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
12 changes: 12 additions & 0 deletions assets/src/main/java/bisq/asset/LiquidBitcoinAddressValidator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package bisq.asset;

public class LiquidBitcoinAddressValidator extends RegexAddressValidator {
static private final String REGEX = "^([a-km-zA-HJ-NP-Z1-9]{26,35}|[a-km-zA-HJ-NP-Z1-9]{80}|[a-z]{2,5}1[ac-hj-np-z02-9]{8,87}|[A-Z]{2,5}1[AC-HJ-NP-Z02-9]{8,87})$";
public LiquidBitcoinAddressValidator() {
super(REGEX);
}

public LiquidBitcoinAddressValidator(String regex, String errorMessageI18nKey) {
super(REGEX, "validation.altcoin.liquidBitcoin.invalidAddress");
}
}
3 changes: 2 additions & 1 deletion assets/src/main/java/bisq/asset/coins/LiquidBitcoin.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@

import bisq.asset.AltCoinAccountDisclaimer;
import bisq.asset.Coin;
import bisq.asset.LiquidBitcoinAddressValidator;
import bisq.asset.RegexAddressValidator;

@AltCoinAccountDisclaimer("account.altcoin.popup.liquidbitcoin.msg")
public class LiquidBitcoin extends Coin {

public LiquidBitcoin() {
super("Liquid Bitcoin", "L-BTC", new RegexAddressValidator("^([a-km-zA-HJ-NP-Z1-9]{26,35}|[a-km-zA-HJ-NP-Z1-9]{80}|[a-z]{2,5}1[ac-hj-np-z02-9]{8,87}|[A-Z]{2,5}1[AC-HJ-NP-Z02-9]{8,87})$", "validation.altcoin.liquidBitcoin.invalidAddress"));
super("Liquid Bitcoin", "L-BTC", new LiquidBitcoinAddressValidator());
}
}
12 changes: 12 additions & 0 deletions assets/src/main/java/bisq/asset/coins/TetherUSDLiquid.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package bisq.asset.coins;

import bisq.asset.Coin;
import bisq.asset.LiquidBitcoinAddressValidator;

public class TetherUSDLiquid extends Coin {
public TetherUSDLiquid() {
// If you add a new USDT variant or want to change this ticker symbol you should also look here:
// core/src/main/java/bisq/core/provider/price/PriceProvider.java:getAll()
super("Tether USD (Liquid Bitcoin)", "L-USDT", new LiquidBitcoinAddressValidator());
}
}
12 changes: 12 additions & 0 deletions assets/src/main/java/bisq/asset/coins/TetherUSDOmni.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package bisq.asset.coins;

import bisq.asset.Base58BitcoinAddressValidator;
import bisq.asset.Coin;

public class TetherUSDOmni extends Coin {
public TetherUSDOmni() {
// If you add a new USDT variant or want to change this ticker symbol you should also look here:
// core/src/main/java/bisq/core/provider/price/PriceProvider.java:getAll()
super("Tether USD (Omni)", "USDT-O", new Base58BitcoinAddressValidator());
}
}
11 changes: 11 additions & 0 deletions assets/src/main/java/bisq/asset/tokens/TetherUSDERC20.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package bisq.asset.tokens;

import bisq.asset.Erc20Token;

public class TetherUSDERC20 extends Erc20Token {
public TetherUSDERC20() {
// If you add a new USDT variant or want to change this ticker symbol you should also look here:
// core/src/main/java/bisq/core/provider/price/PriceProvider.java:getAll()
super("Tether USD (ERC20)", "USDT-E");
}
}
3 changes: 3 additions & 0 deletions assets/src/main/resources/META-INF/services/bisq.asset.Asset
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ bisq.asset.coins.Spectrecoin
bisq.asset.coins.Starwels
bisq.asset.coins.SUB1X
bisq.asset.coins.TEO
bisq.asset.coins.TetherUSDLiquid
bisq.asset.coins.TetherUSDOmni
bisq.asset.coins.TurtleCoin
bisq.asset.coins.UnitedCommunityCoin
bisq.asset.coins.Unobtanium
Expand All @@ -123,6 +125,7 @@ bisq.asset.coins.ZeroClassic
bisq.asset.tokens.AugmintEuro
bisq.asset.tokens.DaiStablecoin
bisq.asset.tokens.EtherStone
bisq.asset.tokens.TetherUSDERC20
bisq.asset.tokens.TrueUSD
bisq.asset.tokens.USDCoin
bisq.asset.tokens.VectorspaceAI
11 changes: 10 additions & 1 deletion core/src/main/java/bisq/core/provider/price/PriceProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ public Tuple2<Map<String, Long>, Map<String, MarketPrice>> getAll() throws IOExc
final double price = (Double) treeMap.get("price");
// json uses double for our timestampSec long value...
final long timestampSec = MathUtils.doubleToLong((Double) treeMap.get("timestampSec"));
marketPriceMap.put(currencyCode, new MarketPrice(currencyCode, price, timestampSec, true));
if (currencyCode.equals("USDT")) {
addPrice(marketPriceMap, "USDT-O", price, timestampSec);
addPrice(marketPriceMap, "USDT-E", price, timestampSec);
addPrice(marketPriceMap, "L-USDT", price, timestampSec);
}
addPrice(marketPriceMap, currencyCode, price, timestampSec);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are adding USDT additionally as well. So we will end up with 4 price entries for USDT. I am not sure if L-USDT is treated as a seperate altcoin and if preice might differ slightly. I assume so. We should consider to either filter out the USDT-O and USDT-E in the price display code or to not add USDT (so users need to look up USDT-O or USDT-E). As both are the same price I guess its better to filter then out and use USDT.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this is getting more messy with sepcial cases I would suggest to add generic support. Add a new field in the asset to indicate the ticker currency for price feed (USDT). That will be used then for picking up price and price display in case the tickersymbol is not available in the price feed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On first glance this seems kind of hard because a lot of times currency codes are just passed around as strings instead of objects. But I'll investigate how I can make a nice solution

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will have a look into it.

} catch (Throwable t) {
log.error(t.toString());
t.printStackTrace();
Expand All @@ -80,6 +85,10 @@ public Tuple2<Map<String, Long>, Map<String, MarketPrice>> getAll() throws IOExc
return new Tuple2<>(tsMap, marketPriceMap);
}

private void addPrice(Map<String, MarketPrice> marketPriceMap, String currencyCode, double price, long timestampSec) {
marketPriceMap.put(currencyCode, new MarketPrice(currencyCode, price, timestampSec, true));
}

public String getBaseUrl() {
return httpClient.getBaseUrl();
}
Expand Down
3 changes: 1 addition & 2 deletions desktop/src/main/java/bisq/desktop/main/MainView.java
Original file line number Diff line number Diff line change
Expand Up @@ -534,11 +534,10 @@ private String getPriceProviderTooltipString() {

String selectedCurrencyCode = model.getPriceFeedService().getCurrencyCode();
MarketPrice selectedMarketPrice = model.getPriceFeedService().getMarketPrice(selectedCurrencyCode);

return Res.get("mainView.marketPrice.tooltip",
"Bisq Price Index for " + selectedCurrencyCode,
"",
DisplayUtils.formatTime(new Date(selectedMarketPrice.getTimestampSec())),
selectedMarketPrice != null ? DisplayUtils.formatTime(new Date(selectedMarketPrice.getTimestampSec())) : Res.get("shared.na"),
model.getPriceFeedService().getProviderNodeAddress());
}

Expand Down