mirror of
https://github.com/haveno-dex/haveno.git
synced 2024-10-01 01:35:48 -04:00
fix adjustment < min amount creating offers
This commit is contained in:
parent
4f5f82bf0f
commit
f261a38cce
@ -47,7 +47,7 @@ public class CoinUtil {
|
||||
|
||||
public static double getFeePerVbyte(Coin miningFee, int txVsize) {
|
||||
double value = miningFee != null ? miningFee.value : 0;
|
||||
return MathUtils.roundDouble((value / (double) txVsize), 2);
|
||||
return MathUtils.roundDouble((value / txVsize), 2);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -127,8 +127,8 @@ public class CoinUtil {
|
||||
@VisibleForTesting
|
||||
static BigInteger getAdjustedAmount(BigInteger amount, Price price, long maxTradeLimit, int factor) {
|
||||
checkArgument(
|
||||
amount.longValueExact() >= HavenoUtils.xmrToAtomicUnits(0.0001).longValueExact(),
|
||||
"amount needs to be above minimum of 0.0001 xmr" // TODO: update amount for XMR
|
||||
amount.longValueExact() >= Restrictions.getMinTradeAmount().longValueExact(),
|
||||
"amount needs to be above minimum of " + HavenoUtils.atomicUnitsToXmr(Restrictions.getMinTradeAmount()) + " xmr"
|
||||
);
|
||||
checkArgument(
|
||||
factor > 0,
|
||||
@ -143,10 +143,9 @@ public class CoinUtil {
|
||||
BigInteger smallestUnitForAmount = price.getAmountByVolume(smallestUnitForVolume);
|
||||
long minTradeAmount = Restrictions.getMinTradeAmount().longValueExact();
|
||||
|
||||
// We use 10 000 satoshi as min allowed amount
|
||||
checkArgument(
|
||||
minTradeAmount >= HavenoUtils.xmrToAtomicUnits(0.0001).longValueExact(),
|
||||
"MinTradeAmount must be at least 0.0001 xmr" // TODO: update amount for XMR
|
||||
minTradeAmount >= Restrictions.getMinTradeAmount().longValueExact(),
|
||||
"MinTradeAmount must be at least " + HavenoUtils.atomicUnitsToXmr(Restrictions.getMinTradeAmount()) + " xmr"
|
||||
);
|
||||
smallestUnitForAmount = BigInteger.valueOf(Math.max(minTradeAmount, smallestUnitForAmount.longValueExact()));
|
||||
// We don't allow smaller amount values than smallestUnitForAmount
|
||||
@ -164,8 +163,7 @@ public class CoinUtil {
|
||||
BigInteger amountByVolume = price.getAmountByVolume(volume);
|
||||
|
||||
// For the amount we allow only 4 decimal places
|
||||
// TODO: remove rounding for XMR?
|
||||
long adjustedAmount = HavenoUtils.centinerosToAtomicUnits(Math.round((double) HavenoUtils.atomicUnitsToCentineros(amountByVolume) / 10000d) * 10000).longValueExact();
|
||||
long adjustedAmount = HavenoUtils.centinerosToAtomicUnits(Math.round(HavenoUtils.atomicUnitsToCentineros(amountByVolume) / 10000d) * 10000).longValueExact();
|
||||
|
||||
// If we are above our trade limit we reduce the amount by the smallestUnitForAmount
|
||||
while (adjustedAmount > maxTradeLimit) {
|
||||
|
@ -59,7 +59,7 @@ public class CoinUtilTest {
|
||||
@Test
|
||||
public void testGetAdjustedAmount() {
|
||||
BigInteger result = CoinUtil.getAdjustedAmount(
|
||||
HavenoUtils.xmrToAtomicUnits(0.001),
|
||||
HavenoUtils.xmrToAtomicUnits(0.1),
|
||||
Price.valueOf("USD", 1000_0000),
|
||||
HavenoUtils.xmrToAtomicUnits(0.2).longValueExact(),
|
||||
1);
|
||||
@ -78,7 +78,7 @@ public class CoinUtilTest {
|
||||
fail("Expected IllegalArgumentException to be thrown when amount is too low.");
|
||||
} catch (IllegalArgumentException iae) {
|
||||
assertEquals(
|
||||
"amount needs to be above minimum of 0.0001 xmr",
|
||||
"amount needs to be above minimum of 0.1 xmr",
|
||||
iae.getMessage(),
|
||||
"Unexpected exception message."
|
||||
);
|
||||
@ -112,7 +112,7 @@ public class CoinUtilTest {
|
||||
// 0.05 USD worth, which is below the factor of 1 USD, but does respect the maxTradeLimit.
|
||||
// Basically the given constraints (maxTradeLimit vs factor) are impossible to both fulfill..
|
||||
result = CoinUtil.getAdjustedAmount(
|
||||
HavenoUtils.xmrToAtomicUnits(0.001),
|
||||
HavenoUtils.xmrToAtomicUnits(0.1),
|
||||
Price.valueOf("USD", 1000_0000),
|
||||
HavenoUtils.xmrToAtomicUnits(0.00005).longValueExact(),
|
||||
1);
|
||||
|
@ -524,6 +524,7 @@ public abstract class MutableOfferDataModel extends OfferDataModel {
|
||||
// if the volume != amount * price, we need to adjust the amount
|
||||
if (amount.get() == null || !volumeBefore.equals(price.get().getVolumeByAmount(amount.get()))) {
|
||||
BigInteger value = price.get().getAmountByVolume(volumeBefore);
|
||||
value = value.max(Restrictions.getMinTradeAmount()); // adjust if below minimum
|
||||
value = CoinUtil.getRoundedAmount(value, price.get(), getMaxTradeLimit(), tradeCurrencyCode.get(), paymentAccount.getPaymentMethod().getId());
|
||||
amount.set(value);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user