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

BATM-7015: added buy and sell support for USDC via BitGo #956

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
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class Converters {
public static final BigDecimal XRP = BigDecimal.TEN.pow(6);
public static final BigDecimal VERUM = BigDecimal.TEN.pow(8);
public static final BigDecimal TRX = BigDecimal.TEN.pow(6);
public static final BigDecimal USDC = BigDecimal.TEN.pow(6);

public static final BigDecimal TBCH = BigDecimal.TEN.pow(8);
public static final BigDecimal TBTC = BigDecimal.TEN.pow(8);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*************************************************************************************
* Copyright (C) 2014-2024 GENERAL BYTES s.r.o. All rights reserved.
* Copyright (C) 2014-2025 GENERAL BYTES s.r.o. All rights reserved.
*
* This software may be distributed and modified under the terms of the GNU
* General Public License version 2 (GPL2) as published by the Free Software
Expand Down Expand Up @@ -56,7 +56,9 @@
import com.generalbytes.batm.server.extensions.extra.bitcoin.wallets.coinbase.v2.CoinbaseWalletV2WithUniqueAddresses;
import com.generalbytes.batm.server.extensions.extra.bitcoin.wallets.cryptx.v2.CryptXWallet;
import com.generalbytes.batm.server.extensions.extra.bitcoin.wallets.cryptx.v2.CryptXWithUniqueAddresses;
import com.generalbytes.batm.server.extensions.extra.ethereum.UsdcDefinition;
import com.generalbytes.batm.server.extensions.watchlist.IWatchList;
import com.google.common.collect.ImmutableSet;

import java.math.BigDecimal;
import java.net.InetSocketAddress;
Expand Down Expand Up @@ -613,14 +615,15 @@ public IRateSource createRateSource(String sourceLogin) {

@Override
public Set<String> getSupportedCryptoCurrencies() {
Set<String> result = new HashSet<String>();
Set<String> result = new HashSet<>();
result.add(CryptoCurrency.BTC.getCode());
result.add(CryptoCurrency.ETH.getCode());
result.add(CryptoCurrency.LTC.getCode());
result.add(CryptoCurrency.BCH.getCode());
result.add(CryptoCurrency.EGLD.getCode());
result.add(CryptoCurrency.USDTTRON.getCode());
result.add(CryptoCurrency.BNB.getCode());
result.add(CryptoCurrency.USDC.getCode());
return result;
}

Expand All @@ -636,6 +639,6 @@ public IWatchList getWatchList(String name) {

@Override
public Set<ICryptoCurrencyDefinition> getCryptoCurrencyDefinitions() {
return null;
return ImmutableSet.of(new UsdcDefinition());
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*************************************************************************************
* Copyright (C) 2014-2024 GENERAL BYTES s.r.o. All rights reserved.
* Copyright (C) 2014-2025 GENERAL BYTES s.r.o. All rights reserved.
*
* This software may be distributed and modified under the terms of the GNU
* General Public License version 2 (GPL2) as published by the Free Software
Expand Down Expand Up @@ -70,6 +70,7 @@ public class BitgoWallet implements IWallet, ICanSendMany {
put(CryptoCurrency.USDTTRON.getCode(), "trx:usdt");
put(CryptoCurrency.XRP.getCode(), "xrp");
put(CryptoCurrency.TBTC.getCode(), "tbtc");
put(CryptoCurrency.USDC.getCode(), "usdc");
}
};

Expand All @@ -85,6 +86,7 @@ public class BitgoWallet implements IWallet, ICanSendMany {
put(CryptoCurrency.TBTC.getCode(), pow10Exp(Converters.TBTC));
put(CryptoCurrency.TLTC.getCode(), pow10Exp(Converters.TLTC));
put(CryptoCurrency.TBCH.getCode(), pow10Exp(Converters.TBCH));
put(CryptoCurrency.USDC.getCode(), pow10Exp(Converters.USDC));
}

private int pow10Exp(BigDecimal val) {
Expand Down Expand Up @@ -138,7 +140,7 @@ public String sendMany(Collection<Transfer> transfers, String cryptoCurrency, St
List<BitGoRecipient> recipients = transfers.stream()
.map(transfer -> new BitGoRecipient(transfer.getDestinationAddress(), toSatoshis(transfer.getAmount(), cryptoCurrency)))
.collect(Collectors.toList());
final BitGoSendManyRequest request = new BitGoSendManyRequest(recipients, walletPassphrase, description, this.numBlocks);
final BitGoSendManyRequest request = createBitGoSendManyRequest(recipients, cryptoCurrency, description);
String bitgoCryptoCurrency = cryptoCurrencies.get(cryptoCurrency);
return getResultTxId(api.sendMany(bitgoCryptoCurrency, this.walletId, request));
} catch (HttpStatusIOException hse) {
Expand All @@ -154,7 +156,7 @@ public String sendMany(Collection<Transfer> transfers, String cryptoCurrency, St
@Override
public String sendCoins(String destinationAddress, BigDecimal amount, String cryptoCurrency, String description) {
try {
final BitGoCoinRequest request = new BitGoCoinRequest(destinationAddress, toSatoshis(amount, cryptoCurrency), walletPassphrase, description, this.numBlocks, this.feeRate, this.maxFeeRate);
final BitGoCoinRequest request = createBitGoCoinRequest(destinationAddress, amount, cryptoCurrency, description);
String bitgoCryptoCurrency = cryptoCurrencies.get(cryptoCurrency);
return getResultTxId(api.sendCoins(bitgoCryptoCurrency, this.walletId, request));
} catch (HttpStatusIOException hse) {
Expand All @@ -167,6 +169,43 @@ public String sendCoins(String destinationAddress, BigDecimal amount, String cry
return null;
}

private BitGoSendManyRequest createBitGoSendManyRequest(List<BitGoRecipient> recipients, String cryptoCurrency, String description) {
if (CryptoCurrency.USDC.getCode().equalsIgnoreCase(cryptoCurrency)) {
return new BitGoSendManyRequest(recipients, this.walletPassphrase, description, this.numBlocks, "transfer");
}

return new BitGoSendManyRequest(recipients, this.walletPassphrase, description, this.numBlocks);
}

private BitGoCoinRequest createBitGoCoinRequest(String destinationAddress,
BigDecimal amount,
String cryptoCurrency,
String description
) {
if (CryptoCurrency.USDC.getCode().equalsIgnoreCase(cryptoCurrency)) {
return new BitGoCoinRequest(
destinationAddress,
toSatoshis(amount, cryptoCurrency),
this.walletPassphrase,
description,
this.numBlocks,
this.feeRate,
this.maxFeeRate,
"transfer"
);
}

return new BitGoCoinRequest(
destinationAddress,
toSatoshis(amount, cryptoCurrency),
this.walletPassphrase,
description,
this.numBlocks,
this.feeRate,
this.maxFeeRate
);
}

protected String toSatoshis(BigDecimal amount, String cryptoCurrency) {
return amount
.movePointRight(getDecimals(cryptoCurrency))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*************************************************************************************
* Copyright (C) 2014-2024 GENERAL BYTES s.r.o. All rights reserved.
* Copyright (C) 2014-2025 GENERAL BYTES s.r.o. All rights reserved.
*
* This software may be distributed and modified under the terms of the GNU
* General Public License version 2 (GPL2) as published by the Free Software
Expand Down Expand Up @@ -45,6 +45,7 @@ public class BitgoWalletWithUniqueAddresses extends BitgoWallet implements IGene
{
put(CryptoCurrency.USDT.getCode(), "eth");
put(CryptoCurrency.USDTTRON.getCode(), "trx");
put(CryptoCurrency.USDC.getCode(), "eth");
}
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*************************************************************************************
* Copyright (C) 2014-2020 GENERAL BYTES s.r.o. All rights reserved.
* Copyright (C) 2014-2025 GENERAL BYTES s.r.o. All rights reserved.
*
* This software may be distributed and modified under the terms of the GNU
* General Public License version 2 (GPL2) as published by the Free Software
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*************************************************************************************
* Copyright (C) 2014-2024 GENERAL BYTES s.r.o. All rights reserved.
* Copyright (C) 2014-2025 GENERAL BYTES s.r.o. All rights reserved.
*
* This software may be distributed and modified under the terms of the GNU
* General Public License version 2 (GPL2) as published by the Free Software
Expand Down Expand Up @@ -28,6 +28,7 @@ public class BitGoCoinRequest {
private String comment;
private Integer feeRate;
private Integer maxFeeRate;
private String type;


public BitGoCoinRequest(String address, String amount, String walletPassphrase, String comment, Integer numBlocks) {
Expand All @@ -38,13 +39,34 @@ public BitGoCoinRequest(String address, String amount, String walletPassphrase,
this.comment = comment;
}

public BitGoCoinRequest(String address, String amount, String walletPassphrase, String comment, Integer numBlocks, Integer feeRate, Integer maxFeeRate) {
public BitGoCoinRequest(String address,
String amount,
String walletPassphrase,
String comment,
Integer numBlocks,
Integer feeRate,
Integer maxFeeRate
) {
this(address, amount, walletPassphrase, comment, numBlocks);

this.feeRate = feeRate;
this.maxFeeRate = maxFeeRate;
}

public BitGoCoinRequest(String address,
String amount,
String walletPassphrase,
String comment,
Integer numBlocks,
Integer feeRate,
Integer maxFeeRate,
String type
) {
this(address, amount, walletPassphrase, comment, numBlocks, feeRate, maxFeeRate);

this.type = type;
}

public String getAddress() {
return address;
}
Expand Down Expand Up @@ -100,4 +122,12 @@ public Integer getMaxFeeRate() {
public void setMaxFeeRate(Integer maxFeeRate) {
this.maxFeeRate = maxFeeRate;
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*************************************************************************************
* Copyright (C) 2014-2019 GENERAL BYTES s.r.o. All rights reserved.
* Copyright (C) 2014-2025 GENERAL BYTES s.r.o. All rights reserved.
*
* This software may be distributed and modified under the terms of the GNU
* General Public License version 2 (GPL2) as published by the Free Software
Expand All @@ -24,6 +24,7 @@ public class BitGoSendManyRequest {
public String walletPassphrase;
public Integer numBlocks;
public String comment;
public String type;

public BitGoSendManyRequest(List<BitGoRecipient> recipients, String walletPassphrase, String comment){
this(recipients, walletPassphrase, comment, 2);
Expand All @@ -36,6 +37,12 @@ public BitGoSendManyRequest(List<BitGoRecipient> recipients, String walletPassph
this.comment = comment;
}

public BitGoSendManyRequest(List<BitGoRecipient> recipients, String walletPassphrase, String comment, Integer numBlocks, String type) {
this(recipients, walletPassphrase, comment, numBlocks);

this.type = type;
}

public static class BitGoRecipient {
public String address;
public String amount; // in satoshis
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
/*************************************************************************************
* Copyright (C) 2014-2025 GENERAL BYTES s.r.o. All rights reserved.
*
* This software may be distributed and modified under the terms of the GNU
* General Public License version 2 (GPL2) as published by the Free Software
* Foundation and appearing in the file GPL2.TXT included in the packaging of
* this file. Please note that GPL2 Section 2[b] requires that all works based
* on this software must also be made publicly available under the terms of
* the GPL2 ("Copyleft").
*
* Contact information
* -------------------
*
* GENERAL BYTES s.r.o.
* Web : http://www.generalbytes.com
*
************************************************************************************/
package com.generalbytes.batm.server.extensions.extra.ethereum;

import com.generalbytes.batm.common.currencies.CryptoCurrency;
import com.generalbytes.batm.server.extensions.CryptoCurrencyDefinition;
import com.generalbytes.batm.server.extensions.payment.IPaymentSupport;

public class UsdcDefinition extends CryptoCurrencyDefinition{
public class UsdcDefinition extends CryptoCurrencyDefinition {
private final IPaymentSupport paymentSupport = new UsdcPaymentSupport();

public UsdcDefinition() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*************************************************************************************
* Copyright (C) 2014-2020 GENERAL BYTES s.r.o. All rights reserved.
* Copyright (C) 2014-2025 GENERAL BYTES s.r.o. All rights reserved.
*
* This software may be distributed and modified under the terms of the GNU
* General Public License version 2 (GPL2) as published by the Free Software
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<cryptocurrency buyonly="true">ETH</cryptocurrency><!--BitGo’s Ethereum wallets are only available to BitGo Enterprise customers-->
<cryptocurrency>XRP</cryptocurrency><!-- BitGo Enterprise-->
<cryptocurrency buyonly="true">USDT</cryptocurrency>
<cryptocurrency buyonly="true">USDC</cryptocurrency>
<help>Host should start with http:// or https://. num_blocks is an integer greater than 2.</help>
</wallet>
<wallet prefix="bitgonoforward" name="BitGo Wallet (no forward)">
Expand All @@ -65,6 +66,7 @@
<cryptocurrency>XRP</cryptocurrency><!-- BitGo Enterprise-->
<cryptocurrency>USDT</cryptocurrency><!-- BitGo Enterprise-->
<cryptocurrency>USDTTRON</cryptocurrency>
<cryptocurrency>USDC</cryptocurrency>
<help>This variant of the wallet generates new addresses for each sell transaction and does not forward payments from temporary address. Host should start with http:// or https://. num_blocks is an integer greater than 2.</help>
</wallet>
<wallet prefix="cryptx" name="CryptX Wallet System">
Expand Down
Loading