Skip to content

Commit 890b2d3

Browse files
feat: feature flag to disable relay gas station (#7255)
## Explanation Add new feature flag property to disable gas station on specific source chains in Relay. ## References Related to [#23350 ](MetaMask/metamask-mobile#23350) ## Checklist - [x] I've updated the test suite for new or updated code as appropriate - [x] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [x] I've communicated my changes to consumers by [updating changelogs for packages I've changed](https://github.com/MetaMask/core/tree/main/docs/contributing.md#updating-changelogs) - [x] I've introduced [breaking changes](https://github.com/MetaMask/core/tree/main/docs/breaking-changes.md) in this PR and have prepared draft pull requests for clients and consumer packages to resolve them <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Introduces `relayDisabledGasStationChains` feature flag and uses it to skip gas station logic on specified source chains; updates feature flag utils and tests. > > - **Relay strategy (`src/strategy/relay/relay-quotes.ts`)** > - Read `relayDisabledGasStationChains` from feature flags and bypass gas fee token path when the source chain is listed. > - **Feature flags utils (`src/utils/feature-flags.ts`)** > - Add `relayDisabledGasStationChains` to raw and normalized types with default `[]`. > - **Tests** > - Add coverage for disabled-chain behavior in `relay-quotes.test.ts`. > - Extend `feature-flags.test.ts` to assert new flag defaults and remote values. > - **Changelog** > - Document new flag usage under Unreleased. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 40dd5c5. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 6a9eb1e commit 890b2d3

File tree

5 files changed

+66
-0
lines changed

5 files changed

+66
-0
lines changed

packages/transaction-pay-controller/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Use `relayDisabledGasStationChains` feature flag to disable gas station on specific source chains in Relay strategy ([#7255](https://github.com/MetaMask/core/pull/7255))
13+
1014
### Changed
1115

1216
- Bump `@metamask/bridge-status-controller` from `^63.0.0` to `^63.1.0` ([#7245](https://github.com/MetaMask/core/pull/7245))

packages/transaction-pay-controller/src/strategy/relay/relay-quotes.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,46 @@ describe('Relay Quotes Utils', () => {
645645
}),
646646
);
647647
});
648+
649+
it('not using gas fee token cost if chain disabled in feature flag', async () => {
650+
successfulFetchMock.mockResolvedValue({
651+
json: async () => QUOTE_MOCK,
652+
} as never);
653+
654+
getTokenBalanceMock.mockReturnValue('1724999999999999');
655+
getGasFeeTokensMock.mockResolvedValue([GAS_FEE_TOKEN_MOCK]);
656+
657+
getRemoteFeatureFlagControllerStateMock.mockReturnValue({
658+
cacheTimestamp: 0,
659+
remoteFeatureFlags: {
660+
confirmations_pay: {
661+
relayDisabledGasStationChains: [QUOTE_REQUEST_MOCK.sourceChainId],
662+
},
663+
},
664+
});
665+
666+
const result = await getRelayQuotes({
667+
messenger,
668+
requests: [QUOTE_REQUEST_MOCK],
669+
transaction: TRANSACTION_META_MOCK,
670+
});
671+
672+
expect(result[0].fees.isSourceGasFeeToken).toBeUndefined();
673+
expect(result[0].fees.sourceNetwork).toStrictEqual({
674+
estimate: {
675+
fiat: '4.56',
676+
human: '1.725',
677+
raw: '1725000000000000',
678+
usd: '3.45',
679+
},
680+
max: {
681+
fiat: '4.56',
682+
human: '1.725',
683+
raw: '1725000000000000',
684+
usd: '3.45',
685+
},
686+
});
687+
});
648688
});
649689

650690
it('includes target network fee in quote', async () => {

packages/transaction-pay-controller/src/strategy/relay/relay-quotes.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ async function calculateSourceNetworkCost(
372372
> {
373373
const { from, sourceChainId, sourceTokenAddress } = request;
374374
const allParams = quote.steps.flatMap((s) => s.items).map((i) => i.data);
375+
const { relayDisabledGasStationChains } = getFeatureFlags(messenger);
375376

376377
const { chainId, data, maxFeePerGas, maxPriorityFeePerGas, to, value } =
377378
allParams[0];
@@ -420,6 +421,15 @@ async function calculateSourceNetworkCost(
420421
return { estimate, max };
421422
}
422423

424+
if (relayDisabledGasStationChains.includes(sourceChainId)) {
425+
log('Skipping gas station as disabled chain', {
426+
sourceChainId,
427+
disabledChainIds: relayDisabledGasStationChains,
428+
});
429+
430+
return { estimate, max };
431+
}
432+
423433
log('Checking gas fee tokens as insufficient native balance', {
424434
nativeBalance,
425435
max: max.raw,

packages/transaction-pay-controller/src/utils/feature-flags.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { getMessengerMock } from '../tests/messenger-mock';
99
const GAS_FALLBACK_ESTIMATE_MOCK = 123;
1010
const GAS_FALLBACK_MAX_MOCK = 456;
1111
const RELAY_QUOTE_URL_MOCK = 'https://test.com/test';
12+
const RELAY_GAS_STATION_DISABLED_CHAINS_MOCK = ['0x1', '0x2'];
1213

1314
describe('Feature Flags Utils', () => {
1415
const { messenger, getRemoteFeatureFlagControllerStateMock } =
@@ -28,6 +29,7 @@ describe('Feature Flags Utils', () => {
2829
const featureFlags = getFeatureFlags(messenger);
2930

3031
expect(featureFlags).toStrictEqual({
32+
relayDisabledGasStationChains: [],
3133
relayFallbackGas: {
3234
estimate: DEFAULT_RELAY_FALLBACK_GAS_ESTIMATE,
3335
max: DEFAULT_RELAY_FALLBACK_GAS_MAX,
@@ -41,6 +43,8 @@ describe('Feature Flags Utils', () => {
4143
cacheTimestamp: 0,
4244
remoteFeatureFlags: {
4345
confirmations_pay: {
46+
relayDisabledGasStationChains:
47+
RELAY_GAS_STATION_DISABLED_CHAINS_MOCK,
4448
relayFallbackGas: {
4549
estimate: GAS_FALLBACK_ESTIMATE_MOCK,
4650
max: GAS_FALLBACK_MAX_MOCK,
@@ -53,6 +57,7 @@ describe('Feature Flags Utils', () => {
5357
const featureFlags = getFeatureFlags(messenger);
5458

5559
expect(featureFlags).toStrictEqual({
60+
relayDisabledGasStationChains: RELAY_GAS_STATION_DISABLED_CHAINS_MOCK,
5661
relayFallbackGas: {
5762
estimate: GAS_FALLBACK_ESTIMATE_MOCK,
5863
max: GAS_FALLBACK_MAX_MOCK,

packages/transaction-pay-controller/src/utils/feature-flags.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { Hex } from '@metamask/utils';
12
import { createModuleLogger } from '@metamask/utils';
23

34
import type { TransactionPayControllerMessenger } from '..';
@@ -11,6 +12,7 @@ export const DEFAULT_RELAY_FALLBACK_GAS_MAX = 1500000;
1112
export const DEFAULT_RELAY_QUOTE_URL = `${RELAY_URL_BASE}/quote`;
1213

1314
type FeatureFlagsRaw = {
15+
relayDisabledGasStationChains?: Hex[];
1416
relayFallbackGas?: {
1517
estimate?: number;
1618
max?: number;
@@ -19,6 +21,7 @@ type FeatureFlagsRaw = {
1921
};
2022

2123
export type FeatureFlags = {
24+
relayDisabledGasStationChains: Hex[];
2225
relayFallbackGas: {
2326
estimate: number;
2427
max: number;
@@ -49,7 +52,11 @@ export function getFeatureFlags(
4952

5053
const relayQuoteUrl = featureFlags.relayQuoteUrl ?? DEFAULT_RELAY_QUOTE_URL;
5154

55+
const relayDisabledGasStationChains =
56+
featureFlags.relayDisabledGasStationChains ?? [];
57+
5258
const result = {
59+
relayDisabledGasStationChains,
5360
relayFallbackGas: {
5461
estimate,
5562
max,

0 commit comments

Comments
 (0)