Make max trade limit dependent on payment method. increase limits to 0.1-0.2 btc

This commit is contained in:
Manfred Karrer 2016-03-10 18:47:53 +01:00
parent 44445cd411
commit 4010f5a727
26 changed files with 140 additions and 130 deletions

View file

@ -62,7 +62,7 @@ public class FeePolicy {
// Some wallets (Mycelium) don't support higher fees
public static Coin getMinRequiredFeeForFundingTx() {
return Coin.valueOf(20_000);
return Coin.valueOf(20_000);
}
@ -78,17 +78,8 @@ public class FeePolicy {
}
// TODO make final again later 100_000_000
// 0.1 BTC; about 4 EUR @ 400 EUR/BTC
private static Coin SECURITY_DEPOSIT = Coin.valueOf(10_000_000);
public static Coin getSecurityDeposit() {
return SECURITY_DEPOSIT;
}
// Called from WalletService to reduce SECURITY_DEPOSIT for mainnet to 0.01 btc
// TODO remove later when tested enough
public static void setSecurityDeposit(Coin securityDeposit) {
SECURITY_DEPOSIT = securityDeposit;
return Coin.valueOf(10_000_000);
}
}

View file

@ -22,18 +22,8 @@ import org.bitcoinj.core.Transaction;
public class Restrictions {
// TODO make final again later
public static final Coin MIN_TRADE_AMOUNT = Coin.parseCoin("0.0001"); // 4 cent @ 400 EUR/BTC
// TODO make final again later
public static Coin MAX_TRADE_AMOUNT = Coin.parseCoin("1");
// Called from WalletService to reduce MAX_TRADE_AMOUNT for mainnet to 0.01 btc
// TODO remove later when tested enough
public static void setMaxTradeAmount(Coin maxTradeAmount) {
MAX_TRADE_AMOUNT = maxTradeAmount;
}
public static boolean isAboveFixedTxFeeAndDust(Coin amount) {
return amount != null && amount.compareTo(FeePolicy.getFixedTxFeeForTrades().add(Transaction.MIN_NONDUST_OUTPUT)) > 0;
}

View file

@ -213,12 +213,6 @@ public class WalletService {
walletAppKit.connectToLocalHost(); // You should run a regtest mode bitcoind locally.}
}
} else if (params == MainNetParams.get()) {
// reduce for mainnet testing
// TODO revert later when tested enough
FeePolicy.setSecurityDeposit(Coin.parseCoin("0.01")); // 4 EUR @ 400 EUR/BTC
Restrictions.setMaxTradeAmount(Coin.parseCoin("0.1")); // 40 EUR @ 400 EUR/BTC
// Checkpoints are block headers that ship inside our app: for a new user, we pick the last header
// in the checkpoints file and then download the rest from the network. It makes things much faster.
// Checkpoint files are made using the BuildCheckpoints tool and usually we have to download the

View file

@ -19,10 +19,12 @@ package io.bitsquare.payment;
import io.bitsquare.app.Version;
import io.bitsquare.common.persistance.Persistable;
import org.bitcoinj.core.Coin;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@ -65,39 +67,56 @@ public final class PaymentMethod implements Persistable, Comparable {
public static PaymentMethod BLOCK_CHAINS;
public static final List<PaymentMethod> ALL_VALUES = new ArrayList<>(Arrays.asList(
OK_PAY = new PaymentMethod(OK_PAY_ID, 0, DAY), // tx instant so min. wait time
PERFECT_MONEY = new PaymentMethod(PERFECT_MONEY_ID, 0, DAY),
SEPA = new PaymentMethod(SEPA_ID, 0, 8 * DAY), // sepa takes 1-3 business days. We use 8 days to include safety for holidays
NATIONAL_BANK = new PaymentMethod(NATIONAL_BANK_ID, 0, 4 * DAY),
SAME_BANK = new PaymentMethod(SAME_BANK_ID, 0, 2 * DAY),
SPECIFIC_BANKS = new PaymentMethod(SPECIFIC_BANKS_ID, 0, 4 * DAY),
SWISH = new PaymentMethod(SWISH_ID, 0, DAY),
ALI_PAY = new PaymentMethod(ALI_PAY_ID, 0, DAY),
/* FED_WIRE = new PaymentMethod(FED_WIRE_ID, 0, DAY),*/
/* TRANSFER_WISE = new PaymentMethod(TRANSFER_WISE_ID, 0, DAY),*/
/* US_POSTAL_MONEY_ORDER = new PaymentMethod(US_POSTAL_MONEY_ORDER_ID, 0, DAY),*/
BLOCK_CHAINS = new PaymentMethod(BLOCK_CHAINS_ID, 0, DAY)
OK_PAY = new PaymentMethod(OK_PAY_ID, 0, DAY, Coin.parseCoin("0.5")), // tx instant so min. wait time
PERFECT_MONEY = new PaymentMethod(PERFECT_MONEY_ID, 0, DAY, Coin.parseCoin("0.2")),
SEPA = new PaymentMethod(SEPA_ID, 0, 8 * DAY, Coin.parseCoin("0.1")), // sepa takes 1-3 business days. We use 8 days to include safety for holidays
NATIONAL_BANK = new PaymentMethod(NATIONAL_BANK_ID, 0, 4 * DAY, Coin.parseCoin("0.1")),
SAME_BANK = new PaymentMethod(SAME_BANK_ID, 0, 2 * DAY, Coin.parseCoin("0.1")),
SPECIFIC_BANKS = new PaymentMethod(SPECIFIC_BANKS_ID, 0, 4 * DAY, Coin.parseCoin("0.1")),
SWISH = new PaymentMethod(SWISH_ID, 0, DAY, Coin.parseCoin("0.2")),
ALI_PAY = new PaymentMethod(ALI_PAY_ID, 0, DAY, Coin.parseCoin("0.2")),
/* FED_WIRE = new PaymentMethod(FED_WIRE_ID, 0, DAY, Coin.parseCoin("0.1")),*/
/* TRANSFER_WISE = new PaymentMethod(TRANSFER_WISE_ID, 0, DAY, Coin.parseCoin("0.1")),*/
/* US_POSTAL_MONEY_ORDER = new PaymentMethod(US_POSTAL_MONEY_ORDER_ID, 0, DAY, Coin.parseCoin("0.1")),*/
BLOCK_CHAINS = new PaymentMethod(BLOCK_CHAINS_ID, 0, DAY, Coin.parseCoin("0.2"))
));
private final String id;
private final long lockTime;
private long lockTime;
private final int maxTradePeriod;
private int maxTradePeriod;
private Coin maxTradeLimitInBitcoin;
/**
* @param id
* @param lockTime lock time when seller release BTC until the payout tx gets valid (bitcoin tx lockTime). Serves as protection
* against charge back risk. If Bank do the charge back quickly the Arbitrator and the seller can push another
* double spend tx to invalidate the time locked payout tx. For the moment we set all to 0 but will have it in
* place when needed.
* @param maxTradePeriod The min. period a trader need to wait until he gets displayed the contact form for opening a dispute.
* @param lockTime lock time when seller release BTC until the payout tx gets valid (bitcoin tx lockTime). Serves as protection
* against charge back risk. If Bank do the charge back quickly the Arbitrator and the seller can push another
* double spend tx to invalidate the time locked payout tx. For the moment we set all to 0 but will have it in
* place when needed.
* @param maxTradePeriod The min. period a trader need to wait until he gets displayed the contact form for opening a dispute.
* @param maxTradeLimitInBitcoin The max. allowed trade amount in Bitcoin for that payment method (depending on charge back risk)
*/
public PaymentMethod(String id, long lockTime, int maxTradePeriod) {
public PaymentMethod(String id, long lockTime, int maxTradePeriod, Coin maxTradeLimitInBitcoin) {
this.id = id;
this.lockTime = lockTime;
this.maxTradePeriod = maxTradePeriod;
this.maxTradeLimitInBitcoin = maxTradeLimitInBitcoin;
}
private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
try {
in.defaultReadObject();
// In case we update those values we want that the persisted accounts get updated as well
PaymentMethod paymentMethod = PaymentMethod.getPaymentMethodById(id);
this.lockTime = paymentMethod.getLockTime();
this.maxTradePeriod = paymentMethod.getMaxTradePeriod();
this.maxTradeLimitInBitcoin = paymentMethod.getMaxTradeLimitInBitcoin();
} catch (Throwable t) {
log.error("Cannot be deserialized." + t.getMessage());
}
}
public static PaymentMethod getPaymentMethodById(String name) {
@ -116,6 +135,10 @@ public final class PaymentMethod implements Persistable, Comparable {
return lockTime;
}
public Coin getMaxTradeLimitInBitcoin() {
return maxTradeLimitInBitcoin;
}
@Override
public int compareTo(@NotNull Object other) {
if (id != null)
@ -133,7 +156,8 @@ public final class PaymentMethod implements Persistable, Comparable {
if (lockTime != that.lockTime) return false;
if (maxTradePeriod != that.maxTradePeriod) return false;
return !(id != null ? !id.equals(that.id) : that.id != null);
if (id != null ? !id.equals(that.id) : that.id != null) return false;
return !(maxTradeLimitInBitcoin != null ? !maxTradeLimitInBitcoin.equals(that.maxTradeLimitInBitcoin) : that.maxTradeLimitInBitcoin != null);
}
@ -142,6 +166,7 @@ public final class PaymentMethod implements Persistable, Comparable {
int result = id != null ? id.hashCode() : 0;
result = 31 * result + (int) (lockTime ^ (lockTime >>> 32));
result = 31 * result + maxTradePeriod;
result = 31 * result + (maxTradeLimitInBitcoin != null ? maxTradeLimitInBitcoin.hashCode() : 0);
return result;
}
@ -150,7 +175,8 @@ public final class PaymentMethod implements Persistable, Comparable {
return "PaymentMethod{" +
"id='" + id + '\'' +
", lockTime=" + lockTime +
", waitPeriodForOpenDispute=" + maxTradePeriod +
", maxTradePeriod=" + maxTradePeriod +
", maxTradeLimitInBitcoin=" + maxTradeLimitInBitcoin +
'}';
}
}

View file

@ -200,8 +200,8 @@ public final class Offer implements StoragePayload, RequiresOwnerIsOnlinePayload
checkArgument(getMinAmount().compareTo(Restrictions.MIN_TRADE_AMOUNT) >= 0, "MinAmount is less then "
+ Restrictions.MIN_TRADE_AMOUNT.toFriendlyString());
checkArgument(getAmount().compareTo(Restrictions.MAX_TRADE_AMOUNT) <= 0, "Amount is larger then "
+ Restrictions.MAX_TRADE_AMOUNT.toFriendlyString());
checkArgument(getAmount().compareTo(getPaymentMethod().getMaxTradeLimitInBitcoin()) <= 0, "Amount is larger then "
+ getPaymentMethod().getMaxTradeLimitInBitcoin().toFriendlyString());
checkArgument(getAmount().compareTo(getMinAmount()) >= 0, "MinAmount is larger then Amount");
checkArgument(getPrice().isPositive(), "Price is not a positive value");