Skip to content

Commit 044daae

Browse files
authored
Improve nonce management logic for private mempool handling (#6277)
* Add support for default private mempool timeout of 2 minutes * fix: rename chainsPrivateMempoolTimout * Use existing timestamp to update tx timestamp for new pending txns or updating pending txns * Update nonce management logic * Wrap latest and pending tx count calls in Promise.all * Add support for batched provider * Use batched provider in nonce manager logic * Update getNextNonce forloop exit * Fix: handle when localNonce not set yet * Remove nonce logic for flashbots from pending txn watcher * Remove flashbots toggle from swap review panel * Remove flashbots from swap-provider * Remove flashbots logic from swap gas panel * Remove flashbots from swap settings and meteorology * Remove flashbots enabled from redux and global settings * Remove flashbots from speedup and cancel sheet and redux gas * Remove flashbots from explain sheet * Remove flashbots from raps * Remove getFlashbotsProvider * Remove flashbots from remote config defaults * Remove flashbots from txns parser * Remove flashbots row from swap settings panel * Remove flashbots from animated swap styles * Remove supported flashbots chain ids list * Remove flashbots in analytics and experimental config * Remove flashbots from GasSpeedButton and FeesPanel * Remove flashbots min tip constant * Remove en_US flashbots copy * Adding new txn to behave similar to updating txns in order to handle new txns that are using a gapped nonce * Fix addPendingTxn to ensure pending txns are ordered by nonce * Simplify updateTransaction which matches addNewTransaction * Support pendingTransactions function for returning txns in recent first order * Cleanup sort function * Fix: setNonce only when nonce is greater than currentNonce now that addNewtx and updateTxn have been consolidated and a gapped nonce can be picked up * Set up HARDHAT_RPC_URL constant * Fix: array sort sorts in place * Remove flashbots from latest changes for navigateToSwaps * Add a comment for getNextNonce logic * Remove unnecessary updating of nonces from pending txn watcher as it clobbers over data during for loop * Fix: off by one error when comparing local nonce with pending txn count * Remove flashbots reference
1 parent 7b33b8d commit 044daae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+167
-566
lines changed

src/__swaps__/screens/Swap/components/GasPanel.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as i18n from '@/languages';
22
import React, { PropsWithChildren, ReactNode, useMemo } from 'react';
33
import Animated, { runOnJS, useAnimatedReaction, useAnimatedStyle, withDelay, withSpring } from 'react-native-reanimated';
44

5-
import { MIN_FLASHBOTS_PRIORITY_FEE, THICK_BORDER_WIDTH } from '@/__swaps__/screens/Swap/constants';
5+
import { THICK_BORDER_WIDTH } from '@/__swaps__/screens/Swap/constants';
66
import { NavigationSteps, useSwapContext } from '@/__swaps__/screens/Swap/providers/swap-provider';
77
import { ChainId } from '@/chains/types';
88
import { GasSpeed } from '@/__swaps__/types/gas';
@@ -318,18 +318,14 @@ function EditMaxBaseFee() {
318318

319319
function EditPriorityFee() {
320320
const { navigate } = useNavigation();
321-
322-
const isFlashbotsEnabled = useSwapsStore(s => s.flashbots);
323-
const min = isFlashbotsEnabled ? MIN_FLASHBOTS_PRIORITY_FEE : '0';
324-
325321
const maxPriorityFee = useGasPanelState('maxPriorityFee');
326322

327323
return (
328324
<Inline horizontalSpace="10px" alignVertical="center" alignHorizontal="justify">
329325
<PressableLabel onPress={() => navigate(Routes.EXPLAIN_SHEET, { type: MINER_TIP_TYPE })}>
330326
{i18n.t(i18n.l.gas.miner_tip)}
331327
</PressableLabel>
332-
<GasSettingInput value={maxPriorityFee} onChange={maxPriorityFee => setGasPanelState({ maxPriorityFee })} min={min} />
328+
<GasSettingInput value={maxPriorityFee} onChange={maxPriorityFee => setGasPanelState({ maxPriorityFee })} min={'0'} />
333329
</Inline>
334330
);
335331
}

src/__swaps__/screens/Swap/components/ReviewPanel.tsx

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ import Animated, {
3939
import { REVIEW_SHEET_ROW_HEIGHT, THICK_BORDER_WIDTH } from '../constants';
4040
import { useSelectedGasSpeed } from '../hooks/useSelectedGas';
4141
import { NavigationSteps, useSwapContext } from '../providers/swap-provider';
42-
import { AnimatedSwitch } from './AnimatedSwitch';
4342
import { EstimatedSwapGasFee, EstimatedSwapGasFeeSlot } from './EstimatedSwapGasFee';
4443
import { UnmountOnAnimatedReaction } from './UnmountOnAnimatedReaction';
4544
import { chainsLabel, chainsNativeAsset } from '@/chains';
@@ -51,7 +50,6 @@ const NETWORK_LABEL = i18n.t(i18n.l.settings.network);
5150
const MINIMUM_RECEIVED_LABEL = i18n.t(i18n.l.expanded_state.swap_details_v2.minimum_received);
5251
const MAXIMUM_SOLD_LABEL = i18n.t(i18n.l.expanded_state.swap_details_v2.maximum_sold);
5352
const RAINBOW_FEE_LABEL = i18n.t(i18n.l.expanded_state.swap_details_v2.rainbow_fee);
54-
const FLASHBOTS_PROTECTION_LABEL = i18n.t(i18n.l.swap.flashbots_protection);
5553
const MAX_SLIPPAGE_LABEL = i18n.t(i18n.l.exchange.slippage_tolerance);
5654
const ESTIMATED_NETWORK_FEE_LABEL = i18n.t(i18n.l.gas.network_fee);
5755

@@ -126,71 +124,6 @@ function EstimatedArrivalTime() {
126124
);
127125
}
128126

129-
function FlashbotsToggle() {
130-
const { SwapSettings } = useSwapContext();
131-
132-
return (
133-
<AnimatedSwitch
134-
onToggle={SwapSettings.onToggleFlashbots}
135-
value={SwapSettings.flashbots}
136-
activeLabel={i18n.t(i18n.l.expanded_state.swap.on)}
137-
inactiveLabel={i18n.t(i18n.l.expanded_state.swap.off)}
138-
/>
139-
);
140-
}
141-
142-
export const FlashbotsRow = () => {
143-
const { navigate } = useNavigation();
144-
const { internalSelectedInputAsset } = useSwapContext();
145-
146-
const labelTertiary = useForegroundColor('labelTertiary');
147-
148-
const flashbotsVisibilityStyle = useAnimatedStyle(() => {
149-
const shouldDisplay = (internalSelectedInputAsset.value?.chainId ?? ChainId.mainnet) === ChainId.mainnet;
150-
return {
151-
display: shouldDisplay ? 'flex' : 'none',
152-
};
153-
});
154-
155-
const openFlashbotsExplainer = useCallback(() => {
156-
navigate(Routes.EXPLAIN_SHEET, {
157-
type: 'flashbots',
158-
});
159-
}, [navigate]);
160-
161-
return (
162-
<Animated.View style={[flashbotsVisibilityStyle, { height: REVIEW_SHEET_ROW_HEIGHT, justifyContent: 'center' }]}>
163-
<Inline wrap={false} horizontalSpace="10px" alignVertical="center" alignHorizontal="justify">
164-
<Inline wrap={false} horizontalSpace="12px">
165-
<TextIcon color="labelTertiary" height={9} size="icon 13px" weight="bold" width={16}>
166-
􀋦
167-
</TextIcon>
168-
<Inline wrap={false} horizontalSpace="4px">
169-
<Text color="labelTertiary" weight="semibold" size="15pt">
170-
{FLASHBOTS_PROTECTION_LABEL}
171-
</Text>
172-
<Bleed space="12px">
173-
<ButtonPressAnimation onPress={openFlashbotsExplainer} scaleTo={0.8}>
174-
<Text
175-
align="center"
176-
color={{ custom: opacity(labelTertiary, 0.24) }}
177-
size="icon 13px"
178-
style={{ padding: 12, top: 0.5 }}
179-
weight="semibold"
180-
>
181-
􀅴
182-
</Text>
183-
</ButtonPressAnimation>
184-
</Bleed>
185-
</Inline>
186-
</Inline>
187-
188-
<FlashbotsToggle />
189-
</Inline>
190-
</Animated.View>
191-
);
192-
};
193-
194127
export const SlippageRow = () => {
195128
const { navigate } = useNavigation();
196129
const { SwapSettings } = useSwapContext();
@@ -439,8 +372,6 @@ export function ReviewPanel() {
439372

440373
<Separator color={{ custom: opacity(separator, 0.03) }} thickness={THICK_BORDER_WIDTH} />
441374

442-
<FlashbotsRow />
443-
444375
<SlippageRow />
445376

446377
<Separator color={{ custom: opacity(separator, 0.03) }} thickness={THICK_BORDER_WIDTH} />

src/__swaps__/screens/Swap/components/SettingsPanel.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { THICK_BORDER_WIDTH } from '../constants';
1010
import { NavigationSteps, useSwapContext } from '../providers/swap-provider';
1111
import { AnimatedSwitch } from './AnimatedSwitch';
1212
import { GestureHandlerButton } from './GestureHandlerButton';
13-
import { FlashbotsRow, SlippageRow } from './ReviewPanel';
13+
import { SlippageRow } from './ReviewPanel';
1414

1515
const PreferredNetworkMenu = () => {
1616
const preferredNetwork = useSwapsStore(state => state.preferredNetwork);
@@ -98,7 +98,6 @@ export function SettingsPanel() {
9898

9999
<Box gap={28} paddingHorizontal="12px" width="full">
100100
<Animated.View style={[degenSettingsVisibilityStyle, { gap: 28 }]}>
101-
<FlashbotsRow />
102101
<SlippageRow />
103102
<Separator color={{ custom: opacity(separator, 0.03) }} thickness={THICK_BORDER_WIDTH} />
104103
</Animated.View>

src/__swaps__/screens/Swap/constants.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { gweiToWei } from '@/parsers';
21
import { getDefaultKeyboardHeight } from '@/redux/keyboardHeight';
32
import { deviceUtils, safeAreaInsetValues } from '@/utils';
43
import { Easing, WithSpringConfig, WithTimingConfig } from 'react-native-reanimated';
@@ -85,5 +84,3 @@ export const highPriceImpactThreshold = 0.05;
8584
export const severePriceImpactThreshold = 0.1;
8685

8786
export const slippageStep = 0.5;
88-
89-
export const MIN_FLASHBOTS_PRIORITY_FEE = gweiToWei('6');

src/__swaps__/screens/Swap/hooks/useAnimatedSwapStyles.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import { safeAreaInsetValues } from '@/utils';
2323
import { getSoftMenuBarHeight } from 'react-native-extra-dimensions-android';
2424
import { DerivedValue, SharedValue, interpolate, useAnimatedStyle, useDerivedValue, withSpring, withTiming } from 'react-native-reanimated';
2525
import { NavigationSteps } from './useSwapNavigation';
26-
import { ChainId } from '@/chains/types';
2726
import { SPRING_CONFIGS, TIMING_CONFIGS } from '@/components/animations/animationConfigs';
2827

2928
const INSET_BOTTOM = IS_ANDROID ? getSoftMenuBarHeight() - 24 : safeAreaInsetValues.bottom + 16;
@@ -169,15 +168,11 @@ export function useAnimatedSwapStyles({
169168
const isSettingsOpen = configProgress.value === NavigationSteps.SHOW_SETTINGS;
170169
const isBottomSheetOpen = isReviewing || isSettingsOpen || configProgress.value === NavigationSteps.SHOW_GAS;
171170

172-
const shouldHideFlashbotsRow = (internalSelectedInputAsset.value?.chainId ?? ChainId.mainnet) !== ChainId.mainnet;
173-
174171
let heightForCurrentSheet = HEIGHT_FOR_PANEL[configProgress.value];
175-
if (isReviewing && shouldHideFlashbotsRow) {
176-
// Remove height when the Flashbots row in the review sheet is hidden
172+
if (isReviewing) {
177173
heightForCurrentSheet -= REVIEW_SHEET_ROW_HEIGHT + REVIEW_SHEET_ROW_GAP;
178174
} else if (degenMode.value && isSettingsOpen && swapInfo.value.areBothAssetsSet) {
179175
heightForCurrentSheet += REVIEW_SHEET_ROW_HEIGHT + SETTINGS_SHEET_ROW_GAP * 2 + THICK_BORDER_WIDTH;
180-
if (!shouldHideFlashbotsRow) heightForCurrentSheet += REVIEW_SHEET_ROW_HEIGHT + SETTINGS_SHEET_ROW_GAP;
181176
}
182177

183178
return {

src/__swaps__/screens/Swap/hooks/useSwapSettings.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,15 @@ import { swapsStore } from '@/state/swaps/swapsStore';
44
import { runOnJS, SharedValue, useSharedValue } from 'react-native-reanimated';
55

66
export const useSwapSettings = ({ debouncedFetchQuote, slippage }: { debouncedFetchQuote: () => void; slippage: SharedValue<string> }) => {
7-
const flashbots = useSharedValue(swapsStore.getState().flashbots);
87
const degenMode = useSharedValue(swapsStore.getState().degenMode);
98

109
const setSlippage = swapsStore(state => state.setSlippage);
11-
const setFlashbots = swapsStore(state => state.setFlashbots);
1210

1311
const setDegenMode = (value: boolean) => {
1412
swapsStore.getState().setDegenMode(value);
1513
analyticsV2.track(analyticsV2.event.swapsToggledDegenMode, { enabled: value });
1614
};
1715

18-
const onToggleFlashbots = () => {
19-
'worklet';
20-
21-
const current = flashbots.value;
22-
flashbots.value = !current;
23-
runOnJS(setFlashbots)(!current);
24-
};
25-
2616
const onUpdateSlippage = (operation: 'plus' | 'minus') => {
2717
'worklet';
2818

@@ -51,11 +41,8 @@ export const useSwapSettings = ({ debouncedFetchQuote, slippage }: { debouncedFe
5141
};
5242

5343
return {
54-
flashbots,
5544
slippage,
5645
degenMode,
57-
58-
onToggleFlashbots,
5946
onUpdateSlippage,
6047
onToggleDegenMode,
6148
};

src/__swaps__/screens/Swap/navigateToSwaps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { watchingAlert } from '@/utils';
99
import Routes from '@/navigation/routesNames';
1010

1111
export type SwapsParams = Partial<
12-
Pick<SwapsState, 'inputAsset' | 'outputAsset' | 'percentageToSell' | 'flashbots' | 'slippage'> & {
12+
Pick<SwapsState, 'inputAsset' | 'outputAsset' | 'percentageToSell' | 'slippage'> & {
1313
inputAmount: string;
1414
outputAmount: string;
1515
gasSpeed: GasSpeed;

src/__swaps__/screens/Swap/providers/swap-provider.tsx

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { SwapAssetType, inputKeys } from '@/__swaps__/types/swap';
2929
import { clamp, getDefaultSlippageWorklet, parseAssetAndExtend } from '@/__swaps__/utils/swaps';
3030
import { analyticsV2 } from '@/analytics';
3131
import { LegacyTransactionGasParamAmounts, TransactionGasParamAmounts } from '@/entities';
32-
import { getFlashbotsProvider, getProvider } from '@/handlers/web3';
32+
import { getProvider } from '@/handlers/web3';
3333
import { WrappedAlert as Alert } from '@/helpers/alert';
3434
import { useAccountSettings } from '@/hooks';
3535
import { useAnimatedInterval } from '@/hooks/reanimated/useAnimatedInterval';
@@ -58,11 +58,9 @@ import { SyncGasStateToSharedValues, SyncQuoteSharedValuesToState } from './Sync
5858
import { performanceTracking, Screens, TimeToSignOperation } from '@/state/performance/performance';
5959
import { getRemoteConfig } from '@/model/remoteConfig';
6060
import { useConnectedToHardhatStore } from '@/state/connectedToHardhat';
61-
import { chainsNativeAsset, supportedFlashbotsChainIds } from '@/chains';
61+
import { chainsNativeAsset } from '@/chains';
6262
import { getSwapsNavigationParams } from '../navigateToSwaps';
6363
import { LedgerSigner } from '@/handlers/LedgerSigner';
64-
import { EventProperties } from '@/analytics/event';
65-
import { isEqual } from 'lodash';
6664

6765
const swapping = i18n.t(i18n.l.swap.actions.swapping);
6866
const holdToSwap = i18n.t(i18n.l.swap.actions.hold_to_swap);
@@ -227,10 +225,7 @@ export const SwapProvider = ({ children }: SwapProviderProps) => {
227225
const NotificationManager = IS_IOS ? NativeModules.NotificationManager : null;
228226
NotificationManager?.postNotification('rapInProgress');
229227

230-
const provider =
231-
parameters.flashbots && supportedFlashbotsChainIds.includes(parameters.chainId)
232-
? getFlashbotsProvider()
233-
: getProvider({ chainId: parameters.chainId });
228+
const provider = getProvider({ chainId: parameters.chainId });
234229
const connectedToHardhat = useConnectedToHardhatStore.getState().connectedToHardhat;
235230

236231
const isBridge = swapsStore.getState().inputAsset?.mainnetAddress === swapsStore.getState().outputAsset?.mainnetAddress;
@@ -327,7 +322,6 @@ export const SwapProvider = ({ children }: SwapProviderProps) => {
327322
mainnetAddress: (parameters.assetToBuy.chainId === ChainId.mainnet
328323
? parameters.assetToBuy.address
329324
: parameters.assetToSell.mainnetAddress) as AddressOrEth,
330-
flashbots: parameters.flashbots ?? false,
331325
tradeAmountUSD: parameters.quote.tradeAmountUSD,
332326
degenMode: isDegenModeEnabled,
333327
isSwappingToPopularAsset,
@@ -399,7 +393,6 @@ export const SwapProvider = ({ children }: SwapProviderProps) => {
399393
mainnetAddress: (parameters.assetToBuy.chainId === ChainId.mainnet
400394
? parameters.assetToBuy.address
401395
: parameters.assetToSell.mainnetAddress) as AddressOrEth,
402-
flashbots: parameters.flashbots ?? false,
403396
tradeAmountUSD: parameters.quote.tradeAmountUSD,
404397
degenMode: isDegenModeEnabled,
405398
isSwappingToPopularAsset,
@@ -441,8 +434,6 @@ export const SwapProvider = ({ children }: SwapProviderProps) => {
441434

442435
const type = inputAsset.chainId !== outputAsset.chainId ? 'crosschainSwap' : 'swap';
443436
const quoteData = q as QuoteTypeMap[typeof type];
444-
const flashbots = (SwapSettings.flashbots.value && !!supportedFlashbotsChainIds.includes(inputAsset.chainId)) ?? false;
445-
446437
const isNativeWrapOrUnwrap = quoteData.swapType === SwapType.wrap || quoteData.swapType === SwapType.unwrap;
447438

448439
const parameters: Omit<RapSwapActionParameters<typeof type>, 'gasParams' | 'gasFeeParamsBySpeed' | 'selectedGasFee'> = {
@@ -457,7 +448,6 @@ export const SwapProvider = ({ children }: SwapProviderProps) => {
457448
sellAmountDisplay: isNativeWrapOrUnwrap ? quoteData.sellAmount : quoteData.sellAmountDisplay,
458449
feeInEth: isNativeWrapOrUnwrap ? '0' : quoteData.feeInEth,
459450
},
460-
flashbots,
461451
};
462452

463453
runOnJS(getNonceAndPerformSwap)({

src/__swaps__/types/swap.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export type inputKeys = 'inputAmount' | 'inputNativeValue' | 'outputAmount' | 'o
44
export type inputMethods = inputKeys | 'slider';
55
export type inputValuesType = { [key in inputKeys]: number | string };
66

7-
export type settingsKeys = 'swapFee' | 'slippage' | 'flashbots';
7+
export type settingsKeys = 'swapFee' | 'slippage';
88

99
export enum SortMethod {
1010
token = 'token',

src/__swaps__/utils/gasUtils.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ import { addHexPrefix, toHex } from '@/handlers/web3';
3131
import { MeteorologyLegacyResponse, MeteorologyResponse } from '@/entities/gas';
3232
import { getMinimalTimeUnitStringForMs } from '@/helpers/time';
3333

34-
export const FLASHBOTS_MIN_TIP = 6;
35-
3634
export const parseGasDataConfirmationTime = ({
3735
maxBaseFee,
3836
maxPriorityFee,
@@ -463,7 +461,6 @@ export const parseGasFeeParamsBySpeed = ({
463461
nativeAsset,
464462
currency,
465463
optimismL1SecurityFee,
466-
flashbotsEnabled,
467464
additionalTime = 0,
468465
}: {
469466
chainId: ChainId;
@@ -472,7 +469,6 @@ export const parseGasFeeParamsBySpeed = ({
472469
nativeAsset?: ParsedAsset;
473470
currency: SupportedCurrencyKey;
474471
optimismL1SecurityFee?: string | null;
475-
flashbotsEnabled?: boolean;
476472
additionalTime?: number;
477473
}) => {
478474
if (meteorologySupportsType2ForChain(chainId)) {
@@ -486,16 +482,6 @@ export const parseGasFeeParamsBySpeed = ({
486482
byPriorityFee: response.data.blocksToConfirmationByPriorityFee,
487483
};
488484

489-
if (flashbotsEnabled) {
490-
for (const speed in maxPriorityFeeSuggestions) {
491-
type gasSpeed = 'fast' | 'normal' | 'urgent';
492-
maxPriorityFeeSuggestions[speed as gasSpeed] = Math.max(
493-
Number(gweiToWei(FLASHBOTS_MIN_TIP.toString())),
494-
Number(maxPriorityFeeSuggestions[speed as gasSpeed])
495-
).toString();
496-
}
497-
}
498-
499485
const parseGasFeeParamsSpeed = ({ speed }: { speed: GasSpeed }) =>
500486
parseGasFeeParams({
501487
currentBaseFee,

0 commit comments

Comments
 (0)