Skip to content

Commit

Permalink
support no deposit offers with passphrase
Browse files Browse the repository at this point in the history
  • Loading branch information
woodser committed Dec 15, 2024
1 parent 9ec2794 commit f8a8407
Show file tree
Hide file tree
Showing 113 changed files with 3,813 additions and 805 deletions.
6 changes: 3 additions & 3 deletions apitest/src/test/java/haveno/apitest/method/MethodTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import static haveno.apitest.config.ApiTestConfig.BTC;
import static haveno.apitest.config.ApiTestRateMeterInterceptorConfig.getTestRateMeterInterceptorConfig;
import static haveno.cli.table.builder.TableType.BTC_BALANCE_TBL;
import static haveno.core.xmr.wallet.Restrictions.getDefaultBuyerSecurityDepositAsPercent;
import static haveno.core.xmr.wallet.Restrictions.getDefaultSecurityDepositAsPercent;
import static java.lang.String.format;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Arrays.stream;
Expand Down Expand Up @@ -157,8 +157,8 @@ protected final haveno.core.payment.PaymentAccount createPaymentAccount(GrpcClie
return haveno.core.payment.PaymentAccount.fromProto(paymentAccount, CORE_PROTO_RESOLVER);
}

public static final Supplier<Double> defaultBuyerSecurityDepositPct = () -> {
var defaultPct = BigDecimal.valueOf(getDefaultBuyerSecurityDepositAsPercent());
public static final Supplier<Double> defaultSecurityDepositPct = () -> {
var defaultPct = BigDecimal.valueOf(getDefaultSecurityDepositAsPercent());
if (defaultPct.precision() != 2)
throw new IllegalStateException(format(
"Unexpected decimal precision, expected 2 but actual is %d%n."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class CancelOfferTest extends AbstractOfferTest {
10000000L,
10000000L,
0.00,
defaultBuyerSecurityDepositPct.get(),
defaultSecurityDepositPct.get(),
paymentAccountId,
NO_TRIGGER_PRICE);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void testCreateAUDBTCBuyOfferUsingFixedPrice16000() {
10_000_000L,
10_000_000L,
"36000",
defaultBuyerSecurityDepositPct.get(),
defaultSecurityDepositPct.get(),
audAccount.getId());
log.debug("Offer #1:\n{}", toOfferTable.apply(newOffer));
assertTrue(newOffer.getIsMyOffer());
Expand Down Expand Up @@ -97,7 +97,7 @@ public void testCreateUSDBTCBuyOfferUsingFixedPrice100001234() {
10_000_000L,
10_000_000L,
"30000.1234",
defaultBuyerSecurityDepositPct.get(),
defaultSecurityDepositPct.get(),
usdAccount.getId());
log.debug("Offer #2:\n{}", toOfferTable.apply(newOffer));
assertTrue(newOffer.getIsMyOffer());
Expand Down Expand Up @@ -145,7 +145,7 @@ public void testCreateEURBTCSellOfferUsingFixedPrice95001234() {
10_000_000L,
5_000_000L,
"29500.1234",
defaultBuyerSecurityDepositPct.get(),
defaultSecurityDepositPct.get(),
eurAccount.getId());
log.debug("Offer #3:\n{}", toOfferTable.apply(newOffer));
assertTrue(newOffer.getIsMyOffer());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void testCreateUSDBTCBuyOffer5PctPriceMargin() {
10_000_000L,
10_000_000L,
priceMarginPctInput,
defaultBuyerSecurityDepositPct.get(),
defaultSecurityDepositPct.get(),
usdAccount.getId(),
NO_TRIGGER_PRICE);
log.debug("Offer #1:\n{}", toOfferTable.apply(newOffer));
Expand Down Expand Up @@ -114,7 +114,7 @@ public void testCreateNZDBTCBuyOfferMinus2PctPriceMargin() {
10_000_000L,
10_000_000L,
priceMarginPctInput,
defaultBuyerSecurityDepositPct.get(),
defaultSecurityDepositPct.get(),
nzdAccount.getId(),
NO_TRIGGER_PRICE);
log.debug("Offer #2:\n{}", toOfferTable.apply(newOffer));
Expand Down Expand Up @@ -162,7 +162,7 @@ public void testCreateGBPBTCSellOfferMinus1Point5PctPriceMargin() {
10_000_000L,
5_000_000L,
priceMarginPctInput,
defaultBuyerSecurityDepositPct.get(),
defaultSecurityDepositPct.get(),
gbpAccount.getId(),
NO_TRIGGER_PRICE);
log.debug("Offer #3:\n{}", toOfferTable.apply(newOffer));
Expand Down Expand Up @@ -210,7 +210,7 @@ public void testCreateBRLBTCSellOffer6Point55PctPriceMargin() {
10_000_000L,
5_000_000L,
priceMarginPctInput,
defaultBuyerSecurityDepositPct.get(),
defaultSecurityDepositPct.get(),
brlAccount.getId(),
NO_TRIGGER_PRICE);
log.debug("Offer #4:\n{}", toOfferTable.apply(newOffer));
Expand Down Expand Up @@ -259,7 +259,7 @@ public void testCreateUSDBTCBuyOfferWithTriggerPrice() {
10_000_000L,
5_000_000L,
0.0,
defaultBuyerSecurityDepositPct.get(),
defaultSecurityDepositPct.get(),
usdAccount.getId(),
triggerPrice);
assertTrue(newOffer.getIsMyOffer());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void testCreateFixedPriceBuy1BTCFor200KXMROffer() {
100_000_000L,
75_000_000L,
"0.005", // FIXED PRICE IN BTC FOR 1 XMR
defaultBuyerSecurityDepositPct.get(),
defaultSecurityDepositPct.get(),
alicesXmrAcct.getId());
log.debug("Sell XMR (Buy BTC) offer:\n{}", toOfferTable.apply(newOffer));
assertTrue(newOffer.getIsMyOffer());
Expand Down Expand Up @@ -108,7 +108,7 @@ public void testCreateFixedPriceSell1BTCFor200KXMROffer() {
100_000_000L,
50_000_000L,
"0.005", // FIXED PRICE IN BTC (satoshis) FOR 1 XMR
defaultBuyerSecurityDepositPct.get(),
defaultSecurityDepositPct.get(),
alicesXmrAcct.getId());
log.debug("Buy XMR (Sell BTC) offer:\n{}", toOfferTable.apply(newOffer));
assertTrue(newOffer.getIsMyOffer());
Expand Down Expand Up @@ -156,7 +156,7 @@ public void testCreatePriceMarginBasedBuy1BTCOfferWithTriggerPrice() {
100_000_000L,
75_000_000L,
priceMarginPctInput,
defaultBuyerSecurityDepositPct.get(),
defaultSecurityDepositPct.get(),
alicesXmrAcct.getId(),
triggerPrice);
log.debug("Pending Sell XMR (Buy BTC) offer:\n{}", toOfferTable.apply(newOffer));
Expand Down Expand Up @@ -211,7 +211,7 @@ public void testCreatePriceMarginBasedSell1BTCOffer() {
100_000_000L,
50_000_000L,
priceMarginPctInput,
defaultBuyerSecurityDepositPct.get(),
defaultSecurityDepositPct.get(),
alicesXmrAcct.getId(),
NO_TRIGGER_PRICE);
log.debug("Buy XMR (Sell BTC) offer:\n{}", toOfferTable.apply(newOffer));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void testAmtTooLargeShouldThrowException() {
100000000000L, // exceeds amount limit
100000000000L,
"10000.0000",
defaultBuyerSecurityDepositPct.get(),
defaultSecurityDepositPct.get(),
usdAccount.getId()));
assertEquals("UNKNOWN: An error occurred at task: ValidateOffer", exception.getMessage());
}
Expand All @@ -63,7 +63,7 @@ public void testNoMatchingEURPaymentAccountShouldThrowException() {
10000000L,
10000000L,
"40000.0000",
defaultBuyerSecurityDepositPct.get(),
defaultSecurityDepositPct.get(),
chfAccount.getId()));
String expectedError = format("UNKNOWN: cannot create EUR offer with payment account %s", chfAccount.getId());
assertEquals(expectedError, exception.getMessage());
Expand All @@ -80,7 +80,7 @@ public void testNoMatchingCADPaymentAccountShouldThrowException() {
10000000L,
10000000L,
"63000.0000",
defaultBuyerSecurityDepositPct.get(),
defaultSecurityDepositPct.get(),
audAccount.getId()));
String expectedError = format("UNKNOWN: cannot create CAD offer with payment account %s", audAccount.getId());
assertEquals(expectedError, exception.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void testTakeAlicesBuyOffer(final TestInfo testInfo) {
12_500_000L,
12_500_000L, // min-amount = amount
0.00,
defaultBuyerSecurityDepositPct.get(),
defaultSecurityDepositPct.get(),
alicesUsdAccount.getId(),
NO_TRIGGER_PRICE);
var offerId = alicesOffer.getId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void testTakeAlicesBuyOffer(final TestInfo testInfo) {
1_000_000L,
1_000_000L, // min-amount = amount
0.00,
defaultBuyerSecurityDepositPct.get(),
defaultSecurityDepositPct.get(),
alicesPaymentAccount.getId(),
NO_TRIGGER_PRICE);
var offerId = alicesOffer.getId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void testTakeAlicesSellBTCForXMROffer(final TestInfo testInfo) {
15_000_000L,
7_500_000L,
"0.00455500", // FIXED PRICE IN BTC (satoshis) FOR 1 XMR
defaultBuyerSecurityDepositPct.get(),
defaultSecurityDepositPct.get(),
alicesXmrAcct.getId());
log.debug("Alice's BUY XMR (SELL BTC) Offer:\n{}", new TableBuilder(OFFER_TBL, alicesOffer).build());
genBtcBlocksThenWait(1, 5000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void testTakeAlicesSellOffer(final TestInfo testInfo) {
12_500_000L,
12_500_000L, // min-amount = amount
0.00,
defaultBuyerSecurityDepositPct.get(),
defaultSecurityDepositPct.get(),
alicesUsdAccount.getId(),
NO_TRIGGER_PRICE);
var offerId = alicesOffer.getId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void testTakeAlicesBuyBTCForXMROffer(final TestInfo testInfo) {
20_000_000L,
10_500_000L,
priceMarginPctInput,
defaultBuyerSecurityDepositPct.get(),
defaultSecurityDepositPct.get(),
alicesXmrAcct.getId(),
NO_TRIGGER_PRICE);
log.debug("Alice's SELL XMR (BUY BTC) Offer:\n{}", new TableBuilder(OFFER_TBL, alicesOffer).build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void testSellOfferAutoDisable(final TestInfo testInfo) {
1_000_000,
1_000_000,
0.00,
defaultBuyerSecurityDepositPct.get(),
defaultSecurityDepositPct.get(),
paymentAcct.getId(),
triggerPrice);
log.info("SELL offer {} created with margin based price {}.",
Expand Down Expand Up @@ -103,7 +103,7 @@ public void testBuyOfferAutoDisable(final TestInfo testInfo) {
1_000_000,
1_000_000,
0.00,
defaultBuyerSecurityDepositPct.get(),
defaultSecurityDepositPct.get(),
paymentAcct.getId(),
triggerPrice);
log.info("BUY offer {} created with margin based price {}.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import java.util.Objects;
import java.util.function.Supplier;

import static haveno.apitest.method.offer.AbstractOfferTest.defaultBuyerSecurityDepositPct;
import static haveno.apitest.method.offer.AbstractOfferTest.defaultSecurityDepositPct;
import static haveno.cli.CurrencyFormat.formatInternalFiatPrice;
import static haveno.cli.CurrencyFormat.formatSatoshis;
import static haveno.common.util.MathUtils.scaleDownByPowerOf10;
Expand Down Expand Up @@ -119,7 +119,7 @@ public RandomOffer create() throws InvalidRandomOfferException {
amount,
minAmount,
priceMargin,
defaultBuyerSecurityDepositPct.get(),
defaultSecurityDepositPct.get(),
"0" /*no trigger price*/);
} else {
this.offer = botClient.createOfferAtFixedPrice(paymentAccount,
Expand All @@ -128,7 +128,7 @@ public RandomOffer create() throws InvalidRandomOfferException {
amount,
minAmount,
fixedOfferPrice,
defaultBuyerSecurityDepositPct.get());
defaultSecurityDepositPct.get());
}
this.id = offer.getId();
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public OfferInfo createOffer(String direction,
.setUseMarketBasedPrice(useMarketBasedPrice)
.setPrice(fixedPrice)
.setMarketPriceMarginPct(marketPriceMarginPct)
.setBuyerSecurityDepositPct(securityDepositPct)
.setSecurityDepositPct(securityDepositPct)
.setPaymentAccountId(paymentAcctId)
.setTriggerPrice(triggerPrice)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import haveno.core.offer.OfferRestrictions;
import haveno.core.payment.ChargeBackRisk;
import haveno.core.payment.PaymentAccount;
import haveno.core.payment.TradeLimits;
import haveno.core.payment.payload.PaymentAccountPayload;
import haveno.core.payment.payload.PaymentMethod;
import haveno.core.support.dispute.Dispute;
Expand Down Expand Up @@ -498,10 +499,15 @@ public long getMyAccountAge(PaymentAccountPayload paymentAccountPayload) {
return getAccountAge(getMyWitness(paymentAccountPayload), new Date());
}

public long getMyTradeLimit(PaymentAccount paymentAccount, String currencyCode, OfferDirection direction) {
public long getMyTradeLimit(PaymentAccount paymentAccount, String currencyCode, OfferDirection direction, boolean buyerAsTakerWithoutDeposit) {
if (paymentAccount == null)
return 0;

if (buyerAsTakerWithoutDeposit) {
TradeLimits tradeLimits = new TradeLimits();
return tradeLimits.getMaxTradeLimitBuyerAsTakerWithoutDeposit().longValueExact();
}

AccountAgeWitness accountAgeWitness = getMyWitness(paymentAccount.getPaymentAccountPayload());
BigInteger maxTradeLimit = paymentAccount.getPaymentMethod().getMaxTradeLimit(currencyCode);
if (hasTradeLimitException(accountAgeWitness)) {
Expand Down
22 changes: 16 additions & 6 deletions core/src/main/java/haveno/core/api/CoreApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -419,10 +419,12 @@ public void postOffer(String currencyCode,
double marketPriceMargin,
long amountAsLong,
long minAmountAsLong,
double buyerSecurityDeposit,
double securityDepositPct,
String triggerPriceAsString,
boolean reserveExactAmount,
String paymentAccountId,
boolean isPrivateOffer,
boolean buyerAsTakerWithoutDeposit,
Consumer<Offer> resultHandler,
ErrorMessageHandler errorMessageHandler) {
coreOffersService.postOffer(currencyCode,
Expand All @@ -432,10 +434,12 @@ public void postOffer(String currencyCode,
marketPriceMargin,
amountAsLong,
minAmountAsLong,
buyerSecurityDeposit,
securityDepositPct,
triggerPriceAsString,
reserveExactAmount,
paymentAccountId,
isPrivateOffer,
buyerAsTakerWithoutDeposit,
resultHandler,
errorMessageHandler);
}
Expand All @@ -448,8 +452,10 @@ public Offer editOffer(String offerId,
double marketPriceMargin,
BigInteger amount,
BigInteger minAmount,
double buyerSecurityDeposit,
PaymentAccount paymentAccount) {
double securityDepositPct,
PaymentAccount paymentAccount,
boolean isPrivateOffer,
boolean buyerAsTakerWithoutDeposit) {
return coreOffersService.editOffer(offerId,
currencyCode,
direction,
Expand All @@ -458,8 +464,10 @@ public Offer editOffer(String offerId,
marketPriceMargin,
amount,
minAmount,
buyerSecurityDeposit,
paymentAccount);
securityDepositPct,
paymentAccount,
isPrivateOffer,
buyerAsTakerWithoutDeposit);
}

public void cancelOffer(String id, ResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) {
Expand Down Expand Up @@ -535,9 +543,11 @@ public MarketDepthInfo getMarketDepth(String currencyCode) throws ExecutionExcep
public void takeOffer(String offerId,
String paymentAccountId,
long amountAsLong,
String challenge,
Consumer<Trade> resultHandler,
ErrorMessageHandler errorMessageHandler) {
Offer offer = coreOffersService.getOffer(offerId);
offer.setChallenge(challenge);
coreTradesService.takeOffer(offer, paymentAccountId, amountAsLong, resultHandler, errorMessageHandler);
}

Expand Down
Loading

0 comments on commit f8a8407

Please sign in to comment.