diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index e93a4a001865..ffa1b9a65803 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -159,7 +159,11 @@ import { toChecksumHexAddress } from '../../shared/modules/hexstring-utils'; ///: END:ONLY_INCLUDE_IF import { AssetType, TokenStandard } from '../../shared/constants/transaction'; -import { SWAPS_CLIENT_ID } from '../../shared/constants/swaps'; +import { + GAS_API_BASE_URL, + GAS_DEV_API_BASE_URL, + SWAPS_CLIENT_ID, +} from '../../shared/constants/swaps'; import { CHAIN_IDS, NETWORK_TYPES, @@ -776,6 +780,10 @@ export default class MetamaskController extends EventEmitter { allowedEvents: ['NetworkController:stateChange'], }); + const gasApiBaseUrl = process.env.SWAPS_USE_DEV_APIS + ? GAS_DEV_API_BASE_URL + : GAS_API_BASE_URL; + this.gasFeeController = new GasFeeController({ state: initState.GasFeeController, interval: 10000, @@ -795,12 +803,13 @@ export default class MetamaskController extends EventEmitter { ), getCurrentAccountEIP1559Compatibility: this.getCurrentAccountEIP1559Compatibility.bind(this), + legacyAPIEndpoint: `${gasApiBaseUrl}/networks//gasPrices`, + EIP1559APIEndpoint: `${gasApiBaseUrl}/networks//suggestedGasFees`, getCurrentNetworkLegacyGasAPICompatibility: () => { const { chainId } = this.networkController.state.providerConfig; return chainId === CHAIN_IDS.BSC; }, getChainId: () => this.networkController.state.providerConfig.chainId, - infuraAPIKey: opts.infuraProjectId, }); this.appStateController = new AppStateController({ diff --git a/privacy-snapshot.json b/privacy-snapshot.json index 499582424bd4..b45cf79a6e8f 100644 --- a/privacy-snapshot.json +++ b/privacy-snapshot.json @@ -18,7 +18,7 @@ "etherscan.io", "execution.metamask.io", "fonts.gstatic.com", - "gas.api.infura.io", + "gas.api.cx.metamask.io", "github.com", "goerli.infura.io", "localhost:8000", diff --git a/shared/constants/swaps.ts b/shared/constants/swaps.ts index 61f9b58b3ed5..bd3db9d94a2f 100644 --- a/shared/constants/swaps.ts +++ b/shared/constants/swaps.ts @@ -171,7 +171,7 @@ const SWAPS_TESTNET_CHAIN_ID = '0x539'; export const SWAPS_API_V2_BASE_URL = 'https://swap.api.cx.metamask.io'; export const SWAPS_DEV_API_V2_BASE_URL = 'https://swap.dev-api.cx.metamask.io'; export const TOKEN_API_BASE_URL = 'https://tokens.api.cx.metamask.io'; -export const GAS_API_BASE_URL = 'https://gas.api.infura.io'; +export const GAS_API_BASE_URL = 'https://gas.api.cx.metamask.io'; export const GAS_DEV_API_BASE_URL = 'https://gas.uat-api.cx.metamask.io'; const BSC_DEFAULT_BLOCK_EXPLORER_URL = 'https://bscscan.com/'; diff --git a/shared/lib/swaps-utils.js b/shared/lib/swaps-utils.js index 303e0f12f0e1..f27f4c9e8a8f 100644 --- a/shared/lib/swaps-utils.js +++ b/shared/lib/swaps-utils.js @@ -3,6 +3,7 @@ import log from 'loglevel'; import { CHAIN_IDS } from '../constants/network'; import { GAS_API_BASE_URL, + GAS_DEV_API_BASE_URL, SWAPS_API_V2_BASE_URL, SWAPS_CHAINID_DEFAULT_TOKEN_MAP, SWAPS_CLIENT_ID, @@ -130,7 +131,7 @@ const getBaseUrlForNewSwapsApi = (type, chainId) => { const v2ApiBaseUrl = useDevApis ? SWAPS_DEV_API_V2_BASE_URL : SWAPS_API_V2_BASE_URL; - const gasApiBaseUrl = GAS_API_BASE_URL; + const gasApiBaseUrl = useDevApis ? GAS_DEV_API_BASE_URL : GAS_API_BASE_URL; const tokenApiBaseUrl = TOKEN_API_BASE_URL; const noNetworkSpecificTypes = ['refreshTime']; // These types don't need network info in the URL. if (noNetworkSpecificTypes.includes(type)) { diff --git a/test/e2e/mock-e2e.js b/test/e2e/mock-e2e.js index fa1d89ab38ec..b70349d5e10a 100644 --- a/test/e2e/mock-e2e.js +++ b/test/e2e/mock-e2e.js @@ -183,60 +183,18 @@ async function setupMocking( }; }); - const gasPricesCallbackMock = () => ({ - statusCode: 200, - json: { - SafeGasPrice: '1', - ProposeGasPrice: '2', - FastGasPrice: '3', - }, - }); - const suggestedGasFeesCallbackMock = () => ({ - statusCode: 200, - json: { - low: { - suggestedMaxPriorityFeePerGas: '1', - suggestedMaxFeePerGas: '20.44436136', - minWaitTimeEstimate: 15000, - maxWaitTimeEstimate: 30000, - }, - medium: { - suggestedMaxPriorityFeePerGas: '1.5', - suggestedMaxFeePerGas: '25.80554517', - minWaitTimeEstimate: 15000, - maxWaitTimeEstimate: 45000, - }, - high: { - suggestedMaxPriorityFeePerGas: '2', - suggestedMaxFeePerGas: '27.277766977', - minWaitTimeEstimate: 15000, - maxWaitTimeEstimate: 60000, - }, - estimatedBaseFee: '19.444436136', - networkCongestion: 0.14685, - latestPriorityFeeRange: ['0.378818859', '6.555563864'], - historicalPriorityFeeRange: ['0.1', '248.262969261'], - historicalBaseFeeRange: ['14.146999781', '28.825256275'], - priorityFeeTrend: 'down', - baseFeeTrend: 'up', - }, - }); - await server .forGet(`${GAS_API_BASE_URL}/networks/${chainId}/gasPrices`) - .thenCallback(gasPricesCallbackMock); - - await server - .forGet(`${GAS_API_BASE_URL}/networks/1/gasPrices`) - .thenCallback(gasPricesCallbackMock); - - await server - .forGet(`${GAS_API_BASE_URL}/networks/1/suggestedGasFees`) - .thenCallback(suggestedGasFeesCallbackMock); - - await server - .forGet(`${GAS_API_BASE_URL}/networks/${chainId}/suggestedGasFees`) - .thenCallback(suggestedGasFeesCallbackMock); + .thenCallback(() => { + return { + statusCode: 200, + json: { + SafeGasPrice: '1', + ProposeGasPrice: '2', + FastGasPrice: '3', + }, + }; + }); await server .forGet('https://swap.api.cx.metamask.io/networks/1/token') @@ -255,6 +213,41 @@ async function setupMocking( }; }); + await server + .forGet(`${GAS_API_BASE_URL}/networks/${chainId}/suggestedGasFees`) + .thenCallback(() => { + return { + statusCode: 200, + json: { + low: { + suggestedMaxPriorityFeePerGas: '1', + suggestedMaxFeePerGas: '20.44436136', + minWaitTimeEstimate: 15000, + maxWaitTimeEstimate: 30000, + }, + medium: { + suggestedMaxPriorityFeePerGas: '1.5', + suggestedMaxFeePerGas: '25.80554517', + minWaitTimeEstimate: 15000, + maxWaitTimeEstimate: 45000, + }, + high: { + suggestedMaxPriorityFeePerGas: '2', + suggestedMaxFeePerGas: '27.277766977', + minWaitTimeEstimate: 15000, + maxWaitTimeEstimate: 60000, + }, + estimatedBaseFee: '19.444436136', + networkCongestion: 0.14685, + latestPriorityFeeRange: ['0.378818859', '6.555563864'], + historicalPriorityFeeRange: ['0.1', '248.262969261'], + historicalBaseFeeRange: ['14.146999781', '28.825256275'], + priorityFeeTrend: 'down', + baseFeeTrend: 'up', + }, + }; + }); + await server .forGet('https://swap.api.cx.metamask.io/featureFlags') .thenCallback(() => { diff --git a/test/jest/constants.js b/test/jest/constants.js index 37253f494720..5f63bda3eb9d 100644 --- a/test/jest/constants.js +++ b/test/jest/constants.js @@ -1,2 +1,2 @@ export const METASWAP_BASE_URL = 'https://swap.api.cx.metamask.io'; -export const GAS_API_URL = 'https://gas.api.infura.io'; +export const GAS_API_URL = 'https://gas.api.cx.metamask.io'; diff --git a/ui/pages/swaps/swaps.util.ts b/ui/pages/swaps/swaps.util.ts index 8d258cbf5a14..ce06d4ef37f8 100644 --- a/ui/pages/swaps/swaps.util.ts +++ b/ui/pages/swaps/swaps.util.ts @@ -49,11 +49,6 @@ const CACHE_REFRESH_FIVE_MINUTES = 300000; const USD_CURRENCY_CODE = 'usd'; const clientIdHeader = { 'X-Client-Id': SWAPS_CLIENT_ID }; -const infuraAuthHeader = { - Authorization: `Basic ${Buffer.from( - `${process.env.INFURA_PROJECT_ID}:`, - ).toString('base64')}`, -}; type Validator = { property: string; @@ -276,13 +271,7 @@ export async function fetchSwapsGasPrices(chainId: any): Promise< const gasPricesUrl = getBaseApi('gasPrices', chainId); const response = await fetchWithCache({ url: gasPricesUrl, - fetchOptions: { - method: 'GET', - headers: { - ...clientIdHeader, - ...infuraAuthHeader, - }, - }, + fetchOptions: { method: 'GET', headers: clientIdHeader }, cacheOptions: { cacheRefreshTime: 30000 }, functionName: 'fetchSwapsGasPrices', }); diff --git a/yarn.lock b/yarn.lock index cf50e0a9db6d..0087bd4eaee8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5397,7 +5397,7 @@ __metadata: languageName: node linkType: hard -"@metamask/gas-fee-controller@npm:^15.1.1, @metamask/gas-fee-controller@npm:^15.1.2": +"@metamask/gas-fee-controller@npm:15.1.2": version: 15.1.2 resolution: "@metamask/gas-fee-controller@npm:15.1.2" dependencies: @@ -5439,6 +5439,27 @@ __metadata: languageName: node linkType: hard +"@metamask/gas-fee-controller@patch:@metamask/gas-fee-controller@npm%3A15.1.2#~/.yarn/patches/@metamask-gas-fee-controller-npm-15.1.2-db4d2976aa.patch": + version: 15.1.2 + resolution: "@metamask/gas-fee-controller@patch:@metamask/gas-fee-controller@npm%3A15.1.2#~/.yarn/patches/@metamask-gas-fee-controller-npm-15.1.2-db4d2976aa.patch::version=15.1.2&hash=c5be0a" + dependencies: + "@metamask/base-controller": "npm:^5.0.2" + "@metamask/controller-utils": "npm:^9.1.0" + "@metamask/eth-query": "npm:^4.0.0" + "@metamask/ethjs-unit": "npm:^0.3.0" + "@metamask/network-controller": "npm:^18.1.0" + "@metamask/polling-controller": "npm:^6.0.2" + "@metamask/utils": "npm:^8.3.0" + "@types/bn.js": "npm:^5.1.5" + "@types/uuid": "npm:^8.3.0" + bn.js: "npm:^5.2.1" + uuid: "npm:^8.3.2" + peerDependencies: + "@metamask/network-controller": ^18.0.0 + checksum: 10/4785ff26e541911ffc5a280a9e1a9a648fb3d89e672afeedcd4951a8f176d8e6ae91192afe56fa943f6b4eeff3ce0dba7ec05228a62a8fee1664bb82642fcc15 + languageName: node + linkType: hard + "@metamask/jazzicon@npm:^2.0.0": version: 2.0.0 resolution: "@metamask/jazzicon@npm:2.0.0" @@ -24898,7 +24919,7 @@ __metadata: "@metamask/ethjs-contract": "npm:^0.4.1" "@metamask/ethjs-query": "npm:^0.7.1" "@metamask/forwarder": "npm:^1.1.0" - "@metamask/gas-fee-controller": "npm:^15.1.2" + "@metamask/gas-fee-controller": "patch:@metamask/gas-fee-controller@npm%3A15.1.2#~/.yarn/patches/@metamask-gas-fee-controller-npm-15.1.2-db4d2976aa.patch" "@metamask/jazzicon": "npm:^2.0.0" "@metamask/keyring-api": "npm:^6.3.1" "@metamask/keyring-controller": "patch:@metamask/keyring-controller@npm%3A15.0.0#~/.yarn/patches/@metamask-keyring-controller-npm-15.0.0-fa070ce311.patch"