diff --git a/CHANGELOG.md b/CHANGELOG.md index 71df78542..2c06c88bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [9.8.2] +### Changed +- [1156511545](https://github.com/MetaMask/metamask-extension/pull/11545): Allow MetaMask Swaps to support Polygon network + +### Fixed +- [11565](https://github.com/MetaMask/metamask-extension/pull/11565): Fix gas limit estimation for some tokens on custom networks +- [11581](https://github.com/MetaMask/metamask-extension/pull/11581): Fixed bug that resulted in sends to some contracts being disabled. + ## [9.8.1] ### Changed - Adjusting transaction metrics values @@ -2336,7 +2344,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Uncategorized - Added the ability to restore accounts from seed words. -[Unreleased]: https://github.com/MetaMask/metamask-extension/compare/v9.8.1...HEAD +[Unreleased]: https://github.com/MetaMask/metamask-extension/compare/v9.8.2...HEAD +[9.8.2]: https://github.com/MetaMask/metamask-extension/compare/v9.8.1...v9.8.2 [9.8.1]: https://github.com/MetaMask/metamask-extension/compare/v9.8.0...v9.8.1 [9.8.0]: https://github.com/MetaMask/metamask-extension/compare/v9.7.1...v9.8.0 [9.7.1]: https://github.com/MetaMask/metamask-extension/compare/v9.7.0...v9.7.1 diff --git a/app/images/matic-token.png b/app/images/matic-token.png new file mode 100644 index 000000000..b154c46ea Binary files /dev/null and b/app/images/matic-token.png differ diff --git a/package.json b/package.json index 9fb661cbc..61b05b65f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "metamask-crx", - "version": "9.8.1", + "version": "9.8.2", "private": true, "repository": { "type": "git", diff --git a/shared/constants/network.js b/shared/constants/network.js index 66bd1e949..1d22b5271 100644 --- a/shared/constants/network.js +++ b/shared/constants/network.js @@ -49,10 +49,12 @@ export const ETH_SYMBOL = 'ETH'; export const WETH_SYMBOL = 'WETH'; export const TEST_ETH_SYMBOL = 'TESTETH'; export const BNB_SYMBOL = 'BNB'; +export const MATIC_SYMBOL = 'MATIC'; export const ETH_TOKEN_IMAGE_URL = './images/eth_logo.svg'; export const TEST_ETH_TOKEN_IMAGE_URL = './images/black-eth-logo.svg'; export const BNB_TOKEN_IMAGE_URL = './images/bnb.png'; +export const MATIC_TOKEN_IMAGE_URL = './images/matic-token.png'; export const INFURA_PROVIDER_TYPES = [ROPSTEN, RINKEBY, KOVAN, MAINNET, GOERLI]; diff --git a/shared/constants/swaps.js b/shared/constants/swaps.js index 00512c0cc..dba447b2c 100644 --- a/shared/constants/swaps.js +++ b/shared/constants/swaps.js @@ -6,6 +6,9 @@ import { TEST_ETH_TOKEN_IMAGE_URL, BNB_TOKEN_IMAGE_URL, BSC_CHAIN_ID, + POLYGON_CHAIN_ID, + MATIC_SYMBOL, + MATIC_TOKEN_IMAGE_URL, } from './network'; export const QUOTES_EXPIRED_ERROR = 'quotes-expired'; @@ -35,6 +38,14 @@ export const BNB_SWAPS_TOKEN_OBJECT = { iconUrl: BNB_TOKEN_IMAGE_URL, }; +export const MATIC_SWAPS_TOKEN_OBJECT = { + symbol: MATIC_SYMBOL, + name: 'Matic', + address: DEFAULT_TOKEN_ADDRESS, + decimals: 18, + iconUrl: MATIC_TOKEN_IMAGE_URL, +}; + export const TEST_ETH_SWAPS_TOKEN_OBJECT = { symbol: TEST_ETH_SYMBOL, name: 'Test Ether', @@ -52,6 +63,9 @@ const TESTNET_CONTRACT_ADDRESS = '0x881d40237659c251811cec9c364ef91dc08d300c'; const BSC_CONTRACT_ADDRESS = '0x1a1ec25dc08e98e5e93f1104b5e5cdd298707d31'; +// It's the same as we use for BSC. +const POLYGON_CONTRACT_ADDRESS = '0x1a1ec25dc08e98e5e93f1104b5e5cdd298707d31'; + export const ETH_WETH_CONTRACT_ADDRESS = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'; @@ -64,13 +78,16 @@ const SWAPS_TESTNET_HOST = 'https://metaswap-api.airswap-dev.codefi.network'; const BSC_DEFAULT_BLOCK_EXPLORER_URL = 'https://bscscan.com/'; const MAINNET_DEFAULT_BLOCK_EXPLORER_URL = 'https://etherscan.io/'; +const POLYGON_DEFAULT_BLOCK_EXPLORER_URL = 'https://polygonscan.com/'; export const ALLOWED_SWAPS_CHAIN_IDS = { [MAINNET_CHAIN_ID]: true, [SWAPS_TESTNET_CHAIN_ID]: true, [BSC_CHAIN_ID]: true, + [POLYGON_CHAIN_ID]: true, }; +// This is mapping for v1 URLs and will be removed once we migrate to v2. export const METASWAP_CHAINID_API_HOST_MAP = { [MAINNET_CHAIN_ID]: METASWAP_ETH_API_HOST, [SWAPS_TESTNET_CHAIN_ID]: SWAPS_TESTNET_HOST, @@ -81,17 +98,20 @@ export const SWAPS_CHAINID_CONTRACT_ADDRESS_MAP = { [MAINNET_CHAIN_ID]: MAINNET_CONTRACT_ADDRESS, [SWAPS_TESTNET_CHAIN_ID]: TESTNET_CONTRACT_ADDRESS, [BSC_CHAIN_ID]: BSC_CONTRACT_ADDRESS, + [POLYGON_CHAIN_ID]: POLYGON_CONTRACT_ADDRESS, }; export const SWAPS_CHAINID_DEFAULT_TOKEN_MAP = { [MAINNET_CHAIN_ID]: ETH_SWAPS_TOKEN_OBJECT, [SWAPS_TESTNET_CHAIN_ID]: TEST_ETH_SWAPS_TOKEN_OBJECT, [BSC_CHAIN_ID]: BNB_SWAPS_TOKEN_OBJECT, + [POLYGON_CHAIN_ID]: MATIC_SWAPS_TOKEN_OBJECT, }; export const SWAPS_CHAINID_DEFAULT_BLOCK_EXPLORER_URL_MAP = { [BSC_CHAIN_ID]: BSC_DEFAULT_BLOCK_EXPLORER_URL, [MAINNET_CHAIN_ID]: MAINNET_DEFAULT_BLOCK_EXPLORER_URL, + [POLYGON_CHAIN_ID]: POLYGON_DEFAULT_BLOCK_EXPLORER_URL, }; export const ETHEREUM = 'ethereum'; diff --git a/ui/ducks/send/send.js b/ui/ducks/send/send.js index 718d78d93..33b20cb30 100644 --- a/ui/ducks/send/send.js +++ b/ui/ducks/send/send.js @@ -183,8 +183,19 @@ async function estimateGasLimitForSend({ let isSimpleSendOnNonStandardNetwork = false; // blockGasLimit may be a falsy, but defined, value when we receive it from - // state, so we use logical or to fall back to MIN_GAS_LIMIT_HEX. - const blockGasLimit = options.blockGasLimit || MIN_GAS_LIMIT_HEX; + // state, so we use logical or to fall back to MIN_GAS_LIMIT_HEX. Some + // network implementations check the gas parameter supplied to + // eth_estimateGas for validity. For this reason, we set token sends + // blockGasLimit default to a higher number. Note that the current gasLimit + // on a BLOCK is 15,000,000 and will be 30,000,000 on mainnet after London. + // Meanwhile, MIN_GAS_LIMIT_HEX is 0x5208. + let blockGasLimit = MIN_GAS_LIMIT_HEX; + if (options.blockGasLimit) { + blockGasLimit = options.blockGasLimit; + } else if (sendToken) { + blockGasLimit = GAS_LIMITS.BASE_TOKEN_ESTIMATE; + } + // The parameters below will be sent to our background process to estimate // how much gas will be used for a transaction. That background process is // located in tx-gas-utils.js in the transaction controller folder. @@ -1026,6 +1037,11 @@ const slice = createSlice({ }); } }) + .addCase(computeEstimatedGasLimit.rejected, (state) => { + // If gas estimation fails, we should set the loading state to false, + // because it is no longer loading + state.gas.isGasEstimateLoading = false; + }) .addCase(SET_BASIC_GAS_ESTIMATE_DATA, (state, action) => { // When we receive a new gasPrice via the gas duck we need to update // the gasPrice in our slice. We call into the caseReducer diff --git a/ui/pages/swaps/swaps.util.js b/ui/pages/swaps/swaps.util.js index 068c3f870..160cded10 100644 --- a/ui/pages/swaps/swaps.util.js +++ b/ui/pages/swaps/swaps.util.js @@ -77,6 +77,9 @@ const getBaseApi = function ( const baseUrl = useNewSwapsApi ? getBaseUrlForNewSwapsApi(type, chainId) : METASWAP_CHAINID_API_HOST_MAP[chainId]; + if (!baseUrl) { + throw new Error(`Swaps API calls are disabled for chainId: ${chainId}`); + } switch (type) { case 'trade': return `${baseUrl}/trades?`;