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 trade limit. Make trade limit a DAO parameter #2413

Merged
merged 5 commits into from Feb 15, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions common/src/main/proto/pb.proto
Expand Up @@ -710,14 +710,14 @@ message PaymentAccountPayload {
CryptoCurrencyAccountPayload crypto_currency_account_payload = 8;
FasterPaymentsAccountPayload faster_payments_account_payload = 9;
InteracETransferAccountPayload interac_e_transfer_account_payload = 10;
OKPayAccountPayload o_k_pay_account_payload = 11;
OKPayAccountPayload o_k_pay_account_payload = 11; // Deprecated, not used anymore
PerfectMoneyAccountPayload perfect_money_account_payload = 12;
SwishAccountPayload swish_account_payload = 13;
USPostalMoneyOrderAccountPayload u_s_postal_money_order_account_payload = 14;
UpholdAccountPayload uphold_account_payload = 16;
CashAppAccountPayload cash_app_account_payload = 17;
CashAppAccountPayload cash_app_account_payload = 17; // Deprecated, not used anymore
MoneyBeamAccountPayload money_beam_account_payload = 18;
VenmoAccountPayload venmo_account_payload = 19;
VenmoAccountPayload venmo_account_payload = 19; // Deprecated, not used anymore
PopmoneyAccountPayload popmoney_account_payload = 20;
RevolutAccountPayload revolut_account_payload = 21;
WeChatPayAccountPayload we_chat_pay_account_payload = 22;
Expand Down Expand Up @@ -849,6 +849,7 @@ message InteracETransferAccountPayload {
string answer = 4;
}

// Deprecated, not used anymore
message OKPayAccountPayload {
string account_nr = 1;
}
Expand All @@ -857,6 +858,7 @@ message UpholdAccountPayload {
string account_id = 1;
}

// Deprecated, not used anymore
message CashAppAccountPayload {
string cash_tag = 1;
}
Expand All @@ -865,6 +867,7 @@ message MoneyBeamAccountPayload {
string account_id = 1;
}

// Deprecated, not used anymore
message VenmoAccountPayload {
string venmo_user_name = 1;
string holder_name = 2;
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/java/bisq/core/CoreModule.java
Expand Up @@ -41,6 +41,7 @@
import bisq.core.notifications.alerts.market.MarketAlerts;
import bisq.core.notifications.alerts.price.PriceAlert;
import bisq.core.offer.OfferModule;
import bisq.core.payment.TradeLimits;
import bisq.core.presentation.CorePresentationModule;
import bisq.core.proto.network.CoreNetworkProtoResolver;
import bisq.core.proto.persistable.CorePersistenceProtoResolver;
Expand Down Expand Up @@ -87,6 +88,8 @@ protected void configure() {

bind(BisqEnvironment.class).toInstance((BisqEnvironment) environment);

bind(TradeLimits.class).in(Singleton.class);

bind(KeyStorage.class).in(Singleton.class);
bind(KeyRing.class).in(Singleton.class);
bind(User.class).in(Singleton.class);
Expand Down
7 changes: 5 additions & 2 deletions core/src/main/java/bisq/core/app/BisqSetup.java
Expand Up @@ -43,7 +43,7 @@
import bisq.core.offer.OpenOfferManager;
import bisq.core.payment.AccountAgeWitnessService;
import bisq.core.payment.PaymentAccount;
import bisq.core.payment.payload.PaymentMethod;
import bisq.core.payment.TradeLimits;
import bisq.core.provider.fee.FeeService;
import bisq.core.provider.price.PriceFeedService;
import bisq.core.trade.TradeManager;
Expand Down Expand Up @@ -151,6 +151,7 @@ public interface BisqSetupCompleteListener {
private final AssetTradeActivityCheck tradeActivityCheck;
private final AssetService assetService;
private final TorSetup torSetup;
private final TradeLimits tradeLimits;
private final BSFormatter formatter;
@Setter
@Nullable
Expand Down Expand Up @@ -228,6 +229,7 @@ public BisqSetup(P2PNetworkSetup p2PNetworkSetup,
AssetTradeActivityCheck tradeActivityCheck,
AssetService assetService,
TorSetup torSetup,
TradeLimits tradeLimits,
BSFormatter formatter) {


Expand Down Expand Up @@ -267,6 +269,7 @@ public BisqSetup(P2PNetworkSetup p2PNetworkSetup,
this.tradeActivityCheck = tradeActivityCheck;
this.assetService = assetService;
this.torSetup = torSetup;
this.tradeLimits = tradeLimits;
this.formatter = formatter;
}

Expand Down Expand Up @@ -583,7 +586,7 @@ private void initDomainServices() {

clock.start();

PaymentMethod.onAllServicesInitialized();
tradeLimits.onAllServicesInitialized();

disputeManager.onAllServicesInitialized();

Expand Down
Expand Up @@ -112,6 +112,7 @@ public enum Param {

LOCK_TIME_TRADE_PAYOUT("4320", ParamType.BLOCK), // 30 days
ARBITRATOR_FEE("0", ParamType.BTC),
MAX_TRADE_LIMIT("2", ParamType.BTC), // max trade limit for lowest risk payment method. Others will get derived from that.

// See: https://github.com/bisq-network/proposals/issues/46
// The last block in the proposal and vote phases are not shown to the user as he cannot make a tx there as it would be
Expand Down
Expand Up @@ -168,6 +168,19 @@ public void validateParamValue(Param param, String inputValue) throws Validation
case RECIPIENT_BTC_ADDRESS:
break;

case ASSET_LISTING_FEE_PER_DAY:
break;
case ASSET_MIN_VOLUME:
break;

case LOCK_TIME_TRADE_PAYOUT:
break;
case ARBITRATOR_FEE:
break;

case MAX_TRADE_LIMIT:
break;

case PHASE_UNDEFINED:
break;
case PHASE_PROPOSAL:
Expand Down
29 changes: 0 additions & 29 deletions core/src/main/java/bisq/core/locale/CurrencyUtil.java
Expand Up @@ -155,7 +155,6 @@ public static List<CryptoCurrency> getRemovedCryptoCurrencies() {
return currencies;
}

// At OKPay you can exchange internally those currencies
public static List<TradeCurrency> getAllAdvancedCashCurrencies() {
ArrayList<TradeCurrency> currencies = new ArrayList<>(Arrays.asList(
new FiatCurrency("USD"),
Expand All @@ -170,34 +169,6 @@ public static List<TradeCurrency> getAllAdvancedCashCurrencies() {
return currencies;
}

public static List<TradeCurrency> getAllOKPayCurrencies() {
ArrayList<TradeCurrency> currencies = new ArrayList<>(Arrays.asList(
new FiatCurrency("EUR"),
new FiatCurrency("USD"),
new FiatCurrency("GBP"),
new FiatCurrency("CHF"),
new FiatCurrency("RUB"),
new FiatCurrency("PLN"),
new FiatCurrency("JPY"),
new FiatCurrency("CAD"),
new FiatCurrency("AUD"),
new FiatCurrency("CZK"),
new FiatCurrency("NOK"),
new FiatCurrency("SEK"),
new FiatCurrency("DKK"),
new FiatCurrency("HRK"),
new FiatCurrency("HUF"),
new FiatCurrency("NZD"),
new FiatCurrency("RON"),
new FiatCurrency("TRY"),
new FiatCurrency("ZAR"),
new FiatCurrency("HKD"),
new FiatCurrency("CNY")
));
currencies.sort(Comparator.comparing(TradeCurrency::getCode));
return currencies;
}

public static List<TradeCurrency> getAllMoneyGramCurrencies() {
ArrayList<TradeCurrency> currencies = new ArrayList<>(Arrays.asList(
new FiatCurrency("AED"),
Expand Down
48 changes: 0 additions & 48 deletions core/src/main/java/bisq/core/payment/CashAppAccount.java

This file was deleted.

47 changes: 0 additions & 47 deletions core/src/main/java/bisq/core/payment/OKPayAccount.java

This file was deleted.

Expand Up @@ -22,16 +22,10 @@
public class PaymentAccountFactory {
public static PaymentAccount getPaymentAccount(PaymentMethod paymentMethod) {
switch (paymentMethod.getId()) {
case PaymentMethod.OK_PAY_ID:
return new OKPayAccount();
case PaymentMethod.UPHOLD_ID:
return new UpholdAccount();
case PaymentMethod.CASH_APP_ID:
return new CashAppAccount();
case PaymentMethod.MONEY_BEAM_ID:
return new MoneyBeamAccount();
case PaymentMethod.VENMO_ID:
return new VenmoAccount();
case PaymentMethod.POPMONEY_ID:
return new PopmoneyAccount();
case PaymentMethod.REVOLUT_ID:
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/bisq/core/payment/PaymentAccountUtil.java
Expand Up @@ -106,7 +106,7 @@ public static String getBankId(PaymentAccount paymentAccount) {

@Nullable
public static String getCountryCode(PaymentAccount paymentAccount) {
// That is optional and set to null if not supported (AltCoins, OKPay,...)
// That is optional and set to null if not supported (AltCoins,...)
if (paymentAccount instanceof CountryBasedPaymentAccount) {
Country country = (((CountryBasedPaymentAccount) paymentAccount)).getCountry();
return country != null ? country.code : null;
Expand All @@ -115,7 +115,7 @@ public static String getCountryCode(PaymentAccount paymentAccount) {
}

// TODO no code duplication found in UI code (added for API)
// That is optional and set to null if not supported (AltCoins, OKPay,...)
// That is optional and set to null if not supported (AltCoins,...)
/* public static String getCountryCode(PaymentAccount paymentAccount) {
if (paymentAccount instanceof CountryBasedPaymentAccount) {
Country country = ((CountryBasedPaymentAccount) paymentAccount).getCountry();
Expand Down
95 changes: 95 additions & 0 deletions core/src/main/java/bisq/core/payment/TradeLimits.java
@@ -0,0 +1,95 @@
/*
* 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 bisq.core.payment;

import bisq.core.dao.governance.param.Param;
import bisq.core.dao.governance.period.PeriodService;
import bisq.core.dao.state.DaoStateService;

import bisq.common.util.MathUtils;

import org.bitcoinj.core.Coin;

import javax.inject.Inject;

import com.google.common.annotations.VisibleForTesting;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

import javax.annotation.Nullable;

@Slf4j
public class TradeLimits {
@Nullable
@Getter
private static TradeLimits INSTANCE;

private final DaoStateService daoStateService;
private final PeriodService periodService;

@Inject
public TradeLimits(DaoStateService daoStateService, PeriodService periodService) {
this.daoStateService = daoStateService;
this.periodService = periodService;
INSTANCE = this;
}

public void onAllServicesInitialized() {
// Do nothing but required to enforce class creation by guice.
// The TradeLimits is used by PaymentMethod via the static INSTANCE and this would not trigger class creation by
// guice.
}

public Coin getMaxTradeLimit() {
return daoStateService.getParamValueAsCoin(Param.MAX_TRADE_LIMIT, periodService.getChainHeight());
}

// We possibly rounded value for the first month gets multiplied by 4 to get the trade limit after the account
// age witness is not considered anymore (> 2 months).

/**
*
* @param maxLimit Satoshi value of max trade limit
* @param riskFactor Risk factor to decrease trade limit for higher risk payment methods
* @return Possibly adjusted trade limit to avoid that in first month trade limit get precision < 4.
*/
public long getRoundedRiskBasedTradeLimit(long maxLimit, long riskFactor) {
return getFirstMonthRiskBasedTradeLimit(maxLimit, riskFactor) * 4;
}

// The first month we allow only 0.25% of he trade limit. We want to ensure that precision is <=4 otherwise we round.

/**
*
* @param maxLimit Satoshi value of max trade limit
* @param riskFactor Risk factor to decrease trade limit for higher risk payment methods
* @return Rounded trade limit for first month to avoid BTC value with precision < 4.
*/
@VisibleForTesting
long getFirstMonthRiskBasedTradeLimit(long maxLimit, long riskFactor) {
// The first month we use 1/4 of the max limit. We multiply with riskFactor, so 1/ (4 * 8) is smallest limit in
// first month of a maxTradeLimitHighRisk method
long smallestLimit = maxLimit / (4 * riskFactor); // e.g. 100000000 / 32 = 3125000
// We want to avoid more then 4 decimal places (100000000 / 32 = 3125000 or 1 BTC / 32 = 0.03125 BTC).
// We want rounding to 0.0313 BTC
double decimalForm = MathUtils.scaleDownByPowerOf10((double) smallestLimit, 8);
double rounded = MathUtils.roundDouble(decimalForm, 4);
return MathUtils.roundDoubleToLong(MathUtils.scaleUpByPowerOf10(rounded, 8));
}
}