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

set buyer and seller payout tx fee and amount, fix csv export #720 #728

Merged
merged 10 commits into from
Dec 10, 2023
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ configure(project(':desktop')) {
apply plugin: 'com.github.johnrengelman.shadow'
apply from: 'package/package.gradle'

version = '1.0.15-SNAPSHOT'
version = '1.0.16-SNAPSHOT'

jar.manifest.attributes(
"Implementation-Title": project.name,
Expand Down
2 changes: 1 addition & 1 deletion common/src/main/java/haveno/common/app/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
public class Version {
// The application versions
// We use semantic versioning with major, minor and patch
public static final String VERSION = "1.0.15";
public static final String VERSION = "1.0.16";

/**
* Holds a list of the tagged resource files for optimizing the getData requests.
Expand Down
43 changes: 16 additions & 27 deletions core/src/main/java/haveno/core/api/CoreDisputesService.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,6 @@ public void resolveDispute(String tradeId, DisputeResult.Winner winner, DisputeR
}
applyPayoutAmountsToDisputeResult(payout, winningDispute, winnerDisputeResult, customWinnerAmount);

// create dispute payout tx
trade.getProcessModel().setUnsignedPayoutTx(arbitrationManager.createDisputePayoutTx(trade, winningDispute.getContract(), winnerDisputeResult, false));

// close winning dispute ticket
closeDisputeTicket(arbitrationManager, winningDispute, winnerDisputeResult, () -> {
arbitrationManager.requestPersistence();
Expand All @@ -180,8 +177,8 @@ public void resolveDispute(String tradeId, DisputeResult.Winner winner, DisputeR
if (!loserDisputeOptional.isPresent()) throw new IllegalStateException("could not find peer dispute");
var loserDispute = loserDisputeOptional.get();
var loserDisputeResult = createDisputeResult(loserDispute, winner, reason, summaryNotes, closeDate);
loserDisputeResult.setBuyerPayoutAmount(winnerDisputeResult.getBuyerPayoutAmount());
loserDisputeResult.setSellerPayoutAmount(winnerDisputeResult.getSellerPayoutAmount());
loserDisputeResult.setBuyerPayoutAmountBeforeCost(winnerDisputeResult.getBuyerPayoutAmountBeforeCost());
loserDisputeResult.setSellerPayoutAmountBeforeCost(winnerDisputeResult.getSellerPayoutAmountBeforeCost());
loserDisputeResult.setSubtractFeeFrom(winnerDisputeResult.getSubtractFeeFrom());
closeDisputeTicket(arbitrationManager, loserDispute, loserDisputeResult, () -> {
arbitrationManager.requestPersistence();
Expand Down Expand Up @@ -217,31 +214,23 @@ public void applyPayoutAmountsToDisputeResult(DisputePayout payout, Dispute disp
BigInteger tradeAmount = contract.getTradeAmount();
disputeResult.setSubtractFeeFrom(DisputeResult.SubtractFeeFrom.BUYER_AND_SELLER);
if (payout == DisputePayout.BUYER_GETS_TRADE_AMOUNT) {
disputeResult.setBuyerPayoutAmount(tradeAmount.add(buyerSecurityDeposit));
disputeResult.setSellerPayoutAmount(sellerSecurityDeposit);
disputeResult.setBuyerPayoutAmountBeforeCost(tradeAmount.add(buyerSecurityDeposit));
disputeResult.setSellerPayoutAmountBeforeCost(sellerSecurityDeposit);
} else if (payout == DisputePayout.BUYER_GETS_ALL) {
disputeResult.setBuyerPayoutAmount(tradeAmount
.add(buyerSecurityDeposit)
.add(sellerSecurityDeposit)); // TODO (woodser): apply min payout to incentivize loser? (see post v1.1.7)
disputeResult.setSellerPayoutAmount(BigInteger.valueOf(0));
disputeResult.setBuyerPayoutAmountBeforeCost(tradeAmount.add(buyerSecurityDeposit).add(sellerSecurityDeposit)); // TODO (woodser): apply min payout to incentivize loser? (see post v1.1.7)
disputeResult.setSellerPayoutAmountBeforeCost(BigInteger.ZERO);
} else if (payout == DisputePayout.SELLER_GETS_TRADE_AMOUNT) {
disputeResult.setBuyerPayoutAmount(buyerSecurityDeposit);
disputeResult.setSellerPayoutAmount(tradeAmount.add(sellerSecurityDeposit));
disputeResult.setBuyerPayoutAmountBeforeCost(buyerSecurityDeposit);
disputeResult.setSellerPayoutAmountBeforeCost(tradeAmount.add(sellerSecurityDeposit));
} else if (payout == DisputePayout.SELLER_GETS_ALL) {
disputeResult.setBuyerPayoutAmount(BigInteger.valueOf(0));
disputeResult.setSellerPayoutAmount(tradeAmount
.add(sellerSecurityDeposit)
.add(buyerSecurityDeposit));
disputeResult.setBuyerPayoutAmountBeforeCost(BigInteger.ZERO);
disputeResult.setSellerPayoutAmountBeforeCost(tradeAmount.add(sellerSecurityDeposit).add(buyerSecurityDeposit));
} else if (payout == DisputePayout.CUSTOM) {
if (customWinnerAmount > trade.getWallet().getBalance().longValueExact()) {
throw new RuntimeException("Winner payout is more than the trade wallet's balance");
}
if (customWinnerAmount > trade.getWallet().getBalance().longValueExact()) throw new RuntimeException("Winner payout is more than the trade wallet's balance");
long loserAmount = tradeAmount.add(buyerSecurityDeposit).add(sellerSecurityDeposit).subtract(BigInteger.valueOf(customWinnerAmount)).longValueExact();
if (loserAmount < 0) {
throw new RuntimeException("Loser payout cannot be negative");
}
disputeResult.setBuyerPayoutAmount(BigInteger.valueOf(disputeResult.getWinner() == DisputeResult.Winner.BUYER ? customWinnerAmount : loserAmount));
disputeResult.setSellerPayoutAmount(BigInteger.valueOf(disputeResult.getWinner() == DisputeResult.Winner.BUYER ? loserAmount : customWinnerAmount));
if (loserAmount < 0) throw new RuntimeException("Loser payout cannot be negative");
disputeResult.setBuyerPayoutAmountBeforeCost(BigInteger.valueOf(disputeResult.getWinner() == DisputeResult.Winner.BUYER ? customWinnerAmount : loserAmount));
disputeResult.setSellerPayoutAmountBeforeCost(BigInteger.valueOf(disputeResult.getWinner() == DisputeResult.Winner.BUYER ? loserAmount : customWinnerAmount));
disputeResult.setSubtractFeeFrom(disputeResult.getWinner() == DisputeResult.Winner.BUYER ? SubtractFeeFrom.SELLER_ONLY : SubtractFeeFrom.BUYER_ONLY); // winner gets exact amount, loser pays mining fee
}
}
Expand All @@ -263,8 +252,8 @@ public void closeDisputeTicket(DisputeManager disputeManager, Dispute dispute, D
currencyCode,
Res.get("disputeSummaryWindow.reason." + reason.name()),
amount,
HavenoUtils.formatXmr(disputeResult.getBuyerPayoutAmount(), true),
HavenoUtils.formatXmr(disputeResult.getSellerPayoutAmount(), true),
HavenoUtils.formatXmr(disputeResult.getBuyerPayoutAmountBeforeCost(), true),
HavenoUtils.formatXmr(disputeResult.getSellerPayoutAmountBeforeCost(), true),
disputeResult.summaryNotesProperty().get()
);

Expand Down
37 changes: 37 additions & 0 deletions core/src/main/java/haveno/core/api/model/TradeInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ public class TradeInfo implements Payload {
private final long amount;
private final long buyerSecurityDeposit;
private final long sellerSecurityDeposit;
private final long buyerDepositTxFee;
private final long sellerDepositTxFee;
private final long buyerPayoutTxFee;
private final long sellerPayoutTxFee;
private final long buyerPayoutAmount;
private final long sellerPayoutAmount;
private final String price;
private final String volume;
private final String arbitratorNodeAddress;
Expand Down Expand Up @@ -105,6 +111,12 @@ public TradeInfo(TradeInfoV1Builder builder) {
this.amount = builder.getAmount();
this.buyerSecurityDeposit = builder.getBuyerSecurityDeposit();
this.sellerSecurityDeposit = builder.getSellerSecurityDeposit();
this.buyerDepositTxFee = builder.getBuyerDepositTxFee();
this.sellerDepositTxFee = builder.getSellerDepositTxFee();
this.buyerPayoutTxFee = builder.getBuyerPayoutTxFee();
this.sellerPayoutTxFee = builder.getSellerPayoutTxFee();
this.buyerPayoutAmount = builder.getBuyerPayoutAmount();
this.sellerPayoutAmount = builder.getSellerPayoutAmount();
this.price = builder.getPrice();
this.volume = builder.getVolume();
this.arbitratorNodeAddress = builder.getArbitratorNodeAddress();
Expand Down Expand Up @@ -161,6 +173,13 @@ public static TradeInfo toTradeInfo(Trade trade, String role) {
.withAmount(trade.getAmount().longValueExact())
.withBuyerSecurityDeposit(trade.getBuyer().getSecurityDeposit() == null ? -1 : trade.getBuyer().getSecurityDeposit().longValueExact())
.withSellerSecurityDeposit(trade.getSeller().getSecurityDeposit() == null ? -1 : trade.getSeller().getSecurityDeposit().longValueExact())
.withBuyerDepositTxFee(trade.getBuyer().getDepositTxFee() == null ? -1 : trade.getBuyer().getDepositTxFee().longValueExact())
.withSellerDepositTxFee(trade.getSeller().getDepositTxFee() == null ? -1 : trade.getSeller().getDepositTxFee().longValueExact())
.withBuyerPayoutTxFee(trade.getBuyer().getPayoutTxFee() == null ? -1 : trade.getBuyer().getPayoutTxFee().longValueExact())
.withSellerPayoutTxFee(trade.getSeller().getPayoutTxFee() == null ? -1 : trade.getSeller().getPayoutTxFee().longValueExact())
.withBuyerPayoutAmount(trade.getBuyer().getPayoutAmount() == null ? -1 : trade.getBuyer().getPayoutAmount().longValueExact())
.withSellerPayoutAmount(trade.getSeller().getPayoutAmount() == null ? -1 : trade.getSeller().getPayoutAmount().longValueExact())
.withTotalTxFee(trade.getTotalTxFee().longValueExact())
.withPrice(toPreciseTradePrice.apply(trade))
.withVolume(toRoundedVolume.apply(trade))
.withArbitratorNodeAddress(toArbitratorNodeAddress.apply(trade))
Expand Down Expand Up @@ -204,6 +223,12 @@ public haveno.proto.grpc.TradeInfo toProtoMessage() {
.setAmount(amount)
.setBuyerSecurityDeposit(buyerSecurityDeposit)
.setSellerSecurityDeposit(sellerSecurityDeposit)
.setBuyerDepositTxFee(buyerDepositTxFee)
.setSellerDepositTxFee(sellerDepositTxFee)
.setBuyerPayoutTxFee(buyerPayoutTxFee)
.setSellerPayoutTxFee(sellerPayoutTxFee)
.setBuyerPayoutAmount(buyerPayoutAmount)
.setSellerPayoutAmount(sellerPayoutAmount)
.setPrice(price)
.setTradeVolume(volume)
.setArbitratorNodeAddress(arbitratorNodeAddress)
Expand Down Expand Up @@ -241,6 +266,12 @@ public static TradeInfo fromProto(haveno.proto.grpc.TradeInfo proto) {
.withAmount(proto.getAmount())
.withBuyerSecurityDeposit(proto.getBuyerSecurityDeposit())
.withSellerSecurityDeposit(proto.getSellerSecurityDeposit())
.withBuyerDepositTxFee(proto.getBuyerDepositTxFee())
.withSellerDepositTxFee(proto.getSellerDepositTxFee())
.withBuyerPayoutTxFee(proto.getBuyerPayoutTxFee())
.withSellerPayoutTxFee(proto.getSellerPayoutTxFee())
.withBuyerPayoutAmount(proto.getBuyerPayoutAmount())
.withSellerPayoutAmount(proto.getSellerPayoutAmount())
.withPrice(proto.getPrice())
.withVolume(proto.getTradeVolume())
.withPeriodState(proto.getPeriodState())
Expand Down Expand Up @@ -278,6 +309,12 @@ public String toString() {
", amount='" + amount + '\'' + "\n" +
", buyerSecurityDeposit='" + buyerSecurityDeposit + '\'' + "\n" +
", sellerSecurityDeposit='" + sellerSecurityDeposit + '\'' + "\n" +
", buyerDepositTxFee='" + buyerDepositTxFee + '\'' + "\n" +
", sellerDepositTxFee='" + sellerDepositTxFee + '\'' + "\n" +
", buyerPayoutTxFee='" + buyerPayoutTxFee + '\'' + "\n" +
", sellerPayoutTxFee='" + sellerPayoutTxFee + '\'' + "\n" +
", buyerPayoutAmount='" + buyerPayoutAmount + '\'' + "\n" +
", sellerPayoutAmount='" + sellerPayoutAmount + '\'' + "\n" +
", price='" + price + '\'' + "\n" +
", arbitratorNodeAddress='" + arbitratorNodeAddress + '\'' + "\n" +
", tradePeerNodeAddress='" + tradePeerNodeAddress + '\'' + "\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ public final class TradeInfoV1Builder {
private long takerFee;
private long buyerSecurityDeposit;
private long sellerSecurityDeposit;
private long buyerDepositTxFee;
private long sellerDepositTxFee;
private long buyerPayoutTxFee;
private long sellerPayoutTxFee;
private long buyerPayoutAmount;
private long sellerPayoutAmount;
private String makerDepositTxId;
private String takerDepositTxId;
private String payoutTxId;
Expand Down Expand Up @@ -117,6 +123,36 @@ public TradeInfoV1Builder withSellerSecurityDeposit(long sellerSecurityDeposit)
return this;
}

public TradeInfoV1Builder withBuyerDepositTxFee(long buyerDepositTxFee) {
this.buyerDepositTxFee = buyerDepositTxFee;
return this;
}

public TradeInfoV1Builder withSellerDepositTxFee(long sellerDepositTxFee) {
this.sellerDepositTxFee = sellerDepositTxFee;
return this;
}

public TradeInfoV1Builder withBuyerPayoutTxFee(long buyerPayoutTxFee) {
this.buyerPayoutTxFee = buyerPayoutTxFee;
return this;
}

public TradeInfoV1Builder withSellerPayoutTxFee(long sellerPayoutTxFee) {
this.sellerPayoutTxFee = sellerPayoutTxFee;
return this;
}

public TradeInfoV1Builder withBuyerPayoutAmount(long buyerPayoutAmount) {
this.buyerPayoutAmount = buyerPayoutAmount;
return this;
}

public TradeInfoV1Builder withSellerPayoutAmount(long sellerPayoutAmount) {
this.sellerPayoutAmount = sellerPayoutAmount;
return this;
}

public TradeInfoV1Builder withMakerDepositTxId(String makerDepositTxId) {
this.makerDepositTxId = makerDepositTxId;
return this;
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/haveno/core/app/WalletAppSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void init(@Nullable Consumer<String> chainFileLockedExceptionHandler,
Long bestWalletHeight = walletHeight == null ? null : (Long) walletHeight;
String walletHeightAsString = bestWalletHeight != null && bestWalletHeight > 0 ? String.valueOf(bestWalletHeight) : "";
if (walletDownloadPercentageD == 1) {
String synchronizedWith = Res.get("mainView.footer.xmrInfo.synchronizedWalletWith", getXmrWalletNetworkAsString(), walletHeightAsString);
String synchronizedWith = Res.get("mainView.footer.xmrInfo.syncedWith", getXmrWalletNetworkAsString(), walletHeightAsString);
String feeInfo = ""; // TODO: feeService.isFeeAvailable() returns true, disable
result = Res.get("mainView.footer.xmrInfo", synchronizedWith, feeInfo);
getXmrSplashSyncIconId().set("image-connection-synced");
Expand All @@ -142,12 +142,12 @@ void init(@Nullable Consumer<String> chainFileLockedExceptionHandler,
Long bestChainHeight = chainHeight == null ? null : (Long) chainHeight;
String chainHeightAsString = bestChainHeight != null && bestChainHeight > 0 ? String.valueOf(bestChainHeight) : "";
if (chainDownloadPercentageD == 1) {
String synchronizedWith = Res.get("mainView.footer.xmrInfo.synchronizedDaemonWith", getXmrDaemonNetworkAsString(), chainHeightAsString);
String synchronizedWith = Res.get("mainView.footer.xmrInfo.syncedWith", getXmrDaemonNetworkAsString(), chainHeightAsString);
String feeInfo = ""; // TODO: feeService.isFeeAvailable() returns true, disable
result = Res.get("mainView.footer.xmrInfo", synchronizedWith, feeInfo);
getXmrSplashSyncIconId().set("image-connection-synced");
} else if (chainDownloadPercentageD > 0.0) {
String synchronizingWith = Res.get("mainView.footer.xmrInfo.synchronizingDaemonWith", getXmrDaemonNetworkAsString(), chainHeightAsString, FormattingUtils.formatToRoundedPercentWithSymbol(chainDownloadPercentageD));
String synchronizingWith = Res.get("mainView.footer.xmrInfo.synchronizingWith", getXmrDaemonNetworkAsString(), chainHeightAsString, FormattingUtils.formatToRoundedPercentWithSymbol(chainDownloadPercentageD));
result = Res.get("mainView.footer.xmrInfo", synchronizingWith, "");
} else {
result = Res.get("mainView.footer.xmrInfo",
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/haveno/core/monetary/Price.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public BigInteger getAmountByVolume(Volume volume) {
else if (monetary instanceof CryptoMoney && this.monetary instanceof CryptoMoney)
return HavenoUtils.coinToAtomicUnits(new CryptoExchangeRate((CryptoMoney) this.monetary).cryptoToCoin((CryptoMoney) monetary));
else
return BigInteger.valueOf(0);
return BigInteger.ZERO;
}

public String getCurrencyCode() {
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/haveno/core/offer/OfferUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ public boolean isBalanceSufficient(BigInteger cost, BigInteger balance) {
public BigInteger getBalanceShortage(BigInteger cost, BigInteger balance) {
if (cost != null) {
BigInteger shortage = cost.subtract(balance);
return shortage.compareTo(BigInteger.valueOf(0)) < 0 ? BigInteger.valueOf(0) : shortage;
return shortage.compareTo(BigInteger.ZERO) < 0 ? BigInteger.ZERO : shortage;
} else {
return BigInteger.valueOf(0);
return BigInteger.ZERO;
}
}

Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/haveno/core/offer/OpenOfferManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@ private void scheduleWithEarliestTxs(List<OpenOffer> openOffers, OpenOffer openO

// get earliest unscheduled txs with sufficient incoming amount
List<String> scheduledTxHashes = new ArrayList<String>();
BigInteger scheduledAmount = BigInteger.valueOf(0);
BigInteger scheduledAmount = BigInteger.ZERO;
for (MoneroTxWallet lockedTx : lockedTxs) {
if (isTxScheduled(openOffers, lockedTx.getHash())) continue;
if (lockedTx.getIncomingTransfers() == null || lockedTx.getIncomingTransfers().isEmpty()) continue;
Expand All @@ -1048,7 +1048,7 @@ private void scheduleWithEarliestTxs(List<OpenOffer> openOffers, OpenOffer openO
}

private BigInteger getScheduledAmount(List<OpenOffer> openOffers) {
BigInteger scheduledAmount = BigInteger.valueOf(0);
BigInteger scheduledAmount = BigInteger.ZERO;
for (OpenOffer openOffer : openOffers) {
if (openOffer.getState() != OpenOffer.State.SCHEDULED) continue;
if (openOffer.getScheduledTxHashes() == null) continue;
Expand Down Expand Up @@ -1178,7 +1178,7 @@ private void handleSignOfferRequest(SignOfferRequest request, NodeAddress peer)
}

// verify maker's reserve tx (double spend, trade fee, trade amount, mining fee)
BigInteger sendAmount = offer.getDirection() == OfferDirection.BUY ? BigInteger.valueOf(0) : offer.getAmount();
BigInteger sendAmount = offer.getDirection() == OfferDirection.BUY ? BigInteger.ZERO : offer.getAmount();
BigInteger securityDeposit = offer.getDirection() == OfferDirection.BUY ? offer.getMaxBuyerSecurityDeposit() : offer.getMaxSellerSecurityDeposit();
Tuple2<MoneroTx, BigInteger> txResult = xmrWalletService.verifyTradeTx(
offer.getId(),
Expand Down
Loading
Loading