Skip to content

Commit e48a245

Browse files
authored
chore: update default bridge slippage to 2% (#37367)
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** Update default slippage value for bridge quotes from 0.5 to 2%. <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? --> [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/37367?quickstart=1) ## **Changelog** <!-- If this PR is not End-User-Facing and should not show up in the CHANGELOG, you can choose to either: 1. Write `CHANGELOG entry: null` 2. Label with `no-changelog` If this PR is End-User-Facing, please write a short User-Facing description in the past tense like: `CHANGELOG entry: Added a new tab for users to see their NFTs` `CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker` (This helps the Release Engineer do their job more quickly and accurately) --> CHANGELOG entry: chore: update default bridge slippage to 2% ## **Related issues** Fixes: ## **Manual testing steps** 1. Go to this page... 2. 3. ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [ ] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Sets bridge default slippage to 2% via SlippageValue enum and updates UI logic and tests accordingly. > > - **Bridge logic**: > - Replace `BRIDGE_DEFAULT_SLIPPAGE` with `SlippageValue` enum; set `BridgeDefault = 2` and use in `ui/ducks/bridge/bridge.ts` initial state. > - Update slippage calculation to treat cross-chain as `2%` in `ui/pages/bridge/utils/slippage-service.ts`. > - **UI**: > - Use `SlippageValue` in `bridge-transaction-settings-modal.tsx`; hardcoded options now `[EvmStablecoin(0.5), BridgeDefault(2)]` and default selection uses `BridgeDefault`. > - **Tests**: > - Update unit tests in `ui/ducks/bridge/bridge.test.ts` to expect `SlippageValue.BridgeDefault`. > - Adjust e2e analytics assertion in `test/e2e/tests/metrics/bridge.spec.ts` to expect `18` `SwapBridgeInputChanged` events. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 5bf8097. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 822bc47 commit e48a245

File tree

5 files changed

+16
-13
lines changed

5 files changed

+16
-13
lines changed

test/e2e/tests/metrics/bridge.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ describe('Bridge tests', function (this: Suite) {
115115
*/
116116

117117
assert(
118-
swapBridgeInputChanged.length === 22,
119-
'Should have 22 input change events',
118+
swapBridgeInputChanged.length === 18,
119+
`Should have 18 input change events, but got ${swapBridgeInputChanged.length}`,
120120
);
121121

122122
const swapBridgeInputChangedKeys = new Set(

ui/ducks/bridge/bridge.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { zeroAddress } from 'ethereumjs-util';
44
import {
55
BridgeBackgroundAction,
66
BridgeUserAction,
7-
BRIDGE_DEFAULT_SLIPPAGE,
87
formatChainIdToCaip,
98
getNativeAssetForChainId,
109
} from '@metamask/bridge-controller';
@@ -14,6 +13,7 @@ import { toAssetId } from '../../../shared/lib/asset-utils';
1413
import { CHAIN_IDS } from '../../../shared/constants/network';
1514
import { setBackgroundConnection } from '../../store/background-connection';
1615
import { MultichainNetworks } from '../../../shared/constants/multichain/networks';
16+
import { SlippageValue } from '../../pages/bridge/utils/slippage-service';
1717
import bridgeReducer from './bridge';
1818
import {
1919
setFromToken,
@@ -141,7 +141,7 @@ describe('Ducks - Bridge', () => {
141141
toChainId: null,
142142
fromToken: null,
143143
toToken: null,
144-
slippage: BRIDGE_DEFAULT_SLIPPAGE,
144+
slippage: SlippageValue.BridgeDefault,
145145
fromTokenInputValue: null,
146146
sortOrder: 'cost_ascending',
147147
toTokenExchangeRate: null,
@@ -240,7 +240,7 @@ describe('Ducks - Bridge', () => {
240240
fromTokenExchangeRate: null,
241241
fromTokenInputValue: null,
242242
selectedQuote: null,
243-
slippage: BRIDGE_DEFAULT_SLIPPAGE,
243+
slippage: SlippageValue.BridgeDefault,
244244
sortOrder: 'cost_ascending',
245245
toChainId: null,
246246
toToken: null,

ui/ducks/bridge/bridge.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { createAsyncThunk, createSlice } from '@reduxjs/toolkit';
22
import {
33
SortOrder,
4-
BRIDGE_DEFAULT_SLIPPAGE,
54
formatChainIdToCaip,
65
getNativeAssetForChainId,
76
calcLatestSrcBalance,
@@ -15,6 +14,7 @@ import {
1514
import { zeroAddress } from 'ethereumjs-util';
1615
import { fetchTxAlerts } from '../../../shared/modules/bridge-utils/security-alerts-api.util';
1716
import { endTrace, TraceName } from '../../../shared/lib/trace';
17+
import { SlippageValue } from '../../pages/bridge/utils/slippage-service';
1818
import { getTokenExchangeRate, toBridgeToken } from './utils';
1919
import type { BridgeState, ChainIdPayload, TokenPayload } from './types';
2020

@@ -31,7 +31,7 @@ const initialState: BridgeState = {
3131
sortOrder: SortOrder.COST_ASC,
3232
selectedQuote: null,
3333
wasTxDeclined: false,
34-
slippage: BRIDGE_DEFAULT_SLIPPAGE,
34+
slippage: SlippageValue.BridgeDefault,
3535
txAlert: null,
3636
};
3737

ui/pages/bridge/prepare/bridge-transaction-settings-modal.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React, { useState, useEffect } from 'react';
22
import { useDispatch, useSelector } from 'react-redux';
3-
import { BRIDGE_DEFAULT_SLIPPAGE } from '@metamask/bridge-controller';
43
import {
54
Button,
65
ButtonSize,
@@ -30,9 +29,13 @@ import {
3029
} from '../../../helpers/constants/design-system';
3130
import { getIsSolanaSwap, getSlippage } from '../../../ducks/bridge/selectors';
3231
import { setSlippage } from '../../../ducks/bridge/actions';
32+
import { SlippageValue } from '../utils/slippage-service';
3333
import { Column, Row, Tooltip } from '../layout';
3434

35-
const HARDCODED_SLIPPAGE_OPTIONS = [BRIDGE_DEFAULT_SLIPPAGE, 2];
35+
const HARDCODED_SLIPPAGE_OPTIONS = [
36+
SlippageValue.EvmStablecoin,
37+
SlippageValue.BridgeDefault,
38+
];
3639

3740
export const BridgeTransactionSettingsModal = ({
3841
onClose,
@@ -69,7 +72,7 @@ export const BridgeTransactionSettingsModal = ({
6972
if (!slippage || slippage === 0) {
7073
// Default to first option if no slippage set, null, or 0
7174
// This handles undefined, null, 0, and other falsy values
72-
setLocalSlippage(BRIDGE_DEFAULT_SLIPPAGE);
75+
setLocalSlippage(SlippageValue.BridgeDefault);
7376
setCustomSlippage(undefined);
7477
} else if (HARDCODED_SLIPPAGE_OPTIONS.includes(slippage)) {
7578
setLocalSlippage(slippage);

ui/pages/bridge/utils/slippage-service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { STABLECOINS_BY_CHAIN_ID } from './stablecoins';
88
export enum SlippageValue {
99
EvmStablecoin = 0.5,
1010
EvmDefault = 2,
11-
BridgeDefault = 0.5,
11+
BridgeDefault = 2,
1212
}
1313

1414
/**
@@ -70,7 +70,7 @@ function isStablecoinPair(
7070
* Calculates the appropriate slippage based on the transaction context
7171
*
7272
* Rules:
73-
* - Bridge (cross-chain): Always 0.5%
73+
* - Bridge (cross-chain): Always 2%
7474
* - Swap on Solana: Always undefined (AUTO mode)
7575
* - Swap on EVM stablecoin pairs (same chain only): 0.5%
7676
* - Swap on EVM other pairs: 2%
@@ -87,7 +87,7 @@ export function calculateSlippage(
8787
return SlippageValue.BridgeDefault;
8888
}
8989

90-
// 1. Cross-chain (bridge) → 0.5%
90+
// 1. Cross-chain (bridge) → 2%
9191
if (!isSwap || fromChain.chainId !== toChain.chainId) {
9292
return SlippageValue.BridgeDefault;
9393
}

0 commit comments

Comments
 (0)