From 73c498f509de21fe58d324306384072619873baa Mon Sep 17 00:00:00 2001 From: Antonio Regadas Date: Mon, 11 Nov 2024 15:30:53 +0000 Subject: [PATCH 01/23] chore: adds SOL support --- .../lib/accounts/BalancesController.ts | 58 ++++++++++++++----- .../snap-keyring/keyring-snaps-permissions.ts | 1 + shared/constants/network.ts | 8 ++- ui/components/app/wallet-overview/index.js | 2 +- ...ories.tsx => non-evm-overview.stories.tsx} | 6 +- ...iew.test.tsx => non-evm-overview.test.tsx} | 20 +++---- ...{btc-overview.tsx => non-evm-overview.tsx} | 6 +- .../app/wallet-overview/sol-overview.tsx | 31 ++++++++++ .../account-list-menu/account-list-menu.tsx | 2 + .../account-overview-btc.stories.tsx | 12 ---- .../account-overview-non-evm.stories.tsx | 19 ++++++ ....tsx => account-overview-non-evm.test.tsx} | 12 ++-- ...w-btc.tsx => account-overview-non-evm.tsx} | 14 ++--- .../account-overview/account-overview.tsx | 11 +++- .../token-list-item/token-list-item.tsx | 7 ++- ui/hooks/useCurrencyDisplay.js | 23 +++++--- ui/selectors/multichain.ts | 48 +++++++++++---- 17 files changed, 197 insertions(+), 83 deletions(-) rename ui/components/app/wallet-overview/{btc-overview.stories.tsx => non-evm-overview.stories.tsx} (70%) rename ui/components/app/wallet-overview/{btc-overview.test.tsx => non-evm-overview.test.tsx} (93%) rename ui/components/app/wallet-overview/{btc-overview.tsx => non-evm-overview.tsx} (92%) create mode 100644 ui/components/app/wallet-overview/sol-overview.tsx delete mode 100644 ui/components/multichain/account-overview/account-overview-btc.stories.tsx create mode 100644 ui/components/multichain/account-overview/account-overview-non-evm.stories.tsx rename ui/components/multichain/account-overview/{account-overview-btc.test.tsx => account-overview-non-evm.test.tsx} (84%) rename ui/components/multichain/account-overview/{account-overview-btc.tsx => account-overview-non-evm.tsx} (50%) diff --git a/app/scripts/lib/accounts/BalancesController.ts b/app/scripts/lib/accounts/BalancesController.ts index e657fe47e64f..e7a2389e0733 100644 --- a/app/scripts/lib/accounts/BalancesController.ts +++ b/app/scripts/lib/accounts/BalancesController.ts @@ -13,6 +13,7 @@ import { type CaipAssetType, type InternalAccount, isEvmAccountType, + SolAccountType, } from '@metamask/keyring-api'; import type { HandleSnapRequest } from '@metamask/snaps-controllers'; import type { SnapId } from '@metamask/snaps-sdk'; @@ -23,7 +24,10 @@ import type { AccountsControllerAccountRemovedEvent, AccountsControllerListMultichainAccountsAction, } from '@metamask/accounts-controller'; -import { isBtcMainnetAddress } from '../../../../shared/lib/multichain'; +import { + isBtcMainnetAddress, + isSolanaAddress, +} from '../../../../shared/lib/multichain'; import { BalancesTracker } from './BalancesTracker'; const controllerName = 'BalancesController'; @@ -126,9 +130,15 @@ const BTC_TESTNET_ASSETS = ['bip122:000000000933ea01ad0ee984209779ba/slip44:0']; const BTC_MAINNET_ASSETS = ['bip122:000000000019d6689c085ae165831e93/slip44:0']; const BTC_AVG_BLOCK_TIME = 10 * 60 * 1000; // 10 minutes in milliseconds +const SOLANA_ASSETS = ['solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/slip44:501']; +const SOLANA_DEVNET_ASSETS = [ + 'solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1/slip44:501', +]; +const SOLANA_AVG_BLOCK_TIME = 400; // 400 milliseconds + // NOTE: We set an interval of half the average block time to mitigate when our interval // is de-synchronized with the actual block time. -export const BALANCES_UPDATE_TIME = BTC_AVG_BLOCK_TIME / 2; +export const BTC_BALANCES_UPDATE_TIME = BTC_AVG_BLOCK_TIME / 2; /** * The BalancesController is responsible for fetching and caching account @@ -165,7 +175,11 @@ export class BalancesController extends BaseController< // Register all non-EVM accounts into the tracker for (const account of this.#listAccounts()) { if (this.#isNonEvmAccount(account)) { - this.#tracker.track(account.id, BALANCES_UPDATE_TIME); + const updateTime = + account.type === BtcAccountType.P2wpkh + ? BTC_BALANCES_UPDATE_TIME + : SOLANA_AVG_BLOCK_TIME; + this.#tracker.track(account.id, updateTime); } } @@ -207,15 +221,16 @@ export class BalancesController extends BaseController< /** * Lists the accounts that we should get balances for. * - * Currently, we only get balances for P2WPKH accounts, but this will change - * in the future when we start support other non-EVM account types. - * * @returns A list of accounts that we should get balances for. */ #listAccounts(): InternalAccount[] { const accounts = this.#listMultichainAccounts(); - return accounts.filter((account) => account.type === BtcAccountType.P2wpkh); + return accounts.filter( + (account) => + account.type === SolAccountType.DataAccount || + account.type === BtcAccountType.P2wpkh, + ); } /** @@ -249,13 +264,21 @@ export class BalancesController extends BaseController< const partialState: BalancesControllerState = { balances: {} }; if (account.metadata.snap) { - partialState.balances[account.id] = await this.#getBalances( - account.id, - account.metadata.snap.id, - isBtcMainnetAddress(account.address) - ? BTC_MAINNET_ASSETS - : BTC_TESTNET_ASSETS, - ); + // In here we need to check which assets to query + let assetTypes: CaipAssetType[]; + if (isSolanaAddress(account.address)) { + assetTypes = SOLANA_ASSETS; + } else if (isBtcMainnetAddress(account.address)) { + assetTypes = BTC_MAINNET_ASSETS; + } else { + // If not mainnet, we need to check if it's testnet or devnet + assetTypes = + account.type === BtcAccountType.P2wpkh + ? BTC_TESTNET_ASSETS + : SOLANA_DEVNET_ASSETS; + } + + await this.#getBalances(account.id, account.metadata.snap.id, assetTypes); } this.update((state: Draft) => ({ @@ -312,8 +335,11 @@ export class BalancesController extends BaseController< return; } - this.#tracker.track(account.id, BTC_AVG_BLOCK_TIME); - // NOTE: Unfortunately, we cannot update the balance right away here, because + const updateTime = + account.type === BtcAccountType.P2wpkh + ? BTC_AVG_BLOCK_TIME + : SOLANA_AVG_BLOCK_TIME; + this.#tracker.track(account.id, updateTime); // NOTE: Unfortunately, we cannot update the balance right away here, because // messenger's events are running synchronously and fetching the balance is // asynchronous. // Updating the balance here would resume at some point but the event emitter diff --git a/app/scripts/lib/snap-keyring/keyring-snaps-permissions.ts b/app/scripts/lib/snap-keyring/keyring-snaps-permissions.ts index f7d9c829a3cc..9cc8713f7aa5 100644 --- a/app/scripts/lib/snap-keyring/keyring-snaps-permissions.ts +++ b/app/scripts/lib/snap-keyring/keyring-snaps-permissions.ts @@ -8,6 +8,7 @@ import { KeyringRpcMethod } from '@metamask/keyring-api'; * The origins of the Portfolio dapp. */ const PORTFOLIO_ORIGINS: string[] = [ + 'http://localhost:3000', 'https://portfolio.metamask.io', ///: BEGIN:ONLY_INCLUDE_IF(build-flask) 'https://dev.portfolio.metamask.io', diff --git a/shared/constants/network.ts b/shared/constants/network.ts index 4844e7c2e981..ef31a23364d4 100644 --- a/shared/constants/network.ts +++ b/shared/constants/network.ts @@ -299,7 +299,6 @@ export const CURRENCY_SYMBOLS = { AVALANCHE: 'AVAX', BNB: 'BNB', BUSD: 'BUSD', - BTC: 'BTC', // Do we wanna mix EVM and non-EVM here? CELO: 'CELO', DAI: 'DAI', GNOSIS: 'XDAI', @@ -320,8 +319,15 @@ export const CURRENCY_SYMBOLS = { ONE: 'ONE', } as const; +// Non-EVM currency symbols +export const NON_EVM_CURRENCY_SYMBOLS = { + BTC: 'BTC', + SOL: 'SOL', +} as const; + const CHAINLIST_CURRENCY_SYMBOLS_MAP = { ...CURRENCY_SYMBOLS, + ...NON_EVM_CURRENCY_SYMBOLS, BASE: 'ETH', LINEA_MAINNET: 'ETH', OPBNB: 'BNB', diff --git a/ui/components/app/wallet-overview/index.js b/ui/components/app/wallet-overview/index.js index 54536007bc41..82003b364199 100644 --- a/ui/components/app/wallet-overview/index.js +++ b/ui/components/app/wallet-overview/index.js @@ -1,2 +1,2 @@ export { default as EthOverview } from './eth-overview'; -export { default as BtcOverview } from './btc-overview'; +export { default as NonEvmOverview } from './non-evm-overview'; diff --git a/ui/components/app/wallet-overview/btc-overview.stories.tsx b/ui/components/app/wallet-overview/non-evm-overview.stories.tsx similarity index 70% rename from ui/components/app/wallet-overview/btc-overview.stories.tsx rename to ui/components/app/wallet-overview/non-evm-overview.stories.tsx index 43dff2554bef..2e8ae16045ce 100644 --- a/ui/components/app/wallet-overview/btc-overview.stories.tsx +++ b/ui/components/app/wallet-overview/non-evm-overview.stories.tsx @@ -1,9 +1,9 @@ import React from 'react'; -import BtcOverview from './btc-overview'; +import NonEvmOverview from './non-evm-overview'; export default { title: 'Components/App/WalletOverview/BtcOverview', - component: BtcOverview, + component: NonEvmOverview, parameters: { docs: { description: { @@ -14,6 +14,6 @@ export default { }, }; -const Template = (args) => ; +const Template = (args) => ; export const Default = Template.bind({}); diff --git a/ui/components/app/wallet-overview/btc-overview.test.tsx b/ui/components/app/wallet-overview/non-evm-overview.test.tsx similarity index 93% rename from ui/components/app/wallet-overview/btc-overview.test.tsx rename to ui/components/app/wallet-overview/non-evm-overview.test.tsx index ffaed244e958..f248bba7c121 100644 --- a/ui/components/app/wallet-overview/btc-overview.test.tsx +++ b/ui/components/app/wallet-overview/non-evm-overview.test.tsx @@ -11,7 +11,7 @@ import { MultichainNetworks } from '../../../../shared/constants/multichain/netw import { RampsMetaMaskEntry } from '../../../hooks/ramps/useRamps/useRamps'; import { defaultBuyableChains } from '../../../ducks/ramps/constants'; import { setBackgroundConnection } from '../../../store/background-connection'; -import BtcOverview from './btc-overview'; +import NonEvmOverview from './non-evm-overview'; const PORTOFOLIO_URL = 'https://portfolio.test'; @@ -113,7 +113,7 @@ describe('BtcOverview', () => { }); it('shows the primary balance as BTC when showNativeTokenAsMainBalance if true', async () => { - const { queryByTestId } = renderWithProvider(, getStore()); + const { queryByTestId } = renderWithProvider(, getStore()); const primaryBalance = queryByTestId(BTC_OVERVIEW_PRIMARY_CURRENCY); expect(primaryBalance).toBeInTheDocument(); @@ -122,7 +122,7 @@ describe('BtcOverview', () => { it('shows the primary balance as fiat when showNativeTokenAsMainBalance if false', async () => { const { queryByTestId } = renderWithProvider( - , + , getStore({ metamask: { ...mockMetamaskStore, @@ -141,7 +141,7 @@ describe('BtcOverview', () => { it('shows a spinner if balance is not available', async () => { const { container } = renderWithProvider( - , + , getStore({ metamask: { ...mockMetamaskStore, @@ -158,7 +158,7 @@ describe('BtcOverview', () => { }); it('buttons Swap/Bridge are disabled', () => { - const { queryByTestId } = renderWithProvider(, getStore()); + const { queryByTestId } = renderWithProvider(, getStore()); for (const buttonTestId of [BTC_OVERVIEW_SWAP, BTC_OVERVIEW_BRIDGE]) { const button = queryByTestId(buttonTestId); @@ -168,13 +168,13 @@ describe('BtcOverview', () => { }); it('shows the "Buy & Sell" button', () => { - const { queryByTestId } = renderWithProvider(, getStore()); + const { queryByTestId } = renderWithProvider(, getStore()); const buyButton = queryByTestId(BTC_OVERVIEW_BUY); expect(buyButton).toBeInTheDocument(); }); it('"Buy & Sell" button is disabled if BTC is not buyable', () => { - const { queryByTestId } = renderWithProvider(, getStore()); + const { queryByTestId } = renderWithProvider(, getStore()); const buyButton = queryByTestId(BTC_OVERVIEW_BUY); expect(buyButton).toBeInTheDocument(); @@ -189,7 +189,7 @@ describe('BtcOverview', () => { }); const { queryByTestId } = renderWithProvider( - , + , storeWithBtcBuyable, ); @@ -207,7 +207,7 @@ describe('BtcOverview', () => { }); const { queryByTestId } = renderWithProvider( - , + , storeWithBtcBuyable, ); @@ -229,7 +229,7 @@ describe('BtcOverview', () => { }); it('always show the Receive button', () => { - const { queryByTestId } = renderWithProvider(, getStore()); + const { queryByTestId } = renderWithProvider(, getStore()); const receiveButton = queryByTestId(BTC_OVERVIEW_RECEIVE); expect(receiveButton).toBeInTheDocument(); }); diff --git a/ui/components/app/wallet-overview/btc-overview.tsx b/ui/components/app/wallet-overview/non-evm-overview.tsx similarity index 92% rename from ui/components/app/wallet-overview/btc-overview.tsx rename to ui/components/app/wallet-overview/non-evm-overview.tsx index 2ddaefd92f58..62843815f37c 100644 --- a/ui/components/app/wallet-overview/btc-overview.tsx +++ b/ui/components/app/wallet-overview/non-evm-overview.tsx @@ -14,11 +14,11 @@ import { useMultichainSelector } from '../../../hooks/useMultichainSelector'; ///: END:ONLY_INCLUDE_IF import { CoinOverview } from './coin-overview'; -type BtcOverviewProps = { +type NonEvmOverviewProps = { className?: string; }; -const BtcOverview = ({ className }: BtcOverviewProps) => { +const NonEvmOverview = ({ className }: NonEvmOverviewProps) => { const { chainId } = useSelector(getMultichainProviderConfig); const balance = useSelector(getMultichainSelectedAccountCachedBalance); ///: BEGIN:ONLY_INCLUDE_IF(build-main,build-beta,build-flask) @@ -47,4 +47,4 @@ const BtcOverview = ({ className }: BtcOverviewProps) => { ); }; -export default BtcOverview; +export default NonEvmOverview; diff --git a/ui/components/app/wallet-overview/sol-overview.tsx b/ui/components/app/wallet-overview/sol-overview.tsx new file mode 100644 index 000000000000..3e600a919a38 --- /dev/null +++ b/ui/components/app/wallet-overview/sol-overview.tsx @@ -0,0 +1,31 @@ +import React from 'react'; +import { useSelector } from 'react-redux'; +import { + getMultichainProviderConfig, + getMultichainSelectedAccountCachedBalance, +} from '../../../selectors/multichain'; +import { CoinOverview } from './coin-overview'; + +type SolOverviewProps = { + className?: string; +}; + +const SolOverview = ({ className }: SolOverviewProps) => { + const { chainId } = useSelector(getMultichainProviderConfig); + const balance = useSelector(getMultichainSelectedAccountCachedBalance); + + return ( + + ); +}; + +export default SolOverview; diff --git a/ui/components/multichain/account-list-menu/account-list-menu.tsx b/ui/components/multichain/account-list-menu/account-list-menu.tsx index 75d04e9e60e0..34e47bf1276a 100644 --- a/ui/components/multichain/account-list-menu/account-list-menu.tsx +++ b/ui/components/multichain/account-list-menu/account-list-menu.tsx @@ -12,6 +12,7 @@ import { useDispatch, useSelector } from 'react-redux'; import { BtcAccountType, EthAccountType, + SolAccountType, ///: BEGIN:ONLY_INCLUDE_IF(build-flask) InternalAccount, KeyringAccountType, @@ -218,6 +219,7 @@ export const AccountListMenu = ({ EthAccountType.Eoa, EthAccountType.Erc4337, BtcAccountType.P2wpkh, + SolAccountType.DataAccount, ], }: AccountListMenuProps) => { const t = useI18nContext(); diff --git a/ui/components/multichain/account-overview/account-overview-btc.stories.tsx b/ui/components/multichain/account-overview/account-overview-btc.stories.tsx deleted file mode 100644 index 2afc54e22b23..000000000000 --- a/ui/components/multichain/account-overview/account-overview-btc.stories.tsx +++ /dev/null @@ -1,12 +0,0 @@ -import React from 'react'; -import { AccountOverviewBtc } from './account-overview-btc' -import { AccountOverviewCommonProps } from './common'; - -export default { - title: 'Components/Multichain/AccountOverviewBtc', - component: AccountOverviewBtc, -}; - -export const DefaultStory = ( - args: JSX.IntrinsicAttributes & AccountOverviewCommonProps -) => ; diff --git a/ui/components/multichain/account-overview/account-overview-non-evm.stories.tsx b/ui/components/multichain/account-overview/account-overview-non-evm.stories.tsx new file mode 100644 index 000000000000..de3ac5484baf --- /dev/null +++ b/ui/components/multichain/account-overview/account-overview-non-evm.stories.tsx @@ -0,0 +1,19 @@ +import React from 'react'; +import { AccountOverviewNonEvm } from './account-overview-non-evm'; +import { AccountOverviewCommonProps } from './common'; +import { BtcAccountType, SolAccountType } from '@metamask/keyring-api'; + +export default { + title: 'Components/Multichain/AccountOverviewNonEvm', + component: AccountOverviewNonEvm, + args: { + accountType: BtcAccountType.P2wpkh, + }, +}; + +export const DefaultStory = ( + args: JSX.IntrinsicAttributes & + AccountOverviewCommonProps & { + accountType: BtcAccountType.P2wpkh | SolAccountType.DataAccount; + }, +) => ; diff --git a/ui/components/multichain/account-overview/account-overview-btc.test.tsx b/ui/components/multichain/account-overview/account-overview-non-evm.test.tsx similarity index 84% rename from ui/components/multichain/account-overview/account-overview-btc.test.tsx rename to ui/components/multichain/account-overview/account-overview-non-evm.test.tsx index 9d265657432b..cf0323f7eb2b 100644 --- a/ui/components/multichain/account-overview/account-overview-btc.test.tsx +++ b/ui/components/multichain/account-overview/account-overview-non-evm.test.tsx @@ -4,23 +4,23 @@ import configureStore from '../../../store/store'; import { renderWithProvider } from '../../../../test/jest/rendering'; import { setBackgroundConnection } from '../../../store/background-connection'; import { - AccountOverviewBtc, - AccountOverviewBtcProps, -} from './account-overview-btc'; + AccountOverviewNonEvm, + AccountOverviewNonEvmProps, +} from './account-overview-non-evm'; -const defaultProps: AccountOverviewBtcProps = { +const defaultProps: AccountOverviewNonEvmProps = { defaultHomeActiveTabName: '', onTabClick: jest.fn(), setBasicFunctionalityModalOpen: jest.fn(), onSupportLinkClick: jest.fn(), }; -const render = (props: AccountOverviewBtcProps = defaultProps) => { +const render = (props: AccountOverviewNonEvmProps = defaultProps) => { const store = configureStore({ metamask: mockState.metamask, }); - return renderWithProvider(, store); + return renderWithProvider(, store); }; describe('AccountOverviewBtc', () => { diff --git a/ui/components/multichain/account-overview/account-overview-btc.tsx b/ui/components/multichain/account-overview/account-overview-non-evm.tsx similarity index 50% rename from ui/components/multichain/account-overview/account-overview-btc.tsx rename to ui/components/multichain/account-overview/account-overview-non-evm.tsx index dd58b2eef414..86b6b7973175 100644 --- a/ui/components/multichain/account-overview/account-overview-btc.tsx +++ b/ui/components/multichain/account-overview/account-overview-non-evm.tsx @@ -1,11 +1,13 @@ import React from 'react'; -import { BtcOverview } from '../../app/wallet-overview'; +import { NonEvmOverview } from '../../app/wallet-overview'; import { AccountOverviewLayout } from './account-overview-layout'; import { AccountOverviewCommonProps } from './common'; -export type AccountOverviewBtcProps = AccountOverviewCommonProps; +export type AccountOverviewNonEvmProps = AccountOverviewCommonProps; -export const AccountOverviewBtc = (props: AccountOverviewBtcProps) => { +export const AccountOverviewNonEvm = ({ + ...props +}: AccountOverviewNonEvmProps) => { return ( { showActivity={true} {...props} > - { - ///: BEGIN:ONLY_INCLUDE_IF(build-main,build-beta,build-flask,build-mmi) - - ///: END:ONLY_INCLUDE_IF - } + ); }; diff --git a/ui/components/multichain/account-overview/account-overview.tsx b/ui/components/multichain/account-overview/account-overview.tsx index 3d6121e41471..f3f3e427a688 100644 --- a/ui/components/multichain/account-overview/account-overview.tsx +++ b/ui/components/multichain/account-overview/account-overview.tsx @@ -1,13 +1,17 @@ import React from 'react'; import { useSelector } from 'react-redux'; -import { BtcAccountType, EthAccountType } from '@metamask/keyring-api'; +import { + BtcAccountType, + EthAccountType, + SolAccountType, +} from '@metamask/keyring-api'; import { useI18nContext } from '../../../hooks/useI18nContext'; import { BannerAlert, BannerAlertSeverity } from '../../component-library'; import { getSelectedInternalAccount } from '../../../selectors'; import { AccountOverviewEth } from './account-overview-eth'; -import { AccountOverviewBtc } from './account-overview-btc'; import { AccountOverviewUnknown } from './account-overview-unknown'; import { AccountOverviewCommonProps } from './common'; +import { AccountOverviewNonEvm } from './account-overview-non-evm'; export type AccountOverviewProps = AccountOverviewCommonProps & { useExternalServices: boolean; @@ -25,7 +29,8 @@ export function AccountOverview(props: AccountOverviewProps) { case EthAccountType.Erc4337: return ; case BtcAccountType.P2wpkh: - return ; + case SolAccountType.DataAccount: + return ; default: return ; } diff --git a/ui/components/multichain/token-list-item/token-list-item.tsx b/ui/components/multichain/token-list-item/token-list-item.tsx index bf3968963465..6da0a7a56c2e 100644 --- a/ui/components/multichain/token-list-item/token-list-item.tsx +++ b/ui/components/multichain/token-list-item/token-list-item.tsx @@ -57,7 +57,10 @@ import { MetaMetricsEventCategory, MetaMetricsEventName, } from '../../../../shared/constants/metametrics'; -import { CURRENCY_SYMBOLS } from '../../../../shared/constants/network'; +import { + CURRENCY_SYMBOLS, + NON_EVM_CURRENCY_SYMBOLS, +} from '../../../../shared/constants/network'; import { hexToDecimal } from '../../../../shared/modules/conversion.utils'; import { NETWORKS_ROUTE } from '../../../helpers/constants/routes'; @@ -142,7 +145,7 @@ export const TokenListItem = ({ switch (title) { case CURRENCY_SYMBOLS.ETH: return t('networkNameEthereum'); - case CURRENCY_SYMBOLS.BTC: + case NON_EVM_CURRENCY_SYMBOLS.BTC: return t('networkNameBitcoin'); default: return title; diff --git a/ui/hooks/useCurrencyDisplay.js b/ui/hooks/useCurrencyDisplay.js index 12b2cfc06ec3..0f18231c5c10 100644 --- a/ui/hooks/useCurrencyDisplay.js +++ b/ui/hooks/useCurrencyDisplay.js @@ -1,5 +1,6 @@ import { useMemo } from 'react'; import BigNumber from 'bignumber.js'; +import { BtcAccountType } from '@metamask/keyring-api'; import { formatCurrency } from '../helpers/utils/confirm-tx.util'; import { getMultichainCurrentCurrency, @@ -9,7 +10,10 @@ import { } from '../selectors/multichain'; import { getValueFromWeiHex } from '../../shared/modules/conversion.utils'; -import { TEST_NETWORK_TICKER_MAP } from '../../shared/constants/network'; +import { + TEST_NETWORK_TICKER_MAP, + NON_EVM_CURRENCY_SYMBOLS, +} from '../../shared/constants/network'; import { Numeric } from '../../shared/modules/Numeric'; import { EtherDenomination } from '../../shared/constants/common'; import { getTokenFiatAmount } from '../helpers/utils/token-util'; @@ -62,7 +66,8 @@ function formatEthCurrencyDisplay({ return null; } -function formatBtcCurrencyDisplay({ +function formatNonEvmAssetCurrencyDisplay({ + nonEvmAsset, isNativeCurrency, isUserPreferredCurrency, currency, @@ -77,15 +82,19 @@ function formatBtcCurrencyDisplay({ // We use `Numeric` here, so we handle those amount the same way than for EVMs (it's worth // noting that if `inputValue` is not properly defined, the amount will be set to '0', see // `Numeric` constructor for that) - return new Numeric(inputValue, 10).toString(); // BTC usually uses 10 digits + return new Numeric(inputValue, 10).toString(); } else if (isUserPreferredCurrency && conversionRate) { + const nonEvmAssetSymbol = + nonEvmAsset === BtcAccountType.P2wpkh + ? NON_EVM_CURRENCY_SYMBOLS.BTC + : NON_EVM_CURRENCY_SYMBOLS.SOL; const amount = getTokenFiatAmount( 1, // coin to native conversion rate is 1:1 Number(conversionRate), // native to fiat conversion rate currentCurrency, inputValue, - 'BTC', + nonEvmAssetSymbol, false, false, ) ?? '0'; // if the conversion fails, return 0 @@ -161,9 +170,9 @@ export function useCurrencyDisplay( return displayValue; } - if (!isEvm) { - // TODO: We would need to update this for other non-EVM coins - return formatBtcCurrencyDisplay({ + if (!isEvm && account) { + return formatNonEvmAssetCurrencyDisplay({ + nonEvmAsset: account.type, isNativeCurrency, isUserPreferredCurrency, currency, diff --git a/ui/selectors/multichain.ts b/ui/selectors/multichain.ts index 96266687b6df..82bf6150a5e5 100644 --- a/ui/selectors/multichain.ts +++ b/ui/selectors/multichain.ts @@ -1,5 +1,10 @@ import PropTypes from 'prop-types'; -import { InternalAccount, isEvmAccountType } from '@metamask/keyring-api'; +import { + BtcAccountType, + InternalAccount, + isEvmAccountType, + SolAccountType, +} from '@metamask/keyring-api'; import type { RatesControllerState } from '@metamask/assets-controllers'; import { CaipChainId, Hex, KnownCaipNamespace } from '@metamask/utils'; import { createSelector } from 'reselect'; @@ -322,11 +327,19 @@ export function getMultichainIsMainnet( ) { const selectedAccount = account ?? getSelectedInternalAccount(state); const providerConfig = getMultichainProviderConfig(state, selectedAccount); - return getMultichainIsEvm(state, account) - ? getIsMainnet(state) - : // TODO: For now we only check for bitcoin, but we will need to - // update this for other non-EVM networks later! - providerConfig.chainId === MultichainNetworks.BITCOIN; + + if (getMultichainIsEvm(state, account)) { + return getIsMainnet(state); + } + + const mainnetMap = { + [SolAccountType.DataAccount]: + providerConfig.chainId === MultichainNetworks.SOLANA, + [BtcAccountType.P2wpkh]: + providerConfig.chainId === MultichainNetworks.BITCOIN, + }; + + return mainnetMap[selectedAccount.type as keyof typeof mainnetMap] ?? false; } export function getMultichainIsTestnet( @@ -359,12 +372,25 @@ export const getMultichainCoinRates = (state: MultichainState) => { return state.metamask.rates; }; -function getBtcCachedBalance(state: MultichainState) { +function getNonEvmCachedBalance(state: MultichainState) { const balances = getMultichainBalances(state); const account = getSelectedInternalAccount(state); - const asset = getMultichainIsMainnet(state) - ? MultichainNativeAssets.BITCOIN - : MultichainNativeAssets.BITCOIN_TESTNET; + const isMainnet = getMultichainIsMainnet(state); + + const assetMap = { + [SolAccountType.DataAccount]: isMainnet + ? MultichainNativeAssets.SOLANA + : MultichainNativeAssets.SOLANA_DEVNET, + [BtcAccountType.P2wpkh]: isMainnet + ? MultichainNativeAssets.BITCOIN + : MultichainNativeAssets.BITCOIN_TESTNET, + }; + + const asset = + assetMap[account.type as keyof typeof assetMap] ?? + (isMainnet + ? MultichainNativeAssets.BITCOIN + : MultichainNativeAssets.BITCOIN_TESTNET); return balances?.[account.id]?.[asset]?.amount; } @@ -376,7 +402,7 @@ export function getMultichainSelectedAccountCachedBalance( ) { return getMultichainIsEvm(state) ? getSelectedAccountCachedBalance(state) - : getBtcCachedBalance(state); + : getNonEvmCachedBalance(state); } export const getMultichainSelectedAccountCachedBalanceIsZero = createSelector( From dd6fcbfdd1cdf25fbedbf2055581c508b50011fd Mon Sep 17 00:00:00 2001 From: Antonio Regadas Date: Tue, 12 Nov 2024 09:22:47 +0000 Subject: [PATCH 02/23] chore: prettier run --- .../wallet-overview/non-evm-overview.test.tsx | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/ui/components/app/wallet-overview/non-evm-overview.test.tsx b/ui/components/app/wallet-overview/non-evm-overview.test.tsx index f248bba7c121..53e7c24b1e13 100644 --- a/ui/components/app/wallet-overview/non-evm-overview.test.tsx +++ b/ui/components/app/wallet-overview/non-evm-overview.test.tsx @@ -113,7 +113,10 @@ describe('BtcOverview', () => { }); it('shows the primary balance as BTC when showNativeTokenAsMainBalance if true', async () => { - const { queryByTestId } = renderWithProvider(, getStore()); + const { queryByTestId } = renderWithProvider( + , + getStore(), + ); const primaryBalance = queryByTestId(BTC_OVERVIEW_PRIMARY_CURRENCY); expect(primaryBalance).toBeInTheDocument(); @@ -158,7 +161,10 @@ describe('BtcOverview', () => { }); it('buttons Swap/Bridge are disabled', () => { - const { queryByTestId } = renderWithProvider(, getStore()); + const { queryByTestId } = renderWithProvider( + , + getStore(), + ); for (const buttonTestId of [BTC_OVERVIEW_SWAP, BTC_OVERVIEW_BRIDGE]) { const button = queryByTestId(buttonTestId); @@ -168,13 +174,19 @@ describe('BtcOverview', () => { }); it('shows the "Buy & Sell" button', () => { - const { queryByTestId } = renderWithProvider(, getStore()); + const { queryByTestId } = renderWithProvider( + , + getStore(), + ); const buyButton = queryByTestId(BTC_OVERVIEW_BUY); expect(buyButton).toBeInTheDocument(); }); it('"Buy & Sell" button is disabled if BTC is not buyable', () => { - const { queryByTestId } = renderWithProvider(, getStore()); + const { queryByTestId } = renderWithProvider( + , + getStore(), + ); const buyButton = queryByTestId(BTC_OVERVIEW_BUY); expect(buyButton).toBeInTheDocument(); @@ -229,7 +241,10 @@ describe('BtcOverview', () => { }); it('always show the Receive button', () => { - const { queryByTestId } = renderWithProvider(, getStore()); + const { queryByTestId } = renderWithProvider( + , + getStore(), + ); const receiveButton = queryByTestId(BTC_OVERVIEW_RECEIVE); expect(receiveButton).toBeInTheDocument(); }); @@ -254,7 +269,7 @@ describe('BtcOverview', () => { }); const { queryByTestId } = renderWithProvider( - , + , storeWithBtcBuyable, ); From 8a51986f250554e9b865813728933110ec6d1bf5 Mon Sep 17 00:00:00 2001 From: Antonio Regadas Date: Tue, 12 Nov 2024 10:07:14 +0000 Subject: [PATCH 03/23] chore: clean up --- .../app/wallet-overview/sol-overview.tsx | 31 ------------------- 1 file changed, 31 deletions(-) delete mode 100644 ui/components/app/wallet-overview/sol-overview.tsx diff --git a/ui/components/app/wallet-overview/sol-overview.tsx b/ui/components/app/wallet-overview/sol-overview.tsx deleted file mode 100644 index 3e600a919a38..000000000000 --- a/ui/components/app/wallet-overview/sol-overview.tsx +++ /dev/null @@ -1,31 +0,0 @@ -import React from 'react'; -import { useSelector } from 'react-redux'; -import { - getMultichainProviderConfig, - getMultichainSelectedAccountCachedBalance, -} from '../../../selectors/multichain'; -import { CoinOverview } from './coin-overview'; - -type SolOverviewProps = { - className?: string; -}; - -const SolOverview = ({ className }: SolOverviewProps) => { - const { chainId } = useSelector(getMultichainProviderConfig); - const balance = useSelector(getMultichainSelectedAccountCachedBalance); - - return ( - - ); -}; - -export default SolOverview; From a56008b364a8e8f059a00eccc0c3928239e7a38e Mon Sep 17 00:00:00 2001 From: Antonio Regadas Date: Tue, 12 Nov 2024 10:20:39 +0000 Subject: [PATCH 04/23] chore: adds comment and btc check for now --- ui/components/app/wallet-overview/non-evm-overview.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ui/components/app/wallet-overview/non-evm-overview.tsx b/ui/components/app/wallet-overview/non-evm-overview.tsx index 62843815f37c..9ffc972e313a 100644 --- a/ui/components/app/wallet-overview/non-evm-overview.tsx +++ b/ui/components/app/wallet-overview/non-evm-overview.tsx @@ -13,6 +13,7 @@ import { getSelectedInternalAccount } from '../../../selectors'; import { useMultichainSelector } from '../../../hooks/useMultichainSelector'; ///: END:ONLY_INCLUDE_IF import { CoinOverview } from './coin-overview'; +import { BtcAccountType, SolAccountType } from '@metamask/keyring-api'; type NonEvmOverviewProps = { className?: string; @@ -28,6 +29,11 @@ const NonEvmOverview = ({ className }: NonEvmOverviewProps) => { selectedAccount, ); const isBtcBuyable = useSelector(getIsBitcoinBuyable); + + // TODO: Update this to add support to check if Solana is buyable when the Send flow starts + const accountType = selectedAccount.type; + const isBtc = accountType === BtcAccountType.P2wpkh; + const isBuyableChain = isBtc ? isBtcBuyable && isBtcMainnetAccount : false; ///: END:ONLY_INCLUDE_IF return ( @@ -41,7 +47,7 @@ const NonEvmOverview = ({ className }: NonEvmOverviewProps) => { isSwapsChain={false} ///: BEGIN:ONLY_INCLUDE_IF(build-main,build-beta,build-flask) isBridgeChain={false} - isBuyableChain={isBtcBuyable && isBtcMainnetAccount} + isBuyableChain={isBuyableChain} ///: END:ONLY_INCLUDE_IF /> ); From f503046c41cfb533f53024f9ec758d35f53066a8 Mon Sep 17 00:00:00 2001 From: Antonio Regadas Date: Tue, 12 Nov 2024 13:34:55 +0000 Subject: [PATCH 05/23] chore: updates packages version to support Solana --- package.json | 12 ++++++-- .../app/wallet-overview/non-evm-overview.tsx | 4 ++- yarn.lock | 29 ++++++++++--------- 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index 39a5bb13b596..d1c149ef6d76 100644 --- a/package.json +++ b/package.json @@ -250,7 +250,13 @@ "@metamask/network-controller@npm:^17.0.0": "patch:@metamask/network-controller@npm%3A21.0.0#~/.yarn/patches/@metamask-network-controller-npm-21.0.0-559aa8e395.patch", "@metamask/network-controller@npm:^19.0.0": "patch:@metamask/network-controller@npm%3A21.0.0#~/.yarn/patches/@metamask-network-controller-npm-21.0.0-559aa8e395.patch", "@metamask/network-controller@npm:^20.0.0": "patch:@metamask/network-controller@npm%3A21.0.0#~/.yarn/patches/@metamask-network-controller-npm-21.0.0-559aa8e395.patch", - "path-to-regexp": "1.9.0" + "path-to-regexp": "1.9.0", + "@metamask/keyring-api@^8.1.3": "npm:@metamask/keyring-api@10.1.0", + "@metamask/keyring-api@^8.0.0": "npm:@metamask/keyring-api@10.1.0", + "@metamask/keyring-api@9.0.0": "npm:@metamask/keyring-api@10.1.0", + "@metamask/eth-snap-keyring@^4.4.0": "npm:@metamask/eth-snap-keyring@5.0.1", + "@metamask/eth-snap-keyring@^4.3.1": "npm:@metamask/eth-snap-keyring@5.0.1", + "@metamask/eth-snap-keyring@^4.3.6": "npm:@metamask/eth-snap-keyring@5.0.1" }, "dependencies": { "@babel/runtime": "patch:@babel/runtime@npm%3A7.25.9#~/.yarn/patches/@babel-runtime-npm-7.25.9-fe8c62510a.patch", @@ -300,7 +306,7 @@ "@metamask/eth-ledger-bridge-keyring": "^3.0.1", "@metamask/eth-query": "^4.0.0", "@metamask/eth-sig-util": "^7.0.1", - "@metamask/eth-snap-keyring": "^4.4.0", + "@metamask/eth-snap-keyring": "^5.0.1", "@metamask/eth-token-tracker": "^8.0.0", "@metamask/eth-trezor-keyring": "^3.1.3", "@metamask/etherscan-link": "^3.0.0", @@ -311,7 +317,7 @@ "@metamask/jazzicon": "^2.0.0", "@metamask/json-rpc-engine": "^10.0.0", "@metamask/json-rpc-middleware-stream": "^8.0.4", - "@metamask/keyring-api": "^8.1.3", + "@metamask/keyring-api": "^10.1.0", "@metamask/keyring-controller": "^17.2.2", "@metamask/logging-controller": "^6.0.0", "@metamask/logo": "^3.1.2", diff --git a/ui/components/app/wallet-overview/non-evm-overview.tsx b/ui/components/app/wallet-overview/non-evm-overview.tsx index 9ffc972e313a..d2497a04fe9c 100644 --- a/ui/components/app/wallet-overview/non-evm-overview.tsx +++ b/ui/components/app/wallet-overview/non-evm-overview.tsx @@ -1,5 +1,8 @@ import React from 'react'; import { useSelector } from 'react-redux'; +///: BEGIN:ONLY_INCLUDE_IF(build-main,build-beta,build-flask) +import { BtcAccountType } from '@metamask/keyring-api'; +///: END:ONLY_INCLUDE_IF import { ///: BEGIN:ONLY_INCLUDE_IF(build-main,build-beta,build-flask) getMultichainIsMainnet, @@ -13,7 +16,6 @@ import { getSelectedInternalAccount } from '../../../selectors'; import { useMultichainSelector } from '../../../hooks/useMultichainSelector'; ///: END:ONLY_INCLUDE_IF import { CoinOverview } from './coin-overview'; -import { BtcAccountType, SolAccountType } from '@metamask/keyring-api'; type NonEvmOverviewProps = { className?: string; diff --git a/yarn.lock b/yarn.lock index 95217329e1c3..1f0a28b6a8a2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5276,12 +5276,12 @@ __metadata: languageName: node linkType: hard -"@metamask/eth-snap-keyring@npm:^4.3.1, @metamask/eth-snap-keyring@npm:^4.3.6, @metamask/eth-snap-keyring@npm:^4.4.0": - version: 4.4.0 - resolution: "@metamask/eth-snap-keyring@npm:4.4.0" +"@metamask/eth-snap-keyring@npm:@metamask/eth-snap-keyring@5.0.1, @metamask/eth-snap-keyring@npm:^5.0.1": + version: 5.0.1 + resolution: "@metamask/eth-snap-keyring@npm:5.0.1" dependencies: "@ethereumjs/tx": "npm:^4.2.0" - "@metamask/eth-sig-util": "npm:^7.0.3" + "@metamask/eth-sig-util": "npm:^8.0.0" "@metamask/snaps-controllers": "npm:^9.10.0" "@metamask/snaps-sdk": "npm:^6.7.0" "@metamask/snaps-utils": "npm:^8.3.0" @@ -5290,8 +5290,8 @@ __metadata: "@types/uuid": "npm:^9.0.8" uuid: "npm:^9.0.1" peerDependencies: - "@metamask/keyring-api": ^8.1.3 - checksum: 10/fd9926ba3706506bd9a16d1c2501e7c6cd7b7e3e7ea332bc7f28e0fca1f67f4514da51e6f9f4541a7354a2363d04c09c445f61b98fdc366432e1def9c2f27d07 + "@metamask/keyring-api": ^10.1.0 + checksum: 10/4d9d700b7c2ecc1b17e92f716f7aeb04bbd03836601b5d37f639bed7fba4d5f00bafadf5359d2416c319cdf18eb2f9417c7353654737af87a6e8579d5e5bab79 languageName: node linkType: hard @@ -5559,19 +5559,20 @@ __metadata: languageName: node linkType: hard -"@metamask/keyring-api@npm:^8.0.0, @metamask/keyring-api@npm:^8.1.3": - version: 8.1.3 - resolution: "@metamask/keyring-api@npm:8.1.3" +"@metamask/keyring-api@npm:@metamask/keyring-api@10.1.0, @metamask/keyring-api@npm:^10.1.0": + version: 10.1.0 + resolution: "@metamask/keyring-api@npm:10.1.0" dependencies: - "@metamask/snaps-sdk": "npm:^6.5.1" + "@metamask/snaps-sdk": "npm:^6.7.0" "@metamask/superstruct": "npm:^3.1.0" "@metamask/utils": "npm:^9.2.1" "@types/uuid": "npm:^9.0.8" bech32: "npm:^2.0.0" uuid: "npm:^9.0.1" + webextension-polyfill: "npm:^0.12.0" peerDependencies: - "@metamask/providers": ^17.2.0 - checksum: 10/9857b6286760d22b1b7102ea8bdf03ebf56c71e9f0adee19a2230def6b7a9230561c1a3bfcb308735b79ab9a5afa9afd07a1617c1d165f63d193cd6a6b6e7a15 + "@metamask/providers": ^18.1.0 + checksum: 10/de22b9f5f3aecc290210fa78161e157aa8358f8dad421a093c9f6dbe35c4755067472a732f10d1ddbfba789e871c64edd8ea1c4c7316a392b214a187efd46ebe languageName: node linkType: hard @@ -26538,7 +26539,7 @@ __metadata: "@metamask/eth-ledger-bridge-keyring": "npm:^3.0.1" "@metamask/eth-query": "npm:^4.0.0" "@metamask/eth-sig-util": "npm:^7.0.1" - "@metamask/eth-snap-keyring": "npm:^4.4.0" + "@metamask/eth-snap-keyring": "npm:^5.0.1" "@metamask/eth-token-tracker": "npm:^8.0.0" "@metamask/eth-trezor-keyring": "npm:^3.1.3" "@metamask/etherscan-link": "npm:^3.0.0" @@ -26550,7 +26551,7 @@ __metadata: "@metamask/jazzicon": "npm:^2.0.0" "@metamask/json-rpc-engine": "npm:^10.0.0" "@metamask/json-rpc-middleware-stream": "npm:^8.0.4" - "@metamask/keyring-api": "npm:^8.1.3" + "@metamask/keyring-api": "npm:^10.1.0" "@metamask/keyring-controller": "npm:^17.2.2" "@metamask/logging-controller": "npm:^6.0.0" "@metamask/logo": "npm:^3.1.2" From 3cbd8874eaa328f28a1a3e0f44cab501cd9040df Mon Sep 17 00:00:00 2001 From: MetaMask Bot Date: Tue, 12 Nov 2024 14:18:13 +0000 Subject: [PATCH 06/23] Update LavaMoat policies --- lavamoat/browserify/beta/policy.json | 13 ++++++++++++- lavamoat/browserify/flask/policy.json | 13 ++++++++++++- lavamoat/browserify/main/policy.json | 13 ++++++++++++- lavamoat/browserify/mmi/policy.json | 13 ++++++++++++- 4 files changed, 48 insertions(+), 4 deletions(-) diff --git a/lavamoat/browserify/beta/policy.json b/lavamoat/browserify/beta/policy.json index eaac48a8f5f0..85ba1fecd215 100644 --- a/lavamoat/browserify/beta/policy.json +++ b/lavamoat/browserify/beta/policy.json @@ -965,7 +965,7 @@ }, "packages": { "@ethereumjs/tx": true, - "@metamask/eth-sig-util": true, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util": true, "@metamask/eth-snap-keyring>@metamask/utils": true, "@metamask/eth-snap-keyring>uuid": true, "@metamask/keyring-api": true, @@ -973,6 +973,17 @@ "webpack>events": true } }, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util": { + "packages": { + "@ethereumjs/tx>@ethereumjs/util": true, + "@ethereumjs/tx>ethereum-cryptography": true, + "@metamask/abi-utils": true, + "@metamask/eth-sig-util>tweetnacl": true, + "@metamask/eth-snap-keyring>@metamask/utils": true, + "@metamask/utils>@scure/base": true, + "browserify>buffer": true + } + }, "@metamask/eth-snap-keyring>@metamask/utils": { "globals": { "TextDecoder": true, diff --git a/lavamoat/browserify/flask/policy.json b/lavamoat/browserify/flask/policy.json index eaac48a8f5f0..85ba1fecd215 100644 --- a/lavamoat/browserify/flask/policy.json +++ b/lavamoat/browserify/flask/policy.json @@ -965,7 +965,7 @@ }, "packages": { "@ethereumjs/tx": true, - "@metamask/eth-sig-util": true, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util": true, "@metamask/eth-snap-keyring>@metamask/utils": true, "@metamask/eth-snap-keyring>uuid": true, "@metamask/keyring-api": true, @@ -973,6 +973,17 @@ "webpack>events": true } }, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util": { + "packages": { + "@ethereumjs/tx>@ethereumjs/util": true, + "@ethereumjs/tx>ethereum-cryptography": true, + "@metamask/abi-utils": true, + "@metamask/eth-sig-util>tweetnacl": true, + "@metamask/eth-snap-keyring>@metamask/utils": true, + "@metamask/utils>@scure/base": true, + "browserify>buffer": true + } + }, "@metamask/eth-snap-keyring>@metamask/utils": { "globals": { "TextDecoder": true, diff --git a/lavamoat/browserify/main/policy.json b/lavamoat/browserify/main/policy.json index eaac48a8f5f0..85ba1fecd215 100644 --- a/lavamoat/browserify/main/policy.json +++ b/lavamoat/browserify/main/policy.json @@ -965,7 +965,7 @@ }, "packages": { "@ethereumjs/tx": true, - "@metamask/eth-sig-util": true, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util": true, "@metamask/eth-snap-keyring>@metamask/utils": true, "@metamask/eth-snap-keyring>uuid": true, "@metamask/keyring-api": true, @@ -973,6 +973,17 @@ "webpack>events": true } }, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util": { + "packages": { + "@ethereumjs/tx>@ethereumjs/util": true, + "@ethereumjs/tx>ethereum-cryptography": true, + "@metamask/abi-utils": true, + "@metamask/eth-sig-util>tweetnacl": true, + "@metamask/eth-snap-keyring>@metamask/utils": true, + "@metamask/utils>@scure/base": true, + "browserify>buffer": true + } + }, "@metamask/eth-snap-keyring>@metamask/utils": { "globals": { "TextDecoder": true, diff --git a/lavamoat/browserify/mmi/policy.json b/lavamoat/browserify/mmi/policy.json index 467ef781215c..6c6bf1f60ed8 100644 --- a/lavamoat/browserify/mmi/policy.json +++ b/lavamoat/browserify/mmi/policy.json @@ -1057,7 +1057,7 @@ }, "packages": { "@ethereumjs/tx": true, - "@metamask/eth-sig-util": true, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util": true, "@metamask/eth-snap-keyring>@metamask/utils": true, "@metamask/eth-snap-keyring>uuid": true, "@metamask/keyring-api": true, @@ -1065,6 +1065,17 @@ "webpack>events": true } }, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util": { + "packages": { + "@ethereumjs/tx>@ethereumjs/util": true, + "@ethereumjs/tx>ethereum-cryptography": true, + "@metamask/abi-utils": true, + "@metamask/eth-sig-util>tweetnacl": true, + "@metamask/eth-snap-keyring>@metamask/utils": true, + "@metamask/utils>@scure/base": true, + "browserify>buffer": true + } + }, "@metamask/eth-snap-keyring>@metamask/utils": { "globals": { "TextDecoder": true, From 6248ba5698e5d0a1cbb96f54c1963d79d1c3281a Mon Sep 17 00:00:00 2001 From: Antonio Regadas Date: Tue, 12 Nov 2024 14:41:40 +0000 Subject: [PATCH 07/23] chore: update enum value --- .yarnrc.yml | 132 ++++-------------- builds.yml | 1 + shared/lib/accounts/solana-wallet-snap.ts | 4 +- test/data/mock-accounts.ts | 4 +- test/jest/mocks.ts | 2 +- .../wallet-overview/non-evm-overview.test.tsx | 2 +- ui/helpers/utils/permissions.test.ts | 2 +- .../useMultichainWalletSnapClient.test.ts | 2 +- 8 files changed, 39 insertions(+), 110 deletions(-) diff --git a/.yarnrc.yml b/.yarnrc.yml index 8e12d8037c6a..05ee9d46e6a9 100644 --- a/.yarnrc.yml +++ b/.yarnrc.yml @@ -13,115 +13,41 @@ logFilters: nodeLinker: node-modules npmAuditIgnoreAdvisories: - ### Advisories: - - # Issue: yargs-parser Vulnerable to Prototype Pollution - # URL - https://github.com/advisories/GHSA-p9pc-299p-vxgp - # The affected version (<5.0.0) is only included via @ensdomains/ens via - # 'solc' which is not used in the imports we use from this package. - 1088783 - - # Issue: protobufjs Prototype Pollution vulnerability - # URL - https://github.com/advisories/GHSA-h755-8qp9-cq85 - # Not easily patched. Minimally effects the extension due to usage of - # LavaMoat lockdown. Additional id added that resolves to the same advisory - # but has a different entry due to it being a new dependency of - # @trezor/connect-web. Upgrading - 1092429 - 1095136 - - # Issue: Regular Expression Denial of Service (ReDOS) - # URL: https://github.com/advisories/GHSA-257v-vj4p-3w2h - # color-string is listed as a dependency of 'color' which is brought in by - # @metamask/jazzicon v2.0.0 but there is work done on that repository to - # remove the color dependency. We should upgrade - 1089718 - - # Issue: semver vulnerable to Regular Expression Denial of Service - # URL: https://github.com/advisories/GHSA-c2qf-rxjj-qqgw - # semver is used in the solidity compiler portion of @truffle/codec that does - # not appear to be used. - 1092461 - - # Temp fix for https://github.com/MetaMask/metamask-extension/pull/16920 for the sake of 11.7.1 hotfix - # This will be removed in this ticket https://github.com/MetaMask/metamask-extension/issues/22299 - - 'ts-custom-error (deprecation)' - - 'text-encoding (deprecation)' - - ### Package Deprecations: - - # React-tippy brings in popper.js and react-tippy has not been updated in - # three years. - - 'popper.js (deprecation)' - - # React-router is out of date and brings in the following deprecated package - - 'mini-create-react-context (deprecation)' - - # The affected version, which is less than 7.0.0, is brought in by - # ethereumjs-wallet version 0.6.5 used in the extension but only in a single - # file app/scripts/account-import-strategies/index.js, which may be easy to - # upgrade. - - 'uuid (deprecation)' - - # @npmcli/move-file is brought in via CopyWebpackPlugin used in the storybook - # main.js file, which can be upgraded to remove this dependency in favor of - # @npmcli/fs - - '@npmcli/move-file (deprecation)' - - # Upgrading babel will result in the following deprecated packages being - # updated: - - 'core-js (deprecation)' - - # Material UI dependencies are planned for removal - - '@material-ui/core (deprecation)' - - '@material-ui/styles (deprecation)' - - '@material-ui/system (deprecation)' - - # @ensdomains/ens should be explored for upgrade. The following packages are - # deprecated and would be resolved by upgrading to newer versions of - # ensdomains packages: - - '@ensdomains/ens (deprecation)' - - '@ensdomains/resolver (deprecation)' - - 'testrpc (deprecation)' - - # Dependencies brought in by @truffle/decoder that are deprecated: - - 'cids (deprecation)' # via @ensdomains/content-hash - - 'multibase (deprecation)' # via cids - - 'multicodec (deprecation)' # via cids - - # MetaMask owned repositories brought in by other MetaMask dependencies that - # can be resolved by updating the versions throughout the dependency tree - - 'eth-sig-util (deprecation)' # via @metamask/eth-ledger-bridge-keyring - - '@metamask/controller-utils (deprecation)' # via @metamask/phishing-controller - - 'safe-event-emitter (deprecation)' # via eth-block-tracker and others - - # @metamask-institutional relies upon crypto which is deprecated - - 'crypto (deprecation)' - - # @metamask/providers uses webextension-polyfill-ts which has been moved to - # @types/webextension-polyfill - - 'webextension-polyfill-ts (deprecation)' - - # Imported in @trezor/blockchain-link@npm:2.1.8, but not actually depended on - # by MetaMask - - 'ripple-lib (deprecation)' - - # Brought in by ethereumjs-utils, which is used in the extension and in many - # other dependencies. At the time of this exclusion, the extension has three - # old versions of ethereumjs-utils which should be upgraded to - # @ethereumjs/utils throughout our owned repositories. However even doing - # that may be insufficient due to dependencies we do not own still relying - # upon old versions of ethereumjs-utils. - - 'ethereum-cryptography (deprecation)' - - # Currently in use for the network list drag and drop functionality. - # Maintenance has stopped and the project will be archived in 2025. - - 'react-beautiful-dnd (deprecation)' - # New package name format for new versions: @ethereumjs/wallet. - - 'ethereumjs-wallet (deprecation)' + - ts-custom-error (deprecation) + - text-encoding (deprecation) + - popper.js (deprecation) + - mini-create-react-context (deprecation) + - uuid (deprecation) + - "@npmcli/move-file (deprecation)" + - core-js (deprecation) + - "@material-ui/core (deprecation)" + - "@material-ui/styles (deprecation)" + - "@material-ui/system (deprecation)" + - "@ensdomains/ens (deprecation)" + - "@ensdomains/resolver (deprecation)" + - testrpc (deprecation) + - cids (deprecation) + - multibase (deprecation) + - multicodec (deprecation) + - eth-sig-util (deprecation) + - "@metamask/controller-utils (deprecation)" + - safe-event-emitter (deprecation) + - crypto (deprecation) + - webextension-polyfill-ts (deprecation) + - ripple-lib (deprecation) + - ethereum-cryptography (deprecation) + - react-beautiful-dnd (deprecation) + - ethereumjs-wallet (deprecation) plugins: - path: .yarn/plugins/@yarnpkg/plugin-allow-scripts.cjs - spec: 'https://raw.githubusercontent.com/LavaMoat/LavaMoat/main/packages/yarn-plugin-allow-scripts/bundles/@yarnpkg/plugin-allow-scripts.js' + spec: "https://raw.githubusercontent.com/LavaMoat/LavaMoat/main/packages/yarn-plugin-allow-scripts/bundles/@yarnpkg/plugin-allow-scripts.js" - path: .yarn/plugins/@yarnpkg/plugin-engines.cjs - spec: 'https://raw.githubusercontent.com/devoto13/yarn-plugin-engines/main/bundles/%40yarnpkg/plugin-engines.js' + spec: "https://raw.githubusercontent.com/devoto13/yarn-plugin-engines/main/bundles/%40yarnpkg/plugin-engines.js" + +yarnPath: .yarn/releases/yarn-4.4.1.cjs diff --git a/builds.yml b/builds.yml index 2442ad51475a..2aba907353e8 100644 --- a/builds.yml +++ b/builds.yml @@ -64,6 +64,7 @@ buildTypes: features: - build-flask - keyring-snaps + - solana env: - INFURA_FLASK_PROJECT_ID - SEGMENT_FLASK_WRITE_KEY diff --git a/shared/lib/accounts/solana-wallet-snap.ts b/shared/lib/accounts/solana-wallet-snap.ts index 1f6622c8bbdc..3feff60c2a03 100644 --- a/shared/lib/accounts/solana-wallet-snap.ts +++ b/shared/lib/accounts/solana-wallet-snap.ts @@ -3,7 +3,9 @@ import { SnapId } from '@metamask/snaps-sdk'; // the Snap is being pre-installed only for Flask build (for the moment). import SolanaWalletSnap from '@metamask/solana-wallet-snap/dist/preinstalled-snap.json'; -export const SOLANA_WALLET_SNAP_ID: SnapId = SolanaWalletSnap.snapId as SnapId; +// export const SOLANA_WALLET_SNAP_ID: SnapId = SolanaWalletSnap.snapId as SnapId; +export const SOLANA_WALLET_SNAP_ID: SnapId = + 'local:http://localhost:8080' as SnapId; export const SOLANA_WALLET_NAME: string = SolanaWalletSnap.manifest.proposedName; diff --git a/test/data/mock-accounts.ts b/test/data/mock-accounts.ts index 2273915f7a5f..b956dbadd6bb 100644 --- a/test/data/mock-accounts.ts +++ b/test/data/mock-accounts.ts @@ -42,7 +42,7 @@ export const MOCK_ACCOUNT_BIP122_P2WPKH: InternalAccount = { id: 'ae247df6-3911-47f7-9e36-28e6a7d96078', address: 'bc1qwl8399fz829uqvqly9tcatgrgtwp3udnhxfq4k', options: {}, - methods: [BtcMethod.SendMany], + methods: [BtcMethod.SendBitcoin], type: BtcAccountType.P2wpkh, metadata: { name: 'Bitcoin Account', @@ -56,7 +56,7 @@ export const MOCK_ACCOUNT_BIP122_P2WPKH_TESTNET: InternalAccount = { id: 'fcdafe8b-4bdf-4e25-9051-e255b2a0af5f', address: 'tb1q6rmsq3vlfdhjdhtkxlqtuhhlr6pmj09y6w43g8', options: {}, - methods: [BtcMethod.SendMany], + methods: [BtcMethod.SendBitcoin], type: BtcAccountType.P2wpkh, metadata: { name: 'Bitcoin Testnet Account', diff --git a/test/jest/mocks.ts b/test/jest/mocks.ts index be1120429290..bc7127fb2383 100644 --- a/test/jest/mocks.ts +++ b/test/jest/mocks.ts @@ -214,7 +214,7 @@ export function createMockInternalAccount({ ]; break; case BtcAccountType.P2wpkh: - methods = [BtcMethod.SendMany]; + methods = [BtcMethod.SendBitcoin]; break; default: throw new Error(`Unknown account type: ${type}`); diff --git a/ui/components/app/wallet-overview/non-evm-overview.test.tsx b/ui/components/app/wallet-overview/non-evm-overview.test.tsx index 7f5b68e7b3db..722fffdbc719 100644 --- a/ui/components/app/wallet-overview/non-evm-overview.test.tsx +++ b/ui/components/app/wallet-overview/non-evm-overview.test.tsx @@ -57,7 +57,7 @@ const mockNonEvmAccount = { }, }, options: {}, - methods: [BtcMethod.SendMany], + methods: [BtcMethod.SendBitcoin], type: BtcAccountType.P2wpkh, }; diff --git a/ui/helpers/utils/permissions.test.ts b/ui/helpers/utils/permissions.test.ts index 2ebfd42b2874..43857afb1815 100644 --- a/ui/helpers/utils/permissions.test.ts +++ b/ui/helpers/utils/permissions.test.ts @@ -11,7 +11,7 @@ const mockNonEvmAccount = { ...mockAccount, id: '4b94987c-165c-4287-bbc6-bee9c440e82a', type: BtcAccountType.P2wpkh, - methods: [BtcMethod.SendMany], + methods: [BtcMethod.SendBitcoin], address: 'bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq', }; diff --git a/ui/hooks/accounts/useMultichainWalletSnapClient.test.ts b/ui/hooks/accounts/useMultichainWalletSnapClient.test.ts index d177986fee44..5efdbfd9b4ea 100644 --- a/ui/hooks/accounts/useMultichainWalletSnapClient.test.ts +++ b/ui/hooks/accounts/useMultichainWalletSnapClient.test.ts @@ -35,7 +35,7 @@ describe('useMultichainWalletSnapClient', () => { address: 'tb1q2hjrlnf8kmtt5dj6e49gqzy6jnpe0sj7ty50cl', id: '11a33c6b-0d46-43f4-a401-01587d575fd0', options: {}, - methods: [BtcMethod.SendMany], + methods: [BtcMethod.SendBitcoin], type: BtcAccountType.P2wpkh, }, }, From 97c7198970d8ed7b6806022356fc4a90e9e86e18 Mon Sep 17 00:00:00 2001 From: Antonio Regadas Date: Tue, 12 Nov 2024 14:42:43 +0000 Subject: [PATCH 08/23] chore: undo --- .yarnrc.yml | 132 +++++++++++++++++----- builds.yml | 1 - shared/lib/accounts/solana-wallet-snap.ts | 4 +- 3 files changed, 104 insertions(+), 33 deletions(-) diff --git a/.yarnrc.yml b/.yarnrc.yml index 05ee9d46e6a9..8e12d8037c6a 100644 --- a/.yarnrc.yml +++ b/.yarnrc.yml @@ -13,41 +13,115 @@ logFilters: nodeLinker: node-modules npmAuditIgnoreAdvisories: + ### Advisories: + + # Issue: yargs-parser Vulnerable to Prototype Pollution + # URL - https://github.com/advisories/GHSA-p9pc-299p-vxgp + # The affected version (<5.0.0) is only included via @ensdomains/ens via + # 'solc' which is not used in the imports we use from this package. - 1088783 + + # Issue: protobufjs Prototype Pollution vulnerability + # URL - https://github.com/advisories/GHSA-h755-8qp9-cq85 + # Not easily patched. Minimally effects the extension due to usage of + # LavaMoat lockdown. Additional id added that resolves to the same advisory + # but has a different entry due to it being a new dependency of + # @trezor/connect-web. Upgrading - 1092429 - 1095136 + + # Issue: Regular Expression Denial of Service (ReDOS) + # URL: https://github.com/advisories/GHSA-257v-vj4p-3w2h + # color-string is listed as a dependency of 'color' which is brought in by + # @metamask/jazzicon v2.0.0 but there is work done on that repository to + # remove the color dependency. We should upgrade - 1089718 + + # Issue: semver vulnerable to Regular Expression Denial of Service + # URL: https://github.com/advisories/GHSA-c2qf-rxjj-qqgw + # semver is used in the solidity compiler portion of @truffle/codec that does + # not appear to be used. - 1092461 - - ts-custom-error (deprecation) - - text-encoding (deprecation) - - popper.js (deprecation) - - mini-create-react-context (deprecation) - - uuid (deprecation) - - "@npmcli/move-file (deprecation)" - - core-js (deprecation) - - "@material-ui/core (deprecation)" - - "@material-ui/styles (deprecation)" - - "@material-ui/system (deprecation)" - - "@ensdomains/ens (deprecation)" - - "@ensdomains/resolver (deprecation)" - - testrpc (deprecation) - - cids (deprecation) - - multibase (deprecation) - - multicodec (deprecation) - - eth-sig-util (deprecation) - - "@metamask/controller-utils (deprecation)" - - safe-event-emitter (deprecation) - - crypto (deprecation) - - webextension-polyfill-ts (deprecation) - - ripple-lib (deprecation) - - ethereum-cryptography (deprecation) - - react-beautiful-dnd (deprecation) - - ethereumjs-wallet (deprecation) + + # Temp fix for https://github.com/MetaMask/metamask-extension/pull/16920 for the sake of 11.7.1 hotfix + # This will be removed in this ticket https://github.com/MetaMask/metamask-extension/issues/22299 + - 'ts-custom-error (deprecation)' + - 'text-encoding (deprecation)' + + ### Package Deprecations: + + # React-tippy brings in popper.js and react-tippy has not been updated in + # three years. + - 'popper.js (deprecation)' + + # React-router is out of date and brings in the following deprecated package + - 'mini-create-react-context (deprecation)' + + # The affected version, which is less than 7.0.0, is brought in by + # ethereumjs-wallet version 0.6.5 used in the extension but only in a single + # file app/scripts/account-import-strategies/index.js, which may be easy to + # upgrade. + - 'uuid (deprecation)' + + # @npmcli/move-file is brought in via CopyWebpackPlugin used in the storybook + # main.js file, which can be upgraded to remove this dependency in favor of + # @npmcli/fs + - '@npmcli/move-file (deprecation)' + + # Upgrading babel will result in the following deprecated packages being + # updated: + - 'core-js (deprecation)' + + # Material UI dependencies are planned for removal + - '@material-ui/core (deprecation)' + - '@material-ui/styles (deprecation)' + - '@material-ui/system (deprecation)' + + # @ensdomains/ens should be explored for upgrade. The following packages are + # deprecated and would be resolved by upgrading to newer versions of + # ensdomains packages: + - '@ensdomains/ens (deprecation)' + - '@ensdomains/resolver (deprecation)' + - 'testrpc (deprecation)' + + # Dependencies brought in by @truffle/decoder that are deprecated: + - 'cids (deprecation)' # via @ensdomains/content-hash + - 'multibase (deprecation)' # via cids + - 'multicodec (deprecation)' # via cids + + # MetaMask owned repositories brought in by other MetaMask dependencies that + # can be resolved by updating the versions throughout the dependency tree + - 'eth-sig-util (deprecation)' # via @metamask/eth-ledger-bridge-keyring + - '@metamask/controller-utils (deprecation)' # via @metamask/phishing-controller + - 'safe-event-emitter (deprecation)' # via eth-block-tracker and others + + # @metamask-institutional relies upon crypto which is deprecated + - 'crypto (deprecation)' + + # @metamask/providers uses webextension-polyfill-ts which has been moved to + # @types/webextension-polyfill + - 'webextension-polyfill-ts (deprecation)' + + # Imported in @trezor/blockchain-link@npm:2.1.8, but not actually depended on + # by MetaMask + - 'ripple-lib (deprecation)' + + # Brought in by ethereumjs-utils, which is used in the extension and in many + # other dependencies. At the time of this exclusion, the extension has three + # old versions of ethereumjs-utils which should be upgraded to + # @ethereumjs/utils throughout our owned repositories. However even doing + # that may be insufficient due to dependencies we do not own still relying + # upon old versions of ethereumjs-utils. + - 'ethereum-cryptography (deprecation)' + + # Currently in use for the network list drag and drop functionality. + # Maintenance has stopped and the project will be archived in 2025. + - 'react-beautiful-dnd (deprecation)' + # New package name format for new versions: @ethereumjs/wallet. + - 'ethereumjs-wallet (deprecation)' plugins: - path: .yarn/plugins/@yarnpkg/plugin-allow-scripts.cjs - spec: "https://raw.githubusercontent.com/LavaMoat/LavaMoat/main/packages/yarn-plugin-allow-scripts/bundles/@yarnpkg/plugin-allow-scripts.js" + spec: 'https://raw.githubusercontent.com/LavaMoat/LavaMoat/main/packages/yarn-plugin-allow-scripts/bundles/@yarnpkg/plugin-allow-scripts.js' - path: .yarn/plugins/@yarnpkg/plugin-engines.cjs - spec: "https://raw.githubusercontent.com/devoto13/yarn-plugin-engines/main/bundles/%40yarnpkg/plugin-engines.js" - -yarnPath: .yarn/releases/yarn-4.4.1.cjs + spec: 'https://raw.githubusercontent.com/devoto13/yarn-plugin-engines/main/bundles/%40yarnpkg/plugin-engines.js' diff --git a/builds.yml b/builds.yml index 2aba907353e8..2442ad51475a 100644 --- a/builds.yml +++ b/builds.yml @@ -64,7 +64,6 @@ buildTypes: features: - build-flask - keyring-snaps - - solana env: - INFURA_FLASK_PROJECT_ID - SEGMENT_FLASK_WRITE_KEY diff --git a/shared/lib/accounts/solana-wallet-snap.ts b/shared/lib/accounts/solana-wallet-snap.ts index 3feff60c2a03..1f6622c8bbdc 100644 --- a/shared/lib/accounts/solana-wallet-snap.ts +++ b/shared/lib/accounts/solana-wallet-snap.ts @@ -3,9 +3,7 @@ import { SnapId } from '@metamask/snaps-sdk'; // the Snap is being pre-installed only for Flask build (for the moment). import SolanaWalletSnap from '@metamask/solana-wallet-snap/dist/preinstalled-snap.json'; -// export const SOLANA_WALLET_SNAP_ID: SnapId = SolanaWalletSnap.snapId as SnapId; -export const SOLANA_WALLET_SNAP_ID: SnapId = - 'local:http://localhost:8080' as SnapId; +export const SOLANA_WALLET_SNAP_ID: SnapId = SolanaWalletSnap.snapId as SnapId; export const SOLANA_WALLET_NAME: string = SolanaWalletSnap.manifest.proposedName; From b0dd1c6d5c8cfddce1ad2406048a98edc8040bcc Mon Sep 17 00:00:00 2001 From: Antonio Regadas Date: Tue, 12 Nov 2024 16:21:46 +0000 Subject: [PATCH 09/23] chore: improvements --- app/_locales/en/messages.json | 3 ++ .../lib/accounts/BalancesController.ts | 45 +++++++++++-------- .../snap-keyring/keyring-snaps-permissions.ts | 1 - package.json | 2 +- shared/constants/network.ts | 8 ---- .../token-list-item/token-list-item.tsx | 2 + ui/selectors/multichain.ts | 19 +++----- 7 files changed, 39 insertions(+), 41 deletions(-) diff --git a/app/_locales/en/messages.json b/app/_locales/en/messages.json index 610ddba3a4dd..afee4329142a 100644 --- a/app/_locales/en/messages.json +++ b/app/_locales/en/messages.json @@ -3158,6 +3158,9 @@ "networkNameBitcoin": { "message": "Bitcoin" }, + "networkNameSolana": { + "message": "Solana" + }, "networkNameDefinition": { "message": "The name associated with this network." }, diff --git a/app/scripts/lib/accounts/BalancesController.ts b/app/scripts/lib/accounts/BalancesController.ts index e7a2389e0733..e8bef98ef16e 100644 --- a/app/scripts/lib/accounts/BalancesController.ts +++ b/app/scripts/lib/accounts/BalancesController.ts @@ -29,6 +29,8 @@ import { isSolanaAddress, } from '../../../../shared/lib/multichain'; import { BalancesTracker } from './BalancesTracker'; +import { MultichainNetworks } from '../../../../shared/constants/multichain/networks'; +import { MultichainNativeAssets } from '../../../../shared/constants/multichain/assets'; const controllerName = 'BalancesController'; @@ -175,10 +177,15 @@ export class BalancesController extends BaseController< // Register all non-EVM accounts into the tracker for (const account of this.#listAccounts()) { if (this.#isNonEvmAccount(account)) { + const updateTimes = { + [BtcAccountType.P2wpkh]: BTC_BALANCES_UPDATE_TIME, + [SolAccountType.DataAccount]: SOLANA_AVG_BLOCK_TIME, + }; + const updateTime = - account.type === BtcAccountType.P2wpkh - ? BTC_BALANCES_UPDATE_TIME - : SOLANA_AVG_BLOCK_TIME; + updateTimes[account.type as keyof typeof updateTimes] || + SOLANA_AVG_BLOCK_TIME; + this.#tracker.track(account.id, updateTime); } } @@ -264,19 +271,16 @@ export class BalancesController extends BaseController< const partialState: BalancesControllerState = { balances: {} }; if (account.metadata.snap) { - // In here we need to check which assets to query - let assetTypes: CaipAssetType[]; - if (isSolanaAddress(account.address)) { - assetTypes = SOLANA_ASSETS; - } else if (isBtcMainnetAddress(account.address)) { - assetTypes = BTC_MAINNET_ASSETS; - } else { - // If not mainnet, we need to check if it's testnet or devnet - assetTypes = - account.type === BtcAccountType.P2wpkh - ? BTC_TESTNET_ASSETS - : SOLANA_DEVNET_ASSETS; - } + const assetMap = { + [MultichainNetworks.SOLANA]: MultichainNativeAssets.SOLANA, + [MultichainNetworks.SOLANA_TESTNET]: MultichainNativeAssets.SOLANA_TESTNET, + [MultichainNetworks.SOLANA_DEVNET]: MultichainNativeAssets.SOLANA_DEVNET, + [MultichainNetworks.BITCOIN]: MultichainNativeAssets.BITCOIN, + [MultichainNetworks.BITCOIN_TESTNET]: MultichainNativeAssets.BITCOIN_TESTNET, + }; + + const scope = account.options.scope as keyof typeof assetMap; + const assetTypes = [assetMap[scope]]; await this.#getBalances(account.id, account.metadata.snap.id, assetTypes); } @@ -334,11 +338,14 @@ export class BalancesController extends BaseController< // Nothing to do here for EVM accounts return; } + const updateTimes = { + [BtcAccountType.P2wpkh]: BTC_AVG_BLOCK_TIME, + [SolAccountType.DataAccount]: SOLANA_AVG_BLOCK_TIME, + }; const updateTime = - account.type === BtcAccountType.P2wpkh - ? BTC_AVG_BLOCK_TIME - : SOLANA_AVG_BLOCK_TIME; + updateTimes[account.type as keyof typeof updateTimes] || + SOLANA_AVG_BLOCK_TIME; this.#tracker.track(account.id, updateTime); // NOTE: Unfortunately, we cannot update the balance right away here, because // messenger's events are running synchronously and fetching the balance is // asynchronous. diff --git a/app/scripts/lib/snap-keyring/keyring-snaps-permissions.ts b/app/scripts/lib/snap-keyring/keyring-snaps-permissions.ts index 9cc8713f7aa5..f7d9c829a3cc 100644 --- a/app/scripts/lib/snap-keyring/keyring-snaps-permissions.ts +++ b/app/scripts/lib/snap-keyring/keyring-snaps-permissions.ts @@ -8,7 +8,6 @@ import { KeyringRpcMethod } from '@metamask/keyring-api'; * The origins of the Portfolio dapp. */ const PORTFOLIO_ORIGINS: string[] = [ - 'http://localhost:3000', 'https://portfolio.metamask.io', ///: BEGIN:ONLY_INCLUDE_IF(build-flask) 'https://dev.portfolio.metamask.io', diff --git a/package.json b/package.json index d1c149ef6d76..0ab60617da38 100644 --- a/package.json +++ b/package.json @@ -757,5 +757,5 @@ "jest-preview": false } }, - "packageManager": "yarn@4.5.1" + "packageManager": "yarn@4.4.1" } diff --git a/shared/constants/network.ts b/shared/constants/network.ts index ef31a23364d4..8365f0f5d5a6 100644 --- a/shared/constants/network.ts +++ b/shared/constants/network.ts @@ -540,14 +540,6 @@ export const BUILT_IN_INFURA_NETWORKS = pick( export type BuiltInInfuraNetwork = keyof typeof BUILT_IN_INFURA_NETWORKS; -// type SupportedNetworksType = { -// [key: string]: { -// domain: string; -// subdomain: string; -// networkId: string; -// }; -// }; - export const NETWORK_TO_NAME_MAP = { [NETWORK_TYPES.GOERLI]: GOERLI_DISPLAY_NAME, [NETWORK_TYPES.MAINNET]: MAINNET_DISPLAY_NAME, diff --git a/ui/components/multichain/token-list-item/token-list-item.tsx b/ui/components/multichain/token-list-item/token-list-item.tsx index 5a25e2562425..cf9cba532f69 100644 --- a/ui/components/multichain/token-list-item/token-list-item.tsx +++ b/ui/components/multichain/token-list-item/token-list-item.tsx @@ -147,6 +147,8 @@ export const TokenListItem = ({ return t('networkNameEthereum'); case NON_EVM_CURRENCY_SYMBOLS.BTC: return t('networkNameBitcoin'); + case NON_EVM_CURRENCY_SYMBOLS.SOL: + return t('networkNameSolana'); default: return title; } diff --git a/ui/selectors/multichain.ts b/ui/selectors/multichain.ts index 82bf6150a5e5..59f70535ff1a 100644 --- a/ui/selectors/multichain.ts +++ b/ui/selectors/multichain.ts @@ -375,22 +375,17 @@ export const getMultichainCoinRates = (state: MultichainState) => { function getNonEvmCachedBalance(state: MultichainState) { const balances = getMultichainBalances(state); const account = getSelectedInternalAccount(state); - const isMainnet = getMultichainIsMainnet(state); + const network = getMultichainCurrentNetwork(state); const assetMap = { - [SolAccountType.DataAccount]: isMainnet - ? MultichainNativeAssets.SOLANA - : MultichainNativeAssets.SOLANA_DEVNET, - [BtcAccountType.P2wpkh]: isMainnet - ? MultichainNativeAssets.BITCOIN - : MultichainNativeAssets.BITCOIN_TESTNET, + [MultichainNetworks.SOLANA]: MultichainNativeAssets.SOLANA, + [MultichainNetworks.SOLANA_TESTNET]: MultichainNativeAssets.SOLANA_TESTNET, + [MultichainNetworks.SOLANA_DEVNET]: MultichainNativeAssets.SOLANA_DEVNET, + [MultichainNetworks.BITCOIN]: MultichainNativeAssets.BITCOIN, + [MultichainNetworks.BITCOIN_TESTNET]: MultichainNativeAssets.BITCOIN_TESTNET, }; - const asset = - assetMap[account.type as keyof typeof assetMap] ?? - (isMainnet - ? MultichainNativeAssets.BITCOIN - : MultichainNativeAssets.BITCOIN_TESTNET); + const asset = assetMap[network.chainId as keyof typeof assetMap]; return balances?.[account.id]?.[asset]?.amount; } From e40f75c313cb7ffec2322ec585a6271c706957c2 Mon Sep 17 00:00:00 2001 From: Antonio Regadas Date: Tue, 12 Nov 2024 16:27:06 +0000 Subject: [PATCH 10/23] chore: prettier --- app/_locales/en/messages.json | 6 ++--- .../lib/accounts/BalancesController.ts | 22 ++++++------------- ui/selectors/multichain.ts | 3 ++- 3 files changed, 12 insertions(+), 19 deletions(-) diff --git a/app/_locales/en/messages.json b/app/_locales/en/messages.json index afee4329142a..fbaf4224c2d6 100644 --- a/app/_locales/en/messages.json +++ b/app/_locales/en/messages.json @@ -3158,9 +3158,6 @@ "networkNameBitcoin": { "message": "Bitcoin" }, - "networkNameSolana": { - "message": "Solana" - }, "networkNameDefinition": { "message": "The name associated with this network." }, @@ -3179,6 +3176,9 @@ "networkNamePolygon": { "message": "Polygon" }, + "networkNameSolana": { + "message": "Solana" + }, "networkNameTestnet": { "message": "Testnet" }, diff --git a/app/scripts/lib/accounts/BalancesController.ts b/app/scripts/lib/accounts/BalancesController.ts index e8bef98ef16e..d17d0505e2b9 100644 --- a/app/scripts/lib/accounts/BalancesController.ts +++ b/app/scripts/lib/accounts/BalancesController.ts @@ -24,13 +24,9 @@ import type { AccountsControllerAccountRemovedEvent, AccountsControllerListMultichainAccountsAction, } from '@metamask/accounts-controller'; -import { - isBtcMainnetAddress, - isSolanaAddress, -} from '../../../../shared/lib/multichain'; -import { BalancesTracker } from './BalancesTracker'; import { MultichainNetworks } from '../../../../shared/constants/multichain/networks'; import { MultichainNativeAssets } from '../../../../shared/constants/multichain/assets'; +import { BalancesTracker } from './BalancesTracker'; const controllerName = 'BalancesController'; @@ -128,14 +124,7 @@ const balancesControllerMetadata = { }, }; -const BTC_TESTNET_ASSETS = ['bip122:000000000933ea01ad0ee984209779ba/slip44:0']; -const BTC_MAINNET_ASSETS = ['bip122:000000000019d6689c085ae165831e93/slip44:0']; const BTC_AVG_BLOCK_TIME = 10 * 60 * 1000; // 10 minutes in milliseconds - -const SOLANA_ASSETS = ['solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/slip44:501']; -const SOLANA_DEVNET_ASSETS = [ - 'solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1/slip44:501', -]; const SOLANA_AVG_BLOCK_TIME = 400; // 400 milliseconds // NOTE: We set an interval of half the average block time to mitigate when our interval @@ -273,10 +262,13 @@ export class BalancesController extends BaseController< if (account.metadata.snap) { const assetMap = { [MultichainNetworks.SOLANA]: MultichainNativeAssets.SOLANA, - [MultichainNetworks.SOLANA_TESTNET]: MultichainNativeAssets.SOLANA_TESTNET, - [MultichainNetworks.SOLANA_DEVNET]: MultichainNativeAssets.SOLANA_DEVNET, + [MultichainNetworks.SOLANA_TESTNET]: + MultichainNativeAssets.SOLANA_TESTNET, + [MultichainNetworks.SOLANA_DEVNET]: + MultichainNativeAssets.SOLANA_DEVNET, [MultichainNetworks.BITCOIN]: MultichainNativeAssets.BITCOIN, - [MultichainNetworks.BITCOIN_TESTNET]: MultichainNativeAssets.BITCOIN_TESTNET, + [MultichainNetworks.BITCOIN_TESTNET]: + MultichainNativeAssets.BITCOIN_TESTNET, }; const scope = account.options.scope as keyof typeof assetMap; diff --git a/ui/selectors/multichain.ts b/ui/selectors/multichain.ts index 59f70535ff1a..6c018f9afb8a 100644 --- a/ui/selectors/multichain.ts +++ b/ui/selectors/multichain.ts @@ -382,7 +382,8 @@ function getNonEvmCachedBalance(state: MultichainState) { [MultichainNetworks.SOLANA_TESTNET]: MultichainNativeAssets.SOLANA_TESTNET, [MultichainNetworks.SOLANA_DEVNET]: MultichainNativeAssets.SOLANA_DEVNET, [MultichainNetworks.BITCOIN]: MultichainNativeAssets.BITCOIN, - [MultichainNetworks.BITCOIN_TESTNET]: MultichainNativeAssets.BITCOIN_TESTNET, + [MultichainNetworks.BITCOIN_TESTNET]: + MultichainNativeAssets.BITCOIN_TESTNET, }; const asset = assetMap[network.chainId as keyof typeof assetMap]; From 1a81480b0a3691a89c8c02063ce57166311890c1 Mon Sep 17 00:00:00 2001 From: Antonio Regadas Date: Tue, 12 Nov 2024 16:35:34 +0000 Subject: [PATCH 11/23] chore: undo change --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0ab60617da38..d1c149ef6d76 100644 --- a/package.json +++ b/package.json @@ -757,5 +757,5 @@ "jest-preview": false } }, - "packageManager": "yarn@4.4.1" + "packageManager": "yarn@4.5.1" } From d7da72a56b83147f92cf4e3508f19434f83d2dc1 Mon Sep 17 00:00:00 2001 From: Antonio Regadas Date: Tue, 12 Nov 2024 17:12:35 +0000 Subject: [PATCH 12/23] chore: test update for balancesController --- app/scripts/lib/accounts/BalancesController.test.ts | 4 ++++ app/scripts/lib/accounts/BalancesController.ts | 2 +- test/jest/mocks.ts | 6 +++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/scripts/lib/accounts/BalancesController.test.ts b/app/scripts/lib/accounts/BalancesController.test.ts index e8ddd89f021e..ec7c10791922 100644 --- a/app/scripts/lib/accounts/BalancesController.test.ts +++ b/app/scripts/lib/accounts/BalancesController.test.ts @@ -15,6 +15,7 @@ import { BalancesControllerMessenger, } from './BalancesController'; import { BalancesTracker } from './BalancesTracker'; +import { MultichainNetworks } from '../../../../shared/constants/multichain/networks'; const mockBtcAccount = createMockInternalAccount({ address: '', @@ -25,6 +26,9 @@ const mockBtcAccount = createMockInternalAccount({ name: 'mock-btc-snap', enabled: true, }, + options: { + scope: MultichainNetworks.BITCOIN_TESTNET, + }, }); const mockBalanceResult = { diff --git a/app/scripts/lib/accounts/BalancesController.ts b/app/scripts/lib/accounts/BalancesController.ts index d17d0505e2b9..41549a4d718d 100644 --- a/app/scripts/lib/accounts/BalancesController.ts +++ b/app/scripts/lib/accounts/BalancesController.ts @@ -274,7 +274,7 @@ export class BalancesController extends BaseController< const scope = account.options.scope as keyof typeof assetMap; const assetTypes = [assetMap[scope]]; - await this.#getBalances(account.id, account.metadata.snap.id, assetTypes); + partialState.balances[account.id] = await this.#getBalances(account.id, account.metadata.snap.id, assetTypes); } this.update((state: Draft) => ({ diff --git a/test/jest/mocks.ts b/test/jest/mocks.ts index bc7127fb2383..992971c8d063 100644 --- a/test/jest/mocks.ts +++ b/test/jest/mocks.ts @@ -182,6 +182,7 @@ export function createMockInternalAccount({ keyringType = KeyringTypes.hd, lastSelected = 0, snapOptions = undefined, + options = undefined, }: { name?: string; address?: string; @@ -193,6 +194,9 @@ export function createMockInternalAccount({ name: string; id: string; }; + options?: { + scope: string; + }; } = {}) { let methods; @@ -232,7 +236,7 @@ export function createMockInternalAccount({ snap: snapOptions, lastSelected, }, - options: {}, + options: options ?? {}, methods, type, }; From 7743068dda609d9511810bb848f24ea4017411ce Mon Sep 17 00:00:00 2001 From: Antonio Regadas Date: Tue, 12 Nov 2024 17:20:14 +0000 Subject: [PATCH 13/23] chore: prettier --- .../lib/accounts/BalancesController.ts | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/app/scripts/lib/accounts/BalancesController.ts b/app/scripts/lib/accounts/BalancesController.ts index 41549a4d718d..c3f474138b6d 100644 --- a/app/scripts/lib/accounts/BalancesController.ts +++ b/app/scripts/lib/accounts/BalancesController.ts @@ -27,6 +27,10 @@ import type { import { MultichainNetworks } from '../../../../shared/constants/multichain/networks'; import { MultichainNativeAssets } from '../../../../shared/constants/multichain/assets'; import { BalancesTracker } from './BalancesTracker'; +import { + isBtcMainnetAddress, + isBtcTestnetAddress, +} from '../../../../shared/lib/multichain'; const controllerName = 'BalancesController'; @@ -271,10 +275,25 @@ export class BalancesController extends BaseController< MultichainNativeAssets.BITCOIN_TESTNET, }; - const scope = account.options.scope as keyof typeof assetMap; + let scope = account.options.scope as keyof typeof assetMap; + + // For Bitcoin accounts, override the scope based on the address format + // For solana we know we have a scope, but for bitcoin we are not sure + if (account.type === BtcAccountType.P2wpkh) { + if (isBtcMainnetAddress(account.address)) { + scope = MultichainNetworks.BITCOIN; + } else if (isBtcTestnetAddress(account.address)) { + scope = MultichainNetworks.BITCOIN_TESTNET; + } + } + const assetTypes = [assetMap[scope]]; - partialState.balances[account.id] = await this.#getBalances(account.id, account.metadata.snap.id, assetTypes); + partialState.balances[account.id] = await this.#getBalances( + account.id, + account.metadata.snap.id, + assetTypes, + ); } this.update((state: Draft) => ({ From 7daa2ac7a587d2553db4a8a1107747b5f910e0ac Mon Sep 17 00:00:00 2001 From: Antonio Regadas Date: Tue, 12 Nov 2024 17:24:37 +0000 Subject: [PATCH 14/23] chore: import order, lint --- app/scripts/lib/accounts/BalancesController.test.ts | 2 +- app/scripts/lib/accounts/BalancesController.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/scripts/lib/accounts/BalancesController.test.ts b/app/scripts/lib/accounts/BalancesController.test.ts index ec7c10791922..982df0289fea 100644 --- a/app/scripts/lib/accounts/BalancesController.test.ts +++ b/app/scripts/lib/accounts/BalancesController.test.ts @@ -6,6 +6,7 @@ import { InternalAccount, } from '@metamask/keyring-api'; import { createMockInternalAccount } from '../../../../test/jest/mocks'; +import { MultichainNetworks } from '../../../../shared/constants/multichain/networks'; import { BalancesController, AllowedActions, @@ -15,7 +16,6 @@ import { BalancesControllerMessenger, } from './BalancesController'; import { BalancesTracker } from './BalancesTracker'; -import { MultichainNetworks } from '../../../../shared/constants/multichain/networks'; const mockBtcAccount = createMockInternalAccount({ address: '', diff --git a/app/scripts/lib/accounts/BalancesController.ts b/app/scripts/lib/accounts/BalancesController.ts index c3f474138b6d..86a88542739a 100644 --- a/app/scripts/lib/accounts/BalancesController.ts +++ b/app/scripts/lib/accounts/BalancesController.ts @@ -26,11 +26,11 @@ import type { } from '@metamask/accounts-controller'; import { MultichainNetworks } from '../../../../shared/constants/multichain/networks'; import { MultichainNativeAssets } from '../../../../shared/constants/multichain/assets'; -import { BalancesTracker } from './BalancesTracker'; import { isBtcMainnetAddress, isBtcTestnetAddress, } from '../../../../shared/lib/multichain'; +import { BalancesTracker } from './BalancesTracker'; const controllerName = 'BalancesController'; From e6e8485efe61b415e3ac46392cf0b28cbe0f7cd9 Mon Sep 17 00:00:00 2001 From: Antonio Regadas Date: Tue, 12 Nov 2024 17:43:29 +0000 Subject: [PATCH 15/23] chore: test update --- app/scripts/metamask-controller.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/scripts/metamask-controller.test.js b/app/scripts/metamask-controller.test.js index 750f8771568b..110a72be984a 100644 --- a/app/scripts/metamask-controller.test.js +++ b/app/scripts/metamask-controller.test.js @@ -41,7 +41,7 @@ import { createMockInternalAccount } from '../../test/jest/mocks'; import { mockNetworkState } from '../../test/stub/networks'; import { BalancesController as MultichainBalancesController, - BALANCES_UPDATE_TIME as MULTICHAIN_BALANCES_UPDATE_TIME, + BTC_BALANCES_UPDATE_TIME as MULTICHAIN_BALANCES_UPDATE_TIME, } from './lib/accounts/BalancesController'; import { BalancesTracker as MultichainBalancesTracker } from './lib/accounts/BalancesTracker'; import { deferredPromise } from './lib/util'; From 91422840a80918f3bae0ba799fea7f01920e6541 Mon Sep 17 00:00:00 2001 From: Antonio Regadas Date: Wed, 13 Nov 2024 10:13:01 +0000 Subject: [PATCH 16/23] chore: test update --- test/e2e/flask/create-watch-account.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/flask/create-watch-account.spec.ts b/test/e2e/flask/create-watch-account.spec.ts index 75fc1c66b0cd..1dbf4cd75958 100644 --- a/test/e2e/flask/create-watch-account.spec.ts +++ b/test/e2e/flask/create-watch-account.spec.ts @@ -5,7 +5,7 @@ import FixtureBuilder from '../fixture-builder'; import { defaultGanacheOptions, unlockWallet, withFixtures } from '../helpers'; import { Driver } from '../webdriver/driver'; -const ACCOUNT_1 = '0x5CfE73b6021E818B776b421B1c4Db2474086a7e1'; +const ACCOUNT_1 = '0x5cfe73b6021e818b776b421b1c4db2474086a7e1'; const EOA_ADDRESS = '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045'; const SHORTENED_EOA_ADDRESS = '0xd8dA6...96045'; const DEFAULT_WATCHED_ACCOUNT_NAME = 'Watched Account 1'; From 3a16d1c44a5a32e1445d09bdb10d13233e036d74 Mon Sep 17 00:00:00 2001 From: Antonio Regadas Date: Wed, 13 Nov 2024 16:20:47 +0000 Subject: [PATCH 17/23] chore: updates the metamask/assets-controllers package --- package.json | 7 ++-- yarn.lock | 111 ++++++++++++++++++++------------------------------- 2 files changed, 48 insertions(+), 70 deletions(-) diff --git a/package.json b/package.json index 70a091b31fda..540422810eca 100644 --- a/package.json +++ b/package.json @@ -298,7 +298,7 @@ "@metamask/address-book-controller": "^6.0.0", "@metamask/announcement-controller": "^7.0.0", "@metamask/approval-controller": "^7.0.0", - "@metamask/assets-controllers": "patch:@metamask/assets-controllers@npm%3A42.0.0#~/.yarn/patches/@metamask-assets-controllers-npm-42.0.0-57b3d695bb.patch", + "@metamask/assets-controllers": "^43.1.0", "@metamask/base-controller": "^7.0.0", "@metamask/bitcoin-wallet-snap": "^0.8.2", "@metamask/browser-passworder": "^4.3.0", @@ -358,7 +358,7 @@ "@metamask/snaps-rpc-methods": "^11.5.1", "@metamask/snaps-sdk": "^6.10.0", "@metamask/snaps-utils": "^8.5.2", - "@metamask/solana-wallet-snap": "^0.1.9", + "@metamask/solana-wallet-snap": "1.0.0", "@metamask/transaction-controller": "^38.3.0", "@metamask/user-operation-controller": "^13.0.0", "@metamask/utils": "^10.0.1", @@ -760,7 +760,8 @@ "resolve-url-loader>es6-iterator>d>es5-ext": false, "resolve-url-loader>es6-iterator>d>es5-ext>esniff>es5-ext": false, "level>classic-level": false, - "jest-preview": false + "jest-preview": false, + "@metamask/solana-wallet-snap>@solana/web3.js>bigint-buffer": false } }, "packageManager": "yarn@4.5.1" diff --git a/yarn.lock b/yarn.lock index c5423cdab97c..c2243625acf6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4934,9 +4934,9 @@ __metadata: languageName: node linkType: hard -"@metamask/assets-controllers@npm:42.0.0": - version: 42.0.0 - resolution: "@metamask/assets-controllers@npm:42.0.0" +"@metamask/assets-controllers@npm:^43.1.0": + version: 43.1.0 + resolution: "@metamask/assets-controllers@npm:43.1.0" dependencies: "@ethereumjs/util": "npm:^8.1.0" "@ethersproject/address": "npm:^5.7.0" @@ -4946,7 +4946,7 @@ __metadata: "@metamask/abi-utils": "npm:^2.0.3" "@metamask/base-controller": "npm:^7.0.2" "@metamask/contract-metadata": "npm:^2.4.0" - "@metamask/controller-utils": "npm:^11.4.2" + "@metamask/controller-utils": "npm:^11.4.3" "@metamask/eth-query": "npm:^4.0.0" "@metamask/metamask-eth-abis": "npm:^3.1.1" "@metamask/polling-controller": "npm:^12.0.1" @@ -4963,50 +4963,12 @@ __metadata: single-call-balance-checker-abi: "npm:^1.0.0" uuid: "npm:^8.3.2" peerDependencies: - "@metamask/accounts-controller": ^18.0.0 + "@metamask/accounts-controller": ^19.0.0 "@metamask/approval-controller": ^7.0.0 - "@metamask/keyring-controller": ^17.0.0 + "@metamask/keyring-controller": ^18.0.0 "@metamask/network-controller": ^22.0.0 - "@metamask/preferences-controller": ^13.0.0 - checksum: 10/64d2bd43139ee5c19bd665b07212cd5d5dd41b457dedde3b5db31442292c4d064dc015011f5f001bb423683675fb20898ff652e91d2339ad1d21cc45fa93487a - languageName: node - linkType: hard - -"@metamask/assets-controllers@patch:@metamask/assets-controllers@npm%3A42.0.0#~/.yarn/patches/@metamask-assets-controllers-npm-42.0.0-57b3d695bb.patch": - version: 42.0.0 - resolution: "@metamask/assets-controllers@patch:@metamask/assets-controllers@npm%3A42.0.0#~/.yarn/patches/@metamask-assets-controllers-npm-42.0.0-57b3d695bb.patch::version=42.0.0&hash=e14ff8" - dependencies: - "@ethereumjs/util": "npm:^8.1.0" - "@ethersproject/address": "npm:^5.7.0" - "@ethersproject/bignumber": "npm:^5.7.0" - "@ethersproject/contracts": "npm:^5.7.0" - "@ethersproject/providers": "npm:^5.7.0" - "@metamask/abi-utils": "npm:^2.0.3" - "@metamask/base-controller": "npm:^7.0.2" - "@metamask/contract-metadata": "npm:^2.4.0" - "@metamask/controller-utils": "npm:^11.4.2" - "@metamask/eth-query": "npm:^4.0.0" - "@metamask/metamask-eth-abis": "npm:^3.1.1" - "@metamask/polling-controller": "npm:^12.0.1" - "@metamask/rpc-errors": "npm:^7.0.1" - "@metamask/utils": "npm:^10.0.0" - "@types/bn.js": "npm:^5.1.5" - "@types/uuid": "npm:^8.3.0" - async-mutex: "npm:^0.5.0" - bn.js: "npm:^5.2.1" - cockatiel: "npm:^3.1.2" - immer: "npm:^9.0.6" - lodash: "npm:^4.17.21" - multiformats: "npm:^13.1.0" - single-call-balance-checker-abi: "npm:^1.0.0" - uuid: "npm:^8.3.2" - peerDependencies: - "@metamask/accounts-controller": ^18.0.0 - "@metamask/approval-controller": ^7.0.0 - "@metamask/keyring-controller": ^17.0.0 - "@metamask/network-controller": ^22.0.0 - "@metamask/preferences-controller": ^13.0.0 - checksum: 10/9a6727b28f88fd2df3f4b1628dd5d8c2f3e73fd4b9cd090f22d175c2522faa6c6b7e9a93d0ec2b2d123a263c8f4116fbfe97f196b99401b28ac8597f522651eb + "@metamask/preferences-controller": ^14.0.0 + checksum: 10/a40863c8a3fcba4309732dedc4ef0c6b42602c042e433228ce3fd590c7b741c1ffc9d0212fe3f61f5a523b9296f374948a185af86c663d9d1d58e87c394eba74 languageName: node linkType: hard @@ -5087,9 +5049,9 @@ __metadata: languageName: node linkType: hard -"@metamask/controller-utils@npm:^11.0.0, @metamask/controller-utils@npm:^11.0.2, @metamask/controller-utils@npm:^11.1.0, @metamask/controller-utils@npm:^11.2.0, @metamask/controller-utils@npm:^11.3.0, @metamask/controller-utils@npm:^11.4.0, @metamask/controller-utils@npm:^11.4.1, @metamask/controller-utils@npm:^11.4.2": - version: 11.4.2 - resolution: "@metamask/controller-utils@npm:11.4.2" +"@metamask/controller-utils@npm:^11.0.0, @metamask/controller-utils@npm:^11.0.2, @metamask/controller-utils@npm:^11.1.0, @metamask/controller-utils@npm:^11.2.0, @metamask/controller-utils@npm:^11.3.0, @metamask/controller-utils@npm:^11.4.0, @metamask/controller-utils@npm:^11.4.1, @metamask/controller-utils@npm:^11.4.2, @metamask/controller-utils@npm:^11.4.3": + version: 11.4.3 + resolution: "@metamask/controller-utils@npm:11.4.3" dependencies: "@ethereumjs/util": "npm:^8.1.0" "@metamask/eth-query": "npm:^4.0.0" @@ -5101,7 +5063,7 @@ __metadata: bn.js: "npm:^5.2.1" eth-ens-namehash: "npm:^2.0.8" fast-deep-equal: "npm:^3.1.3" - checksum: 10/fdae49ee97e7a2a1bb6414011ca59932f8712a768a9c4c43673a2504c9fa9e61d83df53a21ff0506ef6a8cf774704f2df58a6d71385c8786ec5cab4359c051e1 + checksum: 10/5703b0721daf679cf44affc690f2b313e40893b64b0aafaf203e69ee51438197cc3634ef7094145f580a8a8aaadcb79026b2fbd4065c1bb4a8c26627a2c4c69a languageName: node linkType: hard @@ -5722,9 +5684,9 @@ __metadata: languageName: node linkType: hard -"@metamask/keyring-api@npm:@metamask/keyring-api@10.1.0, @metamask/keyring-api@npm:^10.1.0": - version: 10.1.0 - resolution: "@metamask/keyring-api@npm:10.1.0" +"@metamask/keyring-api@npm:@metamask-previews/keyring-api@9.0.0-f9cd26b": + version: 9.0.0-f9cd26b + resolution: "@metamask-previews/keyring-api@npm:9.0.0-f9cd26b" dependencies: "@metamask/snaps-sdk": "npm:^6.7.0" "@metamask/superstruct": "npm:^3.1.0" @@ -5735,13 +5697,13 @@ __metadata: webextension-polyfill: "npm:^0.12.0" peerDependencies: "@metamask/providers": ^18.1.0 - checksum: 10/de22b9f5f3aecc290210fa78161e157aa8358f8dad421a093c9f6dbe35c4755067472a732f10d1ddbfba789e871c64edd8ea1c4c7316a392b214a187efd46ebe + checksum: 10/483ad73a55a0718c6a71cffc713a9a64dd4fd0b41e65eef4bf2389d9c25937416641244fae2a219b8e0579e90a1b6943fa8d4a0a70c4f3fd61a73621146a4f7f languageName: node linkType: hard -"@metamask/keyring-api@npm:^9.0.0": - version: 9.0.0 - resolution: "@metamask/keyring-api@npm:9.0.0" +"@metamask/keyring-api@npm:@metamask/keyring-api@10.1.0, @metamask/keyring-api@npm:^10.1.0": + version: 10.1.0 + resolution: "@metamask/keyring-api@npm:10.1.0" dependencies: "@metamask/snaps-sdk": "npm:^6.7.0" "@metamask/superstruct": "npm:^3.1.0" @@ -5751,8 +5713,8 @@ __metadata: uuid: "npm:^9.0.1" webextension-polyfill: "npm:^0.12.0" peerDependencies: - "@metamask/providers": ^17.2.0 - checksum: 10/ff552c04a4d06c7b1a43d52809a9c141d38772586388f0ab96123bce445f148aa7f7e8165d03fa92ac391351de252c4b299fc2c16e690193f669b5329941fe75 + "@metamask/providers": ^18.1.0 + checksum: 10/de22b9f5f3aecc290210fa78161e157aa8358f8dad421a093c9f6dbe35c4755067472a732f10d1ddbfba789e871c64edd8ea1c4c7316a392b214a187efd46ebe languageName: node linkType: hard @@ -6530,14 +6492,20 @@ __metadata: languageName: node linkType: hard -"@metamask/solana-wallet-snap@npm:^0.1.9": - version: 0.1.9 - resolution: "@metamask/solana-wallet-snap@npm:0.1.9" +"@metamask/solana-wallet-snap@npm:1.0.0": + version: 1.0.0 + resolution: "@metamask/solana-wallet-snap@npm:1.0.0" dependencies: - "@metamask/keyring-api": "npm:^9.0.0" + "@metamask/key-tree": "npm:^9.1.2" + "@metamask/keyring-api": "npm:@metamask-previews/keyring-api@9.0.0-f9cd26b" "@metamask/snaps-sdk": "npm:^6.9.0" + "@solana/web3.js": "npm:^1.95.4" + bs58: "npm:^6.0.0" buffer: "npm:^6.0.3" - checksum: 10/ec540948e1b5c693b0a31a32521d84c5d3796a5d62d1dfa0986cae47483040a0381c30419af4a86b2402efa5e95283b45a5d17bb705c11a181d0c6fa70b5be60 + superstruct: "npm:^2.0.2" + tweetnacl: "npm:^1.0.3" + uuid: "npm:^11.0.2" + checksum: 10/0017f9d93a169c229399b9be68d821c3380f636161405bcc7e75136e75d93c22055d8e732e588f4eb5901f3ef6357c8e6fcabd9773c502f21843210aa168de0c languageName: node linkType: hard @@ -8310,7 +8278,7 @@ __metadata: languageName: node linkType: hard -"@solana/web3.js@npm:^1.95.0": +"@solana/web3.js@npm:^1.95.0, @solana/web3.js@npm:^1.95.4": version: 1.95.4 resolution: "@solana/web3.js@npm:1.95.4" dependencies: @@ -26700,7 +26668,7 @@ __metadata: "@metamask/announcement-controller": "npm:^7.0.0" "@metamask/api-specs": "npm:^0.9.3" "@metamask/approval-controller": "npm:^7.0.0" - "@metamask/assets-controllers": "patch:@metamask/assets-controllers@npm%3A42.0.0#~/.yarn/patches/@metamask-assets-controllers-npm-42.0.0-57b3d695bb.patch" + "@metamask/assets-controllers": "npm:^43.1.0" "@metamask/auto-changelog": "npm:^2.1.0" "@metamask/base-controller": "npm:^7.0.0" "@metamask/bitcoin-wallet-snap": "npm:^0.8.2" @@ -26771,7 +26739,7 @@ __metadata: "@metamask/snaps-rpc-methods": "npm:^11.5.1" "@metamask/snaps-sdk": "npm:^6.10.0" "@metamask/snaps-utils": "npm:^8.5.2" - "@metamask/solana-wallet-snap": "npm:^0.1.9" + "@metamask/solana-wallet-snap": "npm:1.0.0" "@metamask/test-bundler": "npm:^1.0.0" "@metamask/test-dapp": "npm:8.13.0" "@metamask/transaction-controller": "npm:^38.3.0" @@ -36957,6 +36925,15 @@ __metadata: languageName: node linkType: hard +"uuid@npm:^11.0.2": + version: 11.0.3 + resolution: "uuid@npm:11.0.3" + bin: + uuid: dist/esm/bin/uuid + checksum: 10/251385563195709eb0697c74a834764eef28e1656d61174e35edbd129288acb4d95a43f4ce8a77b8c2fc128e2b55924296a0945f964b05b9173469d045625ff2 + languageName: node + linkType: hard + "uuid@npm:^3.3.3": version: 3.4.0 resolution: "uuid@npm:3.4.0" From 22d1eba58f59f20e356c5807a2a952c885eb7844 Mon Sep 17 00:00:00 2001 From: MetaMask Bot Date: Wed, 13 Nov 2024 16:44:35 +0000 Subject: [PATCH 18/23] Update LavaMoat policies --- lavamoat/browserify/beta/policy.json | 15 ++++++++------- lavamoat/browserify/flask/policy.json | 15 ++++++++------- lavamoat/browserify/main/policy.json | 15 ++++++++------- lavamoat/browserify/mmi/policy.json | 15 ++++++++------- 4 files changed, 32 insertions(+), 28 deletions(-) diff --git a/lavamoat/browserify/beta/policy.json b/lavamoat/browserify/beta/policy.json index dfce6718f632..5542ad53d449 100644 --- a/lavamoat/browserify/beta/policy.json +++ b/lavamoat/browserify/beta/policy.json @@ -676,6 +676,7 @@ "Headers": true, "URL": true, "URLSearchParams": true, + "__import__": true, "clearInterval": true, "clearTimeout": true, "console.error": true, @@ -684,8 +685,8 @@ "setTimeout": true }, "packages": { - "@ensdomains/content-hash>multicodec>uint8arrays>multiformats": true, "@ethereumjs/tx>@ethereumjs/util": true, + "@ethersproject/bignumber": true, "@ethersproject/contracts": true, "@ethersproject/providers": true, "@metamask/abi-utils": true, @@ -3122,6 +3123,11 @@ "semver": true } }, + "@metamask/solana-wallet-snap>@solana/web3.js>bs58": { + "packages": { + "@ensdomains/content-hash>multihashes>multibase>base-x": true + } + }, "@metamask/test-bundler>@ethersproject/networks": { "packages": { "ethers>@ethersproject/logger": true @@ -4520,16 +4526,11 @@ }, "ethereumjs-util>ethereum-cryptography>bs58check": { "packages": { + "@metamask/solana-wallet-snap>@solana/web3.js>bs58": true, "ethereumjs-util>create-hash": true, - "ethereumjs-util>ethereum-cryptography>bs58check>bs58": true, "koa>content-disposition>safe-buffer": true } }, - "ethereumjs-util>ethereum-cryptography>bs58check>bs58": { - "packages": { - "@ensdomains/content-hash>multihashes>multibase>base-x": true - } - }, "ethereumjs-util>ethereum-cryptography>keccak": { "packages": { "browserify>buffer": true, diff --git a/lavamoat/browserify/flask/policy.json b/lavamoat/browserify/flask/policy.json index dfce6718f632..5542ad53d449 100644 --- a/lavamoat/browserify/flask/policy.json +++ b/lavamoat/browserify/flask/policy.json @@ -676,6 +676,7 @@ "Headers": true, "URL": true, "URLSearchParams": true, + "__import__": true, "clearInterval": true, "clearTimeout": true, "console.error": true, @@ -684,8 +685,8 @@ "setTimeout": true }, "packages": { - "@ensdomains/content-hash>multicodec>uint8arrays>multiformats": true, "@ethereumjs/tx>@ethereumjs/util": true, + "@ethersproject/bignumber": true, "@ethersproject/contracts": true, "@ethersproject/providers": true, "@metamask/abi-utils": true, @@ -3122,6 +3123,11 @@ "semver": true } }, + "@metamask/solana-wallet-snap>@solana/web3.js>bs58": { + "packages": { + "@ensdomains/content-hash>multihashes>multibase>base-x": true + } + }, "@metamask/test-bundler>@ethersproject/networks": { "packages": { "ethers>@ethersproject/logger": true @@ -4520,16 +4526,11 @@ }, "ethereumjs-util>ethereum-cryptography>bs58check": { "packages": { + "@metamask/solana-wallet-snap>@solana/web3.js>bs58": true, "ethereumjs-util>create-hash": true, - "ethereumjs-util>ethereum-cryptography>bs58check>bs58": true, "koa>content-disposition>safe-buffer": true } }, - "ethereumjs-util>ethereum-cryptography>bs58check>bs58": { - "packages": { - "@ensdomains/content-hash>multihashes>multibase>base-x": true - } - }, "ethereumjs-util>ethereum-cryptography>keccak": { "packages": { "browserify>buffer": true, diff --git a/lavamoat/browserify/main/policy.json b/lavamoat/browserify/main/policy.json index dfce6718f632..5542ad53d449 100644 --- a/lavamoat/browserify/main/policy.json +++ b/lavamoat/browserify/main/policy.json @@ -676,6 +676,7 @@ "Headers": true, "URL": true, "URLSearchParams": true, + "__import__": true, "clearInterval": true, "clearTimeout": true, "console.error": true, @@ -684,8 +685,8 @@ "setTimeout": true }, "packages": { - "@ensdomains/content-hash>multicodec>uint8arrays>multiformats": true, "@ethereumjs/tx>@ethereumjs/util": true, + "@ethersproject/bignumber": true, "@ethersproject/contracts": true, "@ethersproject/providers": true, "@metamask/abi-utils": true, @@ -3122,6 +3123,11 @@ "semver": true } }, + "@metamask/solana-wallet-snap>@solana/web3.js>bs58": { + "packages": { + "@ensdomains/content-hash>multihashes>multibase>base-x": true + } + }, "@metamask/test-bundler>@ethersproject/networks": { "packages": { "ethers>@ethersproject/logger": true @@ -4520,16 +4526,11 @@ }, "ethereumjs-util>ethereum-cryptography>bs58check": { "packages": { + "@metamask/solana-wallet-snap>@solana/web3.js>bs58": true, "ethereumjs-util>create-hash": true, - "ethereumjs-util>ethereum-cryptography>bs58check>bs58": true, "koa>content-disposition>safe-buffer": true } }, - "ethereumjs-util>ethereum-cryptography>bs58check>bs58": { - "packages": { - "@ensdomains/content-hash>multihashes>multibase>base-x": true - } - }, "ethereumjs-util>ethereum-cryptography>keccak": { "packages": { "browserify>buffer": true, diff --git a/lavamoat/browserify/mmi/policy.json b/lavamoat/browserify/mmi/policy.json index c7b4c32968c1..69385bde9412 100644 --- a/lavamoat/browserify/mmi/policy.json +++ b/lavamoat/browserify/mmi/policy.json @@ -768,6 +768,7 @@ "Headers": true, "URL": true, "URLSearchParams": true, + "__import__": true, "clearInterval": true, "clearTimeout": true, "console.error": true, @@ -776,8 +777,8 @@ "setTimeout": true }, "packages": { - "@ensdomains/content-hash>multicodec>uint8arrays>multiformats": true, "@ethereumjs/tx>@ethereumjs/util": true, + "@ethersproject/bignumber": true, "@ethersproject/contracts": true, "@ethersproject/providers": true, "@metamask/abi-utils": true, @@ -3214,6 +3215,11 @@ "semver": true } }, + "@metamask/solana-wallet-snap>@solana/web3.js>bs58": { + "packages": { + "@ensdomains/content-hash>multihashes>multibase>base-x": true + } + }, "@metamask/test-bundler>@ethersproject/networks": { "packages": { "ethers>@ethersproject/logger": true @@ -4612,16 +4618,11 @@ }, "ethereumjs-util>ethereum-cryptography>bs58check": { "packages": { + "@metamask/solana-wallet-snap>@solana/web3.js>bs58": true, "ethereumjs-util>create-hash": true, - "ethereumjs-util>ethereum-cryptography>bs58check>bs58": true, "koa>content-disposition>safe-buffer": true } }, - "ethereumjs-util>ethereum-cryptography>bs58check>bs58": { - "packages": { - "@ensdomains/content-hash>multihashes>multibase>base-x": true - } - }, "ethereumjs-util>ethereum-cryptography>keccak": { "packages": { "browserify>buffer": true, From 6c8e19e57fd97b8b3e85adc4f84bea3d7564e9b6 Mon Sep 17 00:00:00 2001 From: Antonio Regadas Date: Thu, 14 Nov 2024 10:45:45 +0000 Subject: [PATCH 19/23] chore: re-apply the patch for assets-controllers --- ...ts-controllers-npm-43.1.0-253de35116.patch | 35 ++++++++++++++++ package.json | 2 +- yarn.lock | 42 ++++++++++++++++++- 3 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 .yarn/patches/@metamask-assets-controllers-npm-43.1.0-253de35116.patch diff --git a/.yarn/patches/@metamask-assets-controllers-npm-43.1.0-253de35116.patch b/.yarn/patches/@metamask-assets-controllers-npm-43.1.0-253de35116.patch new file mode 100644 index 000000000000..ac1b02873481 --- /dev/null +++ b/.yarn/patches/@metamask-assets-controllers-npm-43.1.0-253de35116.patch @@ -0,0 +1,35 @@ +diff --git a/dist/assetsUtil.cjs b/dist/assetsUtil.cjs +index c2e83cf6caee19152aa164f1333cfef7b681e900..6e007c8c43f1a31fa12baad6116823428ec09480 100644 +--- a/dist/assetsUtil.cjs ++++ b/dist/assetsUtil.cjs +@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; + }; + Object.defineProperty(exports, "__esModule", { value: true }); ++function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } + exports.fetchTokenContractExchangeRates = exports.reduceInBatchesSerially = exports.divideIntoBatches = exports.ethersBigNumberToBN = exports.addUrlProtocolPrefix = exports.getFormattedIpfsUrl = exports.getIpfsCIDv1AndPath = exports.removeIpfsProtocolPrefix = exports.isTokenListSupportedForNetwork = exports.isTokenDetectionSupportedForNetwork = exports.SupportedStakedBalanceNetworks = exports.SupportedTokenDetectionNetworks = exports.formatIconUrlWithProxy = exports.formatAggregatorNames = exports.hasNewCollectionFields = exports.compareNftMetadata = exports.TOKEN_PRICES_BATCH_SIZE = void 0; + const controller_utils_1 = require("@metamask/controller-utils"); + const utils_1 = require("@metamask/utils"); +@@ -233,7 +234,7 @@ async function getIpfsCIDv1AndPath(ipfsUrl) { + const index = url.indexOf('/'); + const cid = index !== -1 ? url.substring(0, index) : url; + const path = index !== -1 ? url.substring(index) : undefined; +- const { CID } = await import("multiformats"); ++ const { CID } = _interopRequireWildcard(require("multiformats")); + // We want to ensure that the CID is v1 (https://docs.ipfs.io/concepts/content-addressing/#identifier-formats) + // because most cid v0s appear to be incompatible with IPFS subdomains + return { +diff --git a/dist/token-prices-service/codefi-v2.mjs b/dist/token-prices-service/codefi-v2.mjs +index e7eaad2cfa8b233c4fd42a51f745233a1cc5c387..b89849c0caf7e5db3b53cf03dd5746b6b1433543 100644 +--- a/dist/token-prices-service/codefi-v2.mjs ++++ b/dist/token-prices-service/codefi-v2.mjs +@@ -12,8 +12,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function ( + var _CodefiTokenPricesServiceV2_tokenPricePolicy; + import { handleFetch } from "@metamask/controller-utils"; + import { hexToNumber } from "@metamask/utils"; +-import $cockatiel from "cockatiel"; +-const { circuitBreaker, ConsecutiveBreaker, ExponentialBackoff, handleAll, retry, wrap, CircuitState } = $cockatiel; ++import { circuitBreaker, ConsecutiveBreaker, ExponentialBackoff, handleAll, retry, wrap, CircuitState } from "cockatiel"; + /** + * The list of currencies that can be supplied as the `vsCurrency` parameter to + * the `/spot-prices` endpoint, in lowercase form. diff --git a/package.json b/package.json index 10ba6a586e3e..5d428adbcb38 100644 --- a/package.json +++ b/package.json @@ -298,7 +298,7 @@ "@metamask/address-book-controller": "^6.0.0", "@metamask/announcement-controller": "^7.0.0", "@metamask/approval-controller": "^7.0.0", - "@metamask/assets-controllers": "^43.1.0", + "@metamask/assets-controllers": "patch:@metamask/assets-controllers@npm%3A43.1.0#~/.yarn/patches/@metamask-assets-controllers-npm-43.1.0-253de35116.patch", "@metamask/base-controller": "^7.0.0", "@metamask/bitcoin-wallet-snap": "^0.8.2", "@metamask/browser-passworder": "^4.3.0", diff --git a/yarn.lock b/yarn.lock index 2c95af563be5..9e5cc0874ec0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4934,7 +4934,7 @@ __metadata: languageName: node linkType: hard -"@metamask/assets-controllers@npm:^43.1.0": +"@metamask/assets-controllers@npm:43.1.0": version: 43.1.0 resolution: "@metamask/assets-controllers@npm:43.1.0" dependencies: @@ -4972,6 +4972,44 @@ __metadata: languageName: node linkType: hard +"@metamask/assets-controllers@patch:@metamask/assets-controllers@npm%3A43.1.0#~/.yarn/patches/@metamask-assets-controllers-npm-43.1.0-253de35116.patch": + version: 43.1.0 + resolution: "@metamask/assets-controllers@patch:@metamask/assets-controllers@npm%3A43.1.0#~/.yarn/patches/@metamask-assets-controllers-npm-43.1.0-253de35116.patch::version=43.1.0&hash=321fe5" + dependencies: + "@ethereumjs/util": "npm:^8.1.0" + "@ethersproject/address": "npm:^5.7.0" + "@ethersproject/bignumber": "npm:^5.7.0" + "@ethersproject/contracts": "npm:^5.7.0" + "@ethersproject/providers": "npm:^5.7.0" + "@metamask/abi-utils": "npm:^2.0.3" + "@metamask/base-controller": "npm:^7.0.2" + "@metamask/contract-metadata": "npm:^2.4.0" + "@metamask/controller-utils": "npm:^11.4.3" + "@metamask/eth-query": "npm:^4.0.0" + "@metamask/metamask-eth-abis": "npm:^3.1.1" + "@metamask/polling-controller": "npm:^12.0.1" + "@metamask/rpc-errors": "npm:^7.0.1" + "@metamask/utils": "npm:^10.0.0" + "@types/bn.js": "npm:^5.1.5" + "@types/uuid": "npm:^8.3.0" + async-mutex: "npm:^0.5.0" + bn.js: "npm:^5.2.1" + cockatiel: "npm:^3.1.2" + immer: "npm:^9.0.6" + lodash: "npm:^4.17.21" + multiformats: "npm:^13.1.0" + single-call-balance-checker-abi: "npm:^1.0.0" + uuid: "npm:^8.3.2" + peerDependencies: + "@metamask/accounts-controller": ^19.0.0 + "@metamask/approval-controller": ^7.0.0 + "@metamask/keyring-controller": ^18.0.0 + "@metamask/network-controller": ^22.0.0 + "@metamask/preferences-controller": ^14.0.0 + checksum: 10/ca407aa4b744b58a9ab752794eeb4677afcb90669c2f9d7bd2c290ea9ce27a7b6e19e00eb90084afa8c867bc17b5f584293f3733a19f2a0575cf9cc634411e06 + languageName: node + linkType: hard + "@metamask/auto-changelog@npm:^2.1.0": version: 2.6.1 resolution: "@metamask/auto-changelog@npm:2.6.1" @@ -26668,7 +26706,7 @@ __metadata: "@metamask/announcement-controller": "npm:^7.0.0" "@metamask/api-specs": "npm:^0.9.3" "@metamask/approval-controller": "npm:^7.0.0" - "@metamask/assets-controllers": "npm:^43.1.0" + "@metamask/assets-controllers": "patch:@metamask/assets-controllers@npm%3A43.1.0#~/.yarn/patches/@metamask-assets-controllers-npm-43.1.0-253de35116.patch" "@metamask/auto-changelog": "npm:^2.1.0" "@metamask/base-controller": "npm:^7.0.0" "@metamask/bitcoin-wallet-snap": "npm:^0.8.2" From 9babd20d6dc0abcd49169d466854d73a70f3ccbe Mon Sep 17 00:00:00 2001 From: MetaMask Bot Date: Thu, 14 Nov 2024 11:05:31 +0000 Subject: [PATCH 20/23] Update LavaMoat policies --- lavamoat/browserify/beta/policy.json | 2 +- lavamoat/browserify/flask/policy.json | 2 +- lavamoat/browserify/main/policy.json | 2 +- lavamoat/browserify/mmi/policy.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lavamoat/browserify/beta/policy.json b/lavamoat/browserify/beta/policy.json index ce39e0c59633..6497de9ed99d 100644 --- a/lavamoat/browserify/beta/policy.json +++ b/lavamoat/browserify/beta/policy.json @@ -676,7 +676,6 @@ "Headers": true, "URL": true, "URLSearchParams": true, - "__import__": true, "clearInterval": true, "clearTimeout": true, "console.error": true, @@ -685,6 +684,7 @@ "setTimeout": true }, "packages": { + "@ensdomains/content-hash>multicodec>uint8arrays>multiformats": true, "@ethereumjs/tx>@ethereumjs/util": true, "@ethersproject/bignumber": true, "@ethersproject/contracts": true, diff --git a/lavamoat/browserify/flask/policy.json b/lavamoat/browserify/flask/policy.json index ce39e0c59633..6497de9ed99d 100644 --- a/lavamoat/browserify/flask/policy.json +++ b/lavamoat/browserify/flask/policy.json @@ -676,7 +676,6 @@ "Headers": true, "URL": true, "URLSearchParams": true, - "__import__": true, "clearInterval": true, "clearTimeout": true, "console.error": true, @@ -685,6 +684,7 @@ "setTimeout": true }, "packages": { + "@ensdomains/content-hash>multicodec>uint8arrays>multiformats": true, "@ethereumjs/tx>@ethereumjs/util": true, "@ethersproject/bignumber": true, "@ethersproject/contracts": true, diff --git a/lavamoat/browserify/main/policy.json b/lavamoat/browserify/main/policy.json index ce39e0c59633..6497de9ed99d 100644 --- a/lavamoat/browserify/main/policy.json +++ b/lavamoat/browserify/main/policy.json @@ -676,7 +676,6 @@ "Headers": true, "URL": true, "URLSearchParams": true, - "__import__": true, "clearInterval": true, "clearTimeout": true, "console.error": true, @@ -685,6 +684,7 @@ "setTimeout": true }, "packages": { + "@ensdomains/content-hash>multicodec>uint8arrays>multiformats": true, "@ethereumjs/tx>@ethereumjs/util": true, "@ethersproject/bignumber": true, "@ethersproject/contracts": true, diff --git a/lavamoat/browserify/mmi/policy.json b/lavamoat/browserify/mmi/policy.json index e5da1a114745..588c92c57c57 100644 --- a/lavamoat/browserify/mmi/policy.json +++ b/lavamoat/browserify/mmi/policy.json @@ -768,7 +768,6 @@ "Headers": true, "URL": true, "URLSearchParams": true, - "__import__": true, "clearInterval": true, "clearTimeout": true, "console.error": true, @@ -777,6 +776,7 @@ "setTimeout": true }, "packages": { + "@ensdomains/content-hash>multicodec>uint8arrays>multiformats": true, "@ethereumjs/tx>@ethereumjs/util": true, "@ethersproject/bignumber": true, "@ethersproject/contracts": true, From cc81cda966de73e88afe53619c254286695df71b Mon Sep 17 00:00:00 2001 From: Antonio Regadas Date: Thu, 14 Nov 2024 11:54:20 +0000 Subject: [PATCH 21/23] chore: update e2e snapshots data --- .../errors-after-init-opt-in-background-state.json | 9 ++++++--- .../errors-after-init-opt-in-ui-state.json | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-background-state.json b/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-background-state.json index bb1640d99365..0acd2274ec94 100644 --- a/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-background-state.json +++ b/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-background-state.json @@ -145,8 +145,11 @@ "MultichainBalancesController": { "balances": "object" }, "MultichainRatesController": { "fiatCurrency": "usd", - "rates": { "btc": { "conversionDate": 0, "conversionRate": 0 } }, - "cryptocurrencies": ["btc"] + "rates": { + "btc": { "conversionDate": 0, "conversionRate": 0 }, + "sol": { "conversionDate": 0, "conversionRate": 0 } + }, + "cryptocurrencies": ["btc", "sol"] }, "NameController": { "names": "object", "nameSources": "object" }, "NetworkController": { @@ -243,6 +246,7 @@ "snapRegistryList": "object", "theme": "light", "snapsAddSnapAccountModalDismissed": "boolean", + "solanaSupportEnabled": "boolean", "useExternalNameSources": "boolean", "useTransactionSimulations": true, "enableMV3TimestampSave": true, @@ -327,7 +331,6 @@ }, "TxController": { "methodData": "object", - "submitHistory": "object", "transactions": "object", "lastFetchedBlockNumbers": "object", "submitHistory": "object" diff --git a/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-ui-state.json b/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-ui-state.json index 3d36d5fc7592..b2921a878119 100644 --- a/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-ui-state.json +++ b/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-ui-state.json @@ -33,7 +33,6 @@ "smartTransactionsOptInStatus": true, "showNativeTokenAsMainBalance": true, "petnamesEnabled": true, - "showMultiRpcModal": "boolean", "isRedesignedConfirmationsDeveloperEnabled": "boolean", "redesignedConfirmationsEnabled": true, "redesignedTransactionsEnabled": "boolean", @@ -141,6 +140,7 @@ "snapRegistryList": "object", "theme": "light", "snapsAddSnapAccountModalDismissed": "boolean", + "solanaSupportEnabled": "boolean", "useExternalNameSources": "boolean", "useTransactionSimulations": true, "enableMV3TimestampSave": true, @@ -198,8 +198,11 @@ "lastFetchedBlockNumbers": "object", "submitHistory": "object", "fiatCurrency": "usd", - "rates": { "btc": { "conversionDate": 0, "conversionRate": 0 } }, - "cryptocurrencies": ["btc"], + "rates": { + "btc": { "conversionDate": 0, "conversionRate": 0 }, + "sol": { "conversionDate": 0, "conversionRate": 0 } + }, + "cryptocurrencies": ["btc", "sol"], "snaps": "object", "jobs": "object", "database": null, From 9f1189b35e33191c54f31d14254075d409b0b523 Mon Sep 17 00:00:00 2001 From: Antonio Regadas Date: Thu, 14 Nov 2024 12:34:42 +0000 Subject: [PATCH 22/23] chore: update e2e --- .../errors-after-init-opt-in-background-state.json | 1 - .../state-snapshots/errors-after-init-opt-in-ui-state.json | 1 - 2 files changed, 2 deletions(-) diff --git a/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-background-state.json b/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-background-state.json index 0acd2274ec94..337d69d718a1 100644 --- a/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-background-state.json +++ b/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-background-state.json @@ -246,7 +246,6 @@ "snapRegistryList": "object", "theme": "light", "snapsAddSnapAccountModalDismissed": "boolean", - "solanaSupportEnabled": "boolean", "useExternalNameSources": "boolean", "useTransactionSimulations": true, "enableMV3TimestampSave": true, diff --git a/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-ui-state.json b/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-ui-state.json index b2921a878119..7fafb239cbdc 100644 --- a/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-ui-state.json +++ b/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-ui-state.json @@ -140,7 +140,6 @@ "snapRegistryList": "object", "theme": "light", "snapsAddSnapAccountModalDismissed": "boolean", - "solanaSupportEnabled": "boolean", "useExternalNameSources": "boolean", "useTransactionSimulations": true, "enableMV3TimestampSave": true, From ce125fa2c7a151219f6b69cb323d2c8ddd81c893 Mon Sep 17 00:00:00 2001 From: Antonio Regadas Date: Thu, 14 Nov 2024 14:16:07 +0000 Subject: [PATCH 23/23] chore: comment flaky endpoint --- .../tests/privacy/basic-functionality.spec.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/test/e2e/tests/privacy/basic-functionality.spec.js b/test/e2e/tests/privacy/basic-functionality.spec.js index e6439c569339..f5f65a75e8ef 100644 --- a/test/e2e/tests/privacy/basic-functionality.spec.js +++ b/test/e2e/tests/privacy/basic-functionality.spec.js @@ -14,14 +14,15 @@ async function mockApis(mockServer) { body: [{ fakedata: true }], }; }), - await mockServer - .forGet('https://token.api.cx.metamask.io/tokens/1') - .thenCallback(() => { - return { - statusCode: 200, - body: [{ fakedata: true }], - }; - }), + // NOTE: Very Flaky, this endpoint is constantly failing with no reason even if the driver delay is increased + // await mockServer + // .forGet('https://token.api.cx.metamask.io/tokens/1') + // .thenCallback(() => { + // return { + // statusCode: 200, + // body: [{ fakedata: true }], + // }; + // }), await mockServer .forGet('https://min-api.cryptocompare.com/data/pricemulti') .withQuery({ fsyms: 'ETH', tsyms: 'usd' })