reduce penalty fee to trade fee

This commit is contained in:
woodser 2023-08-15 15:44:15 -04:00
parent f112760432
commit 20f26ea623
4 changed files with 17 additions and 20 deletions

View File

@ -1168,8 +1168,7 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
request.getReserveTxHash(), request.getReserveTxHash(),
request.getReserveTxHex(), request.getReserveTxHex(),
request.getReserveTxKey(), request.getReserveTxKey(),
request.getReserveTxKeyImages(), request.getReserveTxKeyImages());
true);
// arbitrator signs offer to certify they have valid reserve tx // arbitrator signs offer to certify they have valid reserve tx
byte[] signature = HavenoUtils.signOffer(request.getOfferPayload(), keyRing); byte[] signature = HavenoUtils.signOffer(request.getOfferPayload(), keyRing);
@ -1182,7 +1181,7 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
signedOfferPayload.getPubKeyRing().hashCode(), // trader id signedOfferPayload.getPubKeyRing().hashCode(), // trader id
signedOfferPayload.getId(), signedOfferPayload.getId(),
offer.getAmount().longValueExact(), offer.getAmount().longValueExact(),
txResult.second.longValueExact(), tradeFee.longValueExact(),
request.getReserveTxHash(), request.getReserveTxHash(),
request.getReserveTxHex(), request.getReserveTxHex(),
request.getReserveTxKeyImages(), request.getReserveTxKeyImages(),

View File

@ -96,8 +96,7 @@ public class ArbitratorProcessDepositRequest extends TradeTask {
trader.getDepositTxHash(), trader.getDepositTxHash(),
request.getDepositTxHex(), request.getDepositTxHex(),
request.getDepositTxKey(), request.getDepositTxKey(),
null, null);
false);
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException("Error processing deposit tx from " + (isFromTaker ? "taker " : "maker ") + trader.getNodeAddress() + ", offerId=" + offer.getId() + ": " + e.getMessage()); throw new RuntimeException("Error processing deposit tx from " + (isFromTaker ? "taker " : "maker ") + trader.getNodeAddress() + ", offerId=" + offer.getId() + ": " + e.getMessage());
} }

View File

@ -68,8 +68,7 @@ public class ArbitratorProcessReserveTx extends TradeTask {
request.getReserveTxHash(), request.getReserveTxHash(),
request.getReserveTxHex(), request.getReserveTxHex(),
request.getReserveTxKey(), request.getReserveTxKey(),
null, null);
true);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
throw new RuntimeException("Error processing reserve tx from " + (isFromTaker ? "taker " : "maker ") + request.getSenderNodeAddress() + ", offerId=" + offer.getId() + ": " + e.getMessage()); throw new RuntimeException("Error processing reserve tx from " + (isFromTaker ? "taker " : "maker ") + request.getSenderNodeAddress() + ", offerId=" + offer.getId() + ": " + e.getMessage());

View File

@ -353,7 +353,7 @@ public class XmrWalletService {
public MoneroTxWallet createReserveTx(BigInteger tradeFee, BigInteger sendAmount, BigInteger securityDeposit, String returnAddress, boolean reserveExactAmount, Integer preferredSubaddressIndex) { public MoneroTxWallet createReserveTx(BigInteger tradeFee, BigInteger sendAmount, BigInteger securityDeposit, String returnAddress, boolean reserveExactAmount, Integer preferredSubaddressIndex) {
log.info("Creating reserve tx with preferred subaddress index={}, return address={}", preferredSubaddressIndex, returnAddress); log.info("Creating reserve tx with preferred subaddress index={}, return address={}", preferredSubaddressIndex, returnAddress);
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
MoneroTxWallet reserveTx = createTradeTx(tradeFee, sendAmount, securityDeposit, returnAddress, true, reserveExactAmount, preferredSubaddressIndex); MoneroTxWallet reserveTx = createTradeTx(tradeFee, sendAmount, securityDeposit, returnAddress, reserveExactAmount, preferredSubaddressIndex);
log.info("Done creating reserve tx in {} ms", System.currentTimeMillis() - time); log.info("Done creating reserve tx in {} ms", System.currentTimeMillis() - time);
return reserveTx; return reserveTx;
} }
@ -382,13 +382,13 @@ public class XmrWalletService {
BigInteger securityDeposit = trade instanceof BuyerTrade ? offer.getBuyerSecurityDeposit() : offer.getSellerSecurityDeposit(); BigInteger securityDeposit = trade instanceof BuyerTrade ? offer.getBuyerSecurityDeposit() : offer.getSellerSecurityDeposit();
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
log.info("Creating deposit tx with multisig address={}", multisigAddress); log.info("Creating deposit tx with multisig address={}", multisigAddress);
MoneroTxWallet depositTx = createTradeTx(tradeFee, sendAmount, securityDeposit, multisigAddress, false, reserveExactAmount, preferredSubaddressIndex); MoneroTxWallet depositTx = createTradeTx(tradeFee, sendAmount, securityDeposit, multisigAddress, reserveExactAmount, preferredSubaddressIndex);
log.info("Done creating deposit tx for trade {} {} in {} ms", trade.getClass().getSimpleName(), trade.getId(), System.currentTimeMillis() - time); log.info("Done creating deposit tx for trade {} {} in {} ms", trade.getClass().getSimpleName(), trade.getId(), System.currentTimeMillis() - time);
return depositTx; return depositTx;
} }
} }
private MoneroTxWallet createTradeTx(BigInteger tradeFee, BigInteger sendAmount, BigInteger securityDeposit, String address, boolean isReserveTx, boolean reserveExactAmount, Integer preferredSubaddressIndex) { private MoneroTxWallet createTradeTx(BigInteger tradeFee, BigInteger sendAmount, BigInteger securityDeposit, String address, boolean reserveExactAmount, Integer preferredSubaddressIndex) {
synchronized (walletLock) { synchronized (walletLock) {
MoneroWallet wallet = getWallet(); MoneroWallet wallet = getWallet();
@ -413,26 +413,26 @@ public class XmrWalletService {
// first try preferred subaddressess // first try preferred subaddressess
for (int i = 0; i < subaddressIndices.size(); i++) { for (int i = 0; i < subaddressIndices.size(); i++) {
try { try {
return createTradeTxFromSubaddress(tradeFee, sendAmount, securityDeposit, address, isReserveTx, reserveExactAmount, subaddressIndices.get(i)); return createTradeTxFromSubaddress(tradeFee, sendAmount, securityDeposit, address, reserveExactAmount, subaddressIndices.get(i));
} catch (Exception e) { } catch (Exception e) {
if (i == subaddressIndices.size() - 1 && reserveExactAmount) throw e; // throw if no subaddress with exact output if (i == subaddressIndices.size() - 1 && reserveExactAmount) throw e; // throw if no subaddress with exact output
} }
} }
// try any subaddress // try any subaddress
return createTradeTxFromSubaddress(tradeFee, sendAmount, securityDeposit, address, isReserveTx, reserveExactAmount, null); return createTradeTxFromSubaddress(tradeFee, sendAmount, securityDeposit, address, reserveExactAmount, null);
} }
} }
private MoneroTxWallet createTradeTxFromSubaddress(BigInteger tradeFee, BigInteger sendAmount, BigInteger securityDeposit, String address, boolean isReserveTx, boolean reserveExactAmount, Integer subaddressIndex) { private MoneroTxWallet createTradeTxFromSubaddress(BigInteger tradeFee, BigInteger sendAmount, BigInteger securityDeposit, String address, boolean reserveExactAmount, Integer subaddressIndex) {
// create tx // create tx
MoneroTxWallet tradeTx = wallet.createTx(new MoneroTxConfig() MoneroTxWallet tradeTx = wallet.createTx(new MoneroTxConfig()
.setAccountIndex(0) .setAccountIndex(0)
.setSubaddressIndices(subaddressIndex) .setSubaddressIndices(subaddressIndex)
.addDestination(HavenoUtils.getTradeFeeAddress(), isReserveTx ? securityDeposit : tradeFee) // reserve tx charges security deposit if published .addDestination(HavenoUtils.getTradeFeeAddress(), tradeFee)
.addDestination(address, sendAmount.add(isReserveTx ? tradeFee : securityDeposit)) .addDestination(address, sendAmount.add(securityDeposit))
.setSubtractFeeFrom(isReserveTx ? 0 : 1)); // pay fee from same destination as security deposit .setSubtractFeeFrom(1)); // pay fee from security deposit
// check if tx uses exact input, since wallet2 can prefer to spend 2 outputs // check if tx uses exact input, since wallet2 can prefer to spend 2 outputs
if (reserveExactAmount) { if (reserveExactAmount) {
@ -466,7 +466,7 @@ public class XmrWalletService {
* @param keyImages expected key images of inputs, ignored if null * @param keyImages expected key images of inputs, ignored if null
* @return tuple with the verified tx and its actual security deposit * @return tuple with the verified tx and its actual security deposit
*/ */
public Tuple2<MoneroTx, BigInteger> verifyTradeTx(String offerId, BigInteger tradeFee, BigInteger sendAmount, BigInteger securityDeposit, String address, String txHash, String txHex, String txKey, List<String> keyImages, boolean isReserveTx) { public Tuple2<MoneroTx, BigInteger> verifyTradeTx(String offerId, BigInteger tradeFee, BigInteger sendAmount, BigInteger securityDeposit, String address, String txHash, String txHex, String txKey, List<String> keyImages) {
if (txHash == null) throw new IllegalArgumentException("Cannot verify trade tx with null id"); if (txHash == null) throw new IllegalArgumentException("Cannot verify trade tx with null id");
MoneroDaemonRpc daemon = getDaemon(); MoneroDaemonRpc daemon = getDaemon();
MoneroWallet wallet = getWallet(); MoneroWallet wallet = getWallet();
@ -512,9 +512,9 @@ public class XmrWalletService {
if (!transferCheck.isGood()) throw new RuntimeException("Invalid proof to transfer address"); if (!transferCheck.isGood()) throw new RuntimeException("Invalid proof to transfer address");
// collect actual trade fee, send amount, and security deposit // collect actual trade fee, send amount, and security deposit
BigInteger actualTradeFee = isReserveTx ? transferCheck.getReceivedAmount().subtract(sendAmount) : tradeFeeCheck.getReceivedAmount(); BigInteger actualTradeFee = tradeFeeCheck.getReceivedAmount();
actualSecurityDeposit = isReserveTx ? tradeFeeCheck.getReceivedAmount() : transferCheck.getReceivedAmount().subtract(sendAmount); actualSecurityDeposit = transferCheck.getReceivedAmount().subtract(sendAmount);
BigInteger actualSendAmount = transferCheck.getReceivedAmount().subtract(isReserveTx ? actualTradeFee : actualSecurityDeposit); BigInteger actualSendAmount = transferCheck.getReceivedAmount().subtract(actualSecurityDeposit);
// verify trade fee // verify trade fee
if (actualTradeFee.compareTo(tradeFee) < 0) { if (actualTradeFee.compareTo(tradeFee) < 0) {