From f8abe33e8240c723983bf6439d897ca4e2da5c0b Mon Sep 17 00:00:00 2001 From: woodenfurniture <125113430+woodenfurniture@users.noreply.github.com> Date: Wed, 21 Feb 2024 09:00:55 +1100 Subject: [PATCH 1/2] fix: allow quote sell amounts to be lower than user input sell amount --- src/state/apis/swapper/helpers/validateTradeQuote.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/state/apis/swapper/helpers/validateTradeQuote.ts b/src/state/apis/swapper/helpers/validateTradeQuote.ts index 8ba75e8ebd3..3ea934fca95 100644 --- a/src/state/apis/swapper/helpers/validateTradeQuote.ts +++ b/src/state/apis/swapper/helpers/validateTradeQuote.ts @@ -255,8 +255,9 @@ export const validateTradeQuote = async ( })() // ensure the trade is not selling an amount higher than the user input - const invalidQuoteSellAmount = - inputSellAmountCryptoBaseUnit !== firstHop.sellAmountIncludingProtocolFeesCryptoBaseUnit + const invalidQuoteSellAmount = bn(inputSellAmountCryptoBaseUnit).gte( + firstHop.sellAmountIncludingProtocolFeesCryptoBaseUnit, + ) return { errors: [ From 084eb2f27f75cdf73a29a7de11ddde1440fc8979 Mon Sep 17 00:00:00 2001 From: woodenfurniture <125113430+woodenfurniture@users.noreply.github.com> Date: Wed, 21 Feb 2024 10:02:49 +1100 Subject: [PATCH 2/2] fix: fix logic, add a teeny tiny thrshold so cowswap works --- src/state/apis/swapper/helpers/validateTradeQuote.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/state/apis/swapper/helpers/validateTradeQuote.ts b/src/state/apis/swapper/helpers/validateTradeQuote.ts index 3ea934fca95..f18004f1b8e 100644 --- a/src/state/apis/swapper/helpers/validateTradeQuote.ts +++ b/src/state/apis/swapper/helpers/validateTradeQuote.ts @@ -254,10 +254,11 @@ export const validateTradeQuote = async ( return false })() - // ensure the trade is not selling an amount higher than the user input - const invalidQuoteSellAmount = bn(inputSellAmountCryptoBaseUnit).gte( - firstHop.sellAmountIncludingProtocolFeesCryptoBaseUnit, - ) + // Ensure the trade is not selling an amount higher than the user input, within a very safe threshold. + // Threshold is required because cowswap sometimes quotes a sell amount a teeny-tiny bit more than you input. + const invalidQuoteSellAmount = bn(inputSellAmountCryptoBaseUnit) + .times('1.0000000000001') + .lt(firstHop.sellAmountIncludingProtocolFeesCryptoBaseUnit) return { errors: [