From 0182fa407e2388a648190c5c12ecfc02b1c7613b Mon Sep 17 00:00:00 2001 From: Dong-Ha Kim Date: Thu, 22 Feb 2024 18:39:53 +0100 Subject: [PATCH] fix: gas fee percent (#572) --- src/relayFeeCalculator/relayFeeCalculator.ts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/relayFeeCalculator/relayFeeCalculator.ts b/src/relayFeeCalculator/relayFeeCalculator.ts index d3642ff3..52a6a488 100644 --- a/src/relayFeeCalculator/relayFeeCalculator.ts +++ b/src/relayFeeCalculator/relayFeeCalculator.ts @@ -237,15 +237,14 @@ export class RelayFeeCalculator { throw new Error(`Could not find token information for ${inputToken}`); } - if (simulateZeroFill) { - amountToRelay = safeOutputAmount; - // Reduce the output amount to simulate a full fill with a lower value to estimate - // the fill cost accurately without risking a failure due to insufficient balance. - deposit = isV2Deposit(deposit) - ? { ...deposit, amount: amountToRelay } - : { ...deposit, outputAmount: amountToRelay }; - } - const getGasCosts = this.queries.getGasCosts(deposit, amountToRelay, relayerAddress).catch((error) => { + // Reduce the output amount to simulate a full fill with a lower value to estimate + // the fill cost accurately without risking a failure due to insufficient balance. + const simulatedAmount = simulateZeroFill ? safeOutputAmount : toBN(amountToRelay); + deposit = isV2Deposit(deposit) + ? { ...deposit, amount: simulatedAmount } + : { ...deposit, outputAmount: simulatedAmount }; + + const getGasCosts = this.queries.getGasCosts(deposit, simulatedAmount, relayerAddress).catch((error) => { this.logger.error({ at: "sdk-v2/gasFeePercent", message: "Error while fetching gas costs",