<commit_before>/*
 * This file is part of bisq.
 *
 * bisq is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or (at
 * your option) any later version.
 *
 * bisq is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
 * License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with bisq. If not, see <http://www.gnu.org/licenses/>.
 */

package io.bisq.core.provider.fee;

import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.SettableFuture;
import com.google.inject.Inject;
import io.bisq.common.UserThread;
import io.bisq.common.handlers.FaultHandler;
import io.bisq.common.util.Tuple2;
import io.bisq.core.app.BisqEnvironment;
import io.bisq.core.provider.ProvidersRepository;
import io.bisq.network.http.HttpClient;
import org.bitcoinj.core.Coin;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Nullable;
import java.time.Instant;
import java.util.Map;

import static com.google.common.base.Preconditions.checkNotNull;

public class FeeService {
    private static final Logger log = LoggerFactory.getLogger(FeeService.class);

    // https://litecoin.info/Transaction_fees
    //0.001 (LTC)/kb -> 0.00100000 sat/kb -> 100 sat/byte
    public static final long LTC_DEFAULT_TX_FEE = 100;
    public static final long BTC_DEFAULT_TX_FEE = 150;
    public static final long DOGE_DEFAULT_TX_FEE = 100;

    // Dust limit for LTC is 100 000 sat
    // https://litecoin.info/Transaction_fees
    private static final long MIN_MAKER_FEE_IN_BASE_CUR = 100_000; // 0.03 USD at LTC price 30 USD
    private static final long MIN_TAKER_FEE_IN_BASE_CUR = 100_000;
    private static final long DEFAULT_MAKER_FEE_IN_BASE_CUR = 300_000; // 0.10 USD at LTC price 30 USD
    private static final long DEFAULT_TAKER_FEE_IN_BASE_CUR = 400_000; // 0.12 USD at LTC price 30 USD

    private static final long MIN_MAKER_FEE_IN_MBSQ = 30; // 0.0003 bsq -> 0.003 USD -> 1% of MIN_MAKER_FEE_IN_BASE_CUR
    private static final long MIN_TAKER_FEE_IN_MBSQ = 30;
    private static final long DEFAULT_MAKER_FEE_IN_MBSQ = 90;
    private static final long DEFAULT_TAKER_FEE_IN_MBSQ = 120;


    // 0.00216 btc is for 3 x tx fee for taker -> about 2 EUR!

    public static final long MIN_PAUSE_BETWEEN_REQUESTS_IN_MIN = 10;

    private final FeeProvider feeProvider;
    private final String baseCurrencyCode;
    private long txFeePerByte;
    private Map<String, Long> timeStampMap;
    private long epochInSecondAtLastRequest;
    private long lastRequest;

    ///////////////////////////////////////////////////////////////////////////////////////////
    // Constructor
    ///////////////////////////////////////////////////////////////////////////////////////////

    @Inject
    public FeeService(HttpClient httpClient, ProvidersRepository providersRepository) {
        baseCurrencyCode = BisqEnvironment.getBaseCurrencyNetwork().getCurrencyCode();
        feeProvider = new FeeProvider(httpClient, providersRepository.getBaseUrl());

        switch (baseCurrencyCode) {
            case "BTC":
                txFeePerByte = BTC_DEFAULT_TX_FEE;
                break;
            case "LTC":
                txFeePerByte = LTC_DEFAULT_TX_FEE;
                break;
            case "DOGE":
                txFeePerByte = DOGE_DEFAULT_TX_FEE;
                break;
            default:
                throw new RuntimeException("baseCurrencyCode not defined. baseCurrencyCode=" + baseCurrencyCode);
        }
    }

    public void onAllServicesInitialized() {<commit_msg>Adjust fees<commit_after>/*
 * This file is part of bisq.
 *
 * bisq is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or (at
 * your option) any later version.
 *
 * bisq is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
 * License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with bisq. If not, see <http://www.gnu.org/licenses/>.
 */

package io.bisq.core.provider.fee;

import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.SettableFuture;
import com.google.inject.Inject;
import io.bisq.common.UserThread;
import io.bisq.common.handlers.FaultHandler;
import io.bisq.common.util.Tuple2;
import io.bisq.core.app.BisqEnvironment;
import io.bisq.core.provider.ProvidersRepository;
import io.bisq.network.http.HttpClient;
import org.bitcoinj.core.Coin;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Nullable;
import java.time.Instant;
import java.util.Map;

import static com.google.common.base.Preconditions.checkNotNull;

public class FeeService {
    private static final Logger log = LoggerFactory.getLogger(FeeService.class);

    // https://litecoin.info/Transaction_fees
    //0.001 (LTC)/kb -> 0.00100000 sat/kb -> 100 sat/byte
    public static final long LTC_DEFAULT_TX_FEE = 100;
    public static final long BTC_DEFAULT_TX_FEE = 150;
    public static final long DOGE_DEFAULT_TX_FEE = 100;

    // Dust limit for LTC is 100 000 sat
    // https://litecoin.info/Transaction_fees
    private static long MIN_MAKER_FEE_IN_BASE_CUR;
    private static long MIN_TAKER_FEE_IN_BASE_CUR;
    private static long DEFAULT_MAKER_FEE_IN_BASE_CUR;
    private static long DEFAULT_TAKER_FEE_IN_BASE_CUR;

    private static final long MIN_MAKER_FEE_IN_MBSQ = 30; // 0.0003 bsq -> 0.003 USD -> 1% of MIN_MAKER_FEE_IN_BASE_CUR
    private static final long MIN_TAKER_FEE_IN_MBSQ = 30;
    private static final long DEFAULT_MAKER_FEE_IN_MBSQ = 90;
    private static final long DEFAULT_TAKER_FEE_IN_MBSQ = 120;


    // 0.00216 btc is for 3 x tx fee for taker -> about 2 EUR!

    public static final long MIN_PAUSE_BETWEEN_REQUESTS_IN_MIN = 10;

    private final FeeProvider feeProvider;
    private final String baseCurrencyCode;
    private long txFeePerByte;
    private Map<String, Long> timeStampMap;
    private long epochInSecondAtLastRequest;
    private long lastRequest;

    ///////////////////////////////////////////////////////////////////////////////////////////
    // Constructor
    ///////////////////////////////////////////////////////////////////////////////////////////

    @Inject
    public FeeService(HttpClient httpClient, ProvidersRepository providersRepository) {
        baseCurrencyCode = BisqEnvironment.getBaseCurrencyNetwork().getCurrencyCode();
        feeProvider = new FeeProvider(httpClient, providersRepository.getBaseUrl());

        switch (baseCurrencyCode) {
            case "BTC":
                MIN_MAKER_FEE_IN_BASE_CUR = 10_000; // 0.25 USD at BTC price 2500 USD 
                MIN_TAKER_FEE_IN_BASE_CUR = 10_000;
                DEFAULT_MAKER_FEE_IN_BASE_CUR = 100_000; // 2.50 USD at BTC price 2500 USD
                DEFAULT_TAKER_FEE_IN_BASE_CUR = 150_000; // 3.25 USD at BTC price 2500 USD
                txFeePerByte = BTC_DEFAULT_TX_FEE;
                break;
            case "LTC":
                MIN_MAKER_FEE_IN_BASE_CUR = 600_000; // 0.24 USD at LTC price 40 USD
                MIN_TAKER_FEE_IN_BASE_CUR = 600_000;
                DEFAULT_MAKER_FEE_IN_BASE_CUR = 6_000_000; // 2.4 USD at LTC price 40 USD
                DEFAULT_TAKER_FEE_IN_BASE_CUR = 9_000_000; // 3.6 USD at LTC price 40 USD
                txFeePerByte = LTC_DEFAULT_TX_FEE;
                break;
            case "DOGE":
                MIN_MAKER_FEE_IN_BASE_CUR = 80_000_000_000L; // 0.24 USD at DOGE price 0.003 USD
                MIN_TAKER_FEE_IN_BASE_CUR = 80_000_000_000L;
                DEFAULT_MAKER_FEE_IN_BASE_CUR = 800_000_000_000L; // 2.4 USD at DOGE price 0.003 USD 
                DEFAULT_TAKER_FEE_IN_BASE_CUR = 1_200_000_000_000L; // 3.6 USD at DOGE price 0.003 USD
                txFeePerByte = DOGE_DEFAULT_TX_FEE;
                break;
            default:
                throw new RuntimeException("baseCurrencyCode not defined. baseCurrencyCode=" + baseCurrencyCode);
        }
    }

    public void onAllServicesInitialized() {
{'fraction_non_alphanumeric': 0.10951302378255946, 'fraction_numerical': 0.03567383918459796, 'mean_word_length': 2.6658364466583646, 'pattern_counts': {'":': 6, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5934416', 'n_tokens_mistral': 2937, 'n_tokens_neox': 2638, 'n_words': 749}