From 6db854e540c3dab13cd26cbe272c16c3f4ebe386 Mon Sep 17 00:00:00 2001 From: Jin Date: Fri, 15 Nov 2024 11:07:42 -0600 Subject: [PATCH] Update handling of flashbots flow (#6265) * Trace call complains about formatting of block tag or block number * Remove unused handlers swap estimate gas function * Move estimateUnlockAndSwap function * Update swap action to use unlock and swap estimation * Move estimateUnlockAndCrosschainSwap * Update crosschain swap action to use unlock and crosschain swap estimation * Get nonce and swap should actually get nonce * Check flashbots for swaps flow on getNextNonce * getFlashbotsProvider does not need to be async * Make checking flashbots for mainnet the default * Remove flashbots provider check in getNextNonce --- .../Swap/hooks/useSwapEstimatedGasLimit.ts | 4 +- .../screens/Swap/providers/swap-provider.tsx | 7 +- src/handlers/swap.ts | 77 +---------------- src/handlers/web3.ts | 4 +- src/raps/actions/crosschainSwap.ts | 77 +++++++++++++++-- src/raps/actions/swap.ts | 82 +++++++++++++++++-- src/raps/unlockAndCrosschainSwap.ts | 64 +-------------- src/raps/unlockAndSwap.ts | 73 +---------------- src/raps/utils.ts | 2 +- src/screens/SpeedUpAndCancelSheet.tsx | 22 ++--- 10 files changed, 168 insertions(+), 244 deletions(-) diff --git a/src/__swaps__/screens/Swap/hooks/useSwapEstimatedGasLimit.ts b/src/__swaps__/screens/Swap/hooks/useSwapEstimatedGasLimit.ts index bc9b301a87b..d061ca5fe3f 100644 --- a/src/__swaps__/screens/Swap/hooks/useSwapEstimatedGasLimit.ts +++ b/src/__swaps__/screens/Swap/hooks/useSwapEstimatedGasLimit.ts @@ -3,8 +3,8 @@ import { useQuery } from '@tanstack/react-query'; import { ParsedSearchAsset } from '@/__swaps__/types/assets'; import { ChainId } from '@/chains/types'; -import { estimateUnlockAndCrosschainSwap } from '@/raps/unlockAndCrosschainSwap'; -import { estimateUnlockAndSwap } from '@/raps/unlockAndSwap'; +import { estimateUnlockAndCrosschainSwap } from '@/raps/actions/crosschainSwap'; +import { estimateUnlockAndSwap } from '@/raps/actions/swap'; import { QueryConfigWithSelect, QueryFunctionArgs, QueryFunctionResult, createQueryKey } from '@/react-query'; import { gasUnits } from '@/references/gasUnits'; diff --git a/src/__swaps__/screens/Swap/providers/swap-provider.tsx b/src/__swaps__/screens/Swap/providers/swap-provider.tsx index 7197e5c0d04..9d82264a1d5 100644 --- a/src/__swaps__/screens/Swap/providers/swap-provider.tsx +++ b/src/__swaps__/screens/Swap/providers/swap-provider.tsx @@ -44,6 +44,8 @@ import { queryClient } from '@/react-query'; import { userAssetsQueryKey } from '@/resources/assets/UserAssetsQuery'; import { userAssetsStore } from '@/state/assets/userAssets'; import { swapsStore } from '@/state/swaps/swapsStore'; +import { getNextNonce } from '@/state/nonces'; + import { haptics } from '@/utils'; import { CrosschainQuote, Quote, QuoteError, SwapType } from '@rainbow-me/swaps'; @@ -202,7 +204,7 @@ export const SwapProvider = ({ children }: SwapProviderProps) => { const provider = parameters.flashbots && supportedFlashbotsChainIds.includes(parameters.chainId) - ? await getFlashbotsProvider() + ? getFlashbotsProvider() : getProvider({ chainId: parameters.chainId }); const connectedToHardhat = useConnectedToHardhatStore.getState().connectedToHardhat; @@ -261,6 +263,8 @@ export const SwapProvider = ({ children }: SwapProviderProps) => { } const chainId = connectedToHardhat ? ChainId.hardhat : parameters.chainId; + const nonce = await getNextNonce({ address: parameters.quote.from, chainId }); + const { errorMessage } = await performanceTracking.getState().executeFn({ fn: walletExecuteRap, screen: Screens.SWAPS, @@ -270,6 +274,7 @@ export const SwapProvider = ({ children }: SwapProviderProps) => { }, })(wallet, type, { ...parameters, + nonce, chainId, gasParams, // @ts-expect-error - collision between old gas types and new diff --git a/src/handlers/swap.ts b/src/handlers/swap.ts index 8dacc675b13..9a537286856 100644 --- a/src/handlers/swap.ts +++ b/src/handlers/swap.ts @@ -1,14 +1,6 @@ import { BigNumberish } from '@ethersproject/bignumber'; import { Block, StaticJsonRpcProvider } from '@ethersproject/providers'; -import { - CrosschainQuote, - getQuoteExecutionDetails, - getRainbowRouterContractAddress, - getWrappedAssetMethod, - PermitSupportedTokenList, - Quote, - SwapType, -} from '@rainbow-me/swaps'; +import { CrosschainQuote, getQuoteExecutionDetails, getRainbowRouterContractAddress, Quote } from '@rainbow-me/swaps'; import { Contract } from '@ethersproject/contracts'; import { MaxUint256 } from '@ethersproject/constants'; import { IS_TESTING } from 'react-native-dotenv'; @@ -184,73 +176,6 @@ export const getSwapGasLimitWithFakeApproval = async ( return getDefaultGasLimitForTrade(tradeDetails, chainId); }; -export const estimateSwapGasLimit = async ({ - chainId, - requiresApprove, - tradeDetails, -}: { - chainId: ChainId; - requiresApprove?: boolean; - tradeDetails: Quote | null; -}): Promise => { - const provider = getProvider({ chainId }); - if (!provider || !tradeDetails) { - return ethereumUtils.getBasicSwapGasLimit(Number(chainId)); - } - const isWrapNativeAsset = tradeDetails.swapType === SwapType.wrap; - const isUnwrapNativeAsset = tradeDetails.swapType === SwapType.unwrap; - - // Wrap / Unwrap Eth - if (isWrapNativeAsset || isUnwrapNativeAsset) { - const default_estimate = isWrapNativeAsset ? ethUnits.weth_wrap : ethUnits.weth_unwrap; - try { - const gasLimit = await estimateGasWithPadding( - { - from: tradeDetails.from, - value: isWrapNativeAsset ? tradeDetails.buyAmount : '0', - }, - getWrappedAssetMethod(isWrapNativeAsset ? 'deposit' : 'withdraw', provider, chainId as number), - // @ts-ignore - isUnwrapNativeAsset ? [tradeDetails.buyAmount] : null, - provider, - 1.002 - ); - - return gasLimit || tradeDetails?.defaultGasLimit || default_estimate; - } catch (e) { - return tradeDetails?.defaultGasLimit || default_estimate; - } - // Swap - } else { - try { - const { params, method, methodArgs } = getQuoteExecutionDetails(tradeDetails, { from: tradeDetails.from }, provider); - - if (requiresApprove) { - if (CHAIN_IDS_WITH_TRACE_SUPPORT.includes(chainId) && IS_TESTING !== 'true') { - try { - const gasLimitWithFakeApproval = await getSwapGasLimitWithFakeApproval(chainId, provider, tradeDetails); - logger.debug('[swap]: Got gasLimitWithFakeApproval!', { - gasLimitWithFakeApproval, - }); - return gasLimitWithFakeApproval; - } catch (e) { - logger.error(new RainbowError('[swap]: Error estimating swap gas limit with approval'), { - error: e, - }); - } - } - - return getDefaultGasLimitForTrade(tradeDetails, chainId); - } - - const gasLimit = await estimateGasWithPadding(params, method, methodArgs as any, provider, SWAP_GAS_PADDING); - return gasLimit || getDefaultGasLimitForTrade(tradeDetails, chainId); - } catch (error) { - return getDefaultGasLimitForTrade(tradeDetails, chainId); - } - } -}; - export const estimateCrosschainSwapGasLimit = async ({ chainId, requiresApprove, diff --git a/src/handlers/web3.ts b/src/handlers/web3.ts index ec3244df2ab..fd5ad561fd4 100644 --- a/src/handlers/web3.ts +++ b/src/handlers/web3.ts @@ -103,8 +103,8 @@ export const isTestnetChain = ({ chainId = ChainId.mainnet }: { chainId?: ChainI return !!defaultChains[chainId].testnet; }; -// shoudl figure out better way to include this in networks -export const getFlashbotsProvider = async () => { +// TODO: should figure out better way to include this in networks +export const getFlashbotsProvider = () => { return new StaticJsonRpcProvider( proxyCustomRpcEndpoint( ChainId.mainnet, diff --git a/src/raps/actions/crosschainSwap.ts b/src/raps/actions/crosschainSwap.ts index 6df8f65cf40..4ce949d8582 100644 --- a/src/raps/actions/crosschainSwap.ts +++ b/src/raps/actions/crosschainSwap.ts @@ -2,6 +2,8 @@ import { Signer } from '@ethersproject/abstract-signer'; import { CrosschainQuote, fillCrosschainQuote } from '@rainbow-me/swaps'; import { Address } from 'viem'; import { estimateGasWithPadding, getProvider, toHex } from '@/handlers/web3'; +import { add } from '@/helpers/utilities'; +import { assetNeedsUnlocking, estimateApprove } from './unlock'; import { REFERRER, gasUnits, ReferrerType } from '@/references'; import { ChainId } from '@/chains/types'; @@ -10,7 +12,8 @@ import { addNewTransaction } from '@/state/pendingTransactions'; import { RainbowError, logger } from '@/logger'; import { TransactionGasParams, TransactionLegacyGasParams } from '@/__swaps__/types/gas'; -import { ActionProps, RapActionResult } from '../references'; +import { ActionProps, RapActionResult, RapSwapActionParameters } from '../references'; + import { CHAIN_IDS_WITH_TRACE_SUPPORT, SWAP_GAS_PADDING, @@ -27,6 +30,65 @@ import { chainsName } from '@/chains'; const getCrosschainSwapDefaultGasLimit = (quote: CrosschainQuote) => quote?.routes?.[0]?.userTxs?.[0]?.gasFees?.gasLimit; +export const estimateUnlockAndCrosschainSwap = async ({ + sellAmount, + quote, + chainId, + assetToSell, +}: Pick, 'sellAmount' | 'quote' | 'chainId' | 'assetToSell'>) => { + const { + from: accountAddress, + sellTokenAddress, + allowanceTarget, + allowanceNeeded, + } = quote as { + from: Address; + sellTokenAddress: Address; + allowanceTarget: Address; + allowanceNeeded: boolean; + }; + + let gasLimits: (string | number)[] = []; + let swapAssetNeedsUnlocking = false; + + if (allowanceNeeded) { + swapAssetNeedsUnlocking = await assetNeedsUnlocking({ + owner: accountAddress, + amount: sellAmount, + assetToUnlock: assetToSell, + spender: allowanceTarget, + chainId, + }); + } + + if (swapAssetNeedsUnlocking) { + const unlockGasLimit = await estimateApprove({ + owner: accountAddress, + tokenAddress: sellTokenAddress, + spender: allowanceTarget, + chainId, + }); + gasLimits = gasLimits.concat(unlockGasLimit); + } + + const swapGasLimit = await estimateCrosschainSwapGasLimit({ + chainId, + requiresApprove: swapAssetNeedsUnlocking, + quote, + }); + + if (swapGasLimit === null || swapGasLimit === undefined || isNaN(Number(swapGasLimit))) { + return getCrosschainSwapDefaultGasLimit(quote) || getDefaultGasLimitForTrade(quote, chainId); + } + + const gasLimit = gasLimits.concat(swapGasLimit).reduce((acc, limit) => add(acc, limit), '0'); + if (isNaN(Number(gasLimit))) { + return getCrosschainSwapDefaultGasLimit(quote) || getDefaultGasLimitForTrade(quote, chainId); + } + + return gasLimit.toString(); +}; + export const estimateCrosschainSwapGasLimit = async ({ chainId, requiresApprove, @@ -112,7 +174,7 @@ export const crosschainSwap = async ({ gasParams, gasFeeParamsBySpeed, }: ActionProps<'crosschainSwap'>): Promise => { - const { quote, chainId, requiresApprove } = parameters; + const { assetToSell, sellAmount, quote, chainId } = parameters; let gasParamsToUse = gasParams; if (currentRap.actions.length - 1 > index) { @@ -125,10 +187,11 @@ export const crosschainSwap = async ({ let gasLimit; try { - gasLimit = await estimateCrosschainSwapGasLimit({ - chainId, - requiresApprove, + gasLimit = await estimateUnlockAndCrosschainSwap({ + sellAmount, quote, + chainId, + assetToSell, }); } catch (e) { logger.error(new RainbowError('[raps/crosschainSwap]: error estimateCrosschainSwapGasLimit'), { @@ -187,7 +250,7 @@ export const crosschainSwap = async ({ price: nativePriceForAssetToBuy, } satisfies ParsedAsset; - const assetToSell = { + const updatedAssetToSell = { ...parameters.assetToSell, network: chainsName[parameters.assetToSell.chainId], networks: parameters.assetToSell.networks as Record, @@ -206,7 +269,7 @@ export const crosschainSwap = async ({ { direction: TransactionDirection.OUT, asset: { - ...assetToSell, + ...updatedAssetToSell, native: undefined, }, value: quote.sellAmount.toString(), diff --git a/src/raps/actions/swap.ts b/src/raps/actions/swap.ts index 12164beb055..cc0c6d35550 100644 --- a/src/raps/actions/swap.ts +++ b/src/raps/actions/swap.ts @@ -24,7 +24,7 @@ import { RainbowError, logger } from '@/logger'; import { gasUnits, REFERRER } from '@/references'; import { TransactionGasParams, TransactionLegacyGasParams } from '@/__swaps__/types/gas'; -import { ActionProps, RapActionResult } from '../references'; +import { ActionProps, RapActionResult, RapSwapActionParameters } from '../references'; import { CHAIN_IDS_WITH_TRACE_SUPPORT, SWAP_GAS_PADDING, @@ -34,7 +34,7 @@ import { populateSwap, } from '../utils'; -import { populateApprove } from './unlock'; +import { assetNeedsUnlocking, estimateApprove, populateApprove } from './unlock'; import { TokenColors } from '@/graphql/__generated__/metadata'; import { swapMetadataStorage } from '../common'; import { AddysNetworkDetails, ParsedAsset } from '@/resources/assets/types'; @@ -45,6 +45,73 @@ import { chainsName } from '@/chains'; const WRAP_GAS_PADDING = 1.002; +export const estimateUnlockAndSwap = async ({ + sellAmount, + quote, + chainId, + assetToSell, +}: Pick, 'sellAmount' | 'quote' | 'chainId' | 'assetToSell'>) => { + const { + from: accountAddress, + sellTokenAddress, + allowanceNeeded, + } = quote as { + from: Address; + sellTokenAddress: Address; + allowanceNeeded: boolean; + }; + + let gasLimits: (string | number)[] = []; + let swapAssetNeedsUnlocking = false; + + if (allowanceNeeded) { + swapAssetNeedsUnlocking = await assetNeedsUnlocking({ + owner: accountAddress, + amount: sellAmount, + assetToUnlock: assetToSell, + spender: getRainbowRouterContractAddress(chainId), + chainId, + }); + } + + if (swapAssetNeedsUnlocking) { + const gasLimitFromMetadata = await estimateUnlockAndSwapFromMetadata({ + swapAssetNeedsUnlocking, + chainId, + accountAddress, + sellTokenAddress, + quote, + }); + if (gasLimitFromMetadata) { + return gasLimitFromMetadata; + } + const unlockGasLimit = await estimateApprove({ + owner: accountAddress, + tokenAddress: sellTokenAddress, + spender: getRainbowRouterContractAddress(chainId), + chainId, + }); + gasLimits = gasLimits.concat(unlockGasLimit); + } + + const swapGasLimit = await estimateSwapGasLimit({ + chainId, + requiresApprove: swapAssetNeedsUnlocking, + quote, + }); + + if (swapGasLimit === null || swapGasLimit === undefined || isNaN(Number(swapGasLimit))) { + return getDefaultGasLimitForTrade(quote, chainId); + } + + const gasLimit = gasLimits.concat(swapGasLimit).reduce((acc, limit) => add(acc, limit), '0'); + if (isNaN(Number(gasLimit))) { + return getDefaultGasLimitForTrade(quote, chainId); + } + + return gasLimit.toString(); +}; + export const estimateSwapGasLimit = async ({ chainId, requiresApprove, @@ -238,7 +305,7 @@ export const swap = async ({ }: ActionProps<'swap'>): Promise => { let gasParamsToUse = gasParams; - const { quote, chainId, requiresApprove } = parameters; + const { assetToSell, quote, chainId, sellAmount } = parameters; // if swap isn't the last action, use fast gas or custom (whatever is faster) if (currentRap.actions.length - 1 > index) { @@ -251,9 +318,10 @@ export const swap = async ({ let gasLimit; try { - gasLimit = await estimateSwapGasLimit({ + gasLimit = await estimateUnlockAndSwap({ + sellAmount, + assetToSell, chainId, - requiresApprove, quote, }); } catch (e) { @@ -313,7 +381,7 @@ export const swap = async ({ price: nativePriceForAssetToBuy, } satisfies ParsedAsset; - const assetToSell = { + const updatedAssetToSell = { ...parameters.assetToSell, network: chainsName[parameters.assetToSell.chainId], networks: parameters.assetToSell.networks as Record, @@ -332,7 +400,7 @@ export const swap = async ({ { direction: TransactionDirection.OUT, asset: { - ...assetToSell, + ...updatedAssetToSell, native: undefined, }, value: quote.sellAmount.toString(), diff --git a/src/raps/unlockAndCrosschainSwap.ts b/src/raps/unlockAndCrosschainSwap.ts index f5d9ab1371d..d92b2265aec 100644 --- a/src/raps/unlockAndCrosschainSwap.ts +++ b/src/raps/unlockAndCrosschainSwap.ts @@ -1,71 +1,9 @@ import { Address } from 'viem'; -import { add } from '@/helpers/utilities'; - -import { assetNeedsUnlocking, estimateApprove } from './actions'; -import { estimateCrosschainSwapGasLimit } from './actions/crosschainSwap'; +import { assetNeedsUnlocking } from './actions'; import { createNewAction, createNewRap } from './common'; import { RapAction, RapSwapActionParameters, RapUnlockActionParameters } from './references'; -export const estimateUnlockAndCrosschainSwap = async ({ - sellAmount, - quote, - chainId, - assetToSell, -}: Pick, 'sellAmount' | 'quote' | 'chainId' | 'assetToSell'>) => { - const { - from: accountAddress, - sellTokenAddress, - allowanceTarget, - allowanceNeeded, - } = quote as { - from: Address; - sellTokenAddress: Address; - allowanceTarget: Address; - allowanceNeeded: boolean; - }; - - let gasLimits: (string | number)[] = []; - let swapAssetNeedsUnlocking = false; - - if (allowanceNeeded) { - swapAssetNeedsUnlocking = await assetNeedsUnlocking({ - owner: accountAddress, - amount: sellAmount, - assetToUnlock: assetToSell, - spender: allowanceTarget, - chainId, - }); - } - - if (swapAssetNeedsUnlocking) { - const unlockGasLimit = await estimateApprove({ - owner: accountAddress, - tokenAddress: sellTokenAddress, - spender: allowanceTarget, - chainId, - }); - gasLimits = gasLimits.concat(unlockGasLimit); - } - - const swapGasLimit = await estimateCrosschainSwapGasLimit({ - chainId, - requiresApprove: swapAssetNeedsUnlocking, - quote, - }); - - if (swapGasLimit === null || swapGasLimit === undefined || isNaN(Number(swapGasLimit))) { - return null; - } - - const gasLimit = gasLimits.concat(swapGasLimit).reduce((acc, limit) => add(acc, limit), '0'); - if (isNaN(Number(gasLimit))) { - return null; - } - - return gasLimit.toString(); -}; - export const createUnlockAndCrosschainSwapRap = async (swapParameters: RapSwapActionParameters<'crosschainSwap'>) => { let actions: RapAction<'crosschainSwap' | 'unlock'>[] = []; const { sellAmount, assetToBuy, quote, chainId, assetToSell } = swapParameters; diff --git a/src/raps/unlockAndSwap.ts b/src/raps/unlockAndSwap.ts index bdf1f9fb9f6..573397b1daf 100644 --- a/src/raps/unlockAndSwap.ts +++ b/src/raps/unlockAndSwap.ts @@ -1,80 +1,9 @@ import { getRainbowRouterContractAddress } from '@rainbow-me/swaps'; import { Address } from 'viem'; - -import { add } from '@/helpers/utilities'; - -import { assetNeedsUnlocking, estimateApprove, estimateSwapGasLimit } from './actions'; -import { estimateUnlockAndSwapFromMetadata } from './actions/swap'; +import { assetNeedsUnlocking } from './actions'; import { createNewAction, createNewRap } from './common'; import { RapAction, RapSwapActionParameters, RapUnlockActionParameters } from './references'; -export const estimateUnlockAndSwap = async ({ - sellAmount, - quote, - chainId, - assetToSell, -}: Pick, 'sellAmount' | 'quote' | 'chainId' | 'assetToSell'>) => { - const { - from: accountAddress, - sellTokenAddress, - allowanceNeeded, - } = quote as { - from: Address; - sellTokenAddress: Address; - allowanceNeeded: boolean; - }; - - let gasLimits: (string | number)[] = []; - let swapAssetNeedsUnlocking = false; - - if (allowanceNeeded) { - swapAssetNeedsUnlocking = await assetNeedsUnlocking({ - owner: accountAddress, - amount: sellAmount, - assetToUnlock: assetToSell, - spender: getRainbowRouterContractAddress(chainId), - chainId, - }); - } - - if (swapAssetNeedsUnlocking) { - const gasLimitFromMetadata = await estimateUnlockAndSwapFromMetadata({ - swapAssetNeedsUnlocking, - chainId, - accountAddress, - sellTokenAddress, - quote, - }); - if (gasLimitFromMetadata) { - return gasLimitFromMetadata; - } - const unlockGasLimit = await estimateApprove({ - owner: accountAddress, - tokenAddress: sellTokenAddress, - spender: getRainbowRouterContractAddress(chainId), - chainId, - }); - gasLimits = gasLimits.concat(unlockGasLimit); - } - - const swapGasLimit = await estimateSwapGasLimit({ - chainId, - requiresApprove: swapAssetNeedsUnlocking, - quote, - }); - - if (swapGasLimit === null || swapGasLimit === undefined || isNaN(Number(swapGasLimit))) { - return null; - } - - const gasLimit = gasLimits.concat(swapGasLimit).reduce((acc, limit) => add(acc, limit), '0'); - if (isNaN(Number(gasLimit))) { - return null; - } - - return gasLimit.toString(); -}; - export const createUnlockAndSwapRap = async (swapParameters: RapSwapActionParameters<'swap'>) => { let actions: RapAction<'swap' | 'unlock'>[] = []; diff --git a/src/raps/utils.ts b/src/raps/utils.ts index 284596be057..6da90630263 100644 --- a/src/raps/utils.ts +++ b/src/raps/utils.ts @@ -70,7 +70,7 @@ const getStateDiff = async (provider: Provider, quote: Quote | CrosschainQuote): value: '0x0', }, ['stateDiff'], - blockNumber - TRACE_CALL_BLOCK_NUMBER_OFFSET, + toHexNoLeadingZeros(blockNumber - TRACE_CALL_BLOCK_NUMBER_OFFSET), ]; const trace = await (provider as StaticJsonRpcProvider).send('trace_call', callParams); diff --git a/src/screens/SpeedUpAndCancelSheet.tsx b/src/screens/SpeedUpAndCancelSheet.tsx index 352df10fd8e..8fda0f1441a 100644 --- a/src/screens/SpeedUpAndCancelSheet.tsx +++ b/src/screens/SpeedUpAndCancelSheet.tsx @@ -312,19 +312,15 @@ export default function SpeedUpAndCancelSheet() { useEffect(() => { if (currentChainId) { startPollingGasFees(currentChainId, tx.flashbots); - const updateProvider = async () => { - let provider; - if (supportedFlashbotsChainIds.includes(tx.chainId || ChainId.mainnet) && tx.flashbots) { - logger.debug(`[SpeedUpAndCancelSheet]: using flashbots provider for chainId ${tx?.chainId}`); - provider = await getFlashbotsProvider(); - } else { - logger.debug(`[SpeedUpAndCancelSheet]: using provider for network ${tx?.chainId}`); - provider = getProvider({ chainId: currentChainId }); - } - setCurrentProvider(provider); - }; - - updateProvider(); + let provider; + if (supportedFlashbotsChainIds.includes(tx.chainId || ChainId.mainnet) && tx.flashbots) { + logger.debug(`[SpeedUpAndCancelSheet]: using flashbots provider for chainId ${tx?.chainId}`); + provider = getFlashbotsProvider(); + } else { + logger.debug(`[SpeedUpAndCancelSheet]: using provider for network ${tx?.chainId}`); + provider = getProvider({ chainId: currentChainId }); + } + setCurrentProvider(provider); return () => { stopPollingGasFees();