diff --git a/core/src/main/java/bisq/core/dao/governance/param/Param.java b/core/src/main/java/bisq/core/dao/governance/param/Param.java index f26ad02cd5f..98172f2364f 100644 --- a/core/src/main/java/bisq/core/dao/governance/param/Param.java +++ b/core/src/main/java/bisq/core/dao/governance/param/Param.java @@ -45,16 +45,16 @@ public enum Param { // Fee in BTC satoshi for a 1 BTC trade. 200_000 Satoshi = 0.00200000 BTC = 0.2%. // 10 USD at BTC price 5_000 USD for a 1 BTC trade; - DEFAULT_MAKER_FEE_BTC("0.002", ParamType.BTC, 5, 5), - DEFAULT_TAKER_FEE_BTC("0.002", ParamType.BTC, 5, 5), // 0.2% of trade amount + DEFAULT_MAKER_FEE_BTC("0.001", ParamType.BTC, 5, 5), + DEFAULT_TAKER_FEE_BTC("0.003", ParamType.BTC, 5, 5), // 0.2% of trade amount MIN_MAKER_FEE_BTC("0.00005", ParamType.BTC, 5, 5), // 0.005% of trade amount MIN_TAKER_FEE_BTC("0.00005", ParamType.BTC, 5, 5), // Fee in BSQ satoshi for a 1 BTC trade. 100 Satoshi = 1 BSQ => about 0.02%. // About 1 USD if 1 BSQ = 1 USD for a 1 BTC trade which is about 10% of the BTC fee., // Might need adjustment if BSQ/BTC rate changes. - DEFAULT_MAKER_FEE_BSQ("1.00", ParamType.BSQ, 5, 5), // ~ 0.02% of trade amount - DEFAULT_TAKER_FEE_BSQ("1", ParamType.BSQ, 5, 5), + DEFAULT_MAKER_FEE_BSQ("0.50", ParamType.BSQ, 5, 5), // ~ 0.01% of trade amount + DEFAULT_TAKER_FEE_BSQ("1.5", ParamType.BSQ, 5, 5), // 0.03 BSQ (3 satoshi) for a 1 BTC trade. 0.05 USD if 1 BSQ = 1 USD, 10 % of the BTC fee MIN_MAKER_FEE_BSQ("0.03", ParamType.BSQ, 5, 5), // 0.0003%. MIN_TAKER_FEE_BSQ("0.03", ParamType.BSQ, 5, 5), diff --git a/core/src/main/java/bisq/core/offer/OfferUtil.java b/core/src/main/java/bisq/core/offer/OfferUtil.java index ad91bbc7ddc..f6dbafcaaa9 100644 --- a/core/src/main/java/bisq/core/offer/OfferUtil.java +++ b/core/src/main/java/bisq/core/offer/OfferUtil.java @@ -73,17 +73,12 @@ public static boolean isBuyOffer(OfferPayload.Direction direction) { * @param bsqWalletService * @param preferences preferences are used to see if the user indicated a preference for paying fees in BTC * @param amount - * @param marketPriceAvailable - * @param marketPriceMargin * @return */ @Nullable - public static Coin getMakerFee(BsqWalletService bsqWalletService, Preferences preferences, Coin amount, boolean marketPriceAvailable, double marketPriceMargin) { - final boolean isCurrencyForMakerFeeBtc = isCurrencyForMakerFeeBtc(preferences, bsqWalletService, amount, marketPriceAvailable, marketPriceMargin); - return getMakerFee(isCurrencyForMakerFeeBtc, - amount, - marketPriceAvailable, - marketPriceMargin); + public static Coin getMakerFee(BsqWalletService bsqWalletService, Preferences preferences, Coin amount) { + boolean isCurrencyForMakerFeeBtc = isCurrencyForMakerFeeBtc(preferences, bsqWalletService, amount); + return getMakerFee(isCurrencyForMakerFeeBtc, amount); } /** @@ -91,27 +86,13 @@ public static Coin getMakerFee(BsqWalletService bsqWalletService, Preferences pr * * @param isCurrencyForMakerFeeBtc * @param amount - * @param marketPriceAvailable - * @param marketPriceMargin * @return */ @Nullable - public static Coin getMakerFee(boolean isCurrencyForMakerFeeBtc, @Nullable Coin amount, boolean marketPriceAvailable, double marketPriceMargin) { + public static Coin getMakerFee(boolean isCurrencyForMakerFeeBtc, @Nullable Coin amount) { if (amount != null) { Coin feePerBtc = CoinUtil.getFeePerBtc(FeeService.getMakerFeePerBtc(isCurrencyForMakerFeeBtc), amount); - double makerFeeAsDouble = (double) feePerBtc.value; - if (marketPriceAvailable) { - if (marketPriceMargin > 0) - makerFeeAsDouble = makerFeeAsDouble * Math.sqrt(marketPriceMargin * 100); - else - makerFeeAsDouble = 0; - - // For BTC we round so min value change is 100 satoshi - if (isCurrencyForMakerFeeBtc) - makerFeeAsDouble = MathUtils.roundDouble(makerFeeAsDouble / 100, 0) * 100; - } - - return CoinUtil.maxCoin(Coin.valueOf(MathUtils.doubleToLong(makerFeeAsDouble)), FeeService.getMinMakerFee(isCurrencyForMakerFeeBtc)); + return CoinUtil.maxCoin(feePerBtc, FeeService.getMinMakerFee(isCurrencyForMakerFeeBtc)); } else { return null; } @@ -124,14 +105,11 @@ public static Coin getMakerFee(boolean isCurrencyForMakerFeeBtc, @Nullable Coin * @param preferences * @param bsqWalletService * @param amount - * @param marketPriceAvailable - * @param marketPriceMargin * @return */ - public static boolean isCurrencyForMakerFeeBtc(Preferences preferences, BsqWalletService bsqWalletService, Coin amount, - boolean marketPriceAvailable, double marketPriceMargin) { + public static boolean isCurrencyForMakerFeeBtc(Preferences preferences, BsqWalletService bsqWalletService, Coin amount) { boolean payFeeInBtc = preferences.getPayFeeInBtc(); - boolean bsqForFeeAvailable = isBsqForMakerFeeAvailable(bsqWalletService, amount, marketPriceAvailable, marketPriceMargin); + boolean bsqForFeeAvailable = isBsqForMakerFeeAvailable(bsqWalletService, amount); return payFeeInBtc || !bsqForFeeAvailable; } @@ -140,13 +118,11 @@ public static boolean isCurrencyForMakerFeeBtc(Preferences preferences, BsqWalle * * @param bsqWalletService * @param amount - * @param marketPriceAvailable - * @param marketPriceMargin * @return */ - public static boolean isBsqForMakerFeeAvailable(BsqWalletService bsqWalletService, @Nullable Coin amount, boolean marketPriceAvailable, double marketPriceMargin) { + public static boolean isBsqForMakerFeeAvailable(BsqWalletService bsqWalletService, @Nullable Coin amount) { Coin availableBalance = bsqWalletService.getAvailableBalance(); - Coin makerFee = getMakerFee(false, amount, marketPriceAvailable, marketPriceMargin); + Coin makerFee = getMakerFee(false, amount); // If we don't know yet the maker fee (amount is not set) we return true, otherwise we would disable BSQ // fee each time we open the create offer screen as there the amount is not set. diff --git a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java index 4b7ad4a946a..755f4aa3a8e 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/MutableOfferDataModel.java @@ -53,7 +53,6 @@ import bisq.core.user.Preferences; import bisq.core.user.User; import bisq.core.util.BSFormatter; -import bisq.core.util.BsqFormatter; import bisq.network.p2p.P2PService; @@ -110,7 +109,6 @@ public abstract class MutableOfferDataModel extends OfferDataModel implements Bs private final TradeWalletService tradeWalletService; private final FeeService feeService; private final ReferralIdService referralIdService; - private final BsqFormatter bsqFormatter; private final BSFormatter btcFormatter; private final String offerId; private final BalanceListener btcBalanceListener; @@ -137,10 +135,10 @@ public abstract class MutableOfferDataModel extends OfferDataModel implements Bs protected PaymentAccount paymentAccount; protected boolean isTabSelected; protected double marketPriceMargin = 0; - protected Coin txFeeFromFeeService = Coin.ZERO; - protected boolean marketPriceAvailable; - protected int feeTxSize = 260; // size of typical tx with 1 input - protected int feeTxSizeEstimationRecursionCounter; + private Coin txFeeFromFeeService = Coin.ZERO; + private boolean marketPriceAvailable; + private int feeTxSize = 260; // size of typical tx with 1 input + private int feeTxSizeEstimationRecursionCounter; protected boolean allowAmountUpdate = true; @@ -153,7 +151,7 @@ public MutableOfferDataModel(OpenOfferManager openOfferManager, BtcWalletService Preferences preferences, User user, KeyRing keyRing, P2PService p2PService, PriceFeedService priceFeedService, FilterManager filterManager, AccountAgeWitnessService accountAgeWitnessService, TradeWalletService tradeWalletService, - FeeService feeService, ReferralIdService referralIdService, BsqFormatter bsqFormatter, + FeeService feeService, ReferralIdService referralIdService, BSFormatter btcFormatter) { super(btcWalletService); @@ -169,7 +167,6 @@ public MutableOfferDataModel(OpenOfferManager openOfferManager, BtcWalletService this.tradeWalletService = tradeWalletService; this.feeService = feeService; this.referralIdService = referralIdService; - this.bsqFormatter = bsqFormatter; this.btcFormatter = btcFormatter; offerId = Utilities.getRandomPrefix(5, 8) + "-" + @@ -328,11 +325,9 @@ Offer createAndGetOffer() { ArrayList acceptedCountryCodes = null; if (paymentAccount instanceof SepaAccount) { - acceptedCountryCodes = new ArrayList<>(); - acceptedCountryCodes.addAll(((SepaAccount) paymentAccount).getAcceptedCountryCodes()); + acceptedCountryCodes = new ArrayList<>(((SepaAccount) paymentAccount).getAcceptedCountryCodes()); } else if (paymentAccount instanceof SepaInstantAccount) { - acceptedCountryCodes = new ArrayList<>(); - acceptedCountryCodes.addAll(((SepaInstantAccount) paymentAccount).getAcceptedCountryCodes()); + acceptedCountryCodes = new ArrayList<>(((SepaInstantAccount) paymentAccount).getAcceptedCountryCodes()); } else if (paymentAccount instanceof CountryBasedPaymentAccount) { acceptedCountryCodes = new ArrayList<>(); acceptedCountryCodes.add(((CountryBasedPaymentAccount) paymentAccount).getCountry().code); @@ -825,23 +820,23 @@ public void setMarketPriceAvailable(boolean marketPriceAvailable) { } public Coin getMakerFee(boolean isCurrencyForMakerFeeBtc) { - return OfferUtil.getMakerFee(isCurrencyForMakerFeeBtc, amount.get(), marketPriceAvailable, marketPriceMargin); + return OfferUtil.getMakerFee(isCurrencyForMakerFeeBtc, amount.get()); } public Coin getMakerFee() { - return OfferUtil.getMakerFee(bsqWalletService, preferences, amount.get(), marketPriceAvailable, marketPriceMargin); + return OfferUtil.getMakerFee(bsqWalletService, preferences, amount.get()); } public Coin getMakerFeeInBtc() { - return OfferUtil.getMakerFee(true, amount.get(), marketPriceAvailable, marketPriceMargin); + return OfferUtil.getMakerFee(true, amount.get()); } public Coin getMakerFeeInBsq() { - return OfferUtil.getMakerFee(false, amount.get(), marketPriceAvailable, marketPriceMargin); + return OfferUtil.getMakerFee(false, amount.get()); } public boolean isCurrencyForMakerFeeBtc() { - return OfferUtil.isCurrencyForMakerFeeBtc(preferences, bsqWalletService, amount.get(), marketPriceAvailable, marketPriceMargin); + return OfferUtil.isCurrencyForMakerFeeBtc(preferences, bsqWalletService, amount.get()); } public boolean isPreferredFeeCurrencyBtc() { @@ -849,7 +844,7 @@ public boolean isPreferredFeeCurrencyBtc() { } public boolean isBsqForFeeAvailable() { - return OfferUtil.isBsqForMakerFeeAvailable(bsqWalletService, amount.get(), marketPriceAvailable, marketPriceMargin); + return OfferUtil.isBsqForMakerFeeAvailable(bsqWalletService, amount.get()); } public boolean isHalCashAccount() { diff --git a/desktop/src/main/java/bisq/desktop/main/offer/createoffer/CreateOfferDataModel.java b/desktop/src/main/java/bisq/desktop/main/offer/createoffer/CreateOfferDataModel.java index 630ad4bbbd2..b3f3dd1e2ae 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/createoffer/CreateOfferDataModel.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/createoffer/CreateOfferDataModel.java @@ -35,7 +35,6 @@ import bisq.core.user.Preferences; import bisq.core.user.User; import bisq.core.util.BSFormatter; -import bisq.core.util.BsqFormatter; import bisq.network.p2p.P2PService; @@ -64,7 +63,6 @@ public CreateOfferDataModel(OpenOfferManager openOfferManager, TradeWalletService tradeWalletService, FeeService feeService, ReferralIdService referralIdService, - BsqFormatter bsqFormatter, BSFormatter btcFormatter) { super(openOfferManager, btcWalletService, @@ -79,7 +77,6 @@ public CreateOfferDataModel(OpenOfferManager openOfferManager, tradeWalletService, feeService, referralIdService, - bsqFormatter, btcFormatter); } } diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/editoffer/EditOfferDataModel.java b/desktop/src/main/java/bisq/desktop/main/portfolio/editoffer/EditOfferDataModel.java index 253b70de574..2054869aa06 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/editoffer/EditOfferDataModel.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/editoffer/EditOfferDataModel.java @@ -39,7 +39,6 @@ import bisq.core.user.Preferences; import bisq.core.user.User; import bisq.core.util.BSFormatter; -import bisq.core.util.BsqFormatter; import bisq.network.p2p.P2PService; @@ -49,6 +48,8 @@ import com.google.inject.Inject; +import java.util.Optional; + class EditOfferDataModel extends MutableOfferDataModel { private final CorePersistenceProtoResolver corePersistenceProtoResolver; @@ -69,7 +70,6 @@ class EditOfferDataModel extends MutableOfferDataModel { TradeWalletService tradeWalletService, FeeService feeService, ReferralIdService referralIdService, - BsqFormatter bsqFormatter, BSFormatter btcFormatter, CorePersistenceProtoResolver corePersistenceProtoResolver) { super(openOfferManager, @@ -85,7 +85,6 @@ class EditOfferDataModel extends MutableOfferDataModel { tradeWalletService, feeService, referralIdService, - bsqFormatter, btcFormatter); this.corePersistenceProtoResolver = corePersistenceProtoResolver; } @@ -117,14 +116,15 @@ public void applyOpenOffer(OpenOffer openOffer) { this.initialState = openOffer.getState(); PaymentAccount tmpPaymentAccount = user.getPaymentAccount(openOffer.getOffer().getMakerPaymentAccountId()); - TradeCurrency selectedTradeCurrency = CurrencyUtil.getTradeCurrency(openOffer.getOffer().getCurrencyCode()).get(); - - this.paymentAccount = PaymentAccount.fromProto(tmpPaymentAccount.toProtoMessage(), corePersistenceProtoResolver); - - if (paymentAccount.getSingleTradeCurrency() != null) - paymentAccount.setSingleTradeCurrency(selectedTradeCurrency); - else - paymentAccount.setSelectedTradeCurrency(selectedTradeCurrency); + Optional optionalTradeCurrency = CurrencyUtil.getTradeCurrency(openOffer.getOffer().getCurrencyCode()); + if (optionalTradeCurrency.isPresent() && tmpPaymentAccount != null) { + TradeCurrency selectedTradeCurrency = optionalTradeCurrency.get(); + this.paymentAccount = PaymentAccount.fromProto(tmpPaymentAccount.toProtoMessage(), corePersistenceProtoResolver); + if (paymentAccount.getSingleTradeCurrency() != null) + paymentAccount.setSingleTradeCurrency(selectedTradeCurrency); + else + paymentAccount.setSelectedTradeCurrency(selectedTradeCurrency); + } allowAmountUpdate = false; } diff --git a/desktop/src/test/java/bisq/desktop/main/offer/createoffer/CreateOfferViewModelTest.java b/desktop/src/test/java/bisq/desktop/main/offer/createoffer/CreateOfferViewModelTest.java index bdd3ff6f0e6..d38f32ed5cc 100644 --- a/desktop/src/test/java/bisq/desktop/main/offer/createoffer/CreateOfferViewModelTest.java +++ b/desktop/src/test/java/bisq/desktop/main/offer/createoffer/CreateOfferViewModelTest.java @@ -112,7 +112,7 @@ public void setUp() { when(bsqFormatter.formatCoin(any())).thenReturn("0"); when(bsqWalletService.getAvailableBalance()).thenReturn(Coin.ZERO); - CreateOfferDataModel dataModel = new CreateOfferDataModel(null, btcWalletService, bsqWalletService, empty, user, null, null, priceFeedService, null, accountAgeWitnessService, null, feeService, null, bsqFormatter, bsFormatter); + CreateOfferDataModel dataModel = new CreateOfferDataModel(null, btcWalletService, bsqWalletService, empty, user, null, null, priceFeedService, null, accountAgeWitnessService, null, feeService, null, bsFormatter); dataModel.initWithData(OfferPayload.Direction.BUY, new CryptoCurrency("BTC", "bitcoin")); dataModel.activate();