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-pay-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Use `relayDisabledGasStationChains` feature flag to disable gas station on specific source chains in Relay strategy ([#7255](https://github.com/MetaMask/core/pull/7255))

### Changed

- Bump `@metamask/transaction-controller` from `^62.2.0` to `^62.3.0` ([#7236](https://github.com/MetaMask/core/pull/7236))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,46 @@ describe('Relay Quotes Utils', () => {
}),
);
});

it('not using gas fee token cost if chain disabled in feature flag', async () => {
successfulFetchMock.mockResolvedValue({
json: async () => QUOTE_MOCK,
} as never);

getTokenBalanceMock.mockReturnValue('1724999999999999');
getGasFeeTokensMock.mockResolvedValue([GAS_FEE_TOKEN_MOCK]);

getRemoteFeatureFlagControllerStateMock.mockReturnValue({
cacheTimestamp: 0,
remoteFeatureFlags: {
confirmations_pay: {
relayDisabledGasStationChains: [QUOTE_REQUEST_MOCK.sourceChainId],
},
},
});

const result = await getRelayQuotes({
messenger,
requests: [QUOTE_REQUEST_MOCK],
transaction: TRANSACTION_META_MOCK,
});

expect(result[0].fees.isSourceGasFeeToken).toBeUndefined();
expect(result[0].fees.sourceNetwork).toStrictEqual({
estimate: {
fiat: '4.56',
human: '1.725',
raw: '1725000000000000',
usd: '3.45',
},
max: {
fiat: '4.56',
human: '1.725',
raw: '1725000000000000',
usd: '3.45',
},
});
});
});

it('includes target network fee in quote', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ async function calculateSourceNetworkCost(
> {
const { from, sourceChainId, sourceTokenAddress } = request;
const allParams = quote.steps.flatMap((s) => s.items).map((i) => i.data);
const { relayDisabledGasStationChains } = getFeatureFlags(messenger);

const { chainId, data, maxFeePerGas, maxPriorityFeePerGas, to, value } =
allParams[0];
Expand Down Expand Up @@ -420,6 +421,15 @@ async function calculateSourceNetworkCost(
return { estimate, max };
}

if (relayDisabledGasStationChains.includes(sourceChainId)) {
log('Skipping gas station as disabled chain', {
sourceChainId,
disabledChainIds: relayDisabledGasStationChains,
});

return { estimate, max };
}

log('Checking gas fee tokens as insufficient native balance', {
nativeBalance,
max: max.raw,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { getMessengerMock } from '../tests/messenger-mock';
const GAS_FALLBACK_ESTIMATE_MOCK = 123;
const GAS_FALLBACK_MAX_MOCK = 456;
const RELAY_QUOTE_URL_MOCK = 'https://test.com/test';
const RELAY_GAS_STATION_DISABLED_CHAINS_MOCK = ['0x1', '0x2'];

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

expect(featureFlags).toStrictEqual({
relayDisabledGasStationChains: [],
relayFallbackGas: {
estimate: DEFAULT_RELAY_FALLBACK_GAS_ESTIMATE,
max: DEFAULT_RELAY_FALLBACK_GAS_MAX,
Expand All @@ -41,6 +43,8 @@ describe('Feature Flags Utils', () => {
cacheTimestamp: 0,
remoteFeatureFlags: {
confirmations_pay: {
relayDisabledGasStationChains:
RELAY_GAS_STATION_DISABLED_CHAINS_MOCK,
relayFallbackGas: {
estimate: GAS_FALLBACK_ESTIMATE_MOCK,
max: GAS_FALLBACK_MAX_MOCK,
Expand All @@ -53,6 +57,7 @@ describe('Feature Flags Utils', () => {
const featureFlags = getFeatureFlags(messenger);

expect(featureFlags).toStrictEqual({
relayDisabledGasStationChains: RELAY_GAS_STATION_DISABLED_CHAINS_MOCK,
relayFallbackGas: {
estimate: GAS_FALLBACK_ESTIMATE_MOCK,
max: GAS_FALLBACK_MAX_MOCK,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Hex } from '@metamask/utils';
import { createModuleLogger } from '@metamask/utils';

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

type FeatureFlagsRaw = {
relayDisabledGasStationChains?: Hex[];
relayFallbackGas?: {
estimate?: number;
max?: number;
Expand All @@ -19,6 +21,7 @@ type FeatureFlagsRaw = {
};

export type FeatureFlags = {
relayDisabledGasStationChains: Hex[];
relayFallbackGas: {
estimate: number;
max: number;
Expand Down Expand Up @@ -49,7 +52,11 @@ export function getFeatureFlags(

const relayQuoteUrl = featureFlags.relayQuoteUrl ?? DEFAULT_RELAY_QUOTE_URL;

const relayDisabledGasStationChains =
featureFlags.relayDisabledGasStationChains ?? [];

const result = {
relayDisabledGasStationChains,
relayFallbackGas: {
estimate,
max,
Expand Down
Loading