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

Increase security deposits #3826

Merged
merged 2 commits into from
Jan 2, 2020
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
33 changes: 10 additions & 23 deletions core/src/main/java/bisq/core/btc/wallet/Restrictions.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,9 @@
package bisq.core.btc.wallet;

import bisq.core.app.BisqEnvironment;
import bisq.core.payment.PaymentAccount;
import bisq.core.payment.PaymentAccountUtil;

import org.bitcoinj.core.Coin;

import javax.annotation.Nullable;

public class Restrictions {
private static Coin MIN_TRADE_AMOUNT;
private static Coin MIN_BUYER_SECURITY_DEPOSIT;
Expand All @@ -50,47 +46,38 @@ public static boolean isDust(Coin amount) {

public static Coin getMinTradeAmount() {
if (MIN_TRADE_AMOUNT == null)
MIN_TRADE_AMOUNT = Coin.valueOf(10_000); // 0,4 USD @ 4000 USD/BTC
MIN_TRADE_AMOUNT = Coin.valueOf(10_000); // 0,7 USD @ 7000 USD/BTC
return MIN_TRADE_AMOUNT;
}

public static double getDefaultBuyerSecurityDepositAsPercent(@Nullable PaymentAccount paymentAccount) {
if (PaymentAccountUtil.isCryptoCurrencyAccount(paymentAccount))
return 0.02; // 2% of trade amount.
else
return 0.1; // 10% of trade amount.
public static double getDefaultBuyerSecurityDepositAsPercent() {
return 0.15; // 15% of trade amount.
}

public static double getMinBuyerSecurityDepositAsPercent(@Nullable PaymentAccount paymentAccount) {
if (PaymentAccountUtil.isCryptoCurrencyAccount(paymentAccount))
return 0.005; // 0.5% of trade amount.
else
return 0.05; // 5% of trade amount.
public static double getMinBuyerSecurityDepositAsPercent() {
return 0.15; // 15% of trade amount.
}

public static double getMaxBuyerSecurityDepositAsPercent(@Nullable PaymentAccount paymentAccount) {
if (PaymentAccountUtil.isCryptoCurrencyAccount(paymentAccount))
return 0.2; // 20% of trade amount. For a 1 BTC trade it is about 800 USD @ 4000 USD/BTC
else
return 0.5; // 50% of trade amount. For a 1 BTC trade it is about 2000 USD @ 4000 USD/BTC
public static double getMaxBuyerSecurityDepositAsPercent() {
return 0.5; // 50% of trade amount. For a 1 BTC trade it is about 3500 USD @ 7000 USD/BTC
}

// We use MIN_BUYER_SECURITY_DEPOSIT as well as lower bound in case of small trade amounts.
// So 0.0005 BTC is the min. buyer security deposit even with amount of 0.0001 BTC and 0.05% percentage value.
public static Coin getMinBuyerSecurityDepositAsCoin() {
if (MIN_BUYER_SECURITY_DEPOSIT == null)
MIN_BUYER_SECURITY_DEPOSIT = Coin.parseCoin("0.001"); // 0.001 BTC about 4 USD @ 4000 USD/BTC
MIN_BUYER_SECURITY_DEPOSIT = Coin.parseCoin("0.006"); // 0.006 BTC about 42 USD @ 7000 USD/BTC
return MIN_BUYER_SECURITY_DEPOSIT;
}


public static double getSellerSecurityDepositAsPercent() {
return 0.05; // 5% of trade amount.
return 0.15; // 15% of trade amount.
}

public static Coin getMinSellerSecurityDepositAsCoin() {
if (SELLER_SECURITY_DEPOSIT == null)
SELLER_SECURITY_DEPOSIT = Coin.parseCoin("0.005"); // 0.005 BTC about 20 USD @ 4000 USD/BTC
SELLER_SECURITY_DEPOSIT = Coin.parseCoin("0.006"); // 0.006 BTC about 42 USD @ 7000 USD/BTC
return SELLER_SECURITY_DEPOSIT;
}
}
8 changes: 4 additions & 4 deletions core/src/main/java/bisq/core/offer/OfferUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -354,12 +354,12 @@ public static void validateOfferData(FilterManager filterManager,
Coin makerFeeAsCoin) {
checkNotNull(makerFeeAsCoin, "makerFee must not be null");
checkNotNull(p2PService.getAddress(), "Address must not be null");
checkArgument(buyerSecurityDeposit <= Restrictions.getMaxBuyerSecurityDepositAsPercent(paymentAccount),
checkArgument(buyerSecurityDeposit <= Restrictions.getMaxBuyerSecurityDepositAsPercent(),
"securityDeposit must not exceed " +
Restrictions.getMaxBuyerSecurityDepositAsPercent(paymentAccount));
checkArgument(buyerSecurityDeposit >= Restrictions.getMinBuyerSecurityDepositAsPercent(paymentAccount),
Restrictions.getMaxBuyerSecurityDepositAsPercent());
checkArgument(buyerSecurityDeposit >= Restrictions.getMinBuyerSecurityDepositAsPercent(),
"securityDeposit must not be less than " +
Restrictions.getMinBuyerSecurityDepositAsPercent(paymentAccount));
Restrictions.getMinBuyerSecurityDepositAsPercent());
checkArgument(!filterManager.isCurrencyBanned(currencyCode),
Res.get("offerbook.warning.currencyBanned"));
checkArgument(!filterManager.isPaymentMethodBanned(paymentAccount.getPaymentMethod()),
Expand Down
10 changes: 5 additions & 5 deletions core/src/main/java/bisq/core/user/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -500,8 +500,8 @@ public void setWithdrawalTxFeeInBytes(long withdrawalTxFeeInBytes) {
}

public void setBuyerSecurityDepositAsPercent(double buyerSecurityDepositAsPercent, PaymentAccount paymentAccount) {
double max = Restrictions.getMaxBuyerSecurityDepositAsPercent(paymentAccount);
double min = Restrictions.getMinBuyerSecurityDepositAsPercent(paymentAccount);
double max = Restrictions.getMaxBuyerSecurityDepositAsPercent();
double min = Restrictions.getMinBuyerSecurityDepositAsPercent();

if (PaymentAccountUtil.isCryptoCurrencyAccount(paymentAccount))
prefPayload.setBuyerSecurityDepositAsPercentForCrypto(Math.min(max, Math.max(min, buyerSecurityDepositAsPercent)));
Expand Down Expand Up @@ -746,12 +746,12 @@ public double getBuyerSecurityDepositAsPercent(PaymentAccount paymentAccount) {
double value = PaymentAccountUtil.isCryptoCurrencyAccount(paymentAccount) ?
prefPayload.getBuyerSecurityDepositAsPercentForCrypto() : prefPayload.getBuyerSecurityDepositAsPercent();

if (value < Restrictions.getMinBuyerSecurityDepositAsPercent(paymentAccount)) {
value = Restrictions.getMinBuyerSecurityDepositAsPercent(paymentAccount);
if (value < Restrictions.getMinBuyerSecurityDepositAsPercent()) {
value = Restrictions.getMinBuyerSecurityDepositAsPercent();
setBuyerSecurityDepositAsPercent(value, paymentAccount);
}

return value == 0 ? Restrictions.getDefaultBuyerSecurityDepositAsPercent(paymentAccount) : value;
return value == 0 ? Restrictions.getDefaultBuyerSecurityDepositAsPercent() : value;
}

//TODO remove and use isPayFeeInBtc instead
Expand Down
5 changes: 2 additions & 3 deletions core/src/main/java/bisq/core/user/PreferencesPayload.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import bisq.core.locale.CryptoCurrency;
import bisq.core.locale.FiatCurrency;
import bisq.core.locale.TradeCurrency;
import bisq.core.payment.CryptoCurrencyAccount;
import bisq.core.payment.PaymentAccount;
import bisq.core.proto.CoreProtoResolver;

Expand Down Expand Up @@ -122,9 +121,9 @@ public final class PreferencesPayload implements PersistableEnvelope {
private String rpcPw;
@Nullable
private String takeOfferSelectedPaymentAccountId;
private double buyerSecurityDepositAsPercent = getDefaultBuyerSecurityDepositAsPercent(null);
private double buyerSecurityDepositAsPercent = getDefaultBuyerSecurityDepositAsPercent();
private int ignoreDustThreshold = 600;
private double buyerSecurityDepositAsPercentForCrypto = getDefaultBuyerSecurityDepositAsPercent(new CryptoCurrencyAccount());
private double buyerSecurityDepositAsPercentForCrypto = getDefaultBuyerSecurityDepositAsPercent();
private int blockNotifyPort;
private boolean tacAcceptedV120;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@
import bisq.core.provider.price.MarketPrice;
import bisq.core.provider.price.PriceFeedService;
import bisq.core.user.Preferences;
import bisq.core.util.coin.BsqFormatter;
import bisq.core.util.FormattingUtils;
import bisq.core.util.ParsingUtils;
import bisq.core.util.coin.BsqFormatter;
import bisq.core.util.coin.CoinFormatter;
import bisq.core.util.validation.InputValidator;

Expand Down Expand Up @@ -878,7 +878,7 @@ void onFocusOutBuyerSecurityDepositTextField(boolean oldValue, boolean newValue)
InputValidator.ValidationResult result = securityDepositValidator.validate(buyerSecurityDeposit.get());
buyerSecurityDepositValidationResult.set(result);
if (result.isValid) {
double defaultSecurityDeposit = Restrictions.getDefaultBuyerSecurityDepositAsPercent(getPaymentAccount());
double defaultSecurityDeposit = Restrictions.getDefaultBuyerSecurityDepositAsPercent();
String key = "buyerSecurityDepositIsLowerAsDefault";
double depositAsDouble = ParsingUtils.parsePercentStringToDouble(buyerSecurityDeposit.get());
if (preferences.showAgain(key) && depositAsDouble < defaultSecurityDeposit) {
Expand Down Expand Up @@ -1139,7 +1139,7 @@ private void setBuyerSecurityDepositToModel() {
if (buyerSecurityDeposit.get() != null && !buyerSecurityDeposit.get().isEmpty()) {
dataModel.setBuyerSecurityDeposit(ParsingUtils.parsePercentStringToDouble(buyerSecurityDeposit.get()));
} else {
dataModel.setBuyerSecurityDeposit(Restrictions.getDefaultBuyerSecurityDepositAsPercent(getPaymentAccount()));
dataModel.setBuyerSecurityDeposit(Restrictions.getDefaultBuyerSecurityDepositAsPercent());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ public void applyOpenOffer(OpenOffer openOffer) {
// by percentage than the restriction. We can't determine the percentage originally entered at offer
// creation, so just use the default value as it doesn't matter anyway.
double buyerSecurityDepositPercent = CoinUtil.getAsPercentPerBtc(offer.getBuyerSecurityDeposit(), offer.getAmount());
if (buyerSecurityDepositPercent > Restrictions.getMaxBuyerSecurityDepositAsPercent(this.paymentAccount)
if (buyerSecurityDepositPercent > Restrictions.getMaxBuyerSecurityDepositAsPercent()
&& offer.getBuyerSecurityDeposit().value == Restrictions.getMinBuyerSecurityDepositAsCoin().value)
buyerSecurityDeposit.set(Restrictions.getDefaultBuyerSecurityDepositAsPercent(this.paymentAccount));
buyerSecurityDeposit.set(Restrictions.getDefaultBuyerSecurityDepositAsPercent());
else
buyerSecurityDeposit.set(buyerSecurityDepositPercent);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public ValidationResult validate(String input) {
private ValidationResult validateIfNotTooLowPercentageValue(String input) {
try {
double percentage = ParsingUtils.parsePercentStringToDouble(input);
double minPercentage = Restrictions.getMinBuyerSecurityDepositAsPercent(paymentAccount);
double minPercentage = Restrictions.getMinBuyerSecurityDepositAsPercent();
if (percentage < minPercentage)
return new ValidationResult(false,
Res.get("validation.inputTooSmall", FormattingUtils.formatToPercentWithSymbol(minPercentage)));
Expand All @@ -72,7 +72,7 @@ private ValidationResult validateIfNotTooLowPercentageValue(String input) {
private ValidationResult validateIfNotTooHighPercentageValue(String input) {
try {
double percentage = ParsingUtils.parsePercentStringToDouble(input);
double maxPercentage = Restrictions.getMaxBuyerSecurityDepositAsPercent(paymentAccount);
double maxPercentage = Restrictions.getMaxBuyerSecurityDepositAsPercent();
if (percentage > maxPercentage)
return new ValidationResult(false,
Res.get("validation.inputTooLarge", FormattingUtils.formatToPercentWithSymbol(maxPercentage)));
Expand Down