Skip to content

Commit

Permalink
Merge pull request #4383 from jmacxx/fix_low_bsq_offer
Browse files Browse the repository at this point in the history
Maintain floor amount of 5.46 BSQ to prevent dust errors
  • Loading branch information
ripcurlx authored Jul 29, 2020
2 parents d9eb1d8 + 2d5ab2a commit 66d3589
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 12 deletions.
8 changes: 8 additions & 0 deletions core/src/main/java/bisq/core/offer/OfferUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ public static boolean isBsqForMakerFeeAvailable(BsqWalletService bsqWalletServic
if (makerFee == null)
return true;

Coin surplusFunds = availableBalance.subtract(makerFee);
if (Restrictions.isDust(surplusFunds)) {
return false; // we can't be left with dust
}
return !availableBalance.subtract(makerFee).isNegative();
}

Expand Down Expand Up @@ -171,6 +175,10 @@ public static boolean isBsqForTakerFeeAvailable(BsqWalletService bsqWalletServic
if (takerFee == null)
return true;

Coin surplusFunds = availableBalance.subtract(takerFee);
if (Restrictions.isDust(surplusFunds)) {
return false; // we can't be left with dust
}
return !availableBalance.subtract(takerFee).isNegative();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -718,8 +718,14 @@ ReadOnlyObjectProperty<Coin> totalToPayAsCoinProperty() {
return totalToPayAsCoin;
}

Coin getBsqBalance() {
return bsqWalletService.getAvailableConfirmedBalance();
Coin getUsableBsqBalance() {
// we have to keep a minimum amount of BSQ == bitcoin dust limit
// otherwise there would be dust violations for change UTXOs
// essentially means the minimum usable balance of BSQ is 5.46
Coin usableBsqBalance = bsqWalletService.getAvailableConfirmedBalance().subtract(Restrictions.getMinNonDustOutput());
if (usableBsqBalance.isNegative())
usableBsqBalance = Coin.ZERO;
return usableBsqBalance;
}

public void setMarketPriceAvailable(boolean marketPriceAvailable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,9 @@ private void showInsufficientBsqFundsForBtcFeePaymentPopup() {
String message = null;
if (makerFee != null) {
message = Res.get("popup.warning.insufficientBsqFundsForBtcFeePayment",
bsqFormatter.formatCoinWithCode(makerFee.subtract(model.getDataModel().getBsqBalance())));
bsqFormatter.formatCoinWithCode(makerFee.subtract(model.getDataModel().getUsableBsqBalance())));

} else if (model.getDataModel().getBsqBalance().isZero())
} else if (model.getDataModel().getUsableBsqBalance().isZero())
message = Res.get("popup.warning.noBsqFundsForBtcFeePayment");

if (message != null)
Expand Down Expand Up @@ -1109,9 +1109,9 @@ private void showFeeOption() {
String missingBsq = null;
if (makerFee != null) {
missingBsq = Res.get("popup.warning.insufficientBsqFundsForBtcFeePayment",
bsqFormatter.formatCoinWithCode(makerFee.subtract(model.getDataModel().getBsqBalance())));
bsqFormatter.formatCoinWithCode(makerFee.subtract(model.getDataModel().getUsableBsqBalance())));

} else if (model.getDataModel().getBsqBalance().isZero()) {
} else if (model.getDataModel().getUsableBsqBalance().isZero()) {
missingBsq = Res.get("popup.warning.noBsqFundsForBtcFeePayment");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -639,8 +639,14 @@ public Coin getSellerSecurityDeposit() {
return offer.getSellerSecurityDeposit();
}

public Coin getBsqBalance() {
return bsqWalletService.getAvailableConfirmedBalance();
public Coin getUsableBsqBalance() {
// we have to keep a minimum amount of BSQ == bitcoin dust limit
// otherwise there would be dust violations for change UTXOs
// essentially means the minimum usable balance of BSQ is 5.46
Coin usableBsqBalance = bsqWalletService.getAvailableConfirmedBalance().subtract(Restrictions.getMinNonDustOutput());
if (usableBsqBalance.isNegative())
usableBsqBalance = Coin.ZERO;
return usableBsqBalance;
}

public boolean isHalCashAccount() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -927,9 +927,9 @@ private void showFeeOption() {
String missingBsq = null;
if (takerFee != null) {
missingBsq = Res.get("popup.warning.insufficientBsqFundsForBtcFeePayment",
bsqFormatter.formatCoinWithCode(takerFee.subtract(model.dataModel.getBsqBalance())));
bsqFormatter.formatCoinWithCode(takerFee.subtract(model.dataModel.getUsableBsqBalance())));

} else if (model.dataModel.getBsqBalance().isZero()) {
} else if (model.dataModel.getUsableBsqBalance().isZero()) {
missingBsq = Res.get("popup.warning.noBsqFundsForBtcFeePayment");
}

Expand Down Expand Up @@ -1225,9 +1225,9 @@ private void showInsufficientBsqFundsForBtcFeePaymentPopup() {
String message = null;
if (takerFee != null)
message = Res.get("popup.warning.insufficientBsqFundsForBtcFeePayment",
bsqFormatter.formatCoinWithCode(takerFee.subtract(model.dataModel.getBsqBalance())));
bsqFormatter.formatCoinWithCode(takerFee.subtract(model.dataModel.getUsableBsqBalance())));

else if (model.dataModel.getBsqBalance().isZero())
else if (model.dataModel.getUsableBsqBalance().isZero())
message = Res.get("popup.warning.noBsqFundsForBtcFeePayment");

if (message != null)
Expand Down

0 comments on commit 66d3589

Please sign in to comment.