From a4b4ff13d28e06e7d032568d6f47e31b5ef1d9d8 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Sat, 9 Aug 2025 17:54:30 -0700 Subject: [PATCH] Handling corner cases when validating counter offer against operator fee --- src/use-cases/offer/index.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/use-cases/offer/index.js b/src/use-cases/offer/index.js index 35aedb9..e8aa821 100644 --- a/src/use-cases/offer/index.js +++ b/src/use-cases/offer/index.js @@ -635,9 +635,16 @@ class OfferUseCases { throw new Error('Could not calculate the amount of BCH offered in the Counter Offer') } const operatorSatsOut = this.adapters.wallet.bchWallet.bchjs.BitcoinCash.toSatoshi(txObj.vout[3].value) - const estimatedOperatorFee = Math.floor(txObj.vout[2].scriptPubKey.addresses[0] * orderData.operatorPercentage / 100) + let estimatedOperatorFee = Math.floor(txObj.vout[3].value * orderData.operatorPercentage / 100) + if (estimatedOperatorFee < 546) estimatedOperatorFee = 546 + console.log('operatorSatsOut: ', operatorSatsOut, 'estimatedOperatorFee: ', estimatedOperatorFee) if (operatorSatsOut < estimatedOperatorFee) { - throw new Error(`The Counter Offer has an output of ${operatorSatsOut}, which is less than the estimated operator fee of ${estimatedOperatorFee}.`) + console.log(`Skipping: The Counter Offer has an output of ${operatorSatsOut}, which is less than the estimated operator fee of ${estimatedOperatorFee}.`) + + // Add order to list of seen orders, so that we don't spent time trying to validate it again. + this.seenOffers.push(eventId) + + return 'N/A' } // Get the User ID from the Order model.