Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/transaction-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Bump `@metamask/gas-fee-controller` from `^26.2.4` to `^26.3.0` ([#9629](https://github.com/MetaMask/core/pull/9629))

### Fixed

- Apply saved gas fee preferences to wallet-initiated transfers while continuing to ignore them for swaps and bridge transactions ([#9682](https://github.com/MetaMask/core/pull/9682)).

## [69.2.1]

### Changed
Expand Down
24 changes: 23 additions & 1 deletion packages/transaction-controller/src/utils/gas-fees.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,31 @@ describe('gas-fees', () => {
);
});

it('are ignored for internal transactions (e.g. swaps and bridges)', async () => {
it('are applied for internal wallet transactions', async () => {
updateGasFeeRequest.txMeta.isInternal = true;
updateGasFeeRequest.txMeta.type = TransactionType.simpleSend;
updateGasFeeRequest.getSavedGasFees.mockReturnValueOnce(
SAVED_GAS_FEES_MOCK,
);

await updateGasFees(updateGasFeeRequest);

expect(updateGasFeeRequest.getSavedGasFees).toHaveBeenCalledTimes(1);
expect(updateGasFeeRequest.txMeta.txParams.maxFeePerGas).toBe(
'0x1ca35f0e00', // 123 gwei
);
});

it.each([
TransactionType.swap,
TransactionType.swapAndSend,
TransactionType.swapApproval,
TransactionType.bridge,
TransactionType.bridgeApproval,
])('are ignored for %s transactions', async (type) => {
mockGasFeeFlowMockResponse(FLOW_RESPONSE_FEE_MARKET_MOCK);
updateGasFeeRequest.txMeta.isInternal = true;
updateGasFeeRequest.txMeta.type = type;
updateGasFeeRequest.getSavedGasFees.mockReturnValueOnce(
SAVED_GAS_FEES_MOCK,
);
Expand Down
19 changes: 14 additions & 5 deletions packages/transaction-controller/src/utils/gas-fees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ import type {
import {
GasFeeEstimateLevel,
GasFeeEstimateType,
TransactionType,
UserFeeLevel,
} from '../types.js';
import { getGasFeeFlow } from './gas-flow.js';
import { rpcRequest } from './provider.js';
import { SWAP_TRANSACTION_TYPES } from './swaps.js';

export type UpdateGasFeesRequest = {
eip1559: boolean;
Expand Down Expand Up @@ -57,6 +59,12 @@ type SuggestedGasFees = {

const log = createModuleLogger(projectLogger, 'gas-fees');

const SAVED_GAS_FEES_IGNORED_TRANSACTION_TYPES = [
...SWAP_TRANSACTION_TYPES,
TransactionType.bridge,
TransactionType.bridgeApproval,
];

/**
* Update the gas fee properties of the provided transaction meta.
*
Expand All @@ -68,12 +76,13 @@ export async function updateGasFees(
const { txMeta } = request;
const initialParams = { ...txMeta.txParams };

// User-saved (advanced) gas fees only apply to dApp transactions. Internal
// transactions (e.g. swaps and bridges) have their fees dictated by the
// aggregator or relay, so applying saved gas fees could underprice them and
// cause them to fail or get stuck.
const shouldIgnoreSavedGasFees =
SAVED_GAS_FEES_IGNORED_TRANSACTION_TYPES.includes(
txMeta.type as TransactionType,
);

const savedGasFees =
txMeta.isInternal || hasInitialGasFeeParams(initialParams)
shouldIgnoreSavedGasFees || hasInitialGasFeeParams(initialParams)
? undefined
: request.getSavedGasFees(txMeta);

Expand Down